OGS1InterSimComms.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  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.Reflection;
  29. using System.Runtime.Remoting;
  30. using libsecondlife;
  31. using log4net;
  32. using OpenSim.Framework;
  33. namespace OpenSim.Region.Communications.OGS1
  34. {
  35. public delegate bool InformRegionChild(ulong regionHandle, AgentCircuitData agentData);
  36. public delegate bool ExpectArrival(ulong regionHandle, LLUUID agentID, LLVector3 position, bool isFlying);
  37. public delegate bool InformRegionPrimGroup(ulong regionHandle, LLUUID primID, LLVector3 Positon, bool isPhysical);
  38. public delegate bool PrimGroupArrival(ulong regionHandle, LLUUID primID, string objData, int XMLMethod);
  39. public delegate bool RegionUp(RegionUpData region, ulong regionhandle);
  40. public delegate bool ChildAgentUpdate(ulong regionHandle, ChildAgentDataUpdate childUpdate);
  41. public delegate bool TellRegionToCloseChildConnection(ulong regionHandle, LLUUID agentID);
  42. public sealed class InterRegionSingleton
  43. {
  44. private static readonly InterRegionSingleton instance = new InterRegionSingleton();
  45. public event InformRegionChild OnChildAgent;
  46. public event ExpectArrival OnArrival;
  47. public event InformRegionPrimGroup OnPrimGroupNear;
  48. public event PrimGroupArrival OnPrimGroupArrival;
  49. public event RegionUp OnRegionUp;
  50. public event ChildAgentUpdate OnChildAgentUpdate;
  51. public event TellRegionToCloseChildConnection OnTellRegionToCloseChildConnection;
  52. private InformRegionChild handlerChildAgent = null; // OnChildAgent;
  53. private ExpectArrival handlerArrival = null; // OnArrival;
  54. private InformRegionPrimGroup handlerPrimGroupNear = null; // OnPrimGroupNear;
  55. private PrimGroupArrival handlerPrimGroupArrival = null; // OnPrimGroupArrival;
  56. private RegionUp handlerRegionUp = null; // OnRegionUp;
  57. private ChildAgentUpdate handlerChildAgentUpdate = null; // OnChildAgentUpdate;
  58. private TellRegionToCloseChildConnection handlerTellRegionToCloseChildConnection = null; // OnTellRegionToCloseChildConnection;
  59. static InterRegionSingleton()
  60. {
  61. }
  62. private InterRegionSingleton()
  63. {
  64. }
  65. public static InterRegionSingleton Instance
  66. {
  67. get { return instance; }
  68. }
  69. public bool InformRegionOfChildAgent(ulong regionHandle, AgentCircuitData agentData)
  70. {
  71. handlerChildAgent = OnChildAgent;
  72. if (handlerChildAgent != null)
  73. {
  74. return handlerChildAgent(regionHandle, agentData);
  75. }
  76. return false;
  77. }
  78. public bool RegionUp(RegionUpData sregion, ulong regionhandle)
  79. {
  80. handlerRegionUp = OnRegionUp;
  81. if (handlerRegionUp != null)
  82. {
  83. return handlerRegionUp(sregion, regionhandle);
  84. }
  85. return false;
  86. }
  87. public bool ChildAgentUpdate(ulong regionHandle, ChildAgentDataUpdate cAgentUpdate)
  88. {
  89. handlerChildAgentUpdate = OnChildAgentUpdate;
  90. if (handlerChildAgentUpdate != null)
  91. {
  92. return handlerChildAgentUpdate(regionHandle, cAgentUpdate);
  93. }
  94. return false;
  95. }
  96. public bool ExpectAvatarCrossing(ulong regionHandle, LLUUID agentID, LLVector3 position, bool isFlying)
  97. {
  98. handlerArrival = OnArrival;
  99. if (handlerArrival != null)
  100. {
  101. return handlerArrival(regionHandle, agentID, position, isFlying);
  102. }
  103. return false;
  104. }
  105. public bool InformRegionPrim(ulong regionHandle, LLUUID primID, LLVector3 position, bool isPhysical)
  106. {
  107. handlerPrimGroupNear = OnPrimGroupNear;
  108. if (handlerPrimGroupNear != null)
  109. {
  110. return handlerPrimGroupNear(regionHandle, primID, position, isPhysical);
  111. }
  112. return false;
  113. }
  114. public bool ExpectPrimCrossing(ulong regionHandle, LLUUID primID, string objData, int XMLMethod)
  115. {
  116. handlerPrimGroupArrival = OnPrimGroupArrival;
  117. if (handlerPrimGroupArrival != null)
  118. {
  119. return handlerPrimGroupArrival(regionHandle, primID, objData, XMLMethod);
  120. }
  121. return false;
  122. }
  123. public bool TellRegionToCloseChildConnection(ulong regionHandle, LLUUID agentID)
  124. {
  125. handlerTellRegionToCloseChildConnection = OnTellRegionToCloseChildConnection;
  126. if (handlerTellRegionToCloseChildConnection != null)
  127. {
  128. return handlerTellRegionToCloseChildConnection(regionHandle, agentID);
  129. }
  130. return false;
  131. }
  132. }
  133. public class OGS1InterRegionRemoting : MarshalByRefObject
  134. {
  135. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  136. public OGS1InterRegionRemoting()
  137. {
  138. }
  139. public bool InformRegionOfChildAgent(ulong regionHandle, sAgentCircuitData agentData)
  140. {
  141. try
  142. {
  143. return
  144. InterRegionSingleton.Instance.InformRegionOfChildAgent(regionHandle, new AgentCircuitData(agentData));
  145. }
  146. catch (RemotingException e)
  147. {
  148. Console.WriteLine("Remoting Error: Unable to connect to remote region.\n" + e.ToString());
  149. return false;
  150. }
  151. }
  152. public bool RegionUp(RegionUpData region, ulong regionhandle)
  153. {
  154. try
  155. {
  156. return InterRegionSingleton.Instance.RegionUp(region, regionhandle);
  157. }
  158. catch (RemotingException e)
  159. {
  160. Console.WriteLine("Remoting Error: Unable to connect to remote region.\n" + e.ToString());
  161. return false;
  162. }
  163. }
  164. public bool ChildAgentUpdate(ulong regionHandle, ChildAgentDataUpdate cAgentData)
  165. {
  166. try
  167. {
  168. return InterRegionSingleton.Instance.ChildAgentUpdate(regionHandle, cAgentData);
  169. }
  170. catch (RemotingException e)
  171. {
  172. Console.WriteLine("Remoting Error: Unable to send Child agent update to remote region.\n" + e.ToString());
  173. return false;
  174. }
  175. }
  176. public bool ExpectAvatarCrossing(ulong regionHandle, Guid agentID, sLLVector3 position, bool isFlying)
  177. {
  178. try
  179. {
  180. return
  181. InterRegionSingleton.Instance.ExpectAvatarCrossing(regionHandle, new LLUUID(agentID),
  182. new LLVector3(position.x, position.y, position.z),
  183. isFlying);
  184. }
  185. catch (RemotingException e)
  186. {
  187. Console.WriteLine("Remoting Error: Unable to connect to remote region.\n" + e.ToString());
  188. return false;
  189. }
  190. }
  191. public bool InformRegionPrim(ulong regionHandle, Guid SceneObjectGroupID, sLLVector3 position, bool isPhysical)
  192. {
  193. try
  194. {
  195. return
  196. InterRegionSingleton.Instance.InformRegionPrim(regionHandle, new LLUUID(SceneObjectGroupID),
  197. new LLVector3(position.x, position.y, position.z),
  198. isPhysical);
  199. }
  200. catch (RemotingException e)
  201. {
  202. Console.WriteLine("Remoting Error: Unable to connect to remote region.\n" + e.ToString());
  203. return false;
  204. }
  205. }
  206. public bool InformRegionOfPrimCrossing(ulong regionHandle, Guid primID, string objData, int XMLMethod)
  207. {
  208. try
  209. {
  210. return InterRegionSingleton.Instance.ExpectPrimCrossing(regionHandle, new LLUUID(primID), objData, XMLMethod);
  211. }
  212. catch (RemotingException e)
  213. {
  214. Console.WriteLine("Remoting Error: Unable to connect to remote region.\n" + e.ToString());
  215. return false;
  216. }
  217. }
  218. public bool TellRegionToCloseChildConnection(ulong regionHandle, Guid agentID)
  219. {
  220. try
  221. {
  222. return InterRegionSingleton.Instance.TellRegionToCloseChildConnection(regionHandle, new LLUUID(agentID));
  223. }
  224. catch (RemotingException)
  225. {
  226. m_log.Info("[INTERREGION]: Remoting Error: Unable to connect to remote region: " + regionHandle.ToString());
  227. return false;
  228. }
  229. }
  230. }
  231. }