From f4bf581b96347b8d7f115eca74fa84a644eb729c Mon Sep 17 00:00:00 2001 From: Diva Canto Date: Sat, 26 Sep 2009 21:00:51 -0700 Subject: [PATCH] Moved all HG1 operations to HGGridConnector.cs and HypergridServerConnector.cs/HypergridServiceConnector.cs, away from Region.Communications and HGNetworkServersInfo. Fixed small bugs with hyperlinked regions' map positions. --- .../CreateCommsManagerPlugin.cs | 1 - OpenSim/Framework/Util.cs | 26 ++ OpenSim/Region/Application/HGCommands.cs | 3 +- .../Hypergrid/HGGridServices.cs | 50 ++-- .../Grid/HypergridServiceInConnectorModule.cs | 29 +-- .../Grid/HGGridConnector.cs | 227 +++++++++++++++++- .../Interregion/RESTInterregionComms.cs | 22 +- .../Inventory/HGInventoryBroker.cs | 9 +- .../World/WorldMap/MapSearchModule.cs | 4 +- .../Scenes/Hypergrid/HGAssetMapper.cs | 33 ++- .../Hypergrid/HGSceneCommunicationService.cs | 21 +- .../Handlers/Grid/HypergridServerConnector.cs | 111 ++++++++- .../Grid/HypergridServiceConnector.cs | 89 +++++++ OpenSim/Services/Interfaces/IGridService.cs | 14 ++ 14 files changed, 538 insertions(+), 101 deletions(-) diff --git a/OpenSim/ApplicationPlugins/CreateCommsManager/CreateCommsManagerPlugin.cs b/OpenSim/ApplicationPlugins/CreateCommsManager/CreateCommsManagerPlugin.cs index 6a66116eeb..18641f1fa4 100644 --- a/OpenSim/ApplicationPlugins/CreateCommsManager/CreateCommsManagerPlugin.cs +++ b/OpenSim/ApplicationPlugins/CreateCommsManager/CreateCommsManagerPlugin.cs @@ -144,7 +144,6 @@ namespace OpenSim.ApplicationPlugins.CreateCommsManager // We are in grid mode InitialiseHGGridServices(libraryRootFolder); } - HGCommands.HGServices = HGServices; } protected void InitialiseStandardServices(LibraryRootFolder libraryRootFolder) diff --git a/OpenSim/Framework/Util.cs b/OpenSim/Framework/Util.cs index 45b5a105fd..a28a6177b2 100644 --- a/OpenSim/Framework/Util.cs +++ b/OpenSim/Framework/Util.cs @@ -1203,6 +1203,32 @@ namespace OpenSim.Framework return found.ToArray(); } + public static string ServerURI(string uri) + { + if (uri == string.Empty) + return string.Empty; + + // Get rid of eventual slashes at the end + uri = uri.TrimEnd('/'); + + IPAddress ipaddr1 = null; + string port1 = ""; + try + { + ipaddr1 = Util.GetHostFromURL(uri); + } + catch { } + + try + { + port1 = uri.Split(new char[] { ':' })[2]; + } + catch { } + + // We tried our best to convert the domain names to IP addresses + return (ipaddr1 != null) ? "http://" + ipaddr1.ToString() + ":" + port1 : uri; + } + #region FireAndForget Threading Pattern public static void FireAndForget(System.Threading.WaitCallback callback) diff --git a/OpenSim/Region/Application/HGCommands.cs b/OpenSim/Region/Application/HGCommands.cs index f99c1a57f0..f503db75c1 100644 --- a/OpenSim/Region/Application/HGCommands.cs +++ b/OpenSim/Region/Application/HGCommands.cs @@ -43,12 +43,11 @@ namespace OpenSim public class HGCommands { private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); - public static IHyperlink HGServices = null; public static Scene CreateScene(RegionInfo regionInfo, AgentCircuitManager circuitManager, CommunicationsManager m_commsManager, StorageManager storageManager, ModuleLoader m_moduleLoader, ConfigSettings m_configSettings, OpenSimConfigSource m_config, string m_version) { - HGSceneCommunicationService sceneGridService = new HGSceneCommunicationService(m_commsManager, HGServices); + HGSceneCommunicationService sceneGridService = new HGSceneCommunicationService(m_commsManager); return new HGScene( diff --git a/OpenSim/Region/Communications/Hypergrid/HGGridServices.cs b/OpenSim/Region/Communications/Hypergrid/HGGridServices.cs index 54cde0f54b..85bfab4e50 100644 --- a/OpenSim/Region/Communications/Hypergrid/HGGridServices.cs +++ b/OpenSim/Region/Communications/Hypergrid/HGGridServices.cs @@ -596,16 +596,16 @@ namespace OpenSim.Region.Communications.Hypergrid //m_log.Debug(" >> " + loginParams["region_uuid"] + " <<"); //m_log.Debug(" --------- ---------------- -------"); - string serverURI = ""; - if (u.UserProfile is ForeignUserProfileData) - serverURI = HGNetworkServersInfo.ServerURI(((ForeignUserProfileData)u.UserProfile).UserServerURI); - loginParams["userserver_id"] = (serverURI == "") || (serverURI == null) ? HGNetworkServersInfo.Singleton.LocalUserServerURI : serverURI; + //string serverURI = ""; + //if (u.UserProfile is ForeignUserProfileData) + // serverURI = Util.ServerURI(((ForeignUserProfileData)u.UserProfile).UserServerURI); + //loginParams["userserver_id"] = (serverURI == "") || (serverURI == null) ? HGNetworkServersInfo.Singleton.LocalUserServerURI : serverURI; - serverURI = HGNetworkServersInfo.ServerURI(u.UserProfile.UserAssetURI); - loginParams["assetserver_id"] = (serverURI == "") || (serverURI == null) ? HGNetworkServersInfo.Singleton.LocalAssetServerURI : serverURI; + //serverURI = HGNetworkServersInfo.ServerURI(u.UserProfile.UserAssetURI); + //loginParams["assetserver_id"] = (serverURI == "") || (serverURI == null) ? HGNetworkServersInfo.Singleton.LocalAssetServerURI : serverURI; - serverURI = HGNetworkServersInfo.ServerURI(u.UserProfile.UserInventoryURI); - loginParams["inventoryserver_id"] = (serverURI == "") || (serverURI == null) ? HGNetworkServersInfo.Singleton.LocalInventoryServerURI : serverURI; + //serverURI = HGNetworkServersInfo.ServerURI(u.UserProfile.UserInventoryURI); + //loginParams["inventoryserver_id"] = (serverURI == "") || (serverURI == null) ? HGNetworkServersInfo.Singleton.LocalInventoryServerURI : serverURI; loginParams["root_folder_id"] = u.UserProfile.RootInventoryFolderID; @@ -949,33 +949,35 @@ namespace OpenSim.Region.Communications.Hypergrid protected bool IsComingHome(ForeignUserProfileData userData) { - return (userData.UserServerURI == HGNetworkServersInfo.Singleton.LocalUserServerURI); + return false; //(userData.UserServerURI == HGNetworkServersInfo.Singleton.LocalUserServerURI); } protected bool IsGoingHome(CachedUserInfo uinfo, RegionInfo rinfo) { - if (uinfo.UserProfile == null) - return false; + return false; + //if (uinfo.UserProfile == null) + // return false; - string userUserServerURI = String.Empty; - if (uinfo.UserProfile is ForeignUserProfileData) - { - userUserServerURI = HGNetworkServersInfo.ServerURI(((ForeignUserProfileData)uinfo.UserProfile).UserServerURI); - } + //string userUserServerURI = String.Empty; + //if (uinfo.UserProfile is ForeignUserProfileData) + //{ + // userUserServerURI = HGNetworkServersInfo.ServerURI(((ForeignUserProfileData)uinfo.UserProfile).UserServerURI); + //} - return ((uinfo.UserProfile.HomeRegionID == rinfo.RegionID) && - (userUserServerURI != HGNetworkServersInfo.Singleton.LocalUserServerURI)); + //return ((uinfo.UserProfile.HomeRegionID == rinfo.RegionID) && + // (userUserServerURI != HGNetworkServersInfo.Singleton.LocalUserServerURI)); } protected bool IsLocalUser(CachedUserInfo uinfo) { - if (uinfo == null) - return true; + return true; + //if (uinfo == null) + // return true; - if (uinfo.UserProfile is ForeignUserProfileData) - return HGNetworkServersInfo.Singleton.IsLocalUser(((ForeignUserProfileData)uinfo.UserProfile).UserServerURI); - else - return true; + //if (uinfo.UserProfile is ForeignUserProfileData) + // return HGNetworkServersInfo.Singleton.IsLocalUser(((ForeignUserProfileData)uinfo.UserProfile).UserServerURI); + //else + // return true; } diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsIn/Grid/HypergridServiceInConnectorModule.cs b/OpenSim/Region/CoreModules/ServiceConnectorsIn/Grid/HypergridServiceInConnectorModule.cs index 41f96b37bd..9bf31a4131 100644 --- a/OpenSim/Region/CoreModules/ServiceConnectorsIn/Grid/HypergridServiceInConnectorModule.cs +++ b/OpenSim/Region/CoreModules/ServiceConnectorsIn/Grid/HypergridServiceInConnectorModule.cs @@ -37,6 +37,7 @@ using OpenSim.Region.Framework.Interfaces; using OpenSim.Server.Base; using OpenSim.Server.Handlers.Base; using OpenSim.Server.Handlers.Grid; +using OpenSim.Services.Interfaces; using GridRegion = OpenSim.Services.Interfaces.GridRegion; namespace OpenSim.Region.CoreModules.ServiceConnectorsIn.Grid @@ -95,20 +96,6 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsIn.Grid if (!m_Enabled) return; - if (!m_Registered) - { - m_Registered = true; - - m_log.Info("[HypergridService]: Starting..."); - - Object[] args = new Object[] { m_Config, MainServer.Instance }; - - m_HypergridHandler = new HypergridServiceInConnector(m_Config, MainServer.Instance); - //ServerUtils.LoadPlugin("OpenSim.Server.Handlers.dll:HypergridServiceInConnector", args); - } - - GridRegion rinfo = new GridRegion(scene.RegionInfo); - m_HypergridHandler.AddRegion(rinfo); } public void RemoveRegion(Scene scene) @@ -122,6 +109,20 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsIn.Grid public void RegionLoaded(Scene scene) { + if (!m_Registered) + { + m_Registered = true; + + m_log.Info("[HypergridService]: Starting..."); + + Object[] args = new Object[] { m_Config, MainServer.Instance }; + + m_HypergridHandler = new HypergridServiceInConnector(m_Config, MainServer.Instance, scene.RequestModuleInterface()); + //ServerUtils.LoadPlugin("OpenSim.Server.Handlers.dll:HypergridServiceInConnector", args); + } + + GridRegion rinfo = new GridRegion(scene.RegionInfo); + m_HypergridHandler.AddRegion(rinfo); } #endregion diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/HGGridConnector.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/HGGridConnector.cs index 0bb4206738..52db400912 100644 --- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/HGGridConnector.cs +++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/HGGridConnector.cs @@ -31,6 +31,7 @@ using System.Net; using System.Reflection; using System.Xml; +using OpenSim.Framework.Communications.Cache; using OpenSim.Framework; using OpenSim.Region.Framework.Interfaces; using OpenSim.Region.Framework.Scenes; @@ -52,10 +53,14 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid private static readonly ILog m_log = LogManager.GetLogger( MethodBase.GetCurrentMethod().DeclaringType); + private static string LocalAssetServerURI, LocalInventoryServerURI, LocalUserServerURI; private bool m_Enabled = false; private bool m_Initialized = false; + private Scene m_aScene; + private Dictionary m_LocalScenes = new Dictionary(); + private IGridService m_GridServiceConnector; private HypergridServiceConnector m_HypergridServiceConnector; @@ -141,6 +146,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid if (!m_Enabled) return; + m_LocalScenes[scene.RegionInfo.RegionHandle] = scene; scene.RegisterModuleInterface(this); scene.RegisterModuleInterface(this); @@ -148,6 +154,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid public void RemoveRegion(Scene scene) { + m_LocalScenes.Remove(scene.RegionInfo.RegionHandle); } public void RegionLoaded(Scene scene) @@ -157,7 +164,13 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid if (!m_Initialized) { + m_aScene = scene; + LocalAssetServerURI = m_aScene.CommsManager.NetworkServersInfo.UserURL; + LocalInventoryServerURI = m_aScene.CommsManager.NetworkServersInfo.InventoryURL; + LocalUserServerURI = m_aScene.CommsManager.NetworkServersInfo.UserURL; + m_HypergridServiceConnector = new HypergridServiceConnector(scene.AssetService); + HGCommands hgCommands = new HGCommands(this, scene); MainConsole.Instance.Commands.AddCommand("HGGridServicesConnector", false, "link-region", "link-region :[:] ", @@ -167,6 +180,10 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid "Unlink a hypergrid region", hgCommands.RunCommand); MainConsole.Instance.Commands.AddCommand("HGGridServicesConnector", false, "link-mapping", "link-mapping [ ] ", "Set local coordinate to map HG regions to", hgCommands.RunCommand); + + // Yikes!! Remove this as soon as user services get refactored + HGNetworkServersInfo.Init(LocalAssetServerURI, LocalInventoryServerURI, LocalUserServerURI); + m_Initialized = true; } } @@ -240,7 +257,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid // Try the foreign users home collection foreach (GridRegion r in m_knownRegions.Values) if (r.RegionID == regionID) - return m_knownRegions[regionID]; + return r; // Finally, try the normal route return m_GridServiceConnector.GetRegionByUUID(scopeID, regionID); @@ -261,7 +278,9 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid foreach (GridRegion r in m_knownRegions.Values) { if ((r.RegionLocX == snapX) && (r.RegionLocY == snapY)) + { return r; + } } // Finally, try the normal route @@ -328,8 +347,8 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid private void AddHyperlinkRegion(GridRegion regionInfo, ulong regionHandle) { - m_HyperlinkRegions.Add(regionInfo.RegionID, regionInfo); - m_HyperlinkHandles.Add(regionInfo.RegionID, regionHandle); + m_HyperlinkRegions[regionInfo.RegionID] = regionInfo; + m_HyperlinkHandles[regionInfo.RegionID] = regionHandle; } private void RemoveHyperlinkRegion(UUID regionID) @@ -340,8 +359,8 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid private void AddHyperlinkHomeRegion(UUID userID, GridRegion regionInfo, ulong regionHandle) { - m_knownRegions.Add(userID, regionInfo); - m_HyperlinkHandles.Add(regionInfo.RegionID, regionHandle); + m_knownRegions[userID] = regionInfo; + m_HyperlinkHandles[regionInfo.RegionID] = regionHandle; } private void RemoveHyperlinkHomeRegion(UUID regionID) @@ -412,7 +431,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid // From the map search and secondlife://blah public GridRegion TryLinkRegion(Scene m_scene, IClientAPI client, string mapName) { - int xloc = random.Next(0, Int16.MaxValue); + int xloc = random.Next(0, Int16.MaxValue) * (int) Constants.RegionSize; return TryLinkRegionToCoords(m_scene, client, mapName, xloc, 0); } @@ -563,10 +582,206 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid foreach (GridRegion r in m_HyperlinkRegions.Values) if ((r.RegionHandle == handle) && (m_HyperlinkHandles.ContainsKey(r.RegionID))) return m_HyperlinkHandles[r.RegionID]; + + foreach (GridRegion r in m_knownRegions.Values) + if ((r.RegionHandle == handle) && (m_HyperlinkHandles.ContainsKey(r.RegionID))) + return m_HyperlinkHandles[r.RegionID]; + return handle; } + public bool SendUserInformation(GridRegion regInfo, AgentCircuitData agentData) + { + CachedUserInfo uinfo = m_aScene.CommsManager.UserProfileCacheService.GetUserDetails(agentData.AgentID); + + if ((IsLocalUser(uinfo) && (GetHyperlinkRegion(regInfo.RegionHandle) != null)) || + (!IsLocalUser(uinfo) && !IsGoingHome(uinfo, regInfo))) + { + m_log.Info("[HGrid]: Local user is going to foreign region or foreign user is going elsewhere"); + + // Set the position of the region on the remote grid + ulong realHandle = FindRegionHandle(regInfo.RegionHandle); + uint x = 0, y = 0; + Utils.LongToUInts(regInfo.RegionHandle, out x, out y); + GridRegion clonedRegion = new GridRegion(regInfo); + clonedRegion.RegionLocX = (int)x; + clonedRegion.RegionLocY = (int)y; + + // Get the user's home region information + GridRegion home = m_aScene.GridService.GetRegionByUUID(m_aScene.RegionInfo.ScopeID, uinfo.UserProfile.HomeRegionID); + + // Get the user's service URLs + string serverURI = ""; + if (uinfo.UserProfile is ForeignUserProfileData) + serverURI = Util.ServerURI(((ForeignUserProfileData)uinfo.UserProfile).UserServerURI); + string userServer = (serverURI == "") || (serverURI == null) ? LocalUserServerURI : serverURI; + + string assetServer = Util.ServerURI(uinfo.UserProfile.UserAssetURI); + if ((assetServer == null) || (assetServer == "")) + assetServer = LocalAssetServerURI; + + string inventoryServer = Util.ServerURI(uinfo.UserProfile.UserInventoryURI); + if ((inventoryServer == null) || (inventoryServer == "")) + inventoryServer = LocalInventoryServerURI; + + if (!m_HypergridServiceConnector.InformRegionOfUser(clonedRegion, agentData, home, userServer, assetServer, inventoryServer)) + { + m_log.Warn("[HGrid]: Could not inform remote region of transferring user."); + return false; + } + } + //if ((uinfo == null) || !IsGoingHome(uinfo, regInfo)) + //{ + // m_log.Info("[HGrid]: User seems to be going to foreign region."); + // if (!InformRegionOfUser(regInfo, agentData)) + // { + // m_log.Warn("[HGrid]: Could not inform remote region of transferring user."); + // return false; + // } + //} + //else + // m_log.Info("[HGrid]: User seems to be going home " + uinfo.UserProfile.FirstName + " " + uinfo.UserProfile.SurName); + + // May need to change agent's name + if (IsLocalUser(uinfo) && (GetHyperlinkRegion(regInfo.RegionHandle) != null)) + { + agentData.firstname = agentData.firstname + "." + agentData.lastname; + agentData.lastname = "@" + LocalUserServerURI.Replace("http://", ""); ; //HGNetworkServersInfo.Singleton.LocalUserServerURI; + } + + return true; + } + + public void AdjustUserInformation(AgentCircuitData agentData) + { + CachedUserInfo uinfo = m_aScene.CommsManager.UserProfileCacheService.GetUserDetails(agentData.AgentID); + if ((uinfo != null) && (uinfo.UserProfile != null) && + (IsLocalUser(uinfo) || !(uinfo.UserProfile is ForeignUserProfileData))) + { + //m_log.Debug("---------------> Local User!"); + string[] parts = agentData.firstname.Split(new char[] { '.' }); + if (parts.Length == 2) + { + agentData.firstname = parts[0]; + agentData.lastname = parts[1]; + } + } + //else + // m_log.Debug("---------------> Foreign User!"); + } + + // Check if a local user exists with the same UUID as the incoming foreign user + public bool CheckUserAtEntry(UUID userID, UUID sessionID, out bool comingHome) + { + comingHome = false; + if (!m_aScene.SceneGridService.RegionLoginsEnabled) + return false; + + CachedUserInfo uinfo = m_aScene.CommsManager.UserProfileCacheService.GetUserDetails(userID); + if (uinfo != null) + { + // uh-oh we have a potential intruder + if (uinfo.SessionID != sessionID) + // can't have a foreigner with a local UUID + return false; + else + // oh, so it's you! welcome back + comingHome = true; + } + + // OK, user can come in + return true; + } + + public void AcceptUser(ForeignUserProfileData user, GridRegion home) + { + m_aScene.CommsManager.UserProfileCacheService.PreloadUserCache(user); + ulong realHandle = home.RegionHandle; + // Change the local coordinates + // X=0 on the map + home.RegionLocX = 0; + home.RegionLocY = random.Next(0, 10000) * (int)Constants.RegionSize; + + AddHyperlinkHomeRegion(user.ID, home, realHandle); + + DumpUserData(user); + DumpRegionData(home); + + } + + public bool IsLocalUser(UUID userID) + { + CachedUserInfo uinfo = m_aScene.CommsManager.UserProfileCacheService.GetUserDetails(userID); + return IsLocalUser(uinfo); + } + #endregion + #region IHyperlink Misc + + protected bool IsComingHome(ForeignUserProfileData userData) + { + return (userData.UserServerURI == LocalUserServerURI); + } + + // Is the user going back to the home region or the home grid? + protected bool IsGoingHome(CachedUserInfo uinfo, GridRegion rinfo) + { + if (uinfo.UserProfile == null) + return false; + + if (!(uinfo.UserProfile is ForeignUserProfileData)) + // it's a home user, can't be outside to return home + return false; + + // OK, it's a foreign user with a ForeignUserProfileData + // and is going back to exactly the home region. + // We can't check if it's going back to a non-home region + // of the home grid. That will be dealt with in the + // receiving end + return (uinfo.UserProfile.HomeRegionID == rinfo.RegionID); + } + + protected bool IsLocalUser(CachedUserInfo uinfo) + { + if (uinfo == null) + return false; + + return !(uinfo.UserProfile is ForeignUserProfileData); + + } + + protected bool IsLocalRegion(ulong handle) + { + return m_LocalScenes.ContainsKey(handle); + } + + private void DumpUserData(ForeignUserProfileData userData) + { + m_log.Info(" ------------ User Data Dump ----------"); + m_log.Info(" >> Name: " + userData.FirstName + " " + userData.SurName); + m_log.Info(" >> HomeID: " + userData.HomeRegionID); + m_log.Info(" >> UserServer: " + userData.UserServerURI); + m_log.Info(" >> InvServer: " + userData.UserInventoryURI); + m_log.Info(" >> AssetServer: " + userData.UserAssetURI); + m_log.Info(" ------------ -------------- ----------"); + } + + private void DumpRegionData(GridRegion rinfo) + { + m_log.Info(" ------------ Region Data Dump ----------"); + m_log.Info(" >> handle: " + rinfo.RegionHandle); + m_log.Info(" >> coords: " + rinfo.RegionLocX + ", " + rinfo.RegionLocY); + m_log.Info(" >> external host name: " + rinfo.ExternalHostName); + m_log.Info(" >> http port: " + rinfo.HttpPort); + m_log.Info(" >> external EP address: " + rinfo.ExternalEndPoint.Address); + m_log.Info(" >> external EP port: " + rinfo.ExternalEndPoint.Port); + m_log.Info(" ------------ -------------- ----------"); + } + + + #endregion + + } } diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Interregion/RESTInterregionComms.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Interregion/RESTInterregionComms.cs index adf747af7a..696225cddc 100644 --- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Interregion/RESTInterregionComms.cs +++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Interregion/RESTInterregionComms.cs @@ -824,29 +824,15 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Interregion public override void SendUserInformation(GridRegion regInfo, AgentCircuitData aCircuit) { - try - { - if (m_aScene.SceneGridService is HGSceneCommunicationService) - { - // big hack for now - RegionInfo r = new RegionInfo(); - r.ExternalHostName = regInfo.ExternalHostName; - r.HttpPort = regInfo.HttpPort; - r.RegionID = regInfo.RegionID; - r.RegionLocX = (uint)regInfo.RegionLocX; - r.RegionLocY = (uint)regInfo.RegionLocY; - ((HGSceneCommunicationService)(m_aScene.SceneGridService)).m_hg.SendUserInformation(r, aCircuit); - } - } - catch // Bad cast - { } + if (m_hyperlinkService != null) + m_hyperlinkService.SendUserInformation(regInfo, aCircuit); } public override void AdjustUserInformation(AgentCircuitData aCircuit) { - if (m_aScene.SceneGridService is HGSceneCommunicationService) - ((HGSceneCommunicationService)(m_aScene.SceneGridService)).m_hg.AdjustUserInformation(aCircuit); + if (m_hyperlinkService != null) + m_hyperlinkService.AdjustUserInformation(aCircuit); } } diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Inventory/HGInventoryBroker.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Inventory/HGInventoryBroker.cs index 1c66254aca..fd1a75926a 100644 --- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Inventory/HGInventoryBroker.cs +++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Inventory/HGInventoryBroker.cs @@ -525,7 +525,12 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Inventory return true; } - string userInventoryServerURI = HGNetworkServersInfo.ServerURI(uinfo.UserProfile.UserInventoryURI); + if ((uinfo.UserProfile.UserInventoryURI == null) || (uinfo.UserProfile.UserInventoryURI == "")) + // this happens in standalone profiles, apparently + return true; + + string userInventoryServerURI = Util.ServerURI(uinfo.UserProfile.UserInventoryURI); + string uri = m_LocalGridInventoryURI.TrimEnd('/'); if ((userInventoryServerURI == uri) || (userInventoryServerURI == "")) @@ -544,7 +549,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Inventory if ((uinfo == null) || (uinfo.UserProfile == null)) return invURI; - string userInventoryServerURI = HGNetworkServersInfo.ServerURI(uinfo.UserProfile.UserInventoryURI); + string userInventoryServerURI = Util.ServerURI(uinfo.UserProfile.UserInventoryURI); if ((userInventoryServerURI != null) && (userInventoryServerURI != "")) diff --git a/OpenSim/Region/CoreModules/World/WorldMap/MapSearchModule.cs b/OpenSim/Region/CoreModules/World/WorldMap/MapSearchModule.cs index e3661fa936..436f332f1d 100644 --- a/OpenSim/Region/CoreModules/World/WorldMap/MapSearchModule.cs +++ b/OpenSim/Region/CoreModules/World/WorldMap/MapSearchModule.cs @@ -137,8 +137,8 @@ namespace OpenSim.Region.CoreModules.World.WorldMap data.Name = info.RegionName; data.RegionFlags = 0; // TODO not used? data.WaterHeight = 0; // not used - data.X = (ushort)info.RegionLocX; - data.Y = (ushort)info.RegionLocY; + data.X = (ushort)(info.RegionLocX / Constants.RegionSize); + data.Y = (ushort)(info.RegionLocY / Constants.RegionSize); blocks.Add(data); } } diff --git a/OpenSim/Region/Framework/Scenes/Hypergrid/HGAssetMapper.cs b/OpenSim/Region/Framework/Scenes/Hypergrid/HGAssetMapper.cs index 62efd60506..b6fa41de6a 100644 --- a/OpenSim/Region/Framework/Scenes/Hypergrid/HGAssetMapper.cs +++ b/OpenSim/Region/Framework/Scenes/Hypergrid/HGAssetMapper.cs @@ -35,6 +35,7 @@ using OpenSim.Framework; using OpenSim.Framework.Communications.Cache; using OpenSim.Framework.Communications.Clients; using OpenSim.Region.Framework.Scenes.Serialization; +using OpenSim.Services.Interfaces; //using HyperGrid.Framework; //using OpenSim.Region.Communications.Hypergrid; @@ -50,6 +51,18 @@ namespace OpenSim.Region.Framework.Scenes.Hypergrid // private Dictionary m_inventoryServers = new Dictionary(); private Scene m_scene; + + private IHyperlinkService m_hyper; + IHyperlinkService HyperlinkService + { + get + { + if (m_hyper == null) + m_hyper = m_scene.RequestModuleInterface(); + return m_hyper; + } + } + #endregion #region Constructor @@ -79,22 +92,6 @@ namespace OpenSim.Region.Framework.Scenes.Hypergrid // return null; // } - private bool IsLocalUser(UUID userID) - { - CachedUserInfo uinfo = m_scene.CommsManager.UserProfileCacheService.GetUserDetails(userID); - - if (uinfo != null) - { - if (HGNetworkServersInfo.Singleton.IsLocalUser(uinfo.UserProfile)) - { - m_log.Debug("[HGScene]: Home user " + uinfo.UserProfile.FirstName + " " + uinfo.UserProfile.SurName); - return true; - } - } - - m_log.Debug("[HGScene]: Foreign user " + uinfo.UserProfile.FirstName + " " + uinfo.UserProfile.SurName); - return false; - } public AssetBase FetchAsset(string url, UUID assetID) { @@ -170,7 +167,7 @@ namespace OpenSim.Region.Framework.Scenes.Hypergrid public void Get(UUID assetID, UUID ownerID) { - if (!IsLocalUser(ownerID)) + if (!HyperlinkService.IsLocalUser(ownerID)) { // Get the item from the remote asset server onto the local AssetCache // and place an entry in m_assetMap @@ -228,7 +225,7 @@ namespace OpenSim.Region.Framework.Scenes.Hypergrid public void Post(UUID assetID, UUID ownerID) { - if (!IsLocalUser(ownerID)) + if (!HyperlinkService.IsLocalUser(ownerID)) { // Post the item from the local AssetCache onto the remote asset server // and place an entry in m_assetMap diff --git a/OpenSim/Region/Framework/Scenes/Hypergrid/HGSceneCommunicationService.cs b/OpenSim/Region/Framework/Scenes/Hypergrid/HGSceneCommunicationService.cs index ee5eb904ed..1217f9bd9a 100644 --- a/OpenSim/Region/Framework/Scenes/Hypergrid/HGSceneCommunicationService.cs +++ b/OpenSim/Region/Framework/Scenes/Hypergrid/HGSceneCommunicationService.cs @@ -38,6 +38,7 @@ using OpenSim.Framework.Communications; using OpenSim.Framework.Communications.Cache; using OpenSim.Framework.Capabilities; using OpenSim.Region.Framework.Interfaces; +using OpenSim.Services.Interfaces; using GridRegion = OpenSim.Services.Interfaces.GridRegion; namespace OpenSim.Region.Framework.Scenes.Hypergrid @@ -46,11 +47,19 @@ namespace OpenSim.Region.Framework.Scenes.Hypergrid { private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); - public readonly IHyperlink m_hg; - - public HGSceneCommunicationService(CommunicationsManager commsMan, IHyperlink hg) : base(commsMan) + private IHyperlinkService m_hg; + IHyperlinkService HyperlinkService + { + get + { + if (m_hg == null) + m_hg = m_scene.RequestModuleInterface(); + return m_hg; + } + } + + public HGSceneCommunicationService(CommunicationsManager commsMan) : base(commsMan) { - m_hg = hg; } @@ -129,13 +138,13 @@ namespace OpenSim.Region.Framework.Scenes.Hypergrid /// Hypergrid mod start /// /// - bool isHyperLink = m_hg.IsHyperlinkRegion(reg.RegionHandle); + bool isHyperLink = (HyperlinkService.GetHyperlinkRegion(reg.RegionHandle) != null); bool isHomeUser = true; ulong realHandle = regionHandle; CachedUserInfo uinfo = m_commsProvider.UserProfileCacheService.GetUserDetails(avatar.UUID); if (uinfo != null) { - isHomeUser = HGNetworkServersInfo.Singleton.IsLocalUser(uinfo.UserProfile); + isHomeUser = HyperlinkService.IsLocalUser(uinfo.UserProfile.ID); realHandle = m_hg.FindRegionHandle(regionHandle); m_log.Debug("XXX ---- home user? " + isHomeUser + " --- hyperlink? " + isHyperLink + " --- real handle: " + realHandle.ToString()); } diff --git a/OpenSim/Server/Handlers/Grid/HypergridServerConnector.cs b/OpenSim/Server/Handlers/Grid/HypergridServerConnector.cs index d2e791bef2..c47f652294 100644 --- a/OpenSim/Server/Handlers/Grid/HypergridServerConnector.cs +++ b/OpenSim/Server/Handlers/Grid/HypergridServerConnector.cs @@ -38,6 +38,7 @@ using OpenSim.Framework.Servers.HttpServer; using OpenSim.Server.Handlers.Base; using GridRegion = OpenSim.Services.Interfaces.GridRegion; +using OpenMetaverse; using log4net; using Nwc.XmlRpc; @@ -50,11 +51,25 @@ namespace OpenSim.Server.Handlers.Grid MethodBase.GetCurrentMethod().DeclaringType); private List m_RegionsOnSim = new List(); + private IHyperlinkService m_HyperlinkService; - public HypergridServiceInConnector(IConfigSource config, IHttpServer server) : + public HypergridServiceInConnector(IConfigSource config, IHttpServer server, IHyperlinkService hyperService) : base(config, server) { + m_HyperlinkService = hyperService; server.AddXmlRPCHandler("link_region", LinkRegionRequest, false); + server.AddXmlRPCHandler("expect_hg_user", ExpectHGUser, false); + } + + public void AddRegion(GridRegion rinfo) + { + m_RegionsOnSim.Add(rinfo); + } + + public void RemoveRegion(GridRegion rinfo) + { + if (m_RegionsOnSim.Contains(rinfo)) + m_RegionsOnSim.Remove(rinfo); } /// @@ -99,15 +114,95 @@ namespace OpenSim.Server.Handlers.Grid return response; } - public void AddRegion(GridRegion rinfo) + /// + /// Received from other HGrid nodes when a user wants to teleport here. This call allows + /// the region to prepare for direct communication from the client. Sends back an empty + /// xmlrpc response on completion. + /// This is somewhat similar to OGS1's ExpectUser, but with the additional task of + /// registering the user in the local user cache. + /// + /// + /// + public XmlRpcResponse ExpectHGUser(XmlRpcRequest request, IPEndPoint remoteClient) { - m_RegionsOnSim.Add(rinfo); + Hashtable requestData = (Hashtable)request.Params[0]; + ForeignUserProfileData userData = new ForeignUserProfileData(); + + userData.FirstName = (string)requestData["firstname"]; + userData.SurName = (string)requestData["lastname"]; + userData.ID = new UUID((string)requestData["agent_id"]); + UUID sessionID = new UUID((string)requestData["session_id"]); + userData.HomeLocation = new Vector3((float)Convert.ToDecimal((string)requestData["startpos_x"]), + (float)Convert.ToDecimal((string)requestData["startpos_y"]), + (float)Convert.ToDecimal((string)requestData["startpos_z"])); + + userData.UserServerURI = (string)requestData["userserver_id"]; + userData.UserAssetURI = (string)requestData["assetserver_id"]; + userData.UserInventoryURI = (string)requestData["inventoryserver_id"]; + + m_log.DebugFormat("[HGrid]: Prepare for connection from {0} {1} (@{2}) UUID={3}", + userData.FirstName, userData.SurName, userData.UserServerURI, userData.ID); + + ulong userRegionHandle = 0; + int userhomeinternalport = 0; + if (requestData.ContainsKey("region_uuid")) + { + UUID uuid = UUID.Zero; + UUID.TryParse((string)requestData["region_uuid"], out uuid); + userData.HomeRegionID = uuid; + userRegionHandle = Convert.ToUInt64((string)requestData["regionhandle"]); + userData.UserHomeAddress = (string)requestData["home_address"]; + userData.UserHomePort = (string)requestData["home_port"]; + userhomeinternalport = Convert.ToInt32((string)requestData["internal_port"]); + + m_log.Debug("[HGrid]: home_address: " + userData.UserHomeAddress + + "; home_port: " + userData.UserHomePort); + } + else + m_log.WarnFormat("[HGrid]: User has no home region information"); + + XmlRpcResponse resp = new XmlRpcResponse(); + + // Let's check if someone is trying to get in with a stolen local identity. + // The need for this test is a consequence of not having truly global names :-/ + bool comingHome = false; + if (m_HyperlinkService.CheckUserAtEntry(userData.ID, sessionID, out comingHome) == false) + { + m_log.WarnFormat("[HGrid]: Access denied to foreign user."); + Hashtable respdata = new Hashtable(); + respdata["success"] = "FALSE"; + respdata["reason"] = "Foreign user has the same ID as a local user, or logins disabled."; + resp.Value = respdata; + return resp; + } + + // Finally, everything looks ok + //m_log.Debug("XXX---- EVERYTHING OK ---XXX"); + + if (!comingHome) + { + // We don't do this if the user is coming to the home grid + GridRegion home = new GridRegion(); + home.RegionID = userData.HomeRegionID; + home.ExternalHostName = userData.UserHomeAddress; + home.HttpPort = Convert.ToUInt32(userData.UserHomePort); + uint x = 0, y = 0; + Utils.LongToUInts(userRegionHandle, out x, out y); + home.RegionLocX = (int)x; + home.RegionLocY = (int)y; + home.InternalEndPoint = new IPEndPoint(IPAddress.Parse("0.0.0.0"), (int)userhomeinternalport); + + m_HyperlinkService.AcceptUser(userData, home); + } + // else the user is coming to a non-home region of the home grid + // We simply drop this user information altogether + + Hashtable respdata2 = new Hashtable(); + respdata2["success"] = "TRUE"; + resp.Value = respdata2; + + return resp; } - public void RemoveRegion(GridRegion rinfo) - { - if (m_RegionsOnSim.Contains(rinfo)) - m_RegionsOnSim.Remove(rinfo); - } } } diff --git a/OpenSim/Services/Connectors/Grid/HypergridServiceConnector.cs b/OpenSim/Services/Connectors/Grid/HypergridServiceConnector.cs index cf175571cd..dd19b01b81 100644 --- a/OpenSim/Services/Connectors/Grid/HypergridServiceConnector.cs +++ b/OpenSim/Services/Connectors/Grid/HypergridServiceConnector.cs @@ -149,5 +149,94 @@ namespace OpenSim.Services.Connectors.Grid } } + public bool InformRegionOfUser(GridRegion regInfo, AgentCircuitData agentData, GridRegion home, string userServer, string assetServer, string inventoryServer) + { + string capsPath = agentData.CapsPath; + Hashtable loginParams = new Hashtable(); + loginParams["session_id"] = agentData.SessionID.ToString(); + + loginParams["firstname"] = agentData.firstname; + loginParams["lastname"] = agentData.lastname; + + loginParams["agent_id"] = agentData.AgentID.ToString(); + loginParams["circuit_code"] = agentData.circuitcode.ToString(); + loginParams["startpos_x"] = agentData.startpos.X.ToString(); + loginParams["startpos_y"] = agentData.startpos.Y.ToString(); + loginParams["startpos_z"] = agentData.startpos.Z.ToString(); + loginParams["caps_path"] = capsPath; + + if (home != null) + { + loginParams["region_uuid"] = home.RegionID.ToString(); + loginParams["regionhandle"] = home.RegionHandle.ToString(); + loginParams["home_address"] = home.ExternalHostName; + loginParams["home_port"] = home.HttpPort.ToString(); + loginParams["internal_port"] = home.InternalEndPoint.Port.ToString(); + + m_log.Debug(" --------- Home -------"); + m_log.Debug(" >> " + loginParams["home_address"] + " <<"); + m_log.Debug(" >> " + loginParams["region_uuid"] + " <<"); + m_log.Debug(" >> " + loginParams["regionhandle"] + " <<"); + m_log.Debug(" >> " + loginParams["home_port"] + " <<"); + m_log.Debug(" --------- ------------ -------"); + } + else + m_log.WarnFormat("[HGrid]: Home region not found for {0} {1}", agentData.firstname, agentData.lastname); + + loginParams["userserver_id"] = userServer; + loginParams["assetserver_id"] = assetServer; + loginParams["inventoryserver_id"] = inventoryServer; + + + ArrayList SendParams = new ArrayList(); + SendParams.Add(loginParams); + + // Send + string uri = "http://" + regInfo.ExternalHostName + ":" + regInfo.HttpPort + "/"; + //m_log.Debug("XXX uri: " + uri); + XmlRpcRequest request = new XmlRpcRequest("expect_hg_user", SendParams); + XmlRpcResponse reply; + try + { + reply = request.Send(uri, 6000); + } + catch (Exception e) + { + m_log.Warn("[HGrid]: Failed to notify region about user. Reason: " + e.Message); + return false; + } + + if (!reply.IsFault) + { + bool responseSuccess = true; + if (reply.Value != null) + { + Hashtable resp = (Hashtable)reply.Value; + if (resp.ContainsKey("success")) + { + if ((string)resp["success"] == "FALSE") + { + responseSuccess = false; + } + } + } + if (responseSuccess) + { + m_log.Info("[HGrid]: Successfully informed remote region about user " + agentData.AgentID); + return true; + } + else + { + m_log.ErrorFormat("[HGrid]: Region responded that it is not available to receive clients"); + return false; + } + } + else + { + m_log.ErrorFormat("[HGrid]: XmlRpc request to region failed with message {0}, code {1} ", reply.FaultString, reply.FaultCode); + return false; + } + } + } } diff --git a/OpenSim/Services/Interfaces/IGridService.cs b/OpenSim/Services/Interfaces/IGridService.cs index 96dc82b90b..c5495fb209 100644 --- a/OpenSim/Services/Interfaces/IGridService.cs +++ b/OpenSim/Services/Interfaces/IGridService.cs @@ -191,6 +191,20 @@ namespace OpenSim.Services.Interfaces Maturity = ConvertFrom.RegionSettings.Maturity; } + public GridRegion(GridRegion ConvertFrom) + { + m_regionName = ConvertFrom.RegionName; + m_regionLocX = ConvertFrom.RegionLocX; + m_regionLocY = ConvertFrom.RegionLocY; + m_internalEndPoint = ConvertFrom.InternalEndPoint; + m_externalHostName = ConvertFrom.ExternalHostName; + m_httpPort = ConvertFrom.HttpPort; + RegionID = ConvertFrom.RegionID; + ServerURI = ConvertFrom.ServerURI; + TerrainImage = ConvertFrom.TerrainImage; + Access = ConvertFrom.Access; + Maturity = ConvertFrom.Maturity; + } /// /// This accessor can throw all the exceptions that Dns.GetHostAddresses can throw.