aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Server/Handlers/Grid
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Server/Handlers/Grid')
-rw-r--r--OpenSim/Server/Handlers/Grid/GridInfoHandlers.cs199
-rw-r--r--OpenSim/Server/Handlers/Grid/GridInfoServerInConnector.cs57
-rw-r--r--OpenSim/Server/Handlers/Grid/GridServerConnector.cs64
-rw-r--r--OpenSim/Server/Handlers/Grid/GridServerPostHandler.cs661
4 files changed, 981 insertions, 0 deletions
diff --git a/OpenSim/Server/Handlers/Grid/GridInfoHandlers.cs b/OpenSim/Server/Handlers/Grid/GridInfoHandlers.cs
new file mode 100644
index 0000000..346af32
--- /dev/null
+++ b/OpenSim/Server/Handlers/Grid/GridInfoHandlers.cs
@@ -0,0 +1,199 @@
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
28using System;
29using System.Collections;
30using System.IO;
31using System.Net;
32using System.Reflection;
33using System.Security;
34using System.Text;
35using log4net;
36using Nini.Config;
37using Nwc.XmlRpc;
38using OpenSim.Framework;
39using OpenSim.Framework.Servers.HttpServer;
40using OpenMetaverse.StructuredData;
41
42namespace OpenSim.Server.Handlers.Grid
43{
44 public class GridInfoHandlers
45 {
46 private static readonly ILog _log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
47 private IConfigSource m_Config;
48 private Hashtable _info = new Hashtable();
49
50 /// <summary>
51 /// Instantiate a GridInfoService object.
52 /// </summary>
53 /// <param name="configPath">path to config path containing
54 /// grid information</param>
55 /// <remarks>
56 /// GridInfoService uses the [GridInfo] section of the
57 /// standard OpenSim.ini file --- which is not optimal, but
58 /// anything else requires a general redesign of the config
59 /// system.
60 /// </remarks>
61 public GridInfoHandlers(IConfigSource configSource)
62 {
63 m_Config = configSource;
64 loadGridInfo(configSource);
65 }
66
67 private void loadGridInfo(IConfigSource configSource)
68 {
69 _info["platform"] = "OpenSim";
70 try
71 {
72 IConfig gridCfg = configSource.Configs["GridInfoService"];
73 IConfig netCfg = configSource.Configs["Network"];
74
75 if (null != gridCfg)
76 {
77 foreach (string k in gridCfg.GetKeys())
78 {
79 _info[k] = gridCfg.GetString(k);
80 }
81 }
82 else if (null != netCfg)
83 {
84 _info["login"]
85 = String.Format(
86 "http://127.0.0.1:{0}/",
87 netCfg.GetString(
88 "http_listener_port", ConfigSettings.DefaultRegionHttpPort.ToString()));
89
90 IssueWarning();
91 }
92 else
93 {
94 _info["login"] = "http://127.0.0.1:9000/";
95 IssueWarning();
96 }
97 }
98 catch (Exception)
99 {
100 _log.Warn("[GRID INFO SERVICE]: Cannot get grid info from config source, using minimal defaults");
101 }
102
103 _log.DebugFormat("[GRID INFO SERVICE]: Grid info service initialized with {0} keys", _info.Count);
104 }
105
106 private void IssueWarning()
107 {
108 _log.Warn("[GRID INFO SERVICE]: found no [GridInfo] section in your configuration files");
109 _log.Warn("[GRID INFO SERVICE]: trying to guess sensible defaults, you might want to provide better ones:");
110
111 foreach (string k in _info.Keys)
112 {
113 _log.WarnFormat("[GRID INFO SERVICE]: {0}: {1}", k, _info[k]);
114 }
115 }
116
117 public XmlRpcResponse XmlRpcGridInfoMethod(XmlRpcRequest request, IPEndPoint remoteClient)
118 {
119 XmlRpcResponse response = new XmlRpcResponse();
120 Hashtable responseData = new Hashtable();
121
122 _log.Debug("[GRID INFO SERVICE]: Request for grid info");
123
124 foreach (string k in _info.Keys)
125 {
126 responseData[k] = _info[k];
127 }
128 response.Value = responseData;
129
130 return response;
131 }
132
133 public string RestGetGridInfoMethod(string request, string path, string param,
134 IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
135 {
136 StringBuilder sb = new StringBuilder();
137
138 sb.Append("<gridinfo>\n");
139 foreach (string k in _info.Keys)
140 {
141 sb.AppendFormat("<{0}>{1}</{0}>\n", k, SecurityElement.Escape(_info[k].ToString()));
142 }
143 sb.Append("</gridinfo>\n");
144
145 return sb.ToString();
146 }
147
148 /// <summary>
149 /// Get GridInfo in json format: Used bu the OSSL osGetGrid*
150 /// Adding the SRV_HomeIRI to the kvp returned for use in scripts
151 /// </summary>
152 /// <returns>
153 /// json string
154 /// </returns>
155 /// <param name='request'>
156 /// Request.
157 /// </param>
158 /// <param name='path'>
159 /// /json_grid_info
160 /// </param>
161 /// <param name='param'>
162 /// Parameter.
163 /// </param>
164 /// <param name='httpRequest'>
165 /// Http request.
166 /// </param>
167 /// <param name='httpResponse'>
168 /// Http response.
169 /// </param>
170 public string JsonGetGridInfoMethod(string request, string path, string param,
171 IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
172 {
173 OSDMap map = new OSDMap();
174
175 foreach (string k in _info.Keys)
176 {
177 map[k] = OSD.FromString(_info[k].ToString());
178 }
179
180 string HomeURI = Util.GetConfigVarFromSections<string>(m_Config, "HomeURI",
181 new string[] { "Startup", "Hypergrid" }, String.Empty);
182
183 if (!String.IsNullOrEmpty(HomeURI))
184 map["home"] = OSD.FromString(HomeURI);
185 else // Legacy. Remove soon!
186 {
187 IConfig cfg = m_Config.Configs["LoginService"];
188
189 if (null != cfg)
190 HomeURI = cfg.GetString("SRV_HomeURI", HomeURI);
191
192 if (!String.IsNullOrEmpty(HomeURI))
193 map["home"] = OSD.FromString(HomeURI);
194 }
195
196 return OSDParser.SerializeJsonString(map).ToString();
197 }
198 }
199}
diff --git a/OpenSim/Server/Handlers/Grid/GridInfoServerInConnector.cs b/OpenSim/Server/Handlers/Grid/GridInfoServerInConnector.cs
new file mode 100644
index 0000000..f9b5915
--- /dev/null
+++ b/OpenSim/Server/Handlers/Grid/GridInfoServerInConnector.cs
@@ -0,0 +1,57 @@
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
28using System;
29using System.Collections.Generic;
30using System.Reflection;
31using log4net;
32using OpenMetaverse;
33using Nini.Config;
34using OpenSim.Framework;
35using OpenSim.Framework.Servers.HttpServer;
36using OpenSim.Server.Handlers.Base;
37
38namespace OpenSim.Server.Handlers.Grid
39{
40 public class GridInfoServerInConnector : ServiceConnector
41 {
42// private string m_ConfigName = "GridInfoService";
43
44 public GridInfoServerInConnector(IConfigSource config, IHttpServer server, string configName) :
45 base(config, server, configName)
46 {
47 GridInfoHandlers handlers = new GridInfoHandlers(config);
48
49 server.AddStreamHandler(new RestStreamHandler("GET", "/get_grid_info",
50 handlers.RestGetGridInfoMethod));
51 server.AddStreamHandler(new RestStreamHandler("GET", "/json_grid_info",
52 handlers.JsonGetGridInfoMethod));
53 server.AddXmlRPCHandler("get_grid_info", handlers.XmlRpcGridInfoMethod);
54 }
55
56 }
57}
diff --git a/OpenSim/Server/Handlers/Grid/GridServerConnector.cs b/OpenSim/Server/Handlers/Grid/GridServerConnector.cs
new file mode 100644
index 0000000..6eb6a79
--- /dev/null
+++ b/OpenSim/Server/Handlers/Grid/GridServerConnector.cs
@@ -0,0 +1,64 @@
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
28using System;
29using Nini.Config;
30using OpenSim.Server.Base;
31using OpenSim.Services.Interfaces;
32using OpenSim.Framework.ServiceAuth;
33using OpenSim.Framework.Servers.HttpServer;
34using OpenSim.Server.Handlers.Base;
35
36namespace OpenSim.Server.Handlers.Grid
37{
38 public class GridServiceConnector : ServiceConnector
39 {
40 private IGridService m_GridService;
41 private string m_ConfigName = "GridService";
42
43 public GridServiceConnector(IConfigSource config, IHttpServer server, string configName) :
44 base(config, server, configName)
45 {
46 IConfig serverConfig = config.Configs[m_ConfigName];
47 if (serverConfig == null)
48 throw new Exception(String.Format("No section {0} in config file", m_ConfigName));
49
50 string gridService = serverConfig.GetString("LocalServiceModule",
51 String.Empty);
52
53 if (gridService == String.Empty)
54 throw new Exception("No LocalServiceModule in config file");
55
56 Object[] args = new Object[] { config };
57 m_GridService = ServerUtils.LoadPlugin<IGridService>(gridService, args);
58
59 IServiceAuth auth = ServiceAuth.Create(config, m_ConfigName);
60
61 server.AddStreamHandler(new GridServerPostHandler(m_GridService, auth));
62 }
63 }
64}
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
28using Nini.Config;
29using log4net;
30using System;
31using System.Reflection;
32using System.IO;
33using System.Net;
34using System.Text;
35using System.Text.RegularExpressions;
36using System.Xml;
37using System.Xml.Serialization;
38using System.Collections.Generic;
39using OpenSim.Server.Base;
40using OpenSim.Services.Interfaces;
41using GridRegion = OpenSim.Services.Interfaces.GridRegion;
42using OpenSim.Framework;
43using OpenSim.Framework.ServiceAuth;
44using OpenSim.Framework.Servers.HttpServer;
45using OpenMetaverse;
46
47namespace 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}