RemoteSimulationConnector.cs 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  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.IO;
  30. using System.Net;
  31. using System.Reflection;
  32. using System.Text;
  33. using log4net;
  34. using Nini.Config;
  35. using OpenMetaverse;
  36. using OpenMetaverse.StructuredData;
  37. using OpenSim.Framework;
  38. using OpenSim.Framework.Communications;
  39. using OpenSim.Region.Framework.Interfaces;
  40. using OpenSim.Region.Framework.Scenes;
  41. using OpenSim.Region.Framework.Scenes.Serialization;
  42. using OpenSim.Services.Interfaces;
  43. using OpenSim.Services.Connectors.Simulation;
  44. using GridRegion = OpenSim.Services.Interfaces.GridRegion;
  45. namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Simulation
  46. {
  47. public class RemoteSimulationConnectorModule : ISharedRegionModule, ISimulationService
  48. {
  49. private bool initialized = false;
  50. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  51. protected bool m_enabled = false;
  52. protected Scene m_aScene;
  53. // RemoteSimulationConnector does not care about local regions; it delegates that to the Local module
  54. protected LocalSimulationConnectorModule m_localBackend;
  55. protected SimulationServiceConnector m_remoteConnector;
  56. protected bool m_safemode;
  57. protected IPAddress m_thisIP;
  58. #region IRegionModule
  59. public virtual void Initialise(IConfigSource config)
  60. {
  61. IConfig moduleConfig = config.Configs["Modules"];
  62. if (moduleConfig != null)
  63. {
  64. string name = moduleConfig.GetString("SimulationServices", "");
  65. if (name == Name)
  66. {
  67. //IConfig userConfig = config.Configs["SimulationService"];
  68. //if (userConfig == null)
  69. //{
  70. // m_log.Error("[AVATAR CONNECTOR]: SimulationService missing from OpenSim.ini");
  71. // return;
  72. //}
  73. m_remoteConnector = new SimulationServiceConnector();
  74. m_enabled = true;
  75. m_log.Info("[SIMULATION CONNECTOR]: Remote simulation enabled");
  76. }
  77. }
  78. }
  79. public virtual void PostInitialise()
  80. {
  81. }
  82. public virtual void Close()
  83. {
  84. }
  85. public void AddRegion(Scene scene)
  86. {
  87. if (!m_enabled)
  88. return;
  89. if (!initialized)
  90. {
  91. InitOnce(scene);
  92. initialized = true;
  93. }
  94. InitEach(scene);
  95. }
  96. public void RemoveRegion(Scene scene)
  97. {
  98. if (m_enabled)
  99. {
  100. m_localBackend.RemoveScene(scene);
  101. scene.UnregisterModuleInterface<ISimulationService>(this);
  102. }
  103. }
  104. public void RegionLoaded(Scene scene)
  105. {
  106. if (!m_enabled)
  107. return;
  108. }
  109. public Type ReplaceableInterface
  110. {
  111. get { return null; }
  112. }
  113. public virtual string Name
  114. {
  115. get { return "RemoteSimulationConnectorModule"; }
  116. }
  117. protected virtual void InitEach(Scene scene)
  118. {
  119. m_localBackend.Init(scene);
  120. scene.RegisterModuleInterface<ISimulationService>(this);
  121. }
  122. protected virtual void InitOnce(Scene scene)
  123. {
  124. m_localBackend = new LocalSimulationConnectorModule();
  125. m_aScene = scene;
  126. //m_regionClient = new RegionToRegionClient(m_aScene, m_hyperlinkService);
  127. m_thisIP = Util.GetHostFromDNS(scene.RegionInfo.ExternalHostName);
  128. }
  129. #endregion /* IRegionModule */
  130. #region IInterregionComms
  131. public IScene GetScene(ulong handle)
  132. {
  133. return m_localBackend.GetScene(handle);
  134. }
  135. public ISimulationService GetInnerService()
  136. {
  137. return m_localBackend;
  138. }
  139. /**
  140. * Agent-related communications
  141. */
  142. public bool CreateAgent(GridRegion destination, AgentCircuitData aCircuit, uint teleportFlags, out string reason)
  143. {
  144. if (destination == null)
  145. {
  146. reason = "Given destination was null";
  147. m_log.DebugFormat("[REMOTE SIMULATION CONNECTOR]: CreateAgent was given a null destination");
  148. return false;
  149. }
  150. // Try local first
  151. if (m_localBackend.CreateAgent(destination, aCircuit, teleportFlags, out reason))
  152. return true;
  153. // else do the remote thing
  154. if (!m_localBackend.IsLocalRegion(destination.RegionHandle))
  155. {
  156. return m_remoteConnector.CreateAgent(destination, aCircuit, teleportFlags, out reason);
  157. }
  158. return false;
  159. }
  160. public bool UpdateAgent(GridRegion destination, AgentData cAgentData)
  161. {
  162. if (destination == null)
  163. return false;
  164. // Try local first
  165. if (m_localBackend.UpdateAgent(destination, cAgentData))
  166. return true;
  167. // else do the remote thing
  168. if (!m_localBackend.IsLocalRegion(destination.RegionHandle))
  169. return m_remoteConnector.UpdateAgent(destination, cAgentData);
  170. return false;
  171. }
  172. public bool UpdateAgent(GridRegion destination, AgentPosition cAgentData)
  173. {
  174. if (destination == null)
  175. return false;
  176. // Try local first
  177. if (m_localBackend.UpdateAgent(destination, cAgentData))
  178. return true;
  179. // else do the remote thing
  180. if (!m_localBackend.IsLocalRegion(destination.RegionHandle))
  181. return m_remoteConnector.UpdateAgent(destination, cAgentData);
  182. return false;
  183. }
  184. public bool RetrieveAgent(GridRegion destination, UUID id, out IAgentData agent)
  185. {
  186. agent = null;
  187. if (destination == null)
  188. return false;
  189. // Try local first
  190. if (m_localBackend.RetrieveAgent(destination, id, out agent))
  191. return true;
  192. // else do the remote thing
  193. if (!m_localBackend.IsLocalRegion(destination.RegionHandle))
  194. return m_remoteConnector.RetrieveAgent(destination, id, out agent);
  195. return false;
  196. }
  197. public bool ReleaseAgent(UUID origin, UUID id, string uri)
  198. {
  199. // Try local first
  200. if (m_localBackend.ReleaseAgent(origin, id, uri))
  201. return true;
  202. // else do the remote thing
  203. if (!m_localBackend.IsLocalRegion(origin))
  204. return m_remoteConnector.ReleaseAgent(origin, id, uri);
  205. return false;
  206. }
  207. public bool CloseAgent(GridRegion destination, UUID id)
  208. {
  209. if (destination == null)
  210. return false;
  211. // Try local first
  212. if (m_localBackend.CloseAgent(destination, id))
  213. return true;
  214. // else do the remote thing
  215. if (!m_localBackend.IsLocalRegion(destination.RegionHandle))
  216. return m_remoteConnector.CloseAgent(destination, id);
  217. return false;
  218. }
  219. /**
  220. * Object-related communications
  221. */
  222. public bool CreateObject(GridRegion destination, ISceneObject sog, bool isLocalCall)
  223. {
  224. if (destination == null)
  225. return false;
  226. // Try local first
  227. if (m_localBackend.CreateObject(destination, sog, isLocalCall))
  228. {
  229. //m_log.Debug("[REST COMMS]: LocalBackEnd SendCreateObject succeeded");
  230. return true;
  231. }
  232. // else do the remote thing
  233. if (!m_localBackend.IsLocalRegion(destination.RegionHandle))
  234. return m_remoteConnector.CreateObject(destination, sog, isLocalCall);
  235. return false;
  236. }
  237. public bool CreateObject(GridRegion destination, UUID userID, UUID itemID)
  238. {
  239. // Not Implemented
  240. return false;
  241. }
  242. #endregion /* IInterregionComms */
  243. }
  244. }