From 131455b1070c1ca93c4bfda28272a7facbea7b5b Mon Sep 17 00:00:00 2001 From: UbitUmarov Date: Tue, 7 Dec 2021 00:34:40 +0000 Subject: [PATCH] add gridservice GetOnlineRegions() --- OpenSim/Data/IRegionData.cs | 1 + OpenSim/Data/MySQL/MySQLRegionData.cs | 5 ++ OpenSim/Data/Null/NullRegionData.cs | 5 ++ OpenSim/Data/PGSQL/PGSQLRegionData.cs | 5 ++ .../Grid/RegionGridServiceConnector.cs | 26 +++++++++- .../Handlers/Grid/GridServerPostHandler.cs | 50 ++++++++++++++++++ .../Connectors/Grid/GridServicesConnector.cs | 52 +++++++++++++++++++ OpenSim/Services/GridService/GridService.cs | 33 ++++++++++-- OpenSim/Services/Interfaces/IGridService.cs | 1 + 9 files changed, 173 insertions(+), 5 deletions(-) diff --git a/OpenSim/Data/IRegionData.cs b/OpenSim/Data/IRegionData.cs index e90857be5f..c83d37e003 100644 --- a/OpenSim/Data/IRegionData.cs +++ b/OpenSim/Data/IRegionData.cs @@ -86,6 +86,7 @@ namespace OpenSim.Data List GetDefaultHypergridRegions(UUID scopeID); List GetFallbackRegions(UUID scopeID); List GetHyperlinks(UUID scopeID); + List GetOnlineRegions(UUID scopeID); } public class RegionDataDistanceCompare : IComparer diff --git a/OpenSim/Data/MySQL/MySQLRegionData.cs b/OpenSim/Data/MySQL/MySQLRegionData.cs index fcd8109101..d17ff67022 100644 --- a/OpenSim/Data/MySQL/MySQLRegionData.cs +++ b/OpenSim/Data/MySQL/MySQLRegionData.cs @@ -402,6 +402,11 @@ namespace OpenSim.Data.MySQL return Get((int)RegionFlags.Hyperlink, scopeID); } + public List GetOnlineRegions(UUID scopeID) + { + return Get((int)RegionFlags.RegionOnline, scopeID); + } + private List Get(int regionFlags, UUID scopeID) { string command = "select * from `" + m_Realm + "` where (flags & " + regionFlags.ToString() + ") <> 0"; diff --git a/OpenSim/Data/Null/NullRegionData.cs b/OpenSim/Data/Null/NullRegionData.cs index e924bc762b..60d16e48d6 100644 --- a/OpenSim/Data/Null/NullRegionData.cs +++ b/OpenSim/Data/Null/NullRegionData.cs @@ -273,6 +273,11 @@ namespace OpenSim.Data.Null return Get((int)RegionFlags.Hyperlink, scopeID); } + public List GetOnlineRegions(UUID scopeID) + { + return Get((int)RegionFlags.RegionOnline, scopeID); + } + private List Get(int regionFlags, UUID scopeID) { if (Instance != this) diff --git a/OpenSim/Data/PGSQL/PGSQLRegionData.cs b/OpenSim/Data/PGSQL/PGSQLRegionData.cs index 5888ae8bf8..f90a3858c4 100644 --- a/OpenSim/Data/PGSQL/PGSQLRegionData.cs +++ b/OpenSim/Data/PGSQL/PGSQLRegionData.cs @@ -431,6 +431,11 @@ namespace OpenSim.Data.PGSQL return Get((int)RegionFlags.Hyperlink, scopeID); } + public List GetOnlineRegions(UUID scopeID) + { + return Get((int)RegionFlags.RegionOnline, scopeID); + } + private List Get(int regionFlags, UUID scopeID) { string sql = "SELECT * FROM " + m_Realm + " WHERE (\"flags\" & " + regionFlags.ToString() + ") <> 0"; diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/RegionGridServiceConnector.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/RegionGridServiceConnector.cs index 073d9626dd..a8ba8c0f51 100644 --- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/RegionGridServiceConnector.cs +++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/RegionGridServiceConnector.cs @@ -452,7 +452,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid { List rinfo = m_LocalGridService.GetFallbackRegions(scopeID, x, y); //m_log.DebugFormat("[REMOTE GRID CONNECTOR]: Local GetFallbackRegions {0} found {1} regions", name, rinfo.Count); - if(m_RemoteGridService != null) + if (m_RemoteGridService != null) { List grinfo = m_RemoteGridService.GetFallbackRegions(scopeID, x, y); @@ -462,7 +462,29 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid foreach (GridRegion r in grinfo) { m_RegionInfoCache.Cache(r); - if (rinfo.Find(delegate(GridRegion gr) { return gr.RegionID == r.RegionID; }) == null) + if (rinfo.Find(delegate (GridRegion gr) { return gr.RegionID == r.RegionID; }) == null) + rinfo.Add(r); + } + } + } + return rinfo; + } + + public List GetOnlineRegions(UUID scopeID, int x, int y, int maxCount) + { + List rinfo = m_LocalGridService.GetOnlineRegions(scopeID, x, y, maxCount); + //m_log.DebugFormat("[REMOTE GRID CONNECTOR]: Local GetFallbackRegions {0} found {1} regions", name, rinfo.Count); + if (m_RemoteGridService != null) + { + List grinfo = m_RemoteGridService.GetOnlineRegions(scopeID, x, y, maxCount); + + if (grinfo != null) + { + //m_log.DebugFormat("[REMOTE GRID CONNECTOR]: Remote GetOnlineRegions {0} found {1} regions", name, grinfo.Count); + foreach (GridRegion r in grinfo) + { + m_RegionInfoCache.Cache(r); + if (rinfo.Find(delegate (GridRegion gr) { return gr.RegionID == r.RegionID; }) == null) rinfo.Add(r); } } diff --git a/OpenSim/Server/Handlers/Grid/GridServerPostHandler.cs b/OpenSim/Server/Handlers/Grid/GridServerPostHandler.cs index 44d4654ceb..a0791b1d8b 100644 --- a/OpenSim/Server/Handlers/Grid/GridServerPostHandler.cs +++ b/OpenSim/Server/Handlers/Grid/GridServerPostHandler.cs @@ -117,6 +117,9 @@ namespace OpenSim.Server.Handlers.Grid case "get_fallback_regions": return GetFallbackRegions(request); + case "get_online_regions": + return GetOnlineRegions(request); + case "get_hyperlinks": return GetHyperlinks(request); @@ -543,6 +546,53 @@ namespace OpenSim.Server.Handlers.Grid return Util.UTF8NoBomEncoding.GetBytes(xmlString); } + byte[] GetOnlineRegions(Dictionary request) + { + UUID scopeID = UUID.Zero; + object o; + + if (request.TryGetValue("SCOPEID", out o)) + UUID.TryParse(o.ToString(), out scopeID); + else + m_log.WarnFormat("[GRID HANDLER]: no scopeID in request to get online regions"); + + int x = 0, y = 0, max = 0; + if (request.TryGetValue("X", out o)) + Int32.TryParse(o.ToString(), out x); + else + m_log.WarnFormat("[GRID HANDLER]: no X in request to get online regions"); + if (request.TryGetValue("Y", out o)) + Int32.TryParse(o.ToString(), out y); + else + m_log.WarnFormat("[GRID HANDLER]: no Y in request to get online regions"); + if (request.TryGetValue("MC", out o)) + Int32.TryParse(o.ToString(), out max); + else + m_log.WarnFormat("[GRID HANDLER]: no Y in request to get online regions"); + + List rinfos = null; + if (max > 0) + rinfos = m_GridService.GetOnlineRegions(scopeID, x, y, max); + + Dictionary result = new Dictionary(); + if ((rinfos == null) || ((rinfos != null) && (rinfos.Count == 0))) + result["result"] = "null"; + else + { + int i = 0; + foreach (GridRegion rinfo in rinfos) + { + Dictionary rinfoDict = rinfo.ToKeyValuePairs(); + result["region" + i] = rinfoDict; + i++; + } + } + string xmlString = ServerUtils.BuildXmlResponse(result); + + //m_log.DebugFormat("[GRID HANDLER]: resp string: {0}", xmlString); + return Util.UTF8NoBomEncoding.GetBytes(xmlString); + } + byte[] GetHyperlinks(Dictionary request) { //m_log.DebugFormat("[GRID HANDLER]: GetHyperlinks"); diff --git a/OpenSim/Services/Connectors/Grid/GridServicesConnector.cs b/OpenSim/Services/Connectors/Grid/GridServicesConnector.cs index 1ceff3349b..3e31d56437 100644 --- a/OpenSim/Services/Connectors/Grid/GridServicesConnector.cs +++ b/OpenSim/Services/Connectors/Grid/GridServicesConnector.cs @@ -640,6 +640,58 @@ namespace OpenSim.Services.Connectors return rinfos; } + public List GetOnlineRegions(UUID scopeID, int x, int y, int maxCount) + { + Dictionary sendData = new Dictionary(); + + sendData["SCOPEID"] = scopeID.ToString(); + sendData["X"] = x.ToString(); + sendData["Y"] = y.ToString(); + sendData["MC"] = maxCount.ToString(); + + sendData["METHOD"] = "get_online_regions"; + + List rinfos = new List(); + string reply = string.Empty; + try + { + reply = SynchronousRestFormsRequester.MakePostRequest(m_ServerURI + "/grid", + ServerUtils.BuildQueryString(sendData), m_Auth); + + //m_log.DebugFormat("[GRID CONNECTOR]: reply was {0}", reply); + } + catch (Exception e) + { + m_log.DebugFormat("[GRID CONNECTOR]: Exception when contacting grid server at {0}: {1}", m_ServerURI + "/grid", e.Message); + return rinfos; + } + + if (reply != string.Empty) + { + Dictionary replyData = ServerUtils.ParseXmlResponse(reply); + + if (replyData != null) + { + Dictionary.ValueCollection rinfosList = replyData.Values; + foreach (object r in rinfosList) + { + if (r is Dictionary) + { + GridRegion rinfo = new GridRegion((Dictionary)r); + rinfos.Add(rinfo); + } + } + } + else + m_log.DebugFormat("[GRID CONNECTOR]: GetOnlineRegions {0}, {1}-{2} received null response", + scopeID, x, y); + } + else + m_log.DebugFormat("[GRID CONNECTOR]: GetOnlineRegions received null reply"); + + return rinfos; + } + public List GetHyperlinks(UUID scopeID) { Dictionary sendData = new Dictionary(); diff --git a/OpenSim/Services/GridService/GridService.cs b/OpenSim/Services/GridService/GridService.cs index 55d0828338..7c16f62a88 100755 --- a/OpenSim/Services/GridService/GridService.cs +++ b/OpenSim/Services/GridService/GridService.cs @@ -790,8 +790,8 @@ namespace OpenSim.Services.GridService List ret = new List(); List regions = m_Database.GetFallbackRegions(scopeID); - if(regions.Count > 0) - { + if (regions.Count > 0) + { if (regions.Count > 1) { regions.Sort(new RegionDataDistanceCompare(x, y)); @@ -800,7 +800,7 @@ namespace OpenSim.Services.GridService foreach (RegionData r in regions) { int rflags = Convert.ToInt32(r.Data["flags"]); - if((rflags & (int)OpenSim.Framework.RegionFlags.Hyperlink) != 0) + if ((rflags & (int)OpenSim.Framework.RegionFlags.Hyperlink) != 0) continue; if ((rflags & (int)OpenSim.Framework.RegionFlags.RegionOnline) != 0) ret.Add(RegionData2RegionInfo(r)); @@ -811,6 +811,33 @@ namespace OpenSim.Services.GridService return ret; } + public List GetOnlineRegions(UUID scopeID, int x, int y, int maxCount) + { + List ret = new List(); + + List regions = m_Database.GetOnlineRegions(scopeID); + if (regions.Count > 0) + { + if (regions.Count > 1) + { + regions.Sort(new RegionDataDistanceCompare(x, y)); + } + + foreach (RegionData r in regions) + { + int rflags = Convert.ToInt32(r.Data["flags"]); + if ((rflags & (int)OpenSim.Framework.RegionFlags.Hyperlink) != 0) + continue; + ret.Add(RegionData2RegionInfo(r)); + if(ret.Count >= maxCount) + break; + } + } + + m_log.DebugFormat("[GRID SERVICE]: online returned {0} regions", ret.Count); + return ret; + } + public List GetHyperlinks(UUID scopeID) { List ret = new List(); diff --git a/OpenSim/Services/Interfaces/IGridService.cs b/OpenSim/Services/Interfaces/IGridService.cs index 2515fe8930..3c8e59d633 100644 --- a/OpenSim/Services/Interfaces/IGridService.cs +++ b/OpenSim/Services/Interfaces/IGridService.cs @@ -107,6 +107,7 @@ namespace OpenSim.Services.Interfaces List GetDefaultHypergridRegions(UUID scopeID); List GetFallbackRegions(UUID scopeID, int x, int y); List GetHyperlinks(UUID scopeID); + List GetOnlineRegions(UUID scopeID, int x, int y, int maxCount); /// /// Get internal OpenSimulator region flags.