GridServerPostHandler.cs 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750
  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 Nini.Config;
  28. using log4net;
  29. using System;
  30. using System.Reflection;
  31. using System.IO;
  32. using System.Net;
  33. using System.Text;
  34. using System.Text.RegularExpressions;
  35. using System.Xml;
  36. using System.Xml.Serialization;
  37. using System.Collections.Generic;
  38. using OpenSim.Server.Base;
  39. using OpenSim.Services.Interfaces;
  40. using GridRegion = OpenSim.Services.Interfaces.GridRegion;
  41. using OpenSim.Framework;
  42. using OpenSim.Framework.ServiceAuth;
  43. using OpenSim.Framework.Servers.HttpServer;
  44. using OpenMetaverse;
  45. namespace OpenSim.Server.Handlers.Grid
  46. {
  47. public class GridServerPostHandler : BaseStreamHandler
  48. {
  49. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  50. #pragma warning disable 414
  51. private static string LogHeader = "[GRID HANDLER]";
  52. #pragma warning restore 414
  53. private IGridService m_GridService;
  54. public GridServerPostHandler(IGridService service, IServiceAuth auth) :
  55. base("POST", "/grid", auth)
  56. {
  57. m_GridService = service;
  58. }
  59. protected override byte[] ProcessRequest(string path, Stream requestData,
  60. IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
  61. {
  62. string body;
  63. using(StreamReader sr = new StreamReader(requestData))
  64. body = sr.ReadToEnd();
  65. body = body.Trim();
  66. //m_log.DebugFormat("[XXX]: query String: {0}", body);
  67. try
  68. {
  69. Dictionary<string, object> request =
  70. ServerUtils.ParseQueryString(body);
  71. if (!request.ContainsKey("METHOD"))
  72. return FailureResult();
  73. string method = request["METHOD"].ToString();
  74. switch (method)
  75. {
  76. case "register":
  77. return Register(request);
  78. case "deregister":
  79. return Deregister(request);
  80. case "get_neighbours":
  81. return GetNeighbours(request);
  82. case "get_region_by_uuid":
  83. return GetRegionByUUID(request);
  84. case "get_region_by_position":
  85. return GetRegionByPosition(request);
  86. case "get_region_by_name":
  87. return GetRegionByName(request);
  88. case "get_localregion_by_name":
  89. return GetLocalRegionByName(request);
  90. case "get_regions_by_name":
  91. return GetRegionsByName(request);
  92. case "get_region_range":
  93. return GetRegionRange(request);
  94. case "get_default_regions":
  95. return GetDefaultRegions(request);
  96. case "get_default_hypergrid_regions":
  97. return GetDefaultHypergridRegions(request);
  98. case "get_fallback_regions":
  99. return GetFallbackRegions(request);
  100. case "get_online_regions":
  101. return GetOnlineRegions(request);
  102. case "get_hyperlinks":
  103. return GetHyperlinks(request);
  104. case "get_region_flags":
  105. return GetRegionFlags(request);
  106. case "get_grid_extra_features":
  107. return GetGridExtraFeatures(request);
  108. }
  109. m_log.DebugFormat("[GRID HANDLER]: unknown method request {0}", method);
  110. }
  111. catch (Exception e)
  112. {
  113. m_log.ErrorFormat("[GRID HANDLER]: Exception {0} {1}", e.Message, e.StackTrace);
  114. }
  115. return FailureResult();
  116. }
  117. #region Method-specific handlers
  118. byte[] Register(Dictionary<string, object> request)
  119. {
  120. UUID scopeID = UUID.Zero;
  121. if (request.ContainsKey("SCOPEID"))
  122. UUID.TryParse(request["SCOPEID"].ToString(), out scopeID);
  123. else
  124. m_log.WarnFormat("[GRID HANDLER]: no scopeID in request to register region");
  125. int versionNumberMin = 0, versionNumberMax = 0;
  126. if (request.ContainsKey("VERSIONMIN"))
  127. Int32.TryParse(request["VERSIONMIN"].ToString(), out versionNumberMin);
  128. else
  129. m_log.WarnFormat("[GRID HANDLER]: no minimum protocol version in request to register region");
  130. if (request.ContainsKey("VERSIONMAX"))
  131. Int32.TryParse(request["VERSIONMAX"].ToString(), out versionNumberMax);
  132. else
  133. m_log.WarnFormat("[GRID HANDLER]: no maximum protocol version in request to register region");
  134. // Check the protocol version
  135. // This is how it works:
  136. // Example 1:
  137. // Client: [0 0]
  138. // Server: [1 1]
  139. // ==> fail
  140. // Example 2:
  141. // Client: [1 1]
  142. // Server: [0 0]
  143. // ==> fail
  144. // Example 3:
  145. // Client: [0 1]
  146. // Server: [1 1]
  147. // ==> success
  148. // Example 4:
  149. // Client: [1 1]
  150. // Server: [0 1]
  151. // ==> success
  152. if ((versionNumberMin > ProtocolVersions.ServerProtocolVersionMax || versionNumberMax < ProtocolVersions.ServerProtocolVersionMin))
  153. {
  154. // Can't do, there is no overlap in the acceptable ranges
  155. return FailureResult();
  156. }
  157. Dictionary<string, object> rinfoData = new Dictionary<string, object>();
  158. GridRegion rinfo = null;
  159. try
  160. {
  161. foreach (KeyValuePair<string, object> kvp in request)
  162. rinfoData[kvp.Key] = kvp.Value.ToString();
  163. rinfo = new GridRegion(rinfoData);
  164. }
  165. catch (Exception e)
  166. {
  167. m_log.DebugFormat("[GRID HANDLER]: exception unpacking region data: {0}", e);
  168. }
  169. string result = "Error communicating with grid service";
  170. if (rinfo != null)
  171. result = m_GridService.RegisterRegion(scopeID, rinfo);
  172. if (result.Length == 0)
  173. return SuccessResult();
  174. else
  175. return FailureResult(result);
  176. }
  177. byte[] Deregister(Dictionary<string, object> request)
  178. {
  179. UUID regionID = UUID.Zero;
  180. if (request.ContainsKey("REGIONID"))
  181. UUID.TryParse(request["REGIONID"].ToString(), out regionID);
  182. else
  183. m_log.WarnFormat("[GRID HANDLER]: no regionID in request to deregister region");
  184. bool result = m_GridService.DeregisterRegion(regionID);
  185. if (result)
  186. return SuccessResult();
  187. else
  188. return FailureResult();
  189. }
  190. byte[] GetNeighbours(Dictionary<string, object> request)
  191. {
  192. UUID scopeID = UUID.Zero;
  193. if (request.ContainsKey("SCOPEID"))
  194. UUID.TryParse(request["SCOPEID"].ToString(), out scopeID);
  195. else
  196. m_log.WarnFormat("[GRID HANDLER]: no scopeID in request to get neighbours");
  197. UUID regionID = UUID.Zero;
  198. if (request.ContainsKey("REGIONID"))
  199. UUID.TryParse(request["REGIONID"].ToString(), out regionID);
  200. else
  201. m_log.WarnFormat("[GRID HANDLER]: no regionID in request to get neighbours");
  202. List<GridRegion> rinfos = m_GridService.GetNeighbours(scopeID, regionID);
  203. //m_log.DebugFormat("[GRID HANDLER]: neighbours for region {0}: {1}", regionID, rinfos.Count);
  204. Dictionary<string, object> result = new Dictionary<string, object>();
  205. if ((rinfos == null) || ((rinfos != null) && (rinfos.Count == 0)))
  206. result["result"] = "null";
  207. else
  208. {
  209. int i = 0;
  210. foreach (GridRegion rinfo in rinfos)
  211. {
  212. Dictionary<string, object> rinfoDict = rinfo.ToKeyValuePairs();
  213. result["region" + i] = rinfoDict;
  214. i++;
  215. }
  216. }
  217. string xmlString = ServerUtils.BuildXmlResponse(result);
  218. //m_log.DebugFormat("[GRID HANDLER]: resp string: {0}", xmlString);
  219. return Util.UTF8NoBomEncoding.GetBytes(xmlString);
  220. }
  221. byte[] GetRegionByUUID(Dictionary<string, object> request)
  222. {
  223. UUID scopeID = UUID.Zero;
  224. if (request.ContainsKey("SCOPEID"))
  225. UUID.TryParse(request["SCOPEID"].ToString(), out scopeID);
  226. else
  227. m_log.WarnFormat("[GRID HANDLER]: no scopeID in request to get neighbours");
  228. UUID regionID = UUID.Zero;
  229. if (request.ContainsKey("REGIONID"))
  230. UUID.TryParse(request["REGIONID"].ToString(), out regionID);
  231. else
  232. m_log.WarnFormat("[GRID HANDLER]: no regionID in request to get neighbours");
  233. GridRegion rinfo = m_GridService.GetRegionByUUID(scopeID, regionID);
  234. //m_log.DebugFormat("[GRID HANDLER]: neighbours for region {0}: {1}", regionID, rinfos.Count);
  235. Dictionary<string, object> result = new Dictionary<string, object>();
  236. if (rinfo == null)
  237. result["result"] = "null";
  238. else
  239. result["result"] = rinfo.ToKeyValuePairs();
  240. string xmlString = ServerUtils.BuildXmlResponse(result);
  241. //m_log.DebugFormat("[GRID HANDLER]: resp string: {0}", xmlString);
  242. return Util.UTF8NoBomEncoding.GetBytes(xmlString);
  243. }
  244. byte[] GetRegionByPosition(Dictionary<string, object> request)
  245. {
  246. UUID scopeID = UUID.Zero;
  247. if (request.ContainsKey("SCOPEID"))
  248. UUID.TryParse(request["SCOPEID"].ToString(), out scopeID);
  249. else
  250. m_log.WarnFormat("[GRID HANDLER]: no scopeID in request to get region by position");
  251. int x = 0, y = 0;
  252. if (request.ContainsKey("X"))
  253. Int32.TryParse(request["X"].ToString(), out x);
  254. else
  255. m_log.WarnFormat("[GRID HANDLER]: no X in request to get region by position");
  256. if (request.ContainsKey("Y"))
  257. Int32.TryParse(request["Y"].ToString(), out y);
  258. else
  259. m_log.WarnFormat("[GRID HANDLER]: no Y in request to get region by position");
  260. // m_log.DebugFormat("{0} GetRegionByPosition: loc=<{1},{2}>", LogHeader, x, y);
  261. GridRegion rinfo = m_GridService.GetRegionByPosition(scopeID, x, y);
  262. Dictionary<string, object> result = new Dictionary<string, object>();
  263. if (rinfo == null)
  264. result["result"] = "null";
  265. else
  266. result["result"] = rinfo.ToKeyValuePairs();
  267. string xmlString = ServerUtils.BuildXmlResponse(result);
  268. //m_log.DebugFormat("[GRID HANDLER]: resp string: {0}", xmlString);
  269. return Util.UTF8NoBomEncoding.GetBytes(xmlString);
  270. }
  271. byte[] GetRegionByName(Dictionary<string, object> request)
  272. {
  273. UUID scopeID = UUID.Zero;
  274. if (!request.TryGetValue("SCOPEID", out object scpo) || scpo is not string scps || !UUID.TryParse(scps, out scopeID))
  275. m_log.WarnFormat("[GRID HANDLER]: no or invalid scopeID in request to get region by name");
  276. GridRegion rinfo = null;
  277. if (request.TryGetValue("NAME", out object nameo) && nameo is string regionName)
  278. rinfo = m_GridService.GetRegionByName(scopeID, regionName);
  279. else
  280. m_log.WarnFormat("[GRID HANDLER]: no name in request to get region by name");
  281. Dictionary<string, object> result = [];
  282. if (rinfo == null)
  283. result["result"] = "null";
  284. else
  285. result["result"] = rinfo.ToKeyValuePairs();
  286. string xmlString = ServerUtils.BuildXmlResponse(result);
  287. //m_log.DebugFormat("[GRID HANDLER]: resp string: {0}", xmlString);
  288. return Util.UTF8NoBomEncoding.GetBytes(xmlString);
  289. }
  290. byte[] GetLocalRegionByName(Dictionary<string, object> request)
  291. {
  292. UUID scopeID = UUID.Zero;
  293. if (!request.TryGetValue("SCOPEID", out object scpo) || scpo is not string scps || !UUID.TryParse(scps, out scopeID))
  294. m_log.WarnFormat("[GRID HANDLER]: no or invalid scopeID in request to get region by name");
  295. GridRegion rinfo = null;
  296. if (request.TryGetValue("NAME", out object nameo) && nameo is string regionName)
  297. rinfo = m_GridService.GetLocalRegionByName(scopeID, regionName);
  298. else
  299. m_log.WarnFormat("[GRID HANDLER]: no name in request to get region by name");
  300. Dictionary<string, object> result = [];
  301. if (rinfo == null)
  302. result["result"] = "null";
  303. else
  304. result["result"] = rinfo.ToKeyValuePairs();
  305. string xmlString = ServerUtils.BuildXmlResponse(result);
  306. //m_log.DebugFormat("[GRID HANDLER]: resp string: {0}", xmlString);
  307. return Util.UTF8NoBomEncoding.GetBytes(xmlString);
  308. }
  309. byte[] GetRegionsByName(Dictionary<string, object> request)
  310. {
  311. UUID scopeID = UUID.Zero;
  312. if (request.ContainsKey("SCOPEID"))
  313. UUID.TryParse(request["SCOPEID"].ToString(), out scopeID);
  314. else
  315. m_log.WarnFormat("[GRID HANDLER]: no scopeID in request to get regions by name");
  316. string regionName = string.Empty;
  317. if (request.ContainsKey("NAME"))
  318. regionName = request["NAME"].ToString();
  319. else
  320. m_log.WarnFormat("[GRID HANDLER]: no NAME in request to get regions by name");
  321. int max = 0;
  322. if (request.ContainsKey("MAX"))
  323. Int32.TryParse(request["MAX"].ToString(), out max);
  324. else
  325. m_log.WarnFormat("[GRID HANDLER]: no MAX in request to get regions by name");
  326. List<GridRegion> rinfos = m_GridService.GetRegionsByName(scopeID, regionName, max);
  327. //m_log.DebugFormat("[GRID HANDLER]: neighbours for region {0}: {1}", regionID, rinfos.Count);
  328. Dictionary<string, object> result = new Dictionary<string, object>();
  329. if ((rinfos == null) || ((rinfos != null) && (rinfos.Count == 0)))
  330. result["result"] = "null";
  331. else
  332. {
  333. int i = 0;
  334. foreach (GridRegion rinfo in rinfos)
  335. {
  336. Dictionary<string, object> rinfoDict = rinfo.ToKeyValuePairs();
  337. result["region" + i] = rinfoDict;
  338. i++;
  339. }
  340. }
  341. string xmlString = ServerUtils.BuildXmlResponse(result);
  342. //m_log.DebugFormat("[GRID HANDLER]: resp string: {0}", xmlString);
  343. return Util.UTF8NoBomEncoding.GetBytes(xmlString);
  344. }
  345. byte[] GetRegionRange(Dictionary<string, object> request)
  346. {
  347. //m_log.DebugFormat("[GRID HANDLER]: GetRegionRange");
  348. UUID scopeID = UUID.Zero;
  349. if (request.ContainsKey("SCOPEID"))
  350. UUID.TryParse(request["SCOPEID"].ToString(), out scopeID);
  351. else
  352. m_log.WarnFormat("[GRID HANDLER]: no scopeID in request to get region range");
  353. int xmin = 0, xmax = 0, ymin = 0, ymax = 0;
  354. if (request.ContainsKey("XMIN"))
  355. Int32.TryParse(request["XMIN"].ToString(), out xmin);
  356. else
  357. m_log.WarnFormat("[GRID HANDLER]: no XMIN in request to get region range");
  358. if (request.ContainsKey("XMAX"))
  359. Int32.TryParse(request["XMAX"].ToString(), out xmax);
  360. else
  361. m_log.WarnFormat("[GRID HANDLER]: no XMAX in request to get region range");
  362. if (request.ContainsKey("YMIN"))
  363. Int32.TryParse(request["YMIN"].ToString(), out ymin);
  364. else
  365. m_log.WarnFormat("[GRID HANDLER]: no YMIN in request to get region range");
  366. if (request.ContainsKey("YMAX"))
  367. Int32.TryParse(request["YMAX"].ToString(), out ymax);
  368. else
  369. m_log.WarnFormat("[GRID HANDLER]: no YMAX in request to get region range");
  370. List<GridRegion> rinfos = m_GridService.GetRegionRange(scopeID, xmin, xmax, ymin, ymax);
  371. Dictionary<string, object> result = new Dictionary<string, object>();
  372. if ((rinfos == null) || ((rinfos != null) && (rinfos.Count == 0)))
  373. result["result"] = "null";
  374. else
  375. {
  376. int i = 0;
  377. foreach (GridRegion rinfo in rinfos)
  378. {
  379. Dictionary<string, object> rinfoDict = rinfo.ToKeyValuePairs();
  380. result["region" + i] = rinfoDict;
  381. i++;
  382. }
  383. }
  384. string xmlString = ServerUtils.BuildXmlResponse(result);
  385. //m_log.DebugFormat("[GRID HANDLER]: resp string: {0}", xmlString);
  386. return Util.UTF8NoBomEncoding.GetBytes(xmlString);
  387. }
  388. byte[] GetDefaultRegions(Dictionary<string, object> request)
  389. {
  390. //m_log.DebugFormat("[GRID HANDLER]: GetDefaultRegions");
  391. UUID scopeID = UUID.Zero;
  392. if (request.ContainsKey("SCOPEID"))
  393. UUID.TryParse(request["SCOPEID"].ToString(), out scopeID);
  394. else
  395. m_log.WarnFormat("[GRID HANDLER]: no scopeID in request to get region range");
  396. List<GridRegion> rinfos = m_GridService.GetDefaultRegions(scopeID);
  397. Dictionary<string, object> result = new Dictionary<string, object>();
  398. if ((rinfos == null) || ((rinfos != null) && (rinfos.Count == 0)))
  399. result["result"] = "null";
  400. else
  401. {
  402. int i = 0;
  403. foreach (GridRegion rinfo in rinfos)
  404. {
  405. Dictionary<string, object> rinfoDict = rinfo.ToKeyValuePairs();
  406. result["region" + i] = rinfoDict;
  407. i++;
  408. }
  409. }
  410. string xmlString = ServerUtils.BuildXmlResponse(result);
  411. //m_log.DebugFormat("[GRID HANDLER]: resp string: {0}", xmlString);
  412. return Util.UTF8NoBomEncoding.GetBytes(xmlString);
  413. }
  414. byte[] GetDefaultHypergridRegions(Dictionary<string, object> request)
  415. {
  416. //m_log.DebugFormat("[GRID HANDLER]: GetDefaultRegions");
  417. UUID scopeID = UUID.Zero;
  418. if (request.ContainsKey("SCOPEID"))
  419. UUID.TryParse(request["SCOPEID"].ToString(), out scopeID);
  420. else
  421. m_log.WarnFormat("[GRID HANDLER]: no scopeID in request to get region range");
  422. List<GridRegion> rinfos = m_GridService.GetDefaultHypergridRegions(scopeID);
  423. Dictionary<string, object> result = new Dictionary<string, object>();
  424. if ((rinfos == null) || ((rinfos != null) && (rinfos.Count == 0)))
  425. result["result"] = "null";
  426. else
  427. {
  428. int i = 0;
  429. foreach (GridRegion rinfo in rinfos)
  430. {
  431. Dictionary<string, object> rinfoDict = rinfo.ToKeyValuePairs();
  432. result["region" + i] = rinfoDict;
  433. i++;
  434. }
  435. }
  436. string xmlString = ServerUtils.BuildXmlResponse(result);
  437. //m_log.DebugFormat("[GRID HANDLER]: resp string: {0}", xmlString);
  438. return Util.UTF8NoBomEncoding.GetBytes(xmlString);
  439. }
  440. byte[] GetFallbackRegions(Dictionary<string, object> request)
  441. {
  442. //m_log.DebugFormat("[GRID HANDLER]: GetRegionRange");
  443. UUID scopeID = UUID.Zero;
  444. if (request.ContainsKey("SCOPEID"))
  445. UUID.TryParse(request["SCOPEID"].ToString(), out scopeID);
  446. else
  447. m_log.WarnFormat("[GRID HANDLER]: no scopeID in request to get fallback regions");
  448. int x = 0, y = 0;
  449. if (request.ContainsKey("X"))
  450. Int32.TryParse(request["X"].ToString(), out x);
  451. else
  452. m_log.WarnFormat("[GRID HANDLER]: no X in request to get fallback regions");
  453. if (request.ContainsKey("Y"))
  454. Int32.TryParse(request["Y"].ToString(), out y);
  455. else
  456. m_log.WarnFormat("[GRID HANDLER]: no Y in request to get fallback regions");
  457. List<GridRegion> rinfos = m_GridService.GetFallbackRegions(scopeID, x, y);
  458. Dictionary<string, object> result = new Dictionary<string, object>();
  459. if ((rinfos == null) || ((rinfos != null) && (rinfos.Count == 0)))
  460. result["result"] = "null";
  461. else
  462. {
  463. int i = 0;
  464. foreach (GridRegion rinfo in rinfos)
  465. {
  466. Dictionary<string, object> rinfoDict = rinfo.ToKeyValuePairs();
  467. result["region" + i] = rinfoDict;
  468. i++;
  469. }
  470. }
  471. string xmlString = ServerUtils.BuildXmlResponse(result);
  472. //m_log.DebugFormat("[GRID HANDLER]: resp string: {0}", xmlString);
  473. return Util.UTF8NoBomEncoding.GetBytes(xmlString);
  474. }
  475. byte[] GetOnlineRegions(Dictionary<string, object> request)
  476. {
  477. UUID scopeID = UUID.Zero;
  478. object o;
  479. if (request.TryGetValue("SCOPEID", out o))
  480. UUID.TryParse(o.ToString(), out scopeID);
  481. else
  482. m_log.WarnFormat("[GRID HANDLER]: no scopeID in request to get online regions");
  483. int x = 0, y = 0, max = 0;
  484. if (request.TryGetValue("X", out o))
  485. Int32.TryParse(o.ToString(), out x);
  486. else
  487. m_log.WarnFormat("[GRID HANDLER]: no X in request to get online regions");
  488. if (request.TryGetValue("Y", out o))
  489. Int32.TryParse(o.ToString(), out y);
  490. else
  491. m_log.WarnFormat("[GRID HANDLER]: no Y in request to get online regions");
  492. if (request.TryGetValue("MC", out o))
  493. Int32.TryParse(o.ToString(), out max);
  494. else
  495. m_log.WarnFormat("[GRID HANDLER]: no Max Count in request to get online regions");
  496. List<GridRegion> rinfos = null;
  497. if (max > 0)
  498. rinfos = m_GridService.GetOnlineRegions(scopeID, x, y, max);
  499. Dictionary<string, object> result = new Dictionary<string, object>();
  500. if ((rinfos == null) || ((rinfos != null) && (rinfos.Count == 0)))
  501. result["result"] = "null";
  502. else
  503. {
  504. int i = 0;
  505. foreach (GridRegion rinfo in rinfos)
  506. {
  507. Dictionary<string, object> rinfoDict = rinfo.ToKeyValuePairs();
  508. result["region" + i] = rinfoDict;
  509. i++;
  510. }
  511. }
  512. string xmlString = ServerUtils.BuildXmlResponse(result);
  513. //m_log.DebugFormat("[GRID HANDLER]: resp string: {0}", xmlString);
  514. return Util.UTF8NoBomEncoding.GetBytes(xmlString);
  515. }
  516. byte[] GetHyperlinks(Dictionary<string, object> request)
  517. {
  518. //m_log.DebugFormat("[GRID HANDLER]: GetHyperlinks");
  519. UUID scopeID = UUID.Zero;
  520. if (request.ContainsKey("SCOPEID"))
  521. UUID.TryParse(request["SCOPEID"].ToString(), out scopeID);
  522. else
  523. m_log.WarnFormat("[GRID HANDLER]: no scopeID in request to get linked regions");
  524. List<GridRegion> rinfos = m_GridService.GetHyperlinks(scopeID);
  525. Dictionary<string, object> result = new Dictionary<string, object>();
  526. if ((rinfos == null) || ((rinfos != null) && (rinfos.Count == 0)))
  527. result["result"] = "null";
  528. else
  529. {
  530. int i = 0;
  531. foreach (GridRegion rinfo in rinfos)
  532. {
  533. Dictionary<string, object> rinfoDict = rinfo.ToKeyValuePairs();
  534. result["region" + i] = rinfoDict;
  535. i++;
  536. }
  537. }
  538. string xmlString = ServerUtils.BuildXmlResponse(result);
  539. //m_log.DebugFormat("[GRID HANDLER]: resp string: {0}", xmlString);
  540. return Util.UTF8NoBomEncoding.GetBytes(xmlString);
  541. }
  542. byte[] GetRegionFlags(Dictionary<string, object> request)
  543. {
  544. UUID scopeID = UUID.Zero;
  545. if (request.ContainsKey("SCOPEID"))
  546. UUID.TryParse(request["SCOPEID"].ToString(), out scopeID);
  547. else
  548. m_log.WarnFormat("[GRID HANDLER]: no scopeID in request to get RegionFlags");
  549. UUID regionID = UUID.Zero;
  550. if (request.ContainsKey("REGIONID"))
  551. UUID.TryParse(request["REGIONID"].ToString(), out regionID);
  552. else
  553. m_log.WarnFormat("[GRID HANDLER]: no regionID in request to get RegionFlags");
  554. int flags = m_GridService.GetRegionFlags(scopeID, regionID);
  555. // m_log.DebugFormat("[GRID HANDLER]: flags for region {0}: {1}", regionID, flags);
  556. Dictionary<string, object> result = new Dictionary<string, object>();
  557. result["result"] = flags.ToString();
  558. string xmlString = ServerUtils.BuildXmlResponse(result);
  559. //m_log.DebugFormat("[GRID HANDLER]: resp string: {0}", xmlString);
  560. return Util.UTF8NoBomEncoding.GetBytes(xmlString);
  561. }
  562. byte[] GetGridExtraFeatures(Dictionary<string, object> request)
  563. {
  564. Dictionary<string, object> result = new Dictionary<string, object> ();
  565. Dictionary<string, object> extraFeatures = m_GridService.GetExtraFeatures ();
  566. foreach (string key in extraFeatures.Keys)
  567. {
  568. result [key] = extraFeatures [key];
  569. }
  570. string xmlString = ServerUtils.BuildXmlResponse(result);
  571. return Util.UTF8NoBomEncoding.GetBytes(xmlString);
  572. }
  573. #endregion
  574. #region Misc
  575. private byte[] SuccessResult()
  576. {
  577. XmlDocument doc = new XmlDocument();
  578. XmlNode xmlnode = doc.CreateNode(XmlNodeType.XmlDeclaration,
  579. "", "");
  580. doc.AppendChild(xmlnode);
  581. XmlElement rootElement = doc.CreateElement("", "ServerResponse",
  582. "");
  583. doc.AppendChild(rootElement);
  584. XmlElement result = doc.CreateElement("", "Result", "");
  585. result.AppendChild(doc.CreateTextNode("Success"));
  586. rootElement.AppendChild(result);
  587. return Util.DocToBytes(doc);
  588. }
  589. private byte[] FailureResult()
  590. {
  591. return FailureResult(String.Empty);
  592. }
  593. private byte[] FailureResult(string msg)
  594. {
  595. XmlDocument doc = new XmlDocument();
  596. XmlNode xmlnode = doc.CreateNode(XmlNodeType.XmlDeclaration,
  597. "", "");
  598. doc.AppendChild(xmlnode);
  599. XmlElement rootElement = doc.CreateElement("", "ServerResponse",
  600. "");
  601. doc.AppendChild(rootElement);
  602. XmlElement result = doc.CreateElement("", "Result", "");
  603. result.AppendChild(doc.CreateTextNode("Failure"));
  604. rootElement.AppendChild(result);
  605. XmlElement message = doc.CreateElement("", "Message", "");
  606. message.AppendChild(doc.CreateTextNode(msg));
  607. rootElement.AppendChild(message);
  608. return Util.DocToBytes(doc);
  609. }
  610. #endregion
  611. }
  612. }