GridServerPostHandler.cs 25 KB

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