EstateModule.cs 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  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 = "XEstate")]
  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.AddStreamHandler(new EstateRequestHandler(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 Scenes)
  130. {
  131. if (s.RegionInfo.RegionID == 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 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,
  166. Message);
  167. }
  168. }
  169. }
  170. if (!m_InInfoUpdate)
  171. m_EstateConnector.SendEstateMessage(estateID, FromID, FromName, Message);
  172. }
  173. private void OnEstateTeleportOneUserHomeRequest(IClientAPI client, UUID invoice, UUID senderID, UUID prey)
  174. {
  175. if (prey == UUID.Zero)
  176. return;
  177. if (!(client.Scene is Scene))
  178. return;
  179. Scene scene = (Scene)client.Scene;
  180. uint estateID = scene.RegionInfo.EstateSettings.EstateID;
  181. if (!scene.Permissions.CanIssueEstateCommand(client.AgentId, false))
  182. return;
  183. foreach (Scene s in Scenes)
  184. {
  185. if (s.RegionInfo.EstateSettings.EstateID != estateID)
  186. continue;
  187. ScenePresence p = scene.GetScenePresence(prey);
  188. if (p != null && !p.IsChildAgent && !p.IsDeleted && !p.IsInTransit)
  189. {
  190. p.ControllingClient.SendTeleportStart(16);
  191. scene.TeleportClientHome(prey, client);
  192. return;
  193. }
  194. }
  195. m_EstateConnector.SendTeleportHomeOneUser(estateID, prey);
  196. }
  197. private void OnEstateTeleportAllUsersHomeRequest(IClientAPI client, UUID invoice, UUID senderID)
  198. {
  199. if (!(client.Scene is Scene))
  200. return;
  201. Scene scene = (Scene)client.Scene;
  202. uint estateID = scene.RegionInfo.EstateSettings.EstateID;
  203. if (!scene.Permissions.CanIssueEstateCommand(client.AgentId, false))
  204. return;
  205. foreach (Scene s in Scenes)
  206. {
  207. if (s.RegionInfo.EstateSettings.EstateID != estateID)
  208. continue;
  209. scene.ForEachScenePresence(delegate(ScenePresence p)
  210. {
  211. if (p != null && !p.IsChildAgent && !p.IsDeleted && !p.IsInTransit)
  212. {
  213. p.ControllingClient.SendTeleportStart(16);
  214. scene.TeleportClientHome(p.ControllingClient.AgentId, client);
  215. }
  216. });
  217. }
  218. m_EstateConnector.SendTeleportHomeAllUsers(estateID);
  219. }
  220. }
  221. }