GridServerPostHandler.cs 26 KB

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