EstateModule.cs 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  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;
  29. using System.Collections.Generic;
  30. using System.Reflection;
  31. using log4net;
  32. using Nini.Config;
  33. using Nwc.XmlRpc;
  34. using OpenMetaverse;
  35. using OpenSim.Framework;
  36. using OpenSim.Region.Framework.Interfaces;
  37. using OpenSim.Region.Framework.Scenes;
  38. using OpenSim.Services.Interfaces;
  39. using OpenSim.Server.Base;
  40. using OpenSim.Framework.Servers;
  41. using OpenSim.Framework.Servers.HttpServer;
  42. using Mono.Addins;
  43. namespace OpenSim.Region.CoreModules.World.Estate
  44. {
  45. [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "EstateModule")]
  46. public class EstateModule : ISharedRegionModule
  47. {
  48. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  49. protected List<Scene> m_Scenes = new List<Scene>();
  50. protected bool m_InInfoUpdate = false;
  51. private string token = "7db8eh2gvgg45jj";
  52. protected bool m_enabled = false;
  53. public bool InInfoUpdate
  54. {
  55. get { return m_InInfoUpdate; }
  56. set { m_InInfoUpdate = value; }
  57. }
  58. public List<Scene> Scenes
  59. {
  60. get { return m_Scenes; }
  61. }
  62. protected EstateConnector m_EstateConnector;
  63. public void Initialise(IConfigSource config)
  64. {
  65. uint port = MainServer.Instance.Port;
  66. IConfig estateConfig = config.Configs["Estates"];
  67. if (estateConfig != null)
  68. {
  69. if (estateConfig.GetString("EstateCommunicationsHandler", Name) == Name)
  70. m_enabled = true;
  71. else
  72. return;
  73. port = (uint)estateConfig.GetInt("Port", 0);
  74. // this will need to came from somewhere else
  75. token = estateConfig.GetString("Token", token);
  76. }
  77. else
  78. {
  79. m_enabled = true;
  80. }
  81. m_EstateConnector = new EstateConnector(this, token, port);
  82. if(port == 0)
  83. port = MainServer.Instance.Port;
  84. // Instantiate the request handler
  85. IHttpServer server = MainServer.GetHttpServer(port);
  86. server.AddSimpleStreamHandler(new EstateSimpleRequestHandler(this, token));
  87. }
  88. public void PostInitialise()
  89. {
  90. }
  91. public void Close()
  92. {
  93. }
  94. public void AddRegion(Scene scene)
  95. {
  96. if (!m_enabled)
  97. return;
  98. lock (m_Scenes)
  99. m_Scenes.Add(scene);
  100. }
  101. public void RegionLoaded(Scene scene)
  102. {
  103. if (!m_enabled)
  104. return;
  105. IEstateModule em = scene.RequestModuleInterface<IEstateModule>();
  106. em.OnRegionInfoChange += OnRegionInfoChange;
  107. em.OnEstateInfoChange += OnEstateInfoChange;
  108. em.OnEstateMessage += OnEstateMessage;
  109. em.OnEstateTeleportOneUserHomeRequest += OnEstateTeleportOneUserHomeRequest;
  110. em.OnEstateTeleportAllUsersHomeRequest += OnEstateTeleportAllUsersHomeRequest;
  111. }
  112. public void RemoveRegion(Scene scene)
  113. {
  114. if (!m_enabled)
  115. return;
  116. lock (m_Scenes)
  117. m_Scenes.Remove(scene);
  118. }
  119. public string Name
  120. {
  121. get { return "EstateModule"; }
  122. }
  123. public Type ReplaceableInterface
  124. {
  125. get { return null; }
  126. }
  127. private Scene FindScene(UUID RegionID)
  128. {
  129. foreach (Scene s in m_Scenes)
  130. {
  131. if (s.RegionInfo.RegionID.Equals(RegionID))
  132. return s;
  133. }
  134. return null;
  135. }
  136. private void OnRegionInfoChange(UUID RegionID)
  137. {
  138. Scene s = FindScene(RegionID);
  139. if (s == null)
  140. return;
  141. if (!m_InInfoUpdate)
  142. m_EstateConnector.SendUpdateCovenant(s.RegionInfo.EstateSettings.EstateID, s.RegionInfo.RegionSettings.Covenant);
  143. }
  144. private void OnEstateInfoChange(UUID RegionID)
  145. {
  146. Scene s = FindScene(RegionID);
  147. if (s == null)
  148. return;
  149. if (!m_InInfoUpdate)
  150. m_EstateConnector.SendUpdateEstate(s.RegionInfo.EstateSettings.EstateID);
  151. }
  152. private void OnEstateMessage(UUID RegionID, UUID FromID, string FromName, string Message)
  153. {
  154. Scene senderScenes = FindScene(RegionID);
  155. if (senderScenes == null)
  156. return;
  157. uint estateID = senderScenes.RegionInfo.EstateSettings.EstateID;
  158. foreach (Scene s in m_Scenes)
  159. {
  160. if (s.RegionInfo.EstateSettings.EstateID == estateID)
  161. {
  162. IDialogModule dm = s.RequestModuleInterface<IDialogModule>();
  163. if (dm != null)
  164. {
  165. dm.SendNotificationToUsersInRegion(FromID, FromName, Message);
  166. }
  167. }
  168. }
  169. if (!m_InInfoUpdate)
  170. m_EstateConnector.SendEstateMessage(estateID, FromID, FromName, Message);
  171. }
  172. private void OnEstateTeleportOneUserHomeRequest(IClientAPI client, UUID invoice, UUID senderID, UUID prey, bool kick)
  173. {
  174. if (prey.IsZero())
  175. return;
  176. Scene scene = client.Scene as Scene;
  177. if (scene == null)
  178. return;
  179. if (!scene.Permissions.CanIssueEstateCommand(client.AgentId, false))
  180. return;
  181. uint estateID = scene.RegionInfo.EstateSettings.EstateID;
  182. foreach (Scene s in m_Scenes)
  183. {
  184. if (s.RegionInfo.EstateSettings.EstateID != estateID)
  185. continue;
  186. ScenePresence p = scene.GetScenePresence(prey);
  187. if (p != null && !p.IsChildAgent && !p.IsDeleted && !p.IsInTransit)
  188. {
  189. if (kick)
  190. {
  191. p.ControllingClient.Kick("You have been kicked out");
  192. s.CloseAgent(p.UUID, false);
  193. }
  194. else
  195. {
  196. p.ControllingClient.SendTeleportStart(16);
  197. if (!s.TeleportClientHome(prey, client))
  198. {
  199. p.ControllingClient.Kick("You were teleported home by the region owner, but the TP failed");
  200. s.CloseAgent(p.UUID, false);
  201. }
  202. }
  203. return;
  204. }
  205. }
  206. m_EstateConnector.SendTeleportHomeOneUser(estateID, prey);
  207. }
  208. private void OnEstateTeleportAllUsersHomeRequest(IClientAPI client, UUID invoice, UUID senderID)
  209. {
  210. Scene scene = client.Scene as Scene;
  211. if(scene == null)
  212. return;
  213. if (!scene.Permissions.CanIssueEstateCommand(client.AgentId, false))
  214. return;
  215. uint estateID = scene.RegionInfo.EstateSettings.EstateID;
  216. foreach (Scene s in m_Scenes)
  217. {
  218. if (s.RegionInfo.EstateSettings.EstateID != estateID)
  219. continue;
  220. scene.ForEachScenePresence(delegate(ScenePresence p)
  221. {
  222. if (p != null && !p.IsChildAgent && !p.IsDeleted && !p.IsInTransit)
  223. {
  224. p.ControllingClient.SendTeleportStart(16);
  225. scene.TeleportClientHome(p.ControllingClient.AgentId, client);
  226. if (!s.TeleportClientHome(p.ControllingClient.AgentId, client))
  227. {
  228. p.ControllingClient.Kick("You were teleported home by the region owner, but the TP failed - you have been logged out.");
  229. s.CloseAgent(p.UUID, false);
  230. }
  231. }
  232. });
  233. }
  234. m_EstateConnector.SendTeleportHomeAllUsers(estateID);
  235. }
  236. }
  237. }