aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Communications/Hypergrid
diff options
context:
space:
mode:
authorJustin Clarke Casey2008-11-25 15:19:00 +0000
committerJustin Clarke Casey2008-11-25 15:19:00 +0000
commite187972377c19bdd85093677c4c54034e4f9196e (patch)
treecc1bb5f003628b018b823eafc9ee0a67f98df31c /OpenSim/Region/Communications/Hypergrid
parent* Adding some virtual hooks and making some privaets protected for great just... (diff)
downloadopensim-SC-e187972377c19bdd85093677c4c54034e4f9196e.zip
opensim-SC-e187972377c19bdd85093677c4c54034e4f9196e.tar.gz
opensim-SC-e187972377c19bdd85093677c4c54034e4f9196e.tar.bz2
opensim-SC-e187972377c19bdd85093677c4c54034e4f9196e.tar.xz
* Apply http://opensimulator.org/mantis/view.php?id=2640
* This is Diva's hypergrid patch, as perviously discussed on the opensim-dev mailing list * Applied some minor prebuild.xml jiggling to resolve a dependency issue * Thanks Diva!
Diffstat (limited to 'OpenSim/Region/Communications/Hypergrid')
-rw-r--r--OpenSim/Region/Communications/Hypergrid/HGCommunicationsGridMode.cs82
-rw-r--r--OpenSim/Region/Communications/Hypergrid/HGCommunicationsStandalone.cs59
-rw-r--r--OpenSim/Region/Communications/Hypergrid/HGGridServices.cs1294
-rw-r--r--OpenSim/Region/Communications/Hypergrid/HGGridServicesGridMode.cs285
-rw-r--r--OpenSim/Region/Communications/Hypergrid/HGGridServicesStandalone.cs928
-rw-r--r--OpenSim/Region/Communications/Hypergrid/HGInventoryService.cs451
-rw-r--r--OpenSim/Region/Communications/Hypergrid/HGUserServices.cs267
7 files changed, 3366 insertions, 0 deletions
diff --git a/OpenSim/Region/Communications/Hypergrid/HGCommunicationsGridMode.cs b/OpenSim/Region/Communications/Hypergrid/HGCommunicationsGridMode.cs
new file mode 100644
index 0000000..9672df3
--- /dev/null
+++ b/OpenSim/Region/Communications/Hypergrid/HGCommunicationsGridMode.cs
@@ -0,0 +1,82 @@
1/**
2 * Copyright (c) 2008, Contributors. All rights reserved.
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without modification,
6 * are permitted provided that the following conditions are met:
7 *
8 * * Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13 * * Neither the name of the Organizations nor the names of Individual
14 * Contributors may be used to endorse or promote products derived from
15 * this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
20 * THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
21 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
22 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
23 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
24 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
25 * OF THE POSSIBILITY OF SUCH DAMAGE.
26 *
27 */
28using System.Reflection;
29
30using log4net;
31
32using OpenSim.Framework;
33using OpenSim.Framework.Communications;
34using OpenSim.Framework.Communications.Cache;
35using OpenSim.Region.Communications.OGS1;
36using OpenSim.Framework.Servers;
37using OpenSim.Region.Environment.Scenes;
38
39namespace OpenSim.Region.Communications.Hypergrid
40{
41 public class HGCommunicationsGridMode : CommunicationsManager // CommunicationsOGS1
42 {
43 private static readonly ILog m_log
44 = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
45
46 IHyperlink m_osw = null;
47 public IHyperlink HGServices
48 {
49 get { return m_osw; }
50 }
51
52 public HGCommunicationsGridMode(
53 NetworkServersInfo serversInfo, BaseHttpServer httpServer,
54 AssetCache assetCache, SceneManager sman, LibraryRootFolder libraryRootFolder)
55 : base(serversInfo, httpServer, assetCache, false, libraryRootFolder)
56 {
57
58 // From constructor at CommunicationsOGS1
59 HGGridServices gridInterComms = new HGGridServicesGridMode(serversInfo, httpServer, assetCache, sman, m_userProfileCacheService);
60 m_gridService = gridInterComms;
61 m_interRegion = gridInterComms;
62 m_osw = gridInterComms;
63
64 // The HG InventoryService always uses secure handlers
65 HGInventoryService invService = new HGInventoryService(serversInfo.InventoryURL, this.m_userProfileCacheService, true);
66 AddSecureInventoryService(invService);
67 m_defaultInventoryHost = invService.Host;
68 if (SecureInventoryService != null)
69 m_log.Info("[HG] SecureInventoryService.");
70 else
71 m_log.Info("[HG] Non-secureInventoryService.");
72
73
74 HGUserServices userServices = new HGUserServices(this);
75 m_userService = userServices;
76 m_messageService = userServices;
77 m_avatarService = (IAvatarService)m_userService;
78
79 }
80
81 }
82}
diff --git a/OpenSim/Region/Communications/Hypergrid/HGCommunicationsStandalone.cs b/OpenSim/Region/Communications/Hypergrid/HGCommunicationsStandalone.cs
new file mode 100644
index 0000000..2868b77
--- /dev/null
+++ b/OpenSim/Region/Communications/Hypergrid/HGCommunicationsStandalone.cs
@@ -0,0 +1,59 @@
1/**
2 * Copyright (c) 2008, Contributors. All rights reserved.
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without modification,
6 * are permitted provided that the following conditions are met:
7 *
8 * * Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13 * * Neither the name of the Organizations nor the names of Individual
14 * Contributors may be used to endorse or promote products derived from
15 * this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
20 * THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
21 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
22 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
23 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
24 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
25 * OF THE POSSIBILITY OF SUCH DAMAGE.
26 *
27 */
28
29
30using OpenSim.Framework;
31using OpenSim.Framework.Communications;
32using OpenSim.Framework.Communications.Cache;
33using OpenSim.Region.Communications.Local;
34using OpenSim.Framework.Servers;
35
36namespace OpenSim.Region.Communications.Hypergrid
37{
38 public class HGCommunicationsStandalone : CommunicationsLocal
39 {
40 public HGCommunicationsStandalone(
41 NetworkServersInfo serversInfo,
42 BaseHttpServer httpServer,
43 AssetCache assetCache,
44 IUserService userService,
45 IUserServiceAdmin userServiceAdmin,
46 LocalInventoryService inventoryService,
47 IInterRegionCommunications interRegionService,
48 HGGridServices gridService, IMessagingService messageService, LibraryRootFolder libraryRootFolder, bool dumpAssetsToFile)
49 : base(serversInfo, httpServer, assetCache, userService, userServiceAdmin, inventoryService, interRegionService, gridService, messageService, libraryRootFolder, dumpAssetsToFile)
50 {
51 gridService.UserProfileCache = m_userProfileCacheService;
52 m_assetCache = assetCache;
53 // Let's swap to always be secure access to inventory
54 AddSecureInventoryService((ISecureInventoryService)inventoryService);
55 m_inventoryServices = null;
56 }
57
58 }
59}
diff --git a/OpenSim/Region/Communications/Hypergrid/HGGridServices.cs b/OpenSim/Region/Communications/Hypergrid/HGGridServices.cs
new file mode 100644
index 0000000..5433e41
--- /dev/null
+++ b/OpenSim/Region/Communications/Hypergrid/HGGridServices.cs
@@ -0,0 +1,1294 @@
1/**
2 * Copyright (c) 2008, Contributors. All rights reserved.
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without modification,
6 * are permitted provided that the following conditions are met:
7 *
8 * * Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13 * * Neither the name of the Organizations nor the names of Individual
14 * Contributors may be used to endorse or promote products derived from
15 * this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
20 * THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
21 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
22 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
23 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
24 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
25 * OF THE POSSIBILITY OF SUCH DAMAGE.
26 *
27 */
28
29
30using System;
31using System.Collections;
32using System.Collections.Generic;
33using System.Drawing;
34using System.Drawing.Drawing2D;
35using System.Drawing.Imaging;
36using System.IO;
37using System.Net;
38using System.Net.Sockets;
39using System.Reflection;
40using System.Runtime.Remoting;
41using System.Runtime.Remoting.Channels;
42using System.Runtime.Remoting.Channels.Tcp;
43using System.Security.Authentication;
44using System.Threading;
45using OpenMetaverse;
46using OpenMetaverse.Imaging;
47using log4net;
48using Nwc.XmlRpc;
49using OpenSim.Framework;
50using OpenSim.Framework.Communications;
51using OpenSim.Framework.Communications.Cache;
52using OpenSim.Framework.Servers;
53using OpenSim.Region.Communications.Local;
54using OpenSim.Region.Communications.OGS1;
55using OpenSim.Region.Environment.Modules.Framework;
56using OpenSim.Region.Environment.Scenes;
57using OpenSim.Region.Interfaces;
58
59namespace OpenSim.Region.Communications.Hypergrid
60{
61 /// <summary>
62 /// This class encapsulates the main hypergrid functions related to creating and managing
63 /// hyperlinks, as well as processing all the inter-region comms between a region and
64 /// an hyperlinked region.
65 /// </summary>
66 public class HGGridServices : IGridServices, IInterRegionCommunications, IHyperlink
67 {
68 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
69
70
71 public BaseHttpServer httpListener;
72 public NetworkServersInfo serversInfo;
73 public BaseHttpServer httpServer;
74
75 protected List<RegionInfo> m_regionsOnInstance = new List<RegionInfo>();
76
77 // Hyperlink regions are hyperlinks on the map
78 protected List<RegionInfo> m_hyperlinkRegions = new List<RegionInfo>();
79
80 // Known regions are home regions of visiting foreign users.
81 // They are not on the map as static hyperlinks. They are dynamic hyperlinks, they go away when
82 // the visitor goes away. They are mapped to X=0 on the map.
83 // This is key-ed on agent ID
84 protected Dictionary<UUID, RegionInfo> m_knownRegions = new Dictionary<UUID, RegionInfo>();
85
86 protected AssetCache m_assetcache;
87 protected UserProfileCacheService m_userProfileCache;
88 protected SceneManager m_sceneman;
89
90 private Dictionary<string, string> m_queuedGridSettings = new Dictionary<string, string>();
91
92 public virtual string gdebugRegionName
93 {
94 get { return "Override me"; }
95 set { ; }
96 }
97
98 public string rdebugRegionName
99 {
100 get { return _rdebugRegionName; }
101 set { _rdebugRegionName = value; }
102 }
103 private string _rdebugRegionName = String.Empty;
104
105 public virtual bool RegionLoginsEnabled
106 {
107 get { return true; }
108 set { ; }
109 }
110
111 public UserProfileCacheService UserProfileCache
112 {
113 set { m_userProfileCache = value; }
114 }
115
116 /// <summary>
117 /// Contructor. Adds "expect_hg_user" and "check" xmlrpc method handlers
118 /// </summary>
119 /// <param name="servers_info"></param>
120 /// <param name="httpServe"></param>
121 public HGGridServices(NetworkServersInfo servers_info, BaseHttpServer httpServe, AssetCache asscache, SceneManager sman)
122 {
123 serversInfo = servers_info;
124 httpServer = httpServe;
125 m_assetcache = asscache;
126 m_sceneman = sman;
127
128 httpServer.AddXmlRPCHandler("link_region", LinkRegionRequest);
129 httpServer.AddXmlRPCHandler("expect_hg_user", ExpectHGUser);
130
131 HGNetworkServersInfo.Init(servers_info.AssetURL, servers_info.InventoryURL, servers_info.UserURL);
132 }
133
134 // see IGridServices
135 public virtual RegionCommsListener RegisterRegion(RegionInfo regionInfo)
136 {
137 // Region doesn't exist here. Trying to link remote region
138
139 m_log.Info("[HGrid]: Linking remote region " + regionInfo.ExternalHostName + ":" + regionInfo.HttpPort );
140 regionInfo.RegionID = LinkRegion(regionInfo); // UUID.Random();
141 if (!regionInfo.RegionID.Equals(UUID.Zero))
142 {
143 m_hyperlinkRegions.Add(regionInfo);
144 m_log.Info("[HGrid]: Successfully linked to region_uuid " + regionInfo.RegionID);
145
146 //Try get the map image
147 GetMapImage(regionInfo);
148 }
149 else
150 {
151 m_log.Info("[HGrid]: No such region " + regionInfo.ExternalHostName + ":" + regionInfo.HttpPort + "(" + regionInfo.InternalEndPoint.Port + ")");
152 }
153 // Note that these remote regions aren't registered in localBackend, so return null, no local listeners
154 return null;
155 }
156
157 // see IGridServices
158 public virtual bool DeregisterRegion(RegionInfo regionInfo)
159 {
160 if (m_hyperlinkRegions.Contains(regionInfo))
161 {
162 m_hyperlinkRegions.Remove(regionInfo);
163 return true;
164 }
165 foreach (KeyValuePair<UUID, RegionInfo> kvp in m_knownRegions)
166 {
167 if (kvp.Value == regionInfo)
168 {
169 m_knownRegions.Remove(kvp.Key);
170 return true;
171 }
172 }
173 return false;
174 }
175
176 public virtual Dictionary<string, string> GetGridSettings()
177 {
178 Dictionary<string, string> returnGridSettings = new Dictionary<string, string>();
179 lock (m_queuedGridSettings)
180 {
181 foreach (string Dictkey in m_queuedGridSettings.Keys)
182 {
183 returnGridSettings.Add(Dictkey, m_queuedGridSettings[Dictkey]);
184 }
185
186 m_queuedGridSettings.Clear();
187 }
188
189 return returnGridSettings;
190 }
191
192 // see IGridServices
193 public virtual List<SimpleRegionInfo> RequestNeighbours(uint x, uint y)
194 {
195 List<SimpleRegionInfo> neighbours = new List<SimpleRegionInfo>();
196 foreach (RegionInfo reg in m_hyperlinkRegions)
197 {
198 if (reg.RegionLocX != x || reg.RegionLocY != y)
199 {
200 //Console.WriteLine("CommsManager- RequestNeighbours() - found a different region in list, checking location");
201 if ((reg.RegionLocX > (x - 2)) && (reg.RegionLocX < (x + 2)))
202 {
203 if ((reg.RegionLocY > (y - 2)) && (reg.RegionLocY < (y + 2)))
204 {
205 neighbours.Add(reg);
206 }
207 }
208 }
209 }
210
211 return neighbours;
212 }
213
214 /// <summary>
215 /// Request information about a region.
216 /// </summary>
217 /// <param name="regionHandle"></param>
218 /// <returns>
219 /// null on a failure to contact or get a response from the grid server
220 /// FIXME: Might be nicer to return a proper exception here since we could inform the client more about the
221 /// nature of the faiulre.
222 /// </returns>
223 public virtual RegionInfo RequestNeighbourInfo(UUID Region_UUID)
224 {
225 foreach (RegionInfo info in m_hyperlinkRegions)
226 {
227 if (info.RegionID == Region_UUID) return info;
228 }
229
230 // I don't trust region uuids to be unique...
231 //foreach (RegionInfo info in m_knownRegions.Values)
232 //{
233 // if (info.RegionID == Region_UUID) return info;
234 //}
235
236 return null;
237 }
238
239 /// <summary>
240 /// Request information about a region.
241 /// </summary>
242 /// <param name="regionHandle"></param>
243 /// <returns></returns>
244 public virtual RegionInfo RequestNeighbourInfo(ulong regionHandle)
245 {
246 //Console.WriteLine("RequestNeighbourInfo for " + regionHandle);
247 foreach (RegionInfo info in m_hyperlinkRegions)
248 {
249 //Console.WriteLine(" .. " + info.RegionHandle);
250 if (info.RegionHandle == regionHandle) return info;
251 }
252
253 foreach (RegionInfo info in m_knownRegions.Values)
254 {
255 if (info.RegionHandle == regionHandle)
256 {
257 //Console.WriteLine("XXX------ Found known region " + info.RegionHandle);
258 return info;
259 }
260 }
261
262 return null;
263 }
264
265 public virtual RegionInfo RequestClosestRegion(string regionName)
266 {
267 foreach (RegionInfo info in m_hyperlinkRegions)
268 {
269 if (info.RegionName == regionName) return info;
270 }
271
272 return null;
273 }
274
275 /// <summary>
276 ///
277 /// </summary>
278 /// <param name="minX"></param>
279 /// <param name="minY"></param>
280 /// <param name="maxX"></param>
281 /// <param name="maxY"></param>
282 /// <returns></returns>
283 public virtual List<MapBlockData> RequestNeighbourMapBlocks(int minX, int minY, int maxX, int maxY)
284 {
285 List<MapBlockData> neighbours = new List<MapBlockData>();
286
287 foreach (RegionInfo regInfo in m_hyperlinkRegions)
288 {
289 if (((regInfo.RegionLocX >= minX) && (regInfo.RegionLocX <= maxX)) &&
290 ((regInfo.RegionLocY >= minY) && (regInfo.RegionLocY <= maxY)))
291 {
292 MapBlockData map = new MapBlockData();
293 map.Name = regInfo.RegionName;
294 map.X = (ushort)regInfo.RegionLocX;
295 map.Y = (ushort)regInfo.RegionLocY;
296 map.WaterHeight = (byte)regInfo.RegionSettings.WaterHeight;
297 map.MapImageId = regInfo.RegionSettings.TerrainImageID;
298// Console.WriteLine("ImgID: " + map.MapImageId);
299 map.Agents = 1;
300 map.RegionFlags = 72458694;
301 map.Access = 13;
302 neighbours.Add(map);
303 }
304 }
305
306 return neighbours;
307 }
308
309
310 protected virtual void GetMapImage(RegionInfo info)
311 {
312 try
313 {
314 string regionimage = "regionImage" + info.RegionID.ToString();
315 regionimage = regionimage.Replace("-", "");
316
317 WebClient c = new WebClient();
318 string uri = "http://" + info.ExternalHostName + ":" + info.HttpPort + "/index.php?method=" + regionimage;
319 //Console.WriteLine("JPEG: " + uri);
320 c.DownloadFile(uri, info.RegionID.ToString() + ".jpg");
321 Bitmap m = new Bitmap(info.RegionID.ToString() + ".jpg");
322 //Console.WriteLine("Size: " + m.PhysicalDimension.Height + "-" + m.PhysicalDimension.Width);
323 byte[] imageData = OpenJPEG.EncodeFromImage(m, true);
324 AssetBase ass = new AssetBase(UUID.Random(), "region " + info.RegionID.ToString());
325 info.RegionSettings.TerrainImageID = ass.FullID;
326 ass.Type = (int)AssetType.Texture;
327 ass.Temporary = false;
328 //imageData.CopyTo(ass.Data, 0);
329 ass.Data = imageData;
330 m_assetcache.AddAsset(ass);
331
332 }
333 catch (Exception e) // LEGIT: Catching problems caused by OpenJPEG p/invoke
334 {
335 Console.WriteLine("Failed getting/storing map image: " + e);
336 }
337 }
338
339 // A little ugly, since this code is exactly the same as OSG1's, and we're already
340 // calling that for when the region in in grid mode... (for the grid regions)
341 //
342 public virtual LandData RequestLandData (ulong regionHandle, uint x, uint y)
343 {
344 m_log.DebugFormat("[HGrid]: requests land data in {0}, at {1}, {2}",
345 regionHandle, x, y);
346
347 // Remote region
348
349 Hashtable hash = new Hashtable();
350 hash["region_handle"] = regionHandle.ToString();
351 hash["x"] = x.ToString();
352 hash["y"] = y.ToString();
353
354 IList paramList = new ArrayList();
355 paramList.Add(hash);
356 LandData landData = null;
357
358 try
359 {
360 RegionInfo info = RequestNeighbourInfo(regionHandle);
361 if (info != null) // just to be sure
362 {
363 XmlRpcRequest request = new XmlRpcRequest("land_data", paramList);
364 string uri = "http://" + info.ExternalEndPoint.Address + ":" + info.HttpPort + "/";
365 XmlRpcResponse response = request.Send(uri, 10000);
366 if (response.IsFault)
367 {
368 m_log.ErrorFormat("[HGrid]: remote call returned an error: {0}", response.FaultString);
369 }
370 else
371 {
372 hash = (Hashtable)response.Value;
373 try
374 {
375 landData = new LandData();
376 landData.AABBMax = Vector3.Parse((string)hash["AABBMax"]);
377 landData.AABBMin = Vector3.Parse((string)hash["AABBMin"]);
378 landData.Area = Convert.ToInt32(hash["Area"]);
379 landData.AuctionID = Convert.ToUInt32(hash["AuctionID"]);
380 landData.Description = (string)hash["Description"];
381 landData.Flags = Convert.ToUInt32(hash["Flags"]);
382 landData.GlobalID = new UUID((string)hash["GlobalID"]);
383 landData.Name = (string)hash["Name"];
384 landData.OwnerID = new UUID((string)hash["OwnerID"]);
385 landData.SalePrice = Convert.ToInt32(hash["SalePrice"]);
386 landData.SnapshotID = new UUID((string)hash["SnapshotID"]);
387 landData.UserLocation = Vector3.Parse((string)hash["UserLocation"]);
388 m_log.DebugFormat("[HGrid]: Got land data for parcel {0}", landData.Name);
389 }
390 catch (Exception e)
391 {
392 m_log.Error("[HGrid]: Got exception while parsing land-data:", e);
393 }
394 }
395 }
396 else m_log.WarnFormat("[HGrid]: Couldn't find region with handle {0}", regionHandle);
397 }
398 catch (Exception e)
399 {
400 m_log.ErrorFormat("[HGrid]: Couldn't contact region {0}: {1}", regionHandle, e);
401 }
402
403 return landData;
404 }
405
406 // Grid Request Processing
407 public virtual List<RegionInfo> RequestNamedRegions (string name, int maxNumber)
408 {
409 List<RegionInfo> infos = new List<RegionInfo>();
410 foreach (RegionInfo info in m_hyperlinkRegions)
411 {
412 if (info.RegionName.ToLower().Contains(name))
413 {
414 infos.Add(info);
415 }
416 }
417 return infos;
418 }
419
420
421 private UUID LinkRegion(RegionInfo info)
422 {
423 UUID uuid = UUID.Zero;
424
425 Hashtable hash = new Hashtable();
426 hash["region_name"] = info.RegionName;
427
428 IList paramList = new ArrayList();
429 paramList.Add(hash);
430
431 XmlRpcRequest request = new XmlRpcRequest("link_region", paramList);
432 string uri = "http://" + info.ExternalEndPoint.Address + ":" + info.HttpPort + "/";
433 m_log.Debug("[HGrid]: Linking to " + uri);
434 XmlRpcResponse response = request.Send(uri, 10000);
435 if (response.IsFault)
436 {
437 m_log.ErrorFormat("[HGrid]: remote call returned an error: {0}", response.FaultString);
438 }
439 else
440 {
441 hash = (Hashtable)response.Value;
442 //foreach (Object o in hash)
443 // Console.WriteLine(">> " + ((DictionaryEntry)o).Key + ":" + ((DictionaryEntry)o).Value);
444 try
445 {
446 UUID.TryParse((string)hash["uuid"], out uuid);
447 info.RegionID = uuid;
448 if ((string)hash["handle"] != null)
449 {
450 info.regionSecret = (string)hash["handle"];
451 //Console.WriteLine(">> HERE: " + info.regionSecret);
452 }
453 if (hash["region_image"] != null)
454 {
455 UUID img = UUID.Zero;
456 UUID.TryParse((string)hash["region_image"], out img);
457 info.RegionSettings.TerrainImageID = img;
458 }
459 if (hash["region_name"] != null)
460 {
461 info.RegionName = (string)hash["region_name"];
462 }
463 if (hash["internal_port"] != null)
464 {
465 int port = Convert.ToInt32((string)hash["internal_port"]);
466 info.InternalEndPoint = new IPEndPoint(IPAddress.Parse("0.0.0.0"), port);
467 //Console.WriteLine(">> " + info.InternalEndPoint.ToString());
468 }
469 if (hash["remoting_port"] != null)
470 {
471 info.RemotingPort = Convert.ToUInt32(hash["remoting_port"]);
472 //Console.WriteLine(">> " + info.RemotingPort);
473 }
474
475 }
476 catch (Exception e)
477 {
478 m_log.Error("[HGrid]: Got exception while parsing hyperlink response " + e.StackTrace);
479 }
480 }
481 return uuid;
482 }
483
484 /// <summary>
485 /// Someone wants to link to us
486 /// </summary>
487 /// <param name="request"></param>
488 /// <returns></returns>
489 public XmlRpcResponse LinkRegionRequest(XmlRpcRequest request)
490 {
491 Hashtable requestData = (Hashtable)request.Params[0];
492 //string host = (string)requestData["host"];
493 //string portstr = (string)requestData["port"];
494 string name = (string)requestData["region_name"];
495
496 m_log.DebugFormat("[HGrid]: Hyperlink request");
497
498
499 RegionInfo regInfo = null;
500 foreach (RegionInfo r in m_regionsOnInstance)
501 {
502 if ((r.RegionName != null) && (name != null) && (r.RegionName.ToLower() == name.ToLower()))
503 {
504 regInfo = r;
505 break;
506 }
507 }
508
509 if (regInfo == null)
510 regInfo = m_regionsOnInstance[0]; // Send out the first region
511
512 Hashtable hash = new Hashtable();
513 hash["uuid"] = regInfo.RegionID.ToString();
514 hash["handle"] = regInfo.RegionHandle.ToString();
515 //Console.WriteLine(">> Here " + regInfo.RegionHandle);
516 hash["region_image"] = regInfo.RegionSettings.TerrainImageID.ToString();
517 hash["region_name"] = regInfo.RegionName;
518 hash["internal_port"] = regInfo.InternalEndPoint.Port.ToString();
519 hash["remoting_port"] = NetworkServersInfo.RemotingListenerPort.ToString();
520 //Console.WriteLine(">> Here: " + regInfo.InternalEndPoint.Port);
521
522
523 XmlRpcResponse response = new XmlRpcResponse();
524 response.Value = hash;
525 return response;
526 }
527
528 public bool InformRegionOfUser(RegionInfo regInfo, AgentCircuitData agentData)
529 {
530 ulong regionHandle = regInfo.RegionHandle;
531 try
532 {
533 regionHandle = Convert.ToUInt64(regInfo.regionSecret);
534 m_log.Info("[HGrid]: InformRegionOfUser: Remote hyperlinked region " + regInfo.regionSecret);
535 }
536 catch
537 {
538 m_log.Info("[HGrid]: InformRegionOfUser: Local grid region " + regInfo.regionSecret);
539 }
540
541 string capsPath = agentData.CapsPath;
542 Hashtable loginParams = new Hashtable();
543 loginParams["session_id"] = agentData.SessionID.ToString();
544 loginParams["secure_session_id"] = agentData.SecureSessionID.ToString();
545
546 loginParams["firstname"] = agentData.firstname;
547 loginParams["lastname"] = agentData.lastname;
548
549 loginParams["agent_id"] = agentData.AgentID.ToString();
550 loginParams["circuit_code"] = agentData.circuitcode.ToString();
551 loginParams["startpos_x"] = agentData.startpos.X.ToString();
552 loginParams["startpos_y"] = agentData.startpos.Y.ToString();
553 loginParams["startpos_z"] = agentData.startpos.Z.ToString();
554 loginParams["caps_path"] = capsPath;
555
556 CachedUserInfo u = m_userProfileCache.GetUserDetails(agentData.AgentID);
557 if (u != null && u.UserProfile != null)
558 {
559 loginParams["region_uuid"] = u.UserProfile.HomeRegionID.ToString(); // This seems to be always Zero
560 //Console.WriteLine(" --------- Home Region UUID -------");
561 //Console.WriteLine(" >> " + loginParams["region_uuid"] + " <<");
562 //Console.WriteLine(" --------- ---------------- -------");
563
564 string serverURI = "";
565 if (u.UserProfile is ForeignUserProfileData)
566 serverURI = HGNetworkServersInfo.ServerURI(((ForeignUserProfileData)u.UserProfile).UserServerURI);
567 loginParams["userserver_id"] = (serverURI == "") || (serverURI == null) ? HGNetworkServersInfo.Singleton.LocalUserServerURI : serverURI;
568
569 serverURI = HGNetworkServersInfo.ServerURI(u.UserProfile.UserAssetURI);
570 loginParams["assetserver_id"] = (serverURI == "") || (serverURI == null) ? HGNetworkServersInfo.Singleton.LocalAssetServerURI : serverURI;
571
572 serverURI = HGNetworkServersInfo.ServerURI(u.UserProfile.UserInventoryURI);
573 loginParams["inventoryserver_id"] = (serverURI == "") || (serverURI == null) ? HGNetworkServersInfo.Singleton.LocalInventoryServerURI : serverURI;
574
575 loginParams["root_folder_id"] = u.UserProfile.RootInventoryFolderID;
576
577 RegionInfo rinfo = RequestNeighbourInfo(u.UserProfile.HomeRegion);
578 if (rinfo != null)
579 {
580 loginParams["internal_port"] = rinfo.InternalEndPoint.Port.ToString();
581 if (!IsLocalUser(u))
582 {
583 loginParams["regionhandle"] = rinfo.regionSecret; // user.CurrentAgent.Handle.ToString();
584 //Console.WriteLine("XXX--- informregionofuser (foreign user) here handle: " + rinfo.regionSecret);
585
586 loginParams["home_address"] = ((ForeignUserProfileData)(u.UserProfile)).UserHomeAddress;
587 loginParams["home_port"] = ((ForeignUserProfileData)(u.UserProfile)).UserHomePort;
588 loginParams["home_remoting"] = ((ForeignUserProfileData)(u.UserProfile)).UserHomeRemotingPort;
589 }
590 else
591 {
592 //Console.WriteLine("XXX--- informregionofuser (local user) here handle: " + rinfo.regionSecret);
593
594 //// local user about to jump out, let's process the name
595 // On second thoughts, let's not do this for the *user*; let's only do it for the *agent*
596 //loginParams["firstname"] = agentData.firstname + "." + agentData.lastname;
597 //loginParams["lastname"] = serversInfo.UserURL;
598
599 // local user, first time out. let's ask the grid about this user's home region
600 loginParams["regionhandle"] = u.UserProfile.HomeRegion.ToString(); // user.CurrentAgent.Handle.ToString();
601
602 loginParams["home_address"] = rinfo.ExternalHostName;
603 Console.WriteLine(" --------- Home Address -------");
604 Console.WriteLine(" >> " + loginParams["home_address"] + " <<");
605 Console.WriteLine(" --------- ------------ -------");
606 loginParams["home_port"] = rinfo.HttpPort.ToString();
607 loginParams["home_remoting"] = NetworkServersInfo.RemotingListenerPort.ToString(); ;
608 }
609 }
610 else
611 {
612 m_log.Warn("[HGrid]: User's home region info not found: " + u.UserProfile.HomeRegionX + ", " + u.UserProfile.HomeRegionY);
613 }
614 }
615
616 ArrayList SendParams = new ArrayList();
617 SendParams.Add(loginParams);
618
619 // Send
620 string uri = "http://" + regInfo.ExternalHostName + ":" + regInfo.HttpPort + "/";
621 //Console.WriteLine("XXX uri: " + uri);
622 XmlRpcRequest request = new XmlRpcRequest("expect_hg_user", SendParams);
623 XmlRpcResponse reply = request.Send(uri, 6000);
624
625 if (!reply.IsFault)
626 {
627 bool responseSuccess = true;
628 if (reply.Value != null)
629 {
630 Hashtable resp = (Hashtable)reply.Value;
631 if (resp.ContainsKey("success"))
632 {
633 if ((string)resp["success"] == "FALSE")
634 {
635 responseSuccess = false;
636 }
637 }
638 }
639 if (responseSuccess)
640 {
641 m_log.Info("[HGrid]: Successfully informed remote region about user " + agentData.AgentID);
642 return true;
643 }
644 else
645 {
646 m_log.ErrorFormat("[HGrid]: Region responded that it is not available to receive clients");
647 return false;
648 }
649 }
650 else
651 {
652 m_log.ErrorFormat("[HGrid]: XmlRpc request to region failed with message {0}, code {1} ", reply.FaultString, reply.FaultCode);
653 return false;
654 }
655 }
656
657
658 /// <summary>
659 /// Received from other HGrid nodes when a user wants to teleport here. This call allows
660 /// the region to prepare for direct communication from the client. Sends back an empty
661 /// xmlrpc response on completion.
662 /// This is somewhat similar to OGS1's ExpectUser, but with the additional task of
663 /// registering the user in the local user cache.
664 /// </summary>
665 /// <param name="request"></param>
666 /// <returns></returns>
667 public XmlRpcResponse ExpectHGUser(XmlRpcRequest request)
668 {
669 Hashtable requestData = (Hashtable)request.Params[0];
670 ForeignUserProfileData userData = new ForeignUserProfileData();
671
672 userData.FirstName = (string)requestData["firstname"];
673 userData.SurName = (string)requestData["lastname"];
674 userData.ID = new UUID((string)requestData["agent_id"]);
675 userData.HomeLocation = new Vector3((float)Convert.ToDecimal((string)requestData["startpos_x"]),
676 (float)Convert.ToDecimal((string)requestData["startpos_y"]),
677 (float)Convert.ToDecimal((string)requestData["startpos_z"]));
678
679 userData.UserServerURI = (string)requestData["userserver_id"];
680 userData.UserAssetURI = (string)requestData["assetserver_id"];
681 userData.UserInventoryURI = (string)requestData["inventoryserver_id"];
682
683 UUID rootID = UUID.Zero;
684 UUID.TryParse((string)requestData["root_folder_id"], out rootID);
685 userData.RootInventoryFolderID = rootID;
686
687 UUID uuid = UUID.Zero;
688 UUID.TryParse((string)requestData["region_uuid"], out uuid);
689 userData.HomeRegionID = uuid; // not quite comfortable about this...
690 ulong userRegionHandle = Convert.ToUInt64((string)requestData["regionhandle"]);
691 //userData.HomeRegion = userRegionHandle;
692 userData.UserHomeAddress = (string)requestData["home_address"];
693 userData.UserHomePort = (string)requestData["home_port"];
694 int userhomeinternalport = Convert.ToInt32((string)requestData["internal_port"]);
695 userData.UserHomeRemotingPort = (string)requestData["home_remoting"];
696
697
698 m_log.DebugFormat("[HGrid]: Told by user service to prepare for a connection from {0} {1} {2}",
699 userData.FirstName, userData.SurName, userData.ID);
700 m_log.Debug("[HGrid]: home_address: " + userData.UserHomeAddress +
701 "; home_port: " + userData.UserHomePort + "; remoting: " + userData.UserHomeRemotingPort);
702
703
704 XmlRpcResponse resp = new XmlRpcResponse();
705
706 if (!RegionLoginsEnabled)
707 {
708 m_log.InfoFormat(
709 "[HGrid]: Denying access for user {0} {1} because region login is currently disabled",
710 userData.FirstName, userData.SurName);
711
712 Hashtable respdata = new Hashtable();
713 respdata["success"] = "FALSE";
714 respdata["reason"] = "region login currently disabled";
715 resp.Value = respdata;
716 }
717 else
718 {
719 RegionInfo[] regions = m_regionsOnInstance.ToArray();
720 //bool banned = false;
721 // Just check one region. We assume they all belong to the same estate.
722 if ((regions.Length > 0) && (regions[0].EstateSettings.IsBanned(userData.ID)))
723 {
724 m_log.InfoFormat(
725 "[HGrid]: Denying access for user {0} {1} because user is banned",
726 userData.FirstName, userData.SurName);
727
728 Hashtable respdata = new Hashtable();
729 respdata["success"] = "FALSE";
730 respdata["reason"] = "banned";
731 resp.Value = respdata;
732 }
733 else
734 {
735 // Finally, everything looks ok
736 //Console.WriteLine("XXX---- EVERYTHING OK ---XXX");
737
738 // Nope, let's do it only for the *agent*
739 //// 0 - Switch name if necessary
740 //if (IsComingHome(userData))
741 //{
742 // string[] parts = userData.FirstName.Split( new char[] {'.'});
743 // if (parts.Length >= 1)
744 // userData.FirstName = parts[0];
745 // if (parts.Length == 2)
746 // userData.SurName = parts[1];
747 // else
748 // m_log.Warn("[HGrid]: Something fishy with user " + userData.FirstName + userData.SurName);
749
750 // m_log.Info("[HGrid]: Welcome home, " + userData.FirstName + " " + userData.SurName);
751 //}
752
753 // 1 - Preload the user data
754 m_userProfileCache.PreloadUserCache(userData.ID, userData);
755
756 // 2 - Load the region info into list of known regions
757 RegionInfo rinfo = new RegionInfo();
758 rinfo.RegionID = userData.HomeRegionID;
759 rinfo.ExternalHostName = userData.UserHomeAddress;
760 rinfo.HttpPort = Convert.ToUInt32(userData.UserHomePort);
761 rinfo.RemotingPort = Convert.ToUInt32(userData.UserHomeRemotingPort);
762 rinfo.RegionID = userData.HomeRegionID;
763 // X=0 on the map
764 rinfo.RegionLocX = 0;
765 rinfo.RegionLocY = (uint)m_knownRegions.Count;
766 rinfo.regionSecret = userRegionHandle.ToString();
767 //Console.WriteLine("XXX--- Here: handle = " + rinfo.regionSecret);
768 try
769 {
770 rinfo.InternalEndPoint = new IPEndPoint(IPAddress.Parse("0.0.0.0"), (int)userhomeinternalport);
771 }
772 catch (Exception e)
773 {
774 m_log.Warn("[HGrid]: Exception while constructing internal endpoint: " + e);
775 }
776 rinfo.RemotingAddress = rinfo.ExternalEndPoint.Address.ToString(); //userData.UserHomeAddress;
777
778 if (!IsComingHome(userData))
779 {
780 // Change the user's home region here!!!
781 userData.HomeRegion = rinfo.RegionHandle;
782 }
783
784 if (!m_knownRegions.ContainsKey(userData.ID))
785 m_knownRegions.Add(userData.ID, rinfo);
786 else
787 // just update it. The previous one was left there when the user departed
788 m_knownRegions[userData.ID] = rinfo;
789
790 // 3 - Send the reply
791 Hashtable respdata = new Hashtable();
792 respdata["success"] = "TRUE";
793 resp.Value = respdata;
794
795 DumpUserData(userData);
796 DumpRegionData(rinfo);
797 }
798 }
799
800 return resp;
801 }
802
803 #region IInterRegionCommunications interface
804
805 public virtual bool AcknowledgeAgentCrossed(ulong regionHandle, UUID agentId) { return false; }
806 public virtual bool AcknowledgePrimCrossed(ulong regionHandle, UUID primID) { return false; }
807 public virtual bool CheckRegion(string address, uint port) { return false; }
808 public virtual bool ChildAgentUpdate(ulong regionHandle, ChildAgentDataUpdate cAgentData) { return false; }
809
810 public virtual bool ExpectAvatarCrossing(ulong regionHandle, UUID agentID, Vector3 position, bool isFlying) {
811 // Remote region
812 RegionInfo regInfo = null;
813 ulong remoteHandle = 0;
814 try
815 {
816 regInfo = RequestNeighbourInfo(regionHandle);
817 if (regInfo != null)
818 {
819 try
820 {
821 remoteHandle = Convert.ToUInt64(regInfo.regionSecret);
822 }
823 catch
824 {
825 m_log.Warn("[HGrid]: Invalid remote region with handle " + regInfo.regionSecret);
826 return false;
827 }
828 //Console.WriteLine("XXX---- Sending Expectavatarcrossing into : " + remoteHandle);
829
830 bool retValue = false;
831 OGS1InterRegionRemoting remObject = (OGS1InterRegionRemoting)Activator.GetObject(
832 typeof(OGS1InterRegionRemoting),
833 "tcp://" + regInfo.RemotingAddress +
834 ":" + regInfo.RemotingPort +
835 "/InterRegions");
836
837 if (remObject != null)
838 {
839 retValue =
840 remObject.ExpectAvatarCrossing(remoteHandle, agentID.Guid, new sLLVector3(position),
841 isFlying);
842 }
843 else
844 {
845 m_log.Warn("[HGrid]: Remoting object not found");
846 }
847 remObject = null;
848
849 return retValue;
850 }
851 //TODO need to see if we know about where this region is and use .net remoting
852 // to inform it.
853 //NoteDeadRegion(regionHandle);
854 return false;
855 }
856 catch (RemotingException e)
857 {
858// NoteDeadRegion(regionHandle);
859
860 m_log.WarnFormat(
861 "[HGrid]: Remoting Error: Unable to connect to adjacent region: {0} {1},{2}",
862 regInfo.RegionName, regInfo.RegionLocX, regInfo.RegionLocY);
863 m_log.DebugFormat("[HGrid]: {0} {1}", e.Source, e.Message);
864
865 return false;
866 }
867 catch
868 {
869// NoteDeadRegion(regionHandle);
870 return false;
871 }
872
873 }
874
875 public virtual bool ExpectPrimCrossing(ulong regionHandle, UUID primID, Vector3 position, bool isFlying) { return false; }
876
877 public virtual bool InformRegionOfChildAgent(ulong regionHandle, AgentCircuitData agentData)
878 {
879 // If we're here, it's because regionHandle is a remote, non-grided region
880 m_log.Info("[HGrid]: InformRegionOfChildAgent for " + regionHandle);
881
882 RegionInfo regInfo = GetHyperlinkRegion(regionHandle);
883 if (regInfo == null)
884 return false;
885
886 ulong realHandle = regionHandle;
887
888 CachedUserInfo uinfo = m_userProfileCache.GetUserDetails(agentData.AgentID);
889 if ((uinfo == null) || !IsGoingHome(uinfo, regInfo))
890 {
891 m_log.Info("[HGrid]: User seems to be going to foreign region " + uinfo.UserProfile.FirstName + " " + uinfo.UserProfile.SurName);
892 if (!InformRegionOfUser(regInfo, agentData))
893 {
894 m_log.Warn("[HGrid]: Could not inform remote region of transferring user.");
895 return false;
896 }
897 }
898 else
899 m_log.Info("[HGrid]: User seems to be going home " + uinfo.UserProfile.FirstName + " " + uinfo.UserProfile.SurName);
900
901 try
902 {
903 // ... and then
904
905 m_log.Debug("[HGrid]: Region is hyperlink.");
906 bool retValue = false;
907 try
908 {
909 regionHandle = Convert.ToUInt64(regInfo.regionSecret);
910 }
911 catch (Exception)
912 {
913 m_log.Warn("[HGrid]: Invalid hyperlink region.");
914 return false;
915 }
916
917 OGS1InterRegionRemoting remObject = (OGS1InterRegionRemoting)Activator.GetObject(
918 typeof(OGS1InterRegionRemoting),
919 "tcp://" + regInfo.RemotingAddress +
920 ":" + regInfo.RemotingPort +
921 "/InterRegions");
922
923 if (remObject != null)
924 {
925 sAgentCircuitData sag = new sAgentCircuitData(agentData);
926 // May need to change agent's name
927 if (IsLocalUser(uinfo))
928 {
929 sag.firstname = agentData.firstname + "." + agentData.lastname;
930 sag.lastname = serversInfo.UserURL; //HGNetworkServersInfo.Singleton.LocalUserServerURI;
931 }
932 retValue = remObject.InformRegionOfChildAgent(regionHandle, sag);
933 }
934 else
935 {
936 m_log.Warn("[HGrid]: remoting object not found");
937 }
938 remObject = null;
939 m_log.Info("[HGrid]: tried to InformRegionOfChildAgent for " +
940 agentData.firstname + " " + agentData.lastname + " and got " +
941 retValue.ToString());
942
943 // Remove the info from this region
944 if (m_knownRegions.ContainsKey(uinfo.UserProfile.ID))
945 m_knownRegions.Remove(uinfo.UserProfile.ID);
946
947 return retValue;
948 }
949 catch (RemotingException e)
950 {
951 //NoteDeadRegion(regionHandle);
952
953 m_log.WarnFormat(
954 "[HGrid]: Remoting Error: Unable to connect to adjacent region: {0} {1},{2}",
955 regInfo.RegionName, regInfo.RegionLocX, regInfo.RegionLocY);
956 m_log.DebugFormat("[HGrid]: {0} {1}", e.Source, e.Message);
957
958 return false;
959 }
960 catch (SocketException e)
961 {
962 //NoteDeadRegion(regionHandle);
963
964 m_log.WarnFormat(
965 "[HGrid]: Remoting Error: Unable to connect to adjacent region: {0} {1},{2}",
966 regInfo.RegionName, regInfo.RegionLocX, regInfo.RegionLocY);
967 m_log.DebugFormat("[HGrid]: {0} {1}", e.Source, e.Message);
968
969 return false;
970 }
971 catch (InvalidCredentialException e)
972 {
973 //NoteDeadRegion(regionHandle);
974
975 m_log.WarnFormat(
976 "[HGrid]: Remoting Error: Unable to connect to adjacent region: {0} {1},{2}",
977 regInfo.RegionName, regInfo.RegionLocX, regInfo.RegionLocY);
978 m_log.DebugFormat("[HGrid]: {0} {1}", e.Source, e.Message);
979
980 return false;
981 }
982 catch (AuthenticationException e)
983 {
984 //NoteDeadRegion(regionHandle);
985
986 m_log.WarnFormat(
987 "[HGrid]: Remoting Error: Unable to connect to adjacent region: {0} {1},{2}",
988 regInfo.RegionName, regInfo.RegionLocX, regInfo.RegionLocY);
989 m_log.DebugFormat("[HGrid]: {0} {1}", e.Source, e.Message);
990
991 return false;
992 }
993 catch (Exception e)
994 {
995 //NoteDeadRegion(regionHandle);
996
997 if (regInfo != null)
998 {
999 m_log.WarnFormat(
1000 "[HGrid]: Remoting Error: Unable to connect to adjacent region: {0} {1},{2}",
1001 regInfo.RegionName, regInfo.RegionLocX, regInfo.RegionLocY);
1002 }
1003 m_log.DebugFormat("[HGrid]: {0} {1}", e.Source, e.Message);
1004
1005 return false;
1006 }
1007
1008
1009 }
1010
1011 public virtual bool InformRegionOfPrimCrossing(ulong regionHandle, UUID primID, string objData, int XMLMethod) { return false; }
1012
1013 public virtual bool RegionUp(SerializableRegionInfo region, ulong regionhandle) {
1014
1015 ulong realHandle = FindRegionHandle(regionhandle);
1016
1017 if (realHandle == regionhandle) // something wrong, not remote region
1018 return false;
1019
1020 SerializableRegionInfo regInfo = null;
1021 try
1022 {
1023 // You may ask why this is in here...
1024 // The region asking the grid services about itself..
1025 // And, surprisingly, the reason is.. it doesn't know
1026 // it's own remoting port! How special.
1027 RegionUpData regiondata = new RegionUpData(region.RegionLocX, region.RegionLocY, region.ExternalHostName, region.InternalEndPoint.Port);
1028
1029 region = new SerializableRegionInfo(RequestNeighbourInfo(realHandle));
1030 region.RemotingAddress = region.ExternalHostName;
1031 region.RemotingPort = NetworkServersInfo.RemotingListenerPort;
1032 region.HttpPort = serversInfo.HttpListenerPort;
1033
1034 regInfo = new SerializableRegionInfo(RequestNeighbourInfo(regionhandle));
1035 if (regInfo != null)
1036 {
1037 // If we're not trying to remote to ourselves.
1038 if (regInfo.RemotingAddress != region.RemotingAddress && region.RemotingAddress != null)
1039 {
1040 //don't want to be creating a new link to the remote instance every time like we are here
1041 bool retValue = false;
1042
1043 OGS1InterRegionRemoting remObject = (OGS1InterRegionRemoting)Activator.GetObject(
1044 typeof(OGS1InterRegionRemoting),
1045 "tcp://" +
1046 regInfo.RemotingAddress +
1047 ":" + regInfo.RemotingPort +
1048 "/InterRegions");
1049
1050 if (remObject != null)
1051 {
1052 retValue = remObject.RegionUp(regiondata, realHandle);
1053 }
1054 else
1055 {
1056 m_log.Warn("[HGrid]: remoting object not found");
1057 }
1058 remObject = null;
1059
1060 m_log.Info(
1061 "[HGrid]: tried to inform region I'm up");
1062
1063 return retValue;
1064 }
1065 else
1066 {
1067 // We're trying to inform ourselves via remoting.
1068 // This is here because we're looping over the listeners before we get here.
1069 // Odd but it should work.
1070 return true;
1071 }
1072 }
1073
1074 return false;
1075 }
1076 catch (RemotingException e)
1077 {
1078 m_log.Warn("[HGrid]: Remoting Error: Unable to connect to adjacent region using tcp://" +
1079 regInfo.RemotingAddress +
1080 ":" + regInfo.RemotingPort +
1081 "/InterRegions - @ " + regInfo.RegionLocX + "," + regInfo.RegionLocY +
1082 " - Is this neighbor up?");
1083 m_log.DebugFormat("[HGrid]: {0} {1}", e.Source, e.Message);
1084 return false;
1085 }
1086 catch (SocketException e)
1087 {
1088 m_log.Warn("[HGrid]: Socket Error: Unable to connect to adjacent region using tcp://" +
1089 regInfo.RemotingAddress +
1090 ":" + regInfo.RemotingPort +
1091 "/InterRegions - @ " + regInfo.RegionLocX + "," + regInfo.RegionLocY +
1092 " - Is this neighbor up?");
1093 m_log.DebugFormat("[HGrid]: {0} {1}", e.Source, e.Message);
1094 return false;
1095 }
1096 catch (InvalidCredentialException e)
1097 {
1098 m_log.Warn("[HGrid]: Invalid Credentials: Unable to connect to adjacent region using tcp://" +
1099 regInfo.RemotingAddress +
1100 ":" + regInfo.RemotingPort +
1101 "/InterRegions - @ " + regInfo.RegionLocX + "," + regInfo.RegionLocY);
1102 m_log.DebugFormat("[HGrid]: {0} {1}", e.Source, e.Message);
1103 return false;
1104 }
1105 catch (AuthenticationException e)
1106 {
1107 m_log.Warn("[HGrid]: Authentication exception: Unable to connect to adjacent region using tcp://" +
1108 regInfo.RemotingAddress +
1109 ":" + regInfo.RemotingPort +
1110 "/InterRegions - @ " + regInfo.RegionLocX + "," + regInfo.RegionLocY);
1111 m_log.DebugFormat("[HGrid]: {0} {1}", e.Source, e.Message);
1112 return false;
1113 }
1114 catch (Exception e)
1115 {
1116 m_log.Debug(e.ToString());
1117 return false;
1118 }
1119
1120 }
1121
1122 public virtual bool TellRegionToCloseChildConnection(ulong regionHandle, UUID agentID) { return false; }
1123
1124 public virtual List<UUID> InformFriendsInOtherRegion(UUID agentId, ulong destRegionHandle, List<UUID> friends, bool online)
1125 {
1126 return new List<UUID>();
1127 }
1128
1129 public virtual bool TriggerTerminateFriend(ulong regionHandle, UUID agentID, UUID exFriendID)
1130 {
1131 return true;
1132 }
1133
1134
1135 #endregion
1136
1137 #region Methods triggered by calls from external instances
1138
1139 /// <summary>
1140 ///
1141 /// </summary>
1142 /// <param name="regionHandle"></param>
1143 /// <param name="agentData"></param>
1144 /// <returns></returns>
1145 protected bool HGIncomingChildAgent(ulong regionHandle, AgentCircuitData agentData)
1146 {
1147 CachedUserInfo uinfo = m_userProfileCache.GetUserDetails(agentData.AgentID);
1148 if ((uinfo != null) && (uinfo.UserProfile != null) &&
1149 (IsLocalUser(uinfo) || !(uinfo.UserProfile is ForeignUserProfileData)))
1150 {
1151 //Console.WriteLine("---------------> Local User!");
1152 string[] parts = agentData.firstname.Split(new char[] { '.' });
1153 if (parts.Length == 2)
1154 {
1155 agentData.firstname = parts[0];
1156 agentData.lastname = parts[1];
1157 }
1158 }
1159 //else
1160 // Console.WriteLine("---------------> Foreign User!");
1161 return true;
1162 }
1163 #endregion
1164
1165
1166 #region IHyperGrid interface
1167
1168 public virtual bool IsHyperlinkRegion(ulong ihandle)
1169 {
1170 if (GetHyperlinkRegion(ihandle) == null)
1171 return false;
1172 else
1173 return true;
1174 }
1175
1176 public virtual RegionInfo GetHyperlinkRegion(ulong ihandle)
1177 {
1178 foreach (RegionInfo info in m_hyperlinkRegions)
1179 {
1180 if (info.RegionHandle == ihandle)
1181 return info;
1182 }
1183
1184 foreach (RegionInfo info in m_knownRegions.Values)
1185 {
1186 if (info.RegionHandle == ihandle)
1187 return info;
1188 }
1189
1190 return null;
1191 }
1192
1193 public virtual ulong FindRegionHandle(ulong ihandle)
1194 {
1195 long ohandle = -1;
1196 List<RegionInfo> rlist = new List<RegionInfo>(m_hyperlinkRegions);
1197 rlist.AddRange(m_knownRegions.Values);
1198 foreach (RegionInfo info in rlist)
1199 {
1200 if (info.RegionHandle == ihandle)
1201 {
1202 try
1203 {
1204 ohandle = Convert.ToInt64(info.regionSecret);
1205 m_log.Info("[HGrid] remote region " + ohandle);
1206 }
1207 catch
1208 {
1209 m_log.Error("[HGrid] Could not convert secret for " + ihandle + " (" + info.regionSecret + ")");
1210 }
1211 break;
1212 }
1213 }
1214 return ohandle < 0 ? ihandle : (ulong)ohandle;
1215 }
1216 #endregion
1217
1218 #region Misc
1219
1220 protected bool IsComingHome(ForeignUserProfileData userData)
1221 {
1222 return (userData.UserServerURI == HGNetworkServersInfo.Singleton.LocalUserServerURI);
1223 }
1224
1225 protected bool IsGoingHome(CachedUserInfo uinfo, RegionInfo rinfo)
1226 {
1227 if (uinfo.UserProfile == null)
1228 return false;
1229
1230 string userUserServerURI = String.Empty;
1231 if (uinfo.UserProfile is ForeignUserProfileData)
1232 {
1233 userUserServerURI = HGNetworkServersInfo.ServerURI(((ForeignUserProfileData)uinfo.UserProfile).UserServerURI);
1234 }
1235
1236 return ((uinfo.UserProfile.HomeRegionID == rinfo.RegionID) &&
1237 (userUserServerURI != HGNetworkServersInfo.Singleton.LocalUserServerURI));
1238 }
1239
1240 protected bool IsLocalUser(CachedUserInfo uinfo)
1241 {
1242 if (uinfo == null)
1243 return true;
1244
1245 if (uinfo.UserProfile is ForeignUserProfileData)
1246 return HGNetworkServersInfo.Singleton.IsLocalUser(((ForeignUserProfileData)uinfo.UserProfile).UserServerURI);
1247 else
1248 return true;
1249
1250 }
1251
1252 protected bool IsLocalRegion(ulong handle)
1253 {
1254 foreach (RegionInfo reg in m_regionsOnInstance)
1255 if (reg.RegionHandle == handle)
1256 return true;
1257 return false;
1258 }
1259
1260 private void DumpUserData(ForeignUserProfileData userData)
1261 {
1262 Console.WriteLine(" ------------ User Data Dump ----------");
1263 Console.WriteLine(" >> Name: " + userData.FirstName + " " + userData.SurName);
1264 Console.WriteLine(" >> HomeID: " + userData.HomeRegionID);
1265 Console.WriteLine(" >> HomeHandle: " + userData.HomeRegion);
1266 Console.WriteLine(" >> HomeX: " + userData.HomeRegionX);
1267 Console.WriteLine(" >> HomeY: " + userData.HomeRegionY);
1268 Console.WriteLine(" >> UserServer: " + userData.UserServerURI);
1269 Console.WriteLine(" >> InvServer: " + userData.UserInventoryURI);
1270 Console.WriteLine(" >> AssetServer: " + userData.UserAssetURI);
1271 Console.WriteLine(" ------------ -------------- ----------");
1272 }
1273
1274 private void DumpRegionData(RegionInfo rinfo)
1275 {
1276 Console.WriteLine(" ------------ Region Data Dump ----------");
1277 Console.WriteLine(" >> handle: " + rinfo.RegionHandle);
1278 Console.WriteLine(" >> coords: " + rinfo.RegionLocX + ", " + rinfo.RegionLocY);
1279 Console.WriteLine(" >> secret: " + rinfo.regionSecret);
1280 Console.WriteLine(" >> remoting address: " + rinfo.RemotingAddress);
1281 Console.WriteLine(" >> remoting port: " + rinfo.RemotingPort);
1282 Console.WriteLine(" >> external host name: " + rinfo.ExternalHostName);
1283 Console.WriteLine(" >> http port: " + rinfo.HttpPort);
1284 Console.WriteLine(" >> external EP address: " + rinfo.ExternalEndPoint.Address);
1285 Console.WriteLine(" >> external EP port: " + rinfo.ExternalEndPoint.Port);
1286 Console.WriteLine(" ------------ -------------- ----------");
1287 }
1288
1289
1290 #endregion
1291
1292
1293 }
1294}
diff --git a/OpenSim/Region/Communications/Hypergrid/HGGridServicesGridMode.cs b/OpenSim/Region/Communications/Hypergrid/HGGridServicesGridMode.cs
new file mode 100644
index 0000000..23258df
--- /dev/null
+++ b/OpenSim/Region/Communications/Hypergrid/HGGridServicesGridMode.cs
@@ -0,0 +1,285 @@
1/**
2 * Copyright (c) 2008, Contributors. All rights reserved.
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without modification,
6 * are permitted provided that the following conditions are met:
7 *
8 * * Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13 * * Neither the name of the Organizations nor the names of Individual
14 * Contributors may be used to endorse or promote products derived from
15 * this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
20 * THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
21 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
22 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
23 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
24 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
25 * OF THE POSSIBILITY OF SUCH DAMAGE.
26 *
27 */
28
29using System;
30using System.Collections.Generic;
31using System.Reflection;
32
33using OpenSim.Framework;
34using OpenSim.Framework.Communications;
35using OpenSim.Framework.Communications.Cache;
36using OpenSim.Framework.Servers;
37using OpenSim.Region.Communications.OGS1;
38using OpenSim.Region.Environment.Scenes;
39
40using OpenMetaverse;
41
42using log4net;
43
44namespace OpenSim.Region.Communications.Hypergrid
45{
46 public class HGGridServicesGridMode : HGGridServices
47 {
48 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
49
50 /// <summary>
51 /// Encapsulate remote backend services for manipulation of grid regions
52 /// </summary>
53 private OGS1GridServices m_remoteBackend = null;
54
55 public OGS1GridServices RemoteBackend
56 {
57 get { return m_remoteBackend; }
58 }
59
60
61 public override string gdebugRegionName
62 {
63 get { return m_remoteBackend.gdebugRegionName; }
64 set { m_remoteBackend.gdebugRegionName = value; }
65 }
66
67 public override bool RegionLoginsEnabled
68 {
69 get { return m_remoteBackend.RegionLoginsEnabled; }
70 set { m_remoteBackend.RegionLoginsEnabled = value; }
71 }
72
73 public HGGridServicesGridMode(NetworkServersInfo servers_info, BaseHttpServer httpServe,
74 AssetCache asscache, SceneManager sman, UserProfileCacheService userv)
75 : base(servers_info, httpServe, asscache, sman)
76 {
77 m_remoteBackend = new OGS1GridServices(servers_info, httpServe);
78 // Let's deregister this, so we can handle it here first
79 InterRegionSingleton.Instance.OnChildAgent -= m_remoteBackend.IncomingChildAgent;
80 InterRegionSingleton.Instance.OnChildAgent += IncomingChildAgent;
81 m_userProfileCache = userv;
82 }
83
84 #region IGridServices interface
85
86 public override RegionCommsListener RegisterRegion(RegionInfo regionInfo)
87 {
88 if (!regionInfo.RegionID.Equals(UUID.Zero))
89 {
90 m_regionsOnInstance.Add(regionInfo);
91 return m_remoteBackend.RegisterRegion(regionInfo);
92 }
93 else
94 return base.RegisterRegion(regionInfo);
95 }
96
97 public override bool DeregisterRegion(RegionInfo regionInfo)
98 {
99 bool success = m_remoteBackend.DeregisterRegion(regionInfo);
100 if (!success)
101 success = base.DeregisterRegion(regionInfo);
102 return success;
103 }
104
105 public override List<SimpleRegionInfo> RequestNeighbours(uint x, uint y)
106 {
107 List<SimpleRegionInfo> neighbours = m_remoteBackend.RequestNeighbours(x, y);
108 List<SimpleRegionInfo> remotes = base.RequestNeighbours(x, y);
109 neighbours.AddRange(remotes);
110
111 return neighbours;
112 }
113
114 public override RegionInfo RequestNeighbourInfo(UUID Region_UUID)
115 {
116 RegionInfo info = m_remoteBackend.RequestNeighbourInfo(Region_UUID);
117 if (info == null)
118 info = base.RequestNeighbourInfo(Region_UUID);
119 return info;
120 }
121
122 public override RegionInfo RequestNeighbourInfo(ulong regionHandle)
123 {
124 RegionInfo info = m_remoteBackend.RequestNeighbourInfo(regionHandle);
125 if (info == null)
126 info = base.RequestNeighbourInfo(regionHandle);
127 return info;
128 }
129
130 public override RegionInfo RequestClosestRegion(string regionName)
131 {
132 RegionInfo info = m_remoteBackend.RequestClosestRegion(regionName);
133 if (info == null)
134 info = base.RequestClosestRegion(regionName);
135 return info;
136 }
137
138 public override List<MapBlockData> RequestNeighbourMapBlocks(int minX, int minY, int maxX, int maxY)
139 {
140 List<MapBlockData> neighbours = m_remoteBackend.RequestNeighbourMapBlocks(minX, minY, maxX, maxY);
141 List<MapBlockData> remotes = base.RequestNeighbourMapBlocks(minX, minY, maxX, maxY);
142 neighbours.AddRange(remotes);
143
144 return neighbours;
145 }
146
147 public override LandData RequestLandData(ulong regionHandle, uint x, uint y)
148 {
149 LandData land = m_remoteBackend.RequestLandData(regionHandle, x, y);
150 if (land == null)
151 land = base.RequestLandData(regionHandle, x, y);
152 return land;
153 }
154
155 public override List<RegionInfo> RequestNamedRegions(string name, int maxNumber)
156 {
157 List<RegionInfo> infos = m_remoteBackend.RequestNamedRegions(name, maxNumber);
158 List<RegionInfo> remotes = base.RequestNamedRegions(name, maxNumber);
159 infos.AddRange(remotes);
160 return infos;
161 }
162
163 #endregion
164
165 #region IInterRegionCommunications interface
166
167 public override bool AcknowledgeAgentCrossed(ulong regionHandle, UUID agentId)
168 {
169 return m_remoteBackend.AcknowledgeAgentCrossed(regionHandle, agentId);
170 }
171
172 public override bool AcknowledgePrimCrossed(ulong regionHandle, UUID primID)
173 {
174 return m_remoteBackend.AcknowledgePrimCrossed(regionHandle, primID);
175 }
176
177 public override bool CheckRegion(string address, uint port)
178 {
179 return m_remoteBackend.CheckRegion(address, port);
180 }
181
182 public override bool ChildAgentUpdate(ulong regionHandle, ChildAgentDataUpdate cAgentData)
183 {
184 return m_remoteBackend.ChildAgentUpdate(regionHandle, cAgentData);
185 }
186
187 public override bool ExpectAvatarCrossing(ulong regionHandle, UUID agentID, Vector3 position, bool isFlying)
188 {
189 if (base.ExpectAvatarCrossing(regionHandle, agentID, position, isFlying))
190 return true;
191 return m_remoteBackend.ExpectAvatarCrossing(regionHandle, agentID, position, isFlying);
192 }
193
194 public override bool ExpectPrimCrossing(ulong regionHandle, UUID primID, Vector3 position, bool isFlying)
195 {
196 return m_remoteBackend.ExpectPrimCrossing(regionHandle, primID, position, isFlying);
197 }
198
199 public override bool InformRegionOfChildAgent(ulong regionHandle, AgentCircuitData agentData)
200 {
201 CachedUserInfo user = m_userProfileCache.GetUserDetails(agentData.AgentID);
202
203 if (IsLocalUser(user))
204 {
205 Console.WriteLine("XXX Home User XXX");
206 if (IsHyperlinkRegion(regionHandle))
207 {
208 Console.WriteLine("XXX Going Hyperlink XXX");
209 return base.InformRegionOfChildAgent(regionHandle, agentData);
210 }
211 else
212 {
213 // non-hypergrid case
214 Console.WriteLine("XXX Going local-grid region XXX");
215 return m_remoteBackend.InformRegionOfChildAgent(regionHandle, agentData);
216 }
217 }
218
219 // Foregin users
220 Console.WriteLine("XXX Foreign User XXX");
221 if (IsLocalRegion(regionHandle)) // regions on the same instance
222 {
223 Console.WriteLine("XXX Going onInstance region XXX");
224 return m_remoteBackend.InformRegionOfChildAgent(regionHandle, agentData);
225 }
226
227 if (IsHyperlinkRegion(regionHandle)) // hyperlinked regions
228 {
229 Console.WriteLine("XXX Going Hyperlink XXX");
230 return base.InformRegionOfChildAgent(regionHandle, agentData);
231 }
232 else
233 {
234 // foreign user going to a non-local region on the same grid
235 // We need to inform that region about this user before
236 // proceeding to the normal backend process.
237 Console.WriteLine("XXX Going local-grid region XXX");
238 RegionInfo regInfo = RequestNeighbourInfo(regionHandle);
239 if (regInfo != null)
240 InformRegionOfUser(regInfo, agentData);
241 return m_remoteBackend.InformRegionOfChildAgent(regionHandle, agentData);
242 }
243
244 }
245
246 public override bool InformRegionOfPrimCrossing(ulong regionHandle, UUID primID, string objData, int XMLMethod)
247 {
248 return m_remoteBackend.InformRegionOfPrimCrossing(regionHandle, primID, objData, XMLMethod);
249 }
250
251 public override bool RegionUp(SerializableRegionInfo region, ulong regionhandle)
252 {
253 if (m_remoteBackend.RegionUp(region, regionhandle))
254 return true;
255 return base.RegionUp(region, regionhandle);
256 }
257
258 public override bool TellRegionToCloseChildConnection(ulong regionHandle, UUID agentID)
259 {
260 return m_remoteBackend.TellRegionToCloseChildConnection(regionHandle, agentID);
261 }
262
263
264 #endregion
265
266 #region Methods triggered by calls from external instances
267
268 /// <summary>
269 ///
270 /// </summary>
271 /// <param name="regionHandle"></param>
272 /// <param name="agentData"></param>
273 /// <returns></returns>
274 public bool IncomingChildAgent(ulong regionHandle, AgentCircuitData agentData)
275 {
276 HGIncomingChildAgent(regionHandle, agentData);
277
278 m_log.Info("[HGrid]: Incoming HGrid Agent " + agentData.firstname + " " + agentData.lastname);
279
280 return m_remoteBackend.IncomingChildAgent(regionHandle, agentData);
281 }
282 #endregion
283
284 }
285}
diff --git a/OpenSim/Region/Communications/Hypergrid/HGGridServicesStandalone.cs b/OpenSim/Region/Communications/Hypergrid/HGGridServicesStandalone.cs
new file mode 100644
index 0000000..4dc26e0
--- /dev/null
+++ b/OpenSim/Region/Communications/Hypergrid/HGGridServicesStandalone.cs
@@ -0,0 +1,928 @@
1/**
2 * Copyright (c) 2008, Contributors. All rights reserved.
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without modification,
6 * are permitted provided that the following conditions are met:
7 *
8 * * Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13 * * Neither the name of the Organizations nor the names of Individual
14 * Contributors may be used to endorse or promote products derived from
15 * this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
20 * THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
21 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
22 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
23 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
24 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
25 * 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;
38
39using OpenSim.Framework;
40using OpenSim.Framework.Communications;
41using OpenSim.Framework.Communications.Cache;
42using OpenSim.Framework.Servers;
43using OpenSim.Region.Communications.Local;
44using OpenSim.Region.Communications.OGS1;
45using OpenSim.Region.Environment.Scenes;
46
47using OpenMetaverse;
48using Nwc.XmlRpc;
49using log4net;
50
51namespace OpenSim.Region.Communications.Hypergrid
52{
53 public class HGGridServicesStandalone : HGGridServices
54 {
55 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
56
57 /// <summary>
58 /// Encapsulate local backend services for manipulation of local regions
59 /// </summary>
60 protected LocalBackEndServices m_localBackend = new LocalBackEndServices();
61
62 private Dictionary<ulong, int> m_deadRegionCache = new Dictionary<ulong, int>();
63
64 public LocalBackEndServices LocalBackend
65 {
66 get { return m_localBackend; }
67 }
68
69 public override string gdebugRegionName
70 {
71 get { return m_localBackend.gdebugRegionName; }
72 set { m_localBackend.gdebugRegionName = value; }
73 }
74
75 public override bool RegionLoginsEnabled
76 {
77 get { return m_localBackend.RegionLoginsEnabled; }
78 set { m_localBackend.RegionLoginsEnabled = value; }
79 }
80
81
82 public HGGridServicesStandalone(NetworkServersInfo servers_info, BaseHttpServer httpServe, AssetCache asscache, SceneManager sman)
83 : base(servers_info, httpServe, asscache, sman)
84 {
85 //Respond to Grid Services requests
86 httpServer.AddXmlRPCHandler("logoff_user", LogOffUser);
87 httpServer.AddXmlRPCHandler("check", PingCheckReply);
88 httpServer.AddXmlRPCHandler("land_data", LandData);
89
90 StartRemoting();
91 }
92
93 #region IGridServices interface
94
95 public override RegionCommsListener RegisterRegion(RegionInfo regionInfo)
96 {
97 if (!regionInfo.RegionID.Equals(UUID.Zero))
98 {
99 m_regionsOnInstance.Add(regionInfo);
100 return m_localBackend.RegisterRegion(regionInfo);
101 }
102 else
103 return base.RegisterRegion(regionInfo);
104
105 }
106
107 public override bool DeregisterRegion(RegionInfo regionInfo)
108 {
109 bool success = m_localBackend.DeregisterRegion(regionInfo);
110 if (!success)
111 success = base.DeregisterRegion(regionInfo);
112 return success;
113 }
114
115 public override List<SimpleRegionInfo> RequestNeighbours(uint x, uint y)
116 {
117 List<SimpleRegionInfo> neighbours = m_localBackend.RequestNeighbours(x, y);
118 List<SimpleRegionInfo> remotes = base.RequestNeighbours(x, y);
119 neighbours.AddRange(remotes);
120
121 return neighbours;
122 }
123
124 public override RegionInfo RequestNeighbourInfo(UUID Region_UUID)
125 {
126 RegionInfo info = m_localBackend.RequestNeighbourInfo(Region_UUID);
127 if (info == null)
128 info = base.RequestNeighbourInfo(Region_UUID);
129 return info;
130 }
131
132 public override RegionInfo RequestNeighbourInfo(ulong regionHandle)
133 {
134 RegionInfo info = m_localBackend.RequestNeighbourInfo(regionHandle);
135 //m_log.Info("[HGrid] Request neighbor info, local backend returned " + info);
136 if (info == null)
137 info = base.RequestNeighbourInfo(regionHandle);
138 return info;
139 }
140
141 public override RegionInfo RequestClosestRegion(string regionName)
142 {
143 RegionInfo info = m_localBackend.RequestClosestRegion(regionName);
144 if (info == null)
145 info = base.RequestClosestRegion(regionName);
146 return info;
147 }
148
149 public override List<MapBlockData> RequestNeighbourMapBlocks(int minX, int minY, int maxX, int maxY)
150 {
151 //m_log.Info("[HGrid] Request map blocks " + minX + "-" + minY + "-" + maxX + "-" + maxY);
152 List<MapBlockData> neighbours = m_localBackend.RequestNeighbourMapBlocks(minX, minY, maxX, maxY);
153 List<MapBlockData> remotes = base.RequestNeighbourMapBlocks(minX, minY, maxX, maxY);
154 neighbours.AddRange(remotes);
155
156 return neighbours;
157 }
158
159 public override LandData RequestLandData(ulong regionHandle, uint x, uint y)
160 {
161 LandData land = m_localBackend.RequestLandData(regionHandle, x, y);
162 if (land == null)
163 land = base.RequestLandData(regionHandle, x, y);
164 return land;
165 }
166
167 public override List<RegionInfo> RequestNamedRegions(string name, int maxNumber)
168 {
169 List<RegionInfo> infos = m_localBackend.RequestNamedRegions(name, maxNumber);
170 List<RegionInfo> remotes = base.RequestNamedRegions(name, maxNumber);
171 infos.AddRange(remotes);
172 return infos;
173 }
174
175 #endregion
176
177 #region XML Request Handlers
178
179 /// <summary>
180 /// A ping / version check
181 /// </summary>
182 /// <param name="request"></param>
183 /// <returns></returns>
184 public virtual XmlRpcResponse PingCheckReply(XmlRpcRequest request)
185 {
186 XmlRpcResponse response = new XmlRpcResponse();
187
188 Hashtable respData = new Hashtable();
189 respData["online"] = "true";
190
191 m_localBackend.PingCheckReply(respData);
192
193 response.Value = respData;
194
195 return response;
196 }
197
198
199 // Grid Request Processing
200 /// <summary>
201 /// Ooops, our Agent must be dead if we're getting this request!
202 /// </summary>
203 /// <param name="request"></param>
204 /// <returns></returns>
205 public XmlRpcResponse LogOffUser(XmlRpcRequest request)
206 {
207 m_log.Debug("[HGrid]: LogOff User Called");
208
209 Hashtable requestData = (Hashtable)request.Params[0];
210 string message = (string)requestData["message"];
211 UUID agentID = UUID.Zero;
212 UUID RegionSecret = UUID.Zero;
213 UUID.TryParse((string)requestData["agent_id"], out agentID);
214 UUID.TryParse((string)requestData["region_secret"], out RegionSecret);
215
216 ulong regionHandle = Convert.ToUInt64((string)requestData["regionhandle"]);
217
218 m_localBackend.TriggerLogOffUser(regionHandle, agentID, RegionSecret, message);
219
220 return new XmlRpcResponse();
221 }
222
223 /// <summary>
224 /// Someone asked us about parcel-information
225 /// </summary>
226 /// <param name="request"></param>
227 /// <returns></returns>
228 public XmlRpcResponse LandData(XmlRpcRequest request)
229 {
230 Hashtable requestData = (Hashtable)request.Params[0];
231 ulong regionHandle = Convert.ToUInt64(requestData["region_handle"]);
232 uint x = Convert.ToUInt32(requestData["x"]);
233 uint y = Convert.ToUInt32(requestData["y"]);
234 m_log.DebugFormat("[HGrid]: Got XML reqeuest for land data at {0}, {1} in region {2}", x, y, regionHandle);
235
236 LandData landData = m_localBackend.RequestLandData(regionHandle, x, y);
237 Hashtable hash = new Hashtable();
238 if (landData != null)
239 {
240 // for now, only push out the data we need for answering a ParcelInfoReqeust
241 hash["AABBMax"] = landData.AABBMax.ToString();
242 hash["AABBMin"] = landData.AABBMin.ToString();
243 hash["Area"] = landData.Area.ToString();
244 hash["AuctionID"] = landData.AuctionID.ToString();
245 hash["Description"] = landData.Description;
246 hash["Flags"] = landData.Flags.ToString();
247 hash["GlobalID"] = landData.GlobalID.ToString();
248 hash["Name"] = landData.Name;
249 hash["OwnerID"] = landData.OwnerID.ToString();
250 hash["SalePrice"] = landData.SalePrice.ToString();
251 hash["SnapshotID"] = landData.SnapshotID.ToString();
252 hash["UserLocation"] = landData.UserLocation.ToString();
253 }
254
255 XmlRpcResponse response = new XmlRpcResponse();
256 response.Value = hash;
257 return response;
258 }
259
260 #endregion
261
262 #region Remoting
263
264 /// <summary>
265 /// Start listening for .net remoting calls from other regions.
266 /// </summary>
267 private void StartRemoting()
268 {
269 m_log.Info("[HGrid]: Start remoting...");
270 TcpChannel ch;
271 try
272 {
273 ch = new TcpChannel((int)NetworkServersInfo.RemotingListenerPort);
274 ChannelServices.RegisterChannel(ch, false); // Disabled security as Mono doesn't support this.
275 }
276 catch (Exception ex)
277 {
278 m_log.Error("[HGrid]: Exception while attempting to listen on TCP port " + (int)NetworkServersInfo.RemotingListenerPort + ".");
279 throw (ex);
280 }
281
282 WellKnownServiceTypeEntry wellType =
283 new WellKnownServiceTypeEntry(typeof(OGS1InterRegionRemoting), "InterRegions",
284 WellKnownObjectMode.Singleton);
285 RemotingConfiguration.RegisterWellKnownServiceType(wellType);
286 InterRegionSingleton.Instance.OnArrival += TriggerExpectAvatarCrossing;
287 InterRegionSingleton.Instance.OnChildAgent += IncomingChildAgent;
288 InterRegionSingleton.Instance.OnPrimGroupArrival += IncomingPrim;
289 InterRegionSingleton.Instance.OnPrimGroupNear += TriggerExpectPrimCrossing;
290 InterRegionSingleton.Instance.OnRegionUp += TriggerRegionUp;
291 InterRegionSingleton.Instance.OnChildAgentUpdate += TriggerChildAgentUpdate;
292 InterRegionSingleton.Instance.OnTellRegionToCloseChildConnection += TriggerTellRegionToCloseChildConnection;
293 }
294
295
296 #endregion
297
298 #region IInterRegionCommunications interface (Methods called by regions in this instance)
299
300 public override bool ChildAgentUpdate(ulong regionHandle, ChildAgentDataUpdate cAgentData)
301 {
302 int failures = 0;
303 lock (m_deadRegionCache)
304 {
305 if (m_deadRegionCache.ContainsKey(regionHandle))
306 {
307 failures = m_deadRegionCache[regionHandle];
308 }
309 }
310 if (failures <= 3)
311 {
312 RegionInfo regInfo = null;
313 try
314 {
315 if (m_localBackend.ChildAgentUpdate(regionHandle, cAgentData))
316 {
317 return true;
318 }
319
320 regInfo = RequestNeighbourInfo(regionHandle);
321 if (regInfo != null)
322 {
323 //don't want to be creating a new link to the remote instance every time like we are here
324 bool retValue = false;
325
326
327 OGS1InterRegionRemoting remObject = (OGS1InterRegionRemoting)Activator.GetObject(
328 typeof(OGS1InterRegionRemoting),
329 "tcp://" + regInfo.RemotingAddress +
330 ":" + regInfo.RemotingPort +
331 "/InterRegions");
332
333 if (remObject != null)
334 {
335 retValue = remObject.ChildAgentUpdate(regionHandle, cAgentData);
336 }
337 else
338 {
339 m_log.Warn("[HGrid]: remoting object not found");
340 }
341 remObject = null;
342
343 return retValue;
344 }
345 NoteDeadRegion(regionHandle);
346
347 return false;
348 }
349 catch (RemotingException e)
350 {
351 NoteDeadRegion(regionHandle);
352
353 m_log.WarnFormat(
354 "[HGrid]: Remoting Error: Unable to connect to adjacent region: {0} {1},{2}",
355 regInfo.RegionName, regInfo.RegionLocX, regInfo.RegionLocY);
356 m_log.DebugFormat("[HGrid]: {0} {1}", e.Source, e.Message);
357
358 return false;
359 }
360 catch (SocketException e)
361 {
362 NoteDeadRegion(regionHandle);
363
364 m_log.WarnFormat(
365 "[HGrid]: Remoting Error: Unable to connect to adjacent region: {0} {1},{2}",
366 regInfo.RegionName, regInfo.RegionLocX, regInfo.RegionLocY);
367 m_log.DebugFormat("[HGrid]: {0} {1}", e.Source, e.Message);
368
369 return false;
370 }
371 catch (InvalidCredentialException e)
372 {
373 NoteDeadRegion(regionHandle);
374
375 m_log.WarnFormat(
376 "[HGrid]: Remoting Error: Unable to connect to adjacent region: {0} {1},{2}",
377 regInfo.RegionName, regInfo.RegionLocX, regInfo.RegionLocY);
378 m_log.DebugFormat("[HGrid]: {0} {1}", e.Source, e.Message);
379
380 return false;
381 }
382 catch (AuthenticationException e)
383 {
384 NoteDeadRegion(regionHandle);
385
386 m_log.WarnFormat(
387 "[HGrid]: Remoting Error: Unable to connect to adjacent region: {0} {1},{2}",
388 regInfo.RegionName, regInfo.RegionLocX, regInfo.RegionLocY);
389 m_log.DebugFormat("[HGrid]: {0} {1}", e.Source, e.Message);
390
391 return false;
392 }
393 catch (Exception e)
394 {
395 NoteDeadRegion(regionHandle);
396
397 m_log.WarnFormat("[HGrid]: Unable to connect to adjacent region: {0} {1},{2}",
398 regInfo.RegionName, regInfo.RegionLocX, regInfo.RegionLocY);
399 m_log.DebugFormat("[HGrid]: {0} {1}", e.Source, e.Message);
400
401 return false;
402 }
403 }
404 else
405 {
406 //m_log.Info("[INTERREGION]: Skipped Sending Child Update to a region because it failed too many times:" + regionHandle.ToString());
407 return false;
408 }
409 }
410
411 /// <summary>
412 /// Inform a region that a child agent will be on the way from a client.
413 /// </summary>
414 /// <param name="regionHandle"></param>
415 /// <param name="agentData"></param>
416 /// <returns></returns>
417 public override bool InformRegionOfChildAgent(ulong regionHandle, AgentCircuitData agentData)
418 {
419
420 if (m_localBackend.InformRegionOfChildAgent(regionHandle, agentData))
421 {
422 return true;
423 }
424 return base.InformRegionOfChildAgent(regionHandle, agentData);
425 }
426
427 // UGLY!
428 public override bool RegionUp(SerializableRegionInfo region, ulong regionhandle)
429 {
430 if (m_localBackend.RegionUp(region, regionhandle))
431 return true;
432 return base.RegionUp(region, regionhandle);
433 }
434
435 /// <summary>
436 ///
437 /// </summary>
438 /// <param name="regionHandle"></param>
439 /// <param name="agentData"></param>
440 /// <returns></returns>
441 public override bool InformRegionOfPrimCrossing(ulong regionHandle, UUID primID, string objData, int XMLMethod)
442 {
443 int failures = 0;
444 lock (m_deadRegionCache)
445 {
446 if (m_deadRegionCache.ContainsKey(regionHandle))
447 {
448 failures = m_deadRegionCache[regionHandle];
449 }
450 }
451 if (failures <= 1)
452 {
453 RegionInfo regInfo = null;
454 try
455 {
456 if (m_localBackend.InformRegionOfPrimCrossing(regionHandle, primID, objData, XMLMethod))
457 {
458 return true;
459 }
460
461 regInfo = RequestNeighbourInfo(regionHandle);
462 if (regInfo != null)
463 {
464 //don't want to be creating a new link to the remote instance every time like we are here
465 bool retValue = false;
466
467 OGS1InterRegionRemoting remObject = (OGS1InterRegionRemoting)Activator.GetObject(
468 typeof(OGS1InterRegionRemoting),
469 "tcp://" + regInfo.RemotingAddress +
470 ":" + regInfo.RemotingPort +
471 "/InterRegions");
472
473 if (remObject != null)
474 {
475 retValue = remObject.InformRegionOfPrimCrossing(regionHandle, primID.Guid, objData, XMLMethod);
476 }
477 else
478 {
479 m_log.Warn("[HGrid]: Remoting object not found");
480 }
481 remObject = null;
482
483 return retValue;
484 }
485 NoteDeadRegion(regionHandle);
486 return false;
487 }
488 catch (RemotingException e)
489 {
490 NoteDeadRegion(regionHandle);
491 m_log.Warn("[HGrid]: Remoting Error: Unable to connect to adjacent region: " + regionHandle);
492 m_log.DebugFormat("[HGrid]: {0} {1}", e.Source, e.Message);
493 return false;
494 }
495 catch (SocketException e)
496 {
497 NoteDeadRegion(regionHandle);
498 m_log.Warn("[HGrid]: Remoting Error: Unable to connect to adjacent region: " + regionHandle);
499 m_log.DebugFormat("[HGrid]: {0} {1}", e.Source, e.Message);
500 return false;
501 }
502 catch (InvalidCredentialException e)
503 {
504 NoteDeadRegion(regionHandle);
505 m_log.Warn("[HGrid]: Invalid Credential Exception: Invalid Credentials : " + regionHandle);
506 m_log.DebugFormat("[HGrid]: {0} {1}", e.Source, e.Message);
507 return false;
508 }
509 catch (AuthenticationException e)
510 {
511 NoteDeadRegion(regionHandle);
512 m_log.Warn("[HGrid]: Authentication exception: Unable to connect to adjacent region: " + regionHandle);
513 m_log.DebugFormat("[HGrid]: {0} {1}", e.Source, e.Message);
514 return false;
515 }
516 catch (Exception e)
517 {
518 NoteDeadRegion(regionHandle);
519 m_log.Warn("[HGrid]: Unknown exception: Unable to connect to adjacent region: " + regionHandle);
520 m_log.DebugFormat("[HGrid]: {0}", e);
521 return false;
522 }
523 }
524 else
525 {
526 return false;
527 }
528 }
529
530 /// <summary>
531 ///
532 /// </summary>
533 /// <param name="regionHandle"></param>
534 /// <param name="agentID"></param>
535 /// <param name="position"></param>
536 /// <returns></returns>
537 public override bool ExpectAvatarCrossing(ulong regionHandle, UUID agentID, Vector3 position, bool isFlying)
538 {
539
540 RegionInfo[] regions = m_regionsOnInstance.ToArray();
541 bool banned = false;
542 bool localregion = false;
543
544 for (int i = 0; i < regions.Length; i++)
545 {
546 if (regions[i] != null)
547 {
548 if (regions[i].RegionHandle == regionHandle)
549 {
550 localregion = true;
551 if (regions[i].EstateSettings.IsBanned(agentID))
552 {
553 banned = true;
554 break;
555 }
556 }
557 }
558 }
559
560 if (banned)
561 return false;
562 if (localregion)
563 return m_localBackend.ExpectAvatarCrossing(regionHandle, agentID, position, isFlying);
564
565 return base.ExpectAvatarCrossing(regionHandle, agentID, position, isFlying);
566
567 }
568
569 public override bool ExpectPrimCrossing(ulong regionHandle, UUID agentID, Vector3 position, bool isPhysical)
570 {
571 RegionInfo regInfo = null;
572 try
573 {
574 if (m_localBackend.TriggerExpectPrimCrossing(regionHandle, agentID, position, isPhysical))
575 {
576 return true;
577 }
578
579 regInfo = RequestNeighbourInfo(regionHandle);
580 if (regInfo != null)
581 {
582 bool retValue = false;
583 OGS1InterRegionRemoting remObject = (OGS1InterRegionRemoting)Activator.GetObject(
584 typeof(OGS1InterRegionRemoting),
585 "tcp://" + regInfo.RemotingAddress +
586 ":" + regInfo.RemotingPort +
587 "/InterRegions");
588
589 if (remObject != null)
590 {
591 retValue =
592 remObject.ExpectAvatarCrossing(regionHandle, agentID.Guid, new sLLVector3(position),
593 isPhysical);
594 }
595 else
596 {
597 m_log.Warn("[HGrid]: Remoting object not found");
598 }
599 remObject = null;
600
601 return retValue;
602 }
603 //TODO need to see if we know about where this region is and use .net remoting
604 // to inform it.
605 NoteDeadRegion(regionHandle);
606 return false;
607 }
608 catch (RemotingException e)
609 {
610 NoteDeadRegion(regionHandle);
611 m_log.Warn("[HGrid]: Remoting Error: Unable to connect to adjacent region: " + regionHandle);
612 m_log.DebugFormat("[HGrid]: {0} {1}", e.Source, e.Message);
613 return false;
614 }
615 catch (SocketException e)
616 {
617 NoteDeadRegion(regionHandle);
618 m_log.Warn("[HGrid]: Remoting Error: Unable to connect to adjacent region: " + regionHandle);
619 m_log.DebugFormat("[HGrid]: {0} {1}", e.Source, e.Message);
620 return false;
621 }
622 catch (InvalidCredentialException e)
623 {
624 NoteDeadRegion(regionHandle);
625 m_log.Warn("[HGrid]: Invalid Credential Exception: Invalid Credentials : " + regionHandle);
626 m_log.DebugFormat("[HGrid]: {0} {1}", e.Source, e.Message);
627 return false;
628 }
629 catch (AuthenticationException e)
630 {
631 NoteDeadRegion(regionHandle);
632 m_log.Warn("[HGrid]: Authentication exception: Unable to connect to adjacent region: " + regionHandle);
633 m_log.DebugFormat("[HGrid]: {0} {1}", e.Source, e.Message);
634 return false;
635 }
636 catch (Exception e)
637 {
638 NoteDeadRegion(regionHandle);
639 m_log.Warn("[HGrid]: Unknown exception: Unable to connect to adjacent region: " + regionHandle);
640 m_log.DebugFormat("[HGrid]: {0}", e);
641 return false;
642 }
643 }
644
645 public override bool TellRegionToCloseChildConnection(ulong regionHandle, UUID agentID)
646 {
647 RegionInfo regInfo = null;
648 try
649 {
650 if (m_localBackend.TriggerTellRegionToCloseChildConnection(regionHandle, agentID))
651 {
652 return true;
653 }
654
655 regInfo = RequestNeighbourInfo(regionHandle);
656 if (regInfo != null)
657 {
658 // bool retValue = false;
659 OGS1InterRegionRemoting remObject = (OGS1InterRegionRemoting)Activator.GetObject(
660 typeof(OGS1InterRegionRemoting),
661 "tcp://" + regInfo.RemotingAddress +
662 ":" + regInfo.RemotingPort +
663 "/InterRegions");
664
665 if (remObject != null)
666 {
667 // retValue =
668 remObject.TellRegionToCloseChildConnection(regionHandle, agentID.Guid);
669 }
670 else
671 {
672 m_log.Warn("[HGrid]: Remoting object not found");
673 }
674 remObject = null;
675
676 return true;
677 }
678 //TODO need to see if we know about where this region is and use .net remoting
679 // to inform it.
680 NoteDeadRegion(regionHandle);
681 return false;
682 }
683 catch (RemotingException)
684 {
685 NoteDeadRegion(regionHandle);
686 m_log.Warn("[HGrid]: Remoting Error: Unable to connect to adjacent region to tell it to close child agents: " + regInfo.RegionName +
687 " " + regInfo.RegionLocX + "," + regInfo.RegionLocY);
688 //m_log.Debug(e.ToString());
689 return false;
690 }
691 catch (SocketException e)
692 {
693 NoteDeadRegion(regionHandle);
694 m_log.Warn("[HGridS]: Socket Error: Unable to connect to adjacent region using tcp://" +
695 regInfo.RemotingAddress +
696 ":" + regInfo.RemotingPort +
697 "/InterRegions - @ " + regInfo.RegionLocX + "," + regInfo.RegionLocY +
698 " - Is this neighbor up?");
699 m_log.DebugFormat("[HGrid]: {0} {1}", e.Source, e.Message);
700 return false;
701 }
702 catch (InvalidCredentialException e)
703 {
704 NoteDeadRegion(regionHandle);
705 m_log.Warn("[HGrid]: Invalid Credentials: Unable to connect to adjacent region using tcp://" +
706 regInfo.RemotingAddress +
707 ":" + regInfo.RemotingPort +
708 "/InterRegions - @ " + regInfo.RegionLocX + "," + regInfo.RegionLocY);
709 m_log.DebugFormat("[HGrid]: {0} {1}", e.Source, e.Message);
710 return false;
711 }
712 catch (AuthenticationException e)
713 {
714 NoteDeadRegion(regionHandle);
715 m_log.Warn("[HGrid]: Authentication exception: Unable to connect to adjacent region using tcp://" +
716 regInfo.RemotingAddress +
717 ":" + regInfo.RemotingPort +
718 "/InterRegions - @ " + regInfo.RegionLocX + "," + regInfo.RegionLocY);
719 m_log.DebugFormat("[HGrid]: {0} {1}", e.Source, e.Message);
720 return false;
721 }
722 catch (WebException e)
723 {
724 NoteDeadRegion(regionHandle);
725 m_log.Warn("[HGrid]: WebException exception: Unable to connect to adjacent region using tcp://" +
726 regInfo.RemotingAddress +
727 ":" + regInfo.RemotingPort +
728 "/InterRegions - @ " + regInfo.RegionLocX + "," + regInfo.RegionLocY);
729 m_log.DebugFormat("[HGrid]: {0} {1}", e.Source, e.Message);
730 return false;
731 }
732 catch (Exception e)
733 {
734 NoteDeadRegion(regionHandle);
735 // This line errors with a Null Reference Exception.. Why? @.@
736 //m_log.Warn("Unknown exception: Unable to connect to adjacent region using tcp://" + regInfo.RemotingAddress +
737 // ":" + regInfo.RemotingPort +
738 //"/InterRegions - @ " + regInfo.RegionLocX + "," + regInfo.RegionLocY + " - This is likely caused by an incompatibility in the protocol between this sim and that one");
739 m_log.DebugFormat("[HGrid]: {0}", e);
740 return false;
741 }
742 }
743
744 public override bool AcknowledgeAgentCrossed(ulong regionHandle, UUID agentId)
745 {
746 return m_localBackend.AcknowledgeAgentCrossed(regionHandle, agentId);
747 }
748
749 public override bool AcknowledgePrimCrossed(ulong regionHandle, UUID primId)
750 {
751 return m_localBackend.AcknowledgePrimCrossed(regionHandle, primId);
752 }
753
754 #endregion
755
756 #region Methods triggered by calls from external instances
757
758 /// <summary>
759 ///
760 /// </summary>
761 /// <param name="regionHandle"></param>
762 /// <param name="agentData"></param>
763 /// <returns></returns>
764 public bool IncomingChildAgent(ulong regionHandle, AgentCircuitData agentData)
765 {
766 HGIncomingChildAgent(regionHandle, agentData);
767
768 m_log.Info("[HGrid]: " + gdebugRegionName + ": Incoming HGrid Agent " + agentData.firstname + " " + agentData.lastname);
769
770 return m_localBackend.IncomingChildAgent(regionHandle, agentData);
771 }
772
773 public bool TriggerRegionUp(RegionUpData regionData, ulong regionhandle)
774 {
775 m_log.Info(
776 "[HGrid]: " +
777 m_localBackend._gdebugRegionName + "Incoming HGrid RegionUpReport: " + "(" + regionData.X +
778 "," + regionData.Y + "). Giving this region a fresh set of 'dead' tries");
779
780 RegionInfo nRegionInfo = new RegionInfo();
781 nRegionInfo.SetEndPoint("127.0.0.1", regionData.PORT);
782 nRegionInfo.ExternalHostName = regionData.IPADDR;
783 nRegionInfo.RegionLocX = regionData.X;
784 nRegionInfo.RegionLocY = regionData.Y;
785
786 lock (m_deadRegionCache)
787 {
788 if (m_deadRegionCache.ContainsKey(nRegionInfo.RegionHandle))
789 {
790 m_deadRegionCache.Remove(nRegionInfo.RegionHandle);
791 }
792 }
793
794 return m_localBackend.TriggerRegionUp(nRegionInfo, regionhandle);
795 }
796
797 public bool TriggerChildAgentUpdate(ulong regionHandle, ChildAgentDataUpdate cAgentData)
798 {
799 //m_log.Info("[INTER]: Incoming HGrid Child Agent Data Update");
800
801 return m_localBackend.TriggerChildAgentUpdate(regionHandle, cAgentData);
802 }
803
804 /// <summary>
805 ///
806 /// </summary>
807 /// <param name="regionHandle"></param>
808 /// <param name="agentData"></param>
809 /// <returns></returns>
810 public bool IncomingPrim(ulong regionHandle, UUID primID, string objData, int XMLMethod)
811 {
812 m_localBackend.TriggerExpectPrim(regionHandle, primID, objData, XMLMethod);
813
814 return true;
815 }
816
817 /// <summary>
818 ///
819 /// </summary>
820 /// <param name="regionHandle"></param>
821 /// <param name="agentID"></param>
822 /// <param name="position"></param>
823 /// <returns></returns>
824 public bool TriggerExpectAvatarCrossing(ulong regionHandle, UUID agentID, Vector3 position, bool isFlying)
825 {
826 return m_localBackend.TriggerExpectAvatarCrossing(regionHandle, agentID, position, isFlying);
827 }
828
829 public bool TriggerExpectPrimCrossing(ulong regionHandle, UUID agentID, Vector3 position, bool isPhysical)
830 {
831 return m_localBackend.TriggerExpectPrimCrossing(regionHandle, agentID, position, isPhysical);
832 }
833
834 public bool TriggerTellRegionToCloseChildConnection(ulong regionHandle, UUID agentID)
835 {
836 return m_localBackend.TriggerTellRegionToCloseChildConnection(regionHandle, agentID);
837 }
838
839 int timeOut = 10; //10 seconds
840 /// <summary>
841 /// Check that a region is available for TCP comms. This is necessary for .NET remoting between regions.
842 /// </summary>
843 /// <param name="address"></param>
844 /// <param name="port"></param>
845 /// <param name="retry"></param>
846 /// <returns></returns>
847 public bool CheckRegion(string address, uint port, bool retry)
848 {
849 bool available = false;
850 bool timed_out = true;
851
852 IPAddress ia;
853 IPAddress.TryParse(address, out ia);
854 IPEndPoint m_EndPoint = new IPEndPoint(ia, (int)port);
855
856 AsyncCallback callback = delegate(IAsyncResult iar)
857 {
858 Socket s = (Socket)iar.AsyncState;
859 try
860 {
861 s.EndConnect(iar);
862 available = true;
863 timed_out = false;
864 }
865 catch (Exception e)
866 {
867 m_log.DebugFormat(
868 "[HGrid]: Callback EndConnect exception: {0}:{1}", e.Message, e.StackTrace);
869 }
870
871 s.Close();
872 };
873
874 try
875 {
876 Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
877 IAsyncResult ar = socket.BeginConnect(m_EndPoint, callback, socket);
878 ar.AsyncWaitHandle.WaitOne(timeOut * 1000, false);
879 }
880 catch (Exception e)
881 {
882 m_log.DebugFormat(
883 "[HGrid]: CheckRegion Socket Setup exception: {0}:{1}", e.Message, e.StackTrace);
884
885 return false;
886 }
887
888 if (timed_out)
889 {
890 m_log.DebugFormat(
891 "[HGrid]: socket [{0}] timed out ({1}) waiting to obtain a connection.",
892 m_EndPoint, timeOut * 1000);
893
894 if (retry)
895 {
896 return CheckRegion(address, port, false);
897 }
898 }
899
900 return available;
901 }
902
903 public override bool CheckRegion(string address, uint port)
904 {
905 return CheckRegion(address, port, true);
906 }
907
908 public void NoteDeadRegion(ulong regionhandle)
909 {
910 lock (m_deadRegionCache)
911 {
912 if (m_deadRegionCache.ContainsKey(regionhandle))
913 {
914 m_deadRegionCache[regionhandle] = m_deadRegionCache[regionhandle] + 1;
915 }
916 else
917 {
918 m_deadRegionCache.Add(regionhandle, 1);
919 }
920 }
921
922 }
923
924 #endregion
925
926
927 }
928}
diff --git a/OpenSim/Region/Communications/Hypergrid/HGInventoryService.cs b/OpenSim/Region/Communications/Hypergrid/HGInventoryService.cs
new file mode 100644
index 0000000..9ef040b
--- /dev/null
+++ b/OpenSim/Region/Communications/Hypergrid/HGInventoryService.cs
@@ -0,0 +1,451 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSim 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.Net;
31using System.Reflection;
32using OpenMetaverse;
33using log4net;
34using OpenSim.Framework;
35using OpenSim.Framework.Communications;
36using OpenSim.Framework.Communications.Cache;
37using OpenSim.Framework.Servers;
38using OpenSim.Framework.Statistics;
39using OpenSim.Region.Communications.Local;
40
41namespace OpenSim.Region.Communications.Hypergrid
42{
43 public class HGInventoryService : LocalInventoryService, ISecureInventoryService
44 {
45 private static readonly ILog m_log
46 = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
47
48 private string _inventoryServerUrl;
49 private Uri m_Uri;
50 private UserProfileCacheService m_userProfileCache;
51 private bool m_gridmode = false;
52
53 private Dictionary<UUID, InventoryReceiptCallback> m_RequestingInventory
54 = new Dictionary<UUID, InventoryReceiptCallback>();
55
56 public UserProfileCacheService UserProfileCache
57 {
58 set { m_userProfileCache = value; }
59 }
60
61 public HGInventoryService(string inventoryServerUrl, UserProfileCacheService userProfileCacheService, bool gridmode)
62 {
63 _inventoryServerUrl = HGNetworkServersInfo.ServerURI(inventoryServerUrl);
64 m_Uri = new Uri(_inventoryServerUrl);
65 m_userProfileCache = userProfileCacheService;
66 m_gridmode = gridmode;
67 }
68
69 #region ISecureInventoryService Members
70
71 public void RequestInventoryForUser(UUID userID, UUID session_id, InventoryReceiptCallback callback)
72 {
73 if (IsLocalStandaloneUser(userID))
74 {
75 base.RequestInventoryForUser(userID, callback);
76 return;
77 }
78
79 // grid/hypergrid mode
80 if (!m_RequestingInventory.ContainsKey(userID))
81 {
82 m_RequestingInventory.Add(userID, callback);
83
84 try
85 {
86 string invServer = GetUserInventoryURI(userID);
87 m_log.InfoFormat(
88 "[HGrid INVENTORY SERVICE]: Requesting inventory from {0}/GetInventory/ for user {1} ({2})",
89 /*_inventoryServerUrl*/ invServer, userID, userID.Guid);
90
91
92 RestSessionObjectPosterResponse<Guid, InventoryCollection> requester
93 = new RestSessionObjectPosterResponse<Guid, InventoryCollection>();
94 requester.ResponseCallback = InventoryResponse;
95
96 requester.BeginPostObject(invServer + "/GetInventory/", userID.Guid, session_id.ToString(), userID.ToString());
97
98 //Test(userID.Guid);
99
100 //RestObjectPosterResponse<InventoryCollection> requester
101 // = new RestObjectPosterResponse<InventoryCollection>();
102 //requester.ResponseCallback = InventoryResponse;
103
104 //requester.BeginPostObject<Guid>(/*_inventoryServerUrl*/ invServer + "/GetInventory/", userID.Guid);
105
106 //RestClient cli = new RestClient(invServer + "/GetInventory/" + userID.Guid);
107 //Stream reply = cli.Request();
108 }
109 catch (WebException e)
110 {
111 if (StatsManager.SimExtraStats != null)
112 StatsManager.SimExtraStats.AddInventoryServiceRetrievalFailure();
113
114 m_log.ErrorFormat("[HGrid INVENTORY SERVICE]: Request inventory operation failed, {0} {1}",
115 e.Source, e.Message);
116 }
117 }
118 else
119 {
120 m_log.ErrorFormat("[HGrid INVENTORY SERVICE]: RequestInventoryForUser() - could not find user profile for {0}", userID);
121 }
122
123 }
124
125 /// <summary>
126 /// Add a new folder to the user's inventory
127 /// </summary>
128 /// <param name="folder"></param>
129 /// <returns>true if the folder was successfully added</returns>
130 public bool AddFolder(InventoryFolderBase folder, UUID session_id)
131 {
132 if (IsLocalStandaloneUser(folder.Owner))
133 {
134 return base.AddFolder(folder);
135 }
136
137 try
138 {
139 string invServ = GetUserInventoryURI(folder.Owner);
140
141 return SynchronousRestSessionObjectPoster<InventoryFolderBase, bool>.BeginPostObject(
142 "POST", invServ + "/NewFolder/", folder, session_id.ToString(), folder.Owner.ToString());
143 }
144 catch (WebException e)
145 {
146 m_log.ErrorFormat("[HGrid INVENTORY SERVICE]: Add new inventory folder operation failed, {0} {1}",
147 e.Source, e.Message);
148 }
149
150 return false;
151
152 }
153
154 /// <summary>
155 /// Update a folder in the user's inventory
156 /// </summary>
157 /// <param name="folder"></param>
158 /// <returns>true if the folder was successfully updated</returns>
159 public bool UpdateFolder(InventoryFolderBase folder, UUID session_id)
160 {
161 if (IsLocalStandaloneUser(folder.Owner))
162 {
163 return base.UpdateFolder(folder);
164 }
165 try
166 {
167 string invServ = GetUserInventoryURI(folder.Owner);
168
169 return SynchronousRestSessionObjectPoster<InventoryFolderBase, bool>.BeginPostObject(
170 "POST", invServ + "/UpdateFolder/", folder, session_id.ToString(), folder.Owner.ToString());
171 }
172 catch (WebException e)
173 {
174 m_log.ErrorFormat("[HGrid INVENTORY SERVICE]: Update inventory folder operation failed, {0} {1}",
175 e.Source, e.Message);
176 }
177
178 return false;
179
180 }
181
182 /// <summary>
183 /// Move an inventory folder to a new location
184 /// </summary>
185 /// <param name="folder">A folder containing the details of the new location</param>
186 /// <returns>true if the folder was successfully moved</returns>
187 public bool MoveFolder(InventoryFolderBase folder, UUID session_id)
188 {
189 if (IsLocalStandaloneUser(folder.Owner))
190 {
191 return base.MoveFolder(folder);
192 }
193
194 try
195 {
196 string invServ = GetUserInventoryURI(folder.Owner);
197
198 return SynchronousRestSessionObjectPoster<InventoryFolderBase, bool>.BeginPostObject(
199 "POST", invServ + "/MoveFolder/", folder, session_id.ToString(), folder.Owner.ToString());
200 }
201 catch (WebException e)
202 {
203 m_log.ErrorFormat("[HGrid INVENTORY SERVICE]: Move inventory folder operation failed, {0} {1}",
204 e.Source, e.Message);
205 }
206
207 return false;
208 }
209
210 /// <summary>
211 /// Purge an inventory folder of all its items and subfolders.
212 /// </summary>
213 /// <param name="folder"></param>
214 /// <returns>true if the folder was successfully purged</returns>
215 public bool PurgeFolder(InventoryFolderBase folder, UUID session_id)
216 {
217 if (IsLocalStandaloneUser(folder.Owner))
218 {
219 return base.PurgeFolder(folder);
220 }
221
222 try
223 {
224 string invServ = GetUserInventoryURI(folder.Owner);
225
226 return SynchronousRestSessionObjectPoster<InventoryFolderBase, bool>.BeginPostObject(
227 "POST", invServ + "/PurgeFolder/", folder, session_id.ToString(), folder.Owner.ToString());
228 }
229 catch (WebException e)
230 {
231 m_log.ErrorFormat("[HGrid INVENTORY SERVICE]: Move inventory folder operation failed, {0} {1}",
232 e.Source, e.Message);
233 }
234
235 return false;
236 }
237
238 /// <summary>
239 /// Add a new item to the user's inventory
240 /// </summary>
241 /// <param name="item"></param>
242 /// <returns>true if the item was successfully added</returns>
243 public bool AddItem(InventoryItemBase item, UUID session_id)
244 {
245 if (IsLocalStandaloneUser(item.Owner))
246 {
247 return base.AddItem(item);
248 }
249
250 try
251 {
252 string invServ = GetUserInventoryURI(item.Owner);
253
254 return SynchronousRestSessionObjectPoster<InventoryItemBase, bool>.BeginPostObject(
255 "POST", invServ + "/NewItem/", item, session_id.ToString(), item.Owner.ToString());
256 }
257 catch (WebException e)
258 {
259 m_log.ErrorFormat("[HGrid INVENTORY SERVICE]: Add new inventory item operation failed, {0} {1}",
260 e.Source, e.Message);
261 }
262
263 return false;
264 }
265
266 /// <summary>
267 /// Update an item in the user's inventory
268 /// </summary>
269 /// <param name="item"></param>
270 /// <returns>true if the item was successfully updated</returns>
271 public bool UpdateItem(InventoryItemBase item, UUID session_id)
272 {
273 if (IsLocalStandaloneUser(item.Owner))
274 {
275 return base.UpdateItem(item);
276 }
277
278 try
279 {
280 string invServ = GetUserInventoryURI(item.Owner);
281 return SynchronousRestSessionObjectPoster<InventoryItemBase, bool>.BeginPostObject(
282 "POST", invServ + "/NewItem/", item, session_id.ToString(), item.Owner.ToString());
283 }
284 catch (WebException e)
285 {
286 m_log.ErrorFormat("[HGrid INVENTORY SERVICE]: Update new inventory item operation failed, {0} {1}",
287 e.Source, e.Message);
288 }
289
290 return false;
291 }
292
293 /// <summary>
294 /// Delete an item from the user's inventory
295 /// </summary>
296 /// <param name="item"></param>
297 /// <returns>true if the item was successfully deleted</returns>
298 public bool DeleteItem(InventoryItemBase item, UUID session_id)
299 {
300 if (IsLocalStandaloneUser(item.Owner))
301 {
302 return base.DeleteItem(item);
303 }
304
305 try
306 {
307 string invServ = GetUserInventoryURI(item.Owner);
308
309 return SynchronousRestSessionObjectPoster<InventoryItemBase, bool>.BeginPostObject(
310 "POST", invServ + "/DeleteItem/", item, session_id.ToString(), item.Owner.ToString());
311 }
312 catch (WebException e)
313 {
314 m_log.ErrorFormat("[HGrid INVENTORY SERVICE]: Delete inventory item operation failed, {0} {1}",
315 e.Source, e.Message);
316 }
317
318 return false;
319 }
320 #endregion
321
322 #region Methods common to ISecureInventoryService and IInventoryService
323
324 /// <summary>
325 /// Does the given user have an inventory structure?
326 /// </summary>
327 /// <param name="userID"></param>
328 /// <returns></returns>
329 public override bool HasInventoryForUser(UUID userID)
330 {
331 if (IsLocalStandaloneUser(userID))
332 {
333 return base.HasInventoryForUser(userID);
334 }
335 return false;
336 }
337
338 /// <summary>
339 /// Retrieve the root inventory folder for the given user.
340 /// </summary>
341 /// <param name="userID"></param>
342 /// <returns>null if no root folder was found</returns>
343 public override InventoryFolderBase RequestRootFolder(UUID userID)
344 {
345 if (IsLocalStandaloneUser(userID))
346 {
347 return base.RequestRootFolder(userID);
348 }
349
350 return null;
351 }
352
353 #endregion
354
355
356 /// <summary>
357 /// Callback used by the inventory server GetInventory request
358 /// </summary>
359 /// <param name="userID"></param>
360 private void InventoryResponse(InventoryCollection response)
361 {
362 UUID userID = response.UserID;
363 if (m_RequestingInventory.ContainsKey(userID))
364 {
365 m_log.InfoFormat("[HGrid INVENTORY SERVICE]: " +
366 "Received inventory response for user {0} containing {1} folders and {2} items",
367 userID, response.Folders.Count, response.Items.Count);
368
369 InventoryFolderImpl rootFolder = null;
370 InventoryReceiptCallback callback = m_RequestingInventory[userID];
371
372 ICollection<InventoryFolderImpl> folders = new List<InventoryFolderImpl>();
373 ICollection<InventoryItemBase> items = new List<InventoryItemBase>();
374
375 foreach (InventoryFolderBase folder in response.Folders)
376 {
377 if (folder.ParentID == UUID.Zero)
378 {
379 rootFolder = new InventoryFolderImpl(folder);
380 folders.Add(rootFolder);
381
382 break;
383 }
384 }
385
386 if (rootFolder != null)
387 {
388 foreach (InventoryFolderBase folder in response.Folders)
389 {
390 if (folder.ID != rootFolder.ID)
391 {
392 folders.Add(new InventoryFolderImpl(folder));
393 }
394 }
395
396 foreach (InventoryItemBase item in response.Items)
397 {
398 items.Add(item);
399 }
400 }
401 else
402 {
403 m_log.ErrorFormat("[HGrid INVENTORY SERVICE]: Did not get back an inventory containing a root folder for user {0}", userID);
404 }
405
406 callback(folders, items);
407
408 m_RequestingInventory.Remove(userID);
409 }
410 else
411 {
412 m_log.WarnFormat(
413 "[HGrid INVENTORY SERVICE]: " +
414 "Received inventory response for {0} for which we do not have a record of requesting!",
415 userID);
416 }
417 }
418
419
420 private bool IsLocalStandaloneUser(UUID userID)
421 {
422 CachedUserInfo uinfo = m_userProfileCache.GetUserDetails(userID);
423 if (uinfo == null)
424 return true;
425
426 string userInventoryServerURI = HGNetworkServersInfo.ServerURI(uinfo.UserProfile.UserInventoryURI);
427
428 if ((!m_gridmode) && ((userInventoryServerURI == _inventoryServerUrl)) || (userInventoryServerURI == ""))
429 {
430 return true;
431 }
432 return false;
433 }
434
435 private string GetUserInventoryURI(UUID userID)
436 {
437 string invURI = _inventoryServerUrl;
438 CachedUserInfo uinfo = m_userProfileCache.GetUserDetails(userID);
439 if ((uinfo == null) || (uinfo.UserProfile == null))
440 return invURI;
441
442 string userInventoryServerURI = HGNetworkServersInfo.ServerURI(uinfo.UserProfile.UserInventoryURI);
443
444 if ((userInventoryServerURI != null) &&
445 (userInventoryServerURI != ""))
446 invURI = userInventoryServerURI;
447 return invURI;
448 }
449
450 }
451}
diff --git a/OpenSim/Region/Communications/Hypergrid/HGUserServices.cs b/OpenSim/Region/Communications/Hypergrid/HGUserServices.cs
new file mode 100644
index 0000000..d9b44a1
--- /dev/null
+++ b/OpenSim/Region/Communications/Hypergrid/HGUserServices.cs
@@ -0,0 +1,267 @@
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 OpenSim 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.Reflection;
33using System.Text.RegularExpressions;
34using OpenMetaverse;
35using log4net;
36using Nwc.XmlRpc;
37using OpenSim.Framework;
38using OpenSim.Framework.Communications;
39using OpenSim.Region.Communications.OGS1;
40
41namespace OpenSim.Region.Communications.Hypergrid
42{
43 /// <summary>
44 /// For the time being, this class is just an identity wrapper around OGS1UserServices,
45 /// so it always fails for foreign users.
46 /// Later it needs to talk with the foreign users' user servers.
47 /// </summary>
48 public class HGUserServices : IUserService, IAvatarService, IMessagingService
49 {
50 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
51
52 private HGCommunicationsGridMode m_parent;
53 private OGS1UserServices m_remoteUserServices;
54
55 public HGUserServices(HGCommunicationsGridMode parent)
56 {
57 m_parent = parent;
58 m_remoteUserServices = new OGS1UserServices(parent);
59 }
60
61 public UserProfileData ConvertXMLRPCDataToUserProfile(Hashtable data)
62 {
63 return m_remoteUserServices.ConvertXMLRPCDataToUserProfile(data);
64 }
65
66 /// <summary>
67 /// Get a user agent from the user server
68 /// </summary>
69 /// <param name="avatarID"></param>
70 /// <returns>null if the request fails</returns>
71 public UserAgentData GetAgentByUUID(UUID userId)
72 {
73 return m_remoteUserServices.GetAgentByUUID(userId);
74 }
75
76 public AvatarAppearance ConvertXMLRPCDataToAvatarAppearance(Hashtable data)
77 {
78 return m_remoteUserServices.ConvertXMLRPCDataToAvatarAppearance(data);
79 }
80
81 public List<AvatarPickerAvatar> ConvertXMLRPCDataToAvatarPickerList(UUID queryID, Hashtable data)
82 {
83 return m_remoteUserServices.ConvertXMLRPCDataToAvatarPickerList(queryID, data);
84 }
85
86 public List<FriendListItem> ConvertXMLRPCDataToFriendListItemList(Hashtable data)
87 {
88 return m_remoteUserServices.ConvertXMLRPCDataToFriendListItemList(data);
89 }
90
91 /// <summary>
92 /// Logs off a user on the user server
93 /// </summary>
94 /// <param name="UserID">UUID of the user</param>
95 /// <param name="regionID">UUID of the Region</param>
96 /// <param name="regionhandle">regionhandle</param>
97 /// <param name="position">final position</param>
98 /// <param name="lookat">final lookat</param>
99 public void LogOffUser(UUID userid, UUID regionid, ulong regionhandle, Vector3 position, Vector3 lookat)
100 {
101 m_remoteUserServices.LogOffUser(userid, regionid, regionhandle, position, lookat);
102 }
103
104 /// <summary>
105 /// Logs off a user on the user server (deprecated as of 2008-08-27)
106 /// </summary>
107 /// <param name="UserID">UUID of the user</param>
108 /// <param name="regionID">UUID of the Region</param>
109 /// <param name="regionhandle">regionhandle</param>
110 /// <param name="posx">final position x</param>
111 /// <param name="posy">final position y</param>
112 /// <param name="posz">final position z</param>
113 public void LogOffUser(UUID userid, UUID regionid, ulong regionhandle, float posx, float posy, float posz)
114 {
115 m_remoteUserServices.LogOffUser(userid, regionid, regionhandle, posx, posy, posz);
116 }
117
118 public UserProfileData GetUserProfile(string firstName, string lastName)
119 {
120 return GetUserProfile(firstName + " " + lastName);
121 }
122
123 public void UpdateUserCurrentRegion(UUID avatarid, UUID regionuuid, ulong regionhandle)
124 {
125 m_remoteUserServices.UpdateUserCurrentRegion(avatarid, regionuuid, regionhandle);
126 }
127
128 public List<AvatarPickerAvatar> GenerateAgentPickerRequestResponse(UUID queryID, string query)
129 {
130 return m_remoteUserServices.GenerateAgentPickerRequestResponse(queryID, query);
131 }
132
133 /// <summary>
134 /// Get a user profile from the user server
135 /// </summary>
136 /// <param name="avatarID"></param>
137 /// <returns>null if the request fails</returns>
138 public UserProfileData GetUserProfile(string name)
139 {
140 return m_remoteUserServices.GetUserProfile(name);
141 }
142
143 /// <summary>
144 /// Get a user profile from the user server
145 /// </summary>
146 /// <param name="avatarID"></param>
147 /// <returns>null if the request fails</returns>
148 public UserProfileData GetUserProfile(UUID avatarID)
149 {
150 return m_remoteUserServices.GetUserProfile(avatarID);
151 }
152
153
154 public void ClearUserAgent(UUID avatarID)
155 {
156 m_remoteUserServices.ClearUserAgent(avatarID);
157 }
158
159 /// <summary>
160 /// Retrieve the user information for the given master uuid.
161 /// </summary>
162 /// <param name="uuid"></param>
163 /// <returns></returns>
164 public UserProfileData SetupMasterUser(string firstName, string lastName)
165 {
166 return m_remoteUserServices.SetupMasterUser(firstName, lastName);
167 }
168
169 /// <summary>
170 /// Retrieve the user information for the given master uuid.
171 /// </summary>
172 /// <param name="uuid"></param>
173 /// <returns></returns>
174 public UserProfileData SetupMasterUser(string firstName, string lastName, string password)
175 {
176 return m_remoteUserServices.SetupMasterUser(firstName, lastName, password);
177 }
178
179 /// <summary>
180 /// Retrieve the user information for the given master uuid.
181 /// </summary>
182 /// <param name="uuid"></param>
183 /// <returns></returns>
184 public UserProfileData SetupMasterUser(UUID uuid)
185 {
186 return m_remoteUserServices.SetupMasterUser(uuid);
187 }
188
189 public UUID AddUserProfile(string firstName, string lastName, string pass, uint regX, uint regY)
190 {
191 return m_remoteUserServices.AddUserProfile(firstName, lastName, pass, regX, regY);
192 }
193
194 public bool ResetUserPassword(string firstName, string lastName, string newPassword)
195 {
196 return m_remoteUserServices.ResetUserPassword(firstName, lastName, newPassword);
197 }
198
199 public bool UpdateUserProfile(UserProfileData userProfile)
200 {
201 return m_remoteUserServices.UpdateUserProfile(userProfile);
202 }
203
204 #region IUserServices Friend Methods
205 /// <summary>
206 /// Adds a new friend to the database for XUser
207 /// </summary>
208 /// <param name="friendlistowner">The agent that who's friends list is being added to</param>
209 /// <param name="friend">The agent that being added to the friends list of the friends list owner</param>
210 /// <param name="perms">A uint bit vector for set perms that the friend being added has; 0 = none, 1=This friend can see when they sign on, 2 = map, 4 edit objects </param>
211 public void AddNewUserFriend(UUID friendlistowner, UUID friend, uint perms)
212 {
213 m_remoteUserServices.AddNewUserFriend(friendlistowner, friend, perms);
214 }
215
216 /// <summary>
217 /// Delete friend on friendlistowner's friendlist.
218 /// </summary>
219 /// <param name="friendlistowner">The agent that who's friends list is being updated</param>
220 /// <param name="friend">The Ex-friend agent</param>
221 public void RemoveUserFriend(UUID friendlistowner, UUID friend)
222 {
223 m_remoteUserServices.RemoveUserFriend(friend, friend);
224 }
225
226 /// <summary>
227 /// Update permissions for friend on friendlistowner's friendlist.
228 /// </summary>
229 /// <param name="friendlistowner">The agent that who's friends list is being updated</param>
230 /// <param name="friend">The agent that is getting or loosing permissions</param>
231 /// <param name="perms">A uint bit vector for set perms that the friend being added has; 0 = none, 1=This friend can see when they sign on, 2 = map, 4 edit objects </param>
232 public void UpdateUserFriendPerms(UUID friendlistowner, UUID friend, uint perms)
233 {
234 m_remoteUserServices.UpdateUserFriendPerms(friendlistowner, friend, perms);
235 }
236 /// <summary>
237 /// Returns a list of FriendsListItems that describe the friends and permissions in the friend relationship for UUID friendslistowner
238 /// </summary>
239 /// <param name="friendlistowner">The agent that we're retreiving the friends Data.</param>
240 public List<FriendListItem> GetUserFriendList(UUID friendlistowner)
241 {
242 return m_remoteUserServices.GetUserFriendList(friendlistowner);
243 }
244
245 #endregion
246
247 /// Appearance
248 public AvatarAppearance GetUserAppearance(UUID user)
249 {
250 return m_remoteUserServices.GetUserAppearance(user);
251 }
252
253 public void UpdateUserAppearance(UUID user, AvatarAppearance appearance)
254 {
255 m_remoteUserServices.UpdateUserAppearance(user, appearance);
256 }
257
258 #region IMessagingService
259
260 public Dictionary<UUID, FriendRegionInfo> GetFriendRegionInfos(List<UUID> uuids)
261 {
262 return m_remoteUserServices.GetFriendRegionInfos(uuids);
263 }
264 #endregion
265
266 }
267}