1
0

PrimLimitsModule.cs 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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. //IConfig myConfig = config.Configs["Startup"];
  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. {
  72. return;
  73. }
  74. scene.Permissions.OnRezObject += CanRezObject;
  75. scene.Permissions.OnObjectEntry += CanObjectEnter;
  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. {
  83. return;
  84. }
  85. scene.Permissions.OnRezObject -= CanRezObject;
  86. scene.Permissions.OnObjectEntry -= CanObjectEnter;
  87. scene.Permissions.OnDuplicateObject -= CanDuplicateObject;
  88. }
  89. public void RegionLoaded(Scene scene)
  90. {
  91. m_dialogModule = scene.RequestModuleInterface<IDialogModule>();
  92. }
  93. private bool CanRezObject(int objectCount, UUID owner, Vector3 objectPosition, Scene scene)
  94. {
  95. ILandObject lo = scene.LandChannel.GetLandObject(objectPosition.X, objectPosition.Y);
  96. int usedPrims = lo.PrimCounts.Total;
  97. int simulatorCapacity = lo.GetSimulatorMaxPrimCount();
  98. if (objectCount + usedPrims > simulatorCapacity)
  99. {
  100. m_dialogModule.SendAlertToUser(owner, "Unable to rez object because the parcel is too full");
  101. return false;
  102. }
  103. return true;
  104. }
  105. private bool CanObjectEnter(UUID objectID, bool enteringRegion, Vector3 newPoint, Scene scene)
  106. {
  107. SceneObjectPart obj = scene.GetSceneObjectPart(objectID);
  108. Vector3 oldPoint = obj.GroupPosition;
  109. int objectCount = obj.ParentGroup.PrimCount;
  110. ILandObject oldParcel = scene.LandChannel.GetLandObject(oldPoint.X, oldPoint.Y);
  111. ILandObject newParcel = scene.LandChannel.GetLandObject(newPoint.X, newPoint.Y);
  112. int usedPrims = newParcel.PrimCounts.Total;
  113. int simulatorCapacity = newParcel.GetSimulatorMaxPrimCount();
  114. // The prim hasn't crossed a region boundry so we don't need to worry
  115. // about prim counts here
  116. if(oldParcel.Equals(newParcel))
  117. {
  118. return true;
  119. }
  120. // Prim counts are determined by the location of the root prim. if we're
  121. // moving a child prim, just let it pass
  122. if(!obj.IsRoot)
  123. {
  124. return true;
  125. }
  126. // TODO: Add Special Case here for temporary prims
  127. if(objectCount + usedPrims > simulatorCapacity)
  128. {
  129. m_dialogModule.SendAlertToUser(obj.OwnerID, "Unable to move object because the destination parcel is too full");
  130. return false;
  131. }
  132. return true;
  133. }
  134. //OnDuplicateObject
  135. private bool CanDuplicateObject(int objectCount, UUID objectID, UUID owner, Scene scene, Vector3 objectPosition)
  136. {
  137. ILandObject lo = scene.LandChannel.GetLandObject(objectPosition.X, objectPosition.Y);
  138. int usedPrims = lo.PrimCounts.Total;
  139. int simulatorCapacity = lo.GetSimulatorMaxPrimCount();
  140. if(objectCount + usedPrims > simulatorCapacity)
  141. {
  142. m_dialogModule.SendAlertToUser(owner, "Unable to duplicate object because the parcel is too full");
  143. return false;
  144. }
  145. return true;
  146. }
  147. }
  148. }