Browse Source

a few changes to getregion(s)byName()

UbitUmarov 3 years ago
parent
commit
d0ade39641

+ 13 - 22
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;
-
-            // 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 (m_RemoteGridService == null || !uri.IsLocalGrid)
+                return rinfo;
 
-            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;
         }

+ 5 - 0
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<GridRegion> GetRegionsByName(UUID scopeID, string name, int maxNumber)
         {
             Dictionary<string, object> sendData = new Dictionary<string, object>();

+ 97 - 91
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<GridRegion> defregs = GetDefaultRegions(scopeID);
+                    if (defregs != null)
+                        return defregs[0];
+                }
+                return null;
+            }
+
+            if (!m_AllowHypergridMapSearch)
+                return null;
+
+            string mapname = uri.RegionHostPortSpaceName;
+            List<RegionData> 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<GridRegion> GetRegionsByName(UUID scopeID, string name, int maxNumber)
@@ -551,7 +596,16 @@ namespace OpenSim.Services.GridService
             if (!nameURI.IsValid)
                 return new List<GridRegion>();
 
-            bool localGrid = true;
+            return GetRegionsByURI(scopeID, nameURI, maxNumber);
+        }
+
+        public List<GridRegion> GetRegionsByURI(UUID scopeID, RegionURI nameURI, int maxNumber)
+        {
+            // m_log.DebugFormat("[GRID SERVICE]: GetRegionsByName {0}", name);
+            if (!nameURI.IsValid)
+                return new List<GridRegion>();
+
+            bool localGrid;
             if (nameURI.HasHost)
             {
                 if (!nameURI.ResolveDNS())
@@ -561,15 +615,8 @@ namespace OpenSim.Services.GridService
                 if (!nameURI.IsValid)
                     return new List<GridRegion>();
             }
-
-            return GetRegionsByURI(scopeID, nameURI, maxNumber);
-        }
-
-        public List<GridRegion> GetRegionsByURI(UUID scopeID, RegionURI nameURI, int maxNumber)
-        {
-            // m_log.DebugFormat("[GRID SERVICE]: GetRegionsByName {0}", name);
-            if (!nameURI.IsValid)
-                return new List<GridRegion>();
+            else
+                localGrid = true;
 
             int count = 0;
 
@@ -577,46 +624,12 @@ namespace OpenSim.Services.GridService
             List<RegionData> rdatas = m_Database.Get("%" + Util.EscapeForLike(mapname) + "%", scopeID);
             List<GridRegion> rinfos = new List<GridRegion>();
 
-            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<GridRegion> 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;
-        }
 
-        /// <summary>
-        /// Get a hypergrid region.
-        /// </summary>
-        /// <param name="scopeID"></param>
-        /// <param name="name"></param>
-        /// <returns>null if no hypergrid region could be found.</returns>
-        protected GridRegion GetHypergridRegionByName(UUID scopeID, string name)
-        {
-            if (name.Contains("."))
-            {
-                string regionURI = "";
-                string regionName = "";
-                if (!Util.buildHGRegionURI(name, out regionURI, out regionName))
-                    return null;
+            if (!m_AllowHypergridMapSearch)
+                return rinfos;
 
-                string mapname;
-                bool localGrid = m_HypergridLinker.IsLocalGrid(regionURI);
-                if (localGrid)
+            if (rdatas != null && (rdatas.Count > 0))
+            {
+                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 if (count++ < maxNumber)
+                        rinfos.Add(RegionData2RegionInfo(rdata));
                 }
-                else
-                    mapname = regionURI + regionName;
-
-                List<RegionData> rdatas = m_Database.Get(Util.EscapeForLike(mapname), scopeID);
-                if ((rdatas != null) && (rdatas.Count > 0))
-                    return RegionData2RegionInfo(rdatas[0]); // get the first
+                if (haveMatch)
+                    return rinfos;
+            }
 
-                if(!localGrid && !string.IsNullOrWhiteSpace(regionURI))
-                {
-                    string HGname = regionURI +" "+ regionName;
-                    return m_HypergridLinker.LinkRegion(scopeID, HGname);
-                }
+            GridRegion r = m_HypergridLinker.LinkRegion(scopeID, nameURI);
+            if (r != null)
+            {
+                if (count == maxNumber)
+                    rinfos.RemoveAt(count - 1);
+                rinfos.Add(r);
             }
-            return null;
+
+            return rinfos;
         }
 
         public List<GridRegion> GetRegionRange(UUID scopeID, int xmin, int xmax, int ymin, int ymax)

+ 1 - 0
OpenSim/Services/Interfaces/IGridService.cs

@@ -83,6 +83,7 @@ namespace OpenSim.Services.Interfaces
         /// <param name="regionName"></param>
         /// <returns>Returns the region information if the name matched.  Null otherwise.</returns>
         GridRegion GetRegionByName(UUID scopeID, string regionName);
+        GridRegion GetRegionByURI(UUID scopeID, RegionURI uri);
 
         /// <summary>
         /// Get information about regions starting with the provided name.