aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/OptionalModules/PrimLimitsModule/PrimLimitsModule.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/OptionalModules/PrimLimitsModule/PrimLimitsModule.cs')
-rw-r--r--OpenSim/Region/OptionalModules/PrimLimitsModule/PrimLimitsModule.cs213
1 files changed, 213 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..395bbf1
--- /dev/null
+++ b/OpenSim/Region/OptionalModules/PrimLimitsModule/PrimLimitsModule.cs
@@ -0,0 +1,213 @@
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.Collections.Generic;
30using System.Linq;
31using System.Reflection;
32using log4net;
33using Mono.Addins;
34using Nini.Config;
35using OpenMetaverse;
36using OpenSim.Framework;
37using OpenSim.Region.Framework.Interfaces;
38using OpenSim.Region.Framework.Scenes;
39
40namespace OpenSim.Region.OptionalModules
41{
42 /// <summary>
43 /// Enables Prim limits for parcel.
44 /// </summary>
45 /// <remarks>
46 /// This module selectivly enables parcel prim limits.
47 /// </remarks>
48 [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "PrimLimitsModule")]
49 public class PrimLimitsModule : INonSharedRegionModule
50 {
51 protected IDialogModule m_dialogModule;
52 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
53 private bool m_enabled;
54
55 public string Name { get { return "PrimLimitsModule"; } }
56
57 public Type ReplaceableInterface { get { return null; } }
58
59 public void Initialise(IConfigSource config)
60 {
61 string permissionModules = Util.GetConfigVarFromSections<string>(config, "permissionmodules",
62 new string[] { "Startup", "Permissions" }, "DefaultPermissionsModule");
63
64 List<string> modules = new List<string>(permissionModules.Split(',').Select(m => m.Trim()));
65
66 if(!modules.Contains("PrimLimitsModule"))
67 return;
68
69 m_log.DebugFormat("[PRIM LIMITS]: Initialized module");
70 m_enabled = true;
71 }
72
73 public void Close()
74 {
75 }
76
77 public void AddRegion(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 m_log.DebugFormat("[PRIM LIMITS]: Region {0} added", scene.RegionInfo.RegionName);
88 }
89
90 public void RemoveRegion(Scene scene)
91 {
92 if (m_enabled)
93 {
94 return;
95 }
96
97 scene.Permissions.OnRezObject -= CanRezObject;
98 scene.Permissions.OnObjectEntry -= CanObjectEnter;
99 scene.Permissions.OnDuplicateObject -= CanDuplicateObject;
100 }
101
102 public void RegionLoaded(Scene scene)
103 {
104 m_dialogModule = scene.RequestModuleInterface<IDialogModule>();
105 }
106
107 private bool CanRezObject(int objectCount, UUID ownerID, Vector3 objectPosition, Scene scene)
108 {
109 ILandObject lo = scene.LandChannel.GetLandObject(objectPosition.X, objectPosition.Y);
110
111 string response = DoCommonChecks(objectCount, ownerID, lo, scene);
112
113 if (response != null)
114 {
115 m_dialogModule.SendAlertToUser(ownerID, response);
116 return false;
117 }
118 return true;
119 }
120
121 //OnDuplicateObject
122 private bool CanDuplicateObject(int objectCount, UUID objectID, UUID ownerID, Scene scene, Vector3 objectPosition)
123 {
124 ILandObject lo = scene.LandChannel.GetLandObject(objectPosition.X, objectPosition.Y);
125
126 string response = DoCommonChecks(objectCount, ownerID, lo, scene);
127
128 if (response != null)
129 {
130 m_dialogModule.SendAlertToUser(ownerID, response);
131 return false;
132 }
133 return true;
134 }
135
136 private bool CanObjectEnter(UUID objectID, bool enteringRegion, Vector3 newPoint, Scene scene)
137 {
138 SceneObjectPart obj = scene.GetSceneObjectPart(objectID);
139 Vector3 oldPoint = obj.GroupPosition;
140 int objectCount = obj.ParentGroup.PrimCount;
141 ILandObject oldParcel = scene.LandChannel.GetLandObject(oldPoint.X, oldPoint.Y);
142 ILandObject newParcel = scene.LandChannel.GetLandObject(newPoint.X, newPoint.Y);
143
144 // newParcel will be null only if it outside of our current region. If this is the case, then the
145 // receiving permissions will perform the check.
146 if (newParcel == null)
147 return true;
148
149 // The prim hasn't crossed a region boundary so we don't need to worry
150 // about prim counts here
151 if(oldParcel.Equals(newParcel))
152 {
153 return true;
154 }
155
156 // Prim counts are determined by the location of the root prim. if we're
157 // moving a child prim, just let it pass
158 if(!obj.IsRoot)
159 {
160 return true;
161 }
162
163 // TODO: Add Special Case here for temporary prims
164
165 string response = DoCommonChecks(objectCount, obj.OwnerID, newParcel, scene);
166
167 if (response != null)
168 {
169 m_dialogModule.SendAlertToUser(obj.OwnerID, response);
170 return false;
171 }
172 return true;
173 }
174
175 private string DoCommonChecks(int objectCount, UUID ownerID, ILandObject lo, Scene scene)
176 {
177 string response = null;
178
179 int simulatorCapacity = lo.GetSimulatorMaxPrimCount();
180 if ((objectCount + lo.PrimCounts.Total) > simulatorCapacity)
181 {
182 response = "Unable to rez object because the parcel is too full";
183 }
184 else
185 {
186 int maxPrimsPerUser = scene.RegionInfo.MaxPrimsPerUser;
187 if (maxPrimsPerUser >= 0)
188 {
189 // per-user prim limit is set
190 if (ownerID != lo.LandData.OwnerID || lo.LandData.IsGroupOwned)
191 {
192 // caller is not the sole Parcel owner
193 EstateSettings estateSettings = scene.RegionInfo.EstateSettings;
194 if (ownerID != estateSettings.EstateOwner)
195 {
196 // caller is NOT the Estate owner
197 List<UUID> mgrs = new List<UUID>(estateSettings.EstateManagers);
198 if (!mgrs.Contains(ownerID))
199 {
200 // caller is not an Estate Manager
201 if ((lo.PrimCounts.Users[ownerID] + objectCount) > maxPrimsPerUser)
202 {
203 response = "Unable to rez object because you have reached your limit";
204 }
205 }
206 }
207 }
208 }
209 }
210 return response;
211 }
212 }
213}