diff --git a/OpenSim/Framework/GridInfo.cs b/OpenSim/Framework/GridInfo.cs index 689a6880ab..a3cb70af21 100644 --- a/OpenSim/Framework/GridInfo.cs +++ b/OpenSim/Framework/GridInfo.cs @@ -177,8 +177,8 @@ namespace OpenSim.Framework private OSHostURL m_gateKeeperURL; private HashSet m_gateKeeperAlias; - //private OSHostURL m_homeURL; - //private HashSet m_homeURLAlias; + private OSHostURL m_homeURL; + private HashSet m_homeURLAlias; public GridInfo (IConfigSource config, string defaultHost = "") { @@ -218,10 +218,45 @@ namespace OpenSim.Framework for (int i = 0; i < alias.Length; ++i) { OSHostURL tmp = new OSHostURL(alias[i].Trim(), false); - if(m_gateKeeperAlias == null) - m_gateKeeperAlias = new HashSet(); if (tmp.URLType != UriHostNameType.Unknown) + { + if (m_gateKeeperAlias == null) + m_gateKeeperAlias = new HashSet(); m_gateKeeperAlias.Add(tmp); + } + } + } + + string home = Util.GetConfigVarFromSections(config, "HomeURI", sections, string.Empty); + + if (string.IsNullOrEmpty(home)) + { + if (!string.IsNullOrEmpty(gatekeeper)) + m_homeURL = m_gateKeeperURL; + else if (!string.IsNullOrEmpty(defaultHost)) + m_homeURL = new OSHostURL(defaultHost, true); + } + else + m_homeURL = new OSHostURL(home, true); + + if (m_homeURL.URLType == UriHostNameType.Unknown) + throw new Exception(String.Format("could not find home(UserAgentsService) URL")); + if (m_homeURL.IP == null) + throw new Exception(String.Format("could not resolve home(UserAgentsService) hostname")); + + string homeAlias = Util.GetConfigVarFromSections(config, "HomeURIAlias", sections, String.Empty); + if (!string.IsNullOrWhiteSpace(homeAlias)) + { + string[] alias = homeAlias.Split(','); + for (int i = 0; i < alias.Length; ++i) + { + OSHostURL tmp = new OSHostURL(alias[i].Trim(), false); + if (tmp.URLType != UriHostNameType.Unknown) + { + if (m_homeURLAlias == null) + m_homeURLAlias = new HashSet(); + m_homeURLAlias.Add(tmp); + } } } } @@ -236,6 +271,16 @@ namespace OpenSim.Framework } } + public string HomeURL + { + get + { + if (m_homeURL.URLType != UriHostNameType.Unknown) + return m_homeURL.URL; + return null; + } + } + public int IsLocalGrid(string gatekeeper) { OSHostURL tmp = new OSHostURL(gatekeeper, false); @@ -247,5 +292,18 @@ namespace OpenSim.Framework return 1; return 0; } + + public int IsLocalHome(string home) + { + OSHostURL tmp = new OSHostURL(home, false); + if (tmp.URLType == UriHostNameType.Unknown) + return -1; + if (tmp.Equals(m_homeURL)) + return 1; + if (m_homeURLAlias != null && m_homeURLAlias.Contains(tmp)) + return 1; + return 0; + } + } } diff --git a/OpenSim/Region/CoreModules/Framework/UserManagement/UserManagementModule.cs b/OpenSim/Region/CoreModules/Framework/UserManagement/UserManagementModule.cs index 0d4aa7cf29..3377d880b5 100755 --- a/OpenSim/Region/CoreModules/Framework/UserManagement/UserManagementModule.cs +++ b/OpenSim/Region/CoreModules/Framework/UserManagement/UserManagementModule.cs @@ -58,8 +58,8 @@ namespace OpenSim.Region.CoreModules.Framework.UserManagement protected IServiceThrottleModule m_ServiceThrottle; protected IUserAccountService m_userAccountService = null; protected IGridUserService m_gridUserService = null; - string m_ThisGatekeeperHost; - HashSet m_ThisGateKeeperAlias = new HashSet(); + + protected GridInfo m_thisGridInfo; // The cache protected ExpiringCacheOS m_userCacheByID = new ExpiringCacheOS(60000); @@ -126,7 +126,8 @@ namespace OpenSim.Region.CoreModules.Framework.UserManagement { m_Scenes.Add(scene); } - + if(m_thisGridInfo == null) + m_thisGridInfo = scene.SceneGridInfo; scene.RegisterModuleInterface(this); scene.RegisterModuleInterface(this); scene.EventManager.OnNewClient += EventManager_OnNewClient; @@ -171,7 +172,7 @@ namespace OpenSim.Region.CoreModules.Framework.UserManagement { m_Scenes.Clear(); } - + m_thisGridInfo = null; Dispose(false); } @@ -267,10 +268,7 @@ namespace OpenSim.Region.CoreModules.Framework.UserManagement string host = uri.DnsSafeHost.ToLower(); - if (m_ThisGatekeeperHost.Equals(host)) - islocal = true; - else if (m_ThisGateKeeperAlias.Contains(host)) - islocal = true; + islocal = m_thisGridInfo.IsLocalHome(host) == 1; return true; } @@ -944,38 +942,6 @@ namespace OpenSim.Region.CoreModules.Framework.UserManagement protected virtual void Init(IConfigSource config) { - m_ThisGatekeeperHost = Util.GetConfigVarFromSections(config, "GatekeeperURI", - new string[] { "Startup", "Hypergrid", "GridService" }, String.Empty); - m_ThisGatekeeperHost = Util.GetConfigVarFromSections(config, "Gatekeeper", - new string[] { "Startup", "Hypergrid", "GridService" }, m_ThisGatekeeperHost); - - string gatekeeperURIAlias = Util.GetConfigVarFromSections(config, "GatekeeperURIAlias", - new string[] { "Startup", "Hypergrid", "GridService" }, String.Empty); - - if (!string.IsNullOrWhiteSpace(m_ThisGatekeeperHost)) - { - try - { - Uri uri = new Uri(m_ThisGatekeeperHost, UriKind.Absolute); - m_ThisGatekeeperHost = uri.DnsSafeHost.ToLower(); - } - catch - { - m_log.Error("[UserManagementModule] Invalid grid gatekeeper"); - m_ThisGatekeeperHost = string.Empty; - } - } - - if (!string.IsNullOrWhiteSpace(gatekeeperURIAlias)) - { - string[] alias = gatekeeperURIAlias.Split(','); - for (int i = 0; i < alias.Length; ++i) - { - if (!string.IsNullOrWhiteSpace(alias[i])) - m_ThisGateKeeperAlias.Add(alias[i].Trim().ToLower()); - } - } - AddUser(UUID.Zero, "Unknown", "User", false, int.MaxValue / 16); AddUser(Constants.m_MrOpenSimID, "Mr", "Opensim", false, int.MaxValue / 16); RegisterConsoleCmds();