GridServerPostHandler.cs 28 KB

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