GodsModule.cs 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  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. using System;
  28. using System.Collections.Generic;
  29. using Nini.Config;
  30. using OpenMetaverse;
  31. using OpenSim.Framework;
  32. using OpenSim.Region.Framework.Scenes;
  33. using OpenSim.Region.Framework.Interfaces;
  34. using Mono.Addins;
  35. namespace OpenSim.Region.CoreModules.Avatar.Gods
  36. {
  37. [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "GodsModule")]
  38. public class GodsModule : INonSharedRegionModule, IGodsModule
  39. {
  40. /// <summary>Special UUID for actions that apply to all agents</summary>
  41. private static readonly UUID ALL_AGENTS = new UUID("44e87126-e794-4ded-05b3-7c42da3d5cdb");
  42. protected Scene m_scene;
  43. protected IDialogModule m_dialogModule;
  44. protected IDialogModule DialogModule
  45. {
  46. get
  47. {
  48. if (m_dialogModule == null)
  49. m_dialogModule = m_scene.RequestModuleInterface<IDialogModule>();
  50. return m_dialogModule;
  51. }
  52. }
  53. public void Initialise(IConfigSource source)
  54. {
  55. }
  56. public void AddRegion(Scene scene)
  57. {
  58. m_scene = scene;
  59. m_scene.RegisterModuleInterface<IGodsModule>(this);
  60. m_scene.EventManager.OnNewClient += SubscribeToClientEvents;
  61. }
  62. public void RemoveRegion(Scene scene)
  63. {
  64. m_scene.UnregisterModuleInterface<IGodsModule>(this);
  65. m_scene.EventManager.OnNewClient -= SubscribeToClientEvents;
  66. m_scene = null;
  67. }
  68. public void RegionLoaded(Scene scene)
  69. {
  70. }
  71. public void Close() {}
  72. public string Name { get { return "Gods Module"; } }
  73. public Type ReplaceableInterface
  74. {
  75. get { return null; }
  76. }
  77. public void SubscribeToClientEvents(IClientAPI client)
  78. {
  79. client.OnGodKickUser += KickUser;
  80. client.OnRequestGodlikePowers += RequestGodlikePowers;
  81. }
  82. public void UnsubscribeFromClientEvents(IClientAPI client)
  83. {
  84. client.OnGodKickUser -= KickUser;
  85. client.OnRequestGodlikePowers -= RequestGodlikePowers;
  86. }
  87. public void RequestGodlikePowers(
  88. UUID agentID, UUID sessionID, UUID token, bool godLike, IClientAPI controllingClient)
  89. {
  90. ScenePresence sp = m_scene.GetScenePresence(agentID);
  91. if (sp != null)
  92. {
  93. if (godLike == false)
  94. {
  95. sp.GrantGodlikePowers(agentID, sessionID, token, godLike);
  96. return;
  97. }
  98. // First check that this is the sim owner
  99. if (m_scene.Permissions.IsGod(agentID))
  100. {
  101. // Next we check for spoofing.....
  102. UUID testSessionID = sp.ControllingClient.SessionId;
  103. if (sessionID == testSessionID)
  104. {
  105. if (sessionID == controllingClient.SessionId)
  106. {
  107. //m_log.Info("godlike: " + godLike.ToString());
  108. sp.GrantGodlikePowers(agentID, testSessionID, token, godLike);
  109. }
  110. }
  111. }
  112. else
  113. {
  114. if (DialogModule != null)
  115. DialogModule.SendAlertToUser(agentID, "Request for god powers denied");
  116. }
  117. }
  118. }
  119. /// <summary>
  120. /// Kicks User specified from the simulator. This logs them off of the grid
  121. /// If the client gets the UUID: 44e87126e7944ded05b37c42da3d5cdb it assumes
  122. /// that you're kicking it even if the avatar's UUID isn't the UUID that the
  123. /// agent is assigned
  124. /// </summary>
  125. /// <param name="godID">The person doing the kicking</param>
  126. /// <param name="sessionID">The session of the person doing the kicking</param>
  127. /// <param name="agentID">the person that is being kicked</param>
  128. /// <param name="kickflags">Tells what to do to the user</param>
  129. /// <param name="reason">The message to send to the user after it's been turned into a field</param>
  130. public void KickUser(UUID godID, UUID sessionID, UUID agentID, uint kickflags, byte[] reason)
  131. {
  132. UUID kickUserID = ALL_AGENTS;
  133. ScenePresence sp = m_scene.GetScenePresence(agentID);
  134. if (sp != null || agentID == kickUserID)
  135. {
  136. if (m_scene.Permissions.IsGod(godID))
  137. {
  138. if (kickflags == 0)
  139. {
  140. if (agentID == kickUserID)
  141. {
  142. string reasonStr = Utils.BytesToString(reason);
  143. m_scene.ForEachClient(
  144. delegate(IClientAPI controller)
  145. {
  146. if (controller.AgentId != godID)
  147. controller.Kick(reasonStr);
  148. }
  149. );
  150. // This is a bit crude. It seems the client will be null before it actually stops the thread
  151. // The thread will kill itself eventually :/
  152. // Is there another way to make sure *all* clients get this 'inter region' message?
  153. m_scene.ForEachRootClient(
  154. delegate(IClientAPI client)
  155. {
  156. if (client.AgentId != godID)
  157. {
  158. client.Close();
  159. }
  160. }
  161. );
  162. }
  163. else
  164. {
  165. m_scene.SceneGraph.removeUserCount(!sp.IsChildAgent);
  166. sp.ControllingClient.Kick(Utils.BytesToString(reason));
  167. sp.ControllingClient.Close();
  168. }
  169. }
  170. if (kickflags == 1)
  171. {
  172. sp.AllowMovement = false;
  173. if (DialogModule != null)
  174. {
  175. DialogModule.SendAlertToUser(agentID, Utils.BytesToString(reason));
  176. DialogModule.SendAlertToUser(godID, "User Frozen");
  177. }
  178. }
  179. if (kickflags == 2)
  180. {
  181. sp.AllowMovement = true;
  182. if (DialogModule != null)
  183. {
  184. DialogModule.SendAlertToUser(agentID, Utils.BytesToString(reason));
  185. DialogModule.SendAlertToUser(godID, "User Unfrozen");
  186. }
  187. }
  188. }
  189. else
  190. {
  191. if (DialogModule != null)
  192. DialogModule.SendAlertToUser(godID, "Kick request denied");
  193. }
  194. }
  195. }
  196. }
  197. }