diff --git a/OpenSim/Region/ClientStack/Linden/Caps/AgentPreferencesModule.cs b/OpenSim/Region/ClientStack/Linden/Caps/AgentPreferencesModule.cs index c34f65f960..dc7aa882f2 100644 --- a/OpenSim/Region/ClientStack/Linden/Caps/AgentPreferencesModule.cs +++ b/OpenSim/Region/ClientStack/Linden/Caps/AgentPreferencesModule.cs @@ -71,7 +71,6 @@ namespace OpenSim.Region.ClientStack.LindenCaps lock (m_scenes) m_scenes.Remove(scene); scene.EventManager.OnRegisterCaps -= RegisterCaps; - scene = null; } public void RegionLoaded(Scene scene) @@ -79,8 +78,7 @@ namespace OpenSim.Region.ClientStack.LindenCaps scene.EventManager.OnRegisterCaps += RegisterCaps; ISimulatorFeaturesModule simFeatures = scene.RequestModuleInterface(); - if(simFeatures != null) - simFeatures.AddFeature("AvatarHoverHeightEnabled",OSD.FromBoolean(true)); + simFeatures?.AddFeature("AvatarHoverHeightEnabled",OSD.FromBoolean(true)); } diff --git a/OpenSim/Server/Base/ServerUtils.cs b/OpenSim/Server/Base/ServerUtils.cs index 32b85a8cc2..91d46a39ab 100644 --- a/OpenSim/Server/Base/ServerUtils.cs +++ b/OpenSim/Server/Base/ServerUtils.cs @@ -543,19 +543,21 @@ namespace OpenSim.Server.Base public static Dictionary ParseXmlResponse(string data) { - try + if(!string.IsNullOrEmpty(data)) { - using XmlReader xr = XmlReader.Create(new StringReader(data), - ParseXmlStringResponseXmlReaderSettings, ParseXmlResponseXmlParserContext); - if (!xr.ReadToFollowing("ServerResponse")) - return new Dictionary(); - return ScanXmlResponse(xr); + try + { + using XmlReader xr = XmlReader.Create(new StringReader(data), + ParseXmlStringResponseXmlReaderSettings, ParseXmlResponseXmlParserContext); + if (xr.ReadToFollowing("ServerResponse")) + return ScanXmlResponse(xr); + } + catch (Exception e) + { + m_log.Debug($"[serverUtils.ParseXmlResponse]: failed error: {e.Message}\n --string:\n{data}\n"); + } } - catch (Exception e) - { - m_log.DebugFormat("[serverUtils.ParseXmlResponse]: failed error: {0}\n --string:\n{1}\n", e.Message, data); - } - return new Dictionary(); + return []; } private static readonly XmlReaderSettings ParseXmlStreamResponseXmlReaderSettings = new() diff --git a/OpenSim/Server/Handlers/Grid/GridServerPostHandler.cs b/OpenSim/Server/Handlers/Grid/GridServerPostHandler.cs index 7dc2254348..72df94b61e 100644 --- a/OpenSim/Server/Handlers/Grid/GridServerPostHandler.cs +++ b/OpenSim/Server/Handlers/Grid/GridServerPostHandler.cs @@ -102,6 +102,9 @@ namespace OpenSim.Server.Handlers.Grid case "get_region_by_name": return GetRegionByName(request); + case "get_localregion_by_name": + return GetLocalRegionByName(request); + case "get_regions_by_name": return GetRegionsByName(request); @@ -327,21 +330,40 @@ namespace OpenSim.Server.Handlers.Grid byte[] GetRegionByName(Dictionary request) { UUID scopeID = UUID.Zero; - if (request.ContainsKey("SCOPEID")) - UUID.TryParse(request["SCOPEID"].ToString(), out scopeID); - else - m_log.WarnFormat("[GRID HANDLER]: no scopeID in request to get region by name"); + if (!request.TryGetValue("SCOPEID", out object scpo) || scpo is not string scps || !UUID.TryParse(scps, out scopeID)) + m_log.WarnFormat("[GRID HANDLER]: no or invalid scopeID in request to get region by name"); - string regionName = string.Empty; - if (request.ContainsKey("NAME")) - regionName = request["NAME"].ToString(); + GridRegion rinfo = null; + if (request.TryGetValue("NAME", out object nameo) && nameo is string regionName) + rinfo = m_GridService.GetRegionByName(scopeID, regionName); else m_log.WarnFormat("[GRID HANDLER]: no name in request to get region by name"); - GridRegion rinfo = m_GridService.GetRegionByName(scopeID, regionName); - //m_log.DebugFormat("[GRID HANDLER]: neighbours for region {0}: {1}", regionID, rinfos.Count); + Dictionary result = []; + if (rinfo == null) + result["result"] = "null"; + else + result["result"] = rinfo.ToKeyValuePairs(); - Dictionary result = new Dictionary(); + string xmlString = ServerUtils.BuildXmlResponse(result); + + //m_log.DebugFormat("[GRID HANDLER]: resp string: {0}", xmlString); + return Util.UTF8NoBomEncoding.GetBytes(xmlString); + } + + byte[] GetLocalRegionByName(Dictionary request) + { + UUID scopeID = UUID.Zero; + if (!request.TryGetValue("SCOPEID", out object scpo) || scpo is not string scps || !UUID.TryParse(scps, out scopeID)) + m_log.WarnFormat("[GRID HANDLER]: no or invalid scopeID in request to get region by name"); + + GridRegion rinfo = null; + if (request.TryGetValue("NAME", out object nameo) && nameo is string regionName) + rinfo = m_GridService.GetLocalRegionByName(scopeID, regionName); + else + m_log.WarnFormat("[GRID HANDLER]: no name in request to get region by name"); + + Dictionary result = []; if (rinfo == null) result["result"] = "null"; else diff --git a/OpenSim/Services/Connectors/Grid/GridServicesConnector.cs b/OpenSim/Services/Connectors/Grid/GridServicesConnector.cs index ec0c3bf8de..f23fc2fe7e 100644 --- a/OpenSim/Services/Connectors/Grid/GridServicesConnector.cs +++ b/OpenSim/Services/Connectors/Grid/GridServicesConnector.cs @@ -28,12 +28,10 @@ using log4net; using System; using System.Collections.Generic; -using System.IO; using System.Reflection; using Nini.Config; using OpenSim.Framework; -using OpenSim.Framework.ServiceAuth; using OpenSim.Services.Interfaces; using GridRegion = OpenSim.Services.Interfaces.GridRegion; using OpenSim.Server.Base; @@ -43,11 +41,9 @@ namespace OpenSim.Services.Connectors { public class GridServicesConnector : BaseServiceConnector, IGridService { - private static readonly ILog m_log = - LogManager.GetLogger( - MethodBase.GetCurrentMethod().DeclaringType); - + private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); private string m_ServerURI = String.Empty; + private string m_ServerGridURI = string.Empty; public GridServicesConnector() { @@ -56,6 +52,7 @@ namespace OpenSim.Services.Connectors public GridServicesConnector(string serverURI) { m_ServerURI = serverURI.TrimEnd('/'); + m_ServerGridURI = serverURI + "/grid"; } public GridServicesConnector(IConfigSource source) @@ -66,21 +63,21 @@ namespace OpenSim.Services.Connectors public virtual void Initialise(IConfigSource source) { IConfig gridConfig = source.Configs["GridService"]; - if (gridConfig == null) + if (gridConfig is null) { m_log.Error("[GRID CONNECTOR]: GridService missing from OpenSim.ini"); throw new Exception("Grid connector init error"); } - string serviceURI = gridConfig.GetString("GridServerURI", - String.Empty); + string serviceURI = gridConfig.GetString("GridServerURI", string.Empty); if (serviceURI.Length == 0) { m_log.Error("[GRID CONNECTOR]: No Server URI named in section GridService"); throw new Exception("Grid connector init error"); } - m_ServerURI = serviceURI; + m_ServerURI = serviceURI.TrimEnd('/'); + m_ServerGridURI = serviceURI + "/grid"; base.Initialise(source, "GridService"); } @@ -91,91 +88,87 @@ namespace OpenSim.Services.Connectors public string RegisterRegion(UUID scopeID, GridRegion regionInfo) { Dictionary rinfo = regionInfo.ToKeyValuePairs(); - Dictionary sendData = new Dictionary(); + Dictionary sendData = new() + { + ["SCOPEID"] = scopeID.ToString(), + ["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString(), + ["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString(), + ["METHOD"] = "register" + }; foreach (KeyValuePair kvp in rinfo) sendData[kvp.Key] = (string)kvp.Value; - sendData["SCOPEID"] = scopeID.ToString(); - sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString(); - sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString(); - sendData["METHOD"] = "register"; - string reqString = ServerUtils.BuildQueryString(sendData); - string uri = m_ServerURI + "/grid"; // m_log.DebugFormat("[GRID CONNECTOR]: queryString = {0}", reqString); try { - string reply = SynchronousRestFormsRequester.MakeRequest("POST", uri, reqString, m_Auth); - if (!string.IsNullOrEmpty(reply)) + string reply = SynchronousRestFormsRequester.MakePostRequest(m_ServerGridURI, reqString, m_Auth); + if (reply.Length > 0) { Dictionary replyData = ServerUtils.ParseXmlResponse(reply); - - if (replyData.ContainsKey("Result")&& (replyData["Result"].ToString().ToLower() == "success")) + if (replyData.TryGetValue("Result", out object tmpo) && tmpo is string tmps) { - return String.Empty; - } - else if (replyData.ContainsKey("Result")&& (replyData["Result"].ToString().ToLower() == "failure")) - { - m_log.ErrorFormat( - "[GRID CONNECTOR]: Registration failed: {0} when contacting {1}", replyData["Message"], uri); - - return replyData["Message"].ToString(); - } - else if (!replyData.ContainsKey("Result")) - { - m_log.ErrorFormat( - "[GRID CONNECTOR]: reply data does not contain result field when contacting {0}", uri); + if(tmps.Equals("success", StringComparison.CurrentCultureIgnoreCase)) + return string.Empty; + if (tmps.Equals("failure", StringComparison.CurrentCultureIgnoreCase)) + { + m_log.Error( + $"[GRID CONNECTOR]: Registration failed: {replyData["Message"]} when contacting {m_ServerGridURI}"); + return replyData["Message"].ToString(); + } + else + { + m_log.Error( + $"[GRID CONNECTOR]: unexpected result {tmps} when contacting {m_ServerGridURI}"); + return "Unexpected result " + tmps; + } } else { - m_log.ErrorFormat( - "[GRID CONNECTOR]: unexpected result {0} when contacting {1}", replyData["Result"], uri); - - return "Unexpected result " + replyData["Result"].ToString(); + m_log.Error( + $"[GRID CONNECTOR]: reply data does not contain result field when contacting {m_ServerGridURI}"); } } else { - m_log.ErrorFormat( - "[GRID CONNECTOR]: RegisterRegion received null reply when contacting grid server at {0}", uri); + m_log.Error( + $"[GRID CONNECTOR]: RegisterRegion received null reply when contacting grid server at {m_ServerGridURI}"); } } catch (Exception e) { - m_log.ErrorFormat("[GRID CONNECTOR]: Exception when contacting grid server at {0}: {1}", uri, e.Message); + m_log.Error($"[GRID CONNECTOR]: Exception when contacting grid server at {m_ServerGridURI}: {e.Message}"); } - return string.Format("Error communicating with the grid service at {0}", uri); + return "Error communicating with the grid service at " + m_ServerGridURI; } public bool DeregisterRegion(UUID regionID) { - Dictionary sendData = new Dictionary(); + Dictionary sendData = new() + { + ["REGIONID"] = regionID.ToString(), - sendData["REGIONID"] = regionID.ToString(); - - sendData["METHOD"] = "deregister"; - - string uri = m_ServerURI + "/grid"; + ["METHOD"] = "deregister" + }; try { - string reply - = SynchronousRestFormsRequester.MakeRequest("POST", uri, ServerUtils.BuildQueryString(sendData), m_Auth); + string reply = SynchronousRestFormsRequester.MakePostRequest(m_ServerGridURI, ServerUtils.BuildQueryString(sendData), m_Auth); - if (reply != string.Empty) + if (reply.Length > 0) { Dictionary replyData = ServerUtils.ParseXmlResponse(reply); - - if ((replyData["Result"] != null) && (replyData["Result"].ToString().ToLower() == "success")) - return true; + return replyData.TryGetValue("Result", out object tmpo) && + tmpo is string rs && + rs.Equals("success", StringComparison.InvariantCultureIgnoreCase); } else - m_log.DebugFormat("[GRID CONNECTOR]: DeregisterRegion received null reply"); + m_log.Debug("[GRID CONNECTOR]: DeregisterRegion received empty reply"); } catch (Exception e) { - m_log.DebugFormat("[GRID CONNECTOR]: Exception when contacting grid server at {0}: {1}", uri, e.Message); + m_log.Error($"[GRID CONNECTOR]: Exception when contacting grid server at {m_ServerGridURI}: {e.Message}"); } return false; @@ -183,196 +176,191 @@ namespace OpenSim.Services.Connectors public List GetNeighbours(UUID scopeID, UUID regionID) { - Dictionary sendData = new Dictionary(); + Dictionary sendData = new() + { + ["SCOPEID"] = scopeID.ToString(), + ["REGIONID"] = regionID.ToString(), - sendData["SCOPEID"] = scopeID.ToString(); - sendData["REGIONID"] = regionID.ToString(); - - sendData["METHOD"] = "get_neighbours"; - - List rinfos = new List(); - - string reqString = ServerUtils.BuildQueryString(sendData); - string reply = string.Empty; - string uri = m_ServerURI + "/grid"; + ["METHOD"] = "get_neighbours" + }; try { - reply = SynchronousRestFormsRequester.MakeRequest("POST", uri, reqString, m_Auth); + string reply = SynchronousRestFormsRequester.MakePostRequest( + m_ServerGridURI, + ServerUtils.BuildQueryString(sendData), m_Auth); + + Dictionary replyData = ServerUtils.ParseXmlResponse(reply); + + //m_log.DebugFormat("[GRID CONNECTOR]: get neighbours returned {0} elements", replyData.Values.Count); + if (replyData.Count > 0) + { + List rinfos = []; + foreach (object r in replyData.Values) + { + if (r is Dictionary dr) + { + GridRegion rinfo = new GridRegion(dr); + rinfos.Add(rinfo); + } + } + return rinfos; + } + } catch (Exception e) { - m_log.DebugFormat("[GRID CONNECTOR]: Exception when contacting grid server at {0}: {1}", uri, e.Message); - return rinfos; + m_log.Error($"[GRID CONNECTOR]: GetNeighbours Exception when contacting grid server at {m_ServerGridURI}: {e.Message}"); + } - Dictionary replyData = ServerUtils.ParseXmlResponse(reply); - - if (replyData != null) - { - Dictionary.ValueCollection rinfosList = replyData.Values; - //m_log.DebugFormat("[GRID CONNECTOR]: get neighbours returned {0} elements", rinfosList.Count); - foreach (object r in rinfosList) - { - if (r is Dictionary) - { - GridRegion rinfo = new GridRegion((Dictionary)r); - rinfos.Add(rinfo); - } - } - } - else - m_log.DebugFormat("[GRID CONNECTOR]: GetNeighbours {0}, {1} received null response", - scopeID, regionID); - - return rinfos; + return []; } public GridRegion GetRegionByUUID(UUID scopeID, UUID regionID) { - Dictionary sendData = new Dictionary(); + Dictionary sendData = new() + { + ["SCOPEID"] = scopeID.ToString(), + ["REGIONID"] = regionID.ToString(), - sendData["SCOPEID"] = scopeID.ToString(); - sendData["REGIONID"] = regionID.ToString(); + ["METHOD"] = "get_region_by_uuid" + }; - sendData["METHOD"] = "get_region_by_uuid"; - - string reply = string.Empty; - string uri = m_ServerURI + "/grid"; try { - reply = SynchronousRestFormsRequester.MakeRequest("POST", uri, ServerUtils.BuildQueryString(sendData), m_Auth); + string reply = SynchronousRestFormsRequester.MakePostRequest(m_ServerGridURI, ServerUtils.BuildQueryString(sendData), m_Auth); + if (reply.Length > 0) + { + Dictionary replyData = ServerUtils.ParseXmlResponse(reply); + if(replyData.TryGetValue("result", out object tmpo) && tmpo is Dictionary td) + return new GridRegion(td); + //else + // m_log.Debug($"[GRID CONNECTOR]: GetRegionByUUID {scopeID}, {regionID} received empty result response"); + } + else + m_log.Debug($"[GRID CONNECTOR]: GetRegionByUUID received empty reply for {scopeID}, {regionID}"); } catch (Exception e) { - m_log.DebugFormat("[GRID CONNECTOR]: Exception when contacting grid server at {0}: {1}", uri, e.Message); - return null; + m_log.Debug($"[GRID CONNECTOR]: Exception when contacting grid server at {m_ServerGridURI}: {e.Message}"); } - GridRegion rinfo = null; - - if (reply != string.Empty) - { - Dictionary replyData = ServerUtils.ParseXmlResponse(reply); - - if ((replyData != null) && (replyData["result"] != null)) - { - if (replyData["result"] is Dictionary) - rinfo = new GridRegion((Dictionary)replyData["result"]); - //else - // m_log.DebugFormat("[GRID CONNECTOR]: GetRegionByUUID {0}, {1} received null response", - // scopeID, regionID); - } - else - m_log.DebugFormat("[GRID CONNECTOR]: GetRegionByUUID {0}, {1} received null response", - scopeID, regionID); - } - else - m_log.DebugFormat("[GRID CONNECTOR]: GetRegionByUUID received null reply"); - - return rinfo; + return null; } public GridRegion GetRegionByHandle(UUID scopeID, ulong regionhandle) { - //still not on protocol Util.RegionHandleToWorldLoc(regionhandle, out uint x, out uint y); return GetRegionByPosition(scopeID, (int)x, (int)y); } public GridRegion GetRegionByPosition(UUID scopeID, int x, int y) { - GridRegion rinfo = null; + Dictionary sendData = new() + { + ["SCOPEID"] = scopeID.ToString(), + ["X"] = x.ToString(), + ["Y"] = y.ToString(), - Dictionary sendData = new Dictionary(); + ["METHOD"] = "get_region_by_position" + }; - sendData["SCOPEID"] = scopeID.ToString(); - sendData["X"] = x.ToString(); - sendData["Y"] = y.ToString(); - - sendData["METHOD"] = "get_region_by_position"; - string reply = string.Empty; - string uri = m_ServerURI + "/grid"; try { - reply = SynchronousRestFormsRequester.MakeRequest("POST", - uri, + string reply = SynchronousRestFormsRequester.MakePostRequest( + m_ServerGridURI, ServerUtils.BuildQueryString(sendData), m_Auth); + + if (reply.Length > 0) + { + Dictionary replyData = ServerUtils.ParseXmlResponse(reply); + if(replyData.TryGetValue("result", out object tmpo) && tmpo is Dictionary td) + return new GridRegion(td); + //else + // m_log.Debug($"[GRID CONNECTOR]: GetRegionByPosition {scopeID}, {x}-{y} received empty result response"); + } + else + m_log.Debug($"[GRID CONNECTOR]: GetRegionByPosition {scopeID}, {x}-{y} received empty response"); } catch (Exception e) { - m_log.DebugFormat("[GRID CONNECTOR]: Exception when contacting grid server at {0}: {1}", uri, e.Message); - return null; + m_log.Debug($"[GRID CONNECTOR]: Exception when contacting grid server at {m_ServerGridURI}: {e.Message}"); } - if (reply != string.Empty) - { - Dictionary replyData = ServerUtils.ParseXmlResponse(reply); - - if ((replyData != null) && (replyData["result"] != null)) - { - if (replyData["result"] is Dictionary) - rinfo = new GridRegion((Dictionary)replyData["result"]); - //else - // m_log.DebugFormat("[GRID CONNECTOR]: GetRegionByPosition {0}, {1}-{2} received no region", - // scopeID, x, y); - } - else - m_log.DebugFormat("[GRID CONNECTOR]: GetRegionByPosition {0}, {1}-{2} received null response", - scopeID, x, y); - } - else - m_log.DebugFormat("[GRID CONNECTOR]: GetRegionByPosition received null reply"); - - return rinfo; + return null; } public GridRegion GetRegionByName(UUID scopeID, string regionName) { - Dictionary sendData = new Dictionary(); + Dictionary sendData = new() + { + ["SCOPEID"] = scopeID.ToString(), + ["NAME"] = regionName, - sendData["SCOPEID"] = scopeID.ToString(); - sendData["NAME"] = regionName; + ["METHOD"] = "get_region_by_name" + }; - sendData["METHOD"] = "get_region_by_name"; - string reply = string.Empty; - string uri = m_ServerURI + "/grid"; try { - reply = SynchronousRestFormsRequester.MakeRequest("POST", - uri, + string reply = SynchronousRestFormsRequester.MakePostRequest( + m_ServerGridURI, ServerUtils.BuildQueryString(sendData), m_Auth); + + if (reply.Length > 0) + { + Dictionary replyData = ServerUtils.ParseXmlResponse(reply); + if(replyData.TryGetValue("result", out object tmpo) && tmpo is Dictionary td) + return new GridRegion(td); + //else + // m_log.DebugFormat("$[GRID CONNECTOR]: GetRegionByName {scopeID}, {regionName} received empty result"); + } + else + m_log.DebugFormat("$[GRID CONNECTOR]: GetRegionByName {scopeID}, {regionName} received empty reply"); } catch (Exception e) { - m_log.DebugFormat("[GRID CONNECTOR]: Exception when contacting grid server at {0}: {1}", uri, e.Message); - return null; + m_log.DebugFormat("[GRID CONNECTOR]: GetRegionByName, Exception when contacting grid server at {0}: {1}", m_ServerGridURI, e.Message); } - GridRegion rinfo = null; - if (reply != string.Empty) - { - Dictionary replyData = ServerUtils.ParseXmlResponse(reply); - - if ((replyData != null) && (replyData["result"] != null)) - { - if (replyData["result"] is Dictionary) - rinfo = new GridRegion((Dictionary)replyData["result"]); - } - else - m_log.DebugFormat("[GRID CONNECTOR]: GetRegionByPosition {0}, {1} received null response", - scopeID, regionName); - } - else - m_log.DebugFormat("[GRID CONNECTOR]: GetRegionByName received null reply"); - - return rinfo; + return null; } public GridRegion GetLocalRegionByName(UUID scopeID, string regionName) { + Dictionary sendData = new() + { + ["SCOPEID"] = scopeID.ToString(), + ["NAME"] = regionName, + + ["METHOD"] = "get_localregion_by_name" + }; + + try + { + string reply = SynchronousRestFormsRequester.MakePostRequest( + m_ServerGridURI, + ServerUtils.BuildQueryString(sendData), m_Auth); + + if (reply.Length > 0) + { + Dictionary replyData = ServerUtils.ParseXmlResponse(reply); + if(replyData.TryGetValue("result", out object tmpo) && tmpo is Dictionary td) + return new GridRegion(td); + //else + // m_log.DebugFormat("$[GRID CONNECTOR]: GetLocalRegionByName {scopeID}, {regionName} received empty result"); + } + else + m_log.DebugFormat("$[GRID CONNECTOR]: GetLocalRegionByName {scopeID}, {regionName} received empty reply"); + } + catch (Exception e) + { + m_log.Debug($"[GRID CONNECTOR]: GetLocalRegionByName, Exception when contacting grid server at {m_ServerGridURI}: {e.Message}"); + } + return null; } + public GridRegion GetRegionByURI(UUID scopeID, RegionURI uri) { return null; @@ -385,52 +373,49 @@ namespace OpenSim.Services.Connectors public List GetRegionsByName(UUID scopeID, string name, int maxNumber) { - Dictionary sendData = new Dictionary(); + Dictionary sendData = new() + { + ["SCOPEID"] = scopeID.ToString(), + ["NAME"] = name, + ["MAX"] = maxNumber.ToString(), - sendData["SCOPEID"] = scopeID.ToString(); - sendData["NAME"] = name; - sendData["MAX"] = maxNumber.ToString(); + ["METHOD"] = "get_regions_by_name" + }; - sendData["METHOD"] = "get_regions_by_name"; - List rinfos = new List(); - string reply = string.Empty; - string uri = m_ServerURI + "/grid"; try { - reply = SynchronousRestFormsRequester.MakeRequest("POST", - uri, + string reply = SynchronousRestFormsRequester.MakePostRequest( + m_ServerGridURI, ServerUtils.BuildQueryString(sendData), m_Auth); + + if (reply.Length > 0) + { + Dictionary replyData = ServerUtils.ParseXmlResponse(reply); + if (replyData.Count > 0) + { + List rinfos = []; + foreach (object r in replyData.Values) + { + if (r is Dictionary dr) + { + GridRegion rinfo = new GridRegion(dr); + rinfos.Add(rinfo); + } + } + return rinfos; + } + else + m_log.Debug($"[GRID CONNECTOR]: GetRegionsByName {scopeID}, {name}, {maxNumber} received empty reply data"); + } + else + m_log.Debug($"[GRID CONNECTOR]: GetRegionsByName {scopeID}, {name}, {maxNumber} received empty reply"); } catch (Exception e) { - m_log.DebugFormat("[GRID CONNECTOR]: Exception when contacting grid server at {0}: {1}", uri, e.Message); - return rinfos; + m_log.Debug($"[GRID CONNECTOR]: Exception when contacting grid server at {m_ServerGridURI}: {e.Message}"); } - 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]: GetRegionsByName {0}, {1}, {2} received null response", - scopeID, name, maxNumber); - } - else - m_log.DebugFormat("[GRID CONNECTOR]: GetRegionsByName received null reply"); - - return rinfos; + return []; } public List GetRegionsByURI(UUID scopeID, RegionURI uri, int maxNumber) @@ -440,402 +425,368 @@ namespace OpenSim.Services.Connectors public List GetRegionRange(UUID scopeID, int xmin, int xmax, int ymin, int ymax) { - Dictionary sendData = new Dictionary(); + Dictionary sendData = new() + { + ["SCOPEID"] = scopeID.ToString(), + ["XMIN"] = xmin.ToString(), + ["XMAX"] = xmax.ToString(), + ["YMIN"] = ymin.ToString(), + ["YMAX"] = ymax.ToString(), - sendData["SCOPEID"] = scopeID.ToString(); - sendData["XMIN"] = xmin.ToString(); - sendData["XMAX"] = xmax.ToString(); - sendData["YMIN"] = ymin.ToString(); - sendData["YMAX"] = ymax.ToString(); - - sendData["METHOD"] = "get_region_range"; - - List rinfos = new List(); - string reply = string.Empty; - string uri = m_ServerURI + "/grid"; + ["METHOD"] = "get_region_range" + }; try { - reply = SynchronousRestFormsRequester.MakeRequest("POST", - uri, + string reply = SynchronousRestFormsRequester.MakePostRequest( + m_ServerGridURI, ServerUtils.BuildQueryString(sendData), m_Auth); - //m_log.DebugFormat("[GRID CONNECTOR]: reply was {0}", reply); + //m_log.DebugFormat("[GRID CONNECTOR]: GetRegionRange reply was {0}", reply); + if (reply.Length > 0) + { + Dictionary replyData = ServerUtils.ParseXmlResponse(reply); + if (replyData.Count > 0) + { + List rinfos = []; + foreach (object r in replyData.Values) + { + if (r is Dictionary dr) + { + GridRegion rinfo = new(dr); + rinfos.Add(rinfo); + } + } + return rinfos; + } + else + m_log.Debug($"[GRID CONNECTOR]: GetRegionRange {scopeID}, {xmin}-{xmax} {ymin}-{ymax} received null response"); + } + else + m_log.Debug("[GRID CONNECTOR]: GetRegionRange received empty reply"); + } catch (Exception e) { - m_log.DebugFormat("[GRID CONNECTOR]: Exception when contacting grid server at {0}: {1}", uri, e.Message); - return rinfos; + m_log.Debug($"[GRID CONNECTOR]: Exception when contacting grid server at {m_ServerGridURI}: {e.Message}"); } - 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]: GetRegionRange {0}, {1}-{2} {3}-{4} received null response", - scopeID, xmin, xmax, ymin, ymax); - } - else - m_log.DebugFormat("[GRID CONNECTOR]: GetRegionRange received null reply"); - - return rinfos; + return []; } public List GetDefaultRegions(UUID scopeID) { - Dictionary sendData = new Dictionary(); + Dictionary sendData = new() + { + ["SCOPEID"] = scopeID.ToString(), - sendData["SCOPEID"] = scopeID.ToString(); + ["METHOD"] = "get_default_regions" + }; - sendData["METHOD"] = "get_default_regions"; - - List rinfos = new List(); - string reply = string.Empty; - string uri = m_ServerURI + "/grid"; try { - reply = SynchronousRestFormsRequester.MakeRequest("POST", - uri, + string reply = SynchronousRestFormsRequester.MakePostRequest( + m_ServerGridURI, ServerUtils.BuildQueryString(sendData), m_Auth); //m_log.DebugFormat("[GRID CONNECTOR]: reply was {0}", reply); + if (reply.Length > 0) + { + Dictionary replyData = ServerUtils.ParseXmlResponse(reply); + + if (replyData.Count > 0) + { + List rinfos = []; + Dictionary.ValueCollection rinfosList = replyData.Values; + foreach (object r in rinfosList) + { + if (r is Dictionary) + { + GridRegion rinfo = new GridRegion((Dictionary)r); + rinfos.Add(rinfo); + } + } + return rinfos; + } + else + m_log.Debug($"[GRID CONNECTOR]: GetDefaultRegions {scopeID} received empty response"); + } + else + m_log.Debug("[GRID CONNECTOR]: GetDefaultRegions received empty reply"); + } catch (Exception e) { - m_log.DebugFormat("[GRID CONNECTOR]: Exception when contacting grid server at {0}: {1}", uri, e.Message); - return rinfos; + m_log.Debug($"[GRID CONNECTOR]: GetDefaultRegions Exception when contacting grid server at {m_ServerGridURI}: {e.Message}"); } - 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]: GetDefaultRegions {0} received null response", - scopeID); - } - else - m_log.DebugFormat("[GRID CONNECTOR]: GetDefaultRegions received null reply"); - - return rinfos; + return []; } public List GetDefaultHypergridRegions(UUID scopeID) { - Dictionary sendData = new Dictionary(); + Dictionary sendData = new() + { + ["SCOPEID"] = scopeID.ToString(), - sendData["SCOPEID"] = scopeID.ToString(); + ["METHOD"] = "get_default_hypergrid_regions" + }; - sendData["METHOD"] = "get_default_hypergrid_regions"; - - List rinfos = new List(); - string reply = string.Empty; - string uri = m_ServerURI + "/grid"; try { - reply = SynchronousRestFormsRequester.MakeRequest("POST", - uri, + string reply = SynchronousRestFormsRequester.MakePostRequest( + m_ServerGridURI, ServerUtils.BuildQueryString(sendData), m_Auth); //m_log.DebugFormat("[GRID CONNECTOR]: reply was {0}", reply); + if (reply.Length > 0) + { + Dictionary replyData = ServerUtils.ParseXmlResponse(reply); + + if (replyData.Count > 0) + { + List rinfos = []; + foreach (object r in replyData.Values) + { + if (r is Dictionary dr) + { + GridRegion rinfo = new(dr); + rinfos.Add(rinfo); + } + } + return rinfos; + } + else + m_log.Debug($"[GRID CONNECTOR]: GetDefaultHypergridRegions {scopeID} received empty response"); + } + else + m_log.Debug("[GRID CONNECTOR]: GetDefaultHypergridRegions received empty reply"); + } catch (Exception e) { - m_log.DebugFormat("[GRID CONNECTOR]: Exception when contacting grid server at {0}: {1}", uri, e.Message); - return rinfos; + m_log.Debug($"[GRID CONNECTOR]: Exception when contacting grid server at {m_ServerGridURI}: {e.Message}"); } - 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]: GetDefaultHypergridRegions {0} received null response", - scopeID); - } - else - m_log.DebugFormat("[GRID CONNECTOR]: GetDefaultHypergridRegions received null reply"); - - return rinfos; + return []; } public List GetFallbackRegions(UUID scopeID, int x, int y) { - Dictionary sendData = new Dictionary(); + Dictionary sendData = new() + { + ["SCOPEID"] = scopeID.ToString(), + ["X"] = x.ToString(), + ["Y"] = y.ToString(), - sendData["SCOPEID"] = scopeID.ToString(); - sendData["X"] = x.ToString(); - sendData["Y"] = y.ToString(); + ["METHOD"] = "get_fallback_regions" + }; - sendData["METHOD"] = "get_fallback_regions"; - - List rinfos = new List(); - string reply = string.Empty; - string uri = m_ServerURI + "/grid"; try { - reply = SynchronousRestFormsRequester.MakeRequest("POST", - uri, + string reply = SynchronousRestFormsRequester.MakePostRequest( + m_ServerGridURI, ServerUtils.BuildQueryString(sendData), m_Auth); //m_log.DebugFormat("[GRID CONNECTOR]: reply was {0}", reply); + if (reply.Length > 0) + { + Dictionary replyData = ServerUtils.ParseXmlResponse(reply); + + if (replyData.Count > 0) + { + List rinfos = []; + foreach (object r in replyData.Values) + { + if (r is Dictionary dr) + { + GridRegion rinfo = new(dr); + rinfos.Add(rinfo); + } + } + return rinfos; + } + else + m_log.Debug($"[GRID CONNECTOR]: GetFallbackRegions {scopeID}, {x}-{y} received empty response"); + } + else + m_log.Debug("[GRID CONNECTOR]: GetFallbackRegions received empty reply"); } catch (Exception e) { - m_log.DebugFormat("[GRID CONNECTOR]: Exception when contacting grid server at {0}: {1}", uri, e.Message); - return rinfos; + m_log.Debug($"[GRID CONNECTOR]: Exception when contacting grid server at {m_ServerGridURI}: {e.Message}"); } - 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]: GetFallbackRegions {0}, {1}-{2} received null response", - scopeID, x, y); - } - else - m_log.DebugFormat("[GRID CONNECTOR]: GetFallbackRegions received null reply"); - - return rinfos; + return []; } public List GetOnlineRegions(UUID scopeID, int x, int y, int maxCount) { - Dictionary sendData = new Dictionary(); + Dictionary sendData = new() + { + ["SCOPEID"] = scopeID.ToString(), + ["X"] = x.ToString(), + ["Y"] = y.ToString(), + ["MC"] = maxCount.ToString(), - sendData["SCOPEID"] = scopeID.ToString(); - sendData["X"] = x.ToString(); - sendData["Y"] = y.ToString(); - sendData["MC"] = maxCount.ToString(); + ["METHOD"] = "get_online_regions" + }; - 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); + string reply = SynchronousRestFormsRequester.MakePostRequest(m_ServerGridURI, ServerUtils.BuildQueryString(sendData), m_Auth); //m_log.DebugFormat("[GRID CONNECTOR]: reply was {0}", reply); + if (reply.Length > 0) + { + Dictionary replyData = ServerUtils.ParseXmlResponse(reply); + + if (replyData.Count > 0) + { + List rinfos = []; + foreach (object r in replyData.Values) + { + if (r is Dictionary dr) + { + GridRegion rinfo = new(dr); + rinfos.Add(rinfo); + } + } + return rinfos; + } + else + m_log.Debug($"[GRID CONNECTOR]: GetOnlineRegions {scopeID}, {x}-{y} received empty response"); + } + else + m_log.Debug("[GRID CONNECTOR]: GetOnlineRegions received empty reply"); } catch (Exception e) { - m_log.DebugFormat("[GRID CONNECTOR]: Exception when contacting grid server at {0}: {1}", m_ServerURI + "/grid", e.Message); - return rinfos; + m_log.Debug($"[GRID CONNECTOR]: Exception when contacting grid server at {m_ServerGridURI}: {e.Message}"); } - 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; + return []; } public List GetHyperlinks(UUID scopeID) { - Dictionary sendData = new Dictionary(); + Dictionary sendData = new() + { + ["SCOPEID"] = scopeID.ToString(), - sendData["SCOPEID"] = scopeID.ToString(); + ["METHOD"] = "get_hyperlinks" + }; - sendData["METHOD"] = "get_hyperlinks"; - - List rinfos = new List(); - string reply = string.Empty; - string uri = m_ServerURI + "/grid"; try { - reply = SynchronousRestFormsRequester.MakeRequest("POST", - uri, + string reply = SynchronousRestFormsRequester.MakePostRequest( + m_ServerGridURI, ServerUtils.BuildQueryString(sendData), m_Auth); //m_log.DebugFormat("[GRID CONNECTOR]: reply was {0}", reply); + if (reply.Length > 0) + { + Dictionary replyData = ServerUtils.ParseXmlResponse(reply); + + if (replyData.Count > 0) + { + List rinfos = []; + foreach (object r in replyData.Values) + { + if (r is Dictionary dr) + { + GridRegion rinfo = new(dr); + rinfos.Add(rinfo); + } + } + return rinfos; + } + else + m_log.Debug($"[GRID CONNECTOR]: GetHyperlinks {scopeID} received empty response"); + } + else + m_log.Debug("[GRID CONNECTOR]: GetHyperlinks received empty reply"); } catch (Exception e) { - m_log.DebugFormat("[GRID CONNECTOR]: Exception when contacting grid server at {0}: {1}", uri, e.Message); - return rinfos; + m_log.Debug($"[GRID CONNECTOR]: Exception when contacting grid server at {m_ServerGridURI}: {e.Message}"); } - 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]: GetHyperlinks {0} received null response", - scopeID); - } - else - m_log.DebugFormat("[GRID CONNECTOR]: GetHyperlinks received null reply"); - - return rinfos; + return []; } public int GetRegionFlags(UUID scopeID, UUID regionID) { - Dictionary sendData = new Dictionary(); + Dictionary sendData = new() + { + ["SCOPEID"] = scopeID.ToString(), + ["REGIONID"] = regionID.ToString(), - sendData["SCOPEID"] = scopeID.ToString(); - sendData["REGIONID"] = regionID.ToString(); + ["METHOD"] = "get_region_flags" + }; - sendData["METHOD"] = "get_region_flags"; - - string reply = string.Empty; - string uri = m_ServerURI + "/grid"; try { - reply = SynchronousRestFormsRequester.MakeRequest("POST", - uri, + string reply = SynchronousRestFormsRequester.MakePostRequest( + m_ServerGridURI, ServerUtils.BuildQueryString(sendData), m_Auth); + + if (reply.Length > 0) + { + Dictionary replyData = ServerUtils.ParseXmlResponse(reply); + if (replyData.TryGetValue("result", out object tmpo) && + tmpo is string tmps && + Int32.TryParse(tmps, out int flags)) + return flags; + else + m_log.Debug($"[GRID CONNECTOR]: GetRegionFlags {scopeID}, {regionID} received invalid response"); + } + else + m_log.Debug("[GRID CONNECTOR]: GetRegionFlags received empty reply"); + } catch (Exception e) { - m_log.DebugFormat("[GRID CONNECTOR]: Exception when contacting grid server at {0}: {1}", uri, e.Message); - return -1; + m_log.Debug($"[GRID CONNECTOR]: Exception when contacting grid server at {m_ServerGridURI}: {e.Message}"); } - int flags = -1; - - if (reply != string.Empty) - { - Dictionary replyData = ServerUtils.ParseXmlResponse(reply); - - if ((replyData != null) && replyData.ContainsKey("result") && (replyData["result"] != null)) - { - Int32.TryParse((string)replyData["result"], out flags); - //else - // m_log.DebugFormat("[GRID CONNECTOR]: GetRegionFlags {0}, {1} received wrong type {2}", - // scopeID, regionID, replyData["result"].GetType()); - } - else - m_log.DebugFormat("[GRID CONNECTOR]: GetRegionFlags {0}, {1} received null response", - scopeID, regionID); - } - else - m_log.DebugFormat("[GRID CONNECTOR]: GetRegionFlags received null reply"); - - return flags; + return -1; } public Dictionary GetExtraFeatures() { - Dictionary sendData = new Dictionary(); - Dictionary extraFeatures = new Dictionary(); - - sendData["METHOD"] = "get_grid_extra_features"; - - string reply = string.Empty; - string uri = m_ServerURI + "/grid"; + Dictionary sendData = new() + { + ["METHOD"] = "get_grid_extra_features" + }; try { - reply = SynchronousRestFormsRequester.MakeRequest("POST", - uri, + string reply = SynchronousRestFormsRequester.MakePostRequest( + m_ServerGridURI, ServerUtils.BuildQueryString(sendData), m_Auth); + if (reply.Length > 0) + { + Dictionary replyData = ServerUtils.ParseXmlResponse(reply); + if (replyData.Count > 0) + { + Dictionary extraFeatures = []; + foreach (string key in replyData.Keys) + { + extraFeatures[key] = replyData[key].ToString(); + } + return extraFeatures; + } + } + else + m_log.Debug("[GRID CONNECTOR]: GetExtraServiceURLs received empty reply"); } catch (Exception e) { - m_log.DebugFormat("[GRID CONNECTOR]: GetExtraFeatures - Exception when contacting grid server at {0}: {1}", uri, e.Message); - return extraFeatures; + m_log.Debug($"[GRID CONNECTOR]: GetExtraFeatures - Exception when contacting grid server at {m_ServerGridURI}: {e.Message}"); } - if (reply != string.Empty) - { - Dictionary replyData = ServerUtils.ParseXmlResponse(reply); - - if ((replyData != null) && replyData.Count > 0) - { - foreach (string key in replyData.Keys) - { - extraFeatures[key] = replyData[key].ToString(); - } - } - } - else - m_log.DebugFormat("[GRID CONNECTOR]: GetExtraServiceURLs received null reply"); - - return extraFeatures; + return []; } #endregion diff --git a/OpenSim/Services/GridService/GridService.cs b/OpenSim/Services/GridService/GridService.cs index 194858bd3e..085b82c576 100755 --- a/OpenSim/Services/GridService/GridService.cs +++ b/OpenSim/Services/GridService/GridService.cs @@ -44,9 +44,7 @@ namespace OpenSim.Services.GridService { public class GridService : GridServiceBase, IGridService { - private static readonly ILog m_log = - LogManager.GetLogger( - MethodBase.GetCurrentMethod().DeclaringType); + private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); private string LogHeader = "[GRID SERVICE]"; private bool m_DeleteOnUnregister = true; @@ -599,7 +597,7 @@ namespace OpenSim.Services.GridService if (!uri.ResolveDNS()) return null; if(!m_HypergridLinker.IsLocalGrid(uri.HostUrl)) - return null; + return null; } if (uri.HasRegionName)