aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/OptionalModules/PrimLimitsModule
diff options
context:
space:
mode:
authorE. Allen Soard2011-05-06 18:48:00 -0700
committerMelanie2011-05-09 03:14:41 +0100
commit65d595597de9e28ad219d2fbe2326cc99be0e642 (patch)
treea233c661c19159a1fa21f69b824ffc553f15494c /OpenSim/Region/OptionalModules/PrimLimitsModule
parentAdd commands to delete objects by name, UUID, creator or owner (diff)
downloadopensim-SC_OLD-65d595597de9e28ad219d2fbe2326cc99be0e642.zip
opensim-SC_OLD-65d595597de9e28ad219d2fbe2326cc99be0e642.tar.gz
opensim-SC_OLD-65d595597de9e28ad219d2fbe2326cc99be0e642.tar.bz2
opensim-SC_OLD-65d595597de9e28ad219d2fbe2326cc99be0e642.tar.xz
Adds an optional module to enforce prim limits on a given parcel Takes into account acculmitive prim allowance when multiple parcels are owned by the same avatar on the same region. Does not handle prims that are moved by a script or account for temporary objects at the time of creation. other wise handles all tested cases including: Creating a new object from the build menu Moving an object from another parcel duplicating an object via shift move rezing an object from a script
Diffstat (limited to 'OpenSim/Region/OptionalModules/PrimLimitsModule')
-rw-r--r--OpenSim/Region/OptionalModules/PrimLimitsModule/PrimLimitsModule.cs163
1 files changed, 163 insertions, 0 deletions
diff --git a/OpenSim/Region/OptionalModules/PrimLimitsModule/PrimLimitsModule.cs b/OpenSim/Region/OptionalModules/PrimLimitsModule/PrimLimitsModule.cs
new file mode 100644
index 0000000..0aee191
--- /dev/null
+++ b/OpenSim/Region/OptionalModules/PrimLimitsModule/PrimLimitsModule.cs
@@ -0,0 +1,163 @@
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
28using System;
29using System.Reflection;
30using log4net;
31using Mono.Addins;
32using Nini.Config;
33using OpenMetaverse;
34using OpenSim.Framework;
35using OpenSim.Region.Framework.Interfaces;
36using OpenSim.Region.Framework.Scenes;
37
38namespace OpenSim.Region.OptionalModules
39{
40 /// <summary>
41 /// Simplest possible example of a non-shared region module.
42 /// </summary>
43 /// <remarks>
44 /// This module is the simplest possible example of a non-shared region module (a module where each scene/region
45 /// in the simulator has its own copy). If anybody wants to create a more complex example in the future then
46 /// please create a separate class.
47 ///
48 /// This module is not active by default. If you want to see it in action,
49 /// then just uncomment the line below starting with [Extension(Path...
50 ///
51 /// When the module is enabled it will print messages when it receives certain events to the screen and the log
52 /// file.
53 /// </remarks>
54 [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "PrimLimitsModule")]
55 public class BareBonesNonSharedModule : INonSharedRegionModule
56 {
57 protected IDialogModule m_dialogModule;
58 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
59
60 public string Name { get { return "Prim Limits Module"; } }
61
62 public Type ReplaceableInterface { get { return null; } }
63
64 public void Initialise(IConfigSource source)
65 {
66 m_log.DebugFormat("[PRIM LIMITS]: INITIALIZED MODULE");
67 }
68
69 public void Close()
70 {
71 m_log.DebugFormat("[PRIM LIMITS]: CLOSED MODULE");
72 }
73
74 public void AddRegion(Scene scene)
75 {
76 scene.Permissions.OnRezObject += CanRezObject;
77 scene.Permissions.OnObjectEntry += CanObjectEnter;
78 scene.Permissions.OnDuplicateObject += CanDuplicateObject;
79 m_log.DebugFormat("[PRIM LIMITS]: REGION {0} ADDED", scene.RegionInfo.RegionName);
80 }
81
82 public void RemoveRegion(Scene scene)
83 {
84 scene.Permissions.OnRezObject -= CanRezObject;
85 scene.Permissions.OnObjectEntry -= CanObjectEnter;
86 scene.Permissions.OnDuplicateObject -= CanDuplicateObject;
87 m_log.DebugFormat("[PRIM LIMITS]: REGION {0} REMOVED", scene.RegionInfo.RegionName);
88 }
89
90 public void RegionLoaded(Scene scene)
91 {
92 m_dialogModule = scene.RequestModuleInterface<IDialogModule>();
93 m_log.DebugFormat("[PRIM LIMITS]: REGION {0} LOADED", scene.RegionInfo.RegionName);
94 }
95 private bool CanRezObject(int objectCount, UUID owner, Vector3 objectPosition, Scene scene)
96 {
97 // This may be a little long winded and can probably be optomized
98 int usedPrims = scene.LandChannel.GetLandObject(objectPosition.X,objectPosition.Y).PrimCounts.Total;
99 LandData landData = scene.LandChannel.GetLandObject(objectPosition.X,objectPosition.Y).LandData;
100 int simulatorCapacity = (int)(((float)landData.SimwideArea / 65536.0f) *
101 (float)scene.RegionInfo.ObjectCapacity * (float)scene.RegionInfo.RegionSettings.ObjectBonus);
102
103 if(objectCount + usedPrims > simulatorCapacity)
104 {
105 m_dialogModule.SendAlertToUser(owner, "Unable to rez object because the parcel is too full");
106 return false;
107 }
108
109 return true;
110 }
111 //OnMoveObject
112 private bool CanObjectEnter(UUID objectID, bool enteringRegion, Vector3 newPoint, Scene scene)
113 {
114 SceneObjectPart obj = scene.GetSceneObjectPart(objectID);
115 Vector3 oldPoint = obj.GroupPosition;
116 int objectCount = obj.ParentGroup.PrimCount;
117 ILandObject oldParcel = scene.LandChannel.GetLandObject(oldPoint.X, oldPoint.Y);
118 ILandObject newParcel = scene.LandChannel.GetLandObject(newPoint.X, newPoint.Y);
119
120 int usedPrims=newParcel.PrimCounts.Total;
121 LandData landData = newParcel.LandData;
122 int simulatorCapacity = (int)(((float)landData.SimwideArea / 65536.0f) *
123 (float)scene.RegionInfo.ObjectCapacity * (float)scene.RegionInfo.RegionSettings.ObjectBonus);
124
125 // The prim hasn't crossed a region boundry so we don't need to worry
126 // about prim counts here
127 if(oldParcel.Equals(newParcel))
128 {
129 return true;
130 }
131 // Prim counts are determined by the location of the root prim. if we're
132 // moving a child prim, just let it pass
133 if(!obj.IsRoot)
134 {
135 return true;
136 }
137 // Add Special Case here for temporary prims
138
139 if(objectCount + usedPrims > simulatorCapacity)
140 {
141 m_dialogModule.SendAlertToUser(obj.OwnerID, "Unable to move object because the destination parcel is too full");
142 return false;
143 }
144 return true;
145 }
146 //OnDuplicateObject
147 private bool CanDuplicateObject(int objectCount, UUID objectID, UUID owner, Scene scene, Vector3 objectPosition)
148 {
149 // This may be a little long winded and can probably be optomized
150 int usedPrims = scene.LandChannel.GetLandObject(objectPosition.X,objectPosition.Y).PrimCounts.Total;
151 LandData landData = scene.LandChannel.GetLandObject(objectPosition.X,objectPosition.Y).LandData;
152 int simulatorCapacity = (int)(((float)landData.SimwideArea / 65536.0f) *
153 (float)scene.RegionInfo.ObjectCapacity * (float)scene.RegionInfo.RegionSettings.ObjectBonus);
154
155 if(objectCount + usedPrims > simulatorCapacity)
156 {
157 m_dialogModule.SendAlertToUser(owner, "Unable to duplicate object because the parcel is too full");
158 return false;
159 }
160 return true;
161 }
162 }
163} \ No newline at end of file