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/GridServerConnector.cs61
-rw-r--r--OpenSim/Server/Handlers/Grid/GridServerPostHandler.cs451
-rw-r--r--OpenSim/Server/Handlers/Grid/HypergridServerConnector.cs208
3 files changed, 720 insertions, 0 deletions
diff --git a/OpenSim/Server/Handlers/Grid/GridServerConnector.cs b/OpenSim/Server/Handlers/Grid/GridServerConnector.cs
new file mode 100644
index 0000000..14daf12
--- /dev/null
+++ b/OpenSim/Server/Handlers/Grid/GridServerConnector.cs
@@ -0,0 +1,61 @@
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.Servers.HttpServer;
33using OpenSim.Server.Handlers.Base;
34
35namespace OpenSim.Server.Handlers.Grid
36{
37 public class GridServiceConnector : ServiceConnector
38 {
39 private IGridService m_GridService;
40 private string m_ConfigName = "GridService";
41
42 public GridServiceConnector(IConfigSource config, IHttpServer server, string configName) :
43 base(config, server, configName)
44 {
45 IConfig serverConfig = config.Configs[m_ConfigName];
46 if (serverConfig == null)
47 throw new Exception(String.Format("No section {0} in config file", m_ConfigName));
48
49 string gridService = serverConfig.GetString("LocalServiceModule",
50 String.Empty);
51
52 if (gridService == String.Empty)
53 throw new Exception("No LocalServiceModule in config file");
54
55 Object[] args = new Object[] { config };
56 m_GridService = ServerUtils.LoadPlugin<IGridService>(gridService, args);
57
58 server.AddStreamHandler(new GridServerPostHandler(m_GridService));
59 }
60 }
61}
diff --git a/OpenSim/Server/Handlers/Grid/GridServerPostHandler.cs b/OpenSim/Server/Handlers/Grid/GridServerPostHandler.cs
new file mode 100644
index 0000000..e22328d
--- /dev/null
+++ b/OpenSim/Server/Handlers/Grid/GridServerPostHandler.cs
@@ -0,0 +1,451 @@
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.Servers.HttpServer;
44using OpenMetaverse;
45
46namespace OpenSim.Server.Handlers.Grid
47{
48 public class GridServerPostHandler : BaseStreamHandler
49 {
50 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
51
52 private IGridService m_GridService;
53
54 public GridServerPostHandler(IGridService service) :
55 base("POST", "/grid")
56 {
57 m_GridService = service;
58 }
59
60 public override byte[] Handle(string path, Stream requestData,
61 OSHttpRequest httpRequest, OSHttpResponse httpResponse)
62 {
63 StreamReader sr = new StreamReader(requestData);
64 string body = sr.ReadToEnd();
65 sr.Close();
66 body = body.Trim();
67
68 //m_log.DebugFormat("[XXX]: query String: {0}", body);
69
70 Dictionary<string, string> request =
71 ServerUtils.ParseQueryString(body);
72
73 if (!request.ContainsKey("METHOD"))
74 return FailureResult();
75
76 string method = request["METHOD"];
77
78 switch (method)
79 {
80 case "register":
81 return Register(request);
82
83 case "deregister":
84 return Deregister(request);
85
86 case "get_neighbours":
87 return GetNeighbours(request);
88
89 case "get_region_by_uuid":
90 return GetRegionByUUID(request);
91
92 case "get_region_by_position":
93 return GetRegionByPosition(request);
94
95 case "get_region_by_name":
96 return GetRegionByName(request);
97
98 case "get_regions_by_name":
99 return GetRegionsByName(request);
100
101 case "get_region_range":
102 return GetRegionRange(request);
103
104 }
105
106 m_log.DebugFormat("[GRID HANDLER]: unknown method {0} request {1}", method.Length, method);
107 return FailureResult();
108
109 }
110
111 #region Method-specific handlers
112
113 byte[] Register(Dictionary<string, string> request)
114 {
115 UUID scopeID = UUID.Zero;
116 if (request["SCOPEID"] != null)
117 UUID.TryParse(request["SCOPEID"], out scopeID);
118 else
119 m_log.WarnFormat("[GRID HANDLER]: no scopeID in request to register region");
120
121 int versionNumberMin = 0, versionNumberMax = 0;
122 if (request.ContainsKey("VERSIONMIN"))
123 Int32.TryParse(request["VERSIONMIN"], out versionNumberMin);
124 else
125 m_log.WarnFormat("[GRID HANDLER]: no minimum protocol version in request to register region");
126
127 if (request.ContainsKey("VERSIONMAX"))
128 Int32.TryParse(request["VERSIONMAX"], out versionNumberMax);
129 else
130 m_log.WarnFormat("[GRID HANDLER]: no maximum protocol version in request to register region");
131
132 // Check the protocol version
133 if ((versionNumberMin > ProtocolVersions.ServerProtocolVersionMax && versionNumberMax < ProtocolVersions.ServerProtocolVersionMax))
134 {
135 // Can't do, there is no overlap in the acceptable ranges
136 return FailureResult();
137 }
138
139 Dictionary<string, object> rinfoData = new Dictionary<string, object>();
140 foreach (KeyValuePair<string, string> kvp in request)
141 rinfoData[kvp.Key] = kvp.Value;
142 GridRegion rinfo = new GridRegion(rinfoData);
143
144 bool result = m_GridService.RegisterRegion(scopeID, rinfo);
145
146 if (result)
147 return SuccessResult();
148 else
149 return FailureResult();
150 }
151
152 byte[] Deregister(Dictionary<string, string> request)
153 {
154 UUID regionID = UUID.Zero;
155 if (request["REGIONID"] != null)
156 UUID.TryParse(request["REGIONID"], out regionID);
157 else
158 m_log.WarnFormat("[GRID HANDLER]: no regionID in request to deregister region");
159
160 bool result = m_GridService.DeregisterRegion(regionID);
161
162 if (result)
163 return SuccessResult();
164 else
165 return FailureResult();
166
167 }
168
169 byte[] GetNeighbours(Dictionary<string, string> request)
170 {
171 UUID scopeID = UUID.Zero;
172 if (request["SCOPEID"] != null)
173 UUID.TryParse(request["SCOPEID"], out scopeID);
174 else
175 m_log.WarnFormat("[GRID HANDLER]: no scopeID in request to get neighbours");
176
177 UUID regionID = UUID.Zero;
178 if (request["REGIONID"] != null)
179 UUID.TryParse(request["REGIONID"], out regionID);
180 else
181 m_log.WarnFormat("[GRID HANDLER]: no regionID in request to get neighbours");
182
183 List<GridRegion> rinfos = m_GridService.GetNeighbours(scopeID, regionID);
184 //m_log.DebugFormat("[GRID HANDLER]: neighbours for region {0}: {1}", regionID, rinfos.Count);
185
186 Dictionary<string, object> result = new Dictionary<string, object>();
187 if ((rinfos == null) || ((rinfos != null) && (rinfos.Count == 0)))
188 result["result"] = "null";
189 else
190 {
191 int i = 0;
192 foreach (GridRegion rinfo in rinfos)
193 {
194 Dictionary<string, object> rinfoDict = rinfo.ToKeyValuePairs();
195 result["region" + i] = rinfoDict;
196 i++;
197 }
198 }
199
200 string xmlString = ServerUtils.BuildXmlResponse(result);
201 //m_log.DebugFormat("[GRID HANDLER]: resp string: {0}", xmlString);
202 UTF8Encoding encoding = new UTF8Encoding();
203 return encoding.GetBytes(xmlString);
204
205 }
206
207 byte[] GetRegionByUUID(Dictionary<string, string> request)
208 {
209 UUID scopeID = UUID.Zero;
210 if (request["SCOPEID"] != null)
211 UUID.TryParse(request["SCOPEID"], out scopeID);
212 else
213 m_log.WarnFormat("[GRID HANDLER]: no scopeID in request to get neighbours");
214
215 UUID regionID = UUID.Zero;
216 if (request["REGIONID"] != null)
217 UUID.TryParse(request["REGIONID"], out regionID);
218 else
219 m_log.WarnFormat("[GRID HANDLER]: no regionID in request to get neighbours");
220
221 GridRegion rinfo = m_GridService.GetRegionByUUID(scopeID, regionID);
222 //m_log.DebugFormat("[GRID HANDLER]: neighbours for region {0}: {1}", regionID, rinfos.Count);
223
224 Dictionary<string, object> result = new Dictionary<string, object>();
225 if (rinfo == null)
226 result["result"] = "null";
227 else
228 result["result"] = rinfo.ToKeyValuePairs();
229
230 string xmlString = ServerUtils.BuildXmlResponse(result);
231 //m_log.DebugFormat("[GRID HANDLER]: resp string: {0}", xmlString);
232 UTF8Encoding encoding = new UTF8Encoding();
233 return encoding.GetBytes(xmlString);
234 }
235
236 byte[] GetRegionByPosition(Dictionary<string, string> request)
237 {
238 UUID scopeID = UUID.Zero;
239 if (request["SCOPEID"] != null)
240 UUID.TryParse(request["SCOPEID"], out scopeID);
241 else
242 m_log.WarnFormat("[GRID HANDLER]: no scopeID in request to get region by position");
243
244 int x = 0, y = 0;
245 if (request["X"] != null)
246 Int32.TryParse(request["X"], out x);
247 else
248 m_log.WarnFormat("[GRID HANDLER]: no X in request to get region by position");
249 if (request["Y"] != null)
250 Int32.TryParse(request["Y"], out y);
251 else
252 m_log.WarnFormat("[GRID HANDLER]: no Y in request to get region by position");
253
254 GridRegion rinfo = m_GridService.GetRegionByPosition(scopeID, x, y);
255 //m_log.DebugFormat("[GRID HANDLER]: neighbours for region {0}: {1}", regionID, rinfos.Count);
256
257 Dictionary<string, object> result = new Dictionary<string, object>();
258 if (rinfo == null)
259 result["result"] = "null";
260 else
261 result["result"] = rinfo.ToKeyValuePairs();
262
263 string xmlString = ServerUtils.BuildXmlResponse(result);
264 //m_log.DebugFormat("[GRID HANDLER]: resp string: {0}", xmlString);
265 UTF8Encoding encoding = new UTF8Encoding();
266 return encoding.GetBytes(xmlString);
267 }
268
269 byte[] GetRegionByName(Dictionary<string, string> request)
270 {
271 UUID scopeID = UUID.Zero;
272 if (request["SCOPEID"] != null)
273 UUID.TryParse(request["SCOPEID"], out scopeID);
274 else
275 m_log.WarnFormat("[GRID HANDLER]: no scopeID in request to get region by name");
276
277 string regionName = string.Empty;
278 if (request["NAME"] != null)
279 regionName = request["NAME"];
280 else
281 m_log.WarnFormat("[GRID HANDLER]: no name in request to get region by name");
282
283 GridRegion rinfo = m_GridService.GetRegionByName(scopeID, regionName);
284 //m_log.DebugFormat("[GRID HANDLER]: neighbours for region {0}: {1}", regionID, rinfos.Count);
285
286 Dictionary<string, object> result = new Dictionary<string, object>();
287 if (rinfo == null)
288 result["result"] = "null";
289 else
290 result["result"] = rinfo.ToKeyValuePairs();
291
292 string xmlString = ServerUtils.BuildXmlResponse(result);
293 //m_log.DebugFormat("[GRID HANDLER]: resp string: {0}", xmlString);
294 UTF8Encoding encoding = new UTF8Encoding();
295 return encoding.GetBytes(xmlString);
296 }
297
298 byte[] GetRegionsByName(Dictionary<string, string> request)
299 {
300 UUID scopeID = UUID.Zero;
301 if (request["SCOPEID"] != null)
302 UUID.TryParse(request["SCOPEID"], out scopeID);
303 else
304 m_log.WarnFormat("[GRID HANDLER]: no scopeID in request to get regions by name");
305
306 string regionName = string.Empty;
307 if (request["NAME"] != null)
308 regionName = request["NAME"];
309 else
310 m_log.WarnFormat("[GRID HANDLER]: no NAME in request to get regions by name");
311
312 int max = 0;
313 if (request["MAX"] != null)
314 Int32.TryParse(request["MAX"], out max);
315 else
316 m_log.WarnFormat("[GRID HANDLER]: no MAX in request to get regions by name");
317
318 List<GridRegion> rinfos = m_GridService.GetRegionsByName(scopeID, regionName, max);
319 //m_log.DebugFormat("[GRID HANDLER]: neighbours for region {0}: {1}", regionID, rinfos.Count);
320
321 Dictionary<string, object> result = new Dictionary<string, object>();
322 if ((rinfos == null) || ((rinfos != null) && (rinfos.Count == 0)))
323 result["result"] = "null";
324 else
325 {
326 int i = 0;
327 foreach (GridRegion rinfo in rinfos)
328 {
329 Dictionary<string, object> rinfoDict = rinfo.ToKeyValuePairs();
330 result["region" + i] = rinfoDict;
331 i++;
332 }
333 }
334
335 string xmlString = ServerUtils.BuildXmlResponse(result);
336 //m_log.DebugFormat("[GRID HANDLER]: resp string: {0}", xmlString);
337 UTF8Encoding encoding = new UTF8Encoding();
338 return encoding.GetBytes(xmlString);
339 }
340
341 byte[] GetRegionRange(Dictionary<string, string> request)
342 {
343 //m_log.DebugFormat("[GRID HANDLER]: GetRegionRange");
344 UUID scopeID = UUID.Zero;
345 if (request.ContainsKey("SCOPEID"))
346 UUID.TryParse(request["SCOPEID"], out scopeID);
347 else
348 m_log.WarnFormat("[GRID HANDLER]: no scopeID in request to get region range");
349
350 int xmin = 0, xmax = 0, ymin = 0, ymax = 0;
351 if (request.ContainsKey("XMIN"))
352 Int32.TryParse(request["XMIN"], out xmin);
353 else
354 m_log.WarnFormat("[GRID HANDLER]: no XMIN in request to get region range");
355 if (request.ContainsKey("XMAX"))
356 Int32.TryParse(request["XMAX"], out xmax);
357 else
358 m_log.WarnFormat("[GRID HANDLER]: no XMAX in request to get region range");
359 if (request.ContainsKey("YMIN"))
360 Int32.TryParse(request["YMIN"], out ymin);
361 else
362 m_log.WarnFormat("[GRID HANDLER]: no YMIN in request to get region range");
363 if (request.ContainsKey("YMAX"))
364 Int32.TryParse(request["YMAX"], out ymax);
365 else
366 m_log.WarnFormat("[GRID HANDLER]: no YMAX in request to get region range");
367
368
369 List<GridRegion> rinfos = m_GridService.GetRegionRange(scopeID, xmin, xmax, ymin, ymax);
370
371 Dictionary<string, object> result = new Dictionary<string, object>();
372 if ((rinfos == null) || ((rinfos != null) && (rinfos.Count == 0)))
373 result["result"] = "null";
374 else
375 {
376 int i = 0;
377 foreach (GridRegion rinfo in rinfos)
378 {
379 Dictionary<string, object> rinfoDict = rinfo.ToKeyValuePairs();
380 result["region" + i] = rinfoDict;
381 i++;
382 }
383 }
384 string xmlString = ServerUtils.BuildXmlResponse(result);
385 //m_log.DebugFormat("[GRID HANDLER]: resp string: {0}", xmlString);
386 UTF8Encoding encoding = new UTF8Encoding();
387 return encoding.GetBytes(xmlString);
388 }
389
390 #endregion
391
392 #region Misc
393
394 private byte[] SuccessResult()
395 {
396 XmlDocument doc = new XmlDocument();
397
398 XmlNode xmlnode = doc.CreateNode(XmlNodeType.XmlDeclaration,
399 "", "");
400
401 doc.AppendChild(xmlnode);
402
403 XmlElement rootElement = doc.CreateElement("", "ServerResponse",
404 "");
405
406 doc.AppendChild(rootElement);
407
408 XmlElement result = doc.CreateElement("", "Result", "");
409 result.AppendChild(doc.CreateTextNode("Success"));
410
411 rootElement.AppendChild(result);
412
413 return DocToBytes(doc);
414 }
415
416 private byte[] FailureResult()
417 {
418 XmlDocument doc = new XmlDocument();
419
420 XmlNode xmlnode = doc.CreateNode(XmlNodeType.XmlDeclaration,
421 "", "");
422
423 doc.AppendChild(xmlnode);
424
425 XmlElement rootElement = doc.CreateElement("", "ServerResponse",
426 "");
427
428 doc.AppendChild(rootElement);
429
430 XmlElement result = doc.CreateElement("", "Result", "");
431 result.AppendChild(doc.CreateTextNode("Failure"));
432
433 rootElement.AppendChild(result);
434
435 return DocToBytes(doc);
436 }
437
438 private byte[] DocToBytes(XmlDocument doc)
439 {
440 MemoryStream ms = new MemoryStream();
441 XmlTextWriter xw = new XmlTextWriter(ms, null);
442 xw.Formatting = Formatting.Indented;
443 doc.WriteTo(xw);
444 xw.Flush();
445
446 return ms.ToArray();
447 }
448
449 #endregion
450 }
451}
diff --git a/OpenSim/Server/Handlers/Grid/HypergridServerConnector.cs b/OpenSim/Server/Handlers/Grid/HypergridServerConnector.cs
new file mode 100644
index 0000000..115ac29
--- /dev/null
+++ b/OpenSim/Server/Handlers/Grid/HypergridServerConnector.cs
@@ -0,0 +1,208 @@
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.Collections.Generic;
31using System.Reflection;
32using System.Net;
33using Nini.Config;
34using OpenSim.Framework;
35using OpenSim.Server.Base;
36using OpenSim.Services.Interfaces;
37using OpenSim.Framework.Servers.HttpServer;
38using OpenSim.Server.Handlers.Base;
39using GridRegion = OpenSim.Services.Interfaces.GridRegion;
40
41using OpenMetaverse;
42using log4net;
43using Nwc.XmlRpc;
44
45namespace OpenSim.Server.Handlers.Grid
46{
47 public class HypergridServiceInConnector : ServiceConnector
48 {
49 private static readonly ILog m_log =
50 LogManager.GetLogger(
51 MethodBase.GetCurrentMethod().DeclaringType);
52
53 private List<GridRegion> m_RegionsOnSim = new List<GridRegion>();
54 private IHyperlinkService m_HyperlinkService;
55
56 public HypergridServiceInConnector(IConfigSource config, IHttpServer server, IHyperlinkService hyperService) :
57 base(config, server, String.Empty)
58 {
59 m_HyperlinkService = hyperService;
60 server.AddXmlRPCHandler("link_region", LinkRegionRequest, false);
61 server.AddXmlRPCHandler("expect_hg_user", ExpectHGUser, false);
62 }
63
64 public void AddRegion(GridRegion rinfo)
65 {
66 m_RegionsOnSim.Add(rinfo);
67 }
68
69 public void RemoveRegion(GridRegion rinfo)
70 {
71 if (m_RegionsOnSim.Contains(rinfo))
72 m_RegionsOnSim.Remove(rinfo);
73 }
74
75 /// <summary>
76 /// Someone wants to link to us
77 /// </summary>
78 /// <param name="request"></param>
79 /// <returns></returns>
80 public XmlRpcResponse LinkRegionRequest(XmlRpcRequest request, IPEndPoint remoteClient)
81 {
82 Hashtable requestData = (Hashtable)request.Params[0];
83 //string host = (string)requestData["host"];
84 //string portstr = (string)requestData["port"];
85 string name = (string)requestData["region_name"];
86
87 m_log.DebugFormat("[HGrid]: Hyperlink request");
88
89 GridRegion regInfo = null;
90 foreach (GridRegion r in m_RegionsOnSim)
91 {
92 if ((r.RegionName != null) && (name != null) && (r.RegionName.ToLower() == name.ToLower()))
93 {
94 regInfo = r;
95 break;
96 }
97 }
98
99 if (regInfo == null)
100 regInfo = m_RegionsOnSim[0]; // Send out the first region
101
102 Hashtable hash = new Hashtable();
103 hash["uuid"] = regInfo.RegionID.ToString();
104 m_log.Debug(">> Here " + regInfo.RegionID);
105 hash["handle"] = regInfo.RegionHandle.ToString();
106 hash["region_image"] = regInfo.TerrainImage.ToString();
107 hash["region_name"] = regInfo.RegionName;
108 hash["internal_port"] = regInfo.InternalEndPoint.Port.ToString();
109 //m_log.Debug(">> Here: " + regInfo.InternalEndPoint.Port);
110
111
112 XmlRpcResponse response = new XmlRpcResponse();
113 response.Value = hash;
114 return response;
115 }
116
117 /// <summary>
118 /// Received from other HGrid nodes when a user wants to teleport here. This call allows
119 /// the region to prepare for direct communication from the client. Sends back an empty
120 /// xmlrpc response on completion.
121 /// This is somewhat similar to OGS1's ExpectUser, but with the additional task of
122 /// registering the user in the local user cache.
123 /// </summary>
124 /// <param name="request"></param>
125 /// <returns></returns>
126 public XmlRpcResponse ExpectHGUser(XmlRpcRequest request, IPEndPoint remoteClient)
127 {
128 Hashtable requestData = (Hashtable)request.Params[0];
129 ForeignUserProfileData userData = new ForeignUserProfileData();
130
131 userData.FirstName = (string)requestData["firstname"];
132 userData.SurName = (string)requestData["lastname"];
133 userData.ID = new UUID((string)requestData["agent_id"]);
134 UUID sessionID = new UUID((string)requestData["session_id"]);
135 userData.HomeLocation = new Vector3((float)Convert.ToDecimal((string)requestData["startpos_x"]),
136 (float)Convert.ToDecimal((string)requestData["startpos_y"]),
137 (float)Convert.ToDecimal((string)requestData["startpos_z"]));
138
139 userData.UserServerURI = (string)requestData["userserver_id"];
140 userData.UserAssetURI = (string)requestData["assetserver_id"];
141 userData.UserInventoryURI = (string)requestData["inventoryserver_id"];
142
143 m_log.DebugFormat("[HGrid]: Prepare for connection from {0} {1} (@{2}) UUID={3}",
144 userData.FirstName, userData.SurName, userData.UserServerURI, userData.ID);
145
146 ulong userRegionHandle = 0;
147 int userhomeinternalport = 0;
148 if (requestData.ContainsKey("region_uuid"))
149 {
150 UUID uuid = UUID.Zero;
151 UUID.TryParse((string)requestData["region_uuid"], out uuid);
152 userData.HomeRegionID = uuid;
153 userRegionHandle = Convert.ToUInt64((string)requestData["regionhandle"]);
154 userData.UserHomeAddress = (string)requestData["home_address"];
155 userData.UserHomePort = (string)requestData["home_port"];
156 userhomeinternalport = Convert.ToInt32((string)requestData["internal_port"]);
157
158 m_log.Debug("[HGrid]: home_address: " + userData.UserHomeAddress +
159 "; home_port: " + userData.UserHomePort);
160 }
161 else
162 m_log.WarnFormat("[HGrid]: User has no home region information");
163
164 XmlRpcResponse resp = new XmlRpcResponse();
165
166 // Let's check if someone is trying to get in with a stolen local identity.
167 // The need for this test is a consequence of not having truly global names :-/
168 bool comingHome = false;
169 if (m_HyperlinkService.CheckUserAtEntry(userData.ID, sessionID, out comingHome) == false)
170 {
171 m_log.WarnFormat("[HGrid]: Access denied to foreign user.");
172 Hashtable respdata = new Hashtable();
173 respdata["success"] = "FALSE";
174 respdata["reason"] = "Foreign user has the same ID as a local user, or logins disabled.";
175 resp.Value = respdata;
176 return resp;
177 }
178
179 // Finally, everything looks ok
180 //m_log.Debug("XXX---- EVERYTHING OK ---XXX");
181
182 if (!comingHome)
183 {
184 // We don't do this if the user is coming to the home grid
185 GridRegion home = new GridRegion();
186 home.RegionID = userData.HomeRegionID;
187 home.ExternalHostName = userData.UserHomeAddress;
188 home.HttpPort = Convert.ToUInt32(userData.UserHomePort);
189 uint x = 0, y = 0;
190 Utils.LongToUInts(userRegionHandle, out x, out y);
191 home.RegionLocX = (int)x;
192 home.RegionLocY = (int)y;
193 home.InternalEndPoint = new IPEndPoint(IPAddress.Parse("0.0.0.0"), (int)userhomeinternalport);
194
195 m_HyperlinkService.AcceptUser(userData, home);
196 }
197 // else the user is coming to a non-home region of the home grid
198 // We simply drop this user information altogether
199
200 Hashtable respdata2 = new Hashtable();
201 respdata2["success"] = "TRUE";
202 resp.Value = respdata2;
203
204 return resp;
205 }
206
207 }
208}