From 5e4d6cab00cb29cd088ab7b62ab13aff103b64cb Mon Sep 17 00:00:00 2001 From: onefang Date: Sun, 19 May 2019 21:24:15 +1000 Subject: Dump OpenSim 0.9.0.1 into it's own branch. --- OpenSim/Services/GridService/GridService.cs | 294 ++++++++++++++-------------- 1 file changed, 148 insertions(+), 146 deletions(-) (limited to 'OpenSim/Services/GridService/GridService.cs') diff --git a/OpenSim/Services/GridService/GridService.cs b/OpenSim/Services/GridService/GridService.cs index 0c502a2..a5c7d34 100644 --- a/OpenSim/Services/GridService/GridService.cs +++ b/OpenSim/Services/GridService/GridService.cs @@ -57,8 +57,6 @@ namespace OpenSim.Services.GridService protected bool m_AllowDuplicateNames = false; protected bool m_AllowHypergridMapSearch = false; - protected bool m_SuppressVarregionOverlapCheckOnRegistration = false; - private static Dictionary m_ExtraFeatures = new Dictionary(); public GridService(IConfigSource config) @@ -74,7 +72,7 @@ namespace OpenSim.Services.GridService if (gridConfig != null) { m_DeleteOnUnregister = gridConfig.GetBoolean("DeleteOnUnregister", true); - + string authService = gridConfig.GetString("AuthenticationService", String.Empty); if (authService != String.Empty) @@ -85,8 +83,6 @@ namespace OpenSim.Services.GridService m_AllowDuplicateNames = gridConfig.GetBoolean("AllowDuplicateNames", m_AllowDuplicateNames); m_AllowHypergridMapSearch = gridConfig.GetBoolean("AllowHypergridMapSearch", m_AllowHypergridMapSearch); - m_SuppressVarregionOverlapCheckOnRegistration = gridConfig.GetBoolean("SuppressVarregionOverlapCheckOnRegistration", m_SuppressVarregionOverlapCheckOnRegistration); - // This service is also used locally by a simulator running in grid mode. This switches prevents // inappropriate console commands from being registered suppressConsoleCommands = gridConfig.GetBoolean("SuppressConsoleCommands", suppressConsoleCommands); @@ -155,9 +151,9 @@ namespace OpenSim.Services.GridService if (loginConfig == null || gridConfig == null) return; - + string configVal; - + configVal = loginConfig.GetString("SearchURL", string.Empty); if (!string.IsNullOrEmpty(configVal)) m_ExtraFeatures["search-server-url"] = configVal; @@ -201,15 +197,28 @@ namespace OpenSim.Services.GridService if (regionInfos.RegionID == UUID.Zero) return "Invalid RegionID - cannot be zero UUID"; + if (regionInfos.RegionLocY <= Constants.MaximumRegionSize) + return "Region location reserved for HG links coord Y must be higher than " + (Constants.MaximumRegionSize/256).ToString(); + String reason = "Region overlaps another region"; - RegionData region = FindAnyConflictingRegion(regionInfos, scopeID, out reason); - // If there is a conflicting region, if it has the same ID and same coordinates - // then it is a region re-registering (permissions and ownership checked later). - if ((region != null) - && ( (region.coordX != regionInfos.RegionCoordX) - || (region.coordY != regionInfos.RegionCoordY) - || (region.RegionID != regionInfos.RegionID) ) - ) + + List rdatas = m_Database.Get( + regionInfos.RegionLocX, + regionInfos.RegionLocY, + regionInfos.RegionLocX + regionInfos.RegionSizeX - 1, + regionInfos.RegionLocY + regionInfos.RegionSizeY - 1 , + scopeID); + + RegionData region = null; + if(rdatas.Count > 1) + { + m_log.WarnFormat("{0} Register region overlaps with {1} regions", LogHeader, scopeID, rdatas.Count); + return reason; + } + else if(rdatas.Count == 1) + region = rdatas[0]; + + if ((region != null) && (region.RegionID != regionInfos.RegionID)) { // If not same ID and same coordinates, this new region has conflicts and can't be registered. m_log.WarnFormat("{0} Register region conflict in scope {1}. {2}", LogHeader, scopeID, reason); @@ -263,7 +272,7 @@ namespace OpenSim.Services.GridService { if (d.RegionID != regionInfos.RegionID) { - m_log.WarnFormat("[GRID SERVICE]: Region tried to register using a duplicate name. New region: {0} ({1}), existing region: {2} ({3}).", + m_log.WarnFormat("[GRID SERVICE]: Region tried to register using a duplicate name. New region: {0} ({1}), existing region: {2} ({3}).", regionInfos.RegionName, regionInfos.RegionID, d.RegionName, d.RegionID); return "Duplicate region name"; } @@ -273,7 +282,7 @@ namespace OpenSim.Services.GridService // If there is an old record for us, delete it if it is elsewhere. region = m_Database.Get(regionInfos.RegionID, scopeID); - if ((region != null) && (region.RegionID == regionInfos.RegionID) && + if ((region != null) && (region.RegionID == regionInfos.RegionID) && ((region.posX != regionInfos.RegionLocX) || (region.posY != regionInfos.RegionLocY))) { if ((Convert.ToInt32(region.Data["flags"]) & (int)OpenSim.Framework.RegionFlags.NoMove) != 0) @@ -284,7 +293,7 @@ namespace OpenSim.Services.GridService // Region reregistering in other coordinates. Delete the old entry m_log.DebugFormat("[GRID SERVICE]: Region {0} ({1}) was previously registered at {2}-{3}. Deleting old entry.", - regionInfos.RegionName, regionInfos.RegionID, regionInfos.RegionLocX, regionInfos.RegionLocY); + regionInfos.RegionName, regionInfos.RegionID, regionInfos.RegionCoordX, regionInfos.RegionCoordY); try { @@ -299,7 +308,7 @@ namespace OpenSim.Services.GridService // Everything is ok, let's register RegionData rdata = RegionInfo2RegionData(regionInfos); rdata.ScopeID = scopeID; - + if (region != null) { int oldFlags = Convert.ToInt32(region.Data["flags"]); @@ -336,107 +345,15 @@ namespace OpenSim.Services.GridService m_log.DebugFormat("[GRID SERVICE]: Database exception: {0}", e); } - m_log.InfoFormat - ("[GRID SERVICE]: Region {0} ({1}, {2}x{3}) registered at {4},{5} with flags {6}", - regionInfos.RegionName, regionInfos.RegionID, regionInfos.RegionSizeX, regionInfos.RegionSizeY, - regionInfos.RegionCoordX, regionInfos.RegionCoordY, + m_log.DebugFormat + ("[GRID SERVICE]: Region {0} ({1}, {2}x{3}) registered at {4},{5} with flags {6}", + regionInfos.RegionName, regionInfos.RegionID, regionInfos.RegionSizeX, regionInfos.RegionSizeY, + regionInfos.RegionCoordX, regionInfos.RegionCoordY, (OpenSim.Framework.RegionFlags)flags); return String.Empty; } - /// - /// Search the region map for regions conflicting with this region. - /// The region to be added is passed and we look for any existing regions that are - /// in the requested location, that are large varregions that overlap this region, or - /// are previously defined regions that would lie under this new region. - /// - /// Information on region requested to be added to the world map - /// Grid id for region - /// The reason the returned region conflicts with passed region - /// - private RegionData FindAnyConflictingRegion(GridRegion regionInfos, UUID scopeID, out string reason) - { - reason = "Reregistration"; - // First see if there is an existing region right where this region is trying to go - // (We keep this result so it can be returned if suppressing errors) - RegionData noErrorRegion = m_Database.Get(regionInfos.RegionLocX, regionInfos.RegionLocY, scopeID); - RegionData region = noErrorRegion; - if (region != null - && region.RegionID == regionInfos.RegionID - && region.sizeX == regionInfos.RegionSizeX - && region.sizeY == regionInfos.RegionSizeY) - { - // If this seems to be exactly the same region, return this as it could be - // a re-registration (permissions checked by calling routine). - m_log.DebugFormat("{0} FindAnyConflictingRegion: re-register of {1}", - LogHeader, RegionString(regionInfos)); - return region; - } - - // No region exactly there or we're resizing an existing region. - // Fetch regions that could be varregions overlapping requested location. - int xmin = regionInfos.RegionLocX - (int)Constants.MaximumRegionSize + 10; - int xmax = regionInfos.RegionLocX; - int ymin = regionInfos.RegionLocY - (int)Constants.MaximumRegionSize + 10; - int ymax = regionInfos.RegionLocY; - List rdatas = m_Database.Get(xmin, ymin, xmax, ymax, scopeID); - foreach (RegionData rdata in rdatas) - { - // m_log.DebugFormat("{0} FindAnyConflictingRegion: find existing. Checking {1}", LogHeader, RegionString(rdata) ); - if ( (rdata.posX + rdata.sizeX > regionInfos.RegionLocX) - && (rdata.posY + rdata.sizeY > regionInfos.RegionLocY) ) - { - region = rdata; - m_log.WarnFormat("{0} FindAnyConflictingRegion: conflict of {1} by existing varregion {2}", - LogHeader, RegionString(regionInfos), RegionString(region)); - reason = String.Format("Region location is overlapped by existing varregion {0}", - RegionString(region)); - - if (m_SuppressVarregionOverlapCheckOnRegistration) - region = noErrorRegion; - return region; - } - } - - // There isn't a region that overlaps this potential region. - // See if this potential region overlaps an existing region. - // First, a shortcut of not looking for overlap if new region is legacy region sized - // and connot overlap anything. - if (regionInfos.RegionSizeX != Constants.RegionSize - || regionInfos.RegionSizeY != Constants.RegionSize) - { - // trim range looked for so we don't pick up neighbor regions just off the edges - xmin = regionInfos.RegionLocX; - xmax = regionInfos.RegionLocX + regionInfos.RegionSizeX - 10; - ymin = regionInfos.RegionLocY; - ymax = regionInfos.RegionLocY + regionInfos.RegionSizeY - 10; - rdatas = m_Database.Get(xmin, ymin, xmax, ymax, scopeID); - - // If the region is being resized, the found region could be ourself. - foreach (RegionData rdata in rdatas) - { - // m_log.DebugFormat("{0} FindAnyConflictingRegion: see if overlap. Checking {1}", LogHeader, RegionString(rdata) ); - if (region == null || region.RegionID != regionInfos.RegionID) - { - region = rdata; - m_log.WarnFormat("{0} FindAnyConflictingRegion: conflict of varregion {1} overlaps existing region {2}", - LogHeader, RegionString(regionInfos), RegionString(region)); - reason = String.Format("Region {0} would overlap existing region {1}", - RegionString(regionInfos), RegionString(region)); - - if (m_SuppressVarregionOverlapCheckOnRegistration) - region = noErrorRegion; - return region; - } - } - } - - // If we get here, region is either null (nothing found here) or - // is the non-conflicting region found at the location being requested. - return region; - } - // String describing name and region location of passed region private String RegionString(RegionData reg) { @@ -463,7 +380,7 @@ namespace OpenSim.Services.GridService int flags = Convert.ToInt32(region.Data["flags"]); - if (!m_DeleteOnUnregister || (flags & (int)OpenSim.Framework.RegionFlags.Persistent) != 0) + if ((!m_DeleteOnUnregister) || ((flags & (int)OpenSim.Framework.RegionFlags.Persistent) != 0)) { flags &= ~(int)OpenSim.Framework.RegionFlags.RegionOnline; region.Data["flags"] = flags.ToString(); @@ -478,7 +395,6 @@ namespace OpenSim.Services.GridService } return true; - } return m_Database.Delete(regionID); @@ -488,13 +404,11 @@ namespace OpenSim.Services.GridService { List rinfos = new List(); RegionData region = m_Database.Get(regionID, scopeID); - + if (region != null) { - // Not really? Maybe? - // The adjacent regions are presumed to be the same size as the current region List rdatas = m_Database.Get( - region.posX - region.sizeX - 1, region.posY - region.sizeY - 1, + region.posX - 1, region.posY - 1, region.posX + region.sizeX + 1, region.posY + region.sizeY + 1, scopeID); foreach (RegionData rdata in rdatas) @@ -516,10 +430,10 @@ namespace OpenSim.Services.GridService else { m_log.WarnFormat( - "[GRID SERVICE]: GetNeighbours() called for scope {0}, region {1} but no such region found", + "[GRID SERVICE]: GetNeighbours() called for scope {0}, region {1} but no such region found", scopeID, regionID); } - + return rinfos; } @@ -537,6 +451,7 @@ namespace OpenSim.Services.GridService // be the base coordinate of the region. // The snapping is technically unnecessary but is harmless because regions are always // multiples of the legacy region size (256). + public GridRegion GetRegionByPosition(UUID scopeID, int x, int y) { uint regionX = Util.WorldToRegionLoc((uint)x); @@ -553,8 +468,8 @@ namespace OpenSim.Services.GridService } else { - m_log.DebugFormat("{0} GetRegionByPosition. Did not find region in database. Pos=<{1},{2}>", - LogHeader, regionX, regionY); +// m_log.DebugFormat("{0} GetRegionByPosition. Did not find region in database. Pos=<{1},{2}>", +// LogHeader, regionX, regionY); return null; } } @@ -584,7 +499,78 @@ namespace OpenSim.Services.GridService int count = 0; List rinfos = new List(); - if (rdatas != null) + if (count < maxNumber && m_AllowHypergridMapSearch && name.Contains(".")) + { + string regionURI = ""; + string regionName = ""; + if(!Util.buildHGRegionURI(name, out regionURI, out regionName)) + return null; + + string mapname; + bool localGrid = m_HypergridLinker.IsLocalGrid(regionURI); + if(localGrid) + mapname = regionName; + else + mapname = regionURI + regionName; + + bool haveMatch = false; + + if (rdatas != null && (rdatas.Count > 0)) + { +// m_log.DebugFormat("[GRID SERVICE]: Found {0} regions", rdatas.Count); + foreach (RegionData rdata in rdatas) + { + if (count++ < maxNumber) + rinfos.Add(RegionData2RegionInfo(rdata)); + if(rdata.RegionName == mapname) + { + haveMatch = true; + if(count == maxNumber) + { + rinfos.RemoveAt(count - 1); + rinfos.Add(RegionData2RegionInfo(rdata)); + } + } + } + if(haveMatch) + return rinfos; + } + + rdatas = m_Database.Get(Util.EscapeForLike(mapname)+ "%", scopeID); + if (rdatas != null && (rdatas.Count > 0)) + { +// m_log.DebugFormat("[GRID SERVICE]: Found {0} regions", rdatas.Count); + foreach (RegionData rdata in rdatas) + { + if (count++ < maxNumber) + rinfos.Add(RegionData2RegionInfo(rdata)); + if(rdata.RegionName == mapname) + { + haveMatch = true; + if(count == maxNumber) + { + rinfos.RemoveAt(count - 1); + rinfos.Add(RegionData2RegionInfo(rdata)); + break; + } + } + } + if(haveMatch) + return rinfos; + } + if(!localGrid && !string.IsNullOrWhiteSpace(regionURI)) + { + string HGname = regionURI +" "+ regionName; // include space for compatibility + GridRegion r = m_HypergridLinker.LinkRegion(scopeID, HGname); + if (r != null) + { + if( count == maxNumber) + rinfos.RemoveAt(count - 1); + rinfos.Add(r); + } + } + } + else if (rdatas != null && (rdatas.Count > 0)) { // m_log.DebugFormat("[GRID SERVICE]: Found {0} regions", rdatas.Count); foreach (RegionData rdata in rdatas) @@ -594,13 +580,6 @@ namespace OpenSim.Services.GridService } } - if (m_AllowHypergridMapSearch && (rdatas == null || (rdatas != null && rdatas.Count == 0))) - { - GridRegion r = GetHypergridRegionByName(scopeID, name); - if (r != null) - rinfos.Add(r); - } - return rinfos; } @@ -613,9 +592,30 @@ namespace OpenSim.Services.GridService protected GridRegion GetHypergridRegionByName(UUID scopeID, string name) { if (name.Contains(".")) - return m_HypergridLinker.LinkRegion(scopeID, name); - else - return null; + { + string regionURI = ""; + string regionName = ""; + if(!Util.buildHGRegionURI(name, out regionURI, out regionName)) + return null; + + string mapname; + bool localGrid = m_HypergridLinker.IsLocalGrid(regionURI); + if(localGrid) + mapname = regionName; + else + mapname = regionURI + regionName; + + List rdatas = m_Database.Get(Util.EscapeForLike(mapname), scopeID); + if ((rdatas != null) && (rdatas.Count > 0)) + return RegionData2RegionInfo(rdatas[0]); // get the first + + if(!localGrid && !string.IsNullOrWhiteSpace(regionURI)) + { + string HGname = regionURI +" "+ regionName; + return m_HypergridLinker.LinkRegion(scopeID, HGname); + } + } + return null; } public List GetRegionRange(UUID scopeID, int xmin, int xmax, int ymin, int ymax) @@ -666,7 +666,7 @@ namespace OpenSim.Services.GridService return rinfo; } - #endregion + #endregion public List GetDefaultRegions(UUID scopeID) { @@ -705,7 +705,7 @@ namespace OpenSim.Services.GridService int normalDefaultRegionsFoundOnline = ret.Count - hgDefaultRegionsFoundOnline; m_log.DebugFormat( - "[GRID SERVICE]: GetDefaultHypergridRegions returning {0} hypergrid default and {1} normal default regions", + "[GRID SERVICE]: GetDefaultHypergridRegions returning {0} hypergrid default and {1} normal default regions", hgDefaultRegionsFoundOnline, normalDefaultRegionsFoundOnline); return ret; @@ -742,7 +742,7 @@ namespace OpenSim.Services.GridService 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); @@ -804,14 +804,14 @@ namespace OpenSim.Services.GridService return; } - List regions = m_Database.Get(int.MinValue, int.MinValue, int.MaxValue, int.MaxValue, UUID.Zero); + List regions = m_Database.Get(0, 0, int.MaxValue, int.MaxValue, UUID.Zero); OutputRegionsToConsoleSummary(regions); } private void HandleShowGridSize(string module, string[] cmd) { - List regions = m_Database.Get(int.MinValue, int.MinValue, int.MaxValue, int.MaxValue, UUID.Zero); + List regions = m_Database.Get(0, 0, int.MaxValue, int.MaxValue, UUID.Zero); double size = 0; @@ -872,7 +872,9 @@ namespace OpenSim.Services.GridService return; } + RegionData region = m_Database.Get((int)Util.RegionToWorldLoc(x), (int)Util.RegionToWorldLoc(y), UUID.Zero); + if (region == null) { MainConsole.Instance.OutputFormat("No region found at {0},{1}", x, y); @@ -889,7 +891,7 @@ namespace OpenSim.Services.GridService ConsoleDisplayList dispList = new ConsoleDisplayList(); dispList.AddRow("Region Name", r.RegionName); dispList.AddRow("Region ID", r.RegionID); - dispList.AddRow("Position", string.Format("{0},{1}", r.coordX, r.coordY)); + dispList.AddRow("Location", string.Format("{0},{1}", r.coordX, r.coordY)); dispList.AddRow("Size", string.Format("{0}x{1}", r.sizeX, r.sizeY)); dispList.AddRow("URI", r.Data["serverURI"]); dispList.AddRow("Owner ID", r.Data["owner_uuid"]); @@ -907,9 +909,9 @@ namespace OpenSim.Services.GridService private void OutputRegionsToConsoleSummary(List regions) { ConsoleDisplayTable dispTable = new ConsoleDisplayTable(); - dispTable.AddColumn("Name", 44); - dispTable.AddColumn("ID", 36); - dispTable.AddColumn("Position", 11); + dispTable.AddColumn("Name", ConsoleDisplayUtil.RegionNameSize); + dispTable.AddColumn("ID", ConsoleDisplayUtil.UuidSize); + dispTable.AddColumn("Position", ConsoleDisplayUtil.CoordTupleSize); dispTable.AddColumn("Size", 11); dispTable.AddColumn("Flags", 60); @@ -992,7 +994,7 @@ namespace OpenSim.Services.GridService } /// - /// Gets the grid extra service URls we wish for the region to send in OpenSimExtras to dynamically refresh + /// Gets the grid extra service URls we wish for the region to send in OpenSimExtras to dynamically refresh /// parameters in the viewer used to access services like map, search and destination guides. /// see "SimulatorFeaturesModule" /// -- cgit v1.1