Allow estate config files to specify a specific EstateID. Defaults to 0 if not specified which uses auto increment id as current behaviour.

This commit is contained in:
Alicia Raven 2020-12-15 17:05:30 +00:00
parent 73d33aee32
commit a969797512
10 changed files with 81 additions and 38 deletions

View File

@ -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<int> existingEstates;
List<int> 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;

View File

@ -55,12 +55,12 @@ namespace OpenSim.Data
EstateSettings LoadEstateSettings(int estateID);
/// <summary>
/// Create a new estate.
/// Create a new estate. Zero estateID for auto increment id
/// </summary>
/// <returns>
/// A <see cref="EstateSettings"/>
/// </returns>
EstateSettings CreateNewEstate();
EstateSettings CreateNewEstate(int estateID);
/// <summary>
/// Load/Get all estate settings.

View File

@ -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<string> names = new List<string>(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();
}

View File

@ -98,7 +98,7 @@ namespace OpenSim.Data.Null
return GetEstate();
}
public EstateSettings CreateNewEstate()
public EstateSettings CreateNewEstate(int estateID)
{
return new EstateSettings();
}

View File

@ -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<string> names = new List<string>(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())

View File

@ -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<string> names = new List<string>(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"]);
}
}
}
}

View File

@ -248,7 +248,7 @@ namespace OpenSim.Services.Connectors
/// Forbidden operation
/// </summary>
/// <returns></returns>
public EstateSettings CreateNewEstate()
public EstateSettings CreateNewEstate(int estateID)
{
// No can do
return null;

View File

@ -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<EstateSettings> LoadEstateSettingsAll()

View File

@ -50,12 +50,12 @@ namespace OpenSim.Services.Interfaces
EstateSettings LoadEstateSettings(int estateID);
/// <summary>
/// Create a new estate.
/// Create a new estate. Zero estateID for auto increment id
/// </summary>
/// <returns>
/// A <see cref="EstateSettings"/>
/// </returns>
EstateSettings CreateNewEstate();
EstateSettings CreateNewEstate(int estateID = 0);
/// <summary>
/// Load/Get all estate settings.
@ -74,7 +74,7 @@ namespace OpenSim.Services.Interfaces
/// <summary>
/// Get estate IDs.
/// </summary>
/// <param name="search">Name of estate to search for. This is the exact name, no parttern matching is done.</param>
/// <param name="search">Name of estate to search for. This is the exact name, no pattern matching is done.</param>
/// <returns></returns>
List<int> GetEstates(string search);

View File

@ -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
; Use 0 For Auto increment ID (Recommended). When specifying a specific id, remember it can not be less than 100
EstateID = 0