aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/HGGridConnector.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/HGGridConnector.cs')
-rw-r--r--OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/HGGridConnector.cs293
1 files changed, 262 insertions, 31 deletions
diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/HGGridConnector.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/HGGridConnector.cs
index 0c2a835..c8062d7 100644
--- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/HGGridConnector.cs
+++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/HGGridConnector.cs
@@ -31,6 +31,7 @@ using System.Net;
31using System.Reflection; 31using System.Reflection;
32using System.Xml; 32using System.Xml;
33 33
34using OpenSim.Framework.Communications.Cache;
34using OpenSim.Framework; 35using OpenSim.Framework;
35using OpenSim.Region.Framework.Interfaces; 36using OpenSim.Region.Framework.Interfaces;
36using OpenSim.Region.Framework.Scenes; 37using OpenSim.Region.Framework.Scenes;
@@ -47,15 +48,19 @@ using Nini.Config;
47 48
48namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid 49namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid
49{ 50{
50 public class HGGridConnector : ISharedRegionModule, IGridService 51 public class HGGridConnector : ISharedRegionModule, IGridService, IHyperlinkService
51 { 52 {
52 private static readonly ILog m_log = 53 private static readonly ILog m_log =
53 LogManager.GetLogger( 54 LogManager.GetLogger(
54 MethodBase.GetCurrentMethod().DeclaringType); 55 MethodBase.GetCurrentMethod().DeclaringType);
56 private static string LocalAssetServerURI, LocalInventoryServerURI, LocalUserServerURI;
55 57
56 private bool m_Enabled = false; 58 private bool m_Enabled = false;
57 private bool m_Initialized = false; 59 private bool m_Initialized = false;
58 60
61 private Scene m_aScene;
62 private Dictionary<ulong, Scene> m_LocalScenes = new Dictionary<ulong, Scene>();
63
59 private IGridService m_GridServiceConnector; 64 private IGridService m_GridServiceConnector;
60 private HypergridServiceConnector m_HypergridServiceConnector; 65 private HypergridServiceConnector m_HypergridServiceConnector;
61 66
@@ -130,6 +135,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid
130 135
131 public void PostInitialise() 136 public void PostInitialise()
132 { 137 {
138 ((ISharedRegionModule)m_GridServiceConnector).PostInitialise();
133 } 139 }
134 140
135 public void Close() 141 public void Close()
@@ -141,12 +147,18 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid
141 if (!m_Enabled) 147 if (!m_Enabled)
142 return; 148 return;
143 149
150 m_LocalScenes[scene.RegionInfo.RegionHandle] = scene;
144 scene.RegisterModuleInterface<IGridService>(this); 151 scene.RegisterModuleInterface<IGridService>(this);
152 scene.RegisterModuleInterface<IHyperlinkService>(this);
153
154 ((ISharedRegionModule)m_GridServiceConnector).AddRegion(scene);
145 155
146 } 156 }
147 157
148 public void RemoveRegion(Scene scene) 158 public void RemoveRegion(Scene scene)
149 { 159 {
160 m_LocalScenes.Remove(scene.RegionInfo.RegionHandle);
161 ((ISharedRegionModule)m_GridServiceConnector).RemoveRegion(scene);
150 } 162 }
151 163
152 public void RegionLoaded(Scene scene) 164 public void RegionLoaded(Scene scene)
@@ -156,29 +168,28 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid
156 168
157 if (!m_Initialized) 169 if (!m_Initialized)
158 { 170 {
171 m_aScene = scene;
172 LocalAssetServerURI = m_aScene.CommsManager.NetworkServersInfo.UserURL;
173 LocalInventoryServerURI = m_aScene.CommsManager.NetworkServersInfo.InventoryURL;
174 LocalUserServerURI = m_aScene.CommsManager.NetworkServersInfo.UserURL;
175
159 m_HypergridServiceConnector = new HypergridServiceConnector(scene.AssetService); 176 m_HypergridServiceConnector = new HypergridServiceConnector(scene.AssetService);
177
160 HGCommands hgCommands = new HGCommands(this, scene); 178 HGCommands hgCommands = new HGCommands(this, scene);
161 MainConsole.Instance.Commands.AddCommand("HGGridServicesConnector", false, "linkk-region", 179 MainConsole.Instance.Commands.AddCommand("HGGridServicesConnector", false, "link-region",
162 "link-region <Xloc> <Yloc> <HostName>:<HttpPort>[:<RemoteRegionName>] <cr>", 180 "link-region <Xloc> <Yloc> <HostName>:<HttpPort>[:<RemoteRegionName>] <cr>",
163 "Link a hypergrid region", hgCommands.RunCommand); 181 "Link a hypergrid region", hgCommands.RunCommand);
164 MainConsole.Instance.Commands.AddCommand("HGGridServicesConnector", false, "unlinkk-region", 182 MainConsole.Instance.Commands.AddCommand("HGGridServicesConnector", false, "unlink-region",
165 "unlink-region <local name> or <HostName>:<HttpPort> <cr>", 183 "unlink-region <local name> or <HostName>:<HttpPort> <cr>",
166 "Unlink a hypergrid region", hgCommands.RunCommand); 184 "Unlink a hypergrid region", hgCommands.RunCommand);
167 MainConsole.Instance.Commands.AddCommand("HGGridServicesConnector", false, "linkk-mapping", "link-mapping [<x> <y>] <cr>", 185 MainConsole.Instance.Commands.AddCommand("HGGridServicesConnector", false, "link-mapping", "link-mapping [<x> <y>] <cr>",
168 "Set local coordinate to map HG regions to", hgCommands.RunCommand); 186 "Set local coordinate to map HG regions to", hgCommands.RunCommand);
169 m_Initialized = true;
170 }
171
172 187
173 //scene.AddCommand("HGGridServicesConnector", "linkk-region", 188 // Yikes!! Remove this as soon as user services get refactored
174 // "link-region <Xloc> <Yloc> <HostName>:<HttpPort>[:<RemoteRegionName>] <cr>", 189 HGNetworkServersInfo.Init(LocalAssetServerURI, LocalInventoryServerURI, LocalUserServerURI);
175 // "Link a hypergrid region", hgCommands.RunCommand);
176 //scene.AddCommand("HGGridServicesConnector", "unlinkk-region",
177 // "unlink-region <local name> or <HostName>:<HttpPort> <cr>",
178 // "Unlink a hypergrid region", hgCommands.RunCommand);
179 //scene.AddCommand("HGGridServicesConnector", "linkk-mapping", "link-mapping [<x> <y>] <cr>",
180 // "Set local coordinate to map HG regions to", hgCommands.RunCommand);
181 190
191 m_Initialized = true;
192 }
182 } 193 }
183 194
184 #endregion 195 #endregion
@@ -250,7 +261,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid
250 // Try the foreign users home collection 261 // Try the foreign users home collection
251 foreach (GridRegion r in m_knownRegions.Values) 262 foreach (GridRegion r in m_knownRegions.Values)
252 if (r.RegionID == regionID) 263 if (r.RegionID == regionID)
253 return m_knownRegions[regionID]; 264 return r;
254 265
255 // Finally, try the normal route 266 // Finally, try the normal route
256 return m_GridServiceConnector.GetRegionByUUID(scopeID, regionID); 267 return m_GridServiceConnector.GetRegionByUUID(scopeID, regionID);
@@ -271,7 +282,9 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid
271 foreach (GridRegion r in m_knownRegions.Values) 282 foreach (GridRegion r in m_knownRegions.Values)
272 { 283 {
273 if ((r.RegionLocX == snapX) && (r.RegionLocY == snapY)) 284 if ((r.RegionLocX == snapX) && (r.RegionLocY == snapY))
285 {
274 return r; 286 return r;
287 }
275 } 288 }
276 289
277 // Finally, try the normal route 290 // Finally, try the normal route
@@ -338,8 +351,8 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid
338 351
339 private void AddHyperlinkRegion(GridRegion regionInfo, ulong regionHandle) 352 private void AddHyperlinkRegion(GridRegion regionInfo, ulong regionHandle)
340 { 353 {
341 m_HyperlinkRegions.Add(regionInfo.RegionID, regionInfo); 354 m_HyperlinkRegions[regionInfo.RegionID] = regionInfo;
342 m_HyperlinkHandles.Add(regionInfo.RegionID, regionHandle); 355 m_HyperlinkHandles[regionInfo.RegionID] = regionHandle;
343 } 356 }
344 357
345 private void RemoveHyperlinkRegion(UUID regionID) 358 private void RemoveHyperlinkRegion(UUID regionID)
@@ -350,8 +363,8 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid
350 363
351 private void AddHyperlinkHomeRegion(UUID userID, GridRegion regionInfo, ulong regionHandle) 364 private void AddHyperlinkHomeRegion(UUID userID, GridRegion regionInfo, ulong regionHandle)
352 { 365 {
353 m_knownRegions.Add(userID, regionInfo); 366 m_knownRegions[userID] = regionInfo;
354 m_HyperlinkHandles.Add(regionInfo.RegionID, regionHandle); 367 m_HyperlinkHandles[regionInfo.RegionID] = regionHandle;
355 } 368 }
356 369
357 private void RemoveHyperlinkHomeRegion(UUID regionID) 370 private void RemoveHyperlinkHomeRegion(UUID regionID)
@@ -367,10 +380,11 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid
367 } 380 }
368 #endregion 381 #endregion
369 382
370 #region Hyperlinks 383 #region IHyperlinkService
371 384
372 private static Random random = new Random(); 385 private static Random random = new Random();
373 386
387
374 public GridRegion TryLinkRegionToCoords(Scene m_scene, IClientAPI client, string mapName, int xloc, int yloc) 388 public GridRegion TryLinkRegionToCoords(Scene m_scene, IClientAPI client, string mapName, int xloc, int yloc)
375 { 389 {
376 string host = "127.0.0.1"; 390 string host = "127.0.0.1";
@@ -417,10 +431,11 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid
417 return null; 431 return null;
418 } 432 }
419 433
434
420 // From the map search and secondlife://blah 435 // From the map search and secondlife://blah
421 public GridRegion TryLinkRegion(Scene m_scene, IClientAPI client, string mapName) 436 public GridRegion TryLinkRegion(Scene m_scene, IClientAPI client, string mapName)
422 { 437 {
423 int xloc = random.Next(0, Int16.MaxValue); 438 int xloc = random.Next(0, Int16.MaxValue) * (int) Constants.RegionSize;
424 return TryLinkRegionToCoords(m_scene, client, mapName, xloc, 0); 439 return TryLinkRegionToCoords(m_scene, client, mapName, xloc, 0);
425 } 440 }
426 441
@@ -447,15 +462,11 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid
447 } 462 }
448 463
449 // Finally, link it 464 // Finally, link it
450 try 465 if (!RegisterRegion(UUID.Zero, regInfo))
451 { 466 {
452 RegisterRegion(UUID.Zero, regInfo); 467 m_log.Warn("[HGrid]: Unable to link region");
453 } 468 return false;
454 catch (Exception e) 469 }
455 {
456 m_log.Warn("[HGrid]: Unable to link region: " + e.Message);
457 return false;
458 }
459 470
460 int x, y; 471 int x, y;
461 if (!Check4096(m_scene, regInfo, out x, out y)) 472 if (!Check4096(m_scene, regInfo, out x, out y))
@@ -554,7 +565,227 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid
554 return true; 565 return true;
555 } 566 }
556 567
568 public GridRegion TryLinkRegion(IClientAPI client, string regionDescriptor)
569 {
570 return TryLinkRegion((Scene)client.Scene, client, regionDescriptor);
571 }
572
573 public GridRegion GetHyperlinkRegion(ulong handle)
574 {
575 foreach (GridRegion r in m_HyperlinkRegions.Values)
576 if (r.RegionHandle == handle)
577 return r;
578 foreach (GridRegion r in m_knownRegions.Values)
579 if (r.RegionHandle == handle)
580 return r;
581 return null;
582 }
583
584 public ulong FindRegionHandle(ulong handle)
585 {
586 foreach (GridRegion r in m_HyperlinkRegions.Values)
587 if ((r.RegionHandle == handle) && (m_HyperlinkHandles.ContainsKey(r.RegionID)))
588 return m_HyperlinkHandles[r.RegionID];
589
590 foreach (GridRegion r in m_knownRegions.Values)
591 if ((r.RegionHandle == handle) && (m_HyperlinkHandles.ContainsKey(r.RegionID)))
592 return m_HyperlinkHandles[r.RegionID];
593
594 return handle;
595 }
596
597 public bool SendUserInformation(GridRegion regInfo, AgentCircuitData agentData)
598 {
599 CachedUserInfo uinfo = m_aScene.CommsManager.UserProfileCacheService.GetUserDetails(agentData.AgentID);
600
601 if ((IsLocalUser(uinfo) && (GetHyperlinkRegion(regInfo.RegionHandle) != null)) ||
602 (!IsLocalUser(uinfo) && !IsGoingHome(uinfo, regInfo)))
603 {
604 m_log.Info("[HGrid]: Local user is going to foreign region or foreign user is going elsewhere");
605
606 // Set the position of the region on the remote grid
607 ulong realHandle = FindRegionHandle(regInfo.RegionHandle);
608 uint x = 0, y = 0;
609 Utils.LongToUInts(regInfo.RegionHandle, out x, out y);
610 GridRegion clonedRegion = new GridRegion(regInfo);
611 clonedRegion.RegionLocX = (int)x;
612 clonedRegion.RegionLocY = (int)y;
613
614 // Get the user's home region information
615 GridRegion home = m_aScene.GridService.GetRegionByUUID(m_aScene.RegionInfo.ScopeID, uinfo.UserProfile.HomeRegionID);
616
617 // Get the user's service URLs
618 string serverURI = "";
619 if (uinfo.UserProfile is ForeignUserProfileData)
620 serverURI = Util.ServerURI(((ForeignUserProfileData)uinfo.UserProfile).UserServerURI);
621 string userServer = (serverURI == "") || (serverURI == null) ? LocalUserServerURI : serverURI;
622
623 string assetServer = Util.ServerURI(uinfo.UserProfile.UserAssetURI);
624 if ((assetServer == null) || (assetServer == ""))
625 assetServer = LocalAssetServerURI;
626
627 string inventoryServer = Util.ServerURI(uinfo.UserProfile.UserInventoryURI);
628 if ((inventoryServer == null) || (inventoryServer == ""))
629 inventoryServer = LocalInventoryServerURI;
630
631 if (!m_HypergridServiceConnector.InformRegionOfUser(clonedRegion, agentData, home, userServer, assetServer, inventoryServer))
632 {
633 m_log.Warn("[HGrid]: Could not inform remote region of transferring user.");
634 return false;
635 }
636 }
637 //if ((uinfo == null) || !IsGoingHome(uinfo, regInfo))
638 //{
639 // m_log.Info("[HGrid]: User seems to be going to foreign region.");
640 // if (!InformRegionOfUser(regInfo, agentData))
641 // {
642 // m_log.Warn("[HGrid]: Could not inform remote region of transferring user.");
643 // return false;
644 // }
645 //}
646 //else
647 // m_log.Info("[HGrid]: User seems to be going home " + uinfo.UserProfile.FirstName + " " + uinfo.UserProfile.SurName);
648
649 // May need to change agent's name
650 if (IsLocalUser(uinfo) && (GetHyperlinkRegion(regInfo.RegionHandle) != null))
651 {
652 agentData.firstname = agentData.firstname + "." + agentData.lastname;
653 agentData.lastname = "@" + LocalUserServerURI.Replace("http://", ""); ; //HGNetworkServersInfo.Singleton.LocalUserServerURI;
654 }
655
656 return true;
657 }
658
659 public void AdjustUserInformation(AgentCircuitData agentData)
660 {
661 CachedUserInfo uinfo = m_aScene.CommsManager.UserProfileCacheService.GetUserDetails(agentData.AgentID);
662 if ((uinfo != null) && (uinfo.UserProfile != null) &&
663 (IsLocalUser(uinfo) || !(uinfo.UserProfile is ForeignUserProfileData)))
664 {
665 //m_log.Debug("---------------> Local User!");
666 string[] parts = agentData.firstname.Split(new char[] { '.' });
667 if (parts.Length == 2)
668 {
669 agentData.firstname = parts[0];
670 agentData.lastname = parts[1];
671 }
672 }
673 //else
674 // m_log.Debug("---------------> Foreign User!");
675 }
676
677 // Check if a local user exists with the same UUID as the incoming foreign user
678 public bool CheckUserAtEntry(UUID userID, UUID sessionID, out bool comingHome)
679 {
680 comingHome = false;
681 if (!m_aScene.SceneGridService.RegionLoginsEnabled)
682 return false;
683
684 CachedUserInfo uinfo = m_aScene.CommsManager.UserProfileCacheService.GetUserDetails(userID);
685 if (uinfo != null)
686 {
687 // uh-oh we have a potential intruder
688 if (uinfo.SessionID != sessionID)
689 // can't have a foreigner with a local UUID
690 return false;
691 else
692 // oh, so it's you! welcome back
693 comingHome = true;
694 }
695
696 // OK, user can come in
697 return true;
698 }
699
700 public void AcceptUser(ForeignUserProfileData user, GridRegion home)
701 {
702 m_aScene.CommsManager.UserProfileCacheService.PreloadUserCache(user);
703 ulong realHandle = home.RegionHandle;
704 // Change the local coordinates
705 // X=0 on the map
706 home.RegionLocX = 0;
707 home.RegionLocY = random.Next(0, 10000) * (int)Constants.RegionSize;
708
709 AddHyperlinkHomeRegion(user.ID, home, realHandle);
710
711 DumpUserData(user);
712 DumpRegionData(home);
713
714 }
715
716 public bool IsLocalUser(UUID userID)
717 {
718 CachedUserInfo uinfo = m_aScene.CommsManager.UserProfileCacheService.GetUserDetails(userID);
719 return IsLocalUser(uinfo);
720 }
721
722 #endregion
723
724 #region IHyperlink Misc
725
726 protected bool IsComingHome(ForeignUserProfileData userData)
727 {
728 return (userData.UserServerURI == LocalUserServerURI);
729 }
730
731 // Is the user going back to the home region or the home grid?
732 protected bool IsGoingHome(CachedUserInfo uinfo, GridRegion rinfo)
733 {
734 if (uinfo.UserProfile == null)
735 return false;
736
737 if (!(uinfo.UserProfile is ForeignUserProfileData))
738 // it's a home user, can't be outside to return home
739 return false;
740
741 // OK, it's a foreign user with a ForeignUserProfileData
742 // and is going back to exactly the home region.
743 // We can't check if it's going back to a non-home region
744 // of the home grid. That will be dealt with in the
745 // receiving end
746 return (uinfo.UserProfile.HomeRegionID == rinfo.RegionID);
747 }
748
749 protected bool IsLocalUser(CachedUserInfo uinfo)
750 {
751 if (uinfo == null)
752 return false;
753
754 return !(uinfo.UserProfile is ForeignUserProfileData);
755
756 }
757
758 protected bool IsLocalRegion(ulong handle)
759 {
760 return m_LocalScenes.ContainsKey(handle);
761 }
762
763 private void DumpUserData(ForeignUserProfileData userData)
764 {
765 m_log.Info(" ------------ User Data Dump ----------");
766 m_log.Info(" >> Name: " + userData.FirstName + " " + userData.SurName);
767 m_log.Info(" >> HomeID: " + userData.HomeRegionID);
768 m_log.Info(" >> UserServer: " + userData.UserServerURI);
769 m_log.Info(" >> InvServer: " + userData.UserInventoryURI);
770 m_log.Info(" >> AssetServer: " + userData.UserAssetURI);
771 m_log.Info(" ------------ -------------- ----------");
772 }
773
774 private void DumpRegionData(GridRegion rinfo)
775 {
776 m_log.Info(" ------------ Region Data Dump ----------");
777 m_log.Info(" >> handle: " + rinfo.RegionHandle);
778 m_log.Info(" >> coords: " + rinfo.RegionLocX + ", " + rinfo.RegionLocY);
779 m_log.Info(" >> external host name: " + rinfo.ExternalHostName);
780 m_log.Info(" >> http port: " + rinfo.HttpPort);
781 m_log.Info(" >> external EP address: " + rinfo.ExternalEndPoint.Address);
782 m_log.Info(" >> external EP port: " + rinfo.ExternalEndPoint.Port);
783 m_log.Info(" ------------ -------------- ----------");
784 }
785
786
557 #endregion 787 #endregion
558 788
789
559 } 790 }
560} 791}