RegionMapService.cs 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  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.Reflection;
  32. using log4net;
  33. using Nini.Config;
  34. using OpenMetaverse;
  35. using OpenSim.Data;
  36. using OpenSim.Framework;
  37. using OpenSim.Framework.Communications;
  38. using OpenSim.Framework.Communications.Cache;
  39. using OpenSim.Framework.Servers.HttpServer;
  40. using OpenSim.Region.Framework.Interfaces;
  41. using OpenSim.Region.Framework.Scenes;
  42. using Nwc.XmlRpc;
  43. namespace OpenSim.Region.CoreModules.Framework.Services
  44. {
  45. public class RegionMapService : IRegionModule
  46. {
  47. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  48. private static bool initialized = false;
  49. private static bool enabled = false;
  50. Scene m_scene;
  51. //AssetService m_assetService;
  52. #region IRegionModule interface
  53. public void Initialise(Scene scene, IConfigSource config)
  54. {
  55. if (!initialized)
  56. {
  57. initialized = true;
  58. m_scene = scene;
  59. // This module is only on for hypergrid mode
  60. enabled = config.Configs["Startup"].GetBoolean("hypergrid", false);
  61. }
  62. }
  63. public void PostInitialise()
  64. {
  65. if (enabled)
  66. {
  67. m_log.Info("[RegionMapService]: Starting...");
  68. //m_assetService = new AssetService(m_scene);
  69. new GridService(m_scene);
  70. }
  71. }
  72. public void Close()
  73. {
  74. }
  75. public string Name
  76. {
  77. get { return "RegionMapService"; }
  78. }
  79. public bool IsSharedModule
  80. {
  81. get { return true; }
  82. }
  83. #endregion
  84. }
  85. public class GridService
  86. {
  87. // private IUserService m_userService;
  88. private IGridServices m_gridService;
  89. private bool m_doLookup = false;
  90. public bool DoLookup
  91. {
  92. get { return m_doLookup; }
  93. set { m_doLookup = value; }
  94. }
  95. private static readonly ILog m_log
  96. = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  97. public GridService(Scene m_scene)
  98. {
  99. AddHandlers(m_scene);
  100. // m_userService = m_scene.CommsManager.UserService;
  101. m_gridService = m_scene.CommsManager.GridService;
  102. }
  103. protected void AddHandlers(Scene m_scene)
  104. {
  105. // IAssetDataPlugin m_assetProvider
  106. // = ((AssetServerBase)m_scene.CommsManager.AssetCache.AssetServer).AssetProviderPlugin;
  107. IHttpServer httpServer = MainServer.Instance;
  108. httpServer.AddXmlRPCHandler("simulator_data_request", XmlRpcSimulatorDataRequestMethod);
  109. //m_httpServer.AddXmlRPCHandler("map_block", XmlRpcMapBlockMethod);
  110. //m_httpServer.AddXmlRPCHandler("search_for_region_by_name", XmlRpcSearchForRegionMethod);
  111. }
  112. /// <summary>
  113. /// Returns an XML RPC response to a simulator profile request
  114. /// </summary>
  115. /// <param name="request"></param>
  116. /// <returns></returns>
  117. public XmlRpcResponse XmlRpcSimulatorDataRequestMethod(XmlRpcRequest request, IPEndPoint remoteClient)
  118. {
  119. Hashtable requestData = (Hashtable)request.Params[0];
  120. Hashtable responseData = new Hashtable();
  121. RegionInfo simData = null;
  122. if (requestData.ContainsKey("region_UUID"))
  123. {
  124. UUID regionID = new UUID((string)requestData["region_UUID"]);
  125. simData = m_gridService.RequestNeighbourInfo(regionID); //.GetRegion(regionID);
  126. if (simData == null)
  127. {
  128. m_log.WarnFormat("[HGGridService] didn't find region for regionID {0} from {1}",
  129. regionID, request.Params.Count > 1 ? request.Params[1] : "unknwon source");
  130. }
  131. }
  132. else if (requestData.ContainsKey("region_handle"))
  133. {
  134. //CFK: The if/else below this makes this message redundant.
  135. //CFK: m_log.Info("requesting data for region " + (string) requestData["region_handle"]);
  136. ulong regionHandle = Convert.ToUInt64((string)requestData["region_handle"]);
  137. simData = m_gridService.RequestNeighbourInfo(regionHandle); //m_gridDBService.GetRegion(regionHandle);
  138. if (simData == null)
  139. {
  140. m_log.WarnFormat("[HGGridService] didn't find region for regionHandle {0} from {1}",
  141. regionHandle, request.Params.Count > 1 ? request.Params[1] : "unknwon source");
  142. }
  143. }
  144. else if (requestData.ContainsKey("region_name_search"))
  145. {
  146. string regionName = (string)requestData["region_name_search"];
  147. List<RegionInfo> regInfos = m_gridService.RequestNamedRegions(regionName, 1);//m_gridDBService.GetRegion(regionName);
  148. if (regInfos != null)
  149. simData = regInfos[0];
  150. if (simData == null)
  151. {
  152. m_log.WarnFormat("[HGGridService] didn't find region for regionName {0} from {1}",
  153. regionName, request.Params.Count > 1 ? request.Params[1] : "unknwon source");
  154. }
  155. }
  156. else m_log.Warn("[HGGridService] regionlookup without regionID, regionHandle or regionHame");
  157. if (simData == null)
  158. {
  159. //Sim does not exist
  160. responseData["error"] = "Sim does not exist";
  161. }
  162. else
  163. {
  164. m_log.Debug("[HGGridService]: found " + (string)simData.RegionName + " regionHandle = " +
  165. (string)requestData["region_handle"]);
  166. responseData["sim_ip"] = simData.ExternalEndPoint.Address.ToString();
  167. responseData["sim_port"] = simData.ExternalEndPoint.Port.ToString();
  168. //responseData["server_uri"] = simData.serverURI;
  169. responseData["http_port"] = simData.HttpPort.ToString();
  170. //responseData["remoting_port"] = simData.remotingPort.ToString();
  171. responseData["region_locx"] = simData.RegionLocX.ToString();
  172. responseData["region_locy"] = simData.RegionLocY.ToString();
  173. responseData["region_UUID"] = simData.RegionID.ToString();
  174. responseData["region_name"] = simData.RegionName;
  175. responseData["region_secret"] = simData.regionSecret;
  176. }
  177. XmlRpcResponse response = new XmlRpcResponse();
  178. response.Value = responseData;
  179. return response;
  180. }
  181. }
  182. }