aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Communications/Hypergrid/HGGridServices.cs
diff options
context:
space:
mode:
authorDiva Canto2009-09-26 21:14:41 -0700
committerDiva Canto2009-09-26 21:14:41 -0700
commit989382352dc5b5b75876607f6fc2f1f753f0fd15 (patch)
treef643df31517478613ec967d180a0e69f2c925194 /OpenSim/Region/Communications/Hypergrid/HGGridServices.cs
parentMoved all HG1 operations to HGGridConnector.cs and HypergridServerConnector.c... (diff)
downloadopensim-SC_OLD-989382352dc5b5b75876607f6fc2f1f753f0fd15.zip
opensim-SC_OLD-989382352dc5b5b75876607f6fc2f1f753f0fd15.tar.gz
opensim-SC_OLD-989382352dc5b5b75876607f6fc2f1f753f0fd15.tar.bz2
opensim-SC_OLD-989382352dc5b5b75876607f6fc2f1f753f0fd15.tar.xz
Poof! on Region.Communications.Hypergrid. Grid code deleted.
Diffstat (limited to 'OpenSim/Region/Communications/Hypergrid/HGGridServices.cs')
-rw-r--r--OpenSim/Region/Communications/Hypergrid/HGGridServices.cs1026
1 files changed, 0 insertions, 1026 deletions
diff --git a/OpenSim/Region/Communications/Hypergrid/HGGridServices.cs b/OpenSim/Region/Communications/Hypergrid/HGGridServices.cs
deleted file mode 100644
index 85bfab4..0000000
--- a/OpenSim/Region/Communications/Hypergrid/HGGridServices.cs
+++ /dev/null
@@ -1,1026 +0,0 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28
29using System;
30using System.Collections;
31using System.Collections.Generic;
32using System.Drawing;
33using System.Net;
34using System.Net.Sockets;
35using System.Reflection;
36using System.Runtime.Remoting;
37using System.Security.Authentication;
38using log4net;
39using Nwc.XmlRpc;
40using OpenMetaverse;
41using OpenMetaverse.Imaging;
42using OpenSim.Framework;
43using OpenSim.Framework.Communications;
44using OpenSim.Framework.Communications.Cache;
45using OpenSim.Framework.Servers;
46using OpenSim.Framework.Servers.HttpServer;
47using OpenSim.Region.Communications.OGS1;
48using OpenSim.Region.Framework.Scenes;
49using OpenSim.Services.Interfaces;
50// using OpenSim.Region.Environment.Modules.Framework;
51
52namespace OpenSim.Region.Communications.Hypergrid
53{
54 /// <summary>
55 /// This class encapsulates the main hypergrid functions related to creating and managing
56 /// hyperlinks, as well as processing all the inter-region comms between a region and
57 /// an hyperlinked region.
58 /// </summary>
59 public class HGGridServices : IGridServices, IHyperlink
60 {
61 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
62
63
64 public BaseHttpServer httpListener;
65 public NetworkServersInfo serversInfo;
66
67 protected List<RegionInfo> m_regionsOnInstance = new List<RegionInfo>();
68
69 // Hyperlink regions are hyperlinks on the map
70 protected List<RegionInfo> m_hyperlinkRegions = new List<RegionInfo>();
71
72 // Known regions are home regions of visiting foreign users.
73 // They are not on the map as static hyperlinks. They are dynamic hyperlinks, they go away when
74 // the visitor goes away. They are mapped to X=0 on the map.
75 // This is key-ed on agent ID
76 protected Dictionary<UUID, RegionInfo> m_knownRegions = new Dictionary<UUID, RegionInfo>();
77
78 protected UserProfileCacheService m_userProfileCache;
79 protected SceneManager m_sceneman;
80
81 private Dictionary<string, string> m_queuedGridSettings = new Dictionary<string, string>();
82
83 public virtual string gdebugRegionName
84 {
85 get { return "Override me"; }
86 set { ; }
87 }
88
89 public string rdebugRegionName
90 {
91 get { return _rdebugRegionName; }
92 set { _rdebugRegionName = value; }
93 }
94 private string _rdebugRegionName = String.Empty;
95
96 public virtual bool RegionLoginsEnabled
97 {
98 get { return true; }
99 set { ; }
100 }
101
102 public UserProfileCacheService UserProfileCache
103 {
104 set { m_userProfileCache = value; }
105 }
106
107 private Random random;
108
109 /// <summary>
110 /// Contructor. Adds "expect_hg_user" and "check" xmlrpc method handlers
111 /// </summary>
112 /// <param name="servers_info"></param>
113 public HGGridServices(NetworkServersInfo servers_info, SceneManager sman)
114 {
115 serversInfo = servers_info;
116 m_sceneman = sman;
117
118 random = new Random();
119
120 MainServer.Instance.AddXmlRPCHandler("link_region", LinkRegionRequest);
121 MainServer.Instance.AddXmlRPCHandler("expect_hg_user", ExpectHGUser);
122
123 HGNetworkServersInfo.Init(servers_info.AssetURL, servers_info.InventoryURL, servers_info.UserURL);
124 }
125
126 // see IGridServices
127 public virtual RegionCommsListener RegisterRegion(RegionInfo regionInfo)
128 {
129 // Region doesn't exist here. Trying to link remote region
130
131 m_log.Info("[HGrid]: Linking remote region " + regionInfo.ExternalHostName + ":" + regionInfo.HttpPort);
132 regionInfo.RegionID = LinkRegion(regionInfo); // UUID.Random();
133 if (!regionInfo.RegionID.Equals(UUID.Zero))
134 {
135 m_hyperlinkRegions.Add(regionInfo);
136 m_log.Info("[HGrid]: Successfully linked to region_uuid " + regionInfo.RegionID);
137
138 //Try get the map image
139 GetMapImage(regionInfo);
140 }
141 else
142 {
143 m_log.Info("[HGrid]: No such region " + regionInfo.ExternalHostName + ":" + regionInfo.HttpPort + "(" + regionInfo.InternalEndPoint.Port + ")");
144 }
145 // Note that these remote regions aren't registered in localBackend, so return null, no local listeners
146 return null;
147 }
148
149 // see IGridServices
150 public virtual bool DeregisterRegion(RegionInfo regionInfo)
151 {
152 if (m_hyperlinkRegions.Contains(regionInfo))
153 {
154 m_hyperlinkRegions.Remove(regionInfo);
155 return true;
156 }
157 foreach (KeyValuePair<UUID, RegionInfo> kvp in m_knownRegions)
158 {
159 if (kvp.Value == regionInfo)
160 {
161 m_knownRegions.Remove(kvp.Key);
162 return true;
163 }
164 }
165 return false;
166 }
167
168 public virtual Dictionary<string, string> GetGridSettings()
169 {
170 Dictionary<string, string> returnGridSettings = new Dictionary<string, string>();
171 lock (m_queuedGridSettings)
172 {
173 foreach (string Dictkey in m_queuedGridSettings.Keys)
174 {
175 returnGridSettings.Add(Dictkey, m_queuedGridSettings[Dictkey]);
176 }
177
178 m_queuedGridSettings.Clear();
179 }
180
181 return returnGridSettings;
182 }
183
184 // see IGridServices
185 public virtual List<SimpleRegionInfo> RequestNeighbours(uint x, uint y)
186 {
187 List<SimpleRegionInfo> neighbours = new List<SimpleRegionInfo>();
188 foreach (RegionInfo reg in m_hyperlinkRegions)
189 {
190 if (reg.RegionLocX != x || reg.RegionLocY != y)
191 {
192 //m_log.Debug("CommsManager- RequestNeighbours() - found a different region in list, checking location");
193 if ((reg.RegionLocX > (x - 2)) && (reg.RegionLocX < (x + 2)))
194 {
195 if ((reg.RegionLocY > (y - 2)) && (reg.RegionLocY < (y + 2)))
196 {
197 neighbours.Add(reg);
198 }
199 }
200 }
201 }
202
203 return neighbours;
204 }
205
206 /// <summary>
207 /// Request information about a region.
208 /// </summary>
209 /// <param name="regionHandle"></param>
210 /// <returns>
211 /// null on a failure to contact or get a response from the grid server
212 /// FIXME: Might be nicer to return a proper exception here since we could inform the client more about the
213 /// nature of the faiulre.
214 /// </returns>
215 public virtual RegionInfo RequestNeighbourInfo(UUID Region_UUID)
216 {
217 foreach (RegionInfo info in m_hyperlinkRegions)
218 {
219 if (info.RegionID == Region_UUID) return info;
220 }
221
222 // I don't trust region uuids to be unique...
223 //foreach (RegionInfo info in m_knownRegions.Values)
224 //{
225 // if (info.RegionID == Region_UUID) return info;
226 //}
227
228 return null;
229 }
230
231 /// <summary>
232 /// Request information about a region.
233 /// </summary>
234 /// <param name="regionHandle"></param>
235 /// <returns></returns>
236 public virtual RegionInfo RequestNeighbourInfo(ulong regionHandle)
237 {
238 //m_log.Debug(" >> RequestNeighbourInfo for " + regionHandle);
239 foreach (RegionInfo info in m_hyperlinkRegions)
240 {
241 //m_log.Debug(" .. " + info.RegionHandle);
242 if (info.RegionHandle == regionHandle) return info;
243 }
244
245 foreach (RegionInfo info in m_knownRegions.Values)
246 {
247 if (info.RegionHandle == regionHandle)
248 {
249 //m_log.Debug("XXX------ known region " + info.RegionHandle);
250 return info;
251 }
252 }
253
254 return null;
255 }
256
257 public virtual RegionInfo RequestNeighbourInfo(string name)
258 {
259 foreach (RegionInfo info in m_hyperlinkRegions)
260 {
261 //m_log.Debug(" .. " + info.RegionHandle);
262 if (info.RegionName == name) return info;
263 }
264
265 foreach (RegionInfo info in m_knownRegions.Values)
266 {
267 if (info.RegionName == name)
268 {
269 //m_log.Debug("XXX------ known region " + info.RegionHandle);
270 return info;
271 }
272 }
273
274 return null;
275 }
276
277 public virtual RegionInfo RequestNeighbourInfo(string hostName, uint port)
278 {
279 foreach (RegionInfo info in m_hyperlinkRegions)
280 {
281 //m_log.Debug(" .. " + info.RegionHandle);
282 if ((info.ExternalHostName == hostName) && (info.HttpPort == port))
283 return info;
284 }
285
286 foreach (RegionInfo info in m_knownRegions.Values)
287 {
288 if ((info.ExternalHostName == hostName) && (info.HttpPort == port))
289 {
290 //m_log.Debug("XXX------ known region " + info.RegionHandle);
291 return info;
292 }
293 }
294
295 return null;
296 }
297
298 public virtual RegionInfo RequestClosestRegion(string regionName)
299 {
300 foreach (RegionInfo info in m_hyperlinkRegions)
301 {
302 if (info.RegionName == regionName) return info;
303 }
304
305 return null;
306 }
307
308 /// <summary>
309 ///
310 /// </summary>
311 /// <param name="minX"></param>
312 /// <param name="minY"></param>
313 /// <param name="maxX"></param>
314 /// <param name="maxY"></param>
315 /// <returns></returns>
316 public virtual List<MapBlockData> RequestNeighbourMapBlocks(int minX, int minY, int maxX, int maxY)
317 {
318 List<MapBlockData> neighbours = new List<MapBlockData>();
319
320 foreach (RegionInfo regInfo in m_hyperlinkRegions)
321 {
322 if (((regInfo.RegionLocX >= minX) && (regInfo.RegionLocX <= maxX)) &&
323 ((regInfo.RegionLocY >= minY) && (regInfo.RegionLocY <= maxY)))
324 {
325 MapBlockData map = new MapBlockData();
326 map.Name = regInfo.RegionName;
327 map.X = (ushort)regInfo.RegionLocX;
328 map.Y = (ushort)regInfo.RegionLocY;
329 map.WaterHeight = (byte)regInfo.RegionSettings.WaterHeight;
330 map.MapImageId = regInfo.RegionSettings.TerrainImageID;
331 // m_log.Debug("ImgID: " + map.MapImageId);
332 map.Agents = 1;
333 map.RegionFlags = 72458694;
334 map.Access = regInfo.AccessLevel;
335 neighbours.Add(map);
336 }
337 }
338
339 return neighbours;
340 }
341
342
343 protected virtual void GetMapImage(RegionInfo info)
344 {
345 try
346 {
347 string regionimage = "regionImage" + info.RegionID.ToString();
348 regionimage = regionimage.Replace("-", "");
349
350 WebClient c = new WebClient();
351 string uri = "http://" + info.ExternalHostName + ":" + info.HttpPort + "/index.php?method=" + regionimage;
352 //m_log.Debug("JPEG: " + uri);
353 c.DownloadFile(uri, info.RegionID.ToString() + ".jpg");
354 Bitmap m = new Bitmap(info.RegionID.ToString() + ".jpg");
355 //m_log.Debug("Size: " + m.PhysicalDimension.Height + "-" + m.PhysicalDimension.Width);
356 byte[] imageData = OpenJPEG.EncodeFromImage(m, true);
357 AssetBase ass = new AssetBase(UUID.Random(), "region " + info.RegionID.ToString());
358 info.RegionSettings.TerrainImageID = ass.FullID;
359 ass.Type = (int)AssetType.Texture;
360 ass.Temporary = false;
361 ass.Local = true;
362 ass.Data = imageData;
363
364 m_sceneman.CurrentOrFirstScene.AssetService.Store(ass);
365
366 }
367 catch // LEGIT: Catching problems caused by OpenJPEG p/invoke
368 {
369 m_log.Warn("[HGrid]: Failed getting/storing map image, because it is probably already in the cache");
370 }
371 }
372
373 // A little ugly, since this code is exactly the same as OSG1's, and we're already
374 // calling that for when the region in in grid mode... (for the grid regions)
375 //
376 public virtual LandData RequestLandData (ulong regionHandle, uint x, uint y)
377 {
378 m_log.DebugFormat("[HGrid]: requests land data in {0}, at {1}, {2}",
379 regionHandle, x, y);
380
381 // Remote region
382
383 Hashtable hash = new Hashtable();
384 hash["region_handle"] = regionHandle.ToString();
385 hash["x"] = x.ToString();
386 hash["y"] = y.ToString();
387
388 IList paramList = new ArrayList();
389 paramList.Add(hash);
390 LandData landData = null;
391
392 try
393 {
394 RegionInfo info = RequestNeighbourInfo(regionHandle);
395 if (info != null) // just to be sure
396 {
397 XmlRpcRequest request = new XmlRpcRequest("land_data", paramList);
398 string uri = "http://" + info.ExternalEndPoint.Address + ":" + info.HttpPort + "/";
399 XmlRpcResponse response = request.Send(uri, 10000);
400 if (response.IsFault)
401 {
402 m_log.ErrorFormat("[HGrid]: remote call returned an error: {0}", response.FaultString);
403 }
404 else
405 {
406 hash = (Hashtable)response.Value;
407 try
408 {
409 landData = new LandData();
410 landData.AABBMax = Vector3.Parse((string)hash["AABBMax"]);
411 landData.AABBMin = Vector3.Parse((string)hash["AABBMin"]);
412 landData.Area = Convert.ToInt32(hash["Area"]);
413 landData.AuctionID = Convert.ToUInt32(hash["AuctionID"]);
414 landData.Description = (string)hash["Description"];
415 landData.Flags = Convert.ToUInt32(hash["Flags"]);
416 landData.GlobalID = new UUID((string)hash["GlobalID"]);
417 landData.Name = (string)hash["Name"];
418 landData.OwnerID = new UUID((string)hash["OwnerID"]);
419 landData.SalePrice = Convert.ToInt32(hash["SalePrice"]);
420 landData.SnapshotID = new UUID((string)hash["SnapshotID"]);
421 landData.UserLocation = Vector3.Parse((string)hash["UserLocation"]);
422 m_log.DebugFormat("[HGrid]: Got land data for parcel {0}", landData.Name);
423 }
424 catch (Exception e)
425 {
426 m_log.Error("[HGrid]: Got exception while parsing land-data:", e);
427 }
428 }
429 }
430 else m_log.WarnFormat("[HGrid]: Couldn't find region with handle {0}", regionHandle);
431 }
432 catch (Exception e)
433 {
434 m_log.ErrorFormat("[HGrid]: Couldn't contact region {0}: {1}", regionHandle, e);
435 }
436
437 return landData;
438 }
439
440 // Grid Request Processing
441 public virtual List<RegionInfo> RequestNamedRegions (string name, int maxNumber)
442 {
443 List<RegionInfo> infos = new List<RegionInfo>();
444 foreach (RegionInfo info in m_hyperlinkRegions)
445 {
446 if (info.RegionName.ToLower().Contains(name))
447 {
448 infos.Add(info);
449 }
450 }
451 return infos;
452 }
453
454
455 private UUID LinkRegion(RegionInfo info)
456 {
457 UUID uuid = UUID.Zero;
458
459 Hashtable hash = new Hashtable();
460 hash["region_name"] = info.RegionName;
461
462 IList paramList = new ArrayList();
463 paramList.Add(hash);
464
465 XmlRpcRequest request = new XmlRpcRequest("link_region", paramList);
466 string uri = "http://" + info.ExternalEndPoint.Address + ":" + info.HttpPort + "/";
467 m_log.Debug("[HGrid]: Linking to " + uri);
468 XmlRpcResponse response = request.Send(uri, 10000);
469 if (response.IsFault)
470 {
471 m_log.ErrorFormat("[HGrid]: remote call returned an error: {0}", response.FaultString);
472 }
473 else
474 {
475 hash = (Hashtable)response.Value;
476 //foreach (Object o in hash)
477 // m_log.Debug(">> " + ((DictionaryEntry)o).Key + ":" + ((DictionaryEntry)o).Value);
478 try
479 {
480 UUID.TryParse((string)hash["uuid"], out uuid);
481 info.RegionID = uuid;
482 if ((string)hash["handle"] != null)
483 {
484 info.regionSecret = (string)hash["handle"];
485 //m_log.Debug(">> HERE: " + info.regionSecret);
486 }
487 if (hash["region_image"] != null)
488 {
489 UUID img = UUID.Zero;
490 UUID.TryParse((string)hash["region_image"], out img);
491 info.RegionSettings.TerrainImageID = img;
492 }
493 if (hash["region_name"] != null)
494 {
495 info.RegionName = (string)hash["region_name"];
496 //m_log.Debug(">> " + info.RegionName);
497 }
498 if (hash["internal_port"] != null)
499 {
500 int port = Convert.ToInt32((string)hash["internal_port"]);
501 info.InternalEndPoint = new IPEndPoint(IPAddress.Parse("0.0.0.0"), port);
502 //m_log.Debug(">> " + info.InternalEndPoint.ToString());
503 }
504 if (hash["remoting_port"] != null)
505 {
506 info.RemotingPort = Convert.ToUInt32(hash["remoting_port"]);
507 //m_log.Debug(">> " + info.RemotingPort);
508 }
509
510 }
511 catch (Exception e)
512 {
513 m_log.Error("[HGrid]: Got exception while parsing hyperlink response " + e.StackTrace);
514 }
515 }
516 return uuid;
517 }
518
519 /// <summary>
520 /// Someone wants to link to us
521 /// </summary>
522 /// <param name="request"></param>
523 /// <returns></returns>
524 public XmlRpcResponse LinkRegionRequest(XmlRpcRequest request, IPEndPoint remoteClient)
525 {
526 Hashtable requestData = (Hashtable)request.Params[0];
527 //string host = (string)requestData["host"];
528 //string portstr = (string)requestData["port"];
529 string name = (string)requestData["region_name"];
530
531 m_log.DebugFormat("[HGrid]: Hyperlink request");
532
533
534 RegionInfo regInfo = null;
535 foreach (RegionInfo r in m_regionsOnInstance)
536 {
537 if ((r.RegionName != null) && (name != null) && (r.RegionName.ToLower() == name.ToLower()))
538 {
539 regInfo = r;
540 break;
541 }
542 }
543
544 if (regInfo == null)
545 regInfo = m_regionsOnInstance[0]; // Send out the first region
546
547 Hashtable hash = new Hashtable();
548 hash["uuid"] = regInfo.RegionID.ToString();
549 hash["handle"] = regInfo.RegionHandle.ToString();
550 //m_log.Debug(">> Here " + regInfo.RegionHandle);
551 hash["region_image"] = regInfo.RegionSettings.TerrainImageID.ToString();
552 hash["region_name"] = regInfo.RegionName;
553 hash["internal_port"] = regInfo.InternalEndPoint.Port.ToString();
554 hash["remoting_port"] = ConfigSettings.DefaultRegionRemotingPort.ToString();
555 //m_log.Debug(">> Here: " + regInfo.InternalEndPoint.Port);
556
557
558 XmlRpcResponse response = new XmlRpcResponse();
559 response.Value = hash;
560 return response;
561 }
562
563 public bool InformRegionOfUser(RegionInfo regInfo, AgentCircuitData agentData)
564 {
565 //ulong regionHandle = regInfo.RegionHandle;
566 try
567 {
568 //regionHandle = Convert.ToUInt64(regInfo.regionSecret);
569 m_log.Info("[HGrid]: InformRegionOfUser: Remote hyperlinked region " + regInfo.regionSecret);
570 }
571 catch
572 {
573 m_log.Info("[HGrid]: InformRegionOfUser: Local grid region " + regInfo.regionSecret);
574 }
575
576 string capsPath = agentData.CapsPath;
577 Hashtable loginParams = new Hashtable();
578 loginParams["session_id"] = agentData.SessionID.ToString();
579 loginParams["secure_session_id"] = agentData.SecureSessionID.ToString();
580
581 loginParams["firstname"] = agentData.firstname;
582 loginParams["lastname"] = agentData.lastname;
583
584 loginParams["agent_id"] = agentData.AgentID.ToString();
585 loginParams["circuit_code"] = agentData.circuitcode.ToString();
586 loginParams["startpos_x"] = agentData.startpos.X.ToString();
587 loginParams["startpos_y"] = agentData.startpos.Y.ToString();
588 loginParams["startpos_z"] = agentData.startpos.Z.ToString();
589 loginParams["caps_path"] = capsPath;
590
591 CachedUserInfo u = m_userProfileCache.GetUserDetails(agentData.AgentID);
592 if (u != null && u.UserProfile != null)
593 {
594 loginParams["region_uuid"] = u.UserProfile.HomeRegionID.ToString(); // This seems to be always Zero
595 //m_log.Debug(" --------- Home Region UUID -------");
596 //m_log.Debug(" >> " + loginParams["region_uuid"] + " <<");
597 //m_log.Debug(" --------- ---------------- -------");
598
599 //string serverURI = "";
600 //if (u.UserProfile is ForeignUserProfileData)
601 // serverURI = Util.ServerURI(((ForeignUserProfileData)u.UserProfile).UserServerURI);
602 //loginParams["userserver_id"] = (serverURI == "") || (serverURI == null) ? HGNetworkServersInfo.Singleton.LocalUserServerURI : serverURI;
603
604 //serverURI = HGNetworkServersInfo.ServerURI(u.UserProfile.UserAssetURI);
605 //loginParams["assetserver_id"] = (serverURI == "") || (serverURI == null) ? HGNetworkServersInfo.Singleton.LocalAssetServerURI : serverURI;
606
607 //serverURI = HGNetworkServersInfo.ServerURI(u.UserProfile.UserInventoryURI);
608 //loginParams["inventoryserver_id"] = (serverURI == "") || (serverURI == null) ? HGNetworkServersInfo.Singleton.LocalInventoryServerURI : serverURI;
609
610 loginParams["root_folder_id"] = u.UserProfile.RootInventoryFolderID;
611
612 RegionInfo rinfo = RequestNeighbourInfo(u.UserProfile.HomeRegion);
613 if (rinfo != null)
614 {
615 loginParams["internal_port"] = rinfo.InternalEndPoint.Port.ToString();
616 if (!IsLocalUser(u))
617 {
618 loginParams["regionhandle"] = rinfo.regionSecret; // user.CurrentAgent.Handle.ToString();
619 //m_log.Debug("XXX--- informregionofuser (foreign user) here handle: " + rinfo.regionSecret);
620
621 loginParams["home_address"] = ((ForeignUserProfileData)(u.UserProfile)).UserHomeAddress;
622 loginParams["home_port"] = ((ForeignUserProfileData)(u.UserProfile)).UserHomePort;
623 loginParams["home_remoting"] = ((ForeignUserProfileData)(u.UserProfile)).UserHomeRemotingPort;
624 }
625 else
626 {
627 //m_log.Debug("XXX--- informregionofuser (local user) here handle: " + rinfo.regionSecret);
628
629 //// local user about to jump out, let's process the name
630 // On second thoughts, let's not do this for the *user*; let's only do it for the *agent*
631 //loginParams["firstname"] = agentData.firstname + "." + agentData.lastname;
632 //loginParams["lastname"] = serversInfo.UserURL;
633
634 // local user, first time out. let's ask the grid about this user's home region
635 loginParams["regionhandle"] = u.UserProfile.HomeRegion.ToString(); // user.CurrentAgent.Handle.ToString();
636
637 loginParams["home_address"] = rinfo.ExternalHostName;
638 m_log.Debug(" --------- Home Address -------");
639 m_log.Debug(" >> " + loginParams["home_address"] + " <<");
640 m_log.Debug(" --------- ------------ -------");
641 loginParams["home_port"] = rinfo.HttpPort.ToString();
642 loginParams["home_remoting"] = ConfigSettings.DefaultRegionRemotingPort.ToString(); ;
643 }
644 }
645 else
646 {
647 m_log.Warn("[HGrid]: User's home region info not found: " + u.UserProfile.HomeRegionX + ", " + u.UserProfile.HomeRegionY);
648 }
649 }
650
651 ArrayList SendParams = new ArrayList();
652 SendParams.Add(loginParams);
653
654 // Send
655 string uri = "http://" + regInfo.ExternalHostName + ":" + regInfo.HttpPort + "/";
656 //m_log.Debug("XXX uri: " + uri);
657 XmlRpcRequest request = new XmlRpcRequest("expect_hg_user", SendParams);
658 XmlRpcResponse reply;
659 try
660 {
661 reply = request.Send(uri, 6000);
662 }
663 catch (Exception e)
664 {
665 m_log.Warn("[HGrid]: Failed to notify region about user. Reason: " + e.Message);
666 return false;
667 }
668
669 if (!reply.IsFault)
670 {
671 bool responseSuccess = true;
672 if (reply.Value != null)
673 {
674 Hashtable resp = (Hashtable)reply.Value;
675 if (resp.ContainsKey("success"))
676 {
677 if ((string)resp["success"] == "FALSE")
678 {
679 responseSuccess = false;
680 }
681 }
682 }
683 if (responseSuccess)
684 {
685 m_log.Info("[HGrid]: Successfully informed remote region about user " + agentData.AgentID);
686 return true;
687 }
688 else
689 {
690 m_log.ErrorFormat("[HGrid]: Region responded that it is not available to receive clients");
691 return false;
692 }
693 }
694 else
695 {
696 m_log.ErrorFormat("[HGrid]: XmlRpc request to region failed with message {0}, code {1} ", reply.FaultString, reply.FaultCode);
697 return false;
698 }
699 }
700
701
702 /// <summary>
703 /// Received from other HGrid nodes when a user wants to teleport here. This call allows
704 /// the region to prepare for direct communication from the client. Sends back an empty
705 /// xmlrpc response on completion.
706 /// This is somewhat similar to OGS1's ExpectUser, but with the additional task of
707 /// registering the user in the local user cache.
708 /// </summary>
709 /// <param name="request"></param>
710 /// <returns></returns>
711 public XmlRpcResponse ExpectHGUser(XmlRpcRequest request, IPEndPoint remoteClient)
712 {
713 Hashtable requestData = (Hashtable)request.Params[0];
714 ForeignUserProfileData userData = new ForeignUserProfileData();
715
716 userData.FirstName = (string)requestData["firstname"];
717 userData.SurName = (string)requestData["lastname"];
718 userData.ID = new UUID((string)requestData["agent_id"]);
719 userData.HomeLocation = new Vector3((float)Convert.ToDecimal((string)requestData["startpos_x"]),
720 (float)Convert.ToDecimal((string)requestData["startpos_y"]),
721 (float)Convert.ToDecimal((string)requestData["startpos_z"]));
722
723 userData.UserServerURI = (string)requestData["userserver_id"];
724 userData.UserAssetURI = (string)requestData["assetserver_id"];
725 userData.UserInventoryURI = (string)requestData["inventoryserver_id"];
726
727 UUID rootID = UUID.Zero;
728 UUID.TryParse((string)requestData["root_folder_id"], out rootID);
729 userData.RootInventoryFolderID = rootID;
730
731 UUID uuid = UUID.Zero;
732 UUID.TryParse((string)requestData["region_uuid"], out uuid);
733 userData.HomeRegionID = uuid; // not quite comfortable about this...
734 ulong userRegionHandle = Convert.ToUInt64((string)requestData["regionhandle"]);
735 //userData.HomeRegion = userRegionHandle;
736 userData.UserHomeAddress = (string)requestData["home_address"];
737 userData.UserHomePort = (string)requestData["home_port"];
738 int userhomeinternalport = Convert.ToInt32((string)requestData["internal_port"]);
739 userData.UserHomeRemotingPort = (string)requestData["home_remoting"];
740
741
742 m_log.DebugFormat("[HGrid]: Prepare for connection from {0} {1} (@{2}) UUID={3}",
743 userData.FirstName, userData.SurName, userData.UserServerURI, userData.ID);
744 m_log.Debug("[HGrid]: home_address: " + userData.UserHomeAddress +
745 "; home_port: " + userData.UserHomePort + "; remoting: " + userData.UserHomeRemotingPort);
746
747 XmlRpcResponse resp = new XmlRpcResponse();
748
749 // Let's check if someone is trying to get in with a stolen local identity.
750 // The need for this test is a consequence of not having truly global names :-/
751 CachedUserInfo uinfo = m_userProfileCache.GetUserDetails(userData.ID);
752 if ((uinfo != null) && !(uinfo.UserProfile is ForeignUserProfileData))
753 {
754 m_log.WarnFormat("[HGrid]: Foreign user trying to get in with local identity. Access denied.");
755 Hashtable respdata = new Hashtable();
756 respdata["success"] = "FALSE";
757 respdata["reason"] = "Foreign user has the same ID as a local user.";
758 resp.Value = respdata;
759 return resp;
760 }
761
762 if (!RegionLoginsEnabled)
763 {
764 m_log.InfoFormat(
765 "[HGrid]: Denying access for user {0} {1} because region login is currently disabled",
766 userData.FirstName, userData.SurName);
767
768 Hashtable respdata = new Hashtable();
769 respdata["success"] = "FALSE";
770 respdata["reason"] = "region login currently disabled";
771 resp.Value = respdata;
772 }
773 else
774 {
775 // Finally, everything looks ok
776 //m_log.Debug("XXX---- EVERYTHING OK ---XXX");
777
778 // 1 - Preload the user data
779 m_userProfileCache.PreloadUserCache(userData);
780
781 if (m_knownRegions.ContainsKey(userData.ID))
782 {
783 // This was left here when the user departed
784 m_knownRegions.Remove(userData.ID);
785 }
786
787 // 2 - Load the region info into list of known regions
788 RegionInfo rinfo = new RegionInfo();
789 rinfo.RegionID = userData.HomeRegionID;
790 rinfo.ExternalHostName = userData.UserHomeAddress;
791 rinfo.HttpPort = Convert.ToUInt32(userData.UserHomePort);
792 rinfo.RemotingPort = Convert.ToUInt32(userData.UserHomeRemotingPort);
793 rinfo.RegionID = userData.HomeRegionID;
794 // X=0 on the map
795 rinfo.RegionLocX = 0;
796 rinfo.RegionLocY = (uint)(random.Next(0, Int32.MaxValue)); //(uint)m_knownRegions.Count;
797 rinfo.regionSecret = userRegionHandle.ToString();
798 //m_log.Debug("XXX--- Here: handle = " + rinfo.regionSecret);
799 try
800 {
801 rinfo.InternalEndPoint = new IPEndPoint(IPAddress.Parse("0.0.0.0"), (int)userhomeinternalport);
802 }
803 catch (Exception e)
804 {
805 m_log.Warn("[HGrid]: Exception while constructing internal endpoint: " + e);
806 }
807 rinfo.RemotingAddress = rinfo.ExternalEndPoint.Address.ToString(); //userData.UserHomeAddress;
808
809 if (!IsComingHome(userData))
810 {
811 // Change the user's home region here!!!
812 userData.HomeRegion = rinfo.RegionHandle;
813 }
814
815 if (!m_knownRegions.ContainsKey(userData.ID))
816 m_knownRegions.Add(userData.ID, rinfo);
817
818 // 3 - Send the reply
819 Hashtable respdata = new Hashtable();
820 respdata["success"] = "TRUE";
821 resp.Value = respdata;
822
823 DumpUserData(userData);
824 DumpRegionData(rinfo);
825
826 }
827
828 return resp;
829 }
830
831 public bool SendUserInformation(RegionInfo regInfo, AgentCircuitData agentData)
832 {
833 CachedUserInfo uinfo = m_userProfileCache.GetUserDetails(agentData.AgentID);
834
835 if ((IsLocalUser(uinfo) && IsHyperlinkRegion(regInfo.RegionHandle)) ||
836 (!IsLocalUser(uinfo) && !IsGoingHome(uinfo, regInfo)))
837 {
838 m_log.Info("[HGrid]: Local user is going to foreign region or foreign user is going elsewhere");
839 if (!InformRegionOfUser(regInfo, agentData))
840 {
841 m_log.Warn("[HGrid]: Could not inform remote region of transferring user.");
842 return false;
843 }
844 }
845 //if ((uinfo == null) || !IsGoingHome(uinfo, regInfo))
846 //{
847 // m_log.Info("[HGrid]: User seems to be going to foreign region.");
848 // if (!InformRegionOfUser(regInfo, agentData))
849 // {
850 // m_log.Warn("[HGrid]: Could not inform remote region of transferring user.");
851 // return false;
852 // }
853 //}
854 //else
855 // m_log.Info("[HGrid]: User seems to be going home " + uinfo.UserProfile.FirstName + " " + uinfo.UserProfile.SurName);
856
857 // May need to change agent's name
858 if (IsLocalUser(uinfo) && IsHyperlinkRegion(regInfo.RegionHandle))
859 {
860 agentData.firstname = agentData.firstname + "." + agentData.lastname;
861 agentData.lastname = "@" + serversInfo.UserURL.Replace("http://", ""); ; //HGNetworkServersInfo.Singleton.LocalUserServerURI;
862 }
863
864 return true;
865 }
866
867
868 #region Methods triggered by calls from external instances
869
870 /// <summary>
871 ///
872 /// </summary>
873 /// <param name="regionHandle"></param>
874 /// <param name="agentData"></param>
875 /// <returns></returns>
876 public void AdjustUserInformation(AgentCircuitData agentData)
877 {
878 CachedUserInfo uinfo = m_userProfileCache.GetUserDetails(agentData.AgentID);
879 if ((uinfo != null) && (uinfo.UserProfile != null) &&
880 (IsLocalUser(uinfo) || !(uinfo.UserProfile is ForeignUserProfileData)))
881 {
882 //m_log.Debug("---------------> Local User!");
883 string[] parts = agentData.firstname.Split(new char[] { '.' });
884 if (parts.Length == 2)
885 {
886 agentData.firstname = parts[0];
887 agentData.lastname = parts[1];
888 }
889 }
890 //else
891 // m_log.Debug("---------------> Foreign User!");
892 }
893 #endregion
894
895
896 #region IHyperGrid interface
897
898 public virtual bool IsHyperlinkRegion(ulong ihandle)
899 {
900 if (GetHyperlinkRegion(ihandle) == null)
901 return false;
902 else
903 return true;
904 }
905
906 public virtual RegionInfo GetHyperlinkRegion(ulong ihandle)
907 {
908 foreach (RegionInfo info in m_hyperlinkRegions)
909 {
910 if (info.RegionHandle == ihandle)
911 return info;
912 }
913
914 foreach (RegionInfo info in m_knownRegions.Values)
915 {
916 if (info.RegionHandle == ihandle)
917 return info;
918 }
919
920 return null;
921 }
922
923 public virtual ulong FindRegionHandle(ulong ihandle)
924 {
925 long ohandle = -1;
926 List<RegionInfo> rlist = new List<RegionInfo>(m_hyperlinkRegions);
927 rlist.AddRange(m_knownRegions.Values);
928 foreach (RegionInfo info in rlist)
929 {
930 if (info.RegionHandle == ihandle)
931 {
932 try
933 {
934 ohandle = Convert.ToInt64(info.regionSecret);
935 m_log.Info("[HGrid] remote region " + ohandle);
936 }
937 catch
938 {
939 m_log.Error("[HGrid] Could not convert secret for " + ihandle + " (" + info.regionSecret + ")");
940 }
941 break;
942 }
943 }
944 return ohandle < 0 ? ihandle : (ulong)ohandle;
945 }
946 #endregion
947
948 #region Misc
949
950 protected bool IsComingHome(ForeignUserProfileData userData)
951 {
952 return false; //(userData.UserServerURI == HGNetworkServersInfo.Singleton.LocalUserServerURI);
953 }
954
955 protected bool IsGoingHome(CachedUserInfo uinfo, RegionInfo rinfo)
956 {
957 return false;
958 //if (uinfo.UserProfile == null)
959 // return false;
960
961 //string userUserServerURI = String.Empty;
962 //if (uinfo.UserProfile is ForeignUserProfileData)
963 //{
964 // userUserServerURI = HGNetworkServersInfo.ServerURI(((ForeignUserProfileData)uinfo.UserProfile).UserServerURI);
965 //}
966
967 //return ((uinfo.UserProfile.HomeRegionID == rinfo.RegionID) &&
968 // (userUserServerURI != HGNetworkServersInfo.Singleton.LocalUserServerURI));
969 }
970
971 protected bool IsLocalUser(CachedUserInfo uinfo)
972 {
973 return true;
974 //if (uinfo == null)
975 // return true;
976
977 //if (uinfo.UserProfile is ForeignUserProfileData)
978 // return HGNetworkServersInfo.Singleton.IsLocalUser(((ForeignUserProfileData)uinfo.UserProfile).UserServerURI);
979 //else
980 // return true;
981
982 }
983
984 protected bool IsLocalRegion(ulong handle)
985 {
986 foreach (RegionInfo reg in m_regionsOnInstance)
987 if (reg.RegionHandle == handle)
988 return true;
989 return false;
990 }
991
992 private void DumpUserData(ForeignUserProfileData userData)
993 {
994 m_log.Info(" ------------ User Data Dump ----------");
995 m_log.Info(" >> Name: " + userData.FirstName + " " + userData.SurName);
996 m_log.Info(" >> HomeID: " + userData.HomeRegionID);
997 m_log.Info(" >> HomeHandle: " + userData.HomeRegion);
998 m_log.Info(" >> HomeX: " + userData.HomeRegionX);
999 m_log.Info(" >> HomeY: " + userData.HomeRegionY);
1000 m_log.Info(" >> UserServer: " + userData.UserServerURI);
1001 m_log.Info(" >> InvServer: " + userData.UserInventoryURI);
1002 m_log.Info(" >> AssetServer: " + userData.UserAssetURI);
1003 m_log.Info(" ------------ -------------- ----------");
1004 }
1005
1006 private void DumpRegionData(RegionInfo rinfo)
1007 {
1008 m_log.Info(" ------------ Region Data Dump ----------");
1009 m_log.Info(" >> handle: " + rinfo.RegionHandle);
1010 m_log.Info(" >> coords: " + rinfo.RegionLocX + ", " + rinfo.RegionLocY);
1011 m_log.Info(" >> secret: " + rinfo.regionSecret);
1012 m_log.Info(" >> remoting address: " + rinfo.RemotingAddress);
1013 m_log.Info(" >> remoting port: " + rinfo.RemotingPort);
1014 m_log.Info(" >> external host name: " + rinfo.ExternalHostName);
1015 m_log.Info(" >> http port: " + rinfo.HttpPort);
1016 m_log.Info(" >> external EP address: " + rinfo.ExternalEndPoint.Address);
1017 m_log.Info(" >> external EP port: " + rinfo.ExternalEndPoint.Port);
1018 m_log.Info(" ------------ -------------- ----------");
1019 }
1020
1021
1022 #endregion
1023
1024
1025 }
1026}