1
0

GridServicesConnector.cs 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794
  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 log4net;
  28. using System;
  29. using System.Collections.Generic;
  30. using System.Reflection;
  31. using Nini.Config;
  32. using OpenSim.Framework;
  33. using OpenSim.Services.Interfaces;
  34. using GridRegion = OpenSim.Services.Interfaces.GridRegion;
  35. using OpenSim.Server.Base;
  36. using OpenMetaverse;
  37. namespace OpenSim.Services.Connectors
  38. {
  39. public class GridServicesConnector : BaseServiceConnector, IGridService
  40. {
  41. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  42. private string m_ServerURI = String.Empty;
  43. private string m_ServerGridURI = string.Empty;
  44. public GridServicesConnector()
  45. {
  46. }
  47. public GridServicesConnector(string serverURI)
  48. {
  49. m_ServerURI = serverURI.TrimEnd('/');
  50. m_ServerGridURI = serverURI + "/grid";
  51. }
  52. public GridServicesConnector(IConfigSource source)
  53. {
  54. Initialise(source);
  55. }
  56. public virtual void Initialise(IConfigSource source)
  57. {
  58. IConfig gridConfig = source.Configs["GridService"];
  59. if (gridConfig is null)
  60. {
  61. m_log.Error("[GRID CONNECTOR]: GridService missing from OpenSim.ini");
  62. throw new Exception("Grid connector init error");
  63. }
  64. string serviceURI = gridConfig.GetString("GridServerURI", string.Empty);
  65. if (serviceURI.Length == 0)
  66. {
  67. m_log.Error("[GRID CONNECTOR]: No Server URI named in section GridService");
  68. throw new Exception("Grid connector init error");
  69. }
  70. m_ServerURI = serviceURI.TrimEnd('/');
  71. m_ServerGridURI = serviceURI + "/grid";
  72. base.Initialise(source, "GridService");
  73. }
  74. #region IGridService
  75. public string RegisterRegion(UUID scopeID, GridRegion regionInfo)
  76. {
  77. Dictionary<string, object> rinfo = regionInfo.ToKeyValuePairs();
  78. Dictionary<string, object> sendData = new()
  79. {
  80. ["SCOPEID"] = scopeID.ToString(),
  81. ["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString(),
  82. ["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString(),
  83. ["METHOD"] = "register"
  84. };
  85. foreach (KeyValuePair<string, object> kvp in rinfo)
  86. sendData[kvp.Key] = (string)kvp.Value;
  87. string reqString = ServerUtils.BuildQueryString(sendData);
  88. // m_log.DebugFormat("[GRID CONNECTOR]: queryString = {0}", reqString);
  89. try
  90. {
  91. string reply = SynchronousRestFormsRequester.MakePostRequest(m_ServerGridURI, reqString, m_Auth);
  92. if (reply.Length > 0)
  93. {
  94. Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
  95. if (replyData.TryGetValue("Result", out object tmpo) && tmpo is string tmps)
  96. {
  97. if(tmps.Equals("success", StringComparison.CurrentCultureIgnoreCase))
  98. return string.Empty;
  99. if (tmps.Equals("failure", StringComparison.CurrentCultureIgnoreCase))
  100. {
  101. m_log.Error(
  102. $"[GRID CONNECTOR]: Registration failed: {replyData["Message"]} when contacting {m_ServerGridURI}");
  103. return replyData["Message"].ToString();
  104. }
  105. else
  106. {
  107. m_log.Error(
  108. $"[GRID CONNECTOR]: unexpected result {tmps} when contacting {m_ServerGridURI}");
  109. return "Unexpected result " + tmps;
  110. }
  111. }
  112. else
  113. {
  114. m_log.Error(
  115. $"[GRID CONNECTOR]: reply data does not contain result field when contacting {m_ServerGridURI}");
  116. }
  117. }
  118. else
  119. {
  120. m_log.Error(
  121. $"[GRID CONNECTOR]: RegisterRegion received null reply when contacting grid server at {m_ServerGridURI}");
  122. }
  123. }
  124. catch (Exception e)
  125. {
  126. m_log.Error($"[GRID CONNECTOR]: Exception when contacting grid server at {m_ServerGridURI}: {e.Message}");
  127. }
  128. return "Error communicating with the grid service at " + m_ServerGridURI;
  129. }
  130. public bool DeregisterRegion(UUID regionID)
  131. {
  132. Dictionary<string, object> sendData = new()
  133. {
  134. ["REGIONID"] = regionID.ToString(),
  135. ["METHOD"] = "deregister"
  136. };
  137. try
  138. {
  139. string reply = SynchronousRestFormsRequester.MakePostRequest(m_ServerGridURI, ServerUtils.BuildQueryString(sendData), m_Auth);
  140. if (reply.Length > 0)
  141. {
  142. Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
  143. return replyData.TryGetValue("Result", out object tmpo) &&
  144. tmpo is string rs &&
  145. rs.Equals("success", StringComparison.InvariantCultureIgnoreCase);
  146. }
  147. else
  148. m_log.Debug("[GRID CONNECTOR]: DeregisterRegion received empty reply");
  149. }
  150. catch (Exception e)
  151. {
  152. m_log.Error($"[GRID CONNECTOR]: Exception when contacting grid server at {m_ServerGridURI}: {e.Message}");
  153. }
  154. return false;
  155. }
  156. public List<GridRegion> GetNeighbours(UUID scopeID, UUID regionID)
  157. {
  158. Dictionary<string, object> sendData = new()
  159. {
  160. ["SCOPEID"] = scopeID.ToString(),
  161. ["REGIONID"] = regionID.ToString(),
  162. ["METHOD"] = "get_neighbours"
  163. };
  164. try
  165. {
  166. string reply = SynchronousRestFormsRequester.MakePostRequest(
  167. m_ServerGridURI,
  168. ServerUtils.BuildQueryString(sendData), m_Auth);
  169. Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
  170. //m_log.DebugFormat("[GRID CONNECTOR]: get neighbours returned {0} elements", replyData.Values.Count);
  171. if (replyData.Count > 0)
  172. {
  173. List<GridRegion> rinfos = [];
  174. foreach (object r in replyData.Values)
  175. {
  176. if (r is Dictionary<string, object> dr)
  177. {
  178. GridRegion rinfo = new GridRegion(dr);
  179. rinfos.Add(rinfo);
  180. }
  181. }
  182. return rinfos;
  183. }
  184. }
  185. catch (Exception e)
  186. {
  187. m_log.Error($"[GRID CONNECTOR]: GetNeighbours Exception when contacting grid server at {m_ServerGridURI}: {e.Message}");
  188. }
  189. return [];
  190. }
  191. public GridRegion GetRegionByUUID(UUID scopeID, UUID regionID)
  192. {
  193. Dictionary<string, object> sendData = new()
  194. {
  195. ["SCOPEID"] = scopeID.ToString(),
  196. ["REGIONID"] = regionID.ToString(),
  197. ["METHOD"] = "get_region_by_uuid"
  198. };
  199. try
  200. {
  201. string reply = SynchronousRestFormsRequester.MakePostRequest(m_ServerGridURI, ServerUtils.BuildQueryString(sendData), m_Auth);
  202. if (reply.Length > 0)
  203. {
  204. Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
  205. if(replyData.TryGetValue("result", out object tmpo) && tmpo is Dictionary<string, object> td)
  206. return new GridRegion(td);
  207. //else
  208. // m_log.Debug($"[GRID CONNECTOR]: GetRegionByUUID {scopeID}, {regionID} received empty result response");
  209. }
  210. else
  211. m_log.Debug($"[GRID CONNECTOR]: GetRegionByUUID received empty reply for {scopeID}, {regionID}");
  212. }
  213. catch (Exception e)
  214. {
  215. m_log.Debug($"[GRID CONNECTOR]: Exception when contacting grid server at {m_ServerGridURI}: {e.Message}");
  216. }
  217. return null;
  218. }
  219. public GridRegion GetRegionByHandle(UUID scopeID, ulong regionhandle)
  220. {
  221. Util.RegionHandleToWorldLoc(regionhandle, out uint x, out uint y);
  222. return GetRegionByPosition(scopeID, (int)x, (int)y);
  223. }
  224. public GridRegion GetRegionByPosition(UUID scopeID, int x, int y)
  225. {
  226. Dictionary<string, object> sendData = new()
  227. {
  228. ["SCOPEID"] = scopeID.ToString(),
  229. ["X"] = x.ToString(),
  230. ["Y"] = y.ToString(),
  231. ["METHOD"] = "get_region_by_position"
  232. };
  233. try
  234. {
  235. string reply = SynchronousRestFormsRequester.MakePostRequest(
  236. m_ServerGridURI,
  237. ServerUtils.BuildQueryString(sendData), m_Auth);
  238. if (reply.Length > 0)
  239. {
  240. Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
  241. if(replyData.TryGetValue("result", out object tmpo) && tmpo is Dictionary<string, object> td)
  242. return new GridRegion(td);
  243. //else
  244. // m_log.Debug($"[GRID CONNECTOR]: GetRegionByPosition {scopeID}, {x}-{y} received empty result response");
  245. }
  246. else
  247. m_log.Debug($"[GRID CONNECTOR]: GetRegionByPosition {scopeID}, {x}-{y} received empty response");
  248. }
  249. catch (Exception e)
  250. {
  251. m_log.Debug($"[GRID CONNECTOR]: Exception when contacting grid server at {m_ServerGridURI}: {e.Message}");
  252. }
  253. return null;
  254. }
  255. public GridRegion GetRegionByName(UUID scopeID, string regionName)
  256. {
  257. Dictionary<string, object> sendData = new()
  258. {
  259. ["SCOPEID"] = scopeID.ToString(),
  260. ["NAME"] = regionName,
  261. ["METHOD"] = "get_region_by_name"
  262. };
  263. try
  264. {
  265. string reply = SynchronousRestFormsRequester.MakePostRequest(
  266. m_ServerGridURI,
  267. ServerUtils.BuildQueryString(sendData), m_Auth);
  268. if (reply.Length > 0)
  269. {
  270. Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
  271. if(replyData.TryGetValue("result", out object tmpo) && tmpo is Dictionary<string, object> td)
  272. return new GridRegion(td);
  273. //else
  274. // m_log.DebugFormat("$[GRID CONNECTOR]: GetRegionByName {scopeID}, {regionName} received empty result");
  275. }
  276. else
  277. m_log.DebugFormat("$[GRID CONNECTOR]: GetRegionByName {scopeID}, {regionName} received empty reply");
  278. }
  279. catch (Exception e)
  280. {
  281. m_log.DebugFormat("[GRID CONNECTOR]: GetRegionByName, Exception when contacting grid server at {0}: {1}", m_ServerGridURI, e.Message);
  282. }
  283. return null;
  284. }
  285. public GridRegion GetLocalRegionByName(UUID scopeID, string regionName)
  286. {
  287. Dictionary<string, object> sendData = new()
  288. {
  289. ["SCOPEID"] = scopeID.ToString(),
  290. ["NAME"] = regionName,
  291. ["METHOD"] = "get_localregion_by_name"
  292. };
  293. try
  294. {
  295. string reply = SynchronousRestFormsRequester.MakePostRequest(
  296. m_ServerGridURI,
  297. ServerUtils.BuildQueryString(sendData), m_Auth);
  298. if (reply.Length > 0)
  299. {
  300. Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
  301. if(replyData.TryGetValue("result", out object tmpo) && tmpo is Dictionary<string, object> td)
  302. return new GridRegion(td);
  303. //else
  304. // m_log.DebugFormat("$[GRID CONNECTOR]: GetLocalRegionByName {scopeID}, {regionName} received empty result");
  305. }
  306. else
  307. m_log.DebugFormat("$[GRID CONNECTOR]: GetLocalRegionByName {scopeID}, {regionName} received empty reply");
  308. }
  309. catch (Exception e)
  310. {
  311. m_log.Debug($"[GRID CONNECTOR]: GetLocalRegionByName, Exception when contacting grid server at {m_ServerGridURI}: {e.Message}");
  312. }
  313. return null;
  314. }
  315. public GridRegion GetRegionByURI(UUID scopeID, RegionURI uri)
  316. {
  317. return null;
  318. }
  319. public GridRegion GetLocalRegionByURI(UUID scopeID, RegionURI uri)
  320. {
  321. return null;
  322. }
  323. public List<GridRegion> GetRegionsByName(UUID scopeID, string name, int maxNumber)
  324. {
  325. Dictionary<string, object> sendData = new()
  326. {
  327. ["SCOPEID"] = scopeID.ToString(),
  328. ["NAME"] = name,
  329. ["MAX"] = maxNumber.ToString(),
  330. ["METHOD"] = "get_regions_by_name"
  331. };
  332. try
  333. {
  334. string reply = SynchronousRestFormsRequester.MakePostRequest(
  335. m_ServerGridURI,
  336. ServerUtils.BuildQueryString(sendData), m_Auth);
  337. if (reply.Length > 0)
  338. {
  339. Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
  340. if (replyData.Count > 0)
  341. {
  342. List<GridRegion> rinfos = [];
  343. foreach (object r in replyData.Values)
  344. {
  345. if (r is Dictionary<string, object> dr)
  346. {
  347. GridRegion rinfo = new GridRegion(dr);
  348. rinfos.Add(rinfo);
  349. }
  350. }
  351. return rinfos;
  352. }
  353. else
  354. m_log.Debug($"[GRID CONNECTOR]: GetRegionsByName {scopeID}, {name}, {maxNumber} received empty reply data");
  355. }
  356. else
  357. m_log.Debug($"[GRID CONNECTOR]: GetRegionsByName {scopeID}, {name}, {maxNumber} received empty reply");
  358. }
  359. catch (Exception e)
  360. {
  361. m_log.Debug($"[GRID CONNECTOR]: Exception when contacting grid server at {m_ServerGridURI}: {e.Message}");
  362. }
  363. return [];
  364. }
  365. public List<GridRegion> GetRegionsByURI(UUID scopeID, RegionURI uri, int maxNumber)
  366. {
  367. return null;
  368. }
  369. public List<GridRegion> GetRegionRange(UUID scopeID, int xmin, int xmax, int ymin, int ymax)
  370. {
  371. Dictionary<string, object> sendData = new()
  372. {
  373. ["SCOPEID"] = scopeID.ToString(),
  374. ["XMIN"] = xmin.ToString(),
  375. ["XMAX"] = xmax.ToString(),
  376. ["YMIN"] = ymin.ToString(),
  377. ["YMAX"] = ymax.ToString(),
  378. ["METHOD"] = "get_region_range"
  379. };
  380. try
  381. {
  382. string reply = SynchronousRestFormsRequester.MakePostRequest(
  383. m_ServerGridURI,
  384. ServerUtils.BuildQueryString(sendData), m_Auth);
  385. //m_log.DebugFormat("[GRID CONNECTOR]: GetRegionRange reply was {0}", reply);
  386. if (reply.Length > 0)
  387. {
  388. Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
  389. if (replyData.Count > 0)
  390. {
  391. List<GridRegion> rinfos = [];
  392. foreach (object r in replyData.Values)
  393. {
  394. if (r is Dictionary<string, object> dr)
  395. {
  396. GridRegion rinfo = new(dr);
  397. rinfos.Add(rinfo);
  398. }
  399. }
  400. return rinfos;
  401. }
  402. else
  403. m_log.Debug($"[GRID CONNECTOR]: GetRegionRange {scopeID}, {xmin}-{xmax} {ymin}-{ymax} received null response");
  404. }
  405. else
  406. m_log.Debug("[GRID CONNECTOR]: GetRegionRange received empty reply");
  407. }
  408. catch (Exception e)
  409. {
  410. m_log.Debug($"[GRID CONNECTOR]: Exception when contacting grid server at {m_ServerGridURI}: {e.Message}");
  411. }
  412. return [];
  413. }
  414. public List<GridRegion> GetDefaultRegions(UUID scopeID)
  415. {
  416. Dictionary<string, object> sendData = new()
  417. {
  418. ["SCOPEID"] = scopeID.ToString(),
  419. ["METHOD"] = "get_default_regions"
  420. };
  421. try
  422. {
  423. string reply = SynchronousRestFormsRequester.MakePostRequest(
  424. m_ServerGridURI,
  425. ServerUtils.BuildQueryString(sendData), m_Auth);
  426. //m_log.DebugFormat("[GRID CONNECTOR]: reply was {0}", reply);
  427. if (reply.Length > 0)
  428. {
  429. Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
  430. if (replyData.Count > 0)
  431. {
  432. List<GridRegion> rinfos = [];
  433. Dictionary<string, object>.ValueCollection rinfosList = replyData.Values;
  434. foreach (object r in rinfosList)
  435. {
  436. if (r is Dictionary<string, object>)
  437. {
  438. GridRegion rinfo = new GridRegion((Dictionary<string, object>)r);
  439. rinfos.Add(rinfo);
  440. }
  441. }
  442. return rinfos;
  443. }
  444. else
  445. m_log.Debug($"[GRID CONNECTOR]: GetDefaultRegions {scopeID} received empty response");
  446. }
  447. else
  448. m_log.Debug("[GRID CONNECTOR]: GetDefaultRegions received empty reply");
  449. }
  450. catch (Exception e)
  451. {
  452. m_log.Debug($"[GRID CONNECTOR]: GetDefaultRegions Exception when contacting grid server at {m_ServerGridURI}: {e.Message}");
  453. }
  454. return [];
  455. }
  456. public List<GridRegion> GetDefaultHypergridRegions(UUID scopeID)
  457. {
  458. Dictionary<string, object> sendData = new()
  459. {
  460. ["SCOPEID"] = scopeID.ToString(),
  461. ["METHOD"] = "get_default_hypergrid_regions"
  462. };
  463. try
  464. {
  465. string reply = SynchronousRestFormsRequester.MakePostRequest(
  466. m_ServerGridURI,
  467. ServerUtils.BuildQueryString(sendData), m_Auth);
  468. //m_log.DebugFormat("[GRID CONNECTOR]: reply was {0}", reply);
  469. if (reply.Length > 0)
  470. {
  471. Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
  472. if (replyData.Count > 0)
  473. {
  474. List<GridRegion> rinfos = [];
  475. foreach (object r in replyData.Values)
  476. {
  477. if (r is Dictionary<string, object> dr)
  478. {
  479. GridRegion rinfo = new(dr);
  480. rinfos.Add(rinfo);
  481. }
  482. }
  483. return rinfos;
  484. }
  485. else
  486. m_log.Debug($"[GRID CONNECTOR]: GetDefaultHypergridRegions {scopeID} received empty response");
  487. }
  488. else
  489. m_log.Debug("[GRID CONNECTOR]: GetDefaultHypergridRegions received empty reply");
  490. }
  491. catch (Exception e)
  492. {
  493. m_log.Debug($"[GRID CONNECTOR]: Exception when contacting grid server at {m_ServerGridURI}: {e.Message}");
  494. }
  495. return [];
  496. }
  497. public List<GridRegion> GetFallbackRegions(UUID scopeID, int x, int y)
  498. {
  499. Dictionary<string, object> sendData = new()
  500. {
  501. ["SCOPEID"] = scopeID.ToString(),
  502. ["X"] = x.ToString(),
  503. ["Y"] = y.ToString(),
  504. ["METHOD"] = "get_fallback_regions"
  505. };
  506. try
  507. {
  508. string reply = SynchronousRestFormsRequester.MakePostRequest(
  509. m_ServerGridURI,
  510. ServerUtils.BuildQueryString(sendData), m_Auth);
  511. //m_log.DebugFormat("[GRID CONNECTOR]: reply was {0}", reply);
  512. if (reply.Length > 0)
  513. {
  514. Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
  515. if (replyData.Count > 0)
  516. {
  517. List<GridRegion> rinfos = [];
  518. foreach (object r in replyData.Values)
  519. {
  520. if (r is Dictionary<string, object> dr)
  521. {
  522. GridRegion rinfo = new(dr);
  523. rinfos.Add(rinfo);
  524. }
  525. }
  526. return rinfos;
  527. }
  528. else
  529. m_log.Debug($"[GRID CONNECTOR]: GetFallbackRegions {scopeID}, {x}-{y} received empty response");
  530. }
  531. else
  532. m_log.Debug("[GRID CONNECTOR]: GetFallbackRegions received empty reply");
  533. }
  534. catch (Exception e)
  535. {
  536. m_log.Debug($"[GRID CONNECTOR]: Exception when contacting grid server at {m_ServerGridURI}: {e.Message}");
  537. }
  538. return [];
  539. }
  540. public List<GridRegion> GetOnlineRegions(UUID scopeID, int x, int y, int maxCount)
  541. {
  542. Dictionary<string, object> sendData = new()
  543. {
  544. ["SCOPEID"] = scopeID.ToString(),
  545. ["X"] = x.ToString(),
  546. ["Y"] = y.ToString(),
  547. ["MC"] = maxCount.ToString(),
  548. ["METHOD"] = "get_online_regions"
  549. };
  550. try
  551. {
  552. string reply = SynchronousRestFormsRequester.MakePostRequest(m_ServerGridURI, ServerUtils.BuildQueryString(sendData), m_Auth);
  553. //m_log.DebugFormat("[GRID CONNECTOR]: reply was {0}", reply);
  554. if (reply.Length > 0)
  555. {
  556. Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
  557. if (replyData.Count > 0)
  558. {
  559. List<GridRegion> rinfos = [];
  560. foreach (object r in replyData.Values)
  561. {
  562. if (r is Dictionary<string, object> dr)
  563. {
  564. GridRegion rinfo = new(dr);
  565. rinfos.Add(rinfo);
  566. }
  567. }
  568. return rinfos;
  569. }
  570. else
  571. m_log.Debug($"[GRID CONNECTOR]: GetOnlineRegions {scopeID}, {x}-{y} received empty response");
  572. }
  573. else
  574. m_log.Debug("[GRID CONNECTOR]: GetOnlineRegions received empty reply");
  575. }
  576. catch (Exception e)
  577. {
  578. m_log.Debug($"[GRID CONNECTOR]: Exception when contacting grid server at {m_ServerGridURI}: {e.Message}");
  579. }
  580. return [];
  581. }
  582. public List<GridRegion> GetHyperlinks(UUID scopeID)
  583. {
  584. Dictionary<string, object> sendData = new()
  585. {
  586. ["SCOPEID"] = scopeID.ToString(),
  587. ["METHOD"] = "get_hyperlinks"
  588. };
  589. try
  590. {
  591. string reply = SynchronousRestFormsRequester.MakePostRequest(
  592. m_ServerGridURI,
  593. ServerUtils.BuildQueryString(sendData), m_Auth);
  594. //m_log.DebugFormat("[GRID CONNECTOR]: reply was {0}", reply);
  595. if (reply.Length > 0)
  596. {
  597. Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
  598. if (replyData.Count > 0)
  599. {
  600. List<GridRegion> rinfos = [];
  601. foreach (object r in replyData.Values)
  602. {
  603. if (r is Dictionary<string, object> dr)
  604. {
  605. GridRegion rinfo = new(dr);
  606. rinfos.Add(rinfo);
  607. }
  608. }
  609. return rinfos;
  610. }
  611. else
  612. m_log.Debug($"[GRID CONNECTOR]: GetHyperlinks {scopeID} received empty response");
  613. }
  614. else
  615. m_log.Debug("[GRID CONNECTOR]: GetHyperlinks received empty reply");
  616. }
  617. catch (Exception e)
  618. {
  619. m_log.Debug($"[GRID CONNECTOR]: Exception when contacting grid server at {m_ServerGridURI}: {e.Message}");
  620. }
  621. return [];
  622. }
  623. public int GetRegionFlags(UUID scopeID, UUID regionID)
  624. {
  625. Dictionary<string, object> sendData = new()
  626. {
  627. ["SCOPEID"] = scopeID.ToString(),
  628. ["REGIONID"] = regionID.ToString(),
  629. ["METHOD"] = "get_region_flags"
  630. };
  631. try
  632. {
  633. string reply = SynchronousRestFormsRequester.MakePostRequest(
  634. m_ServerGridURI,
  635. ServerUtils.BuildQueryString(sendData), m_Auth);
  636. if (reply.Length > 0)
  637. {
  638. Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
  639. if (replyData.TryGetValue("result", out object tmpo) &&
  640. tmpo is string tmps &&
  641. Int32.TryParse(tmps, out int flags))
  642. return flags;
  643. else
  644. m_log.Debug($"[GRID CONNECTOR]: GetRegionFlags {scopeID}, {regionID} received invalid response");
  645. }
  646. else
  647. m_log.Debug("[GRID CONNECTOR]: GetRegionFlags received empty reply");
  648. }
  649. catch (Exception e)
  650. {
  651. m_log.Debug($"[GRID CONNECTOR]: Exception when contacting grid server at {m_ServerGridURI}: {e.Message}");
  652. }
  653. return -1;
  654. }
  655. public Dictionary<string, object> GetExtraFeatures()
  656. {
  657. Dictionary<string, object> sendData = new()
  658. {
  659. ["METHOD"] = "get_grid_extra_features"
  660. };
  661. try
  662. {
  663. string reply = SynchronousRestFormsRequester.MakePostRequest(
  664. m_ServerGridURI,
  665. ServerUtils.BuildQueryString(sendData), m_Auth);
  666. if (reply.Length > 0)
  667. {
  668. Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
  669. if (replyData.Count > 0)
  670. {
  671. Dictionary<string, object> extraFeatures = [];
  672. foreach (string key in replyData.Keys)
  673. {
  674. extraFeatures[key] = replyData[key].ToString();
  675. }
  676. return extraFeatures;
  677. }
  678. }
  679. else
  680. m_log.Debug("[GRID CONNECTOR]: GetExtraServiceURLs received empty reply");
  681. }
  682. catch (Exception e)
  683. {
  684. m_log.Debug($"[GRID CONNECTOR]: GetExtraFeatures - Exception when contacting grid server at {m_ServerGridURI}: {e.Message}");
  685. }
  686. return [];
  687. }
  688. #endregion
  689. }
  690. }