From 7b0d6439995cd6c192c2bc0de80a5b4dcc9bb5b0 Mon Sep 17 00:00:00 2001 From: Marck Date: Wed, 27 Oct 2010 19:03:56 +0200 Subject: HypergridLinker optimizations and enable use of owner_uuid/EstateOwner with linked regions. * Added check for already occupied region coordinates. * Optimized Check4096. --- OpenSim/Services/GridService/HypergridLinker.cs | 47 ++++++++++++++----------- 1 file changed, 27 insertions(+), 20 deletions(-) (limited to 'OpenSim/Services') diff --git a/OpenSim/Services/GridService/HypergridLinker.cs b/OpenSim/Services/GridService/HypergridLinker.cs index b86fb6f..a67404f 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; @@ -154,6 +155,11 @@ namespace OpenSim.Services.GridService // From the command line link-region public GridRegion TryLinkRegionToCoords(UUID scopeID, string mapName, int xloc, int yloc, out string reason) { + return TryLinkRegionToCoords(scopeID, mapName, xloc, yloc, UUID.Zero, out reason); + } + + public GridRegion TryLinkRegionToCoords(UUID scopeID, string mapName, int xloc, int yloc, UUID ownerID, out string reason) + { reason = string.Empty; string host = "127.0.0.1"; string portstr; @@ -189,7 +195,7 @@ namespace OpenSim.Services.GridService //} GridRegion regInfo; - bool success = TryCreateLink(scopeID, xloc, yloc, regionName, port, host, out regInfo, out reason); + bool success = TryCreateLink(scopeID, xloc, yloc, regionName, port, host, ownerID, out regInfo, out reason); if (success) { regInfo.RegionName = mapName; @@ -202,7 +208,8 @@ namespace OpenSim.Services.GridService // From the command line and the 2 above public bool TryCreateLink(UUID scopeID, int xloc, int yloc, - string externalRegionName, uint externalPort, string externalHostName, out GridRegion regInfo, out string reason) + string externalRegionName, uint externalPort, string externalHostName, UUID ownerID, + out GridRegion regInfo, out string reason) { m_log.DebugFormat("[HYPERGRID LINKER]: Link to {0}:{1}:{2}, in {3}-{4}", externalHostName, externalPort, externalRegionName, xloc, yloc); @@ -214,12 +221,22 @@ namespace OpenSim.Services.GridService regInfo.RegionLocX = xloc; regInfo.RegionLocY = yloc; regInfo.ScopeID = scopeID; + regInfo.EstateOwner = ownerID; // Big HACK for Simian Grid !!! // We need to clean up all URLs used in OpenSim !!! if (externalHostName.Contains("/")) regInfo.ServerURI = externalHostName; + // Check for free coordinates + GridRegion region = m_GridService.GetRegionByPosition(regInfo.ScopeID, regInfo.RegionLocX, regInfo.RegionLocY); + if (region != null) + { + m_log.WarnFormat("[HYPERGRID LINKER]: Coordinates {0}-{1} are already occupied by region {2} with uuid {3}", regInfo.RegionLocX, regInfo.RegionLocY, region.RegionName, region.RegionID); + reason = "Coordinates are already in use"; + return false; + } + try { regInfo.InternalEndPoint = new IPEndPoint(IPAddress.Parse("0.0.0.0"), (int)0); @@ -241,11 +258,11 @@ namespace OpenSim.Services.GridService if (regionID != UUID.Zero) { - GridRegion r = m_GridService.GetRegionByUUID(scopeID, regionID); - if (r != null) + region = m_GridService.GetRegionByUUID(scopeID, regionID); + if (region != null) { - m_log.DebugFormat("[HYPERGRID LINKER]: Region already exists in coordinates {0} {1}", r.RegionLocX / Constants.RegionSize, r.RegionLocY / Constants.RegionSize); - regInfo = r; + m_log.DebugFormat("[HYPERGRID LINKER]: Region already exists in coordinates {0} {1}", region.RegionLocX / Constants.RegionSize, region.RegionLocY / Constants.RegionSize); + regInfo = region; return true; } @@ -355,17 +372,8 @@ namespace OpenSim.Services.GridService { // Check for regions which are not linked regions List hyperlinks = m_GridService.GetHyperlinks(m_ScopeID); - // would like to use .Except, but doesn't seem to exist - //IEnumerable availableRegions = regions.Except(hyperlinks); - List availableRegions = regions.FindAll(delegate(GridRegion region) - { - // Ewww! n^2 - if (hyperlinks.Find(delegate(GridRegion r) { return r.RegionID == region.RegionID; }) == null) // not hyperlink. good. - return true; - - return false; - }); - if (availableRegions.Count == 0) + IEnumerable availableRegions = regions.Except(hyperlinks); + if (availableRegions.Count() == 0) return false; } @@ -529,7 +537,7 @@ namespace OpenSim.Services.GridService xloc = xloc * (int)Constants.RegionSize; yloc = yloc * (int)Constants.RegionSize; string reason = string.Empty; - if (TryCreateLink(UUID.Zero, xloc, yloc, "", externalPort, externalHostName, out regInfo, out reason)) + if (TryCreateLink(UUID.Zero, xloc, yloc, "", externalPort, externalHostName, UUID.Zero, out regInfo, out reason)) { if (cmdparams.Length >= 5) { @@ -631,8 +639,7 @@ namespace OpenSim.Services.GridService xloc = xloc * (int)Constants.RegionSize; yloc = yloc * (int)Constants.RegionSize; string reason = string.Empty; - if (TryCreateLink(UUID.Zero, xloc, yloc, "", externalPort, - externalHostName, out regInfo, out reason)) + if (TryCreateLink(UUID.Zero, xloc, yloc, "", externalPort, externalHostName, UUID.Zero, out regInfo, out reason)) { regInfo.RegionName = config.GetString("localName", ""); } -- cgit v1.1