PrimLimitsModule.cs 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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 = myConfig.GetString("permissionmodules", "DefaultPermissionsModule");
  57. List<string> modules=new List<string>(permissionModules.Split(','));
  58. if(!modules.Contains("PrimLimitsModule"))
  59. return;
  60. m_log.DebugFormat("[PRIM LIMITS]: Initialized module");
  61. m_enabled = true;
  62. }
  63. public void Close()
  64. {
  65. }
  66. public void AddRegion(Scene scene)
  67. {
  68. if (!m_enabled)
  69. {
  70. return;
  71. }
  72. scene.Permissions.OnRezObject += CanRezObject;
  73. scene.Permissions.OnObjectEntry += CanObjectEnter;
  74. scene.Permissions.OnDuplicateObject += CanDuplicateObject;
  75. m_log.DebugFormat("[PRIM LIMITS]: Region {0} added", scene.RegionInfo.RegionName);
  76. }
  77. public void RemoveRegion(Scene scene)
  78. {
  79. if (m_enabled)
  80. {
  81. return;
  82. }
  83. scene.Permissions.OnRezObject -= CanRezObject;
  84. scene.Permissions.OnObjectEntry -= CanObjectEnter;
  85. scene.Permissions.OnDuplicateObject -= CanDuplicateObject;
  86. }
  87. public void RegionLoaded(Scene scene)
  88. {
  89. m_dialogModule = scene.RequestModuleInterface<IDialogModule>();
  90. }
  91. private bool CanRezObject(int objectCount, UUID owner, Vector3 objectPosition, Scene scene)
  92. {
  93. ILandObject lo = scene.LandChannel.GetLandObject(objectPosition.X, objectPosition.Y);
  94. int usedPrims = lo.PrimCounts.Total;
  95. int simulatorCapacity = lo.GetSimulatorMaxPrimCount();
  96. if (objectCount + usedPrims > simulatorCapacity)
  97. {
  98. m_dialogModule.SendAlertToUser(owner, "Unable to rez object because the parcel is too full");
  99. return false;
  100. }
  101. return true;
  102. }
  103. private bool CanObjectEnter(UUID objectID, bool enteringRegion, Vector3 newPoint, Scene scene)
  104. {
  105. SceneObjectPart obj = scene.GetSceneObjectPart(objectID);
  106. Vector3 oldPoint = obj.GroupPosition;
  107. int objectCount = obj.ParentGroup.PrimCount;
  108. ILandObject oldParcel = scene.LandChannel.GetLandObject(oldPoint.X, oldPoint.Y);
  109. ILandObject newParcel = scene.LandChannel.GetLandObject(newPoint.X, newPoint.Y);
  110. int usedPrims = newParcel.PrimCounts.Total;
  111. int simulatorCapacity = newParcel.GetSimulatorMaxPrimCount();
  112. // The prim hasn't crossed a region boundry so we don't need to worry
  113. // about prim counts here
  114. if(oldParcel.Equals(newParcel))
  115. {
  116. return true;
  117. }
  118. // Prim counts are determined by the location of the root prim. if we're
  119. // moving a child prim, just let it pass
  120. if(!obj.IsRoot)
  121. {
  122. return true;
  123. }
  124. // TODO: Add Special Case here for temporary prims
  125. if(objectCount + usedPrims > simulatorCapacity)
  126. {
  127. m_dialogModule.SendAlertToUser(obj.OwnerID, "Unable to move object because the destination parcel is too full");
  128. return false;
  129. }
  130. return true;
  131. }
  132. //OnDuplicateObject
  133. private bool CanDuplicateObject(int objectCount, UUID objectID, UUID owner, Scene scene, Vector3 objectPosition)
  134. {
  135. ILandObject lo = scene.LandChannel.GetLandObject(objectPosition.X, objectPosition.Y);
  136. int usedPrims = lo.PrimCounts.Total;
  137. int simulatorCapacity = lo.GetSimulatorMaxPrimCount();
  138. if(objectCount + usedPrims > simulatorCapacity)
  139. {
  140. m_dialogModule.SendAlertToUser(owner, "Unable to duplicate object because the parcel is too full");
  141. return false;
  142. }
  143. return true;
  144. }
  145. }
  146. }