opensim – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | eva | 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 | |||
28 | using System; |
||
29 | using System.Reflection; |
||
30 | using System.Collections.Generic; |
||
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 | |||
39 | namespace OpenSim.Region.OptionalModules |
||
40 | { |
||
41 | /// <summary> |
||
42 | /// Enables Prim limits for parcel. |
||
43 | /// </summary> |
||
44 | /// <remarks> |
||
45 | /// This module selectivly enables parcel prim limits. |
||
46 | /// </remarks> |
||
47 | [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "PrimLimitsModule")] |
||
48 | public class PrimLimitsModule : INonSharedRegionModule |
||
49 | { |
||
50 | protected IDialogModule m_dialogModule; |
||
51 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
||
52 | private bool m_enabled; |
||
53 | |||
54 | public string Name { get { return "PrimLimitsModule"; } } |
||
55 | |||
56 | public Type ReplaceableInterface { get { return null; } } |
||
57 | |||
58 | public void Initialise(IConfigSource config) |
||
59 | { |
||
60 | //IConfig myConfig = config.Configs["Startup"]; |
||
61 | |||
62 | string permissionModules = Util.GetConfigVarFromSections<string>(config, "permissionmodules", |
||
63 | new string[] { "Startup", "Permissions" }, "DefaultPermissionsModule"); |
||
64 | |||
65 | List<string> modules=new List<string>(permissionModules.Split(',')); |
||
66 | |||
67 | if(!modules.Contains("PrimLimitsModule")) |
||
68 | return; |
||
69 | |||
70 | m_log.DebugFormat("[PRIM LIMITS]: Initialized module"); |
||
71 | m_enabled = true; |
||
72 | } |
||
73 | |||
74 | public void Close() |
||
75 | { |
||
76 | } |
||
77 | |||
78 | public void AddRegion(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 | m_log.DebugFormat("[PRIM LIMITS]: Region {0} added", scene.RegionInfo.RegionName); |
||
89 | } |
||
90 | |||
91 | public void RemoveRegion(Scene scene) |
||
92 | { |
||
93 | if (m_enabled) |
||
94 | { |
||
95 | return; |
||
96 | } |
||
97 | |||
98 | scene.Permissions.OnRezObject -= CanRezObject; |
||
99 | scene.Permissions.OnObjectEntry -= CanObjectEnter; |
||
100 | scene.Permissions.OnDuplicateObject -= CanDuplicateObject; |
||
101 | } |
||
102 | |||
103 | public void RegionLoaded(Scene scene) |
||
104 | { |
||
105 | m_dialogModule = scene.RequestModuleInterface<IDialogModule>(); |
||
106 | } |
||
107 | |||
108 | private bool CanRezObject(int objectCount, UUID owner, Vector3 objectPosition, Scene scene) |
||
109 | { |
||
110 | ILandObject lo = scene.LandChannel.GetLandObject(objectPosition.X, objectPosition.Y); |
||
111 | int usedPrims = lo.PrimCounts.Total; |
||
112 | int simulatorCapacity = lo.GetSimulatorMaxPrimCount(); |
||
113 | |||
114 | if (objectCount + usedPrims > simulatorCapacity) |
||
115 | { |
||
116 | m_dialogModule.SendAlertToUser(owner, "Unable to rez object because the parcel is too full"); |
||
117 | return false; |
||
118 | } |
||
119 | |||
120 | return true; |
||
121 | } |
||
122 | |||
123 | private bool CanObjectEnter(UUID objectID, bool enteringRegion, Vector3 newPoint, Scene scene) |
||
124 | { |
||
125 | SceneObjectPart obj = scene.GetSceneObjectPart(objectID); |
||
126 | Vector3 oldPoint = obj.GroupPosition; |
||
127 | int objectCount = obj.ParentGroup.PrimCount; |
||
128 | ILandObject oldParcel = scene.LandChannel.GetLandObject(oldPoint.X, oldPoint.Y); |
||
129 | ILandObject newParcel = scene.LandChannel.GetLandObject(newPoint.X, newPoint.Y); |
||
130 | |||
131 | int usedPrims = newParcel.PrimCounts.Total; |
||
132 | int simulatorCapacity = newParcel.GetSimulatorMaxPrimCount(); |
||
133 | |||
134 | // The prim hasn't crossed a region boundry so we don't need to worry |
||
135 | // about prim counts here |
||
136 | if(oldParcel.Equals(newParcel)) |
||
137 | { |
||
138 | return true; |
||
139 | } |
||
140 | |||
141 | // Prim counts are determined by the location of the root prim. if we're |
||
142 | // moving a child prim, just let it pass |
||
143 | if(!obj.IsRoot) |
||
144 | { |
||
145 | return true; |
||
146 | } |
||
147 | |||
148 | // TODO: Add Special Case here for temporary prims |
||
149 | |||
150 | if(objectCount + usedPrims > simulatorCapacity) |
||
151 | { |
||
152 | m_dialogModule.SendAlertToUser(obj.OwnerID, "Unable to move object because the destination parcel is too full"); |
||
153 | return false; |
||
154 | } |
||
155 | |||
156 | return true; |
||
157 | } |
||
158 | |||
159 | //OnDuplicateObject |
||
160 | private bool CanDuplicateObject(int objectCount, UUID objectID, UUID owner, Scene scene, Vector3 objectPosition) |
||
161 | { |
||
162 | ILandObject lo = scene.LandChannel.GetLandObject(objectPosition.X, objectPosition.Y); |
||
163 | int usedPrims = lo.PrimCounts.Total; |
||
164 | int simulatorCapacity = lo.GetSimulatorMaxPrimCount(); |
||
165 | |||
166 | if(objectCount + usedPrims > simulatorCapacity) |
||
167 | { |
||
168 | m_dialogModule.SendAlertToUser(owner, "Unable to duplicate object because the parcel is too full"); |
||
169 | return false; |
||
170 | } |
||
171 | |||
172 | return true; |
||
173 | } |
||
174 | } |
||
175 | } |