From 28d6705358c2e383fb46c57f064de4dcff144e33 Mon Sep 17 00:00:00 2001 From: Melanie Date: Sat, 9 Jan 2010 20:46:32 +0000 Subject: Preliminary work on the new default region setting mechanism --- OpenSim/Data/IRegionData.cs | 11 ++++ OpenSim/Data/MSSQL/MSSQLRegionData.cs | 10 ++++ OpenSim/Data/MySQL/MySQLRegionData.cs | 26 ++++++++ OpenSim/Data/MySQL/Resources/005_GridStore.sql | 6 ++ OpenSim/Data/Null/NullRegionData.cs | 10 ++++ OpenSim/Data/RegionProfileData.cs | 1 - .../ServiceConnectorsOut/Grid/HGGridConnector.cs | 14 +++++ .../Grid/LocalGridServiceConnector.cs | 16 +++++ .../Connectors/Grid/GridServiceConnector.cs | 14 +++++ OpenSim/Services/GridService/GridService.cs | 69 ++++++++++++++++++++++ OpenSim/Services/Interfaces/IGridService.cs | 4 ++ 11 files changed, 180 insertions(+), 1 deletion(-) create mode 100644 OpenSim/Data/MySQL/Resources/005_GridStore.sql (limited to 'OpenSim') diff --git a/OpenSim/Data/IRegionData.cs b/OpenSim/Data/IRegionData.cs index 7a607ab..b8de1d8 100644 --- a/OpenSim/Data/IRegionData.cs +++ b/OpenSim/Data/IRegionData.cs @@ -60,5 +60,16 @@ namespace OpenSim.Data bool Delete(UUID regionID); + List GetDefaultRegions(UUID scopeID); + List GetFallbackRegions(UUID scopeID, int x, int y); + } + + [Flags] + public enum RegionFlags : int + { + DefaultRegion = 1, // Used for new Rez. Random if multiple defined + FallbackRegion = 2, // Regions we redirect to when the destination is down + RegionOnline = 4, // Set when a region comes online, unset when it unregisters and DeleteOnUnregister is false + NoDirectLogin = 8 // Region unavailable for direct logins (by name) } } diff --git a/OpenSim/Data/MSSQL/MSSQLRegionData.cs b/OpenSim/Data/MSSQL/MSSQLRegionData.cs index a898aab..fbfb78e 100644 --- a/OpenSim/Data/MSSQL/MSSQLRegionData.cs +++ b/OpenSim/Data/MSSQL/MSSQLRegionData.cs @@ -307,5 +307,15 @@ namespace OpenSim.Data.MSSQL } return false; } + + public List GetDefaultRegions(UUID scopeID) + { + return null; + } + + public List GetFallbackRegions(UUID scopeID, int x, int y) + { + return null; + } } } diff --git a/OpenSim/Data/MySQL/MySQLRegionData.cs b/OpenSim/Data/MySQL/MySQLRegionData.cs index b0075e8..d045f61 100644 --- a/OpenSim/Data/MySQL/MySQLRegionData.cs +++ b/OpenSim/Data/MySQL/MySQLRegionData.cs @@ -274,5 +274,31 @@ namespace OpenSim.Data.MySQL return false; } + public List GetDefaultRegions(UUID scopeID) + { + string command = "select * from `"+m_Realm+"` where (flags & 1) <> 0"; + if (scopeID != UUID.Zero) + command += " and ScopeID = ?scopeID"; + + MySqlCommand cmd = new MySqlCommand(command); + + cmd.Parameters.AddWithValue("?scopeID", scopeID.ToString()); + + return RunCommand(cmd); + } + + public List GetFallbackRegions(UUID scopeID, int x, int y) + { + string command = "select * from `"+m_Realm+"` where (flags & 2) <> 0"; + if (scopeID != UUID.Zero) + command += " and ScopeID = ?scopeID"; + + MySqlCommand cmd = new MySqlCommand(command); + + cmd.Parameters.AddWithValue("?scopeID", scopeID.ToString()); + + // TODO: distance-sort results + return RunCommand(cmd); + } } } diff --git a/OpenSim/Data/MySQL/Resources/005_GridStore.sql b/OpenSim/Data/MySQL/Resources/005_GridStore.sql new file mode 100644 index 0000000..835ba89 --- /dev/null +++ b/OpenSim/Data/MySQL/Resources/005_GridStore.sql @@ -0,0 +1,6 @@ +BEGIN; + +ALTER TABLE `regions` ADD COLUMN `flags` integer NOT NULL DEFAULT 0; +CREATE INDEX flags ON regions(flags); + +COMMIT; diff --git a/OpenSim/Data/Null/NullRegionData.cs b/OpenSim/Data/Null/NullRegionData.cs index e8263ea..92db87a 100644 --- a/OpenSim/Data/Null/NullRegionData.cs +++ b/OpenSim/Data/Null/NullRegionData.cs @@ -130,5 +130,15 @@ namespace OpenSim.Data.Null return true; } + + public List GetDefaultRegions(UUID scopeID) + { + return null; + } + + public List GetFallbackRegions(UUID scopeID, int x, int y) + { + return null; + } } } diff --git a/OpenSim/Data/RegionProfileData.cs b/OpenSim/Data/RegionProfileData.cs index 86d7f6b..90713d2 100644 --- a/OpenSim/Data/RegionProfileData.cs +++ b/OpenSim/Data/RegionProfileData.cs @@ -136,7 +136,6 @@ namespace OpenSim.Data /// public uint maturity; - //Data Wrappers public string RegionName { diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/HGGridConnector.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/HGGridConnector.cs index 93cb60c..501f730 100644 --- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/HGGridConnector.cs +++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/HGGridConnector.cs @@ -808,6 +808,20 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid #endregion + public List GetDefaultRegions(UUID scopeID) + { + return null; + } + + public List GetFallbackRegions(UUID scopeID, int x, int y) + { + return null; + } + + public int GetRegionFlags(UUID scopeID, UUID regionID) + { + return 0; + } } } diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/LocalGridServiceConnector.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/LocalGridServiceConnector.cs index 1c72488..f0081fc 100644 --- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/LocalGridServiceConnector.cs +++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/LocalGridServiceConnector.cs @@ -250,5 +250,21 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid m_log.InfoFormat(" {0} @ {1}={2}", r.RegionName, r.RegionLocX / Constants.RegionSize, r.RegionLocY / Constants.RegionSize); } } + + public List GetDefaultRegions(UUID scopeID) + { + return null; + } + + public List GetFallbackRegions(UUID scopeID, int x, int y) + { + return null; + } + + public int GetRegionFlags(UUID scopeID, UUID regionID) + { + return 0; + } + } } diff --git a/OpenSim/Services/Connectors/Grid/GridServiceConnector.cs b/OpenSim/Services/Connectors/Grid/GridServiceConnector.cs index 99aa3fb..7f1f2fd 100644 --- a/OpenSim/Services/Connectors/Grid/GridServiceConnector.cs +++ b/OpenSim/Services/Connectors/Grid/GridServiceConnector.cs @@ -450,5 +450,19 @@ namespace OpenSim.Services.Connectors #endregion + public List GetDefaultRegions(UUID scopeID) + { + return null; + } + + public List GetFallbackRegions(UUID scopeID, int x, int y) + { + return null; + } + + public int GetRegionFlags(UUID scopeID, UUID regionID) + { + return 0; + } } } diff --git a/OpenSim/Services/GridService/GridService.cs b/OpenSim/Services/GridService/GridService.cs index 86815e5..884bc95 100644 --- a/OpenSim/Services/GridService/GridService.cs +++ b/OpenSim/Services/GridService/GridService.cs @@ -46,10 +46,18 @@ namespace OpenSim.Services.GridService LogManager.GetLogger( MethodBase.GetCurrentMethod().DeclaringType); + private bool m_DeleteOnUnregister = true; + public GridService(IConfigSource config) : base(config) { m_log.DebugFormat("[GRID SERVICE]: Starting..."); + + IConfig gridConfig = config.Configs["GridService"]; + if (gridConfig != null) + { + m_DeleteOnUnregister = gridConfig.GetBoolean("DeleteOnUnregister", true); + } } #region IGridService @@ -85,6 +93,15 @@ namespace OpenSim.Services.GridService // Everything is ok, let's register RegionData rdata = RegionInfo2RegionData(regionInfos); rdata.ScopeID = scopeID; + + if (region != null) + { + rdata.Data["flags"] = region.Data["flags"]; // Preserve fields + } + int flags = Convert.ToInt32(rdata.Data["flags"]); + flags |= (int)OpenSim.Data.RegionFlags.RegionOnline; + rdata.Data["flags"] = flags.ToString(); + try { m_Database.Store(rdata); @@ -103,6 +120,28 @@ namespace OpenSim.Services.GridService public bool DeregisterRegion(UUID regionID) { m_log.DebugFormat("[GRID SERVICE]: Region {0} deregistered", regionID); + if (!m_DeleteOnUnregister) + { + RegionData region = m_Database.Get(regionID, UUID.Zero); + if (region == null) + return false; + + int flags = Convert.ToInt32(region.Data["flags"]); + flags &= ~(int)OpenSim.Data.RegionFlags.RegionOnline; + region.Data["flags"] = flags.ToString(); + try + { + m_Database.Store(region); + } + catch (Exception e) + { + m_log.DebugFormat("[GRID SERVICE]: Database exception: {0}", e); + } + + return true; + + } + return m_Database.Delete(regionID); } @@ -218,5 +257,35 @@ namespace OpenSim.Services.GridService #endregion + public List GetDefaultRegions(UUID scopeID) + { + List ret = new List(); + + List regions = m_Database.GetDefaultRegions(scopeID); + + foreach (RegionData r in regions) + ret.Add(RegionData2RegionInfo(r)); + + return ret; + } + + public List GetFallbackRegions(UUID scopeID, int x, int y) + { + List ret = new List(); + + List regions = m_Database.GetFallbackRegions(scopeID, x, y); + + foreach (RegionData r in regions) + ret.Add(RegionData2RegionInfo(r)); + + return ret; + } + + public int GetRegionFlags(UUID scopeID, UUID regionID) + { + RegionData region = m_Database.Get(regionID, scopeID); + + return Convert.ToInt32(region.Data["flags"]); + } } } diff --git a/OpenSim/Services/Interfaces/IGridService.cs b/OpenSim/Services/Interfaces/IGridService.cs index e69e4cd..5ea136f 100644 --- a/OpenSim/Services/Interfaces/IGridService.cs +++ b/OpenSim/Services/Interfaces/IGridService.cs @@ -90,6 +90,10 @@ namespace OpenSim.Services.Interfaces List GetRegionRange(UUID scopeID, int xmin, int xmax, int ymin, int ymax); + List GetDefaultRegions(UUID scopeID); + List GetFallbackRegions(UUID scopeID, int x, int y); + + int GetRegionFlags(UUID scopeID, UUID regionID); } public class GridRegion -- cgit v1.1