PrimLimitsModule.cs 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  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. private Scene m_scene;
  53. public string Name { get { return "PrimLimitsModule"; } }
  54. public Type ReplaceableInterface { get { return null; } }
  55. public void Initialise(IConfigSource config)
  56. {
  57. string permissionModules = Util.GetConfigVarFromSections<string>(config, "permissionmodules",
  58. new string[] { "Startup", "Permissions" }, "DefaultPermissionsModule");
  59. List<string> modules = new List<string>(permissionModules.Split(',').Select(m => m.Trim()));
  60. if(!modules.Contains("PrimLimitsModule"))
  61. return;
  62. m_log.DebugFormat("[PRIM LIMITS]: Initialized module");
  63. m_enabled = true;
  64. }
  65. public void Close()
  66. {
  67. }
  68. public void AddRegion(Scene scene)
  69. {
  70. if (!m_enabled)
  71. return;
  72. m_scene = scene;
  73. scene.Permissions.OnRezObject += CanRezObject;
  74. scene.Permissions.OnObjectEntry += CanObjectEnter;
  75. scene.Permissions.OnObjectEnterWithScripts += CanObjectEnterWithScripts;
  76. scene.Permissions.OnDuplicateObject += CanDuplicateObject;
  77. m_log.DebugFormat("[PRIM LIMITS]: Region {0} added", scene.RegionInfo.RegionName);
  78. }
  79. public void RemoveRegion(Scene scene)
  80. {
  81. if (!m_enabled)
  82. return;
  83. m_scene.Permissions.OnRezObject -= CanRezObject;
  84. m_scene.Permissions.OnObjectEntry -= CanObjectEnter;
  85. scene.Permissions.OnObjectEnterWithScripts -= CanObjectEnterWithScripts;
  86. m_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)
  93. {
  94. ILandObject lo = m_scene.LandChannel.GetLandObject(objectPosition.X, objectPosition.Y);
  95. string response = DoCommonChecks(objectCount, ownerID, lo);
  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(SceneObjectGroup sog, ScenePresence sp)
  105. {
  106. Vector3 objectPosition = sog.AbsolutePosition;
  107. ILandObject lo = m_scene.LandChannel.GetLandObject(objectPosition.X, objectPosition.Y);
  108. string response = DoCommonChecks(sog.PrimCount, sp.UUID, lo);
  109. if (response != null)
  110. {
  111. m_dialogModule.SendAlertToUser(sp.UUID, response);
  112. return false;
  113. }
  114. return true;
  115. }
  116. private bool CanObjectEnter(SceneObjectGroup sog, bool enteringRegion, Vector3 newPoint)
  117. {
  118. float newX = newPoint.X;
  119. float newY = newPoint.Y;
  120. if (newX < -1.0f || newX > (m_scene.RegionInfo.RegionSizeX + 1.0f) ||
  121. newY < -1.0f || newY > (m_scene.RegionInfo.RegionSizeY + 1.0f) )
  122. return true;
  123. if (sog == null)
  124. return false;
  125. ILandObject newParcel = m_scene.LandChannel.GetLandObject(newX, newY);
  126. if (newParcel == null)
  127. return true;
  128. if(!enteringRegion)
  129. {
  130. Vector3 oldPoint = sog.AbsolutePosition;
  131. ILandObject oldParcel = m_scene.LandChannel.GetLandObject(oldPoint.X, oldPoint.Y);
  132. if(oldParcel != null && oldParcel.Equals(newParcel))
  133. return true;
  134. }
  135. int objectCount = sog.PrimCount;
  136. // TODO: Add Special Case here for temporary prims
  137. string response = DoCommonChecks(objectCount, sog.OwnerID, newParcel);
  138. if (response != null)
  139. {
  140. if(m_dialogModule != null)
  141. m_dialogModule.SendAlertToUser(sog.OwnerID, response);
  142. return false;
  143. }
  144. return true;
  145. }
  146. private bool CanObjectEnterWithScripts(SceneObjectGroup sog, ILandObject newParcel)
  147. {
  148. if (sog == null)
  149. return false;
  150. if (newParcel == null)
  151. return true;
  152. int objectCount = sog.PrimCount;
  153. // TODO: Add Special Case here for temporary prims
  154. string response = DoCommonChecks(objectCount, sog.OwnerID, newParcel);
  155. if (response != null)
  156. return false;
  157. return true;
  158. }
  159. private string DoCommonChecks(int objectCount, UUID ownerID, ILandObject lo)
  160. {
  161. string response = null;
  162. int OwnedParcelsCapacity = lo.GetSimulatorMaxPrimCount();
  163. if ((objectCount + lo.PrimCounts.Total) > OwnedParcelsCapacity)
  164. {
  165. response = "Unable to rez object because the parcel is full";
  166. }
  167. else
  168. {
  169. int maxPrimsPerUser = m_scene.RegionInfo.MaxPrimsPerUser;
  170. if (maxPrimsPerUser >= 0)
  171. {
  172. // per-user prim limit is set
  173. if (ownerID != lo.LandData.OwnerID || lo.LandData.IsGroupOwned)
  174. {
  175. // caller is not the sole Parcel owner
  176. EstateSettings estateSettings = m_scene.RegionInfo.EstateSettings;
  177. if (ownerID != estateSettings.EstateOwner)
  178. {
  179. // caller is NOT the Estate owner
  180. List<UUID> mgrs = new List<UUID>(estateSettings.EstateManagers);
  181. if (!mgrs.Contains(ownerID))
  182. {
  183. // caller is not an Estate Manager
  184. if ((lo.PrimCounts.Users[ownerID] + objectCount) > maxPrimsPerUser)
  185. {
  186. response = "Unable to rez object because you have reached your limit";
  187. }
  188. }
  189. }
  190. }
  191. }
  192. }
  193. return response;
  194. }
  195. }
  196. }