OGS1GridServices.cs 39 KB

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