GridServerPostHandler.cs 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648
  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.Servers.HttpServer;
  43. using OpenMetaverse;
  44. namespace OpenSim.Server.Handlers.Grid
  45. {
  46. public class GridServerPostHandler : BaseStreamHandler
  47. {
  48. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  49. private IGridService m_GridService;
  50. public GridServerPostHandler(IGridService service) :
  51. base("POST", "/grid")
  52. {
  53. m_GridService = service;
  54. }
  55. protected override byte[] ProcessRequest(string path, Stream requestData,
  56. IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
  57. {
  58. StreamReader sr = new StreamReader(requestData);
  59. string body = sr.ReadToEnd();
  60. sr.Close();
  61. body = body.Trim();
  62. //m_log.DebugFormat("[XXX]: query String: {0}", body);
  63. try
  64. {
  65. Dictionary<string, object> request =
  66. ServerUtils.ParseQueryString(body);
  67. if (!request.ContainsKey("METHOD"))
  68. return FailureResult();
  69. string method = request["METHOD"].ToString();
  70. switch (method)
  71. {
  72. case "register":
  73. return Register(request);
  74. case "deregister":
  75. return Deregister(request);
  76. case "get_neighbours":
  77. return GetNeighbours(request);
  78. case "get_region_by_uuid":
  79. return GetRegionByUUID(request);
  80. case "get_region_by_position":
  81. return GetRegionByPosition(request);
  82. case "get_region_by_name":
  83. return GetRegionByName(request);
  84. case "get_regions_by_name":
  85. return GetRegionsByName(request);
  86. case "get_region_range":
  87. return GetRegionRange(request);
  88. case "get_default_regions":
  89. return GetDefaultRegions(request);
  90. case "get_default_hypergrid_regions":
  91. return GetDefaultHypergridRegions(request);
  92. case "get_fallback_regions":
  93. return GetFallbackRegions(request);
  94. case "get_hyperlinks":
  95. return GetHyperlinks(request);
  96. case "get_region_flags":
  97. return GetRegionFlags(request);
  98. }
  99. m_log.DebugFormat("[GRID HANDLER]: unknown method request {0}", method);
  100. }
  101. catch (Exception e)
  102. {
  103. m_log.ErrorFormat("[GRID HANDLER]: Exception {0} {1}", e.Message, e.StackTrace);
  104. }
  105. return FailureResult();
  106. }
  107. #region Method-specific handlers
  108. byte[] Register(Dictionary<string, object> request)
  109. {
  110. UUID scopeID = UUID.Zero;
  111. if (request.ContainsKey("SCOPEID"))
  112. UUID.TryParse(request["SCOPEID"].ToString(), out scopeID);
  113. else
  114. m_log.WarnFormat("[GRID HANDLER]: no scopeID in request to register region");
  115. int versionNumberMin = 0, versionNumberMax = 0;
  116. if (request.ContainsKey("VERSIONMIN"))
  117. Int32.TryParse(request["VERSIONMIN"].ToString(), out versionNumberMin);
  118. else
  119. m_log.WarnFormat("[GRID HANDLER]: no minimum protocol version in request to register region");
  120. if (request.ContainsKey("VERSIONMAX"))
  121. Int32.TryParse(request["VERSIONMAX"].ToString(), out versionNumberMax);
  122. else
  123. m_log.WarnFormat("[GRID HANDLER]: no maximum protocol version in request to register region");
  124. // Check the protocol version
  125. if ((versionNumberMin > ProtocolVersions.ServerProtocolVersionMax && versionNumberMax < ProtocolVersions.ServerProtocolVersionMax))
  126. {
  127. // Can't do, there is no overlap in the acceptable ranges
  128. return FailureResult();
  129. }
  130. Dictionary<string, object> rinfoData = new Dictionary<string, object>();
  131. GridRegion rinfo = null;
  132. try
  133. {
  134. foreach (KeyValuePair<string, object> kvp in request)
  135. rinfoData[kvp.Key] = kvp.Value.ToString();
  136. rinfo = new GridRegion(rinfoData);
  137. }
  138. catch (Exception e)
  139. {
  140. m_log.DebugFormat("[GRID HANDLER]: exception unpacking region data: {0}", e);
  141. }
  142. string result = "Error communicating with grid service";
  143. if (rinfo != null)
  144. result = m_GridService.RegisterRegion(scopeID, rinfo);
  145. if (result == String.Empty)
  146. return SuccessResult();
  147. else
  148. return FailureResult(result);
  149. }
  150. byte[] Deregister(Dictionary<string, object> request)
  151. {
  152. UUID regionID = UUID.Zero;
  153. if (request.ContainsKey("REGIONID"))
  154. UUID.TryParse(request["REGIONID"].ToString(), out regionID);
  155. else
  156. m_log.WarnFormat("[GRID HANDLER]: no regionID in request to deregister region");
  157. bool result = m_GridService.DeregisterRegion(regionID);
  158. if (result)
  159. return SuccessResult();
  160. else
  161. return FailureResult();
  162. }
  163. byte[] GetNeighbours(Dictionary<string, object> request)
  164. {
  165. UUID scopeID = UUID.Zero;
  166. if (request.ContainsKey("SCOPEID"))
  167. UUID.TryParse(request["SCOPEID"].ToString(), out scopeID);
  168. else
  169. m_log.WarnFormat("[GRID HANDLER]: no scopeID in request to get neighbours");
  170. UUID regionID = UUID.Zero;
  171. if (request.ContainsKey("REGIONID"))
  172. UUID.TryParse(request["REGIONID"].ToString(), out regionID);
  173. else
  174. m_log.WarnFormat("[GRID HANDLER]: no regionID in request to get neighbours");
  175. List<GridRegion> rinfos = m_GridService.GetNeighbours(scopeID, regionID);
  176. //m_log.DebugFormat("[GRID HANDLER]: neighbours for region {0}: {1}", regionID, rinfos.Count);
  177. Dictionary<string, object> result = new Dictionary<string, object>();
  178. if ((rinfos == null) || ((rinfos != null) && (rinfos.Count == 0)))
  179. result["result"] = "null";
  180. else
  181. {
  182. int i = 0;
  183. foreach (GridRegion rinfo in rinfos)
  184. {
  185. Dictionary<string, object> rinfoDict = rinfo.ToKeyValuePairs();
  186. result["region" + i] = rinfoDict;
  187. i++;
  188. }
  189. }
  190. string xmlString = ServerUtils.BuildXmlResponse(result);
  191. //m_log.DebugFormat("[GRID HANDLER]: resp string: {0}", xmlString);
  192. return Util.UTF8NoBomEncoding.GetBytes(xmlString);
  193. }
  194. byte[] GetRegionByUUID(Dictionary<string, object> request)
  195. {
  196. UUID scopeID = UUID.Zero;
  197. if (request.ContainsKey("SCOPEID"))
  198. UUID.TryParse(request["SCOPEID"].ToString(), out scopeID);
  199. else
  200. m_log.WarnFormat("[GRID HANDLER]: no scopeID in request to get neighbours");
  201. UUID regionID = UUID.Zero;
  202. if (request.ContainsKey("REGIONID"))
  203. UUID.TryParse(request["REGIONID"].ToString(), out regionID);
  204. else
  205. m_log.WarnFormat("[GRID HANDLER]: no regionID in request to get neighbours");
  206. GridRegion rinfo = m_GridService.GetRegionByUUID(scopeID, regionID);
  207. //m_log.DebugFormat("[GRID HANDLER]: neighbours for region {0}: {1}", regionID, rinfos.Count);
  208. Dictionary<string, object> result = new Dictionary<string, object>();
  209. if (rinfo == null)
  210. result["result"] = "null";
  211. else
  212. result["result"] = rinfo.ToKeyValuePairs();
  213. string xmlString = ServerUtils.BuildXmlResponse(result);
  214. //m_log.DebugFormat("[GRID HANDLER]: resp string: {0}", xmlString);
  215. return Util.UTF8NoBomEncoding.GetBytes(xmlString);
  216. }
  217. byte[] GetRegionByPosition(Dictionary<string, object> request)
  218. {
  219. UUID scopeID = UUID.Zero;
  220. if (request.ContainsKey("SCOPEID"))
  221. UUID.TryParse(request["SCOPEID"].ToString(), out scopeID);
  222. else
  223. m_log.WarnFormat("[GRID HANDLER]: no scopeID in request to get region by position");
  224. int x = 0, y = 0;
  225. if (request.ContainsKey("X"))
  226. Int32.TryParse(request["X"].ToString(), out x);
  227. else
  228. m_log.WarnFormat("[GRID HANDLER]: no X in request to get region by position");
  229. if (request.ContainsKey("Y"))
  230. Int32.TryParse(request["Y"].ToString(), out y);
  231. else
  232. m_log.WarnFormat("[GRID HANDLER]: no Y in request to get region by position");
  233. GridRegion rinfo = m_GridService.GetRegionByPosition(scopeID, x, y);
  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[] GetRegionByName(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 name");
  251. string regionName = string.Empty;
  252. if (request.ContainsKey("NAME"))
  253. regionName = request["NAME"].ToString();
  254. else
  255. m_log.WarnFormat("[GRID HANDLER]: no name in request to get region by name");
  256. GridRegion rinfo = m_GridService.GetRegionByName(scopeID, regionName);
  257. //m_log.DebugFormat("[GRID HANDLER]: neighbours for region {0}: {1}", regionID, rinfos.Count);
  258. Dictionary<string, object> result = new Dictionary<string, object>();
  259. if (rinfo == null)
  260. result["result"] = "null";
  261. else
  262. result["result"] = rinfo.ToKeyValuePairs();
  263. string xmlString = ServerUtils.BuildXmlResponse(result);
  264. //m_log.DebugFormat("[GRID HANDLER]: resp string: {0}", xmlString);
  265. return Util.UTF8NoBomEncoding.GetBytes(xmlString);
  266. }
  267. byte[] GetRegionsByName(Dictionary<string, object> request)
  268. {
  269. UUID scopeID = UUID.Zero;
  270. if (request.ContainsKey("SCOPEID"))
  271. UUID.TryParse(request["SCOPEID"].ToString(), out scopeID);
  272. else
  273. m_log.WarnFormat("[GRID HANDLER]: no scopeID in request to get regions by name");
  274. string regionName = string.Empty;
  275. if (request.ContainsKey("NAME"))
  276. regionName = request["NAME"].ToString();
  277. else
  278. m_log.WarnFormat("[GRID HANDLER]: no NAME in request to get regions by name");
  279. int max = 0;
  280. if (request.ContainsKey("MAX"))
  281. Int32.TryParse(request["MAX"].ToString(), out max);
  282. else
  283. m_log.WarnFormat("[GRID HANDLER]: no MAX in request to get regions by name");
  284. List<GridRegion> rinfos = m_GridService.GetRegionsByName(scopeID, regionName, max);
  285. //m_log.DebugFormat("[GRID HANDLER]: neighbours for region {0}: {1}", regionID, rinfos.Count);
  286. Dictionary<string, object> result = new Dictionary<string, object>();
  287. if ((rinfos == null) || ((rinfos != null) && (rinfos.Count == 0)))
  288. result["result"] = "null";
  289. else
  290. {
  291. int i = 0;
  292. foreach (GridRegion rinfo in rinfos)
  293. {
  294. Dictionary<string, object> rinfoDict = rinfo.ToKeyValuePairs();
  295. result["region" + i] = rinfoDict;
  296. i++;
  297. }
  298. }
  299. string xmlString = ServerUtils.BuildXmlResponse(result);
  300. //m_log.DebugFormat("[GRID HANDLER]: resp string: {0}", xmlString);
  301. return Util.UTF8NoBomEncoding.GetBytes(xmlString);
  302. }
  303. byte[] GetRegionRange(Dictionary<string, object> request)
  304. {
  305. //m_log.DebugFormat("[GRID HANDLER]: GetRegionRange");
  306. UUID scopeID = UUID.Zero;
  307. if (request.ContainsKey("SCOPEID"))
  308. UUID.TryParse(request["SCOPEID"].ToString(), out scopeID);
  309. else
  310. m_log.WarnFormat("[GRID HANDLER]: no scopeID in request to get region range");
  311. int xmin = 0, xmax = 0, ymin = 0, ymax = 0;
  312. if (request.ContainsKey("XMIN"))
  313. Int32.TryParse(request["XMIN"].ToString(), out xmin);
  314. else
  315. m_log.WarnFormat("[GRID HANDLER]: no XMIN in request to get region range");
  316. if (request.ContainsKey("XMAX"))
  317. Int32.TryParse(request["XMAX"].ToString(), out xmax);
  318. else
  319. m_log.WarnFormat("[GRID HANDLER]: no XMAX in request to get region range");
  320. if (request.ContainsKey("YMIN"))
  321. Int32.TryParse(request["YMIN"].ToString(), out ymin);
  322. else
  323. m_log.WarnFormat("[GRID HANDLER]: no YMIN in request to get region range");
  324. if (request.ContainsKey("YMAX"))
  325. Int32.TryParse(request["YMAX"].ToString(), out ymax);
  326. else
  327. m_log.WarnFormat("[GRID HANDLER]: no YMAX in request to get region range");
  328. List<GridRegion> rinfos = m_GridService.GetRegionRange(scopeID, xmin, xmax, ymin, ymax);
  329. Dictionary<string, object> result = new Dictionary<string, object>();
  330. if ((rinfos == null) || ((rinfos != null) && (rinfos.Count == 0)))
  331. result["result"] = "null";
  332. else
  333. {
  334. int i = 0;
  335. foreach (GridRegion rinfo in rinfos)
  336. {
  337. Dictionary<string, object> rinfoDict = rinfo.ToKeyValuePairs();
  338. result["region" + i] = rinfoDict;
  339. i++;
  340. }
  341. }
  342. string xmlString = ServerUtils.BuildXmlResponse(result);
  343. //m_log.DebugFormat("[GRID HANDLER]: resp string: {0}", xmlString);
  344. return Util.UTF8NoBomEncoding.GetBytes(xmlString);
  345. }
  346. byte[] GetDefaultRegions(Dictionary<string, object> request)
  347. {
  348. //m_log.DebugFormat("[GRID HANDLER]: GetDefaultRegions");
  349. UUID scopeID = UUID.Zero;
  350. if (request.ContainsKey("SCOPEID"))
  351. UUID.TryParse(request["SCOPEID"].ToString(), out scopeID);
  352. else
  353. m_log.WarnFormat("[GRID HANDLER]: no scopeID in request to get region range");
  354. List<GridRegion> rinfos = m_GridService.GetDefaultRegions(scopeID);
  355. Dictionary<string, object> result = new Dictionary<string, object>();
  356. if ((rinfos == null) || ((rinfos != null) && (rinfos.Count == 0)))
  357. result["result"] = "null";
  358. else
  359. {
  360. int i = 0;
  361. foreach (GridRegion rinfo in rinfos)
  362. {
  363. Dictionary<string, object> rinfoDict = rinfo.ToKeyValuePairs();
  364. result["region" + i] = rinfoDict;
  365. i++;
  366. }
  367. }
  368. string xmlString = ServerUtils.BuildXmlResponse(result);
  369. //m_log.DebugFormat("[GRID HANDLER]: resp string: {0}", xmlString);
  370. return Util.UTF8NoBomEncoding.GetBytes(xmlString);
  371. }
  372. byte[] GetDefaultHypergridRegions(Dictionary<string, object> request)
  373. {
  374. //m_log.DebugFormat("[GRID HANDLER]: GetDefaultRegions");
  375. UUID scopeID = UUID.Zero;
  376. if (request.ContainsKey("SCOPEID"))
  377. UUID.TryParse(request["SCOPEID"].ToString(), out scopeID);
  378. else
  379. m_log.WarnFormat("[GRID HANDLER]: no scopeID in request to get region range");
  380. List<GridRegion> rinfos = m_GridService.GetDefaultHypergridRegions(scopeID);
  381. Dictionary<string, object> result = new Dictionary<string, object>();
  382. if ((rinfos == null) || ((rinfos != null) && (rinfos.Count == 0)))
  383. result["result"] = "null";
  384. else
  385. {
  386. int i = 0;
  387. foreach (GridRegion rinfo in rinfos)
  388. {
  389. Dictionary<string, object> rinfoDict = rinfo.ToKeyValuePairs();
  390. result["region" + i] = rinfoDict;
  391. i++;
  392. }
  393. }
  394. string xmlString = ServerUtils.BuildXmlResponse(result);
  395. //m_log.DebugFormat("[GRID HANDLER]: resp string: {0}", xmlString);
  396. return Util.UTF8NoBomEncoding.GetBytes(xmlString);
  397. }
  398. byte[] GetFallbackRegions(Dictionary<string, object> request)
  399. {
  400. //m_log.DebugFormat("[GRID HANDLER]: GetRegionRange");
  401. UUID scopeID = UUID.Zero;
  402. if (request.ContainsKey("SCOPEID"))
  403. UUID.TryParse(request["SCOPEID"].ToString(), out scopeID);
  404. else
  405. m_log.WarnFormat("[GRID HANDLER]: no scopeID in request to get fallback regions");
  406. int x = 0, y = 0;
  407. if (request.ContainsKey("X"))
  408. Int32.TryParse(request["X"].ToString(), out x);
  409. else
  410. m_log.WarnFormat("[GRID HANDLER]: no X in request to get fallback regions");
  411. if (request.ContainsKey("Y"))
  412. Int32.TryParse(request["Y"].ToString(), out y);
  413. else
  414. m_log.WarnFormat("[GRID HANDLER]: no Y in request to get fallback regions");
  415. List<GridRegion> rinfos = m_GridService.GetFallbackRegions(scopeID, x, y);
  416. Dictionary<string, object> result = new Dictionary<string, object>();
  417. if ((rinfos == null) || ((rinfos != null) && (rinfos.Count == 0)))
  418. result["result"] = "null";
  419. else
  420. {
  421. int i = 0;
  422. foreach (GridRegion rinfo in rinfos)
  423. {
  424. Dictionary<string, object> rinfoDict = rinfo.ToKeyValuePairs();
  425. result["region" + i] = rinfoDict;
  426. i++;
  427. }
  428. }
  429. string xmlString = ServerUtils.BuildXmlResponse(result);
  430. //m_log.DebugFormat("[GRID HANDLER]: resp string: {0}", xmlString);
  431. return Util.UTF8NoBomEncoding.GetBytes(xmlString);
  432. }
  433. byte[] GetHyperlinks(Dictionary<string, object> request)
  434. {
  435. //m_log.DebugFormat("[GRID HANDLER]: GetHyperlinks");
  436. UUID scopeID = UUID.Zero;
  437. if (request.ContainsKey("SCOPEID"))
  438. UUID.TryParse(request["SCOPEID"].ToString(), out scopeID);
  439. else
  440. m_log.WarnFormat("[GRID HANDLER]: no scopeID in request to get linked regions");
  441. List<GridRegion> rinfos = m_GridService.GetHyperlinks(scopeID);
  442. Dictionary<string, object> result = new Dictionary<string, object>();
  443. if ((rinfos == null) || ((rinfos != null) && (rinfos.Count == 0)))
  444. result["result"] = "null";
  445. else
  446. {
  447. int i = 0;
  448. foreach (GridRegion rinfo in rinfos)
  449. {
  450. Dictionary<string, object> rinfoDict = rinfo.ToKeyValuePairs();
  451. result["region" + i] = rinfoDict;
  452. i++;
  453. }
  454. }
  455. string xmlString = ServerUtils.BuildXmlResponse(result);
  456. //m_log.DebugFormat("[GRID HANDLER]: resp string: {0}", xmlString);
  457. return Util.UTF8NoBomEncoding.GetBytes(xmlString);
  458. }
  459. byte[] GetRegionFlags(Dictionary<string, object> request)
  460. {
  461. UUID scopeID = UUID.Zero;
  462. if (request.ContainsKey("SCOPEID"))
  463. UUID.TryParse(request["SCOPEID"].ToString(), out scopeID);
  464. else
  465. m_log.WarnFormat("[GRID HANDLER]: no scopeID in request to get neighbours");
  466. UUID regionID = UUID.Zero;
  467. if (request.ContainsKey("REGIONID"))
  468. UUID.TryParse(request["REGIONID"].ToString(), out regionID);
  469. else
  470. m_log.WarnFormat("[GRID HANDLER]: no regionID in request to get neighbours");
  471. int flags = m_GridService.GetRegionFlags(scopeID, regionID);
  472. // m_log.DebugFormat("[GRID HANDLER]: flags for region {0}: {1}", regionID, flags);
  473. Dictionary<string, object> result = new Dictionary<string, object>();
  474. result["result"] = flags.ToString();
  475. string xmlString = ServerUtils.BuildXmlResponse(result);
  476. //m_log.DebugFormat("[GRID HANDLER]: resp string: {0}", xmlString);
  477. return Util.UTF8NoBomEncoding.GetBytes(xmlString);
  478. }
  479. #endregion
  480. #region Misc
  481. private byte[] SuccessResult()
  482. {
  483. XmlDocument doc = new XmlDocument();
  484. XmlNode xmlnode = doc.CreateNode(XmlNodeType.XmlDeclaration,
  485. "", "");
  486. doc.AppendChild(xmlnode);
  487. XmlElement rootElement = doc.CreateElement("", "ServerResponse",
  488. "");
  489. doc.AppendChild(rootElement);
  490. XmlElement result = doc.CreateElement("", "Result", "");
  491. result.AppendChild(doc.CreateTextNode("Success"));
  492. rootElement.AppendChild(result);
  493. return DocToBytes(doc);
  494. }
  495. private byte[] FailureResult()
  496. {
  497. return FailureResult(String.Empty);
  498. }
  499. private byte[] FailureResult(string msg)
  500. {
  501. XmlDocument doc = new XmlDocument();
  502. XmlNode xmlnode = doc.CreateNode(XmlNodeType.XmlDeclaration,
  503. "", "");
  504. doc.AppendChild(xmlnode);
  505. XmlElement rootElement = doc.CreateElement("", "ServerResponse",
  506. "");
  507. doc.AppendChild(rootElement);
  508. XmlElement result = doc.CreateElement("", "Result", "");
  509. result.AppendChild(doc.CreateTextNode("Failure"));
  510. rootElement.AppendChild(result);
  511. XmlElement message = doc.CreateElement("", "Message", "");
  512. message.AppendChild(doc.CreateTextNode(msg));
  513. rootElement.AppendChild(message);
  514. return DocToBytes(doc);
  515. }
  516. private byte[] DocToBytes(XmlDocument doc)
  517. {
  518. MemoryStream ms = new MemoryStream();
  519. XmlTextWriter xw = new XmlTextWriter(ms, null);
  520. xw.Formatting = Formatting.Indented;
  521. doc.WriteTo(xw);
  522. xw.Flush();
  523. return ms.ToArray();
  524. }
  525. #endregion
  526. }
  527. }