diff options
Diffstat (limited to 'OpenSim/Region/Framework/Scenes/GodController.cs')
-rw-r--r-- | OpenSim/Region/Framework/Scenes/GodController.cs | 287 |
1 files changed, 287 insertions, 0 deletions
diff --git a/OpenSim/Region/Framework/Scenes/GodController.cs b/OpenSim/Region/Framework/Scenes/GodController.cs new file mode 100644 index 0000000..9372366 --- /dev/null +++ b/OpenSim/Region/Framework/Scenes/GodController.cs | |||
@@ -0,0 +1,287 @@ | |||
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.Xml; | ||
30 | using System.Collections.Generic; | ||
31 | using System.Reflection; | ||
32 | using System.Threading; | ||
33 | using System.Timers; | ||
34 | using Timer = System.Timers.Timer; | ||
35 | using OpenMetaverse; | ||
36 | using OpenMetaverse.StructuredData; | ||
37 | using log4net; | ||
38 | using Nini.Config; | ||
39 | using OpenSim.Framework; | ||
40 | using OpenSim.Framework.Client; | ||
41 | using OpenSim.Framework.Monitoring; | ||
42 | using OpenSim.Region.Framework.Interfaces; | ||
43 | using OpenSim.Region.Framework.Scenes.Types; | ||
44 | using OpenSim.Services.Interfaces; | ||
45 | |||
46 | namespace OpenSim.Region.Framework.Scenes | ||
47 | { | ||
48 | public class GodController | ||
49 | { | ||
50 | public enum ImplicitGodLevels : int | ||
51 | { | ||
52 | EstateManager = 210, // estate manager implicit god level | ||
53 | RegionOwner = 220 // region owner implicit god level should be >= than estate | ||
54 | } | ||
55 | |||
56 | ScenePresence m_scenePresence; | ||
57 | Scene m_scene; | ||
58 | protected bool m_allowGridGods; | ||
59 | protected bool m_forceGridGodsOnly; | ||
60 | protected bool m_regionOwnerIsGod; | ||
61 | protected bool m_regionManagerIsGod; | ||
62 | protected bool m_forceGodModeAlwaysOn; | ||
63 | protected bool m_allowGodActionsWithoutGodMode; | ||
64 | |||
65 | protected int m_userLevel = 0; | ||
66 | // the god level from local or grid user rights | ||
67 | protected int m_rightsGodLevel = 0; | ||
68 | // the level seen by viewers | ||
69 | protected int m_viewergodlevel = 0; | ||
70 | // new level that can be fixed or equal to godlevel, acording to options | ||
71 | protected int m_godlevel = 0; | ||
72 | protected int m_lastLevelToViewer = 0; | ||
73 | |||
74 | public GodController(Scene scene, ScenePresence sp, int userlevel) | ||
75 | { | ||
76 | m_scene = scene; | ||
77 | m_scenePresence = sp; | ||
78 | m_userLevel = userlevel; | ||
79 | |||
80 | IConfigSource config = scene.Config; | ||
81 | |||
82 | string[] sections = new string[] { "Startup", "Permissions" }; | ||
83 | |||
84 | // God level is based on UserLevel. Gods will have that | ||
85 | // level grid-wide. Others may become god locally but grid | ||
86 | // gods are god everywhere. | ||
87 | m_allowGridGods = | ||
88 | Util.GetConfigVarFromSections<bool>(config, | ||
89 | "allow_grid_gods", sections, false); | ||
90 | |||
91 | // If grid gods are active, dont allow any other gods | ||
92 | m_forceGridGodsOnly = | ||
93 | Util.GetConfigVarFromSections<bool>(config, | ||
94 | "force_grid_gods_only", sections, false); | ||
95 | |||
96 | if(!m_forceGridGodsOnly) | ||
97 | { | ||
98 | // The owner of a region is a god in his region only. | ||
99 | m_regionOwnerIsGod = | ||
100 | Util.GetConfigVarFromSections<bool>(config, | ||
101 | "region_owner_is_god", sections, true); | ||
102 | |||
103 | // Region managers are gods in the regions they manage. | ||
104 | m_regionManagerIsGod = | ||
105 | Util.GetConfigVarFromSections<bool>(config, | ||
106 | "region_manager_is_god", sections, false); | ||
107 | |||
108 | } | ||
109 | else | ||
110 | m_allowGridGods = true; // reduce potencial user mistakes | ||
111 | |||
112 | // God mode should be turned on in the viewer whenever | ||
113 | // the user has god rights somewhere. They may choose | ||
114 | // to turn it off again, though. | ||
115 | m_forceGodModeAlwaysOn = | ||
116 | Util.GetConfigVarFromSections<bool>(config, | ||
117 | "automatic_gods", sections, false); | ||
118 | |||
119 | // The user can execute any and all god functions, as | ||
120 | // permitted by the viewer UI, without actually "godding | ||
121 | // up". This is the default state in 0.8.2. | ||
122 | m_allowGodActionsWithoutGodMode = | ||
123 | Util.GetConfigVarFromSections<bool>(config, | ||
124 | "implicit_gods", sections, false); | ||
125 | |||
126 | m_rightsGodLevel = CalcRightsGodLevel(); | ||
127 | |||
128 | if(m_allowGodActionsWithoutGodMode) | ||
129 | { | ||
130 | m_godlevel = m_rightsGodLevel; | ||
131 | m_forceGodModeAlwaysOn = false; | ||
132 | } | ||
133 | |||
134 | else if(m_forceGodModeAlwaysOn) | ||
135 | { | ||
136 | m_viewergodlevel = m_rightsGodLevel; | ||
137 | m_godlevel = m_rightsGodLevel; | ||
138 | } | ||
139 | |||
140 | m_scenePresence.IsGod = (m_godlevel >= 200); | ||
141 | m_scenePresence.IsViewerUIGod = (m_viewergodlevel >= 200); | ||
142 | } | ||
143 | |||
144 | // calculates god level at sp creation from local and grid user god rights | ||
145 | // for now this is assumed static until user leaves region. | ||
146 | // later estate and gride level updates may update this | ||
147 | protected int CalcRightsGodLevel() | ||
148 | { | ||
149 | int level = 0; | ||
150 | if (m_allowGridGods && m_userLevel >= 200) | ||
151 | level = m_userLevel; | ||
152 | |||
153 | if(m_forceGridGodsOnly || level >= (int)ImplicitGodLevels.RegionOwner) | ||
154 | return level; | ||
155 | |||
156 | if (m_regionOwnerIsGod && m_scene.RegionInfo.EstateSettings.IsEstateOwner(m_scenePresence.UUID)) | ||
157 | level = (int)ImplicitGodLevels.RegionOwner; | ||
158 | |||
159 | if(level >= (int)ImplicitGodLevels.EstateManager) | ||
160 | return level; | ||
161 | |||
162 | if (m_regionManagerIsGod && m_scene.Permissions.IsEstateManager(m_scenePresence.UUID)) | ||
163 | level = (int)ImplicitGodLevels.EstateManager; | ||
164 | |||
165 | return level; | ||
166 | } | ||
167 | |||
168 | protected bool CanBeGod() | ||
169 | { | ||
170 | return m_rightsGodLevel >= 200; | ||
171 | } | ||
172 | |||
173 | protected void UpdateGodLevels(bool viewerState) | ||
174 | { | ||
175 | if(!CanBeGod()) | ||
176 | { | ||
177 | m_viewergodlevel = 0; | ||
178 | m_godlevel = 0; | ||
179 | m_scenePresence.IsGod = false; | ||
180 | m_scenePresence.IsViewerUIGod = false; | ||
181 | return; | ||
182 | } | ||
183 | |||
184 | // legacy some are controled by viewer, others are static | ||
185 | if(m_allowGodActionsWithoutGodMode) | ||
186 | { | ||
187 | if(viewerState) | ||
188 | m_viewergodlevel = m_rightsGodLevel; | ||
189 | else | ||
190 | m_viewergodlevel = 0; | ||
191 | |||
192 | m_godlevel = m_rightsGodLevel; | ||
193 | } | ||
194 | else | ||
195 | { | ||
196 | // new all change with viewer | ||
197 | if(viewerState) | ||
198 | { | ||
199 | m_viewergodlevel = m_rightsGodLevel; | ||
200 | m_godlevel = m_rightsGodLevel; | ||
201 | } | ||
202 | else | ||
203 | { | ||
204 | m_viewergodlevel = 0; | ||
205 | m_godlevel = 0; | ||
206 | } | ||
207 | } | ||
208 | m_scenePresence.IsGod = (m_godlevel >= 200); | ||
209 | m_scenePresence.IsViewerUIGod = (m_viewergodlevel >= 200); | ||
210 | } | ||
211 | |||
212 | public void SyncViewerState() | ||
213 | { | ||
214 | if(m_lastLevelToViewer == m_viewergodlevel) | ||
215 | return; | ||
216 | |||
217 | m_lastLevelToViewer = m_viewergodlevel; | ||
218 | |||
219 | if(m_scenePresence.IsChildAgent) | ||
220 | return; | ||
221 | |||
222 | m_scenePresence.ControllingClient.SendAdminResponse(UUID.Zero, (uint)m_viewergodlevel); | ||
223 | } | ||
224 | |||
225 | public void RequestGodMode(bool god) | ||
226 | { | ||
227 | UpdateGodLevels(god); | ||
228 | |||
229 | if(m_lastLevelToViewer != m_viewergodlevel) | ||
230 | { | ||
231 | m_scenePresence.ControllingClient.SendAdminResponse(UUID.Zero, (uint)m_viewergodlevel); | ||
232 | m_lastLevelToViewer = m_viewergodlevel; | ||
233 | } | ||
234 | } | ||
235 | |||
236 | public OSD State() | ||
237 | { | ||
238 | OSDMap godMap = new OSDMap(2); | ||
239 | bool m_viewerUiIsGod = m_viewergodlevel >= 200; | ||
240 | godMap.Add("ViewerUiIsGod", OSD.FromBoolean(m_viewerUiIsGod)); | ||
241 | |||
242 | return godMap; | ||
243 | } | ||
244 | |||
245 | public void SetState(OSD state) | ||
246 | { | ||
247 | bool newstate = false; | ||
248 | if(m_forceGodModeAlwaysOn) | ||
249 | newstate = m_viewergodlevel >= 200; | ||
250 | if(state != null) | ||
251 | { | ||
252 | OSDMap s = (OSDMap)state; | ||
253 | |||
254 | if (s.ContainsKey("ViewerUiIsGod")) | ||
255 | newstate = s["ViewerUiIsGod"].AsBoolean(); | ||
256 | m_lastLevelToViewer = m_viewergodlevel; // we are not changing viewer level by default | ||
257 | } | ||
258 | UpdateGodLevels(newstate); | ||
259 | } | ||
260 | |||
261 | public void HasMovedAway() | ||
262 | { | ||
263 | m_lastLevelToViewer = 0; | ||
264 | if(m_forceGodModeAlwaysOn) | ||
265 | { | ||
266 | m_viewergodlevel = m_rightsGodLevel; | ||
267 | m_godlevel = m_rightsGodLevel; | ||
268 | } | ||
269 | } | ||
270 | |||
271 | public int UserLevel | ||
272 | { | ||
273 | get { return m_userLevel; } | ||
274 | set { m_userLevel = value; } | ||
275 | } | ||
276 | |||
277 | public int ViwerUIGodLevel | ||
278 | { | ||
279 | get { return m_viewergodlevel; } | ||
280 | } | ||
281 | |||
282 | public int GodLevel | ||
283 | { | ||
284 | get { return m_godlevel; } | ||
285 | } | ||
286 | } | ||
287 | } | ||