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.cs227
1 files changed, 221 insertions, 6 deletions
diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/HGGridConnector.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/HGGridConnector.cs
index 0bb4206..52db400 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;
@@ -52,10 +53,14 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid
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
@@ -141,6 +146,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid
141 if (!m_Enabled) 146 if (!m_Enabled)
142 return; 147 return;
143 148
149 m_LocalScenes[scene.RegionInfo.RegionHandle] = scene;
144 scene.RegisterModuleInterface<IGridService>(this); 150 scene.RegisterModuleInterface<IGridService>(this);
145 scene.RegisterModuleInterface<IHyperlinkService>(this); 151 scene.RegisterModuleInterface<IHyperlinkService>(this);
146 152
@@ -148,6 +154,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid
148 154
149 public void RemoveRegion(Scene scene) 155 public void RemoveRegion(Scene scene)
150 { 156 {
157 m_LocalScenes.Remove(scene.RegionInfo.RegionHandle);
151 } 158 }
152 159
153 public void RegionLoaded(Scene scene) 160 public void RegionLoaded(Scene scene)
@@ -157,7 +164,13 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid
157 164
158 if (!m_Initialized) 165 if (!m_Initialized)
159 { 166 {
167 m_aScene = scene;
168 LocalAssetServerURI = m_aScene.CommsManager.NetworkServersInfo.UserURL;
169 LocalInventoryServerURI = m_aScene.CommsManager.NetworkServersInfo.InventoryURL;
170 LocalUserServerURI = m_aScene.CommsManager.NetworkServersInfo.UserURL;
171
160 m_HypergridServiceConnector = new HypergridServiceConnector(scene.AssetService); 172 m_HypergridServiceConnector = new HypergridServiceConnector(scene.AssetService);
173
161 HGCommands hgCommands = new HGCommands(this, scene); 174 HGCommands hgCommands = new HGCommands(this, scene);
162 MainConsole.Instance.Commands.AddCommand("HGGridServicesConnector", false, "link-region", 175 MainConsole.Instance.Commands.AddCommand("HGGridServicesConnector", false, "link-region",
163 "link-region <Xloc> <Yloc> <HostName>:<HttpPort>[:<RemoteRegionName>] <cr>", 176 "link-region <Xloc> <Yloc> <HostName>:<HttpPort>[:<RemoteRegionName>] <cr>",
@@ -167,6 +180,10 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid
167 "Unlink a hypergrid region", hgCommands.RunCommand); 180 "Unlink a hypergrid region", hgCommands.RunCommand);
168 MainConsole.Instance.Commands.AddCommand("HGGridServicesConnector", false, "link-mapping", "link-mapping [<x> <y>] <cr>", 181 MainConsole.Instance.Commands.AddCommand("HGGridServicesConnector", false, "link-mapping", "link-mapping [<x> <y>] <cr>",
169 "Set local coordinate to map HG regions to", hgCommands.RunCommand); 182 "Set local coordinate to map HG regions to", hgCommands.RunCommand);
183
184 // Yikes!! Remove this as soon as user services get refactored
185 HGNetworkServersInfo.Init(LocalAssetServerURI, LocalInventoryServerURI, LocalUserServerURI);
186
170 m_Initialized = true; 187 m_Initialized = true;
171 } 188 }
172 } 189 }
@@ -240,7 +257,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid
240 // Try the foreign users home collection 257 // Try the foreign users home collection
241 foreach (GridRegion r in m_knownRegions.Values) 258 foreach (GridRegion r in m_knownRegions.Values)
242 if (r.RegionID == regionID) 259 if (r.RegionID == regionID)
243 return m_knownRegions[regionID]; 260 return r;
244 261
245 // Finally, try the normal route 262 // Finally, try the normal route
246 return m_GridServiceConnector.GetRegionByUUID(scopeID, regionID); 263 return m_GridServiceConnector.GetRegionByUUID(scopeID, regionID);
@@ -261,7 +278,9 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid
261 foreach (GridRegion r in m_knownRegions.Values) 278 foreach (GridRegion r in m_knownRegions.Values)
262 { 279 {
263 if ((r.RegionLocX == snapX) && (r.RegionLocY == snapY)) 280 if ((r.RegionLocX == snapX) && (r.RegionLocY == snapY))
281 {
264 return r; 282 return r;
283 }
265 } 284 }
266 285
267 // Finally, try the normal route 286 // Finally, try the normal route
@@ -328,8 +347,8 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid
328 347
329 private void AddHyperlinkRegion(GridRegion regionInfo, ulong regionHandle) 348 private void AddHyperlinkRegion(GridRegion regionInfo, ulong regionHandle)
330 { 349 {
331 m_HyperlinkRegions.Add(regionInfo.RegionID, regionInfo); 350 m_HyperlinkRegions[regionInfo.RegionID] = regionInfo;
332 m_HyperlinkHandles.Add(regionInfo.RegionID, regionHandle); 351 m_HyperlinkHandles[regionInfo.RegionID] = regionHandle;
333 } 352 }
334 353
335 private void RemoveHyperlinkRegion(UUID regionID) 354 private void RemoveHyperlinkRegion(UUID regionID)
@@ -340,8 +359,8 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid
340 359
341 private void AddHyperlinkHomeRegion(UUID userID, GridRegion regionInfo, ulong regionHandle) 360 private void AddHyperlinkHomeRegion(UUID userID, GridRegion regionInfo, ulong regionHandle)
342 { 361 {
343 m_knownRegions.Add(userID, regionInfo); 362 m_knownRegions[userID] = regionInfo;
344 m_HyperlinkHandles.Add(regionInfo.RegionID, regionHandle); 363 m_HyperlinkHandles[regionInfo.RegionID] = regionHandle;
345 } 364 }
346 365
347 private void RemoveHyperlinkHomeRegion(UUID regionID) 366 private void RemoveHyperlinkHomeRegion(UUID regionID)
@@ -412,7 +431,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid
412 // From the map search and secondlife://blah 431 // From the map search and secondlife://blah
413 public GridRegion TryLinkRegion(Scene m_scene, IClientAPI client, string mapName) 432 public GridRegion TryLinkRegion(Scene m_scene, IClientAPI client, string mapName)
414 { 433 {
415 int xloc = random.Next(0, Int16.MaxValue); 434 int xloc = random.Next(0, Int16.MaxValue) * (int) Constants.RegionSize;
416 return TryLinkRegionToCoords(m_scene, client, mapName, xloc, 0); 435 return TryLinkRegionToCoords(m_scene, client, mapName, xloc, 0);
417 } 436 }
418 437
@@ -563,10 +582,206 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid
563 foreach (GridRegion r in m_HyperlinkRegions.Values) 582 foreach (GridRegion r in m_HyperlinkRegions.Values)
564 if ((r.RegionHandle == handle) && (m_HyperlinkHandles.ContainsKey(r.RegionID))) 583 if ((r.RegionHandle == handle) && (m_HyperlinkHandles.ContainsKey(r.RegionID)))
565 return m_HyperlinkHandles[r.RegionID]; 584 return m_HyperlinkHandles[r.RegionID];
585
586 foreach (GridRegion r in m_knownRegions.Values)
587 if ((r.RegionHandle == handle) && (m_HyperlinkHandles.ContainsKey(r.RegionID)))
588 return m_HyperlinkHandles[r.RegionID];
589
566 return handle; 590 return handle;
567 } 591 }
568 592
593 public bool SendUserInformation(GridRegion regInfo, AgentCircuitData agentData)
594 {
595 CachedUserInfo uinfo = m_aScene.CommsManager.UserProfileCacheService.GetUserDetails(agentData.AgentID);
596
597 if ((IsLocalUser(uinfo) && (GetHyperlinkRegion(regInfo.RegionHandle) != null)) ||
598 (!IsLocalUser(uinfo) && !IsGoingHome(uinfo, regInfo)))
599 {
600 m_log.Info("[HGrid]: Local user is going to foreign region or foreign user is going elsewhere");
601
602 // Set the position of the region on the remote grid
603 ulong realHandle = FindRegionHandle(regInfo.RegionHandle);
604 uint x = 0, y = 0;
605 Utils.LongToUInts(regInfo.RegionHandle, out x, out y);
606 GridRegion clonedRegion = new GridRegion(regInfo);
607 clonedRegion.RegionLocX = (int)x;
608 clonedRegion.RegionLocY = (int)y;
609
610 // Get the user's home region information
611 GridRegion home = m_aScene.GridService.GetRegionByUUID(m_aScene.RegionInfo.ScopeID, uinfo.UserProfile.HomeRegionID);
612
613 // Get the user's service URLs
614 string serverURI = "";
615 if (uinfo.UserProfile is ForeignUserProfileData)
616 serverURI = Util.ServerURI(((ForeignUserProfileData)uinfo.UserProfile).UserServerURI);
617 string userServer = (serverURI == "") || (serverURI == null) ? LocalUserServerURI : serverURI;
618
619 string assetServer = Util.ServerURI(uinfo.UserProfile.UserAssetURI);
620 if ((assetServer == null) || (assetServer == ""))
621 assetServer = LocalAssetServerURI;
622
623 string inventoryServer = Util.ServerURI(uinfo.UserProfile.UserInventoryURI);
624 if ((inventoryServer == null) || (inventoryServer == ""))
625 inventoryServer = LocalInventoryServerURI;
626
627 if (!m_HypergridServiceConnector.InformRegionOfUser(clonedRegion, agentData, home, userServer, assetServer, inventoryServer))
628 {
629 m_log.Warn("[HGrid]: Could not inform remote region of transferring user.");
630 return false;
631 }
632 }
633 //if ((uinfo == null) || !IsGoingHome(uinfo, regInfo))
634 //{
635 // m_log.Info("[HGrid]: User seems to be going to foreign region.");
636 // if (!InformRegionOfUser(regInfo, agentData))
637 // {
638 // m_log.Warn("[HGrid]: Could not inform remote region of transferring user.");
639 // return false;
640 // }
641 //}
642 //else
643 // m_log.Info("[HGrid]: User seems to be going home " + uinfo.UserProfile.FirstName + " " + uinfo.UserProfile.SurName);
644
645 // May need to change agent's name
646 if (IsLocalUser(uinfo) && (GetHyperlinkRegion(regInfo.RegionHandle) != null))
647 {
648 agentData.firstname = agentData.firstname + "." + agentData.lastname;
649 agentData.lastname = "@" + LocalUserServerURI.Replace("http://", ""); ; //HGNetworkServersInfo.Singleton.LocalUserServerURI;
650 }
651
652 return true;
653 }
654
655 public void AdjustUserInformation(AgentCircuitData agentData)
656 {
657 CachedUserInfo uinfo = m_aScene.CommsManager.UserProfileCacheService.GetUserDetails(agentData.AgentID);
658 if ((uinfo != null) && (uinfo.UserProfile != null) &&
659 (IsLocalUser(uinfo) || !(uinfo.UserProfile is ForeignUserProfileData)))
660 {
661 //m_log.Debug("---------------> Local User!");
662 string[] parts = agentData.firstname.Split(new char[] { '.' });
663 if (parts.Length == 2)
664 {
665 agentData.firstname = parts[0];
666 agentData.lastname = parts[1];
667 }
668 }
669 //else
670 // m_log.Debug("---------------> Foreign User!");
671 }
672
673 // Check if a local user exists with the same UUID as the incoming foreign user
674 public bool CheckUserAtEntry(UUID userID, UUID sessionID, out bool comingHome)
675 {
676 comingHome = false;
677 if (!m_aScene.SceneGridService.RegionLoginsEnabled)
678 return false;
679
680 CachedUserInfo uinfo = m_aScene.CommsManager.UserProfileCacheService.GetUserDetails(userID);
681 if (uinfo != null)
682 {
683 // uh-oh we have a potential intruder
684 if (uinfo.SessionID != sessionID)
685 // can't have a foreigner with a local UUID
686 return false;
687 else
688 // oh, so it's you! welcome back
689 comingHome = true;
690 }
691
692 // OK, user can come in
693 return true;
694 }
695
696 public void AcceptUser(ForeignUserProfileData user, GridRegion home)
697 {
698 m_aScene.CommsManager.UserProfileCacheService.PreloadUserCache(user);
699 ulong realHandle = home.RegionHandle;
700 // Change the local coordinates
701 // X=0 on the map
702 home.RegionLocX = 0;
703 home.RegionLocY = random.Next(0, 10000) * (int)Constants.RegionSize;
704
705 AddHyperlinkHomeRegion(user.ID, home, realHandle);
706
707 DumpUserData(user);
708 DumpRegionData(home);
709
710 }
711
712 public bool IsLocalUser(UUID userID)
713 {
714 CachedUserInfo uinfo = m_aScene.CommsManager.UserProfileCacheService.GetUserDetails(userID);
715 return IsLocalUser(uinfo);
716 }
717
569 #endregion 718 #endregion
570 719
720 #region IHyperlink Misc
721
722 protected bool IsComingHome(ForeignUserProfileData userData)
723 {
724 return (userData.UserServerURI == LocalUserServerURI);
725 }
726
727 // Is the user going back to the home region or the home grid?
728 protected bool IsGoingHome(CachedUserInfo uinfo, GridRegion rinfo)
729 {
730 if (uinfo.UserProfile == null)
731 return false;
732
733 if (!(uinfo.UserProfile is ForeignUserProfileData))
734 // it's a home user, can't be outside to return home
735 return false;
736
737 // OK, it's a foreign user with a ForeignUserProfileData
738 // and is going back to exactly the home region.
739 // We can't check if it's going back to a non-home region
740 // of the home grid. That will be dealt with in the
741 // receiving end
742 return (uinfo.UserProfile.HomeRegionID == rinfo.RegionID);
743 }
744
745 protected bool IsLocalUser(CachedUserInfo uinfo)
746 {
747 if (uinfo == null)
748 return false;
749
750 return !(uinfo.UserProfile is ForeignUserProfileData);
751
752 }
753
754 protected bool IsLocalRegion(ulong handle)
755 {
756 return m_LocalScenes.ContainsKey(handle);
757 }
758
759 private void DumpUserData(ForeignUserProfileData userData)
760 {
761 m_log.Info(" ------------ User Data Dump ----------");
762 m_log.Info(" >> Name: " + userData.FirstName + " " + userData.SurName);
763 m_log.Info(" >> HomeID: " + userData.HomeRegionID);
764 m_log.Info(" >> UserServer: " + userData.UserServerURI);
765 m_log.Info(" >> InvServer: " + userData.UserInventoryURI);
766 m_log.Info(" >> AssetServer: " + userData.UserAssetURI);
767 m_log.Info(" ------------ -------------- ----------");
768 }
769
770 private void DumpRegionData(GridRegion rinfo)
771 {
772 m_log.Info(" ------------ Region Data Dump ----------");
773 m_log.Info(" >> handle: " + rinfo.RegionHandle);
774 m_log.Info(" >> coords: " + rinfo.RegionLocX + ", " + rinfo.RegionLocY);
775 m_log.Info(" >> external host name: " + rinfo.ExternalHostName);
776 m_log.Info(" >> http port: " + rinfo.HttpPort);
777 m_log.Info(" >> external EP address: " + rinfo.ExternalEndPoint.Address);
778 m_log.Info(" >> external EP port: " + rinfo.ExternalEndPoint.Port);
779 m_log.Info(" ------------ -------------- ----------");
780 }
781
782
783 #endregion
784
785
571 } 786 }
572} 787}