XEstateModule.cs 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  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.Framework.Communications;
  37. using OpenSim.Region.Framework.Interfaces;
  38. using OpenSim.Region.Framework.Scenes;
  39. using OpenSim.Services.Interfaces;
  40. using OpenSim.Server.Base;
  41. using OpenSim.Framework.Servers;
  42. using OpenSim.Framework.Servers.HttpServer;
  43. using Mono.Addins;
  44. namespace OpenSim.Region.CoreModules.World.Estate
  45. {
  46. [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "XEstate")]
  47. public class XEstateModule : ISharedRegionModule
  48. {
  49. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  50. protected List<Scene> m_Scenes = new List<Scene>();
  51. protected bool m_InInfoUpdate = false;
  52. public bool InInfoUpdate
  53. {
  54. get { return m_InInfoUpdate; }
  55. set { m_InInfoUpdate = value; }
  56. }
  57. public List<Scene> Scenes
  58. {
  59. get { return m_Scenes; }
  60. }
  61. protected EstateConnector m_EstateConnector;
  62. public void Initialise(IConfigSource config)
  63. {
  64. int port = 0;
  65. IConfig estateConfig = config.Configs["Estate"];
  66. if (estateConfig != null)
  67. {
  68. port = estateConfig.GetInt("Port", 0);
  69. }
  70. m_EstateConnector = new EstateConnector(this);
  71. // Instantiate the request handler
  72. IHttpServer server = MainServer.GetHttpServer((uint)port);
  73. server.AddStreamHandler(new EstateRequestHandler(this));
  74. }
  75. public void PostInitialise()
  76. {
  77. }
  78. public void Close()
  79. {
  80. }
  81. public void AddRegion(Scene scene)
  82. {
  83. lock (m_Scenes)
  84. m_Scenes.Add(scene);
  85. scene.EventManager.OnNewClient += OnNewClient;
  86. }
  87. public void RegionLoaded(Scene scene)
  88. {
  89. IEstateModule em = scene.RequestModuleInterface<IEstateModule>();
  90. em.OnRegionInfoChange += OnRegionInfoChange;
  91. em.OnEstateInfoChange += OnEstateInfoChange;
  92. em.OnEstateMessage += OnEstateMessage;
  93. }
  94. public void RemoveRegion(Scene scene)
  95. {
  96. scene.EventManager.OnNewClient -= OnNewClient;
  97. lock (m_Scenes)
  98. m_Scenes.Remove(scene);
  99. }
  100. public string Name
  101. {
  102. get { return "EstateModule"; }
  103. }
  104. public Type ReplaceableInterface
  105. {
  106. get { return null; }
  107. }
  108. private Scene FindScene(UUID RegionID)
  109. {
  110. foreach (Scene s in Scenes)
  111. {
  112. if (s.RegionInfo.RegionID == RegionID)
  113. return s;
  114. }
  115. return null;
  116. }
  117. private void OnRegionInfoChange(UUID RegionID)
  118. {
  119. Scene s = FindScene(RegionID);
  120. if (s == null)
  121. return;
  122. if (!m_InInfoUpdate)
  123. m_EstateConnector.SendUpdateCovenant(s.RegionInfo.EstateSettings.EstateID, s.RegionInfo.RegionSettings.Covenant);
  124. }
  125. private void OnEstateInfoChange(UUID RegionID)
  126. {
  127. Scene s = FindScene(RegionID);
  128. if (s == null)
  129. return;
  130. if (!m_InInfoUpdate)
  131. m_EstateConnector.SendUpdateEstate(s.RegionInfo.EstateSettings.EstateID);
  132. }
  133. private void OnEstateMessage(UUID RegionID, UUID FromID, string FromName, string Message)
  134. {
  135. Scene senderScenes = FindScene(RegionID);
  136. if (senderScenes == null)
  137. return;
  138. uint estateID = senderScenes.RegionInfo.EstateSettings.EstateID;
  139. foreach (Scene s in Scenes)
  140. {
  141. if (s.RegionInfo.EstateSettings.EstateID == estateID)
  142. {
  143. IDialogModule dm = s.RequestModuleInterface<IDialogModule>();
  144. if (dm != null)
  145. {
  146. dm.SendNotificationToUsersInRegion(FromID, FromName,
  147. Message);
  148. }
  149. }
  150. }
  151. if (!m_InInfoUpdate)
  152. m_EstateConnector.SendEstateMessage(estateID, FromID, FromName, Message);
  153. }
  154. private void OnNewClient(IClientAPI client)
  155. {
  156. client.OnEstateTeleportOneUserHomeRequest += OnEstateTeleportOneUserHomeRequest;
  157. client.OnEstateTeleportAllUsersHomeRequest += OnEstateTeleportAllUsersHomeRequest;
  158. }
  159. private void OnEstateTeleportOneUserHomeRequest(IClientAPI client, UUID invoice, UUID senderID, UUID prey)
  160. {
  161. if (prey == UUID.Zero)
  162. return;
  163. if (!(client.Scene is Scene))
  164. return;
  165. Scene scene = (Scene)client.Scene;
  166. uint estateID = scene.RegionInfo.EstateSettings.EstateID;
  167. if (!scene.Permissions.CanIssueEstateCommand(client.AgentId, false))
  168. return;
  169. foreach (Scene s in Scenes)
  170. {
  171. if (s == scene)
  172. continue; // Already handles by estate module
  173. if (s.RegionInfo.EstateSettings.EstateID != estateID)
  174. continue;
  175. ScenePresence p = scene.GetScenePresence(prey);
  176. if (p != null && !p.IsChildAgent)
  177. {
  178. p.ControllingClient.SendTeleportStart(16);
  179. scene.TeleportClientHome(prey, p.ControllingClient);
  180. }
  181. }
  182. m_EstateConnector.SendTeleportHomeOneUser(estateID, prey);
  183. }
  184. private void OnEstateTeleportAllUsersHomeRequest(IClientAPI client, UUID invoice, UUID senderID)
  185. {
  186. if (!(client.Scene is Scene))
  187. return;
  188. Scene scene = (Scene)client.Scene;
  189. uint estateID = scene.RegionInfo.EstateSettings.EstateID;
  190. if (!scene.Permissions.CanIssueEstateCommand(client.AgentId, false))
  191. return;
  192. foreach (Scene s in Scenes)
  193. {
  194. if (s == scene)
  195. continue; // Already handles by estate module
  196. if (s.RegionInfo.EstateSettings.EstateID != estateID)
  197. continue;
  198. scene.ForEachScenePresence(delegate(ScenePresence p) {
  199. if (p != null && !p.IsChildAgent)
  200. {
  201. p.ControllingClient.SendTeleportStart(16);
  202. scene.TeleportClientHome(p.ControllingClient.AgentId, p.ControllingClient);
  203. }
  204. });
  205. }
  206. m_EstateConnector.SendTeleportHomeAllUsers(estateID);
  207. }
  208. }
  209. }