HGGridServicesGridMode.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  1. /**
  2. * Copyright (c) 2008, Contributors. All rights reserved.
  3. * See CONTRIBUTORS.TXT for a full list of copyright holders.
  4. *
  5. * Redistribution and use in source and binary forms, with or without modification,
  6. * are permitted provided that the following conditions are met:
  7. *
  8. * * Redistributions of source code must retain the above copyright notice,
  9. * this list of conditions and the following disclaimer.
  10. * * Redistributions in binary form must reproduce the above copyright notice,
  11. * this list of conditions and the following disclaimer in the documentation
  12. * and/or other materials provided with the distribution.
  13. * * Neither the name of the Organizations nor the names of Individual
  14. * Contributors may be used to endorse or promote products derived from
  15. * this software without specific prior written permission.
  16. *
  17. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  18. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  19. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
  20. * THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  21. * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
  22. * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  23. * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  24. * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
  25. * OF THE POSSIBILITY OF SUCH DAMAGE.
  26. *
  27. */
  28. using System;
  29. using System.Collections.Generic;
  30. using System.Reflection;
  31. using OpenSim.Framework;
  32. using OpenSim.Framework.Communications;
  33. using OpenSim.Framework.Communications.Cache;
  34. using OpenSim.Framework.Servers;
  35. using OpenSim.Region.Communications.OGS1;
  36. using OpenSim.Region.Environment.Scenes;
  37. using OpenMetaverse;
  38. using log4net;
  39. namespace OpenSim.Region.Communications.Hypergrid
  40. {
  41. public class HGGridServicesGridMode : HGGridServices
  42. {
  43. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  44. /// <summary>
  45. /// Encapsulate remote backend services for manipulation of grid regions
  46. /// </summary>
  47. private OGS1GridServices m_remoteBackend = null;
  48. public OGS1GridServices RemoteBackend
  49. {
  50. get { return m_remoteBackend; }
  51. }
  52. public override string gdebugRegionName
  53. {
  54. get { return m_remoteBackend.gdebugRegionName; }
  55. set { m_remoteBackend.gdebugRegionName = value; }
  56. }
  57. public override bool RegionLoginsEnabled
  58. {
  59. get { return m_remoteBackend.RegionLoginsEnabled; }
  60. set { m_remoteBackend.RegionLoginsEnabled = value; }
  61. }
  62. public HGGridServicesGridMode(NetworkServersInfo servers_info, BaseHttpServer httpServe,
  63. AssetCache asscache, SceneManager sman, UserProfileCacheService userv)
  64. : base(servers_info, httpServe, asscache, sman)
  65. {
  66. m_remoteBackend = new OGS1GridServices(servers_info, httpServe);
  67. // Let's deregister this, so we can handle it here first
  68. InterRegionSingleton.Instance.OnChildAgent -= m_remoteBackend.IncomingChildAgent;
  69. InterRegionSingleton.Instance.OnChildAgent += IncomingChildAgent;
  70. m_userProfileCache = userv;
  71. }
  72. #region IGridServices interface
  73. public override RegionCommsListener RegisterRegion(RegionInfo regionInfo)
  74. {
  75. if (!regionInfo.RegionID.Equals(UUID.Zero))
  76. {
  77. m_regionsOnInstance.Add(regionInfo);
  78. return m_remoteBackend.RegisterRegion(regionInfo);
  79. }
  80. else
  81. return base.RegisterRegion(regionInfo);
  82. }
  83. public override bool DeregisterRegion(RegionInfo regionInfo)
  84. {
  85. bool success = m_remoteBackend.DeregisterRegion(regionInfo);
  86. if (!success)
  87. success = base.DeregisterRegion(regionInfo);
  88. return success;
  89. }
  90. public override List<SimpleRegionInfo> RequestNeighbours(uint x, uint y)
  91. {
  92. List<SimpleRegionInfo> neighbours = m_remoteBackend.RequestNeighbours(x, y);
  93. List<SimpleRegionInfo> remotes = base.RequestNeighbours(x, y);
  94. neighbours.AddRange(remotes);
  95. return neighbours;
  96. }
  97. public override RegionInfo RequestNeighbourInfo(UUID Region_UUID)
  98. {
  99. RegionInfo info = m_remoteBackend.RequestNeighbourInfo(Region_UUID);
  100. if (info == null)
  101. info = base.RequestNeighbourInfo(Region_UUID);
  102. return info;
  103. }
  104. public override RegionInfo RequestNeighbourInfo(ulong regionHandle)
  105. {
  106. RegionInfo info = base.RequestNeighbourInfo(regionHandle);
  107. if (info == null)
  108. info = m_remoteBackend.RequestNeighbourInfo(regionHandle);
  109. return info;
  110. }
  111. public override RegionInfo RequestClosestRegion(string regionName)
  112. {
  113. RegionInfo info = m_remoteBackend.RequestClosestRegion(regionName);
  114. if (info == null)
  115. info = base.RequestClosestRegion(regionName);
  116. return info;
  117. }
  118. public override List<MapBlockData> RequestNeighbourMapBlocks(int minX, int minY, int maxX, int maxY)
  119. {
  120. List<MapBlockData> neighbours = m_remoteBackend.RequestNeighbourMapBlocks(minX, minY, maxX, maxY);
  121. List<MapBlockData> remotes = base.RequestNeighbourMapBlocks(minX, minY, maxX, maxY);
  122. neighbours.AddRange(remotes);
  123. return neighbours;
  124. }
  125. public override LandData RequestLandData(ulong regionHandle, uint x, uint y)
  126. {
  127. LandData land = m_remoteBackend.RequestLandData(regionHandle, x, y);
  128. if (land == null)
  129. land = base.RequestLandData(regionHandle, x, y);
  130. return land;
  131. }
  132. public override List<RegionInfo> RequestNamedRegions(string name, int maxNumber)
  133. {
  134. List<RegionInfo> infos = m_remoteBackend.RequestNamedRegions(name, maxNumber);
  135. List<RegionInfo> remotes = base.RequestNamedRegions(name, maxNumber);
  136. infos.AddRange(remotes);
  137. return infos;
  138. }
  139. #endregion
  140. #region IInterRegionCommunications interface
  141. public override bool AcknowledgeAgentCrossed(ulong regionHandle, UUID agentId)
  142. {
  143. return m_remoteBackend.AcknowledgeAgentCrossed(regionHandle, agentId);
  144. }
  145. public override bool AcknowledgePrimCrossed(ulong regionHandle, UUID primID)
  146. {
  147. return m_remoteBackend.AcknowledgePrimCrossed(regionHandle, primID);
  148. }
  149. public override bool CheckRegion(string address, uint port)
  150. {
  151. return m_remoteBackend.CheckRegion(address, port);
  152. }
  153. public override bool ChildAgentUpdate(ulong regionHandle, ChildAgentDataUpdate cAgentData)
  154. {
  155. return m_remoteBackend.ChildAgentUpdate(regionHandle, cAgentData);
  156. }
  157. public override bool ExpectAvatarCrossing(ulong regionHandle, UUID agentID, Vector3 position, bool isFlying)
  158. {
  159. if (base.ExpectAvatarCrossing(regionHandle, agentID, position, isFlying))
  160. return true;
  161. return m_remoteBackend.ExpectAvatarCrossing(regionHandle, agentID, position, isFlying);
  162. }
  163. public override bool ExpectPrimCrossing(ulong regionHandle, UUID primID, Vector3 position, bool isFlying)
  164. {
  165. return m_remoteBackend.ExpectPrimCrossing(regionHandle, primID, position, isFlying);
  166. }
  167. public override bool InformRegionOfChildAgent(ulong regionHandle, AgentCircuitData agentData)
  168. {
  169. CachedUserInfo user = m_userProfileCache.GetUserDetails(agentData.AgentID);
  170. if (IsLocalUser(user))
  171. {
  172. Console.WriteLine("XXX Home User XXX");
  173. if (IsHyperlinkRegion(regionHandle))
  174. {
  175. Console.WriteLine("XXX Going Hyperlink XXX");
  176. return base.InformRegionOfChildAgent(regionHandle, agentData);
  177. }
  178. else
  179. {
  180. // non-hypergrid case
  181. Console.WriteLine("XXX Going local-grid region XXX");
  182. return m_remoteBackend.InformRegionOfChildAgent(regionHandle, agentData);
  183. }
  184. }
  185. // Foregin users
  186. Console.WriteLine("XXX Foreign User XXX");
  187. if (IsLocalRegion(regionHandle)) // regions on the same instance
  188. {
  189. Console.WriteLine("XXX Going onInstance region XXX");
  190. return m_remoteBackend.InformRegionOfChildAgent(regionHandle, agentData);
  191. }
  192. if (IsHyperlinkRegion(regionHandle)) // hyperlinked regions
  193. {
  194. Console.WriteLine("XXX Going Hyperlink XXX");
  195. return base.InformRegionOfChildAgent(regionHandle, agentData);
  196. }
  197. else
  198. {
  199. // foreign user going to a non-local region on the same grid
  200. // We need to inform that region about this user before
  201. // proceeding to the normal backend process.
  202. Console.WriteLine("XXX Going local-grid region XXX");
  203. RegionInfo regInfo = RequestNeighbourInfo(regionHandle);
  204. if (regInfo != null)
  205. // For now, don't test if this succeeds/fails; until someone complains, this is a feature :-)
  206. InformRegionOfUser(regInfo, agentData);
  207. return m_remoteBackend.InformRegionOfChildAgent(regionHandle, agentData);
  208. }
  209. }
  210. public override bool InformRegionOfPrimCrossing(ulong regionHandle, UUID primID, string objData, int XMLMethod)
  211. {
  212. return m_remoteBackend.InformRegionOfPrimCrossing(regionHandle, primID, objData, XMLMethod);
  213. }
  214. public override bool RegionUp(SerializableRegionInfo region, ulong regionhandle)
  215. {
  216. if (m_remoteBackend.RegionUp(region, regionhandle))
  217. return true;
  218. return base.RegionUp(region, regionhandle);
  219. }
  220. public override bool TellRegionToCloseChildConnection(ulong regionHandle, UUID agentID)
  221. {
  222. return m_remoteBackend.TellRegionToCloseChildConnection(regionHandle, agentID);
  223. }
  224. #endregion
  225. #region Methods triggered by calls from external instances
  226. /// <summary>
  227. ///
  228. /// </summary>
  229. /// <param name="regionHandle"></param>
  230. /// <param name="agentData"></param>
  231. /// <returns></returns>
  232. public bool IncomingChildAgent(ulong regionHandle, AgentCircuitData agentData)
  233. {
  234. HGIncomingChildAgent(regionHandle, agentData);
  235. m_log.Info("[HGrid]: Incoming HGrid Agent " + agentData.firstname + " " + agentData.lastname);
  236. return m_remoteBackend.IncomingChildAgent(regionHandle, agentData);
  237. }
  238. #endregion
  239. }
  240. }