/Aurora/Modules/Avatar/AuroraChat/LureModule.cs

https://bitbucket.org/VirtualReality/software-testing · C# · 205 lines · 139 code · 32 blank · 34 comment · 18 complexity · bc38c214073d6e99285b7a6024d976ae MD5 · raw file

  1. /*
  2. * Copyright (c) Contributors, http://aurora-sim.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 Aurora-Sim 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 Aurora.Framework;
  28. using Aurora.Framework.ClientInterfaces;
  29. using Aurora.Framework.ConsoleFramework;
  30. using Aurora.Framework.Modules;
  31. using Aurora.Framework.PresenceInfo;
  32. using Aurora.Framework.SceneInfo;
  33. using Aurora.Framework.Utilities;
  34. using Nini.Config;
  35. using OpenMetaverse;
  36. using System;
  37. namespace Aurora.Modules.Chat
  38. {
  39. /// <summary>
  40. /// This just supports god TP's and thats about it
  41. /// </summary>
  42. public class LureModule : INonSharedRegionModule
  43. {
  44. #region Declares
  45. private IScene m_scene;
  46. private IMessageTransferModule m_TransferModule;
  47. private bool m_Enabled = true;
  48. private bool m_allowGodTeleports = true;
  49. #endregion
  50. #region INonSharedRegionModule
  51. public void Initialise(IConfigSource source)
  52. {
  53. IConfig ccmModuleConfig = source.Configs["Messaging"];
  54. if (ccmModuleConfig != null)
  55. {
  56. m_Enabled = ccmModuleConfig.GetString("LureModule", Name) == Name;
  57. m_allowGodTeleports = ccmModuleConfig.GetBoolean("AllowGodTeleports", m_allowGodTeleports);
  58. }
  59. }
  60. public void AddRegion(IScene scene)
  61. {
  62. if (!m_Enabled)
  63. return;
  64. m_scene = scene;
  65. scene.EventManager.OnNewClient += OnNewClient;
  66. scene.EventManager.OnClosingClient += OnClosingClient;
  67. scene.EventManager.OnIncomingInstantMessage += OnGridInstantMessage;
  68. }
  69. public void RemoveRegion(IScene scene)
  70. {
  71. if (!m_Enabled)
  72. return;
  73. m_scene = null;
  74. scene.EventManager.OnNewClient -= OnNewClient;
  75. scene.EventManager.OnClosingClient -= OnClosingClient;
  76. scene.EventManager.OnIncomingInstantMessage -= OnGridInstantMessage;
  77. }
  78. public void RegionLoaded(IScene scene)
  79. {
  80. if (!m_Enabled)
  81. return;
  82. m_TransferModule = m_scene.RequestModuleInterface<IMessageTransferModule>();
  83. if (m_TransferModule == null)
  84. MainConsole.Instance.Error("[INSTANT MESSAGE]: No message transfer module, " +
  85. "lures will not work!");
  86. }
  87. public Type ReplaceableInterface
  88. {
  89. get { return null; }
  90. }
  91. public void Close()
  92. {
  93. }
  94. public string Name
  95. {
  96. get { return "AuroraLureModule"; }
  97. }
  98. #endregion
  99. #region Client
  100. private void OnNewClient(IClientAPI client)
  101. {
  102. client.OnStartLure += OnStartLure;
  103. client.OnTeleportLureRequest += OnTeleportLureRequest;
  104. }
  105. private void OnClosingClient(IClientAPI client)
  106. {
  107. client.OnStartLure -= OnStartLure;
  108. client.OnTeleportLureRequest -= OnTeleportLureRequest;
  109. }
  110. public void OnStartLure(byte lureType, string message, UUID targetid, IClientAPI client)
  111. {
  112. IScenePresence presence = client.Scene.GetScenePresence(client.AgentId);
  113. Vector3 position = presence.AbsolutePosition + new Vector3(2, 0, 0)*presence.Rotation;
  114. UUID dest = Util.BuildFakeParcelID(
  115. client.Scene.RegionInfo.RegionHandle,
  116. (uint) position.X,
  117. (uint) position.Y,
  118. (uint) position.Z);
  119. GridInstantMessage m;
  120. if (m_allowGodTeleports && client.Scene.Permissions.CanGodTeleport(client.AgentId, targetid))
  121. //if we are an admin and are in god mode
  122. {
  123. //God tp them
  124. m = new GridInstantMessage(client.Scene, client.AgentId,
  125. client.FirstName + " " + client.LastName, targetid,
  126. (byte) InstantMessageDialog.GodLikeRequestTeleport, false,
  127. "", dest, false, presence.AbsolutePosition,
  128. new Byte[0]);
  129. }
  130. else
  131. {
  132. //Not a god, so no god tp
  133. m = new GridInstantMessage(client.Scene, client.AgentId,
  134. client.FirstName + " " + client.LastName, targetid,
  135. (byte) InstantMessageDialog.RequestTeleport, false,
  136. message, dest, false, presence.AbsolutePosition,
  137. new Byte[0]);
  138. }
  139. if (m_TransferModule != null)
  140. m_TransferModule.SendInstantMessage(m);
  141. }
  142. public void OnTeleportLureRequest(UUID lureID, uint teleportFlags, IClientAPI client)
  143. {
  144. ulong handle;
  145. uint x;
  146. uint y;
  147. uint z;
  148. Util.ParseFakeParcelID(lureID, out handle, out x, out y, out z);
  149. Vector3 position = new Vector3 {X = x, Y = y, Z = z};
  150. IEntityTransferModule entityTransfer = client.Scene.RequestModuleInterface<IEntityTransferModule>();
  151. if (entityTransfer != null)
  152. {
  153. entityTransfer.RequestTeleportLocation(client, handle, position,
  154. Vector3.Zero, teleportFlags);
  155. }
  156. }
  157. private void OnGridInstantMessage(GridInstantMessage im)
  158. {
  159. if (im.dialog == (byte) InstantMessageDialog.RequestTeleport)
  160. {
  161. UUID sessionID = new UUID(im.imSessionID);
  162. MainConsole.Instance.DebugFormat(
  163. "[HG LURE MODULE]: RequestTeleport sessionID={0}, regionID={1}, message={2}", im.imSessionID,
  164. im.RegionID, im.message);
  165. // Forward. We do this, because the IM module explicitly rejects
  166. // IMs of this type
  167. if (m_TransferModule != null)
  168. m_TransferModule.SendInstantMessage(im);
  169. }
  170. }
  171. #endregion
  172. }
  173. }