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