HGGridServicesStandalone.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  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.Net;
  31. using System.Net.Sockets;
  32. using System.Reflection;
  33. using System.Runtime.Remoting;
  34. using System.Runtime.Remoting.Channels;
  35. using System.Runtime.Remoting.Channels.Tcp;
  36. using System.Security.Authentication;
  37. using log4net;
  38. using Nwc.XmlRpc;
  39. using OpenMetaverse;
  40. using OpenSim.Framework;
  41. using OpenSim.Framework.Servers;
  42. using OpenSim.Framework.Servers.HttpServer;
  43. using OpenSim.Region.Communications.Local;
  44. using OpenSim.Region.Communications.OGS1;
  45. using OpenSim.Region.Framework.Scenes;
  46. namespace OpenSim.Region.Communications.Hypergrid
  47. {
  48. public class HGGridServicesStandalone : HGGridServices
  49. {
  50. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  51. /// <summary>
  52. /// Encapsulate local backend services for manipulation of local regions
  53. /// </summary>
  54. protected LocalBackEndServices m_localBackend = new LocalBackEndServices();
  55. //private Dictionary<ulong, int> m_deadRegionCache = new Dictionary<ulong, int>();
  56. public LocalBackEndServices LocalBackend
  57. {
  58. get { return m_localBackend; }
  59. }
  60. public override string gdebugRegionName
  61. {
  62. get { return m_localBackend.gdebugRegionName; }
  63. set { m_localBackend.gdebugRegionName = value; }
  64. }
  65. public override bool RegionLoginsEnabled
  66. {
  67. get { return m_localBackend.RegionLoginsEnabled; }
  68. set { m_localBackend.RegionLoginsEnabled = value; }
  69. }
  70. public HGGridServicesStandalone(NetworkServersInfo servers_info, BaseHttpServer httpServe, SceneManager sman)
  71. : base(servers_info, sman)
  72. {
  73. //Respond to Grid Services requests
  74. MainServer.Instance.AddXmlRPCHandler("logoff_user", LogOffUser);
  75. MainServer.Instance.AddXmlRPCHandler("check", PingCheckReply);
  76. MainServer.Instance.AddXmlRPCHandler("land_data", LandData);
  77. }
  78. #region IGridServices interface
  79. public override RegionCommsListener RegisterRegion(RegionInfo regionInfo)
  80. {
  81. if (!regionInfo.RegionID.Equals(UUID.Zero))
  82. {
  83. m_regionsOnInstance.Add(regionInfo);
  84. return m_localBackend.RegisterRegion(regionInfo);
  85. }
  86. else
  87. return base.RegisterRegion(regionInfo);
  88. }
  89. public override bool DeregisterRegion(RegionInfo regionInfo)
  90. {
  91. bool success = m_localBackend.DeregisterRegion(regionInfo);
  92. if (!success)
  93. success = base.DeregisterRegion(regionInfo);
  94. return success;
  95. }
  96. public override List<SimpleRegionInfo> RequestNeighbours(uint x, uint y)
  97. {
  98. List<SimpleRegionInfo> neighbours = m_localBackend.RequestNeighbours(x, y);
  99. //List<SimpleRegionInfo> remotes = base.RequestNeighbours(x, y);
  100. //neighbours.AddRange(remotes);
  101. return neighbours;
  102. }
  103. public override RegionInfo RequestNeighbourInfo(UUID Region_UUID)
  104. {
  105. RegionInfo info = m_localBackend.RequestNeighbourInfo(Region_UUID);
  106. if (info == null)
  107. info = base.RequestNeighbourInfo(Region_UUID);
  108. return info;
  109. }
  110. public override RegionInfo RequestNeighbourInfo(ulong regionHandle)
  111. {
  112. RegionInfo info = m_localBackend.RequestNeighbourInfo(regionHandle);
  113. //m_log.Info("[HGrid] Request neighbor info, local backend returned " + info);
  114. if (info == null)
  115. info = base.RequestNeighbourInfo(regionHandle);
  116. return info;
  117. }
  118. public override RegionInfo RequestClosestRegion(string regionName)
  119. {
  120. RegionInfo info = m_localBackend.RequestClosestRegion(regionName);
  121. if (info == null)
  122. info = base.RequestClosestRegion(regionName);
  123. return info;
  124. }
  125. public override List<MapBlockData> RequestNeighbourMapBlocks(int minX, int minY, int maxX, int maxY)
  126. {
  127. //m_log.Info("[HGrid] Request map blocks " + minX + "-" + minY + "-" + maxX + "-" + maxY);
  128. List<MapBlockData> neighbours = m_localBackend.RequestNeighbourMapBlocks(minX, minY, maxX, maxY);
  129. List<MapBlockData> remotes = base.RequestNeighbourMapBlocks(minX, minY, maxX, maxY);
  130. neighbours.AddRange(remotes);
  131. return neighbours;
  132. }
  133. public override LandData RequestLandData(ulong regionHandle, uint x, uint y)
  134. {
  135. LandData land = m_localBackend.RequestLandData(regionHandle, x, y);
  136. if (land == null)
  137. land = base.RequestLandData(regionHandle, x, y);
  138. return land;
  139. }
  140. public override List<RegionInfo> RequestNamedRegions(string name, int maxNumber)
  141. {
  142. List<RegionInfo> infos = m_localBackend.RequestNamedRegions(name, maxNumber);
  143. List<RegionInfo> remotes = base.RequestNamedRegions(name, maxNumber);
  144. infos.AddRange(remotes);
  145. return infos;
  146. }
  147. #endregion
  148. #region XML Request Handlers
  149. /// <summary>
  150. /// A ping / version check
  151. /// </summary>
  152. /// <param name="request"></param>
  153. /// <returns></returns>
  154. public virtual XmlRpcResponse PingCheckReply(XmlRpcRequest request, IPEndPoint remoteClient)
  155. {
  156. XmlRpcResponse response = new XmlRpcResponse();
  157. Hashtable respData = new Hashtable();
  158. respData["online"] = "true";
  159. m_localBackend.PingCheckReply(respData);
  160. response.Value = respData;
  161. return response;
  162. }
  163. // Grid Request Processing
  164. /// <summary>
  165. /// Ooops, our Agent must be dead if we're getting this request!
  166. /// </summary>
  167. /// <param name="request"></param>
  168. /// <returns></returns>
  169. public XmlRpcResponse LogOffUser(XmlRpcRequest request, IPEndPoint remoteClient)
  170. {
  171. m_log.Debug("[HGrid]: LogOff User Called");
  172. Hashtable requestData = (Hashtable)request.Params[0];
  173. string message = (string)requestData["message"];
  174. UUID agentID = UUID.Zero;
  175. UUID RegionSecret = UUID.Zero;
  176. UUID.TryParse((string)requestData["agent_id"], out agentID);
  177. UUID.TryParse((string)requestData["region_secret"], out RegionSecret);
  178. ulong regionHandle = Convert.ToUInt64((string)requestData["regionhandle"]);
  179. m_localBackend.TriggerLogOffUser(regionHandle, agentID, RegionSecret, message);
  180. return new XmlRpcResponse();
  181. }
  182. /// <summary>
  183. /// Someone asked us about parcel-information
  184. /// </summary>
  185. /// <param name="request"></param>
  186. /// <returns></returns>
  187. public XmlRpcResponse LandData(XmlRpcRequest request, IPEndPoint remoteClient)
  188. {
  189. Hashtable requestData = (Hashtable)request.Params[0];
  190. ulong regionHandle = Convert.ToUInt64(requestData["region_handle"]);
  191. uint x = Convert.ToUInt32(requestData["x"]);
  192. uint y = Convert.ToUInt32(requestData["y"]);
  193. m_log.DebugFormat("[HGrid]: Got XML reqeuest for land data at {0}, {1} in region {2}", x, y, regionHandle);
  194. LandData landData = m_localBackend.RequestLandData(regionHandle, x, y);
  195. Hashtable hash = new Hashtable();
  196. if (landData != null)
  197. {
  198. // for now, only push out the data we need for answering a ParcelInfoReqeust
  199. hash["AABBMax"] = landData.AABBMax.ToString();
  200. hash["AABBMin"] = landData.AABBMin.ToString();
  201. hash["Area"] = landData.Area.ToString();
  202. hash["AuctionID"] = landData.AuctionID.ToString();
  203. hash["Description"] = landData.Description;
  204. hash["Flags"] = landData.Flags.ToString();
  205. hash["GlobalID"] = landData.GlobalID.ToString();
  206. hash["Name"] = landData.Name;
  207. hash["OwnerID"] = landData.OwnerID.ToString();
  208. hash["SalePrice"] = landData.SalePrice.ToString();
  209. hash["SnapshotID"] = landData.SnapshotID.ToString();
  210. hash["UserLocation"] = landData.UserLocation.ToString();
  211. }
  212. XmlRpcResponse response = new XmlRpcResponse();
  213. response.Value = hash;
  214. return response;
  215. }
  216. #endregion
  217. }
  218. }