LocalInterregionComms.cs 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  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 OpenSim 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.Net;
  31. using System.Net.Sockets;
  32. using System.Reflection;
  33. using System.Threading;
  34. using System.Xml;
  35. using OpenMetaverse;
  36. using log4net;
  37. using Nini.Config;
  38. using Nwc.XmlRpc;
  39. using OpenSim.Framework;
  40. using OpenSim.Framework.Communications.Cache;
  41. using OpenSim.Region.Environment.Interfaces;
  42. using OpenSim.Region.Interfaces;
  43. using OpenSim.Region.Environment.Scenes;
  44. namespace OpenSim.Region.Environment.Modules.Communications.Local
  45. {
  46. public class LocalInterregionComms : IRegionModule, IInterregionCommsOut, IInterregionCommsIn
  47. {
  48. private bool m_enabled = false;
  49. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  50. private List<Scene> m_sceneList = new List<Scene>();
  51. #region Events
  52. public event ChildAgentUpdateReceived OnChildAgentUpdate;
  53. #endregion /* Events */
  54. #region IRegionModule
  55. public void Initialise(Scene scene, IConfigSource config)
  56. {
  57. if (m_sceneList.Count == 0)
  58. {
  59. IConfig startupConfig = config.Configs["Communications"];
  60. if ((startupConfig != null) && (startupConfig.GetString("InterregionComms", "RESTCommms") == "LocalComms"))
  61. {
  62. m_log.Debug("[LOCAL COMMS]: Enabling InterregionComms LocalComms module");
  63. m_enabled = true;
  64. }
  65. }
  66. if (!m_enabled)
  67. return;
  68. Init(scene);
  69. }
  70. public void PostInitialise()
  71. {
  72. }
  73. public void Close()
  74. {
  75. }
  76. public string Name
  77. {
  78. get { return "LocalInterregionCommsModule"; }
  79. }
  80. public bool IsSharedModule
  81. {
  82. get { return true; }
  83. }
  84. /// <summary>
  85. /// Can be called from other modules.
  86. /// </summary>
  87. /// <param name="scene"></param>
  88. public void Init(Scene scene)
  89. {
  90. if (!m_sceneList.Contains(scene))
  91. {
  92. lock (m_sceneList)
  93. {
  94. m_sceneList.Add(scene);
  95. if (m_enabled)
  96. scene.RegisterModuleInterface<IInterregionCommsOut>(this);
  97. scene.RegisterModuleInterface<IInterregionCommsIn>(this);
  98. }
  99. }
  100. }
  101. #endregion /* IRegionModule */
  102. #region IInterregionComms
  103. public bool SendCreateChildAgent(ulong regionHandle, AgentCircuitData aCircuit)
  104. {
  105. foreach (Scene s in m_sceneList)
  106. {
  107. if (s.RegionInfo.RegionHandle == regionHandle)
  108. {
  109. // m_log.DebugFormat("[LOCAL COMMS]: Found region {0} to send SendCreateChildAgent", regionHandle);
  110. s.NewUserConnection(aCircuit);
  111. return true;
  112. }
  113. }
  114. // m_log.DebugFormat("[LOCAL COMMS]: Did not find region {0} for SendCreateChildAgent", regionHandle);
  115. return false;
  116. }
  117. public bool SendChildAgentUpdate(ulong regionHandle, AgentData cAgentData)
  118. {
  119. foreach (Scene s in m_sceneList)
  120. {
  121. if (s.RegionInfo.RegionHandle == regionHandle)
  122. {
  123. //m_log.DebugFormat(
  124. // "[LOCAL COMMS]: Found region {0} {1} to send ChildAgentUpdate",
  125. // s.RegionInfo.RegionName, regionHandle);
  126. s.IncomingChildAgentDataUpdate(cAgentData);
  127. return true;
  128. }
  129. }
  130. // m_log.DebugFormat("[LOCAL COMMS]: Did not find region {0} for ChildAgentUpdate", regionHandle);
  131. return false;
  132. }
  133. public bool SendChildAgentUpdate(ulong regionHandle, AgentPosition cAgentData)
  134. {
  135. foreach (Scene s in m_sceneList)
  136. {
  137. if (s.RegionInfo.RegionHandle == regionHandle)
  138. {
  139. //m_log.Debug("[LOCAL COMMS]: Found region to send ChildAgentUpdate");
  140. s.IncomingChildAgentDataUpdate(cAgentData);
  141. return true;
  142. }
  143. }
  144. //m_log.Debug("[LOCAL COMMS]: region not found for ChildAgentUpdate");
  145. return false;
  146. }
  147. public bool SendReleaseAgent(ulong regionHandle, UUID id, string uri)
  148. {
  149. //uint x, y;
  150. //Utils.LongToUInts(regionHandle, out x, out y);
  151. //x = x / Constants.RegionSize;
  152. //y = y / Constants.RegionSize;
  153. //Console.WriteLine("\n >>> Local SendReleaseAgent " + x + "-" + y);
  154. foreach (Scene s in m_sceneList)
  155. {
  156. if (s.RegionInfo.RegionHandle == regionHandle)
  157. {
  158. //m_log.Debug("[LOCAL COMMS]: Found region to SendReleaseAgent");
  159. return s.IncomingReleaseAgent(id);
  160. }
  161. }
  162. //m_log.Debug("[LOCAL COMMS]: region not found in SendReleaseAgent");
  163. return false;
  164. }
  165. public bool SendCloseAgent(ulong regionHandle, UUID id)
  166. {
  167. //uint x, y;
  168. //Utils.LongToUInts(regionHandle, out x, out y);
  169. //x = x / Constants.RegionSize;
  170. //y = y / Constants.RegionSize;
  171. //Console.WriteLine("\n >>> Local SendCloseAgent " + x + "-" + y);
  172. foreach (Scene s in m_sceneList)
  173. {
  174. if (s.RegionInfo.RegionHandle == regionHandle)
  175. {
  176. //m_log.Debug("[LOCAL COMMS]: Found region to SendCloseAgent");
  177. return s.IncomingCloseAgent(id);
  178. }
  179. }
  180. //m_log.Debug("[LOCAL COMMS]: region not found in SendCloseAgent");
  181. return false;
  182. }
  183. #endregion /* IInterregionComms */
  184. }
  185. }