aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Communications
diff options
context:
space:
mode:
authorMelanie2009-09-28 23:03:47 +0100
committerMelanie2009-09-28 23:03:47 +0100
commit07091493134341a316624d9a1f6a2ef1cfa2f2d8 (patch)
tree1d394e128be9766656a441058b2bdf141ba90269 /OpenSim/Region/Communications
parentAllow the notation config_name@port/dll_name:class_name as a handler spec (diff)
parentForgot a return statement. (diff)
downloadopensim-SC_OLD-07091493134341a316624d9a1f6a2ef1cfa2f2d8.zip
opensim-SC_OLD-07091493134341a316624d9a1f6a2ef1cfa2f2d8.tar.gz
opensim-SC_OLD-07091493134341a316624d9a1f6a2ef1cfa2f2d8.tar.bz2
opensim-SC_OLD-07091493134341a316624d9a1f6a2ef1cfa2f2d8.tar.xz
Merge branch 'grid-service-redux'
Diffstat (limited to 'OpenSim/Region/Communications')
-rw-r--r--OpenSim/Region/Communications/Hypergrid/HGCommunicationsGridMode.cs9
-rw-r--r--OpenSim/Region/Communications/Hypergrid/HGCommunicationsStandalone.cs3
-rw-r--r--OpenSim/Region/Communications/Hypergrid/HGGridServices.cs1024
-rw-r--r--OpenSim/Region/Communications/Hypergrid/HGGridServicesGridMode.cs159
-rw-r--r--OpenSim/Region/Communications/Hypergrid/HGGridServicesStandalone.cs259
-rw-r--r--OpenSim/Region/Communications/Local/CommunicationsLocal.cs2
-rw-r--r--OpenSim/Region/Communications/Local/LocalBackEndServices.cs410
-rw-r--r--OpenSim/Region/Communications/OGS1/CommunicationsOGS1.cs2
-rw-r--r--OpenSim/Region/Communications/OGS1/OGS1GridServices.cs937
9 files changed, 0 insertions, 2805 deletions
diff --git a/OpenSim/Region/Communications/Hypergrid/HGCommunicationsGridMode.cs b/OpenSim/Region/Communications/Hypergrid/HGCommunicationsGridMode.cs
index 80f2e79..002ea17 100644
--- a/OpenSim/Region/Communications/Hypergrid/HGCommunicationsGridMode.cs
+++ b/OpenSim/Region/Communications/Hypergrid/HGCommunicationsGridMode.cs
@@ -40,21 +40,12 @@ namespace OpenSim.Region.Communications.Hypergrid
40{ 40{
41 public class HGCommunicationsGridMode : CommunicationsManager // CommunicationsOGS1 41 public class HGCommunicationsGridMode : CommunicationsManager // CommunicationsOGS1
42 { 42 {
43 IHyperlink m_osw = null;
44 public IHyperlink HGServices
45 {
46 get { return m_osw; }
47 }
48 43
49 public HGCommunicationsGridMode( 44 public HGCommunicationsGridMode(
50 NetworkServersInfo serversInfo, 45 NetworkServersInfo serversInfo,
51 SceneManager sman, LibraryRootFolder libraryRootFolder) 46 SceneManager sman, LibraryRootFolder libraryRootFolder)
52 : base(serversInfo, libraryRootFolder) 47 : base(serversInfo, libraryRootFolder)
53 { 48 {
54 // From constructor at CommunicationsOGS1
55 HGGridServices gridInterComms = new HGGridServicesGridMode(serversInfo, sman, m_userProfileCacheService);
56 m_gridService = gridInterComms;
57 m_osw = gridInterComms;
58 49
59 HGUserServices userServices = new HGUserServices(this); 50 HGUserServices userServices = new HGUserServices(this);
60 // This plugin arrangement could eventually be configurable rather than hardcoded here. 51 // This plugin arrangement could eventually be configurable rather than hardcoded here.
diff --git a/OpenSim/Region/Communications/Hypergrid/HGCommunicationsStandalone.cs b/OpenSim/Region/Communications/Hypergrid/HGCommunicationsStandalone.cs
index e4e12d4..f5126ca 100644
--- a/OpenSim/Region/Communications/Hypergrid/HGCommunicationsStandalone.cs
+++ b/OpenSim/Region/Communications/Hypergrid/HGCommunicationsStandalone.cs
@@ -44,7 +44,6 @@ namespace OpenSim.Region.Communications.Hypergrid
44 ConfigSettings configSettings, 44 ConfigSettings configSettings,
45 NetworkServersInfo serversInfo, 45 NetworkServersInfo serversInfo,
46 BaseHttpServer httpServer, 46 BaseHttpServer httpServer,
47 HGGridServices gridService,
48 LibraryRootFolder libraryRootFolder, 47 LibraryRootFolder libraryRootFolder,
49 bool dumpAssetsToFile) 48 bool dumpAssetsToFile)
50 : base(serversInfo, libraryRootFolder) 49 : base(serversInfo, libraryRootFolder)
@@ -64,8 +63,6 @@ namespace OpenSim.Region.Communications.Hypergrid
64 m_avatarService = hgUserService; 63 m_avatarService = hgUserService;
65 m_messageService = hgUserService; 64 m_messageService = hgUserService;
66 65
67 gridService.UserProfileCache = m_userProfileCacheService;
68 m_gridService = gridService;
69 } 66 }
70 } 67 }
71} 68}
diff --git a/OpenSim/Region/Communications/Hypergrid/HGGridServices.cs b/OpenSim/Region/Communications/Hypergrid/HGGridServices.cs
deleted file mode 100644
index 54cde0f..0000000
--- a/OpenSim/Region/Communications/Hypergrid/HGGridServices.cs
+++ /dev/null
@@ -1,1024 +0,0 @@
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
29using System;
30using System.Collections;
31using System.Collections.Generic;
32using System.Drawing;
33using System.Net;
34using System.Net.Sockets;
35using System.Reflection;
36using System.Runtime.Remoting;
37using System.Security.Authentication;
38using log4net;
39using Nwc.XmlRpc;
40using OpenMetaverse;
41using OpenMetaverse.Imaging;
42using OpenSim.Framework;
43using OpenSim.Framework.Communications;
44using OpenSim.Framework.Communications.Cache;
45using OpenSim.Framework.Servers;
46using OpenSim.Framework.Servers.HttpServer;
47using OpenSim.Region.Communications.OGS1;
48using OpenSim.Region.Framework.Scenes;
49using OpenSim.Services.Interfaces;
50// using OpenSim.Region.Environment.Modules.Framework;
51
52namespace OpenSim.Region.Communications.Hypergrid
53{
54 /// <summary>
55 /// This class encapsulates the main hypergrid functions related to creating and managing
56 /// hyperlinks, as well as processing all the inter-region comms between a region and
57 /// an hyperlinked region.
58 /// </summary>
59 public class HGGridServices : IGridServices, IHyperlink
60 {
61 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
62
63
64 public BaseHttpServer httpListener;
65 public NetworkServersInfo serversInfo;
66
67 protected List<RegionInfo> m_regionsOnInstance = new List<RegionInfo>();
68
69 // Hyperlink regions are hyperlinks on the map
70 protected List<RegionInfo> m_hyperlinkRegions = new List<RegionInfo>();
71
72 // Known regions are home regions of visiting foreign users.
73 // They are not on the map as static hyperlinks. They are dynamic hyperlinks, they go away when
74 // the visitor goes away. They are mapped to X=0 on the map.
75 // This is key-ed on agent ID
76 protected Dictionary<UUID, RegionInfo> m_knownRegions = new Dictionary<UUID, RegionInfo>();
77
78 protected UserProfileCacheService m_userProfileCache;
79 protected SceneManager m_sceneman;
80
81 private Dictionary<string, string> m_queuedGridSettings = new Dictionary<string, string>();
82
83 public virtual string gdebugRegionName
84 {
85 get { return "Override me"; }
86 set { ; }
87 }
88
89 public string rdebugRegionName
90 {
91 get { return _rdebugRegionName; }
92 set { _rdebugRegionName = value; }
93 }
94 private string _rdebugRegionName = String.Empty;
95
96 public virtual bool RegionLoginsEnabled
97 {
98 get { return true; }
99 set { ; }
100 }
101
102 public UserProfileCacheService UserProfileCache
103 {
104 set { m_userProfileCache = value; }
105 }
106
107 private Random random;
108
109 /// <summary>
110 /// Contructor. Adds "expect_hg_user" and "check" xmlrpc method handlers
111 /// </summary>
112 /// <param name="servers_info"></param>
113 public HGGridServices(NetworkServersInfo servers_info, SceneManager sman)
114 {
115 serversInfo = servers_info;
116 m_sceneman = sman;
117
118 random = new Random();
119
120 MainServer.Instance.AddXmlRPCHandler("link_region", LinkRegionRequest);
121 MainServer.Instance.AddXmlRPCHandler("expect_hg_user", ExpectHGUser);
122
123 HGNetworkServersInfo.Init(servers_info.AssetURL, servers_info.InventoryURL, servers_info.UserURL);
124 }
125
126 // see IGridServices
127 public virtual RegionCommsListener RegisterRegion(RegionInfo regionInfo)
128 {
129 // Region doesn't exist here. Trying to link remote region
130
131 m_log.Info("[HGrid]: Linking remote region " + regionInfo.ExternalHostName + ":" + regionInfo.HttpPort);
132 regionInfo.RegionID = LinkRegion(regionInfo); // UUID.Random();
133 if (!regionInfo.RegionID.Equals(UUID.Zero))
134 {
135 m_hyperlinkRegions.Add(regionInfo);
136 m_log.Info("[HGrid]: Successfully linked to region_uuid " + regionInfo.RegionID);
137
138 //Try get the map image
139 GetMapImage(regionInfo);
140 }
141 else
142 {
143 m_log.Info("[HGrid]: No such region " + regionInfo.ExternalHostName + ":" + regionInfo.HttpPort + "(" + regionInfo.InternalEndPoint.Port + ")");
144 }
145 // Note that these remote regions aren't registered in localBackend, so return null, no local listeners
146 return null;
147 }
148
149 // see IGridServices
150 public virtual bool DeregisterRegion(RegionInfo regionInfo)
151 {
152 if (m_hyperlinkRegions.Contains(regionInfo))
153 {
154 m_hyperlinkRegions.Remove(regionInfo);
155 return true;
156 }
157 foreach (KeyValuePair<UUID, RegionInfo> kvp in m_knownRegions)
158 {
159 if (kvp.Value == regionInfo)
160 {
161 m_knownRegions.Remove(kvp.Key);
162 return true;
163 }
164 }
165 return false;
166 }
167
168 public virtual Dictionary<string, string> GetGridSettings()
169 {
170 Dictionary<string, string> returnGridSettings = new Dictionary<string, string>();
171 lock (m_queuedGridSettings)
172 {
173 foreach (string Dictkey in m_queuedGridSettings.Keys)
174 {
175 returnGridSettings.Add(Dictkey, m_queuedGridSettings[Dictkey]);
176 }
177
178 m_queuedGridSettings.Clear();
179 }
180
181 return returnGridSettings;
182 }
183
184 // see IGridServices
185 public virtual List<SimpleRegionInfo> RequestNeighbours(uint x, uint y)
186 {
187 List<SimpleRegionInfo> neighbours = new List<SimpleRegionInfo>();
188 foreach (RegionInfo reg in m_hyperlinkRegions)
189 {
190 if (reg.RegionLocX != x || reg.RegionLocY != y)
191 {
192 //m_log.Debug("CommsManager- RequestNeighbours() - found a different region in list, checking location");
193 if ((reg.RegionLocX > (x - 2)) && (reg.RegionLocX < (x + 2)))
194 {
195 if ((reg.RegionLocY > (y - 2)) && (reg.RegionLocY < (y + 2)))
196 {
197 neighbours.Add(reg);
198 }
199 }
200 }
201 }
202
203 return neighbours;
204 }
205
206 /// <summary>
207 /// Request information about a region.
208 /// </summary>
209 /// <param name="regionHandle"></param>
210 /// <returns>
211 /// null on a failure to contact or get a response from the grid server
212 /// FIXME: Might be nicer to return a proper exception here since we could inform the client more about the
213 /// nature of the faiulre.
214 /// </returns>
215 public virtual RegionInfo RequestNeighbourInfo(UUID Region_UUID)
216 {
217 foreach (RegionInfo info in m_hyperlinkRegions)
218 {
219 if (info.RegionID == Region_UUID) return info;
220 }
221
222 // I don't trust region uuids to be unique...
223 //foreach (RegionInfo info in m_knownRegions.Values)
224 //{
225 // if (info.RegionID == Region_UUID) return info;
226 //}
227
228 return null;
229 }
230
231 /// <summary>
232 /// Request information about a region.
233 /// </summary>
234 /// <param name="regionHandle"></param>
235 /// <returns></returns>
236 public virtual RegionInfo RequestNeighbourInfo(ulong regionHandle)
237 {
238 //m_log.Debug(" >> RequestNeighbourInfo for " + regionHandle);
239 foreach (RegionInfo info in m_hyperlinkRegions)
240 {
241 //m_log.Debug(" .. " + info.RegionHandle);
242 if (info.RegionHandle == regionHandle) return info;
243 }
244
245 foreach (RegionInfo info in m_knownRegions.Values)
246 {
247 if (info.RegionHandle == regionHandle)
248 {
249 //m_log.Debug("XXX------ known region " + info.RegionHandle);
250 return info;
251 }
252 }
253
254 return null;
255 }
256
257 public virtual RegionInfo RequestNeighbourInfo(string name)
258 {
259 foreach (RegionInfo info in m_hyperlinkRegions)
260 {
261 //m_log.Debug(" .. " + info.RegionHandle);
262 if (info.RegionName == name) return info;
263 }
264
265 foreach (RegionInfo info in m_knownRegions.Values)
266 {
267 if (info.RegionName == name)
268 {
269 //m_log.Debug("XXX------ known region " + info.RegionHandle);
270 return info;
271 }
272 }
273
274 return null;
275 }
276
277 public virtual RegionInfo RequestNeighbourInfo(string hostName, uint port)
278 {
279 foreach (RegionInfo info in m_hyperlinkRegions)
280 {
281 //m_log.Debug(" .. " + info.RegionHandle);
282 if ((info.ExternalHostName == hostName) && (info.HttpPort == port))
283 return info;
284 }
285
286 foreach (RegionInfo info in m_knownRegions.Values)
287 {
288 if ((info.ExternalHostName == hostName) && (info.HttpPort == port))
289 {
290 //m_log.Debug("XXX------ known region " + info.RegionHandle);
291 return info;
292 }
293 }
294
295 return null;
296 }
297
298 public virtual RegionInfo RequestClosestRegion(string regionName)
299 {
300 foreach (RegionInfo info in m_hyperlinkRegions)
301 {
302 if (info.RegionName == regionName) return info;
303 }
304
305 return null;
306 }
307
308 /// <summary>
309 ///
310 /// </summary>
311 /// <param name="minX"></param>
312 /// <param name="minY"></param>
313 /// <param name="maxX"></param>
314 /// <param name="maxY"></param>
315 /// <returns></returns>
316 public virtual List<MapBlockData> RequestNeighbourMapBlocks(int minX, int minY, int maxX, int maxY)
317 {
318 List<MapBlockData> neighbours = new List<MapBlockData>();
319
320 foreach (RegionInfo regInfo in m_hyperlinkRegions)
321 {
322 if (((regInfo.RegionLocX >= minX) && (regInfo.RegionLocX <= maxX)) &&
323 ((regInfo.RegionLocY >= minY) && (regInfo.RegionLocY <= maxY)))
324 {
325 MapBlockData map = new MapBlockData();
326 map.Name = regInfo.RegionName;
327 map.X = (ushort)regInfo.RegionLocX;
328 map.Y = (ushort)regInfo.RegionLocY;
329 map.WaterHeight = (byte)regInfo.RegionSettings.WaterHeight;
330 map.MapImageId = regInfo.RegionSettings.TerrainImageID;
331 // m_log.Debug("ImgID: " + map.MapImageId);
332 map.Agents = 1;
333 map.RegionFlags = 72458694;
334 map.Access = regInfo.AccessLevel;
335 neighbours.Add(map);
336 }
337 }
338
339 return neighbours;
340 }
341
342
343 protected virtual void GetMapImage(RegionInfo info)
344 {
345 try
346 {
347 string regionimage = "regionImage" + info.RegionID.ToString();
348 regionimage = regionimage.Replace("-", "");
349
350 WebClient c = new WebClient();
351 string uri = "http://" + info.ExternalHostName + ":" + info.HttpPort + "/index.php?method=" + regionimage;
352 //m_log.Debug("JPEG: " + uri);
353 c.DownloadFile(uri, info.RegionID.ToString() + ".jpg");
354 Bitmap m = new Bitmap(info.RegionID.ToString() + ".jpg");
355 //m_log.Debug("Size: " + m.PhysicalDimension.Height + "-" + m.PhysicalDimension.Width);
356 byte[] imageData = OpenJPEG.EncodeFromImage(m, true);
357 AssetBase ass = new AssetBase(UUID.Random(), "region " + info.RegionID.ToString());
358 info.RegionSettings.TerrainImageID = ass.FullID;
359 ass.Type = (int)AssetType.Texture;
360 ass.Temporary = false;
361 ass.Local = true;
362 ass.Data = imageData;
363
364 m_sceneman.CurrentOrFirstScene.AssetService.Store(ass);
365
366 }
367 catch // LEGIT: Catching problems caused by OpenJPEG p/invoke
368 {
369 m_log.Warn("[HGrid]: Failed getting/storing map image, because it is probably already in the cache");
370 }
371 }
372
373 // A little ugly, since this code is exactly the same as OSG1's, and we're already
374 // calling that for when the region in in grid mode... (for the grid regions)
375 //
376 public virtual LandData RequestLandData (ulong regionHandle, uint x, uint y)
377 {
378 m_log.DebugFormat("[HGrid]: requests land data in {0}, at {1}, {2}",
379 regionHandle, x, y);
380
381 // Remote region
382
383 Hashtable hash = new Hashtable();
384 hash["region_handle"] = regionHandle.ToString();
385 hash["x"] = x.ToString();
386 hash["y"] = y.ToString();
387
388 IList paramList = new ArrayList();
389 paramList.Add(hash);
390 LandData landData = null;
391
392 try
393 {
394 RegionInfo info = RequestNeighbourInfo(regionHandle);
395 if (info != null) // just to be sure
396 {
397 XmlRpcRequest request = new XmlRpcRequest("land_data", paramList);
398 string uri = "http://" + info.ExternalEndPoint.Address + ":" + info.HttpPort + "/";
399 XmlRpcResponse response = request.Send(uri, 10000);
400 if (response.IsFault)
401 {
402 m_log.ErrorFormat("[HGrid]: remote call returned an error: {0}", response.FaultString);
403 }
404 else
405 {
406 hash = (Hashtable)response.Value;
407 try
408 {
409 landData = new LandData();
410 landData.AABBMax = Vector3.Parse((string)hash["AABBMax"]);
411 landData.AABBMin = Vector3.Parse((string)hash["AABBMin"]);
412 landData.Area = Convert.ToInt32(hash["Area"]);
413 landData.AuctionID = Convert.ToUInt32(hash["AuctionID"]);
414 landData.Description = (string)hash["Description"];
415 landData.Flags = Convert.ToUInt32(hash["Flags"]);
416 landData.GlobalID = new UUID((string)hash["GlobalID"]);
417 landData.Name = (string)hash["Name"];
418 landData.OwnerID = new UUID((string)hash["OwnerID"]);
419 landData.SalePrice = Convert.ToInt32(hash["SalePrice"]);
420 landData.SnapshotID = new UUID((string)hash["SnapshotID"]);
421 landData.UserLocation = Vector3.Parse((string)hash["UserLocation"]);
422 m_log.DebugFormat("[HGrid]: Got land data for parcel {0}", landData.Name);
423 }
424 catch (Exception e)
425 {
426 m_log.Error("[HGrid]: Got exception while parsing land-data:", e);
427 }
428 }
429 }
430 else m_log.WarnFormat("[HGrid]: Couldn't find region with handle {0}", regionHandle);
431 }
432 catch (Exception e)
433 {
434 m_log.ErrorFormat("[HGrid]: Couldn't contact region {0}: {1}", regionHandle, e);
435 }
436
437 return landData;
438 }
439
440 // Grid Request Processing
441 public virtual List<RegionInfo> RequestNamedRegions (string name, int maxNumber)
442 {
443 List<RegionInfo> infos = new List<RegionInfo>();
444 foreach (RegionInfo info in m_hyperlinkRegions)
445 {
446 if (info.RegionName.ToLower().Contains(name))
447 {
448 infos.Add(info);
449 }
450 }
451 return infos;
452 }
453
454
455 private UUID LinkRegion(RegionInfo info)
456 {
457 UUID uuid = UUID.Zero;
458
459 Hashtable hash = new Hashtable();
460 hash["region_name"] = info.RegionName;
461
462 IList paramList = new ArrayList();
463 paramList.Add(hash);
464
465 XmlRpcRequest request = new XmlRpcRequest("link_region", paramList);
466 string uri = "http://" + info.ExternalEndPoint.Address + ":" + info.HttpPort + "/";
467 m_log.Debug("[HGrid]: Linking to " + uri);
468 XmlRpcResponse response = request.Send(uri, 10000);
469 if (response.IsFault)
470 {
471 m_log.ErrorFormat("[HGrid]: remote call returned an error: {0}", response.FaultString);
472 }
473 else
474 {
475 hash = (Hashtable)response.Value;
476 //foreach (Object o in hash)
477 // m_log.Debug(">> " + ((DictionaryEntry)o).Key + ":" + ((DictionaryEntry)o).Value);
478 try
479 {
480 UUID.TryParse((string)hash["uuid"], out uuid);
481 info.RegionID = uuid;
482 if ((string)hash["handle"] != null)
483 {
484 info.regionSecret = (string)hash["handle"];
485 //m_log.Debug(">> HERE: " + info.regionSecret);
486 }
487 if (hash["region_image"] != null)
488 {
489 UUID img = UUID.Zero;
490 UUID.TryParse((string)hash["region_image"], out img);
491 info.RegionSettings.TerrainImageID = img;
492 }
493 if (hash["region_name"] != null)
494 {
495 info.RegionName = (string)hash["region_name"];
496 //m_log.Debug(">> " + info.RegionName);
497 }
498 if (hash["internal_port"] != null)
499 {
500 int port = Convert.ToInt32((string)hash["internal_port"]);
501 info.InternalEndPoint = new IPEndPoint(IPAddress.Parse("0.0.0.0"), port);
502 //m_log.Debug(">> " + info.InternalEndPoint.ToString());
503 }
504 if (hash["remoting_port"] != null)
505 {
506 info.RemotingPort = Convert.ToUInt32(hash["remoting_port"]);
507 //m_log.Debug(">> " + info.RemotingPort);
508 }
509
510 }
511 catch (Exception e)
512 {
513 m_log.Error("[HGrid]: Got exception while parsing hyperlink response " + e.StackTrace);
514 }
515 }
516 return uuid;
517 }
518
519 /// <summary>
520 /// Someone wants to link to us
521 /// </summary>
522 /// <param name="request"></param>
523 /// <returns></returns>
524 public XmlRpcResponse LinkRegionRequest(XmlRpcRequest request, IPEndPoint remoteClient)
525 {
526 Hashtable requestData = (Hashtable)request.Params[0];
527 //string host = (string)requestData["host"];
528 //string portstr = (string)requestData["port"];
529 string name = (string)requestData["region_name"];
530
531 m_log.DebugFormat("[HGrid]: Hyperlink request");
532
533
534 RegionInfo regInfo = null;
535 foreach (RegionInfo r in m_regionsOnInstance)
536 {
537 if ((r.RegionName != null) && (name != null) && (r.RegionName.ToLower() == name.ToLower()))
538 {
539 regInfo = r;
540 break;
541 }
542 }
543
544 if (regInfo == null)
545 regInfo = m_regionsOnInstance[0]; // Send out the first region
546
547 Hashtable hash = new Hashtable();
548 hash["uuid"] = regInfo.RegionID.ToString();
549 hash["handle"] = regInfo.RegionHandle.ToString();
550 //m_log.Debug(">> Here " + regInfo.RegionHandle);
551 hash["region_image"] = regInfo.RegionSettings.TerrainImageID.ToString();
552 hash["region_name"] = regInfo.RegionName;
553 hash["internal_port"] = regInfo.InternalEndPoint.Port.ToString();
554 hash["remoting_port"] = ConfigSettings.DefaultRegionRemotingPort.ToString();
555 //m_log.Debug(">> Here: " + regInfo.InternalEndPoint.Port);
556
557
558 XmlRpcResponse response = new XmlRpcResponse();
559 response.Value = hash;
560 return response;
561 }
562
563 public bool InformRegionOfUser(RegionInfo regInfo, AgentCircuitData agentData)
564 {
565 //ulong regionHandle = regInfo.RegionHandle;
566 try
567 {
568 //regionHandle = Convert.ToUInt64(regInfo.regionSecret);
569 m_log.Info("[HGrid]: InformRegionOfUser: Remote hyperlinked region " + regInfo.regionSecret);
570 }
571 catch
572 {
573 m_log.Info("[HGrid]: InformRegionOfUser: Local grid region " + regInfo.regionSecret);
574 }
575
576 string capsPath = agentData.CapsPath;
577 Hashtable loginParams = new Hashtable();
578 loginParams["session_id"] = agentData.SessionID.ToString();
579 loginParams["secure_session_id"] = agentData.SecureSessionID.ToString();
580
581 loginParams["firstname"] = agentData.firstname;
582 loginParams["lastname"] = agentData.lastname;
583
584 loginParams["agent_id"] = agentData.AgentID.ToString();
585 loginParams["circuit_code"] = agentData.circuitcode.ToString();
586 loginParams["startpos_x"] = agentData.startpos.X.ToString();
587 loginParams["startpos_y"] = agentData.startpos.Y.ToString();
588 loginParams["startpos_z"] = agentData.startpos.Z.ToString();
589 loginParams["caps_path"] = capsPath;
590
591 CachedUserInfo u = m_userProfileCache.GetUserDetails(agentData.AgentID);
592 if (u != null && u.UserProfile != null)
593 {
594 loginParams["region_uuid"] = u.UserProfile.HomeRegionID.ToString(); // This seems to be always Zero
595 //m_log.Debug(" --------- Home Region UUID -------");
596 //m_log.Debug(" >> " + loginParams["region_uuid"] + " <<");
597 //m_log.Debug(" --------- ---------------- -------");
598
599 string serverURI = "";
600 if (u.UserProfile is ForeignUserProfileData)
601 serverURI = HGNetworkServersInfo.ServerURI(((ForeignUserProfileData)u.UserProfile).UserServerURI);
602 loginParams["userserver_id"] = (serverURI == "") || (serverURI == null) ? HGNetworkServersInfo.Singleton.LocalUserServerURI : serverURI;
603
604 serverURI = HGNetworkServersInfo.ServerURI(u.UserProfile.UserAssetURI);
605 loginParams["assetserver_id"] = (serverURI == "") || (serverURI == null) ? HGNetworkServersInfo.Singleton.LocalAssetServerURI : serverURI;
606
607 serverURI = HGNetworkServersInfo.ServerURI(u.UserProfile.UserInventoryURI);
608 loginParams["inventoryserver_id"] = (serverURI == "") || (serverURI == null) ? HGNetworkServersInfo.Singleton.LocalInventoryServerURI : serverURI;
609
610 loginParams["root_folder_id"] = u.UserProfile.RootInventoryFolderID;
611
612 RegionInfo rinfo = RequestNeighbourInfo(u.UserProfile.HomeRegion);
613 if (rinfo != null)
614 {
615 loginParams["internal_port"] = rinfo.InternalEndPoint.Port.ToString();
616 if (!IsLocalUser(u))
617 {
618 loginParams["regionhandle"] = rinfo.regionSecret; // user.CurrentAgent.Handle.ToString();
619 //m_log.Debug("XXX--- informregionofuser (foreign user) here handle: " + rinfo.regionSecret);
620
621 loginParams["home_address"] = ((ForeignUserProfileData)(u.UserProfile)).UserHomeAddress;
622 loginParams["home_port"] = ((ForeignUserProfileData)(u.UserProfile)).UserHomePort;
623 loginParams["home_remoting"] = ((ForeignUserProfileData)(u.UserProfile)).UserHomeRemotingPort;
624 }
625 else
626 {
627 //m_log.Debug("XXX--- informregionofuser (local user) here handle: " + rinfo.regionSecret);
628
629 //// local user about to jump out, let's process the name
630 // On second thoughts, let's not do this for the *user*; let's only do it for the *agent*
631 //loginParams["firstname"] = agentData.firstname + "." + agentData.lastname;
632 //loginParams["lastname"] = serversInfo.UserURL;
633
634 // local user, first time out. let's ask the grid about this user's home region
635 loginParams["regionhandle"] = u.UserProfile.HomeRegion.ToString(); // user.CurrentAgent.Handle.ToString();
636
637 loginParams["home_address"] = rinfo.ExternalHostName;
638 m_log.Debug(" --------- Home Address -------");
639 m_log.Debug(" >> " + loginParams["home_address"] + " <<");
640 m_log.Debug(" --------- ------------ -------");
641 loginParams["home_port"] = rinfo.HttpPort.ToString();
642 loginParams["home_remoting"] = ConfigSettings.DefaultRegionRemotingPort.ToString(); ;
643 }
644 }
645 else
646 {
647 m_log.Warn("[HGrid]: User's home region info not found: " + u.UserProfile.HomeRegionX + ", " + u.UserProfile.HomeRegionY);
648 }
649 }
650
651 ArrayList SendParams = new ArrayList();
652 SendParams.Add(loginParams);
653
654 // Send
655 string uri = "http://" + regInfo.ExternalHostName + ":" + regInfo.HttpPort + "/";
656 //m_log.Debug("XXX uri: " + uri);
657 XmlRpcRequest request = new XmlRpcRequest("expect_hg_user", SendParams);
658 XmlRpcResponse reply;
659 try
660 {
661 reply = request.Send(uri, 6000);
662 }
663 catch (Exception e)
664 {
665 m_log.Warn("[HGrid]: Failed to notify region about user. Reason: " + e.Message);
666 return false;
667 }
668
669 if (!reply.IsFault)
670 {
671 bool responseSuccess = true;
672 if (reply.Value != null)
673 {
674 Hashtable resp = (Hashtable)reply.Value;
675 if (resp.ContainsKey("success"))
676 {
677 if ((string)resp["success"] == "FALSE")
678 {
679 responseSuccess = false;
680 }
681 }
682 }
683 if (responseSuccess)
684 {
685 m_log.Info("[HGrid]: Successfully informed remote region about user " + agentData.AgentID);
686 return true;
687 }
688 else
689 {
690 m_log.ErrorFormat("[HGrid]: Region responded that it is not available to receive clients");
691 return false;
692 }
693 }
694 else
695 {
696 m_log.ErrorFormat("[HGrid]: XmlRpc request to region failed with message {0}, code {1} ", reply.FaultString, reply.FaultCode);
697 return false;
698 }
699 }
700
701
702 /// <summary>
703 /// Received from other HGrid nodes when a user wants to teleport here. This call allows
704 /// the region to prepare for direct communication from the client. Sends back an empty
705 /// xmlrpc response on completion.
706 /// This is somewhat similar to OGS1's ExpectUser, but with the additional task of
707 /// registering the user in the local user cache.
708 /// </summary>
709 /// <param name="request"></param>
710 /// <returns></returns>
711 public XmlRpcResponse ExpectHGUser(XmlRpcRequest request, IPEndPoint remoteClient)
712 {
713 Hashtable requestData = (Hashtable)request.Params[0];
714 ForeignUserProfileData userData = new ForeignUserProfileData();
715
716 userData.FirstName = (string)requestData["firstname"];
717 userData.SurName = (string)requestData["lastname"];
718 userData.ID = new UUID((string)requestData["agent_id"]);
719 userData.HomeLocation = new Vector3((float)Convert.ToDecimal((string)requestData["startpos_x"]),
720 (float)Convert.ToDecimal((string)requestData["startpos_y"]),
721 (float)Convert.ToDecimal((string)requestData["startpos_z"]));
722
723 userData.UserServerURI = (string)requestData["userserver_id"];
724 userData.UserAssetURI = (string)requestData["assetserver_id"];
725 userData.UserInventoryURI = (string)requestData["inventoryserver_id"];
726
727 UUID rootID = UUID.Zero;
728 UUID.TryParse((string)requestData["root_folder_id"], out rootID);
729 userData.RootInventoryFolderID = rootID;
730
731 UUID uuid = UUID.Zero;
732 UUID.TryParse((string)requestData["region_uuid"], out uuid);
733 userData.HomeRegionID = uuid; // not quite comfortable about this...
734 ulong userRegionHandle = Convert.ToUInt64((string)requestData["regionhandle"]);
735 //userData.HomeRegion = userRegionHandle;
736 userData.UserHomeAddress = (string)requestData["home_address"];
737 userData.UserHomePort = (string)requestData["home_port"];
738 int userhomeinternalport = Convert.ToInt32((string)requestData["internal_port"]);
739 userData.UserHomeRemotingPort = (string)requestData["home_remoting"];
740
741
742 m_log.DebugFormat("[HGrid]: Prepare for connection from {0} {1} (@{2}) UUID={3}",
743 userData.FirstName, userData.SurName, userData.UserServerURI, userData.ID);
744 m_log.Debug("[HGrid]: home_address: " + userData.UserHomeAddress +
745 "; home_port: " + userData.UserHomePort + "; remoting: " + userData.UserHomeRemotingPort);
746
747 XmlRpcResponse resp = new XmlRpcResponse();
748
749 // Let's check if someone is trying to get in with a stolen local identity.
750 // The need for this test is a consequence of not having truly global names :-/
751 CachedUserInfo uinfo = m_userProfileCache.GetUserDetails(userData.ID);
752 if ((uinfo != null) && !(uinfo.UserProfile is ForeignUserProfileData))
753 {
754 m_log.WarnFormat("[HGrid]: Foreign user trying to get in with local identity. Access denied.");
755 Hashtable respdata = new Hashtable();
756 respdata["success"] = "FALSE";
757 respdata["reason"] = "Foreign user has the same ID as a local user.";
758 resp.Value = respdata;
759 return resp;
760 }
761
762 if (!RegionLoginsEnabled)
763 {
764 m_log.InfoFormat(
765 "[HGrid]: Denying access for user {0} {1} because region login is currently disabled",
766 userData.FirstName, userData.SurName);
767
768 Hashtable respdata = new Hashtable();
769 respdata["success"] = "FALSE";
770 respdata["reason"] = "region login currently disabled";
771 resp.Value = respdata;
772 }
773 else
774 {
775 // Finally, everything looks ok
776 //m_log.Debug("XXX---- EVERYTHING OK ---XXX");
777
778 // 1 - Preload the user data
779 m_userProfileCache.PreloadUserCache(userData);
780
781 if (m_knownRegions.ContainsKey(userData.ID))
782 {
783 // This was left here when the user departed
784 m_knownRegions.Remove(userData.ID);
785 }
786
787 // 2 - Load the region info into list of known regions
788 RegionInfo rinfo = new RegionInfo();
789 rinfo.RegionID = userData.HomeRegionID;
790 rinfo.ExternalHostName = userData.UserHomeAddress;
791 rinfo.HttpPort = Convert.ToUInt32(userData.UserHomePort);
792 rinfo.RemotingPort = Convert.ToUInt32(userData.UserHomeRemotingPort);
793 rinfo.RegionID = userData.HomeRegionID;
794 // X=0 on the map
795 rinfo.RegionLocX = 0;
796 rinfo.RegionLocY = (uint)(random.Next(0, Int32.MaxValue)); //(uint)m_knownRegions.Count;
797 rinfo.regionSecret = userRegionHandle.ToString();
798 //m_log.Debug("XXX--- Here: handle = " + rinfo.regionSecret);
799 try
800 {
801 rinfo.InternalEndPoint = new IPEndPoint(IPAddress.Parse("0.0.0.0"), (int)userhomeinternalport);
802 }
803 catch (Exception e)
804 {
805 m_log.Warn("[HGrid]: Exception while constructing internal endpoint: " + e);
806 }
807 rinfo.RemotingAddress = rinfo.ExternalEndPoint.Address.ToString(); //userData.UserHomeAddress;
808
809 if (!IsComingHome(userData))
810 {
811 // Change the user's home region here!!!
812 userData.HomeRegion = rinfo.RegionHandle;
813 }
814
815 if (!m_knownRegions.ContainsKey(userData.ID))
816 m_knownRegions.Add(userData.ID, rinfo);
817
818 // 3 - Send the reply
819 Hashtable respdata = new Hashtable();
820 respdata["success"] = "TRUE";
821 resp.Value = respdata;
822
823 DumpUserData(userData);
824 DumpRegionData(rinfo);
825
826 }
827
828 return resp;
829 }
830
831 public bool SendUserInformation(RegionInfo regInfo, AgentCircuitData agentData)
832 {
833 CachedUserInfo uinfo = m_userProfileCache.GetUserDetails(agentData.AgentID);
834
835 if ((IsLocalUser(uinfo) && IsHyperlinkRegion(regInfo.RegionHandle)) ||
836 (!IsLocalUser(uinfo) && !IsGoingHome(uinfo, regInfo)))
837 {
838 m_log.Info("[HGrid]: Local user is going to foreign region or foreign user is going elsewhere");
839 if (!InformRegionOfUser(regInfo, agentData))
840 {
841 m_log.Warn("[HGrid]: Could not inform remote region of transferring user.");
842 return false;
843 }
844 }
845 //if ((uinfo == null) || !IsGoingHome(uinfo, regInfo))
846 //{
847 // m_log.Info("[HGrid]: User seems to be going to foreign region.");
848 // if (!InformRegionOfUser(regInfo, agentData))
849 // {
850 // m_log.Warn("[HGrid]: Could not inform remote region of transferring user.");
851 // return false;
852 // }
853 //}
854 //else
855 // m_log.Info("[HGrid]: User seems to be going home " + uinfo.UserProfile.FirstName + " " + uinfo.UserProfile.SurName);
856
857 // May need to change agent's name
858 if (IsLocalUser(uinfo) && IsHyperlinkRegion(regInfo.RegionHandle))
859 {
860 agentData.firstname = agentData.firstname + "." + agentData.lastname;
861 agentData.lastname = "@" + serversInfo.UserURL.Replace("http://", ""); ; //HGNetworkServersInfo.Singleton.LocalUserServerURI;
862 }
863
864 return true;
865 }
866
867
868 #region Methods triggered by calls from external instances
869
870 /// <summary>
871 ///
872 /// </summary>
873 /// <param name="regionHandle"></param>
874 /// <param name="agentData"></param>
875 /// <returns></returns>
876 public void AdjustUserInformation(AgentCircuitData agentData)
877 {
878 CachedUserInfo uinfo = m_userProfileCache.GetUserDetails(agentData.AgentID);
879 if ((uinfo != null) && (uinfo.UserProfile != null) &&
880 (IsLocalUser(uinfo) || !(uinfo.UserProfile is ForeignUserProfileData)))
881 {
882 //m_log.Debug("---------------> Local User!");
883 string[] parts = agentData.firstname.Split(new char[] { '.' });
884 if (parts.Length == 2)
885 {
886 agentData.firstname = parts[0];
887 agentData.lastname = parts[1];
888 }
889 }
890 //else
891 // m_log.Debug("---------------> Foreign User!");
892 }
893 #endregion
894
895
896 #region IHyperGrid interface
897
898 public virtual bool IsHyperlinkRegion(ulong ihandle)
899 {
900 if (GetHyperlinkRegion(ihandle) == null)
901 return false;
902 else
903 return true;
904 }
905
906 public virtual RegionInfo GetHyperlinkRegion(ulong ihandle)
907 {
908 foreach (RegionInfo info in m_hyperlinkRegions)
909 {
910 if (info.RegionHandle == ihandle)
911 return info;
912 }
913
914 foreach (RegionInfo info in m_knownRegions.Values)
915 {
916 if (info.RegionHandle == ihandle)
917 return info;
918 }
919
920 return null;
921 }
922
923 public virtual ulong FindRegionHandle(ulong ihandle)
924 {
925 long ohandle = -1;
926 List<RegionInfo> rlist = new List<RegionInfo>(m_hyperlinkRegions);
927 rlist.AddRange(m_knownRegions.Values);
928 foreach (RegionInfo info in rlist)
929 {
930 if (info.RegionHandle == ihandle)
931 {
932 try
933 {
934 ohandle = Convert.ToInt64(info.regionSecret);
935 m_log.Info("[HGrid] remote region " + ohandle);
936 }
937 catch
938 {
939 m_log.Error("[HGrid] Could not convert secret for " + ihandle + " (" + info.regionSecret + ")");
940 }
941 break;
942 }
943 }
944 return ohandle < 0 ? ihandle : (ulong)ohandle;
945 }
946 #endregion
947
948 #region Misc
949
950 protected bool IsComingHome(ForeignUserProfileData userData)
951 {
952 return (userData.UserServerURI == HGNetworkServersInfo.Singleton.LocalUserServerURI);
953 }
954
955 protected bool IsGoingHome(CachedUserInfo uinfo, RegionInfo rinfo)
956 {
957 if (uinfo.UserProfile == null)
958 return false;
959
960 string userUserServerURI = String.Empty;
961 if (uinfo.UserProfile is ForeignUserProfileData)
962 {
963 userUserServerURI = HGNetworkServersInfo.ServerURI(((ForeignUserProfileData)uinfo.UserProfile).UserServerURI);
964 }
965
966 return ((uinfo.UserProfile.HomeRegionID == rinfo.RegionID) &&
967 (userUserServerURI != HGNetworkServersInfo.Singleton.LocalUserServerURI));
968 }
969
970 protected bool IsLocalUser(CachedUserInfo uinfo)
971 {
972 if (uinfo == null)
973 return true;
974
975 if (uinfo.UserProfile is ForeignUserProfileData)
976 return HGNetworkServersInfo.Singleton.IsLocalUser(((ForeignUserProfileData)uinfo.UserProfile).UserServerURI);
977 else
978 return true;
979
980 }
981
982 protected bool IsLocalRegion(ulong handle)
983 {
984 foreach (RegionInfo reg in m_regionsOnInstance)
985 if (reg.RegionHandle == handle)
986 return true;
987 return false;
988 }
989
990 private void DumpUserData(ForeignUserProfileData userData)
991 {
992 m_log.Info(" ------------ User Data Dump ----------");
993 m_log.Info(" >> Name: " + userData.FirstName + " " + userData.SurName);
994 m_log.Info(" >> HomeID: " + userData.HomeRegionID);
995 m_log.Info(" >> HomeHandle: " + userData.HomeRegion);
996 m_log.Info(" >> HomeX: " + userData.HomeRegionX);
997 m_log.Info(" >> HomeY: " + userData.HomeRegionY);
998 m_log.Info(" >> UserServer: " + userData.UserServerURI);
999 m_log.Info(" >> InvServer: " + userData.UserInventoryURI);
1000 m_log.Info(" >> AssetServer: " + userData.UserAssetURI);
1001 m_log.Info(" ------------ -------------- ----------");
1002 }
1003
1004 private void DumpRegionData(RegionInfo rinfo)
1005 {
1006 m_log.Info(" ------------ Region Data Dump ----------");
1007 m_log.Info(" >> handle: " + rinfo.RegionHandle);
1008 m_log.Info(" >> coords: " + rinfo.RegionLocX + ", " + rinfo.RegionLocY);
1009 m_log.Info(" >> secret: " + rinfo.regionSecret);
1010 m_log.Info(" >> remoting address: " + rinfo.RemotingAddress);
1011 m_log.Info(" >> remoting port: " + rinfo.RemotingPort);
1012 m_log.Info(" >> external host name: " + rinfo.ExternalHostName);
1013 m_log.Info(" >> http port: " + rinfo.HttpPort);
1014 m_log.Info(" >> external EP address: " + rinfo.ExternalEndPoint.Address);
1015 m_log.Info(" >> external EP port: " + rinfo.ExternalEndPoint.Port);
1016 m_log.Info(" ------------ -------------- ----------");
1017 }
1018
1019
1020 #endregion
1021
1022
1023 }
1024}
diff --git a/OpenSim/Region/Communications/Hypergrid/HGGridServicesGridMode.cs b/OpenSim/Region/Communications/Hypergrid/HGGridServicesGridMode.cs
deleted file mode 100644
index 5ce1e79..0000000
--- a/OpenSim/Region/Communications/Hypergrid/HGGridServicesGridMode.cs
+++ /dev/null
@@ -1,159 +0,0 @@
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 OpenSim.Framework;
34using OpenSim.Framework.Communications.Cache;
35using OpenSim.Framework.Servers.HttpServer;
36using OpenSim.Region.Communications.OGS1;
37using OpenSim.Region.Framework.Scenes;
38
39namespace OpenSim.Region.Communications.Hypergrid
40{
41 public class HGGridServicesGridMode : HGGridServices
42 {
43 //private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
44
45 /// <summary>
46 /// Encapsulate remote backend services for manipulation of grid regions
47 /// </summary>
48 private OGS1GridServices m_remoteBackend = null;
49
50 public OGS1GridServices RemoteBackend
51 {
52 get { return m_remoteBackend; }
53 }
54
55
56 public override string gdebugRegionName
57 {
58 get { return m_remoteBackend.gdebugRegionName; }
59 set { m_remoteBackend.gdebugRegionName = value; }
60 }
61
62 public override bool RegionLoginsEnabled
63 {
64 get { return m_remoteBackend.RegionLoginsEnabled; }
65 set { m_remoteBackend.RegionLoginsEnabled = value; }
66 }
67
68 public HGGridServicesGridMode(NetworkServersInfo servers_info,
69 SceneManager sman, UserProfileCacheService userv)
70 : base(servers_info, sman)
71 {
72 m_remoteBackend = new OGS1GridServices(servers_info);
73 m_userProfileCache = userv;
74 }
75
76 #region IGridServices interface
77
78 public override RegionCommsListener RegisterRegion(RegionInfo regionInfo)
79 {
80 if (!regionInfo.RegionID.Equals(UUID.Zero))
81 {
82 m_regionsOnInstance.Add(regionInfo);
83 return m_remoteBackend.RegisterRegion(regionInfo);
84 }
85 else
86 return base.RegisterRegion(regionInfo);
87 }
88
89 public override bool DeregisterRegion(RegionInfo regionInfo)
90 {
91 bool success = base.DeregisterRegion(regionInfo);
92 if (!success)
93 success = m_remoteBackend.DeregisterRegion(regionInfo);
94 return success;
95 }
96
97 public override List<SimpleRegionInfo> RequestNeighbours(uint x, uint y)
98 {
99 List<SimpleRegionInfo> neighbours = m_remoteBackend.RequestNeighbours(x, y);
100 //List<SimpleRegionInfo> remotes = base.RequestNeighbours(x, y);
101 //neighbours.AddRange(remotes);
102
103 return neighbours;
104 }
105
106 public override RegionInfo RequestNeighbourInfo(UUID Region_UUID)
107 {
108 RegionInfo info = m_remoteBackend.RequestNeighbourInfo(Region_UUID);
109 if (info == null)
110 info = base.RequestNeighbourInfo(Region_UUID);
111 return info;
112 }
113
114 public override RegionInfo RequestNeighbourInfo(ulong regionHandle)
115 {
116 RegionInfo info = base.RequestNeighbourInfo(regionHandle);
117 if (info == null)
118 info = m_remoteBackend.RequestNeighbourInfo(regionHandle);
119 return info;
120 }
121
122 public override RegionInfo RequestClosestRegion(string regionName)
123 {
124 RegionInfo info = m_remoteBackend.RequestClosestRegion(regionName);
125 if (info == null)
126 info = base.RequestClosestRegion(regionName);
127 return info;
128 }
129
130 public override List<MapBlockData> RequestNeighbourMapBlocks(int minX, int minY, int maxX, int maxY)
131 {
132 List<MapBlockData> neighbours = m_remoteBackend.RequestNeighbourMapBlocks(minX, minY, maxX, maxY);
133 List<MapBlockData> remotes = base.RequestNeighbourMapBlocks(minX, minY, maxX, maxY);
134 neighbours.AddRange(remotes);
135
136 return neighbours;
137 }
138
139 public override LandData RequestLandData(ulong regionHandle, uint x, uint y)
140 {
141 LandData land = m_remoteBackend.RequestLandData(regionHandle, x, y);
142 if (land == null)
143 land = base.RequestLandData(regionHandle, x, y);
144 return land;
145 }
146
147 public override List<RegionInfo> RequestNamedRegions(string name, int maxNumber)
148 {
149 List<RegionInfo> infos = m_remoteBackend.RequestNamedRegions(name, maxNumber);
150 List<RegionInfo> remotes = base.RequestNamedRegions(name, maxNumber);
151 infos.AddRange(remotes);
152 return infos;
153 }
154
155 #endregion
156
157
158 }
159}
diff --git a/OpenSim/Region/Communications/Hypergrid/HGGridServicesStandalone.cs b/OpenSim/Region/Communications/Hypergrid/HGGridServicesStandalone.cs
deleted file mode 100644
index 94cfc49..0000000
--- a/OpenSim/Region/Communications/Hypergrid/HGGridServicesStandalone.cs
+++ /dev/null
@@ -1,259 +0,0 @@
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.Net;
32using System.Net.Sockets;
33using System.Reflection;
34using System.Runtime.Remoting;
35using System.Runtime.Remoting.Channels;
36using System.Runtime.Remoting.Channels.Tcp;
37using System.Security.Authentication;
38using log4net;
39using Nwc.XmlRpc;
40using OpenMetaverse;
41using OpenSim.Framework;
42using OpenSim.Framework.Servers;
43using OpenSim.Framework.Servers.HttpServer;
44using OpenSim.Region.Communications.Local;
45using OpenSim.Region.Communications.OGS1;
46using OpenSim.Region.Framework.Scenes;
47
48namespace OpenSim.Region.Communications.Hypergrid
49{
50 public class HGGridServicesStandalone : HGGridServices
51 {
52 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
53
54 /// <summary>
55 /// Encapsulate local backend services for manipulation of local regions
56 /// </summary>
57 protected LocalBackEndServices m_localBackend = new LocalBackEndServices();
58
59 //private Dictionary<ulong, int> m_deadRegionCache = new Dictionary<ulong, int>();
60
61 public LocalBackEndServices LocalBackend
62 {
63 get { return m_localBackend; }
64 }
65
66 public override string gdebugRegionName
67 {
68 get { return m_localBackend.gdebugRegionName; }
69 set { m_localBackend.gdebugRegionName = value; }
70 }
71
72 public override bool RegionLoginsEnabled
73 {
74 get { return m_localBackend.RegionLoginsEnabled; }
75 set { m_localBackend.RegionLoginsEnabled = value; }
76 }
77
78
79 public HGGridServicesStandalone(NetworkServersInfo servers_info, BaseHttpServer httpServe, SceneManager sman)
80 : base(servers_info, sman)
81 {
82 //Respond to Grid Services requests
83 MainServer.Instance.AddXmlRPCHandler("logoff_user", LogOffUser);
84 MainServer.Instance.AddXmlRPCHandler("check", PingCheckReply);
85 MainServer.Instance.AddXmlRPCHandler("land_data", LandData);
86
87 }
88
89 #region IGridServices interface
90
91 public override RegionCommsListener RegisterRegion(RegionInfo regionInfo)
92 {
93 if (!regionInfo.RegionID.Equals(UUID.Zero))
94 {
95 m_regionsOnInstance.Add(regionInfo);
96 return m_localBackend.RegisterRegion(regionInfo);
97 }
98 else
99 return base.RegisterRegion(regionInfo);
100
101 }
102
103 public override bool DeregisterRegion(RegionInfo regionInfo)
104 {
105 bool success = m_localBackend.DeregisterRegion(regionInfo);
106 if (!success)
107 success = base.DeregisterRegion(regionInfo);
108 return success;
109 }
110
111 public override List<SimpleRegionInfo> RequestNeighbours(uint x, uint y)
112 {
113 List<SimpleRegionInfo> neighbours = m_localBackend.RequestNeighbours(x, y);
114 //List<SimpleRegionInfo> remotes = base.RequestNeighbours(x, y);
115 //neighbours.AddRange(remotes);
116
117 return neighbours;
118 }
119
120 public override RegionInfo RequestNeighbourInfo(UUID Region_UUID)
121 {
122 RegionInfo info = m_localBackend.RequestNeighbourInfo(Region_UUID);
123 if (info == null)
124 info = base.RequestNeighbourInfo(Region_UUID);
125 return info;
126 }
127
128 public override RegionInfo RequestNeighbourInfo(ulong regionHandle)
129 {
130 RegionInfo info = m_localBackend.RequestNeighbourInfo(regionHandle);
131 //m_log.Info("[HGrid] Request neighbor info, local backend returned " + info);
132 if (info == null)
133 info = base.RequestNeighbourInfo(regionHandle);
134 return info;
135 }
136
137 public override RegionInfo RequestClosestRegion(string regionName)
138 {
139 RegionInfo info = m_localBackend.RequestClosestRegion(regionName);
140 if (info == null)
141 info = base.RequestClosestRegion(regionName);
142 return info;
143 }
144
145 public override List<MapBlockData> RequestNeighbourMapBlocks(int minX, int minY, int maxX, int maxY)
146 {
147 //m_log.Info("[HGrid] Request map blocks " + minX + "-" + minY + "-" + maxX + "-" + maxY);
148 List<MapBlockData> neighbours = m_localBackend.RequestNeighbourMapBlocks(minX, minY, maxX, maxY);
149 List<MapBlockData> remotes = base.RequestNeighbourMapBlocks(minX, minY, maxX, maxY);
150 neighbours.AddRange(remotes);
151
152 return neighbours;
153 }
154
155 public override LandData RequestLandData(ulong regionHandle, uint x, uint y)
156 {
157 LandData land = m_localBackend.RequestLandData(regionHandle, x, y);
158 if (land == null)
159 land = base.RequestLandData(regionHandle, x, y);
160 return land;
161 }
162
163 public override List<RegionInfo> RequestNamedRegions(string name, int maxNumber)
164 {
165 List<RegionInfo> infos = m_localBackend.RequestNamedRegions(name, maxNumber);
166 List<RegionInfo> remotes = base.RequestNamedRegions(name, maxNumber);
167 infos.AddRange(remotes);
168 return infos;
169 }
170
171 #endregion
172
173 #region XML Request Handlers
174
175 /// <summary>
176 /// A ping / version check
177 /// </summary>
178 /// <param name="request"></param>
179 /// <returns></returns>
180 public virtual XmlRpcResponse PingCheckReply(XmlRpcRequest request, IPEndPoint remoteClient)
181 {
182 XmlRpcResponse response = new XmlRpcResponse();
183
184 Hashtable respData = new Hashtable();
185 respData["online"] = "true";
186
187 m_localBackend.PingCheckReply(respData);
188
189 response.Value = respData;
190
191 return response;
192 }
193
194
195 // Grid Request Processing
196 /// <summary>
197 /// Ooops, our Agent must be dead if we're getting this request!
198 /// </summary>
199 /// <param name="request"></param>
200 /// <returns></returns>
201 public XmlRpcResponse LogOffUser(XmlRpcRequest request, IPEndPoint remoteClient)
202 {
203 m_log.Debug("[HGrid]: LogOff User Called");
204
205 Hashtable requestData = (Hashtable)request.Params[0];
206 string message = (string)requestData["message"];
207 UUID agentID = UUID.Zero;
208 UUID RegionSecret = UUID.Zero;
209 UUID.TryParse((string)requestData["agent_id"], out agentID);
210 UUID.TryParse((string)requestData["region_secret"], out RegionSecret);
211
212 ulong regionHandle = Convert.ToUInt64((string)requestData["regionhandle"]);
213
214 m_localBackend.TriggerLogOffUser(regionHandle, agentID, RegionSecret, message);
215
216 return new XmlRpcResponse();
217 }
218
219 /// <summary>
220 /// Someone asked us about parcel-information
221 /// </summary>
222 /// <param name="request"></param>
223 /// <returns></returns>
224 public XmlRpcResponse LandData(XmlRpcRequest request, IPEndPoint remoteClient)
225 {
226 Hashtable requestData = (Hashtable)request.Params[0];
227 ulong regionHandle = Convert.ToUInt64(requestData["region_handle"]);
228 uint x = Convert.ToUInt32(requestData["x"]);
229 uint y = Convert.ToUInt32(requestData["y"]);
230 m_log.DebugFormat("[HGrid]: Got XML reqeuest for land data at {0}, {1} in region {2}", x, y, regionHandle);
231
232 LandData landData = m_localBackend.RequestLandData(regionHandle, x, y);
233 Hashtable hash = new Hashtable();
234 if (landData != null)
235 {
236 // for now, only push out the data we need for answering a ParcelInfoReqeust
237 hash["AABBMax"] = landData.AABBMax.ToString();
238 hash["AABBMin"] = landData.AABBMin.ToString();
239 hash["Area"] = landData.Area.ToString();
240 hash["AuctionID"] = landData.AuctionID.ToString();
241 hash["Description"] = landData.Description;
242 hash["Flags"] = landData.Flags.ToString();
243 hash["GlobalID"] = landData.GlobalID.ToString();
244 hash["Name"] = landData.Name;
245 hash["OwnerID"] = landData.OwnerID.ToString();
246 hash["SalePrice"] = landData.SalePrice.ToString();
247 hash["SnapshotID"] = landData.SnapshotID.ToString();
248 hash["UserLocation"] = landData.UserLocation.ToString();
249 }
250
251 XmlRpcResponse response = new XmlRpcResponse();
252 response.Value = hash;
253 return response;
254 }
255
256 #endregion
257
258 }
259}
diff --git a/OpenSim/Region/Communications/Local/CommunicationsLocal.cs b/OpenSim/Region/Communications/Local/CommunicationsLocal.cs
index a658416..99bcea3 100644
--- a/OpenSim/Region/Communications/Local/CommunicationsLocal.cs
+++ b/OpenSim/Region/Communications/Local/CommunicationsLocal.cs
@@ -53,8 +53,6 @@ namespace OpenSim.Region.Communications.Local
53 m_avatarService = lus; 53 m_avatarService = lus;
54 m_messageService = lus; 54 m_messageService = lus;
55 55
56 m_gridService = new LocalBackEndServices();
57
58 //LocalLoginService loginService = CreateLoginService(libraryRootFolder, inventoryService, userService, backendService); 56 //LocalLoginService loginService = CreateLoginService(libraryRootFolder, inventoryService, userService, backendService);
59 } 57 }
60 } 58 }
diff --git a/OpenSim/Region/Communications/Local/LocalBackEndServices.cs b/OpenSim/Region/Communications/Local/LocalBackEndServices.cs
deleted file mode 100644
index 0ab9374..0000000
--- a/OpenSim/Region/Communications/Local/LocalBackEndServices.cs
+++ /dev/null
@@ -1,410 +0,0 @@
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 log4net;
33using OpenMetaverse;
34using OpenSim.Framework;
35using OpenSim.Framework.Communications;
36
37namespace OpenSim.Region.Communications.Local
38{
39 public class LocalBackEndServices : IGridServices
40 {
41 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
42
43 protected Dictionary<ulong, RegionInfo> m_regions = new Dictionary<ulong, RegionInfo>();
44
45 protected Dictionary<ulong, RegionCommsListener> m_regionListeners =
46 new Dictionary<ulong, RegionCommsListener>();
47
48 // private Dictionary<ulong, RegionInfo> m_remoteRegionInfoCache = new Dictionary<ulong, RegionInfo>();
49
50 private Dictionary<string, string> m_queuedGridSettings = new Dictionary<string, string>();
51
52 public string _gdebugRegionName = String.Empty;
53
54 public bool RegionLoginsEnabled
55 {
56 get { return m_regionLoginsEnabled; }
57 set { m_regionLoginsEnabled = value; }
58 }
59 private bool m_regionLoginsEnabled;
60
61 public bool CheckRegion(string address, uint port)
62 {
63 return true;
64 }
65
66 public string gdebugRegionName
67 {
68 get { return _gdebugRegionName; }
69 set { _gdebugRegionName = value; }
70 }
71
72 public string _rdebugRegionName = String.Empty;
73
74 public string rdebugRegionName
75 {
76 get { return _rdebugRegionName; }
77 set { _rdebugRegionName = value; }
78 }
79
80 /// <summary>
81 /// Register a region method with the BackEnd Services.
82 /// </summary>
83 /// <param name="regionInfo"></param>
84 /// <returns></returns>
85 public RegionCommsListener RegisterRegion(RegionInfo regionInfo)
86 {
87 //m_log.Debug("CommsManager - Region " + regionInfo.RegionHandle + " , " + regionInfo.RegionLocX + " , "+ regionInfo.RegionLocY +" is registering");
88 if (!m_regions.ContainsKey(regionInfo.RegionHandle))
89 {
90 //m_log.Debug("CommsManager - Adding Region " + regionInfo.RegionHandle);
91 m_regions.Add(regionInfo.RegionHandle, regionInfo);
92
93 RegionCommsListener regionHost = new RegionCommsListener();
94 if (m_regionListeners.ContainsKey(regionInfo.RegionHandle))
95 {
96 m_log.Error("[INTERREGION STANDALONE]: " +
97 "Error:Region registered twice as an Events listener for Interregion Communications but not as a listed region. " +
98 "In Standalone mode this will cause BIG issues. In grid mode, it means a region went down and came back up.");
99 m_regionListeners.Remove(regionInfo.RegionHandle);
100 }
101 m_regionListeners.Add(regionInfo.RegionHandle, regionHost);
102
103 return regionHost;
104 }
105 else
106 {
107 // Already in our list, so the region went dead and restarted.
108 // don't replace the old regioninfo.. this might be a locking issue.. however we need to
109 // remove it and let it add normally below or we get extremely strange and intermittant
110 // connectivity errors.
111 // Don't change this line below to 'm_regions[regionInfo.RegionHandle] = regionInfo' unless you
112 // *REALLY* know what you are doing here.
113 m_regions[regionInfo.RegionHandle] = regionInfo;
114
115 m_log.Warn("[INTERREGION STANDALONE]: Region registered twice. Region went down and came back up.");
116
117 RegionCommsListener regionHost = new RegionCommsListener();
118 if (m_regionListeners.ContainsKey(regionInfo.RegionHandle))
119 {
120 m_regionListeners.Remove(regionInfo.RegionHandle);
121 }
122 m_regionListeners.Add(regionInfo.RegionHandle, regionHost);
123
124 return regionHost;
125 }
126 }
127
128 public bool DeregisterRegion(RegionInfo regionInfo)
129 {
130 if (m_regions.ContainsKey(regionInfo.RegionHandle))
131 {
132 m_regions.Remove(regionInfo.RegionHandle);
133 if (m_regionListeners.ContainsKey(regionInfo.RegionHandle))
134 {
135 m_regionListeners.Remove(regionInfo.RegionHandle);
136 }
137 return true;
138 }
139 return false;
140 }
141
142 /// <summary>
143 /// </summary>
144 /// <param name="regionInfo"></param>
145 /// <returns></returns>
146 public List<SimpleRegionInfo> RequestNeighbours(uint x, uint y)
147 {
148 // m_log.Debug("Finding Neighbours to " + regionInfo.RegionHandle);
149 List<SimpleRegionInfo> neighbours = new List<SimpleRegionInfo>();
150
151 foreach (RegionInfo reg in m_regions.Values)
152 {
153 // m_log.Debug("CommsManager- RequestNeighbours() checking region " + reg.RegionLocX + " , "+ reg.RegionLocY);
154 if (reg.RegionLocX != x || reg.RegionLocY != y)
155 {
156 //m_log.Debug("CommsManager- RequestNeighbours() - found a different region in list, checking location");
157 if ((reg.RegionLocX > (x - 2)) && (reg.RegionLocX < (x + 2)))
158 {
159 if ((reg.RegionLocY > (y - 2)) && (reg.RegionLocY < (y + 2)))
160 {
161 neighbours.Add(reg);
162 }
163 }
164 }
165 }
166 return neighbours;
167 }
168
169 /// <summary>
170 /// Get information about a neighbouring region
171 /// </summary>
172 /// <param name="regionHandle"></param>
173 /// <returns></returns>
174 public RegionInfo RequestNeighbourInfo(ulong regionHandle)
175 {
176 if (m_regions.ContainsKey(regionHandle))
177 {
178 return m_regions[regionHandle];
179 }
180
181 return null;
182 }
183
184 /// <summary>
185 /// Get information about a neighbouring region
186 /// </summary>
187 /// <param name="regionHandle"></param>
188 /// <returns></returns>
189 public RegionInfo RequestNeighbourInfo(UUID regionID)
190 {
191 // TODO add a dictionary for faster lookup
192 foreach (RegionInfo info in m_regions.Values)
193 {
194 if (info.RegionID == regionID)
195 return info;
196 }
197
198 return null;
199 }
200
201 /// <summary>
202 /// Get information about a neighbouring region
203 /// </summary>
204 /// <param name="regionHandle"></param>
205 /// <returns></returns>
206 public RegionInfo RequestNeighbourInfo(string name)
207 {
208 foreach (RegionInfo info in m_regions.Values)
209 {
210 if (info.RegionName == name)
211 return info;
212 }
213
214 return null;
215 }
216
217 /// <summary>
218 /// Get information about a neighbouring region
219 /// </summary>
220 /// <param name="regionHandle"></param>
221 /// <returns></returns>
222 public RegionInfo RequestNeighbourInfo(string host, uint port)
223 {
224 foreach (RegionInfo info in m_regions.Values)
225 {
226 if ((info.ExternalHostName == host) && (info.HttpPort == port))
227 return info;
228 }
229
230 return null;
231 }
232
233 /// <summary>
234 /// Get information about the closet region given a region name.
235 /// </summary>
236 /// <param name="regionName"></param>
237 /// <returns></returns>
238 public RegionInfo RequestClosestRegion(string regionName)
239 {
240 foreach (RegionInfo regInfo in m_regions.Values)
241 {
242 if (regInfo.RegionName == regionName)
243 return regInfo;
244 }
245 return null;
246 }
247
248 /// <summary>
249 ///
250 /// </summary>
251 /// <param name="minX"></param>
252 /// <param name="minY"></param>
253 /// <param name="maxX"></param>
254 /// <param name="maxY"></param>
255 /// <returns></returns>
256 public List<MapBlockData> RequestNeighbourMapBlocks(int minX, int minY, int maxX, int maxY)
257 {
258 List<MapBlockData> mapBlocks = new List<MapBlockData>();
259 foreach (RegionInfo regInfo in m_regions.Values)
260 {
261 if (((regInfo.RegionLocX >= minX) && (regInfo.RegionLocX <= maxX)) &&
262 ((regInfo.RegionLocY >= minY) && (regInfo.RegionLocY <= maxY)))
263 {
264 MapBlockData map = new MapBlockData();
265 map.Name = regInfo.RegionName;
266 map.X = (ushort) regInfo.RegionLocX;
267 map.Y = (ushort) regInfo.RegionLocY;
268 map.WaterHeight = (byte) regInfo.RegionSettings.WaterHeight;
269 map.MapImageId = regInfo.RegionSettings.TerrainImageID;
270 map.Agents = 1;
271 map.RegionFlags = 72458694;
272 map.Access = regInfo.AccessLevel;
273 mapBlocks.Add(map);
274 }
275 }
276 return mapBlocks;
277 }
278
279 // This function is only here to keep this class in line with the Grid Interface.
280 // It never gets called.
281 public virtual Dictionary<string, string> GetGridSettings()
282 {
283 Dictionary<string, string> returnGridSettings = new Dictionary<string, string>();
284 lock (m_queuedGridSettings)
285 {
286 returnGridSettings = m_queuedGridSettings;
287 m_queuedGridSettings.Clear();
288 }
289
290 return returnGridSettings;
291 }
292
293 public virtual void SetForcefulBanlistsDisallowed()
294 {
295 m_queuedGridSettings.Add("allow_forceful_banlines", "FALSE");
296 }
297
298
299 /// <summary>
300 /// Is a Sandbox mode method, used by the local Login server to inform a region of a connection user/session
301 /// </summary>
302 /// <param name="regionHandle"></param>
303 /// <param name="loginData"></param>
304 /// <returns></returns>
305 public void AddNewSession(ulong regionHandle, Login loginData)
306 {
307 AgentCircuitData agent = new AgentCircuitData();
308 agent.AgentID = loginData.Agent;
309 agent.firstname = loginData.First;
310 agent.lastname = loginData.Last;
311 agent.SessionID = loginData.Session;
312 agent.SecureSessionID = loginData.SecureSession;
313 agent.circuitcode = loginData.CircuitCode;
314 agent.BaseFolder = loginData.BaseFolder;
315 agent.InventoryFolder = loginData.InventoryFolder;
316 agent.startpos = loginData.StartPos;
317 agent.CapsPath = loginData.CapsPath;
318 if (loginData.Appearance != null)
319 agent.Appearance = loginData.Appearance;
320 else
321 {
322 m_log.WarnFormat("[INTER]: Appearance not found for {0} {1}. Creating default.", agent.firstname, agent.lastname);
323 agent.Appearance = new AvatarAppearance(agent.AgentID);
324 }
325
326 TriggerExpectUser(regionHandle, agent);
327 }
328
329 public void TriggerExpectUser(ulong regionHandle, AgentCircuitData agent)
330 {
331 //m_log.Info("[INTER]: " + rdebugRegionName + ":Local BackEnd: Other region is sending child agent our way: " + agent.firstname + " " + agent.lastname);
332
333 if (m_regionListeners.ContainsKey(regionHandle))
334 {
335 //m_log.Info("[INTER]: " + rdebugRegionName + ":Local BackEnd: FoundLocalRegion To send it to: " + agent.firstname + " " + agent.lastname);
336
337 m_regionListeners[regionHandle].TriggerExpectUser(agent);
338 }
339 }
340
341 public void TriggerLogOffUser(ulong regionHandle, UUID agentID, UUID RegionSecret, string message)
342 {
343 if (m_regionListeners.ContainsKey(regionHandle))
344 {
345 //m_log.Info("[INTER]: " + rdebugRegionName + ":Local BackEnd: FoundLocalRegion To send it to: " + agent.firstname + " " + agent.lastname);
346
347 m_regionListeners[regionHandle].TriggerLogOffUser(agentID, RegionSecret, message);
348 }
349 }
350
351 public void PingCheckReply(Hashtable respData)
352 {
353 foreach (ulong region in m_regions.Keys)
354 {
355 Hashtable regData = new Hashtable();
356 RegionInfo reg = m_regions[region];
357 regData["status"] = "active";
358 regData["handle"] = region.ToString();
359
360 respData[reg.RegionID.ToString()] = regData;
361 }
362 }
363
364
365 public LandData RequestLandData (ulong regionHandle, uint x, uint y)
366 {
367 m_log.DebugFormat("[INTERREGION STANDALONE] requests land data in {0}, at {1}, {2}",
368 regionHandle, x, y);
369
370 if (m_regionListeners.ContainsKey(regionHandle))
371 {
372 LandData land = m_regionListeners[regionHandle].TriggerGetLandData(x, y);
373 return land;
374 }
375
376 m_log.Debug("[INTERREGION STANDALONE] didn't find land data locally.");
377 return null;
378 }
379
380 public List<RegionInfo> RequestNamedRegions (string name, int maxNumber)
381 {
382 List<RegionInfo> lowercase_regions = new List<RegionInfo>();
383 List<RegionInfo> regions = new List<RegionInfo>();
384 foreach (RegionInfo info in m_regions.Values)
385 {
386 // Prioritizes exact match
387 if (info.RegionName.StartsWith(name))
388 {
389 regions.Add(info);
390 if (regions.Count >= maxNumber) break;
391 }
392 // But still saves lower case matches
393 else if (info.RegionName.ToLower().StartsWith(name))
394 {
395 if (lowercase_regions.Count < maxNumber)
396 {
397 lowercase_regions.Add(info);
398 }
399 }
400 }
401
402 // If no exact matches found, return lowercase matches (libOMV compatiblity)
403 if (regions.Count == 0 && lowercase_regions.Count != 0)
404 {
405 return lowercase_regions;
406 }
407 return regions;
408 }
409 }
410}
diff --git a/OpenSim/Region/Communications/OGS1/CommunicationsOGS1.cs b/OpenSim/Region/Communications/OGS1/CommunicationsOGS1.cs
index 8b5779f..c2b8f26 100644
--- a/OpenSim/Region/Communications/OGS1/CommunicationsOGS1.cs
+++ b/OpenSim/Region/Communications/OGS1/CommunicationsOGS1.cs
@@ -39,8 +39,6 @@ namespace OpenSim.Region.Communications.OGS1
39 LibraryRootFolder libraryRootFolder) 39 LibraryRootFolder libraryRootFolder)
40 : base(serversInfo, libraryRootFolder) 40 : base(serversInfo, libraryRootFolder)
41 { 41 {
42 OGS1GridServices gridInterComms = new OGS1GridServices(serversInfo);
43 m_gridService = gridInterComms;
44 42
45 // This plugin arrangement could eventually be configurable rather than hardcoded here. 43 // This plugin arrangement could eventually be configurable rather than hardcoded here.
46 OGS1UserServices userServices = new OGS1UserServices(this); 44 OGS1UserServices userServices = new OGS1UserServices(this);
diff --git a/OpenSim/Region/Communications/OGS1/OGS1GridServices.cs b/OpenSim/Region/Communications/OGS1/OGS1GridServices.cs
deleted file mode 100644
index 47c7fe4..0000000
--- a/OpenSim/Region/Communications/OGS1/OGS1GridServices.cs
+++ /dev/null
@@ -1,937 +0,0 @@
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.Net;
32using System.Net.Sockets;
33using System.Reflection;
34using log4net;
35using Nwc.XmlRpc;
36using OpenMetaverse;
37using OpenSim.Framework;
38using OpenSim.Framework.Communications;
39using OpenSim.Framework.Servers.HttpServer;
40using OpenSim.Region.Communications.Local;
41
42namespace OpenSim.Region.Communications.OGS1
43{
44 public class OGS1GridServices : IGridServices
45 {
46 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
47
48 private bool m_useRemoteRegionCache = true;
49 /// <summary>
50 /// Encapsulate local backend services for manipulation of local regions
51 /// </summary>
52 private LocalBackEndServices m_localBackend = new LocalBackEndServices();
53
54 private Dictionary<ulong, RegionInfo> m_remoteRegionInfoCache = new Dictionary<ulong, RegionInfo>();
55 // private List<SimpleRegionInfo> m_knownRegions = new List<SimpleRegionInfo>();
56 private Dictionary<ulong, int> m_deadRegionCache = new Dictionary<ulong, int>();
57 private Dictionary<string, string> m_queuedGridSettings = new Dictionary<string, string>();
58 private List<RegionInfo> m_regionsOnInstance = new List<RegionInfo>();
59
60 public BaseHttpServer httpListener;
61 public NetworkServersInfo serversInfo;
62
63 public string gdebugRegionName
64 {
65 get { return m_localBackend.gdebugRegionName; }
66 set { m_localBackend.gdebugRegionName = value; }
67 }
68
69 public string rdebugRegionName
70 {
71 get { return _rdebugRegionName; }
72 set { _rdebugRegionName = value; }
73 }
74 private string _rdebugRegionName = String.Empty;
75
76 public bool RegionLoginsEnabled
77 {
78 get { return m_localBackend.RegionLoginsEnabled; }
79 set { m_localBackend.RegionLoginsEnabled = value; }
80 }
81
82 /// <summary>
83 /// Contructor. Adds "expect_user" and "check" xmlrpc method handlers
84 /// </summary>
85 /// <param name="servers_info"></param>
86 /// <param name="httpServe"></param>
87 public OGS1GridServices(NetworkServersInfo servers_info)
88 {
89 serversInfo = servers_info;
90
91 //Respond to Grid Services requests
92 MainServer.Instance.AddXmlRPCHandler("check", PingCheckReply);
93 }
94
95 // see IGridServices
96 public RegionCommsListener RegisterRegion(RegionInfo regionInfo)
97 {
98 if (m_regionsOnInstance.Contains(regionInfo))
99 {
100 m_log.Error("[OGS1 GRID SERVICES]: Foobar! Caller is confused, region already registered " + regionInfo.RegionName);
101 Exception e = new Exception(String.Format("Unable to register region"));
102
103 throw e;
104 }
105
106 m_log.InfoFormat(
107 "[OGS1 GRID SERVICES]: Registering region {0} with grid at {1}",
108 regionInfo.RegionName, serversInfo.GridURL);
109
110 m_regionsOnInstance.Add(regionInfo);
111
112 Hashtable GridParams = new Hashtable();
113 // Login / Authentication
114
115 GridParams["authkey"] = serversInfo.GridSendKey;
116 GridParams["recvkey"] = serversInfo.GridRecvKey;
117 GridParams["UUID"] = regionInfo.RegionID.ToString();
118 GridParams["sim_ip"] = regionInfo.ExternalHostName;
119 GridParams["sim_port"] = regionInfo.InternalEndPoint.Port.ToString();
120 GridParams["region_locx"] = regionInfo.RegionLocX.ToString();
121 GridParams["region_locy"] = regionInfo.RegionLocY.ToString();
122 GridParams["sim_name"] = regionInfo.RegionName;
123 GridParams["http_port"] = serversInfo.HttpListenerPort.ToString();
124 GridParams["remoting_port"] = ConfigSettings.DefaultRegionRemotingPort.ToString();
125 GridParams["map-image-id"] = regionInfo.RegionSettings.TerrainImageID.ToString();
126 GridParams["originUUID"] = regionInfo.originRegionID.ToString();
127 GridParams["server_uri"] = regionInfo.ServerURI;
128 GridParams["region_secret"] = regionInfo.regionSecret;
129 GridParams["major_interface_version"] = VersionInfo.MajorInterfaceVersion.ToString();
130
131 if (regionInfo.MasterAvatarAssignedUUID != UUID.Zero)
132 GridParams["master_avatar_uuid"] = regionInfo.MasterAvatarAssignedUUID.ToString();
133 else
134 GridParams["master_avatar_uuid"] = regionInfo.EstateSettings.EstateOwner.ToString();
135
136 GridParams["maturity"] = regionInfo.RegionSettings.Maturity.ToString();
137
138 // Package into an XMLRPC Request
139 ArrayList SendParams = new ArrayList();
140 SendParams.Add(GridParams);
141
142 // Send Request
143 XmlRpcRequest GridReq = new XmlRpcRequest("simulator_login", SendParams);
144 XmlRpcResponse GridResp;
145
146 try
147 {
148 // The timeout should always be significantly larger than the timeout for the grid server to request
149 // the initial status of the region before confirming registration.
150 GridResp = GridReq.Send(serversInfo.GridURL, 9999999);
151 }
152 catch (Exception e)
153 {
154 Exception e2
155 = new Exception(
156 String.Format(
157 "Unable to register region with grid at {0}. Grid service not running?",
158 serversInfo.GridURL),
159 e);
160
161 throw e2;
162 }
163
164 Hashtable GridRespData = (Hashtable)GridResp.Value;
165 // Hashtable griddatahash = GridRespData;
166
167 // Process Response
168 if (GridRespData.ContainsKey("error"))
169 {
170 string errorstring = (string) GridRespData["error"];
171
172 Exception e = new Exception(
173 String.Format("Unable to connect to grid at {0}: {1}", serversInfo.GridURL, errorstring));
174
175 throw e;
176 }
177 else
178 {
179 // m_knownRegions = RequestNeighbours(regionInfo.RegionLocX, regionInfo.RegionLocY);
180 if (GridRespData.ContainsKey("allow_forceful_banlines"))
181 {
182 if ((string) GridRespData["allow_forceful_banlines"] != "TRUE")
183 {
184 //m_localBackend.SetForcefulBanlistsDisallowed(regionInfo.RegionHandle);
185 if (!m_queuedGridSettings.ContainsKey("allow_forceful_banlines"))
186 m_queuedGridSettings.Add("allow_forceful_banlines", "FALSE");
187 }
188 }
189
190 m_log.InfoFormat(
191 "[OGS1 GRID SERVICES]: Region {0} successfully registered with grid at {1}",
192 regionInfo.RegionName, serversInfo.GridURL);
193 }
194
195 return m_localBackend.RegisterRegion(regionInfo);
196 }
197
198 // see IGridServices
199 public bool DeregisterRegion(RegionInfo regionInfo)
200 {
201 Hashtable GridParams = new Hashtable();
202
203 GridParams["UUID"] = regionInfo.RegionID.ToString();
204
205 // Package into an XMLRPC Request
206 ArrayList SendParams = new ArrayList();
207 SendParams.Add(GridParams);
208
209 // Send Request
210 XmlRpcRequest GridReq = new XmlRpcRequest("simulator_after_region_moved", SendParams);
211 XmlRpcResponse GridResp = null;
212
213 try
214 {
215 GridResp = GridReq.Send(serversInfo.GridURL, 10000);
216 }
217 catch (Exception e)
218 {
219 Exception e2
220 = new Exception(
221 String.Format(
222 "Unable to deregister region with grid at {0}. Grid service not running?",
223 serversInfo.GridURL),
224 e);
225
226 throw e2;
227 }
228
229 Hashtable GridRespData = (Hashtable) GridResp.Value;
230
231 // Hashtable griddatahash = GridRespData;
232
233 // Process Response
234 if (GridRespData != null && GridRespData.ContainsKey("error"))
235 {
236 string errorstring = (string)GridRespData["error"];
237 m_log.Error("Unable to connect to grid: " + errorstring);
238 return false;
239 }
240
241 return m_localBackend.DeregisterRegion(regionInfo);
242 }
243
244 public virtual Dictionary<string, string> GetGridSettings()
245 {
246 Dictionary<string, string> returnGridSettings = new Dictionary<string, string>();
247 lock (m_queuedGridSettings)
248 {
249 foreach (string Dictkey in m_queuedGridSettings.Keys)
250 {
251 returnGridSettings.Add(Dictkey, m_queuedGridSettings[Dictkey]);
252 }
253
254 m_queuedGridSettings.Clear();
255 }
256
257 return returnGridSettings;
258 }
259
260 // see IGridServices
261 public List<SimpleRegionInfo> RequestNeighbours(uint x, uint y)
262 {
263 Hashtable respData = MapBlockQuery((int) x - 1, (int) y - 1, (int) x + 1, (int) y + 1);
264
265 List<SimpleRegionInfo> neighbours = new List<SimpleRegionInfo>();
266
267 foreach (ArrayList neighboursList in respData.Values)
268 {
269 foreach (Hashtable neighbourData in neighboursList)
270 {
271 uint regX = Convert.ToUInt32(neighbourData["x"]);
272 uint regY = Convert.ToUInt32(neighbourData["y"]);
273 if ((x != regX) || (y != regY))
274 {
275 string simIp = (string) neighbourData["sim_ip"];
276
277 uint port = Convert.ToUInt32(neighbourData["sim_port"]);
278 // string externalUri = (string) neighbourData["sim_uri"];
279
280 // string externalIpStr = String.Empty;
281 try
282 {
283 // externalIpStr = Util.GetHostFromDNS(simIp).ToString();
284 Util.GetHostFromDNS(simIp).ToString();
285 }
286 catch (SocketException e)
287 {
288 m_log.WarnFormat(
289 "[OGS1 GRID SERVICES]: RequestNeighbours(): Lookup of neighbour {0} failed! Not including in neighbours list. {1}",
290 simIp, e);
291
292 continue;
293 }
294
295 SimpleRegionInfo sri = new SimpleRegionInfo(regX, regY, simIp, port);
296
297 sri.RemotingPort = Convert.ToUInt32(neighbourData["remoting_port"]);
298
299 if (neighbourData.ContainsKey("http_port"))
300 {
301 sri.HttpPort = Convert.ToUInt32(neighbourData["http_port"]);
302 }
303 else
304 {
305 m_log.Error("[OGS1 GRID SERVICES]: Couldn't find httpPort, using default 9000; please upgrade your grid-server to r7621 or later");
306 sri.HttpPort = 9000; // that's the default and will probably be wrong
307 }
308
309 sri.RegionID = new UUID((string) neighbourData["uuid"]);
310
311 neighbours.Add(sri);
312 }
313 }
314 }
315
316 return neighbours;
317 }
318
319 /// <summary>
320 /// Request information about a region.
321 /// </summary>
322 /// <param name="regionHandle"></param>
323 /// <returns>
324 /// null on a failure to contact or get a response from the grid server
325 /// FIXME: Might be nicer to return a proper exception here since we could inform the client more about the
326 /// nature of the faiulre.
327 /// </returns>
328 public RegionInfo RequestNeighbourInfo(UUID Region_UUID)
329 {
330 // don't ask the gridserver about regions on this instance...
331 foreach (RegionInfo info in m_regionsOnInstance)
332 {
333 if (info.RegionID == Region_UUID) return info;
334 }
335
336 // didn't find it so far, we have to go the long way
337 RegionInfo regionInfo;
338 Hashtable requestData = new Hashtable();
339 requestData["region_UUID"] = Region_UUID.ToString();
340 requestData["authkey"] = serversInfo.GridSendKey;
341 ArrayList SendParams = new ArrayList();
342 SendParams.Add(requestData);
343 XmlRpcRequest gridReq = new XmlRpcRequest("simulator_data_request", SendParams);
344 XmlRpcResponse gridResp = null;
345
346 try
347 {
348 gridResp = gridReq.Send(serversInfo.GridURL, 3000);
349 }
350 catch (Exception e)
351 {
352 m_log.ErrorFormat(
353 "[OGS1 GRID SERVICES]: Communication with the grid server at {0} failed, {1}",
354 serversInfo.GridURL, e);
355
356 return null;
357 }
358
359 Hashtable responseData = (Hashtable)gridResp.Value;
360
361 if (responseData.ContainsKey("error"))
362 {
363 m_log.WarnFormat("[OGS1 GRID SERVICES]: Error received from grid server: {0}", responseData["error"]);
364 return null;
365 }
366
367 regionInfo = buildRegionInfo(responseData, String.Empty);
368 if ((m_useRemoteRegionCache) && (requestData.ContainsKey("regionHandle")))
369 {
370 m_remoteRegionInfoCache.Add(Convert.ToUInt64((string) requestData["regionHandle"]), regionInfo);
371 }
372
373 return regionInfo;
374 }
375
376 /// <summary>
377 /// Request information about a region.
378 /// </summary>
379 /// <param name="regionHandle"></param>
380 /// <returns></returns>
381 public RegionInfo RequestNeighbourInfo(ulong regionHandle)
382 {
383 RegionInfo regionInfo = m_localBackend.RequestNeighbourInfo(regionHandle);
384
385 if (regionInfo != null)
386 {
387 return regionInfo;
388 }
389
390 if ((!m_useRemoteRegionCache) || (!m_remoteRegionInfoCache.TryGetValue(regionHandle, out regionInfo)))
391 {
392 try
393 {
394 Hashtable requestData = new Hashtable();
395 requestData["region_handle"] = regionHandle.ToString();
396 requestData["authkey"] = serversInfo.GridSendKey;
397 ArrayList SendParams = new ArrayList();
398 SendParams.Add(requestData);
399 XmlRpcRequest GridReq = new XmlRpcRequest("simulator_data_request", SendParams);
400 XmlRpcResponse GridResp = GridReq.Send(serversInfo.GridURL, 3000);
401
402 Hashtable responseData = (Hashtable) GridResp.Value;
403
404 if (responseData.ContainsKey("error"))
405 {
406 m_log.Error("[OGS1 GRID SERVICES]: Error received from grid server: " + responseData["error"]);
407 return null;
408 }
409
410 uint regX = Convert.ToUInt32((string) responseData["region_locx"]);
411 uint regY = Convert.ToUInt32((string) responseData["region_locy"]);
412 string externalHostName = (string) responseData["sim_ip"];
413 uint simPort = Convert.ToUInt32(responseData["sim_port"]);
414 string regionName = (string)responseData["region_name"];
415 UUID regionID = new UUID((string)responseData["region_UUID"]);
416 uint remotingPort = Convert.ToUInt32((string)responseData["remoting_port"]);
417
418 uint httpPort = 9000;
419 if (responseData.ContainsKey("http_port"))
420 {
421 httpPort = Convert.ToUInt32((string)responseData["http_port"]);
422 }
423
424 // Ok, so this is definitively the wrong place to do this, way too hard coded, but it doesn't seem we GET this info?
425
426 string simURI = "http://" + externalHostName + ":" + simPort;
427
428 // string externalUri = (string) responseData["sim_uri"];
429
430 //IPEndPoint neighbourInternalEndPoint = new IPEndPoint(IPAddress.Parse(internalIpStr), (int) port);
431 regionInfo = RegionInfo.Create(regionID, regionName, regX, regY, externalHostName, httpPort, simPort, remotingPort, simURI);
432
433 if (m_useRemoteRegionCache)
434 {
435 lock (m_remoteRegionInfoCache)
436 {
437 if (!m_remoteRegionInfoCache.ContainsKey(regionHandle))
438 {
439 m_remoteRegionInfoCache.Add(regionHandle, regionInfo);
440 }
441 }
442 }
443 }
444 catch (Exception e)
445 {
446 m_log.Error("[OGS1 GRID SERVICES]: " +
447 "Region lookup failed for: " + regionHandle.ToString() +
448 " - Is the GridServer down?" + e.ToString());
449 return null;
450 }
451 }
452
453 return regionInfo;
454 }
455
456 /// <summary>
457 /// Get information about a neighbouring region
458 /// </summary>
459 /// <param name="regionHandle"></param>
460 /// <returns></returns>
461 public RegionInfo RequestNeighbourInfo(string name)
462 {
463 // Not implemented yet
464 return null;
465 }
466
467 /// <summary>
468 /// Get information about a neighbouring region
469 /// </summary>
470 /// <param name="regionHandle"></param>
471 /// <returns></returns>
472 public RegionInfo RequestNeighbourInfo(string host, uint port)
473 {
474 // Not implemented yet
475 return null;
476 }
477
478 public RegionInfo RequestClosestRegion(string regionName)
479 {
480 if (m_useRemoteRegionCache)
481 {
482 foreach (RegionInfo ri in m_remoteRegionInfoCache.Values)
483 {
484 if (ri.RegionName == regionName)
485 return ri;
486 }
487 }
488
489 RegionInfo regionInfo = null;
490 try
491 {
492 Hashtable requestData = new Hashtable();
493 requestData["region_name_search"] = regionName;
494 requestData["authkey"] = serversInfo.GridSendKey;
495 ArrayList SendParams = new ArrayList();
496 SendParams.Add(requestData);
497 XmlRpcRequest GridReq = new XmlRpcRequest("simulator_data_request", SendParams);
498 XmlRpcResponse GridResp = GridReq.Send(serversInfo.GridURL, 3000);
499
500 Hashtable responseData = (Hashtable) GridResp.Value;
501
502 if (responseData.ContainsKey("error"))
503 {
504 m_log.ErrorFormat("[OGS1 GRID SERVICES]: Error received from grid server: ", responseData["error"]);
505 return null;
506 }
507
508 regionInfo = buildRegionInfo(responseData, "");
509
510 if ((m_useRemoteRegionCache) && (!m_remoteRegionInfoCache.ContainsKey(regionInfo.RegionHandle)))
511 m_remoteRegionInfoCache.Add(regionInfo.RegionHandle, regionInfo);
512 }
513 catch
514 {
515 m_log.Error("[OGS1 GRID SERVICES]: " +
516 "Region lookup failed for: " + regionName +
517 " - Is the GridServer down?");
518 }
519
520 return regionInfo;
521 }
522
523 /// <summary>
524 ///
525 /// </summary>
526 /// <param name="minX"></param>
527 /// <param name="minY"></param>
528 /// <param name="maxX"></param>
529 /// <param name="maxY"></param>
530 /// <returns></returns>
531 public List<MapBlockData> RequestNeighbourMapBlocks(int minX, int minY, int maxX, int maxY)
532 {
533 int temp = 0;
534
535 if (minX > maxX)
536 {
537 temp = minX;
538 minX = maxX;
539 maxX = temp;
540 }
541 if (minY > maxY)
542 {
543 temp = minY;
544 minY = maxY;
545 maxY = temp;
546 }
547
548 Hashtable respData = MapBlockQuery(minX, minY, maxX, maxY);
549
550 List<MapBlockData> neighbours = new List<MapBlockData>();
551
552 foreach (ArrayList a in respData.Values)
553 {
554 foreach (Hashtable n in a)
555 {
556 MapBlockData neighbour = new MapBlockData();
557
558 neighbour.X = Convert.ToUInt16(n["x"]);
559 neighbour.Y = Convert.ToUInt16(n["y"]);
560
561 neighbour.Name = (string) n["name"];
562 neighbour.Access = Convert.ToByte(n["access"]);
563 neighbour.RegionFlags = Convert.ToUInt32(n["region-flags"]);
564 neighbour.WaterHeight = Convert.ToByte(n["water-height"]);
565 neighbour.MapImageId = new UUID((string) n["map-image-id"]);
566
567 neighbours.Add(neighbour);
568 }
569 }
570
571 return neighbours;
572 }
573
574 /// <summary>
575 /// Performs a XML-RPC query against the grid server returning mapblock information in the specified coordinates
576 /// </summary>
577 /// <remarks>REDUNDANT - OGS1 is to be phased out in favour of OGS2</remarks>
578 /// <param name="minX">Minimum X value</param>
579 /// <param name="minY">Minimum Y value</param>
580 /// <param name="maxX">Maximum X value</param>
581 /// <param name="maxY">Maximum Y value</param>
582 /// <returns>Hashtable of hashtables containing map data elements</returns>
583 private Hashtable MapBlockQuery(int minX, int minY, int maxX, int maxY)
584 {
585 Hashtable param = new Hashtable();
586 param["xmin"] = minX;
587 param["ymin"] = minY;
588 param["xmax"] = maxX;
589 param["ymax"] = maxY;
590 IList parameters = new ArrayList();
591 parameters.Add(param);
592
593 try
594 {
595 XmlRpcRequest req = new XmlRpcRequest("map_block", parameters);
596 XmlRpcResponse resp = req.Send(serversInfo.GridURL, 10000);
597 Hashtable respData = (Hashtable) resp.Value;
598 return respData;
599 }
600 catch (Exception e)
601 {
602 m_log.Error("MapBlockQuery XMLRPC failure: " + e);
603 return new Hashtable();
604 }
605 }
606
607 /// <summary>
608 /// A ping / version check
609 /// </summary>
610 /// <param name="request"></param>
611 /// <returns></returns>
612 public XmlRpcResponse PingCheckReply(XmlRpcRequest request, IPEndPoint remoteClient)
613 {
614 XmlRpcResponse response = new XmlRpcResponse();
615
616 Hashtable respData = new Hashtable();
617 respData["online"] = "true";
618
619 m_localBackend.PingCheckReply(respData);
620
621 response.Value = respData;
622
623 return response;
624 }
625
626 /// <summary>
627 /// Received from the user server when a user starts logging in. This call allows
628 /// the region to prepare for direct communication from the client. Sends back an empty
629 /// xmlrpc response on completion.
630 /// </summary>
631 /// <param name="request"></param>
632 /// <returns></returns>
633 public XmlRpcResponse ExpectUser(XmlRpcRequest request)
634 {
635 Hashtable requestData = (Hashtable) request.Params[0];
636 AgentCircuitData agentData = new AgentCircuitData();
637 agentData.SessionID = new UUID((string) requestData["session_id"]);
638 agentData.SecureSessionID = new UUID((string) requestData["secure_session_id"]);
639 agentData.firstname = (string) requestData["firstname"];
640 agentData.lastname = (string) requestData["lastname"];
641 agentData.AgentID = new UUID((string) requestData["agent_id"]);
642 agentData.circuitcode = Convert.ToUInt32(requestData["circuit_code"]);
643 agentData.CapsPath = (string)requestData["caps_path"];
644 ulong regionHandle = Convert.ToUInt64((string) requestData["regionhandle"]);
645
646 // Appearance
647 if (requestData["appearance"] != null)
648 agentData.Appearance = new AvatarAppearance((Hashtable)requestData["appearance"]);
649
650 m_log.DebugFormat(
651 "[CLIENT]: Told by user service to prepare for a connection from {0} {1} {2}, circuit {3}",
652 agentData.firstname, agentData.lastname, agentData.AgentID, agentData.circuitcode);
653
654 if (requestData.ContainsKey("child_agent") && requestData["child_agent"].Equals("1"))
655 {
656 //m_log.Debug("[CLIENT]: Child agent detected");
657 agentData.child = true;
658 }
659 else
660 {
661 //m_log.Debug("[CLIENT]: Main agent detected");
662 agentData.startpos =
663 new Vector3((float)Convert.ToDecimal((string)requestData["startpos_x"]),
664 (float)Convert.ToDecimal((string)requestData["startpos_y"]),
665 (float)Convert.ToDecimal((string)requestData["startpos_z"]));
666 agentData.child = false;
667 }
668
669 XmlRpcResponse resp = new XmlRpcResponse();
670
671 if (!RegionLoginsEnabled)
672 {
673 m_log.InfoFormat(
674 "[CLIENT]: Denying access for user {0} {1} because region login is currently disabled",
675 agentData.firstname, agentData.lastname);
676
677 Hashtable respdata = new Hashtable();
678 respdata["success"] = "FALSE";
679 respdata["reason"] = "region login currently disabled";
680 resp.Value = respdata;
681 }
682 else
683 {
684 RegionInfo[] regions = m_regionsOnInstance.ToArray();
685 bool banned = false;
686
687 for (int i = 0; i < regions.Length; i++)
688 {
689 if (regions[i] != null)
690 {
691 if (regions[i].RegionHandle == regionHandle)
692 {
693 if (regions[i].EstateSettings.IsBanned(agentData.AgentID))
694 {
695 banned = true;
696 break;
697 }
698 }
699 }
700 }
701
702 if (banned)
703 {
704 m_log.InfoFormat(
705 "[CLIENT]: Denying access for user {0} {1} because user is banned",
706 agentData.firstname, agentData.lastname);
707
708 Hashtable respdata = new Hashtable();
709 respdata["success"] = "FALSE";
710 respdata["reason"] = "banned";
711 resp.Value = respdata;
712 }
713 else
714 {
715 m_localBackend.TriggerExpectUser(regionHandle, agentData);
716 Hashtable respdata = new Hashtable();
717 respdata["success"] = "TRUE";
718 resp.Value = respdata;
719 }
720 }
721
722 return resp;
723 }
724
725 // Grid Request Processing
726 /// <summary>
727 /// Ooops, our Agent must be dead if we're getting this request!
728 /// </summary>
729 /// <param name="request"></param>
730 /// <returns></returns>
731 public XmlRpcResponse LogOffUser(XmlRpcRequest request)
732 {
733 m_log.Debug("[CONNECTION DEBUGGING]: LogOff User Called");
734
735 Hashtable requestData = (Hashtable)request.Params[0];
736 string message = (string)requestData["message"];
737 UUID agentID = UUID.Zero;
738 UUID RegionSecret = UUID.Zero;
739 UUID.TryParse((string)requestData["agent_id"], out agentID);
740 UUID.TryParse((string)requestData["region_secret"], out RegionSecret);
741
742 ulong regionHandle = Convert.ToUInt64((string)requestData["regionhandle"]);
743
744 m_localBackend.TriggerLogOffUser(regionHandle, agentID, RegionSecret,message);
745
746 return new XmlRpcResponse();
747 }
748
749 public void NoteDeadRegion(ulong regionhandle)
750 {
751 lock (m_deadRegionCache)
752 {
753 if (m_deadRegionCache.ContainsKey(regionhandle))
754 {
755 m_deadRegionCache[regionhandle] = m_deadRegionCache[regionhandle] + 1;
756 }
757 else
758 {
759 m_deadRegionCache.Add(regionhandle, 1);
760 }
761 }
762 }
763
764 public LandData RequestLandData (ulong regionHandle, uint x, uint y)
765 {
766 m_log.DebugFormat("[OGS1 GRID SERVICES] requests land data in {0}, at {1}, {2}",
767 regionHandle, x, y);
768 LandData landData = m_localBackend.RequestLandData(regionHandle, x, y);
769 if (landData == null)
770 {
771 Hashtable hash = new Hashtable();
772 hash["region_handle"] = regionHandle.ToString();
773 hash["x"] = x.ToString();
774 hash["y"] = y.ToString();
775
776 IList paramList = new ArrayList();
777 paramList.Add(hash);
778
779 try
780 {
781 // this might be cached, as we probably requested it just a moment ago...
782 RegionInfo info = RequestNeighbourInfo(regionHandle);
783 if (info != null) // just to be sure
784 {
785 XmlRpcRequest request = new XmlRpcRequest("land_data", paramList);
786 string uri = "http://" + info.ExternalEndPoint.Address + ":" + info.HttpPort + "/";
787 XmlRpcResponse response = request.Send(uri, 10000);
788 if (response.IsFault)
789 {
790 m_log.ErrorFormat("[OGS1 GRID SERVICES] remote call returned an error: {0}", response.FaultString);
791 }
792 else
793 {
794 hash = (Hashtable)response.Value;
795 try
796 {
797 landData = new LandData();
798 landData.AABBMax = Vector3.Parse((string)hash["AABBMax"]);
799 landData.AABBMin = Vector3.Parse((string)hash["AABBMin"]);
800 landData.Area = Convert.ToInt32(hash["Area"]);
801 landData.AuctionID = Convert.ToUInt32(hash["AuctionID"]);
802 landData.Description = (string)hash["Description"];
803 landData.Flags = Convert.ToUInt32(hash["Flags"]);
804 landData.GlobalID = new UUID((string)hash["GlobalID"]);
805 landData.Name = (string)hash["Name"];
806 landData.OwnerID = new UUID((string)hash["OwnerID"]);
807 landData.SalePrice = Convert.ToInt32(hash["SalePrice"]);
808 landData.SnapshotID = new UUID((string)hash["SnapshotID"]);
809 landData.UserLocation = Vector3.Parse((string)hash["UserLocation"]);
810 m_log.DebugFormat("[OGS1 GRID SERVICES] Got land data for parcel {0}", landData.Name);
811 }
812 catch (Exception e)
813 {
814 m_log.Error("[OGS1 GRID SERVICES] Got exception while parsing land-data:", e);
815 }
816 }
817 }
818 else m_log.WarnFormat("[OGS1 GRID SERVICES] Couldn't find region with handle {0}", regionHandle);
819 }
820 catch (Exception e)
821 {
822 m_log.ErrorFormat("[OGS1 GRID SERVICES] Couldn't contact region {0}: {1}", regionHandle, e);
823 }
824 }
825 return landData;
826 }
827
828 // Grid Request Processing
829 /// <summary>
830 /// Someone asked us about parcel-information
831 /// </summary>
832 /// <param name="request"></param>
833 /// <returns></returns>
834 public XmlRpcResponse LandData(XmlRpcRequest request, IPEndPoint remoteClient)
835 {
836 Hashtable requestData = (Hashtable)request.Params[0];
837 ulong regionHandle = Convert.ToUInt64(requestData["region_handle"]);
838 uint x = Convert.ToUInt32(requestData["x"]);
839 uint y = Convert.ToUInt32(requestData["y"]);
840 m_log.DebugFormat("[OGS1 GRID SERVICES]: Got XML reqeuest for land data at {0}, {1} in region {2}", x, y, regionHandle);
841
842 LandData landData = m_localBackend.RequestLandData(regionHandle, x, y);
843 Hashtable hash = new Hashtable();
844 if (landData != null)
845 {
846 // for now, only push out the data we need for answering a ParcelInfoReqeust
847 hash["AABBMax"] = landData.AABBMax.ToString();
848 hash["AABBMin"] = landData.AABBMin.ToString();
849 hash["Area"] = landData.Area.ToString();
850 hash["AuctionID"] = landData.AuctionID.ToString();
851 hash["Description"] = landData.Description;
852 hash["Flags"] = landData.Flags.ToString();
853 hash["GlobalID"] = landData.GlobalID.ToString();
854 hash["Name"] = landData.Name;
855 hash["OwnerID"] = landData.OwnerID.ToString();
856 hash["SalePrice"] = landData.SalePrice.ToString();
857 hash["SnapshotID"] = landData.SnapshotID.ToString();
858 hash["UserLocation"] = landData.UserLocation.ToString();
859 }
860
861 XmlRpcResponse response = new XmlRpcResponse();
862 response.Value = hash;
863 return response;
864 }
865
866 public List<RegionInfo> RequestNamedRegions (string name, int maxNumber)
867 {
868 // no asking of the local backend first, here, as we have to ask the gridserver anyway.
869 Hashtable hash = new Hashtable();
870 hash["name"] = name;
871 hash["maxNumber"] = maxNumber.ToString();
872
873 IList paramList = new ArrayList();
874 paramList.Add(hash);
875
876 Hashtable result = XmlRpcSearchForRegionByName(paramList);
877 if (result == null) return null;
878
879 uint numberFound = Convert.ToUInt32(result["numFound"]);
880 List<RegionInfo> infos = new List<RegionInfo>();
881 for (int i = 0; i < numberFound; ++i)
882 {
883 string prefix = "region" + i + ".";
884 RegionInfo info = buildRegionInfo(result, prefix);
885 infos.Add(info);
886 }
887 return infos;
888 }
889
890 private RegionInfo buildRegionInfo(Hashtable responseData, string prefix)
891 {
892 uint regX = Convert.ToUInt32((string) responseData[prefix + "region_locx"]);
893 uint regY = Convert.ToUInt32((string) responseData[prefix + "region_locy"]);
894 string internalIpStr = (string) responseData[prefix + "sim_ip"];
895 uint port = Convert.ToUInt32(responseData[prefix + "sim_port"]);
896
897 IPEndPoint neighbourInternalEndPoint = new IPEndPoint(Util.GetHostFromDNS(internalIpStr), (int) port);
898
899 RegionInfo regionInfo = new RegionInfo(regX, regY, neighbourInternalEndPoint, internalIpStr);
900 regionInfo.RemotingPort = Convert.ToUInt32((string) responseData[prefix + "remoting_port"]);
901 regionInfo.RemotingAddress = internalIpStr;
902
903 if (responseData.ContainsKey(prefix + "http_port"))
904 {
905 regionInfo.HttpPort = Convert.ToUInt32((string) responseData[prefix + "http_port"]);
906 }
907
908 regionInfo.RegionID = new UUID((string) responseData[prefix + "region_UUID"]);
909 regionInfo.RegionName = (string) responseData[prefix + "region_name"];
910
911 regionInfo.RegionSettings.TerrainImageID = new UUID((string) responseData[prefix + "map_UUID"]);
912 return regionInfo;
913 }
914
915 private Hashtable XmlRpcSearchForRegionByName(IList parameters)
916 {
917 try
918 {
919 XmlRpcRequest request = new XmlRpcRequest("search_for_region_by_name", parameters);
920 XmlRpcResponse resp = request.Send(serversInfo.GridURL, 10000);
921 Hashtable respData = (Hashtable) resp.Value;
922 if (respData != null && respData.Contains("faultCode"))
923 {
924 m_log.WarnFormat("[OGS1 GRID SERVICES]: Got an error while contacting GridServer: {0}", respData["faultString"]);
925 return null;
926 }
927
928 return respData;
929 }
930 catch (Exception e)
931 {
932 m_log.Error("[OGS1 GRID SERVICES]: MapBlockQuery XMLRPC failure: ", e);
933 return null;
934 }
935 }
936 }
937}