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.Collections; |
||
30 | using System.Collections.Generic; |
||
31 | using System.Collections.Specialized; |
||
32 | using System.IO; |
||
33 | using System.Reflection; |
||
34 | using System.Web; |
||
35 | using System.Xml; |
||
36 | using log4net; |
||
37 | using Mono.Addins; |
||
38 | using Nini.Config; |
||
39 | using OpenMetaverse; |
||
40 | using OpenMetaverse.Messages.Linden; |
||
41 | using OpenMetaverse.StructuredData; |
||
42 | using OpenSim.Framework; |
||
43 | using OpenSim.Framework.Capabilities; |
||
44 | using OpenSim.Framework.Servers; |
||
45 | using OpenSim.Framework.Servers.HttpServer; |
||
46 | using OpenSim.Region.Framework.Scenes; |
||
47 | using OpenSim.Region.Framework.Interfaces; |
||
48 | using Caps = OpenSim.Framework.Capabilities.Caps; |
||
49 | using OSDArray = OpenMetaverse.StructuredData.OSDArray; |
||
50 | using OSDMap = OpenMetaverse.StructuredData.OSDMap; |
||
51 | |||
52 | namespace OpenSim.Region.CoreModules.Avatar.Gods |
||
53 | { |
||
54 | [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "GodsModule")] |
||
55 | public class GodsModule : INonSharedRegionModule, IGodsModule |
||
56 | { |
||
57 | private static readonly ILog m_log = |
||
58 | LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
||
59 | |||
60 | /// <summary>Special UUID for actions that apply to all agents</summary> |
||
61 | private static readonly UUID ALL_AGENTS = new UUID("44e87126-e794-4ded-05b3-7c42da3d5cdb"); |
||
62 | |||
63 | protected Scene m_scene; |
||
64 | protected IDialogModule m_dialogModule; |
||
65 | protected IDialogModule DialogModule |
||
66 | { |
||
67 | get |
||
68 | { |
||
69 | if (m_dialogModule == null) |
||
70 | m_dialogModule = m_scene.RequestModuleInterface<IDialogModule>(); |
||
71 | |||
72 | return m_dialogModule; |
||
73 | } |
||
74 | } |
||
75 | |||
76 | public void Initialise(IConfigSource source) |
||
77 | { |
||
78 | } |
||
79 | |||
80 | public void AddRegion(Scene scene) |
||
81 | { |
||
82 | m_scene = scene; |
||
83 | m_scene.RegisterModuleInterface<IGodsModule>(this); |
||
84 | m_scene.EventManager.OnNewClient += SubscribeToClientEvents; |
||
85 | m_scene.EventManager.OnRegisterCaps += OnRegisterCaps; |
||
86 | scene.EventManager.OnIncomingInstantMessage += |
||
87 | OnIncomingInstantMessage; |
||
88 | } |
||
89 | |||
90 | public void RemoveRegion(Scene scene) |
||
91 | { |
||
92 | m_scene.UnregisterModuleInterface<IGodsModule>(this); |
||
93 | m_scene.EventManager.OnNewClient -= SubscribeToClientEvents; |
||
94 | m_scene = null; |
||
95 | } |
||
96 | |||
97 | public void RegionLoaded(Scene scene) |
||
98 | { |
||
99 | } |
||
100 | |||
101 | public void Close() {} |
||
102 | public string Name { get { return "Gods Module"; } } |
||
103 | |||
104 | public Type ReplaceableInterface |
||
105 | { |
||
106 | get { return null; } |
||
107 | } |
||
108 | |||
109 | public void SubscribeToClientEvents(IClientAPI client) |
||
110 | { |
||
111 | client.OnGodKickUser += KickUser; |
||
112 | client.OnRequestGodlikePowers += RequestGodlikePowers; |
||
113 | } |
||
114 | |||
115 | public void UnsubscribeFromClientEvents(IClientAPI client) |
||
116 | { |
||
117 | client.OnGodKickUser -= KickUser; |
||
118 | client.OnRequestGodlikePowers -= RequestGodlikePowers; |
||
119 | } |
||
120 | |||
121 | private void OnRegisterCaps(UUID agentID, Caps caps) |
||
122 | { |
||
123 | string uri = "/CAPS/" + UUID.Random(); |
||
124 | |||
125 | caps.RegisterHandler( |
||
126 | "UntrustedSimulatorMessage", |
||
127 | new RestStreamHandler("POST", uri, HandleUntrustedSimulatorMessage, "UntrustedSimulatorMessage", null)); |
||
128 | } |
||
129 | |||
130 | private string HandleUntrustedSimulatorMessage(string request, |
||
131 | string path, string param, IOSHttpRequest httpRequest, |
||
132 | IOSHttpResponse httpResponse) |
||
133 | { |
||
134 | OSDMap osd = (OSDMap)OSDParser.DeserializeLLSDXml(request); |
||
135 | |||
136 | string message = osd["message"].AsString(); |
||
137 | |||
138 | if (message == "GodKickUser") |
||
139 | { |
||
140 | OSDMap body = (OSDMap)osd["body"]; |
||
141 | OSDArray userInfo = (OSDArray)body["UserInfo"]; |
||
142 | OSDMap userData = (OSDMap)userInfo[0]; |
||
143 | |||
144 | UUID agentID = userData["AgentID"].AsUUID(); |
||
145 | UUID godID = userData["GodID"].AsUUID(); |
||
146 | UUID godSessionID = userData["GodSessionID"].AsUUID(); |
||
147 | uint kickFlags = userData["KickFlags"].AsUInteger(); |
||
148 | string reason = userData["Reason"].AsString(); |
||
149 | ScenePresence god = m_scene.GetScenePresence(godID); |
||
150 | if (god == null || god.ControllingClient.SessionId != godSessionID) |
||
151 | return String.Empty; |
||
152 | |||
153 | KickUser(godID, godSessionID, agentID, kickFlags, Util.StringToBytes1024(reason)); |
||
154 | } |
||
155 | else |
||
156 | { |
||
157 | m_log.ErrorFormat("[GOD]: Unhandled UntrustedSimulatorMessage: {0}", message); |
||
158 | } |
||
159 | return String.Empty; |
||
160 | } |
||
161 | |||
162 | public void RequestGodlikePowers( |
||
163 | UUID agentID, UUID sessionID, UUID token, bool godLike, IClientAPI controllingClient) |
||
164 | { |
||
165 | ScenePresence sp = m_scene.GetScenePresence(agentID); |
||
166 | |||
167 | if (sp != null) |
||
168 | { |
||
169 | if (godLike == false) |
||
170 | { |
||
171 | sp.GrantGodlikePowers(agentID, sessionID, token, godLike); |
||
172 | return; |
||
173 | } |
||
174 | |||
175 | // First check that this is the sim owner |
||
176 | if (m_scene.Permissions.IsGod(agentID)) |
||
177 | { |
||
178 | // Next we check for spoofing..... |
||
179 | UUID testSessionID = sp.ControllingClient.SessionId; |
||
180 | if (sessionID == testSessionID) |
||
181 | { |
||
182 | if (sessionID == controllingClient.SessionId) |
||
183 | { |
||
184 | //m_log.Info("godlike: " + godLike.ToString()); |
||
185 | sp.GrantGodlikePowers(agentID, testSessionID, token, godLike); |
||
186 | } |
||
187 | } |
||
188 | } |
||
189 | else |
||
190 | { |
||
191 | if (DialogModule != null) |
||
192 | DialogModule.SendAlertToUser(agentID, "Request for god powers denied"); |
||
193 | } |
||
194 | } |
||
195 | } |
||
196 | |||
197 | /// <summary> |
||
198 | /// Kicks User specified from the simulator. This logs them off of the grid |
||
199 | /// If the client gets the UUID: 44e87126e7944ded05b37c42da3d5cdb it assumes |
||
200 | /// that you're kicking it even if the avatar's UUID isn't the UUID that the |
||
201 | /// agent is assigned |
||
202 | /// </summary> |
||
203 | /// <param name="godID">The person doing the kicking</param> |
||
204 | /// <param name="sessionID">The session of the person doing the kicking</param> |
||
205 | /// <param name="agentID">the person that is being kicked</param> |
||
206 | /// <param name="kickflags">Tells what to do to the user</param> |
||
207 | /// <param name="reason">The message to send to the user after it's been turned into a field</param> |
||
208 | public void KickUser(UUID godID, UUID sessionID, UUID agentID, uint kickflags, byte[] reason) |
||
209 | { |
||
210 | if (!m_scene.Permissions.IsGod(godID)) |
||
211 | return; |
||
212 | |||
213 | ScenePresence sp = m_scene.GetScenePresence(agentID); |
||
214 | |||
215 | if (sp == null && agentID != ALL_AGENTS) |
||
216 | { |
||
217 | IMessageTransferModule transferModule = |
||
218 | m_scene.RequestModuleInterface<IMessageTransferModule>(); |
||
219 | if (transferModule != null) |
||
220 | { |
||
221 | m_log.DebugFormat("[GODS]: Sending nonlocal kill for agent {0}", agentID); |
||
222 | transferModule.SendInstantMessage(new GridInstantMessage( |
||
223 | m_scene, godID, "God", agentID, (byte)250, false, |
||
224 | Utils.BytesToString(reason), UUID.Zero, true, |
||
225 | new Vector3(), new byte[] {(byte)kickflags}, true), |
||
226 | delegate(bool success) {} ); |
||
227 | } |
||
228 | return; |
||
229 | } |
||
230 | |||
231 | switch (kickflags) |
||
232 | { |
||
233 | case 0: |
||
234 | if (sp != null) |
||
235 | { |
||
236 | KickPresence(sp, Utils.BytesToString(reason)); |
||
237 | } |
||
238 | else if (agentID == ALL_AGENTS) |
||
239 | { |
||
240 | m_scene.ForEachRootScenePresence( |
||
241 | delegate(ScenePresence p) |
||
242 | { |
||
243 | if (p.UUID != godID && (!m_scene.Permissions.IsGod(p.UUID))) |
||
244 | KickPresence(p, Utils.BytesToString(reason)); |
||
245 | } |
||
246 | ); |
||
247 | } |
||
248 | break; |
||
249 | case 1: |
||
250 | if (sp != null) |
||
251 | { |
||
252 | sp.AllowMovement = false; |
||
253 | m_dialogModule.SendAlertToUser(agentID, Utils.BytesToString(reason)); |
||
254 | m_dialogModule.SendAlertToUser(godID, "User Frozen"); |
||
255 | } |
||
256 | break; |
||
257 | case 2: |
||
258 | if (sp != null) |
||
259 | { |
||
260 | sp.AllowMovement = true; |
||
261 | m_dialogModule.SendAlertToUser(agentID, Utils.BytesToString(reason)); |
||
262 | m_dialogModule.SendAlertToUser(godID, "User Unfrozen"); |
||
263 | } |
||
264 | break; |
||
265 | default: |
||
266 | break; |
||
267 | } |
||
268 | } |
||
269 | |||
270 | private void KickPresence(ScenePresence sp, string reason) |
||
271 | { |
||
272 | if (sp.IsChildAgent) |
||
273 | return; |
||
274 | sp.ControllingClient.Kick(reason); |
||
275 | sp.Scene.CloseAgent(sp.UUID, true); |
||
276 | } |
||
277 | |||
278 | private void OnIncomingInstantMessage(GridInstantMessage msg) |
||
279 | { |
||
280 | if (msg.dialog == (uint)250) // Nonlocal kick |
||
281 | { |
||
282 | UUID agentID = new UUID(msg.toAgentID); |
||
283 | string reason = msg.message; |
||
284 | UUID godID = new UUID(msg.fromAgentID); |
||
285 | uint kickMode = (uint)msg.binaryBucket[0]; |
||
286 | |||
287 | KickUser(godID, UUID.Zero, agentID, kickMode, Util.StringToBytes1024(reason)); |
||
288 | } |
||
289 | } |
||
290 | } |
||
291 | } |