From 7e47ab746ef588648b8edbbc7cfb48c4d90c5e34 Mon Sep 17 00:00:00 2001 From: Marck Date: Fri, 6 Aug 2010 07:46:19 +0200 Subject: [PATCH] Allow creation of link regions if there is an existing region within a 4096 range. Also add GetHyperlinks() to the grid service. --- .../Grid/LocalGridServiceConnector.cs | 5 ++ .../Grid/Tests/GridConnectorsTests.cs | 5 ++ .../Handlers/Grid/GridServerPostHandler.cs | 33 ++++++++++++ .../Connectors/Grid/GridServiceConnector.cs | 50 +++++++++++++++++++ .../SimianGrid/SimianGridServiceConnector.cs | 6 +++ OpenSim/Services/GridService/GridService.cs | 16 ++++++ .../Services/GridService/HypergridLinker.cs | 34 +++++++++++-- OpenSim/Services/Interfaces/IGridService.cs | 1 + 8 files changed, 146 insertions(+), 4 deletions(-) diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/LocalGridServiceConnector.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/LocalGridServiceConnector.cs index b2e3f4f7f5..9ea04d4eff 100644 --- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/LocalGridServiceConnector.cs +++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/LocalGridServiceConnector.cs @@ -233,6 +233,11 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid return m_GridService.GetFallbackRegions(scopeID, x, y); } + public List GetHyperlinks(UUID scopeID) + { + return m_GridService.GetHyperlinks(scopeID); + } + public int GetRegionFlags(UUID scopeID, UUID regionID) { return m_GridService.GetRegionFlags(scopeID, regionID); diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/Tests/GridConnectorsTests.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/Tests/GridConnectorsTests.cs index 95d8737122..1366980c03 100644 --- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/Tests/GridConnectorsTests.cs +++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/Tests/GridConnectorsTests.cs @@ -136,6 +136,11 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid.Tests 900 * (int)Constants.RegionSize, 1100 * (int)Constants.RegionSize); Assert.IsNotNull(results, "Retrieved GetRegionRange list is null"); Assert.That(results.Count, Is.EqualTo(2), "Retrieved neighbour collection is not the number expected"); + + results = m_LocalConnector.GetHyperlinks(UUID.Zero); + Assert.IsNotNull(results, "Retrieved GetHyperlinks list is null"); + Assert.That(results.Count, Is.EqualTo(0), "Retrieved linked regions collection is not the number expected"); + } } } diff --git a/OpenSim/Server/Handlers/Grid/GridServerPostHandler.cs b/OpenSim/Server/Handlers/Grid/GridServerPostHandler.cs index c90dd6f771..913c6c9b3a 100644 --- a/OpenSim/Server/Handlers/Grid/GridServerPostHandler.cs +++ b/OpenSim/Server/Handlers/Grid/GridServerPostHandler.cs @@ -109,6 +109,9 @@ namespace OpenSim.Server.Handlers.Grid case "get_fallback_regions": return GetFallbackRegions(request); + case "get_hyperlinks": + return GetHyperlinks(request); + case "get_region_flags": return GetRegionFlags(request); } @@ -483,6 +486,36 @@ namespace OpenSim.Server.Handlers.Grid return encoding.GetBytes(xmlString); } + byte[] GetHyperlinks(Dictionary request) + { + //m_log.DebugFormat("[GRID HANDLER]: GetHyperlinks"); + 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 linked regions"); + + List rinfos = m_GridService.GetHyperlinks(scopeID); + + 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); + UTF8Encoding encoding = new UTF8Encoding(); + return encoding.GetBytes(xmlString); + } + byte[] GetRegionFlags(Dictionary request) { UUID scopeID = UUID.Zero; diff --git a/OpenSim/Services/Connectors/Grid/GridServiceConnector.cs b/OpenSim/Services/Connectors/Grid/GridServiceConnector.cs index 18315337ac..202bad779c 100644 --- a/OpenSim/Services/Connectors/Grid/GridServiceConnector.cs +++ b/OpenSim/Services/Connectors/Grid/GridServiceConnector.cs @@ -556,6 +556,56 @@ namespace OpenSim.Services.Connectors return rinfos; } + public List GetHyperlinks(UUID scopeID) + { + Dictionary sendData = new Dictionary(); + + sendData["SCOPEID"] = scopeID.ToString(); + + sendData["METHOD"] = "get_hyperlinks"; + + List rinfos = new List(); + string reply = string.Empty; + try + { + reply = SynchronousRestFormsRequester.MakeRequest("POST", + m_ServerURI + "/grid", + ServerUtils.BuildQueryString(sendData)); + + //m_log.DebugFormat("[GRID CONNECTOR]: reply was {0}", reply); + } + catch (Exception e) + { + m_log.DebugFormat("[GRID CONNECTOR]: Exception when contacting grid server: {0}", 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]: GetHyperlinks {0} received null response", + scopeID); + } + else + m_log.DebugFormat("[GRID CONNECTOR]: GetHyperlinks received null reply"); + + return rinfos; + } + public virtual int GetRegionFlags(UUID scopeID, UUID regionID) { Dictionary sendData = new Dictionary(); diff --git a/OpenSim/Services/Connectors/SimianGrid/SimianGridServiceConnector.cs b/OpenSim/Services/Connectors/SimianGrid/SimianGridServiceConnector.cs index bea81726f4..7bc85c65cd 100644 --- a/OpenSim/Services/Connectors/SimianGrid/SimianGridServiceConnector.cs +++ b/OpenSim/Services/Connectors/SimianGrid/SimianGridServiceConnector.cs @@ -357,6 +357,12 @@ namespace OpenSim.Services.Connectors.SimianGrid return new List(0); } + public List GetHyperlinks(UUID scopeID) + { + // Hypergrid/linked regions are not supported + return new List(); + } + public int GetRegionFlags(UUID scopeID, UUID regionID) { const int REGION_ONLINE = 4; diff --git a/OpenSim/Services/GridService/GridService.cs b/OpenSim/Services/GridService/GridService.cs index ebaed42dc5..79a45fe238 100644 --- a/OpenSim/Services/GridService/GridService.cs +++ b/OpenSim/Services/GridService/GridService.cs @@ -426,6 +426,22 @@ namespace OpenSim.Services.GridService return ret; } + public List GetHyperlinks(UUID scopeID) + { + List ret = new List(); + + List regions = m_Database.GetHyperlinks(scopeID); + + foreach (RegionData r in regions) + { + if ((Convert.ToInt32(r.Data["flags"]) & (int)OpenSim.Data.RegionFlags.RegionOnline) != 0) + ret.Add(RegionData2RegionInfo(r)); + } + + m_log.DebugFormat("[GRID SERVICE]: Hyperlinks returned {0} regions", ret.Count); + return ret; + } + public int GetRegionFlags(UUID scopeID, UUID regionID) { RegionData region = m_Database.Get(regionID, scopeID); diff --git a/OpenSim/Services/GridService/HypergridLinker.cs b/OpenSim/Services/GridService/HypergridLinker.cs index 1f530071bb..017df415b8 100644 --- a/OpenSim/Services/GridService/HypergridLinker.cs +++ b/OpenSim/Services/GridService/HypergridLinker.cs @@ -27,6 +27,7 @@ using System; using System.Collections.Generic; +using System.Linq; using System.Net; using System.Reflection; using System.Xml; @@ -332,18 +333,43 @@ namespace OpenSim.Services.GridService /// public bool Check4096(ulong realHandle, out uint x, out uint y) { - GridRegion defRegion = DefaultRegion; - uint ux = 0, uy = 0; Utils.LongToUInts(realHandle, out ux, out uy); x = ux / Constants.RegionSize; y = uy / Constants.RegionSize; - if ((Math.Abs((int)defRegion.RegionLocX - ux) >= 4096 * Constants.RegionSize) || - (Math.Abs((int)defRegion.RegionLocY - uy) >= 4096 * Constants.RegionSize)) + const uint limit = (4096 - 1) * Constants.RegionSize; + uint xmin = ux - limit; + uint xmax = ux + limit; + uint ymin = uy - limit; + uint ymax = uy + limit; + // World map boundary checks + if (xmin < 0 || xmin > ux) + xmin = 0; + if (xmax > int.MaxValue || xmax < ux) + xmax = int.MaxValue; + if (ymin < 0 || ymin > uy) + ymin = 0; + if (ymax > int.MaxValue || ymax < uy) + ymax = int.MaxValue; + + // Check for any regions that are within the possible teleport range to the linked region + List regions = m_GridService.GetRegionRange(m_ScopeID, (int)xmin, (int)xmax, (int)ymin, (int)ymax); + if (regions.Count == 0) { return false; } + else + { + // Check for regions which are not linked regions + List hyperlinks = m_GridService.GetHyperlinks(m_ScopeID); + IEnumerable availableRegions = regions.Except(hyperlinks); + if (availableRegions.Count() == 0) + { + return false; + } + } + return true; } diff --git a/OpenSim/Services/Interfaces/IGridService.cs b/OpenSim/Services/Interfaces/IGridService.cs index e55b633eba..77230a33d7 100644 --- a/OpenSim/Services/Interfaces/IGridService.cs +++ b/OpenSim/Services/Interfaces/IGridService.cs @@ -92,6 +92,7 @@ namespace OpenSim.Services.Interfaces List GetDefaultRegions(UUID scopeID); List GetFallbackRegions(UUID scopeID, int x, int y); + List GetHyperlinks(UUID scopeID); int GetRegionFlags(UUID scopeID, UUID regionID); }