GodsModule.cs 8.1 KB

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