From d0ade396415d492087a7707b5678a5e2d5380e79 Mon Sep 17 00:00:00 2001 From: UbitUmarov Date: Tue, 22 Dec 2020 14:27:01 +0000 Subject: [PATCH] a few changes to getregion(s)byName() --- .../Grid/RegionGridServiceConnector.cs | 35 ++-- .../Connectors/Grid/GridServicesConnector.cs | 5 + OpenSim/Services/GridService/GridService.cs | 192 +++++++++--------- OpenSim/Services/Interfaces/IGridService.cs | 1 + 4 files changed, 118 insertions(+), 115 deletions(-) diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/RegionGridServiceConnector.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/RegionGridServiceConnector.cs index d6dc2c07b1..0b747c8d37 100644 --- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/RegionGridServiceConnector.cs +++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/RegionGridServiceConnector.cs @@ -300,33 +300,25 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid if (inCache) return rinfo; - rinfo = m_LocalGridService.GetRegionByName(scopeID, name); + var ruri = new RegionURI(name, m_ThisGridInfo); + return GetRegionByURI(scopeID, ruri); + } + + public GridRegion GetRegionByURI(UUID scopeID, RegionURI uri) + { + GridRegion rinfo = m_LocalGridService.GetRegionByURI(scopeID, uri); if (rinfo != null) { m_RegionInfoCache.Cache(scopeID, rinfo); return rinfo; } - if(m_RemoteGridService == null) - return null; + if (m_RemoteGridService == null || !uri.IsLocalGrid) + return rinfo; - // HG urls should not get here, strip them - // side effect is that local regions with same name as HG may also be found - // this mb good or bad - string regionName = name; - if(name.Contains(".")) - { - if(!m_ThisGridInfo.HasHGConfig) - return rinfo; // no HG - - string regionURI = ""; - if (!Util.buildHGRegionURI(name, out regionURI, out regionName)) - return rinfo; // invalid - if (m_ThisGridInfo.IsLocalGrid(regionURI) != 1) - return rinfo; // not local grid - } - - if (string.IsNullOrEmpty(regionName)) + if (uri.HasRegionName) + rinfo = m_RemoteGridService.GetRegionByName(scopeID, uri.RegionName); + else { rinfo = m_RemoteGridService.GetDefaultRegions(UUID.Zero)[0]; if (rinfo == null) @@ -334,8 +326,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid else m_log.WarnFormat("[REMOTE GRID CONNECTOR] returned default region {0}", rinfo.RegionName); } - else - rinfo = m_RemoteGridService.GetRegionByName(scopeID, regionName); + m_RegionInfoCache.Cache(scopeID, rinfo); return rinfo; } diff --git a/OpenSim/Services/Connectors/Grid/GridServicesConnector.cs b/OpenSim/Services/Connectors/Grid/GridServicesConnector.cs index 1e8c622be2..1ceff3349b 100644 --- a/OpenSim/Services/Connectors/Grid/GridServicesConnector.cs +++ b/OpenSim/Services/Connectors/Grid/GridServicesConnector.cs @@ -369,6 +369,11 @@ namespace OpenSim.Services.Connectors return rinfo; } + public GridRegion GetRegionByURI(UUID scopeID, RegionURI uri) + { + return null; + } + public List GetRegionsByName(UUID scopeID, string name, int maxNumber) { Dictionary sendData = new Dictionary(); diff --git a/OpenSim/Services/GridService/GridService.cs b/OpenSim/Services/GridService/GridService.cs index 0570187822..9120d63d39 100755 --- a/OpenSim/Services/GridService/GridService.cs +++ b/OpenSim/Services/GridService/GridService.cs @@ -529,18 +529,63 @@ namespace OpenSim.Services.GridService public GridRegion GetRegionByName(UUID scopeID, string name) { - RegionData rdata = m_Database.GetSpecific(name, scopeID); - if (rdata != null) - return RegionData2RegionInfo(rdata); + var nameURI = new RegionURI(name); + if (!nameURI.IsValid) + return null; + return GetRegionByURI(scopeID, nameURI); + } - if (m_AllowHypergridMapSearch) + public GridRegion GetRegionByURI(UUID scopeID, RegionURI uri) + { + if (!uri.IsValid) + return null; + + bool localGrid = true; + if (uri.HasHost) { - GridRegion r = GetHypergridRegionByName(scopeID, name); - if (r != null) - return r; + if (!uri.ResolveDNS()) + return null; + localGrid = m_HypergridLinker.IsLocalGrid(uri.HostUrl); + uri.IsLocalGrid = localGrid; } - return null; + if (localGrid) + { + if(uri.HasRegionName) + { + RegionData rdata = m_Database.GetSpecific(uri.RegionName, scopeID); + if (rdata != null) + return RegionData2RegionInfo(rdata); + } + else + { + List defregs = GetDefaultRegions(scopeID); + if (defregs != null) + return defregs[0]; + } + return null; + } + + if (!m_AllowHypergridMapSearch) + return null; + + string mapname = uri.RegionHostPortSpaceName; + List rdatas = m_Database.Get("%" + Util.EscapeForLike(mapname), scopeID); + if (rdatas != null && rdatas.Count > 0) + { + foreach (RegionData rdata in rdatas) + { + int indx = rdata.RegionName.IndexOf("://"); + if (indx < 0) + continue; + string rname = rdata.RegionName.Substring(indx + 3); + if (mapname.Equals(rname, StringComparison.InvariantCultureIgnoreCase)) + return RegionData2RegionInfo(rdata); + } + } + + GridRegion r = m_HypergridLinker.LinkRegion(scopeID, uri); + return r; } public List GetRegionsByName(UUID scopeID, string name, int maxNumber) @@ -551,17 +596,6 @@ namespace OpenSim.Services.GridService if (!nameURI.IsValid) return new List(); - bool localGrid = true; - if (nameURI.HasHost) - { - if (!nameURI.ResolveDNS()) - return new List(); - localGrid = m_HypergridLinker.IsLocalGrid(nameURI.HostUrl); - nameURI.IsLocalGrid = localGrid; - if (!nameURI.IsValid) - return new List(); - } - return GetRegionsByURI(scopeID, nameURI, maxNumber); } @@ -571,52 +605,31 @@ namespace OpenSim.Services.GridService if (!nameURI.IsValid) return new List(); + bool localGrid; + if (nameURI.HasHost) + { + if (!nameURI.ResolveDNS()) + return new List(); + localGrid = m_HypergridLinker.IsLocalGrid(nameURI.HostUrl); + nameURI.IsLocalGrid = localGrid; + if (!nameURI.IsValid) + return new List(); + } + else + localGrid = true; + int count = 0; string mapname = nameURI.RegionHostPortSpaceName; List rdatas = m_Database.Get("%" + Util.EscapeForLike(mapname) + "%", scopeID); List rinfos = new List(); - if (m_AllowHypergridMapSearch && nameURI.HasHost) - { - if (rdatas != null && (rdatas.Count > 0)) - { - bool haveMatch = false; - // m_log.DebugFormat("[GRID SERVICE]: Found {0} regions", rdatas.Count); - foreach (RegionData rdata in rdatas) - { - int indx = rdata.RegionName.IndexOf("://"); - if(indx < 0) - continue; - string rname = rdata.RegionName.Substring(indx + 3); - if (mapname.Equals(rname, StringComparison.InvariantCultureIgnoreCase)) - { - haveMatch = true; - rinfos.Insert(0, RegionData2RegionInfo(rdata)); - if (count == maxNumber) - rinfos.RemoveAt(count - 1); - } - else if (count++ < maxNumber) - rinfos.Add(RegionData2RegionInfo(rdata)); - } - if (haveMatch) - return rinfos; - } - - GridRegion r = m_HypergridLinker.LinkRegion(scopeID, nameURI); - if (r != null) - { - if (count == maxNumber) - rinfos.RemoveAt(count - 1); - rinfos.Add(r); - } - } - else + if(localGrid) { if (!nameURI.HasRegionName) { List dinfos = GetDefaultRegions(scopeID); - if(dinfos != null && dinfos.Count >0) + if (dinfos != null && dinfos.Count > 0) rinfos.Add(dinfos[0]); } else @@ -638,52 +651,45 @@ namespace OpenSim.Services.GridService } } } + return rinfos; } - return rinfos; - } - /// - /// Get a hypergrid region. - /// - /// - /// - /// null if no hypergrid region could be found. - protected GridRegion GetHypergridRegionByName(UUID scopeID, string name) - { - if (name.Contains(".")) + if (!m_AllowHypergridMapSearch) + return rinfos; + + if (rdatas != null && (rdatas.Count > 0)) { - string regionURI = ""; - string regionName = ""; - if (!Util.buildHGRegionURI(name, out regionURI, out regionName)) - return null; - - string mapname; - bool localGrid = m_HypergridLinker.IsLocalGrid(regionURI); - if (localGrid) + bool haveMatch = false; + // m_log.DebugFormat("[GRID SERVICE]: Found {0} regions", rdatas.Count); + foreach (RegionData rdata in rdatas) { - if (String.IsNullOrWhiteSpace(regionName)) + int indx = rdata.RegionName.IndexOf("://"); + if(indx < 0) + continue; + string rname = rdata.RegionName.Substring(indx + 3); + if (mapname.Equals(rname, StringComparison.InvariantCultureIgnoreCase)) { - List< GridRegion> defregs = GetDefaultRegions(scopeID); - if(defregs == null) - return null; - return defregs[0]; + haveMatch = true; + rinfos.Insert(0, RegionData2RegionInfo(rdata)); + if (count == maxNumber) + rinfos.RemoveAt(count - 1); } - mapname = regionName; - } - else - mapname = regionURI + regionName; - - List rdatas = m_Database.Get(Util.EscapeForLike(mapname), scopeID); - if ((rdatas != null) && (rdatas.Count > 0)) - return RegionData2RegionInfo(rdatas[0]); // get the first - - if(!localGrid && !string.IsNullOrWhiteSpace(regionURI)) - { - string HGname = regionURI +" "+ regionName; - return m_HypergridLinker.LinkRegion(scopeID, HGname); + else if (count++ < maxNumber) + rinfos.Add(RegionData2RegionInfo(rdata)); } + if (haveMatch) + return rinfos; } - return null; + + GridRegion r = m_HypergridLinker.LinkRegion(scopeID, nameURI); + if (r != null) + { + if (count == maxNumber) + rinfos.RemoveAt(count - 1); + rinfos.Add(r); + } + + return rinfos; } public List GetRegionRange(UUID scopeID, int xmin, int xmax, int ymin, int ymax) diff --git a/OpenSim/Services/Interfaces/IGridService.cs b/OpenSim/Services/Interfaces/IGridService.cs index 16bce68695..2515fe8930 100644 --- a/OpenSim/Services/Interfaces/IGridService.cs +++ b/OpenSim/Services/Interfaces/IGridService.cs @@ -83,6 +83,7 @@ namespace OpenSim.Services.Interfaces /// /// Returns the region information if the name matched. Null otherwise. GridRegion GetRegionByName(UUID scopeID, string regionName); + GridRegion GetRegionByURI(UUID scopeID, RegionURI uri); /// /// Get information about regions starting with the provided name.