OpenSim
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros
GodsModule.cs
Go to the documentation of this file.
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;
51 
52 namespace OpenSim.Region.CoreModules.Avatar.Gods
53 {
54  [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "GodsModule")]
56  {
57  private static readonly ILog m_log =
58  LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
59 
61  private static readonly UUID ALL_AGENTS = new UUID("44e87126-e794-4ded-05b3-7c42da3d5cdb");
62 
63  protected Scene m_scene;
65 
66  protected IDialogModule DialogModule
67  {
68  get
69  {
70  if (m_dialogModule == null)
71  m_dialogModule = m_scene.RequestModuleInterface<IDialogModule>();
72 
73  return m_dialogModule;
74  }
75  }
76 
77  public void Initialise(IConfigSource source)
78  {
79  }
80 
81  public void AddRegion(Scene scene)
82  {
83  m_scene = scene;
84  m_scene.RegisterModuleInterface<IGodsModule>(this);
85  m_scene.EventManager.OnNewClient += SubscribeToClientEvents;
86  m_scene.EventManager.OnRegisterCaps += OnRegisterCaps;
87  scene.EventManager.OnIncomingInstantMessage +=
88  OnIncomingInstantMessage;
89  }
90 
91  public void RemoveRegion(Scene scene)
92  {
93  m_scene.UnregisterModuleInterface<IGodsModule>(this);
94  m_scene.EventManager.OnNewClient -= SubscribeToClientEvents;
95  m_scene = null;
96  }
97 
98  public void RegionLoaded(Scene scene)
99  {
100  }
101 
102  public void Close() {}
103  public string Name { get { return "Gods Module"; } }
104 
105  public Type ReplaceableInterface
106  {
107  get { return null; }
108  }
109 
111  {
112  client.OnGodKickUser += KickUser;
113  client.OnRequestGodlikePowers += RequestGodlikePowers;
114  }
115 
117  {
118  client.OnGodKickUser -= KickUser;
119  client.OnRequestGodlikePowers -= RequestGodlikePowers;
120  }
121 
122  private void OnRegisterCaps(UUID agentID, Caps caps)
123  {
124  string uri = "/CAPS/" + UUID.Random();
125 
126  caps.RegisterHandler(
127  "UntrustedSimulatorMessage",
128  new RestStreamHandler("POST", uri, HandleUntrustedSimulatorMessage, "UntrustedSimulatorMessage", null));
129  }
130 
131  private string HandleUntrustedSimulatorMessage(string request,
132  string path, string param, IOSHttpRequest httpRequest,
133  IOSHttpResponse httpResponse)
134  {
135  OSDMap osd = (OSDMap)OSDParser.DeserializeLLSDXml(request);
136 
137  string message = osd["message"].AsString();
138 
139  if (message == "GodKickUser")
140  {
141  OSDMap body = (OSDMap)osd["body"];
142  OSDArray userInfo = (OSDArray)body["UserInfo"];
143  OSDMap userData = (OSDMap)userInfo[0];
144 
145  UUID agentID = userData["AgentID"].AsUUID();
146  UUID godID = userData["GodID"].AsUUID();
147  UUID godSessionID = userData["GodSessionID"].AsUUID();
148  uint kickFlags = userData["KickFlags"].AsUInteger();
149  string reason = userData["Reason"].AsString();
150 
151  ScenePresence god = m_scene.GetScenePresence(godID);
152  if (god == null || god.ControllingClient.SessionId != godSessionID)
153  return String.Empty;
154 
155  KickUser(godID, godSessionID, agentID, kickFlags, Util.StringToBytes1024(reason));
156  }
157  else
158  {
159  m_log.ErrorFormat("[GOD]: Unhandled UntrustedSimulatorMessage: {0}", message);
160  }
161  return String.Empty;
162  }
163 
164  public void RequestGodlikePowers(
165  UUID agentID, UUID sessionID, UUID token, bool godLike, IClientAPI controllingClient)
166  {
167  ScenePresence sp = m_scene.GetScenePresence(agentID);
168 
169  if (sp != null)
170  {
171  if (godLike == false)
172  {
173  sp.GrantGodlikePowers(agentID, sessionID, token, godLike);
174  return;
175  }
176 
177  // First check that this is the sim owner
178  if (m_scene.Permissions.IsGod(agentID))
179  {
180  // Next we check for spoofing.....
181  UUID testSessionID = sp.ControllingClient.SessionId;
182  if (sessionID == testSessionID)
183  {
184  if (sessionID == controllingClient.SessionId)
185  {
186  //m_log.Info("godlike: " + godLike.ToString());
187  sp.GrantGodlikePowers(agentID, testSessionID, token, godLike);
188  }
189  }
190  }
191  else
192  {
193  if (DialogModule != null)
194  DialogModule.SendAlertToUser(agentID, "Request for god powers denied");
195  }
196  }
197  }
198 
210  public void KickUser(UUID godID, UUID sessionID, UUID agentID, uint kickflags, byte[] reason)
211  {
212  if (!m_scene.Permissions.IsGod(godID))
213  return;
214 
215  ScenePresence sp = m_scene.GetScenePresence(agentID);
216 
217  if (sp == null && agentID != ALL_AGENTS)
218  {
219  IMessageTransferModule transferModule =
220  m_scene.RequestModuleInterface<IMessageTransferModule>();
221  if (transferModule != null)
222  {
223  m_log.DebugFormat("[GODS]: Sending nonlocal kill for agent {0}", agentID);
224  transferModule.SendInstantMessage(new GridInstantMessage(
225  m_scene, godID, "God", agentID, (byte)250, false,
226  Utils.BytesToString(reason), UUID.Zero, true,
227  new Vector3(), new byte[] {(byte)kickflags}, true),
228  delegate(bool success) {} );
229  }
230  return;
231  }
232 
233  switch (kickflags)
234  {
235  case 0:
236  if (sp != null)
237  {
238  KickPresence(sp, Utils.BytesToString(reason));
239  }
240  else if (agentID == ALL_AGENTS)
241  {
242  m_scene.ForEachRootScenePresence(
243  delegate(ScenePresence p)
244  {
245  if (p.UUID != godID && (!m_scene.Permissions.IsGod(p.UUID)))
246  KickPresence(p, Utils.BytesToString(reason));
247  }
248  );
249  }
250  break;
251  case 1:
252  if (sp != null)
253  {
254  sp.AllowMovement = false;
255  m_dialogModule.SendAlertToUser(agentID, Utils.BytesToString(reason));
256  m_dialogModule.SendAlertToUser(godID, "User Frozen");
257  }
258  break;
259  case 2:
260  if (sp != null)
261  {
262  sp.AllowMovement = true;
263  m_dialogModule.SendAlertToUser(agentID, Utils.BytesToString(reason));
264  m_dialogModule.SendAlertToUser(godID, "User Unfrozen");
265  }
266  break;
267  default:
268  break;
269  }
270  }
271 
272  private void KickPresence(ScenePresence sp, string reason)
273  {
274  if (sp.IsChildAgent)
275  return;
276  sp.ControllingClient.Kick(reason);
277  sp.Scene.CloseAgent(sp.UUID, true);
278  }
279 
280  private void OnIncomingInstantMessage(GridInstantMessage msg)
281  {
282  if (msg.dialog == (uint)250) // Nonlocal kick
283  {
284  UUID agentID = new UUID(msg.toAgentID);
285  string reason = msg.message;
286  UUID godID = new UUID(msg.fromAgentID);
287  uint kickMode = (uint)msg.binaryBucket[0];
288 
289  KickUser(godID, UUID.Zero, agentID, kickMode, Util.StringToBytes1024(reason));
290  }
291  }
292  }
293 }
void UnsubscribeFromClientEvents(IClientAPI client)
Definition: GodsModule.cs:116
void KickUser(UUID godID, UUID sessionID, UUID agentID, uint kickflags, byte[] reason)
Kicks User specified from the simulator. This logs them off of the grid If the client gets the UUID: ...
Definition: GodsModule.cs:210
void Initialise(IConfigSource source)
This is called to initialize the region module. For shared modules, this is called exactly once...
Definition: GodsModule.cs:77
OpenSim.Server.Handlers.Simulation.Utils Utils
OpenMetaverse.StructuredData.OSDMap OSDMap
Definition: GodsModule.cs:50
delegate void RequestGodlikePowers(UUID AgentID, UUID SessionID, UUID token, bool GodLike, IClientAPI remote_client)
void RequestGodlikePowers(UUID agentID, UUID sessionID, UUID token, bool godLike, IClientAPI controllingClient)
Handle a request for admin rights
Definition: GodsModule.cs:164
void RegionLoaded(Scene scene)
This will be called once for every scene loaded. In a shared module this will be multiple times in on...
Definition: GodsModule.cs:98
void RemoveRegion(Scene scene)
This is called whenever a Scene is removed. For shared modules, this can happen several times...
Definition: GodsModule.cs:91
void Close()
This is the inverse to Initialise. After a Close(), this instance won't be usable anymore...
Definition: GodsModule.cs:102
This interface provides god related methods
Definition: IGodsModule.cs:36
Interactive OpenSim region server
Definition: OpenSim.cs:55
OpenMetaverse.StructuredData.OSDArray OSDArray
Definition: GodsModule.cs:49
OpenSim.Framework.Capabilities.Caps Caps
Definition: GodsModule.cs:48
void AddRegion(Scene scene)
This is called whenever a Scene is added. For shared modules, this can happen several times...
Definition: GodsModule.cs:81