XEstateModule.cs 8.3 KB

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