diff options
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Region/Framework/Scenes/GodController.cs | 231 |
1 files changed, 231 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..a3d0344 --- /dev/null +++ b/OpenSim/Region/Framework/Scenes/GodController.cs | |||
@@ -0,0 +1,231 @@ | |||
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 | ScenePresence m_scenePresence; | ||
51 | Scene m_scene; | ||
52 | protected bool m_allowGridGods; | ||
53 | protected bool m_regionOwnerIsGod; | ||
54 | protected bool m_regionManagerIsGod; | ||
55 | protected bool m_parcelOwnerIsGod; | ||
56 | protected bool m_forceGodModeAlwaysOn; | ||
57 | protected bool m_allowGodActionsWithoutGodMode; | ||
58 | |||
59 | protected bool m_viewerUiIsGod = false; | ||
60 | |||
61 | protected int m_userLevel = 0; | ||
62 | |||
63 | public GodController(Scene scene, ScenePresence sp) | ||
64 | { | ||
65 | m_scene = scene; | ||
66 | m_scenePresence = sp; | ||
67 | |||
68 | IConfigSource config = scene.Config; | ||
69 | |||
70 | string[] sections = new string[] { "Startup", "Permissions" }; | ||
71 | |||
72 | // God level is based on UserLevel. Gods will have that | ||
73 | // level grid-wide. Others may become god locally but grid | ||
74 | // gods are god everywhere. | ||
75 | m_allowGridGods = | ||
76 | Util.GetConfigVarFromSections<bool>(config, | ||
77 | "allow_grid_gods", sections, false); | ||
78 | |||
79 | // The owner of a region is a god in his region only. | ||
80 | m_regionOwnerIsGod = | ||
81 | Util.GetConfigVarFromSections<bool>(config, | ||
82 | "region_owner_is_god", sections, true); | ||
83 | |||
84 | // Region managers are gods in the regions they manage. | ||
85 | m_regionManagerIsGod = | ||
86 | Util.GetConfigVarFromSections<bool>(config, | ||
87 | "region_manager_is_god", sections, false); | ||
88 | |||
89 | // Parcel owners are gods in their own parcels only. | ||
90 | m_parcelOwnerIsGod = | ||
91 | Util.GetConfigVarFromSections<bool>(config, | ||
92 | "parcel_owner_is_god", sections, false); | ||
93 | |||
94 | // God mode should be turned on in the viewer whenever | ||
95 | // the user has god rights somewhere. They may choose | ||
96 | // to turn it off again, though. | ||
97 | m_forceGodModeAlwaysOn = | ||
98 | Util.GetConfigVarFromSections<bool>(config, | ||
99 | "automatic_gods", sections, false); | ||
100 | |||
101 | // The user can execute any and all god functions, as | ||
102 | // permitted by the viewer UI, without actually "godding | ||
103 | // up". This is the default state in 0.8.2. | ||
104 | m_allowGodActionsWithoutGodMode = | ||
105 | Util.GetConfigVarFromSections<bool>(config, | ||
106 | "implicit_gods", sections, false); | ||
107 | |||
108 | } | ||
109 | |||
110 | protected bool CanBeGod() | ||
111 | { | ||
112 | bool canBeGod = false; | ||
113 | |||
114 | if (m_allowGridGods && m_userLevel > 0) | ||
115 | canBeGod = true; | ||
116 | |||
117 | if (m_regionOwnerIsGod && m_scene.RegionInfo.EstateSettings.IsEstateOwner(m_scenePresence.UUID)) | ||
118 | canBeGod = true; | ||
119 | |||
120 | if (m_regionManagerIsGod && m_scene.Permissions.IsEstateManager(m_scenePresence.UUID)) | ||
121 | canBeGod = true; | ||
122 | |||
123 | if (!canBeGod && m_parcelOwnerIsGod) // Skip expensive check if we're already god! | ||
124 | { | ||
125 | Vector3 pos = m_scenePresence.AbsolutePosition; | ||
126 | ILandObject parcel = m_scene.LandChannel.GetLandObject(pos.X, pos.Y); | ||
127 | if (parcel != null && parcel.LandData.OwnerID == m_scenePresence.UUID) | ||
128 | canBeGod = true; | ||
129 | } | ||
130 | |||
131 | return canBeGod; | ||
132 | } | ||
133 | |||
134 | protected void SyncViewerState() | ||
135 | { | ||
136 | bool canBeGod = CanBeGod(); | ||
137 | |||
138 | bool shoudBeGod = m_forceGodModeAlwaysOn ? canBeGod : (m_viewerUiIsGod && canBeGod); | ||
139 | |||
140 | int godLevel = m_allowGridGods ? m_userLevel : 200; | ||
141 | if (!shoudBeGod) | ||
142 | godLevel = 0; | ||
143 | |||
144 | if (m_viewerUiIsGod != shoudBeGod) | ||
145 | { | ||
146 | m_scenePresence.ControllingClient.SendAdminResponse(UUID.Zero, (uint)godLevel); | ||
147 | m_viewerUiIsGod = shoudBeGod; | ||
148 | } | ||
149 | } | ||
150 | |||
151 | public bool RequestGodMode(bool god) | ||
152 | { | ||
153 | if (!god) | ||
154 | { | ||
155 | if (m_viewerUiIsGod) | ||
156 | m_scenePresence.ControllingClient.SendAdminResponse(UUID.Zero, 0); | ||
157 | |||
158 | m_viewerUiIsGod = false; | ||
159 | |||
160 | return true; | ||
161 | } | ||
162 | |||
163 | if (!CanBeGod()) | ||
164 | return false; | ||
165 | |||
166 | int godLevel = m_allowGridGods ? m_userLevel : 200; | ||
167 | |||
168 | if (!m_viewerUiIsGod) | ||
169 | m_scenePresence.ControllingClient.SendAdminResponse(UUID.Zero, (uint)godLevel); | ||
170 | |||
171 | m_viewerUiIsGod = true; | ||
172 | |||
173 | return true; | ||
174 | } | ||
175 | |||
176 | public OSD State() | ||
177 | { | ||
178 | OSDMap godMap = new OSDMap(2); | ||
179 | |||
180 | godMap.Add("ViewerUiIsGod", OSD.FromBoolean(m_viewerUiIsGod)); | ||
181 | godMap.Add("UserLevel", OSD.FromInteger(m_userLevel)); | ||
182 | |||
183 | return godMap; | ||
184 | } | ||
185 | |||
186 | public void SetState(OSD state) | ||
187 | { | ||
188 | OSDMap s = (OSDMap)state; | ||
189 | |||
190 | if (s.ContainsKey("ViewerUiIsGod")) | ||
191 | m_viewerUiIsGod = s["ViewerUiIsGod"].AsBoolean(); | ||
192 | |||
193 | if (s.ContainsKey("UserLevel")) | ||
194 | m_userLevel = s["UserLevel"].AsInteger(); | ||
195 | |||
196 | SyncViewerState(); | ||
197 | } | ||
198 | |||
199 | public int UserLevel | ||
200 | { | ||
201 | get { return m_userLevel; } | ||
202 | } | ||
203 | |||
204 | public int GodLevel | ||
205 | { | ||
206 | get | ||
207 | { | ||
208 | int godLevel = m_allowGridGods ? m_userLevel : 200; | ||
209 | if (!m_viewerUiIsGod) | ||
210 | godLevel = 0; | ||
211 | |||
212 | return godLevel; | ||
213 | } | ||
214 | } | ||
215 | |||
216 | public int EffectiveLevel | ||
217 | { | ||
218 | get | ||
219 | { | ||
220 | int godLevel = m_allowGridGods ? m_userLevel : 200; | ||
221 | if (m_viewerUiIsGod) | ||
222 | return godLevel; | ||
223 | |||
224 | if (m_allowGodActionsWithoutGodMode && CanBeGod()) | ||
225 | return godLevel; | ||
226 | |||
227 | return 0; | ||
228 | } | ||
229 | } | ||
230 | } | ||
231 | } | ||