PrimLimitsModule.cs 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. /*
  2. * Copyright (c) Contributors, http://opensimulator.org/
  3. * See CONTRIBUTORS.TXT for a full list of copyright holders.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. * * Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * * Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. * * Neither the name of the OpenSimulator Project nor the
  13. * names of its contributors may be used to endorse or promote products
  14. * derived from this software without specific prior written permission.
  15. *
  16. * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
  17. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  18. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  19. * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
  20. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  21. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  22. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  23. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  24. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  25. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. */
  27. using System;
  28. using System.Collections.Generic;
  29. using System.Linq;
  30. using System.Reflection;
  31. using log4net;
  32. using Mono.Addins;
  33. using Nini.Config;
  34. using OpenMetaverse;
  35. using OpenSim.Framework;
  36. using OpenSim.Region.Framework.Interfaces;
  37. using OpenSim.Region.Framework.Scenes;
  38. namespace OpenSim.Region.OptionalModules
  39. {
  40. /// <summary>
  41. /// Enables Prim limits for parcel.
  42. /// </summary>
  43. /// <remarks>
  44. /// This module selectivly enables parcel prim limits.
  45. /// </remarks>
  46. [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "PrimLimitsModule")]
  47. public class PrimLimitsModule : INonSharedRegionModule
  48. {
  49. protected IDialogModule m_dialogModule;
  50. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  51. private bool m_enabled;
  52. public string Name { get { return "PrimLimitsModule"; } }
  53. public Type ReplaceableInterface { get { return null; } }
  54. public void Initialise(IConfigSource config)
  55. {
  56. string permissionModules = Util.GetConfigVarFromSections<string>(config, "permissionmodules",
  57. new string[] { "Startup", "Permissions" }, "DefaultPermissionsModule");
  58. List<string> modules = new List<string>(permissionModules.Split(',').Select(m => m.Trim()));
  59. if(!modules.Contains("PrimLimitsModule"))
  60. return;
  61. m_log.DebugFormat("[PRIM LIMITS]: Initialized module");
  62. m_enabled = true;
  63. }
  64. public void Close()
  65. {
  66. }
  67. public void AddRegion(Scene scene)
  68. {
  69. if (!m_enabled)
  70. {
  71. return;
  72. }
  73. scene.Permissions.OnRezObject += CanRezObject;
  74. scene.Permissions.OnObjectEntry += CanObjectEnter;
  75. scene.Permissions.OnDuplicateObject += CanDuplicateObject;
  76. m_log.DebugFormat("[PRIM LIMITS]: Region {0} added", scene.RegionInfo.RegionName);
  77. }
  78. public void RemoveRegion(Scene scene)
  79. {
  80. if (m_enabled)
  81. {
  82. return;
  83. }
  84. scene.Permissions.OnRezObject -= CanRezObject;
  85. scene.Permissions.OnObjectEntry -= CanObjectEnter;
  86. scene.Permissions.OnDuplicateObject -= CanDuplicateObject;
  87. }
  88. public void RegionLoaded(Scene scene)
  89. {
  90. m_dialogModule = scene.RequestModuleInterface<IDialogModule>();
  91. }
  92. private bool CanRezObject(int objectCount, UUID ownerID, Vector3 objectPosition, Scene scene)
  93. {
  94. ILandObject lo = scene.LandChannel.GetLandObject(objectPosition.X, objectPosition.Y);
  95. string response = DoCommonChecks(objectCount, ownerID, lo, scene);
  96. if (response != null)
  97. {
  98. m_dialogModule.SendAlertToUser(ownerID, response);
  99. return false;
  100. }
  101. return true;
  102. }
  103. //OnDuplicateObject
  104. private bool CanDuplicateObject(int objectCount, UUID objectID, UUID ownerID, Scene scene, Vector3 objectPosition)
  105. {
  106. ILandObject lo = scene.LandChannel.GetLandObject(objectPosition.X, objectPosition.Y);
  107. string response = DoCommonChecks(objectCount, ownerID, lo, scene);
  108. if (response != null)
  109. {
  110. m_dialogModule.SendAlertToUser(ownerID, response);
  111. return false;
  112. }
  113. return true;
  114. }
  115. private bool CanObjectEnter(UUID objectID, bool enteringRegion, Vector3 newPoint, Scene scene)
  116. {
  117. SceneObjectPart obj = scene.GetSceneObjectPart(objectID);
  118. Vector3 oldPoint = obj.GroupPosition;
  119. int objectCount = obj.ParentGroup.PrimCount;
  120. ILandObject oldParcel = scene.LandChannel.GetLandObject(oldPoint.X, oldPoint.Y);
  121. ILandObject newParcel = scene.LandChannel.GetLandObject(newPoint.X, newPoint.Y);
  122. // newParcel will be null only if it outside of our current region. If this is the case, then the
  123. // receiving permissions will perform the check.
  124. if (newParcel == null)
  125. return true;
  126. // The prim hasn't crossed a region boundary so we don't need to worry
  127. // about prim counts here
  128. if(oldParcel.Equals(newParcel))
  129. {
  130. return true;
  131. }
  132. // Prim counts are determined by the location of the root prim. if we're
  133. // moving a child prim, just let it pass
  134. if(!obj.IsRoot)
  135. {
  136. return true;
  137. }
  138. // TODO: Add Special Case here for temporary prims
  139. string response = DoCommonChecks(objectCount, obj.OwnerID, newParcel, scene);
  140. if (response != null)
  141. {
  142. m_dialogModule.SendAlertToUser(obj.OwnerID, response);
  143. return false;
  144. }
  145. return true;
  146. }
  147. private string DoCommonChecks(int objectCount, UUID ownerID, ILandObject lo, Scene scene)
  148. {
  149. string response = null;
  150. int simulatorCapacity = lo.GetSimulatorMaxPrimCount();
  151. if ((objectCount + lo.PrimCounts.Total) > simulatorCapacity)
  152. {
  153. response = "Unable to rez object because the parcel is too full";
  154. }
  155. else
  156. {
  157. int maxPrimsPerUser = scene.RegionInfo.MaxPrimsPerUser;
  158. if (maxPrimsPerUser >= 0)
  159. {
  160. // per-user prim limit is set
  161. if (ownerID != lo.LandData.OwnerID || lo.LandData.IsGroupOwned)
  162. {
  163. // caller is not the sole Parcel owner
  164. EstateSettings estateSettings = scene.RegionInfo.EstateSettings;
  165. if (ownerID != estateSettings.EstateOwner)
  166. {
  167. // caller is NOT the Estate owner
  168. List<UUID> mgrs = new List<UUID>(estateSettings.EstateManagers);
  169. if (!mgrs.Contains(ownerID))
  170. {
  171. // caller is not an Estate Manager
  172. if ((lo.PrimCounts.Users[ownerID] + objectCount) > maxPrimsPerUser)
  173. {
  174. response = "Unable to rez object because you have reached your limit";
  175. }
  176. }
  177. }
  178. }
  179. }
  180. }
  181. return response;
  182. }
  183. }
  184. }