PrimLimitsModule.cs 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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.Reflection;
  29. using System.Collections.Generic;
  30. using log4net;
  31. using Mono.Addins;
  32. using Nini.Config;
  33. using OpenMetaverse;
  34. using OpenSim.Framework;
  35. using OpenSim.Region.Framework.Interfaces;
  36. using OpenSim.Region.Framework.Scenes;
  37. namespace OpenSim.Region.OptionalModules
  38. {
  39. /// <summary>
  40. /// Enables Prim limits for parcel.
  41. /// </summary>
  42. /// <remarks>
  43. /// This module selectivly enables parcel prim limits.
  44. /// </remarks>
  45. [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "PrimLimitsModule")]
  46. public class PrimLimitsModule : INonSharedRegionModule
  47. {
  48. protected IDialogModule m_dialogModule;
  49. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  50. private bool m_enabled;
  51. public string Name { get { return "PrimLimitsModule"; } }
  52. public Type ReplaceableInterface { get { return null; } }
  53. public void Initialise(IConfigSource config)
  54. {
  55. //IConfig myConfig = config.Configs["Startup"];
  56. string permissionModules = Util.GetConfigVarFromSections<string>(config, "permissionmodules",
  57. new string[] { "Startup", "Permissions" }, "DefaultPermissionsModule");
  58. List<string> modules=new List<string>(permissionModules.Split(','));
  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 owner, Vector3 objectPosition, Scene scene)
  93. {
  94. ILandObject lo = scene.LandChannel.GetLandObject(objectPosition.X, objectPosition.Y);
  95. int usedPrims = lo.PrimCounts.Total;
  96. int simulatorCapacity = lo.GetSimulatorMaxPrimCount();
  97. if (objectCount + usedPrims > simulatorCapacity)
  98. {
  99. m_dialogModule.SendAlertToUser(owner, "Unable to rez object because the parcel is too full");
  100. return false;
  101. }
  102. return true;
  103. }
  104. private bool CanObjectEnter(UUID objectID, bool enteringRegion, Vector3 newPoint, Scene scene)
  105. {
  106. SceneObjectPart obj = scene.GetSceneObjectPart(objectID);
  107. Vector3 oldPoint = obj.GroupPosition;
  108. int objectCount = obj.ParentGroup.PrimCount;
  109. ILandObject oldParcel = scene.LandChannel.GetLandObject(oldPoint.X, oldPoint.Y);
  110. ILandObject newParcel = scene.LandChannel.GetLandObject(newPoint.X, newPoint.Y);
  111. int usedPrims = newParcel.PrimCounts.Total;
  112. int simulatorCapacity = newParcel.GetSimulatorMaxPrimCount();
  113. // The prim hasn't crossed a region boundry so we don't need to worry
  114. // about prim counts here
  115. if(oldParcel.Equals(newParcel))
  116. {
  117. return true;
  118. }
  119. // Prim counts are determined by the location of the root prim. if we're
  120. // moving a child prim, just let it pass
  121. if(!obj.IsRoot)
  122. {
  123. return true;
  124. }
  125. // TODO: Add Special Case here for temporary prims
  126. if(objectCount + usedPrims > simulatorCapacity)
  127. {
  128. m_dialogModule.SendAlertToUser(obj.OwnerID, "Unable to move object because the destination parcel is too full");
  129. return false;
  130. }
  131. return true;
  132. }
  133. //OnDuplicateObject
  134. private bool CanDuplicateObject(int objectCount, UUID objectID, UUID owner, Scene scene, Vector3 objectPosition)
  135. {
  136. ILandObject lo = scene.LandChannel.GetLandObject(objectPosition.X, objectPosition.Y);
  137. int usedPrims = lo.PrimCounts.Total;
  138. int simulatorCapacity = lo.GetSimulatorMaxPrimCount();
  139. if(objectCount + usedPrims > simulatorCapacity)
  140. {
  141. m_dialogModule.SendAlertToUser(owner, "Unable to duplicate object because the parcel is too full");
  142. return false;
  143. }
  144. return true;
  145. }
  146. }
  147. }