OGS1GridServices.cs 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946
  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 log4net;
  34. using Nwc.XmlRpc;
  35. using OpenMetaverse;
  36. using OpenSim.Framework;
  37. using OpenSim.Framework.Communications;
  38. using OpenSim.Framework.Servers.HttpServer;
  39. using OpenSim.Region.Communications.Local;
  40. namespace OpenSim.Region.Communications.OGS1
  41. {
  42. public class OGS1GridServices : IGridServices
  43. {
  44. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  45. private bool m_useRemoteRegionCache = true;
  46. /// <summary>
  47. /// Encapsulate local backend services for manipulation of local regions
  48. /// </summary>
  49. private LocalBackEndServices m_localBackend = new LocalBackEndServices();
  50. private Dictionary<ulong, RegionInfo> m_remoteRegionInfoCache = new Dictionary<ulong, RegionInfo>();
  51. // private List<SimpleRegionInfo> m_knownRegions = new List<SimpleRegionInfo>();
  52. private Dictionary<ulong, int> m_deadRegionCache = new Dictionary<ulong, int>();
  53. private Dictionary<string, string> m_queuedGridSettings = new Dictionary<string, string>();
  54. private List<RegionInfo> m_regionsOnInstance = new List<RegionInfo>();
  55. public BaseHttpServer httpListener;
  56. public NetworkServersInfo serversInfo;
  57. public BaseHttpServer httpServer;
  58. public string gdebugRegionName
  59. {
  60. get { return m_localBackend.gdebugRegionName; }
  61. set { m_localBackend.gdebugRegionName = value; }
  62. }
  63. public string rdebugRegionName
  64. {
  65. get { return _rdebugRegionName; }
  66. set { _rdebugRegionName = value; }
  67. }
  68. private string _rdebugRegionName = String.Empty;
  69. public bool RegionLoginsEnabled
  70. {
  71. get { return m_localBackend.RegionLoginsEnabled; }
  72. set { m_localBackend.RegionLoginsEnabled = value; }
  73. }
  74. /// <summary>
  75. /// Contructor. Adds "expect_user" and "check" xmlrpc method handlers
  76. /// </summary>
  77. /// <param name="servers_info"></param>
  78. /// <param name="httpServe"></param>
  79. public OGS1GridServices(NetworkServersInfo servers_info, BaseHttpServer httpServe)
  80. {
  81. serversInfo = servers_info;
  82. httpServer = httpServe;
  83. //Respond to Grid Services requests
  84. // httpServer.AddXmlRPCHandler("expect_user", ExpectUser);
  85. // httpServer.AddXmlRPCHandler("logoff_user", LogOffUser);
  86. httpServer.AddXmlRPCHandler("check", PingCheckReply);
  87. // Retired into the new service connectors, 6/14/09
  88. //httpServer.AddXmlRPCHandler("land_data", LandData);
  89. }
  90. // see IGridServices
  91. public RegionCommsListener RegisterRegion(RegionInfo regionInfo)
  92. {
  93. if (m_regionsOnInstance.Contains(regionInfo))
  94. {
  95. m_log.Debug("[OGS1 GRID SERVICES] Foobar! Caller is confused, region already registered " + regionInfo.RegionName);
  96. Exception e = new Exception(String.Format("Unable to register region"));
  97. throw e;
  98. }
  99. m_regionsOnInstance.Add(regionInfo);
  100. m_log.InfoFormat(
  101. "[OGS1 GRID SERVICES]: Attempting to register region {0} with grid at {1}",
  102. regionInfo.RegionName, serversInfo.GridURL);
  103. Hashtable GridParams = new Hashtable();
  104. // Login / Authentication
  105. GridParams["authkey"] = serversInfo.GridSendKey;
  106. GridParams["recvkey"] = serversInfo.GridRecvKey;
  107. GridParams["UUID"] = regionInfo.RegionID.ToString();
  108. GridParams["sim_ip"] = regionInfo.ExternalHostName;
  109. GridParams["sim_port"] = regionInfo.InternalEndPoint.Port.ToString();
  110. GridParams["region_locx"] = regionInfo.RegionLocX.ToString();
  111. GridParams["region_locy"] = regionInfo.RegionLocY.ToString();
  112. GridParams["sim_name"] = regionInfo.RegionName;
  113. GridParams["http_port"] = serversInfo.HttpListenerPort.ToString();
  114. GridParams["remoting_port"] = ConfigSettings.DefaultRegionRemotingPort.ToString();
  115. GridParams["map-image-id"] = regionInfo.RegionSettings.TerrainImageID.ToString();
  116. GridParams["originUUID"] = regionInfo.originRegionID.ToString();
  117. GridParams["server_uri"] = regionInfo.ServerURI;
  118. GridParams["region_secret"] = regionInfo.regionSecret;
  119. GridParams["major_interface_version"] = VersionInfo.MajorInterfaceVersion.ToString();
  120. if (regionInfo.MasterAvatarAssignedUUID != UUID.Zero)
  121. GridParams["master_avatar_uuid"] = regionInfo.MasterAvatarAssignedUUID.ToString();
  122. else
  123. GridParams["master_avatar_uuid"] = regionInfo.EstateSettings.EstateOwner.ToString();
  124. GridParams["maturity"] = regionInfo.RegionSettings.Maturity.ToString();
  125. // Package into an XMLRPC Request
  126. ArrayList SendParams = new ArrayList();
  127. SendParams.Add(GridParams);
  128. // Send Request
  129. XmlRpcRequest GridReq = new XmlRpcRequest("simulator_login", SendParams);
  130. XmlRpcResponse GridResp;
  131. try
  132. {
  133. // The timeout should always be significantly larger than the timeout for the grid server to request
  134. // the initial status of the region before confirming registration.
  135. GridResp = GridReq.Send(serversInfo.GridURL, 90000);
  136. }
  137. catch (Exception e)
  138. {
  139. Exception e2
  140. = new Exception(
  141. String.Format(
  142. "Unable to register region with grid at {0}. Grid service not running?",
  143. serversInfo.GridURL),
  144. e);
  145. throw e2;
  146. }
  147. Hashtable GridRespData = (Hashtable)GridResp.Value;
  148. // Hashtable griddatahash = GridRespData;
  149. // Process Response
  150. if (GridRespData.ContainsKey("error"))
  151. {
  152. string errorstring = (string) GridRespData["error"];
  153. Exception e = new Exception(
  154. String.Format("Unable to connect to grid at {0}: {1}", serversInfo.GridURL, errorstring));
  155. throw e;
  156. }
  157. else
  158. {
  159. // m_knownRegions = RequestNeighbours(regionInfo.RegionLocX, regionInfo.RegionLocY);
  160. if (GridRespData.ContainsKey("allow_forceful_banlines"))
  161. {
  162. if ((string) GridRespData["allow_forceful_banlines"] != "TRUE")
  163. {
  164. //m_localBackend.SetForcefulBanlistsDisallowed(regionInfo.RegionHandle);
  165. if (!m_queuedGridSettings.ContainsKey("allow_forceful_banlines"))
  166. m_queuedGridSettings.Add("allow_forceful_banlines", "FALSE");
  167. }
  168. }
  169. m_log.InfoFormat(
  170. "[OGS1 GRID SERVICES]: Region {0} successfully registered with grid at {1}",
  171. regionInfo.RegionName, serversInfo.GridURL);
  172. }
  173. return m_localBackend.RegisterRegion(regionInfo);
  174. }
  175. // see IGridServices
  176. public bool DeregisterRegion(RegionInfo regionInfo)
  177. {
  178. Hashtable GridParams = new Hashtable();
  179. GridParams["UUID"] = regionInfo.RegionID.ToString();
  180. // Package into an XMLRPC Request
  181. ArrayList SendParams = new ArrayList();
  182. SendParams.Add(GridParams);
  183. // Send Request
  184. XmlRpcRequest GridReq = new XmlRpcRequest("simulator_after_region_moved", SendParams);
  185. XmlRpcResponse GridResp = null;
  186. try
  187. {
  188. GridResp = GridReq.Send(serversInfo.GridURL, 10000);
  189. }
  190. catch (Exception e)
  191. {
  192. Exception e2
  193. = new Exception(
  194. String.Format(
  195. "Unable to deregister region with grid at {0}. Grid service not running?",
  196. serversInfo.GridURL),
  197. e);
  198. throw e2;
  199. }
  200. Hashtable GridRespData = (Hashtable) GridResp.Value;
  201. // Hashtable griddatahash = GridRespData;
  202. // Process Response
  203. if (GridRespData != null && GridRespData.ContainsKey("error"))
  204. {
  205. string errorstring = (string)GridRespData["error"];
  206. m_log.Error("Unable to connect to grid: " + errorstring);
  207. return false;
  208. }
  209. return m_localBackend.DeregisterRegion(regionInfo);
  210. }
  211. public virtual Dictionary<string, string> GetGridSettings()
  212. {
  213. Dictionary<string, string> returnGridSettings = new Dictionary<string, string>();
  214. lock (m_queuedGridSettings)
  215. {
  216. foreach (string Dictkey in m_queuedGridSettings.Keys)
  217. {
  218. returnGridSettings.Add(Dictkey, m_queuedGridSettings[Dictkey]);
  219. }
  220. m_queuedGridSettings.Clear();
  221. }
  222. return returnGridSettings;
  223. }
  224. // see IGridServices
  225. public List<SimpleRegionInfo> RequestNeighbours(uint x, uint y)
  226. {
  227. Hashtable respData = MapBlockQuery((int) x - 1, (int) y - 1, (int) x + 1, (int) y + 1);
  228. List<SimpleRegionInfo> neighbours = new List<SimpleRegionInfo>();
  229. foreach (ArrayList neighboursList in respData.Values)
  230. {
  231. foreach (Hashtable neighbourData in neighboursList)
  232. {
  233. uint regX = Convert.ToUInt32(neighbourData["x"]);
  234. uint regY = Convert.ToUInt32(neighbourData["y"]);
  235. if ((x != regX) || (y != regY))
  236. {
  237. string simIp = (string) neighbourData["sim_ip"];
  238. uint port = Convert.ToUInt32(neighbourData["sim_port"]);
  239. // string externalUri = (string) neighbourData["sim_uri"];
  240. // string externalIpStr = String.Empty;
  241. try
  242. {
  243. // externalIpStr = Util.GetHostFromDNS(simIp).ToString();
  244. Util.GetHostFromDNS(simIp).ToString();
  245. }
  246. catch (SocketException e)
  247. {
  248. m_log.WarnFormat(
  249. "[OGS1 GRID SERVICES]: RequestNeighbours(): Lookup of neighbour {0} failed! Not including in neighbours list. {1}",
  250. simIp, e);
  251. continue;
  252. }
  253. SimpleRegionInfo sri = new SimpleRegionInfo(regX, regY, simIp, port);
  254. sri.RemotingPort = Convert.ToUInt32(neighbourData["remoting_port"]);
  255. if (neighbourData.ContainsKey("http_port"))
  256. {
  257. sri.HttpPort = Convert.ToUInt32(neighbourData["http_port"]);
  258. }
  259. else
  260. {
  261. m_log.Error("[OGS1 GRID SERVICES]: Couldn't find httpPort, using default 9000; please upgrade your grid-server to r7621 or later");
  262. sri.HttpPort = 9000; // that's the default and will probably be wrong
  263. }
  264. sri.RegionID = new UUID((string) neighbourData["uuid"]);
  265. neighbours.Add(sri);
  266. }
  267. }
  268. }
  269. return neighbours;
  270. }
  271. /// <summary>
  272. /// Request information about a region.
  273. /// </summary>
  274. /// <param name="regionHandle"></param>
  275. /// <returns>
  276. /// null on a failure to contact or get a response from the grid server
  277. /// FIXME: Might be nicer to return a proper exception here since we could inform the client more about the
  278. /// nature of the faiulre.
  279. /// </returns>
  280. public RegionInfo RequestNeighbourInfo(UUID Region_UUID)
  281. {
  282. // don't ask the gridserver about regions on this instance...
  283. foreach (RegionInfo info in m_regionsOnInstance)
  284. {
  285. if (info.RegionID == Region_UUID) return info;
  286. }
  287. // didn't find it so far, we have to go the long way
  288. RegionInfo regionInfo;
  289. Hashtable requestData = new Hashtable();
  290. requestData["region_UUID"] = Region_UUID.ToString();
  291. requestData["authkey"] = serversInfo.GridSendKey;
  292. ArrayList SendParams = new ArrayList();
  293. SendParams.Add(requestData);
  294. XmlRpcRequest gridReq = new XmlRpcRequest("simulator_data_request", SendParams);
  295. XmlRpcResponse gridResp = null;
  296. try
  297. {
  298. gridResp = gridReq.Send(serversInfo.GridURL, 3000);
  299. }
  300. catch (Exception e)
  301. {
  302. m_log.ErrorFormat(
  303. "[OGS1 GRID SERVICES]: Communication with the grid server at {0} failed, {1}",
  304. serversInfo.GridURL, e);
  305. return null;
  306. }
  307. Hashtable responseData = (Hashtable)gridResp.Value;
  308. if (responseData.ContainsKey("error"))
  309. {
  310. m_log.WarnFormat("[OGS1 GRID SERVICES]: Error received from grid server: {0}", responseData["error"]);
  311. return null;
  312. }
  313. regionInfo = buildRegionInfo(responseData, String.Empty);
  314. if ((m_useRemoteRegionCache) && (requestData.ContainsKey("regionHandle")))
  315. {
  316. m_remoteRegionInfoCache.Add(Convert.ToUInt64((string) requestData["regionHandle"]), regionInfo);
  317. }
  318. return regionInfo;
  319. }
  320. /// <summary>
  321. /// Request information about a region.
  322. /// </summary>
  323. /// <param name="regionHandle"></param>
  324. /// <returns></returns>
  325. public RegionInfo RequestNeighbourInfo(ulong regionHandle)
  326. {
  327. RegionInfo regionInfo = m_localBackend.RequestNeighbourInfo(regionHandle);
  328. if (regionInfo != null)
  329. {
  330. return regionInfo;
  331. }
  332. if ((!m_useRemoteRegionCache) || (!m_remoteRegionInfoCache.TryGetValue(regionHandle, out regionInfo)))
  333. {
  334. try
  335. {
  336. Hashtable requestData = new Hashtable();
  337. requestData["region_handle"] = regionHandle.ToString();
  338. requestData["authkey"] = serversInfo.GridSendKey;
  339. ArrayList SendParams = new ArrayList();
  340. SendParams.Add(requestData);
  341. XmlRpcRequest GridReq = new XmlRpcRequest("simulator_data_request", SendParams);
  342. XmlRpcResponse GridResp = GridReq.Send(serversInfo.GridURL, 3000);
  343. Hashtable responseData = (Hashtable) GridResp.Value;
  344. if (responseData.ContainsKey("error"))
  345. {
  346. m_log.Error("[OGS1 GRID SERVICES]: Error received from grid server: " + responseData["error"]);
  347. return null;
  348. }
  349. uint regX = Convert.ToUInt32((string) responseData["region_locx"]);
  350. uint regY = Convert.ToUInt32((string) responseData["region_locy"]);
  351. string externalHostName = (string) responseData["sim_ip"];
  352. uint simPort = Convert.ToUInt32(responseData["sim_port"]);
  353. string regionName = (string)responseData["region_name"];
  354. UUID regionID = new UUID((string)responseData["region_UUID"]);
  355. uint remotingPort = Convert.ToUInt32((string)responseData["remoting_port"]);
  356. uint httpPort = 9000;
  357. if (responseData.ContainsKey("http_port"))
  358. {
  359. httpPort = Convert.ToUInt32((string)responseData["http_port"]);
  360. }
  361. // Ok, so this is definitively the wrong place to do this, way too hard coded, but it doesn't seem we GET this info?
  362. string simURI = "http://" + externalHostName + ":" + simPort;
  363. // string externalUri = (string) responseData["sim_uri"];
  364. //IPEndPoint neighbourInternalEndPoint = new IPEndPoint(IPAddress.Parse(internalIpStr), (int) port);
  365. regionInfo = RegionInfo.Create(regionID, regionName, regX, regY, externalHostName, httpPort, simPort, remotingPort, simURI);
  366. if (m_useRemoteRegionCache)
  367. {
  368. lock (m_remoteRegionInfoCache)
  369. {
  370. if (!m_remoteRegionInfoCache.ContainsKey(regionHandle))
  371. {
  372. m_remoteRegionInfoCache.Add(regionHandle, regionInfo);
  373. }
  374. }
  375. }
  376. }
  377. catch (Exception e)
  378. {
  379. m_log.Error("[OGS1 GRID SERVICES]: " +
  380. "Region lookup failed for: " + regionHandle.ToString() +
  381. " - Is the GridServer down?" + e.ToString());
  382. return null;
  383. }
  384. }
  385. return regionInfo;
  386. }
  387. /// <summary>
  388. /// Get information about a neighbouring region
  389. /// </summary>
  390. /// <param name="regionHandle"></param>
  391. /// <returns></returns>
  392. public RegionInfo RequestNeighbourInfo(string name)
  393. {
  394. // Not implemented yet
  395. return null;
  396. }
  397. /// <summary>
  398. /// Get information about a neighbouring region
  399. /// </summary>
  400. /// <param name="regionHandle"></param>
  401. /// <returns></returns>
  402. public RegionInfo RequestNeighbourInfo(string host, uint port)
  403. {
  404. // Not implemented yet
  405. return null;
  406. }
  407. public RegionInfo RequestClosestRegion(string regionName)
  408. {
  409. if (m_useRemoteRegionCache)
  410. {
  411. foreach (RegionInfo ri in m_remoteRegionInfoCache.Values)
  412. {
  413. if (ri.RegionName == regionName)
  414. return ri;
  415. }
  416. }
  417. RegionInfo regionInfo = null;
  418. try
  419. {
  420. Hashtable requestData = new Hashtable();
  421. requestData["region_name_search"] = regionName;
  422. requestData["authkey"] = serversInfo.GridSendKey;
  423. ArrayList SendParams = new ArrayList();
  424. SendParams.Add(requestData);
  425. XmlRpcRequest GridReq = new XmlRpcRequest("simulator_data_request", SendParams);
  426. XmlRpcResponse GridResp = GridReq.Send(serversInfo.GridURL, 3000);
  427. Hashtable responseData = (Hashtable) GridResp.Value;
  428. if (responseData.ContainsKey("error"))
  429. {
  430. m_log.ErrorFormat("[OGS1 GRID SERVICES]: Error received from grid server: ", responseData["error"]);
  431. return null;
  432. }
  433. regionInfo = buildRegionInfo(responseData, "");
  434. if ((m_useRemoteRegionCache) && (!m_remoteRegionInfoCache.ContainsKey(regionInfo.RegionHandle)))
  435. m_remoteRegionInfoCache.Add(regionInfo.RegionHandle, regionInfo);
  436. }
  437. catch
  438. {
  439. m_log.Error("[OGS1 GRID SERVICES]: " +
  440. "Region lookup failed for: " + regionName +
  441. " - Is the GridServer down?");
  442. }
  443. return regionInfo;
  444. }
  445. /// <summary>
  446. ///
  447. /// </summary>
  448. /// <param name="minX"></param>
  449. /// <param name="minY"></param>
  450. /// <param name="maxX"></param>
  451. /// <param name="maxY"></param>
  452. /// <returns></returns>
  453. public List<MapBlockData> RequestNeighbourMapBlocks(int minX, int minY, int maxX, int maxY)
  454. {
  455. int temp = 0;
  456. if (minX > maxX)
  457. {
  458. temp = minX;
  459. minX = maxX;
  460. maxX = temp;
  461. }
  462. if (minY > maxY)
  463. {
  464. temp = minY;
  465. minY = maxY;
  466. maxY = temp;
  467. }
  468. Hashtable respData = MapBlockQuery(minX, minY, maxX, maxY);
  469. List<MapBlockData> neighbours = new List<MapBlockData>();
  470. foreach (ArrayList a in respData.Values)
  471. {
  472. foreach (Hashtable n in a)
  473. {
  474. MapBlockData neighbour = new MapBlockData();
  475. neighbour.X = Convert.ToUInt16(n["x"]);
  476. neighbour.Y = Convert.ToUInt16(n["y"]);
  477. neighbour.Name = (string) n["name"];
  478. neighbour.Access = Convert.ToByte(n["access"]);
  479. neighbour.RegionFlags = Convert.ToUInt32(n["region-flags"]);
  480. neighbour.WaterHeight = Convert.ToByte(n["water-height"]);
  481. neighbour.MapImageId = new UUID((string) n["map-image-id"]);
  482. neighbours.Add(neighbour);
  483. }
  484. }
  485. return neighbours;
  486. }
  487. /// <summary>
  488. /// Performs a XML-RPC query against the grid server returning mapblock information in the specified coordinates
  489. /// </summary>
  490. /// <remarks>REDUNDANT - OGS1 is to be phased out in favour of OGS2</remarks>
  491. /// <param name="minX">Minimum X value</param>
  492. /// <param name="minY">Minimum Y value</param>
  493. /// <param name="maxX">Maximum X value</param>
  494. /// <param name="maxY">Maximum Y value</param>
  495. /// <returns>Hashtable of hashtables containing map data elements</returns>
  496. private Hashtable MapBlockQuery(int minX, int minY, int maxX, int maxY)
  497. {
  498. Hashtable param = new Hashtable();
  499. param["xmin"] = minX;
  500. param["ymin"] = minY;
  501. param["xmax"] = maxX;
  502. param["ymax"] = maxY;
  503. IList parameters = new ArrayList();
  504. parameters.Add(param);
  505. try
  506. {
  507. XmlRpcRequest req = new XmlRpcRequest("map_block", parameters);
  508. XmlRpcResponse resp = req.Send(serversInfo.GridURL, 10000);
  509. Hashtable respData = (Hashtable) resp.Value;
  510. return respData;
  511. }
  512. catch (Exception e)
  513. {
  514. m_log.Error("MapBlockQuery XMLRPC failure: " + e);
  515. return new Hashtable();
  516. }
  517. }
  518. /// <summary>
  519. /// A ping / version check
  520. /// </summary>
  521. /// <param name="request"></param>
  522. /// <returns></returns>
  523. public XmlRpcResponse PingCheckReply(XmlRpcRequest request, IPEndPoint remoteClient)
  524. {
  525. XmlRpcResponse response = new XmlRpcResponse();
  526. Hashtable respData = new Hashtable();
  527. respData["online"] = "true";
  528. m_localBackend.PingCheckReply(respData);
  529. response.Value = respData;
  530. return response;
  531. }
  532. /// <summary>
  533. /// Received from the user server when a user starts logging in. This call allows
  534. /// the region to prepare for direct communication from the client. Sends back an empty
  535. /// xmlrpc response on completion.
  536. /// </summary>
  537. /// <param name="request"></param>
  538. /// <returns></returns>
  539. public XmlRpcResponse ExpectUser(XmlRpcRequest request)
  540. {
  541. Hashtable requestData = (Hashtable) request.Params[0];
  542. AgentCircuitData agentData = new AgentCircuitData();
  543. agentData.SessionID = new UUID((string) requestData["session_id"]);
  544. agentData.SecureSessionID = new UUID((string) requestData["secure_session_id"]);
  545. agentData.firstname = (string) requestData["firstname"];
  546. agentData.lastname = (string) requestData["lastname"];
  547. agentData.AgentID = new UUID((string) requestData["agent_id"]);
  548. agentData.circuitcode = Convert.ToUInt32(requestData["circuit_code"]);
  549. agentData.CapsPath = (string)requestData["caps_path"];
  550. ulong regionHandle = Convert.ToUInt64((string) requestData["regionhandle"]);
  551. // Appearance
  552. if (requestData["appearance"] != null)
  553. agentData.Appearance = new AvatarAppearance((Hashtable)requestData["appearance"]);
  554. m_log.DebugFormat(
  555. "[CLIENT]: Told by user service to prepare for a connection from {0} {1} {2}, circuit {3}",
  556. agentData.firstname, agentData.lastname, agentData.AgentID, agentData.circuitcode);
  557. if (requestData.ContainsKey("child_agent") && requestData["child_agent"].Equals("1"))
  558. {
  559. //m_log.Debug("[CLIENT]: Child agent detected");
  560. agentData.child = true;
  561. }
  562. else
  563. {
  564. //m_log.Debug("[CLIENT]: Main agent detected");
  565. agentData.startpos =
  566. new Vector3((float)Convert.ToDecimal((string)requestData["startpos_x"]),
  567. (float)Convert.ToDecimal((string)requestData["startpos_y"]),
  568. (float)Convert.ToDecimal((string)requestData["startpos_z"]));
  569. agentData.child = false;
  570. }
  571. XmlRpcResponse resp = new XmlRpcResponse();
  572. if (!RegionLoginsEnabled)
  573. {
  574. m_log.InfoFormat(
  575. "[CLIENT]: Denying access for user {0} {1} because region login is currently disabled",
  576. agentData.firstname, agentData.lastname);
  577. Hashtable respdata = new Hashtable();
  578. respdata["success"] = "FALSE";
  579. respdata["reason"] = "region login currently disabled";
  580. resp.Value = respdata;
  581. }
  582. else
  583. {
  584. RegionInfo[] regions = m_regionsOnInstance.ToArray();
  585. bool banned = false;
  586. for (int i = 0; i < regions.Length; i++)
  587. {
  588. if (regions[i] != null)
  589. {
  590. if (regions[i].RegionHandle == regionHandle)
  591. {
  592. if (regions[i].EstateSettings.IsBanned(agentData.AgentID))
  593. {
  594. banned = true;
  595. break;
  596. }
  597. }
  598. }
  599. }
  600. if (banned)
  601. {
  602. m_log.InfoFormat(
  603. "[CLIENT]: Denying access for user {0} {1} because user is banned",
  604. agentData.firstname, agentData.lastname);
  605. Hashtable respdata = new Hashtable();
  606. respdata["success"] = "FALSE";
  607. respdata["reason"] = "banned";
  608. resp.Value = respdata;
  609. }
  610. else
  611. {
  612. m_localBackend.TriggerExpectUser(regionHandle, agentData);
  613. Hashtable respdata = new Hashtable();
  614. respdata["success"] = "TRUE";
  615. resp.Value = respdata;
  616. }
  617. }
  618. return resp;
  619. }
  620. // Grid Request Processing
  621. /// <summary>
  622. /// Ooops, our Agent must be dead if we're getting this request!
  623. /// </summary>
  624. /// <param name="request"></param>
  625. /// <returns></returns>
  626. public XmlRpcResponse LogOffUser(XmlRpcRequest request)
  627. {
  628. m_log.Debug("[CONNECTION DEBUGGING]: LogOff User Called");
  629. Hashtable requestData = (Hashtable)request.Params[0];
  630. string message = (string)requestData["message"];
  631. UUID agentID = UUID.Zero;
  632. UUID RegionSecret = UUID.Zero;
  633. UUID.TryParse((string)requestData["agent_id"], out agentID);
  634. UUID.TryParse((string)requestData["region_secret"], out RegionSecret);
  635. ulong regionHandle = Convert.ToUInt64((string)requestData["regionhandle"]);
  636. m_localBackend.TriggerLogOffUser(regionHandle, agentID, RegionSecret,message);
  637. return new XmlRpcResponse();
  638. }
  639. public void NoteDeadRegion(ulong regionhandle)
  640. {
  641. lock (m_deadRegionCache)
  642. {
  643. if (m_deadRegionCache.ContainsKey(regionhandle))
  644. {
  645. m_deadRegionCache[regionhandle] = m_deadRegionCache[regionhandle] + 1;
  646. }
  647. else
  648. {
  649. m_deadRegionCache.Add(regionhandle, 1);
  650. }
  651. }
  652. }
  653. public LandData RequestLandData (ulong regionHandle, uint x, uint y)
  654. {
  655. m_log.DebugFormat("[OGS1 GRID SERVICES] requests land data in {0}, at {1}, {2}",
  656. regionHandle, x, y);
  657. LandData landData = m_localBackend.RequestLandData(regionHandle, x, y);
  658. if (landData == null)
  659. {
  660. Hashtable hash = new Hashtable();
  661. hash["region_handle"] = regionHandle.ToString();
  662. hash["x"] = x.ToString();
  663. hash["y"] = y.ToString();
  664. IList paramList = new ArrayList();
  665. paramList.Add(hash);
  666. try
  667. {
  668. // this might be cached, as we probably requested it just a moment ago...
  669. RegionInfo info = RequestNeighbourInfo(regionHandle);
  670. if (info != null) // just to be sure
  671. {
  672. XmlRpcRequest request = new XmlRpcRequest("land_data", paramList);
  673. string uri = "http://" + info.ExternalEndPoint.Address + ":" + info.HttpPort + "/";
  674. XmlRpcResponse response = request.Send(uri, 10000);
  675. if (response.IsFault)
  676. {
  677. m_log.ErrorFormat("[OGS1 GRID SERVICES] remote call returned an error: {0}", response.FaultString);
  678. }
  679. else
  680. {
  681. hash = (Hashtable)response.Value;
  682. try
  683. {
  684. landData = new LandData();
  685. landData.AABBMax = Vector3.Parse((string)hash["AABBMax"]);
  686. landData.AABBMin = Vector3.Parse((string)hash["AABBMin"]);
  687. landData.Area = Convert.ToInt32(hash["Area"]);
  688. landData.AuctionID = Convert.ToUInt32(hash["AuctionID"]);
  689. landData.Description = (string)hash["Description"];
  690. landData.Flags = Convert.ToUInt32(hash["Flags"]);
  691. landData.GlobalID = new UUID((string)hash["GlobalID"]);
  692. landData.Name = (string)hash["Name"];
  693. landData.OwnerID = new UUID((string)hash["OwnerID"]);
  694. landData.SalePrice = Convert.ToInt32(hash["SalePrice"]);
  695. landData.SnapshotID = new UUID((string)hash["SnapshotID"]);
  696. landData.UserLocation = Vector3.Parse((string)hash["UserLocation"]);
  697. m_log.DebugFormat("[OGS1 GRID SERVICES] Got land data for parcel {0}", landData.Name);
  698. }
  699. catch (Exception e)
  700. {
  701. m_log.Error("[OGS1 GRID SERVICES] Got exception while parsing land-data:", e);
  702. }
  703. }
  704. }
  705. else m_log.WarnFormat("[OGS1 GRID SERVICES] Couldn't find region with handle {0}", regionHandle);
  706. }
  707. catch (Exception e)
  708. {
  709. m_log.ErrorFormat("[OGS1 GRID SERVICES] Couldn't contact region {0}: {1}", regionHandle, e);
  710. }
  711. }
  712. return landData;
  713. }
  714. // Grid Request Processing
  715. /// <summary>
  716. /// Someone asked us about parcel-information
  717. /// </summary>
  718. /// <param name="request"></param>
  719. /// <returns></returns>
  720. public XmlRpcResponse LandData(XmlRpcRequest request, IPEndPoint remoteClient)
  721. {
  722. Hashtable requestData = (Hashtable)request.Params[0];
  723. ulong regionHandle = Convert.ToUInt64(requestData["region_handle"]);
  724. uint x = Convert.ToUInt32(requestData["x"]);
  725. uint y = Convert.ToUInt32(requestData["y"]);
  726. m_log.DebugFormat("[OGS1 GRID SERVICES]: Got XML reqeuest for land data at {0}, {1} in region {2}", x, y, regionHandle);
  727. LandData landData = m_localBackend.RequestLandData(regionHandle, x, y);
  728. Hashtable hash = new Hashtable();
  729. if (landData != null)
  730. {
  731. // for now, only push out the data we need for answering a ParcelInfoReqeust
  732. hash["AABBMax"] = landData.AABBMax.ToString();
  733. hash["AABBMin"] = landData.AABBMin.ToString();
  734. hash["Area"] = landData.Area.ToString();
  735. hash["AuctionID"] = landData.AuctionID.ToString();
  736. hash["Description"] = landData.Description;
  737. hash["Flags"] = landData.Flags.ToString();
  738. hash["GlobalID"] = landData.GlobalID.ToString();
  739. hash["Name"] = landData.Name;
  740. hash["OwnerID"] = landData.OwnerID.ToString();
  741. hash["SalePrice"] = landData.SalePrice.ToString();
  742. hash["SnapshotID"] = landData.SnapshotID.ToString();
  743. hash["UserLocation"] = landData.UserLocation.ToString();
  744. }
  745. XmlRpcResponse response = new XmlRpcResponse();
  746. response.Value = hash;
  747. return response;
  748. }
  749. public List<RegionInfo> RequestNamedRegions (string name, int maxNumber)
  750. {
  751. // no asking of the local backend first, here, as we have to ask the gridserver anyway.
  752. Hashtable hash = new Hashtable();
  753. hash["name"] = name;
  754. hash["maxNumber"] = maxNumber.ToString();
  755. IList paramList = new ArrayList();
  756. paramList.Add(hash);
  757. Hashtable result = XmlRpcSearchForRegionByName(paramList);
  758. if (result == null) return null;
  759. uint numberFound = Convert.ToUInt32(result["numFound"]);
  760. List<RegionInfo> infos = new List<RegionInfo>();
  761. for (int i = 0; i < numberFound; ++i)
  762. {
  763. string prefix = "region" + i + ".";
  764. RegionInfo info = buildRegionInfo(result, prefix);
  765. infos.Add(info);
  766. }
  767. return infos;
  768. }
  769. private RegionInfo buildRegionInfo(Hashtable responseData, string prefix)
  770. {
  771. uint regX = Convert.ToUInt32((string) responseData[prefix + "region_locx"]);
  772. uint regY = Convert.ToUInt32((string) responseData[prefix + "region_locy"]);
  773. string internalIpStr = (string) responseData[prefix + "sim_ip"];
  774. uint port = Convert.ToUInt32(responseData[prefix + "sim_port"]);
  775. IPEndPoint neighbourInternalEndPoint = new IPEndPoint(Util.GetHostFromDNS(internalIpStr), (int) port);
  776. RegionInfo regionInfo = new RegionInfo(regX, regY, neighbourInternalEndPoint, internalIpStr);
  777. regionInfo.RemotingPort = Convert.ToUInt32((string) responseData[prefix + "remoting_port"]);
  778. regionInfo.RemotingAddress = internalIpStr;
  779. if (responseData.ContainsKey(prefix + "http_port"))
  780. {
  781. regionInfo.HttpPort = Convert.ToUInt32((string) responseData[prefix + "http_port"]);
  782. }
  783. regionInfo.RegionID = new UUID((string) responseData[prefix + "region_UUID"]);
  784. regionInfo.RegionName = (string) responseData[prefix + "region_name"];
  785. regionInfo.RegionSettings.TerrainImageID = new UUID((string) responseData[prefix + "map_UUID"]);
  786. return regionInfo;
  787. }
  788. private Hashtable XmlRpcSearchForRegionByName(IList parameters)
  789. {
  790. try
  791. {
  792. XmlRpcRequest request = new XmlRpcRequest("search_for_region_by_name", parameters);
  793. XmlRpcResponse resp = request.Send(serversInfo.GridURL, 10000);
  794. Hashtable respData = (Hashtable) resp.Value;
  795. if (respData != null && respData.Contains("faultCode"))
  796. {
  797. m_log.WarnFormat("[OGS1 GRID SERVICES]: Got an error while contacting GridServer: {0}", respData["faultString"]);
  798. return null;
  799. }
  800. return respData;
  801. }
  802. catch (Exception e)
  803. {
  804. m_log.Error("[OGS1 GRID SERVICES]: MapBlockQuery XMLRPC failure: ", e);
  805. return null;
  806. }
  807. }
  808. }
  809. }