diff --git a/OpenSim/ApplicationPlugins/LoadRegions/EstateLoaderFileSystem.cs b/OpenSim/ApplicationPlugins/LoadRegions/EstateLoaderFileSystem.cs index 2e5674ecd6..652a5687fa 100644 --- a/OpenSim/ApplicationPlugins/LoadRegions/EstateLoaderFileSystem.cs +++ b/OpenSim/ApplicationPlugins/LoadRegions/EstateLoaderFileSystem.cs @@ -69,14 +69,14 @@ namespace OpenSim.ApplicationPlugins.LoadRegions if (!Directory.Exists(estateConfigPath)) return; // if nothing there, don't bother - string[] iniFiles = null; + string[] iniFiles; try { iniFiles = Directory.GetFiles(estateConfigPath, "*.ini"); } catch { - m_log.Info("[ESTATE LOADER FILE SYSTEM]: could not open " + estateConfigPath); + m_log.Error("[ESTATE LOADER FILE SYSTEM]: could not open " + estateConfigPath); return; } @@ -88,6 +88,8 @@ namespace OpenSim.ApplicationPlugins.LoadRegions List existingEstates; + List existingEstateIDs = m_application.EstateDataService.GetEstatesAll(); + int i = 0; foreach (string file in iniFiles) { @@ -100,7 +102,7 @@ namespace OpenSim.ApplicationPlugins.LoadRegions } catch { - m_log.InfoFormat("[ESTATE LOADER FILE SYSTEM]: failed to parse file {0}", file); + m_log.WarnFormat("[ESTATE LOADER FILE SYSTEM]: failed to parse file {0}", file); } if(source == null) @@ -115,7 +117,7 @@ namespace OpenSim.ApplicationPlugins.LoadRegions if (estateName.Length > 64) // need check this and if utf8 is valid { - m_log.InfoFormat("[ESTATE LOADER FILE SYSTEM]: Estate name {0} is too large, ignoring", estateName); + m_log.WarnFormat("[ESTATE LOADER FILE SYSTEM]: Estate name {0} is too large, ignoring", estateName); continue; } @@ -134,8 +136,27 @@ namespace OpenSim.ApplicationPlugins.LoadRegions //### Should check Estate Owner ID but no Scene object available at this point + // Does Config Specify EstateID (0 Defaults To AutoIncrement) + int EstateID = config.GetInt("EstateID", 0); + + if (EstateID > 0) + { + if (EstateID < 100) + { + // EstateID Cannot be less than 100 + m_log.WarnFormat("[ESTATE LOADER FILE SYSTEM]: Estate name {0} specified estateID that is less that 100, ignoring", estateName); + continue; + } + else if(existingEstateIDs.Contains(EstateID)) + { + // Specified EstateID Exists + m_log.WarnFormat("[ESTATE LOADER FILE SYSTEM]: Estate name {0} specified estateID that is already in use, ignoring", estateName); + continue; + } + } + // Create a new estate with the name provided - EstateSettings estateSettings = m_application.EstateDataService.CreateNewEstate(); + EstateSettings estateSettings = m_application.EstateDataService.CreateNewEstate(EstateID); estateSettings.EstateName = estateName; estateSettings.EstateOwner = estateOwner; diff --git a/OpenSim/Data/IEstateDataStore.cs b/OpenSim/Data/IEstateDataStore.cs index 6b30db2295..cc32d598da 100644 --- a/OpenSim/Data/IEstateDataStore.cs +++ b/OpenSim/Data/IEstateDataStore.cs @@ -55,12 +55,12 @@ namespace OpenSim.Data EstateSettings LoadEstateSettings(int estateID); /// - /// Create a new estate. + /// Create a new estate. Zero estateID for auto increment id /// /// /// A /// - EstateSettings CreateNewEstate(); + EstateSettings CreateNewEstate(int estateID); /// /// Load/Get all estate settings. diff --git a/OpenSim/Data/MySQL/MySQLEstateData.cs b/OpenSim/Data/MySQL/MySQLEstateData.cs index 2406ee6a6e..1cb21e7210 100644 --- a/OpenSim/Data/MySQL/MySQLEstateData.cs +++ b/OpenSim/Data/MySQL/MySQLEstateData.cs @@ -120,10 +120,12 @@ namespace OpenSim.Data.MySQL } } - public EstateSettings CreateNewEstate() + public EstateSettings CreateNewEstate(int estateID) { EstateSettings es = new EstateSettings(); + es.OnSave += StoreEstateSettings; + es.EstateID = Convert.ToUInt32(estateID); DoCreate(es); @@ -193,7 +195,9 @@ namespace OpenSim.Data.MySQL // Migration case List names = new List(FieldList); - names.Remove("EstateID"); + // Remove EstateID and use AutoIncrement + if (es.EstateID < 100) + names.Remove("EstateID"); string sql = "insert into estate_settings (" + String.Join(",", names.ToArray()) + ") values ( ?" + String.Join(", ?", names.ToArray()) + ")"; @@ -222,16 +226,20 @@ namespace OpenSim.Data.MySQL cmd2.ExecuteNonQuery(); - cmd2.CommandText = "select LAST_INSERT_ID() as id"; - cmd2.Parameters.Clear(); - - using (IDataReader r = cmd2.ExecuteReader()) + // Only get Auto ID if we actually used it else we just get 0 + if (es.EstateID < 100) { - r.Read(); - es.EstateID = Convert.ToUInt32(r["id"]); - } + cmd2.CommandText = "select LAST_INSERT_ID() as id"; + cmd2.Parameters.Clear(); - es.Save(); + using (IDataReader r = cmd2.ExecuteReader()) + { + r.Read(); + es.EstateID = Convert.ToUInt32(r["id"]); + } + + es.Save(); + } } dbcon.Close(); } diff --git a/OpenSim/Data/Null/NullEstateData.cs b/OpenSim/Data/Null/NullEstateData.cs index 9f2289600c..bf2ab08690 100755 --- a/OpenSim/Data/Null/NullEstateData.cs +++ b/OpenSim/Data/Null/NullEstateData.cs @@ -98,7 +98,7 @@ namespace OpenSim.Data.Null return GetEstate(); } - public EstateSettings CreateNewEstate() + public EstateSettings CreateNewEstate(int estateID) { return new EstateSettings(); } diff --git a/OpenSim/Data/PGSQL/PGSQLEstateData.cs b/OpenSim/Data/PGSQL/PGSQLEstateData.cs index 16e56fadba..4eff7fb7d7 100644 --- a/OpenSim/Data/PGSQL/PGSQLEstateData.cs +++ b/OpenSim/Data/PGSQL/PGSQLEstateData.cs @@ -177,10 +177,12 @@ namespace OpenSim.Data.PGSQL return es; } - public EstateSettings CreateNewEstate() + public EstateSettings CreateNewEstate(int estateID) { EstateSettings es = new EstateSettings(); + es.OnSave += StoreEstateSettings; + es.EstateID = Convert.ToUInt32(estateID); DoCreate(es); @@ -197,7 +199,9 @@ namespace OpenSim.Data.PGSQL { List names = new List(FieldList); - names.Remove("EstateID"); + // Remove EstateID and use AutoIncrement + if (es.EstateID < 100) + names.Remove("EstateID"); string sql = string.Format("insert into estate_settings (\"{0}\") values ( :{1} )", String.Join("\",\"", names.ToArray()), String.Join(", :", names.ToArray())); @@ -215,10 +219,9 @@ namespace OpenSim.Data.PGSQL //insertCommand.Parameters.Add(idParameter); conn.Open(); - es.EstateID = 100; - - if (insertCommand.ExecuteNonQuery() > 0) + if (insertCommand.ExecuteNonQuery() > 0 && es.EstateID < 100) { + // Only get Auto ID if we actually used it insertCommand.CommandText = "Select cast(lastval() as int) as ID ;"; using (NpgsqlDataReader result = insertCommand.ExecuteReader()) diff --git a/OpenSim/Data/SQLite/SQLiteEstateData.cs b/OpenSim/Data/SQLite/SQLiteEstateData.cs index 88ee3d9c0c..8491302aa7 100644 --- a/OpenSim/Data/SQLite/SQLiteEstateData.cs +++ b/OpenSim/Data/SQLite/SQLiteEstateData.cs @@ -167,10 +167,12 @@ namespace OpenSim.Data.SQLite return es; } - public EstateSettings CreateNewEstate() + public EstateSettings CreateNewEstate(int estateID) { EstateSettings es = new EstateSettings(); + es.OnSave += StoreEstateSettings; + es.EstateID = Convert.ToUInt32(estateID); DoCreate(es); @@ -186,9 +188,12 @@ namespace OpenSim.Data.SQLite private void DoCreate(EstateSettings es) { List names = new List(FieldList); - names.Remove("EstateID"); - using (SqliteCommand cmd = (SqliteCommand)m_connection.CreateCommand()) + // Remove EstateID and use AutoIncrement + if (es.EstateID < 100) + names.Remove("EstateID"); + + using (SqliteCommand cmd = m_connection.CreateCommand()) { string sql = "insert into estate_settings ("+String.Join(",", names.ToArray())+") values ( :"+String.Join(", :", names.ToArray())+")"; @@ -212,12 +217,16 @@ namespace OpenSim.Data.SQLite cmd.ExecuteNonQuery(); - cmd.CommandText = "select LAST_INSERT_ROWID() as id"; - cmd.Parameters.Clear(); - using(IDataReader r = cmd.ExecuteReader()) + // Only get Auto ID if we actually used it else we just get 0 + if (es.EstateID < 100) { - r.Read(); - es.EstateID = Convert.ToUInt32(r["id"]); + cmd.CommandText = "select LAST_INSERT_ROWID() as id"; + cmd.Parameters.Clear(); + using (IDataReader r = cmd.ExecuteReader()) + { + r.Read(); + es.EstateID = Convert.ToUInt32(r["id"]); + } } } } diff --git a/OpenSim/Services/Connectors/Estate/EstateDataConnector.cs b/OpenSim/Services/Connectors/Estate/EstateDataConnector.cs index 0971b3866a..b400df1d40 100644 --- a/OpenSim/Services/Connectors/Estate/EstateDataConnector.cs +++ b/OpenSim/Services/Connectors/Estate/EstateDataConnector.cs @@ -248,7 +248,7 @@ namespace OpenSim.Services.Connectors /// Forbidden operation /// /// - public EstateSettings CreateNewEstate() + public EstateSettings CreateNewEstate(int estateID) { // No can do return null; diff --git a/OpenSim/Services/EstateService/EstateDataService.cs b/OpenSim/Services/EstateService/EstateDataService.cs index f051ffb513..b25b08b68d 100644 --- a/OpenSim/Services/EstateService/EstateDataService.cs +++ b/OpenSim/Services/EstateService/EstateDataService.cs @@ -88,9 +88,9 @@ namespace OpenSim.Services.EstateService return m_database.LoadEstateSettings(estateID); } - public EstateSettings CreateNewEstate() + public EstateSettings CreateNewEstate(int estateID = 0) { - return m_database.CreateNewEstate(); + return m_database.CreateNewEstate(estateID); } public List LoadEstateSettingsAll() diff --git a/OpenSim/Services/Interfaces/IEstateDataService.cs b/OpenSim/Services/Interfaces/IEstateDataService.cs index 9b64a392ba..13f81d55c6 100644 --- a/OpenSim/Services/Interfaces/IEstateDataService.cs +++ b/OpenSim/Services/Interfaces/IEstateDataService.cs @@ -50,12 +50,12 @@ namespace OpenSim.Services.Interfaces EstateSettings LoadEstateSettings(int estateID); /// - /// Create a new estate. + /// Create a new estate. Zero estateID for auto increment id /// /// /// A /// - EstateSettings CreateNewEstate(); + EstateSettings CreateNewEstate(int estateID = 0); /// /// Load/Get all estate settings. @@ -74,7 +74,7 @@ namespace OpenSim.Services.Interfaces /// /// Get estate IDs. /// - /// Name of estate to search for. This is the exact name, no parttern matching is done. + /// Name of estate to search for. This is the exact name, no pattern matching is done. /// List GetEstates(string search); diff --git a/bin/Estates/Estates.ini.example b/bin/Estates/Estates.ini.example index 38ac3649af..0b97898bf7 100644 --- a/bin/Estates/Estates.ini.example +++ b/bin/Estates/Estates.ini.example @@ -14,5 +14,7 @@ ; * ; * You MUST change this! It will NOT be done for you! ; * +Owner = 11111111-2222-3333-4444-555555555555 -Owner = 11111111-2222-3333-4444-555555555555 \ No newline at end of file +; Use 0 For Auto increment ID (Recommended). When specifying a specific id, remember it can not be less than 100 +EstateID = 0 \ No newline at end of file