From dcf18689b9ab29d4ceb2348bb56fc1f77a7a8912 Mon Sep 17 00:00:00 2001 From: Melanie Date: Tue, 23 Mar 2010 02:05:56 +0000 Subject: First stage of the new interactive region creation. This will allow creation of a region and joining it to an existing estate or creating a new estate, as well as creating an estate owner if in standalone, and assigning estate owners. In Grid mode, existing users must be used. MySQL ONLY!!!! so far, as I can't develop or test for either SQLite or MSSQL. --- OpenSim/Data/MSSQL/MSSQLEstateData.cs | 25 +++++ OpenSim/Data/MySQL/MySQLEstateData.cs | 175 ++++++++++++++++++++++++-------- OpenSim/Data/SQLite/SQLiteEstateData.cs | 25 +++++ 3 files changed, 180 insertions(+), 45 deletions(-) (limited to 'OpenSim/Data') diff --git a/OpenSim/Data/MSSQL/MSSQLEstateData.cs b/OpenSim/Data/MSSQL/MSSQLEstateData.cs index 1624f56..474f706 100644 --- a/OpenSim/Data/MSSQL/MSSQLEstateData.cs +++ b/OpenSim/Data/MSSQL/MSSQLEstateData.cs @@ -346,6 +346,31 @@ namespace OpenSim.Data.MSSQL } } } + + public EstateSettings LoadEstateSettings(int estateID) + { + return new EstateSettings(); + } + + public List GetEstates(string search) + { + return new List(); + } + + public bool LinkRegion(UUID regionID, int estateID) + { + return false; + } + + public List GetRegions(int estateID) + { + return new List(); + } + + public bool DeleteEstate(int estateID) + { + return false; + } #endregion } } diff --git a/OpenSim/Data/MySQL/MySQLEstateData.cs b/OpenSim/Data/MySQL/MySQLEstateData.cs index e94dcda..7fe1fcc 100644 --- a/OpenSim/Data/MySQL/MySQLEstateData.cs +++ b/OpenSim/Data/MySQL/MySQLEstateData.cs @@ -123,50 +123,57 @@ namespace OpenSim.Data.MySQL public EstateSettings LoadEstateSettings(UUID regionID, bool create) { - EstateSettings es = new EstateSettings(); - es.OnSave += StoreEstateSettings; - string sql = "select estate_settings." + String.Join(",estate_settings.", FieldList) + " from estate_map left join estate_settings on estate_map.EstateID = estate_settings.EstateID where estate_settings.EstateID is not null and RegionID = ?RegionID"; + using (MySqlCommand cmd = new MySqlCommand()) + { + cmd.CommandText = sql; + cmd.Parameters.AddWithValue("?RegionID", regionID.ToString()); + + return DoLoad(cmd, regionID, create); + } + } + + private EstateSettings DoLoad(MySqlCommand cmd, UUID regionID, bool create) + { + EstateSettings es = new EstateSettings(); + es.OnSave += StoreEstateSettings; + using (MySqlConnection dbcon = new MySqlConnection(m_connectionString)) { dbcon.Open(); + cmd.Connection = dbcon; + bool found = false; - using (MySqlCommand cmd = dbcon.CreateCommand()) + using (IDataReader r = cmd.ExecuteReader()) { - cmd.CommandText = sql; - cmd.Parameters.AddWithValue("?RegionID", regionID.ToString()); - - using (IDataReader r = cmd.ExecuteReader()) + if (r.Read()) { - if (r.Read()) - { - found = true; + found = true; - foreach (string name in FieldList) + foreach (string name in FieldList) + { + if (m_FieldMap[name].GetValue(es) is bool) { - if (m_FieldMap[name].GetValue(es) is bool) - { - int v = Convert.ToInt32(r[name]); - if (v != 0) - m_FieldMap[name].SetValue(es, true); - else - m_FieldMap[name].SetValue(es, false); - } - else if (m_FieldMap[name].GetValue(es) is UUID) - { - UUID uuid = UUID.Zero; - - UUID.TryParse(r[name].ToString(), out uuid); - m_FieldMap[name].SetValue(es, uuid); - } + int v = Convert.ToInt32(r[name]); + if (v != 0) + m_FieldMap[name].SetValue(es, true); else - { - m_FieldMap[name].SetValue(es, r[name]); - } + m_FieldMap[name].SetValue(es, false); + } + else if (m_FieldMap[name].GetValue(es) is UUID) + { + UUID uuid = UUID.Zero; + + UUID.TryParse(r[name].ToString(), out uuid); + m_FieldMap[name].SetValue(es, uuid); + } + else + { + m_FieldMap[name].SetValue(es, r[name]); } } } @@ -179,45 +186,45 @@ namespace OpenSim.Data.MySQL names.Remove("EstateID"); - sql = "insert into estate_settings (" + String.Join(",", names.ToArray()) + ") values ( ?" + String.Join(", ?", names.ToArray()) + ")"; + string sql = "insert into estate_settings (" + String.Join(",", names.ToArray()) + ") values ( ?" + String.Join(", ?", names.ToArray()) + ")"; - using (MySqlCommand cmd = dbcon.CreateCommand()) + using (MySqlCommand cmd2 = dbcon.CreateCommand()) { - cmd.CommandText = sql; - cmd.Parameters.Clear(); + cmd2.CommandText = sql; + cmd2.Parameters.Clear(); foreach (string name in FieldList) { if (m_FieldMap[name].GetValue(es) is bool) { if ((bool)m_FieldMap[name].GetValue(es)) - cmd.Parameters.AddWithValue("?" + name, "1"); + cmd2.Parameters.AddWithValue("?" + name, "1"); else - cmd.Parameters.AddWithValue("?" + name, "0"); + cmd2.Parameters.AddWithValue("?" + name, "0"); } else { - cmd.Parameters.AddWithValue("?" + name, m_FieldMap[name].GetValue(es).ToString()); + cmd2.Parameters.AddWithValue("?" + name, m_FieldMap[name].GetValue(es).ToString()); } } - cmd.ExecuteNonQuery(); + cmd2.ExecuteNonQuery(); - cmd.CommandText = "select LAST_INSERT_ID() as id"; - cmd.Parameters.Clear(); + cmd2.CommandText = "select LAST_INSERT_ID() as id"; + cmd2.Parameters.Clear(); - using (IDataReader r = cmd.ExecuteReader()) + using (IDataReader r = cmd2.ExecuteReader()) { r.Read(); es.EstateID = Convert.ToUInt32(r["id"]); } - cmd.CommandText = "insert into estate_map values (?RegionID, ?EstateID)"; - cmd.Parameters.AddWithValue("?RegionID", regionID.ToString()); - cmd.Parameters.AddWithValue("?EstateID", es.EstateID.ToString()); + cmd2.CommandText = "insert into estate_map values (?RegionID, ?EstateID)"; + cmd2.Parameters.AddWithValue("?RegionID", regionID.ToString()); + cmd2.Parameters.AddWithValue("?EstateID", es.EstateID.ToString()); // This will throw on dupe key - try { cmd.ExecuteNonQuery(); } + try { cmd2.ExecuteNonQuery(); } catch (Exception) { } es.Save(); @@ -390,5 +397,83 @@ namespace OpenSim.Data.MySQL return uuids.ToArray(); } + + public EstateSettings LoadEstateSettings(int estateID) + { + using (MySqlCommand cmd = new MySqlCommand()) + { + string sql = "select estate_settings." + String.Join(",estate_settings.", FieldList) + " from estate_settings where EstateID = ?EstateID"; + + cmd.CommandText = sql; + cmd.Parameters.AddWithValue("?EstateID", estateID); + + return DoLoad(cmd, UUID.Zero, false); + } + } + + public List GetEstates(string search) + { + List result = new List(); + + using (MySqlConnection dbcon = new MySqlConnection(m_connectionString)) + { + dbcon.Open(); + + using (MySqlCommand cmd = dbcon.CreateCommand()) + { + cmd.CommandText = "select estateID from estate_settings where EstateName = ?EstateName"; + cmd.Parameters.AddWithValue("?EstateName", search); + + using (IDataReader reader = cmd.ExecuteReader()) + { + while (reader.Read()) + { + result.Add(Convert.ToInt32(reader["EstateID"])); + } + reader.Close(); + } + } + + + dbcon.Close(); + } + + return result; + } + + public bool LinkRegion(UUID regionID, int estateID) + { + using (MySqlConnection dbcon = new MySqlConnection(m_connectionString)) + { + dbcon.Open(); + + using (MySqlCommand cmd = dbcon.CreateCommand()) + { + cmd.CommandText = "insert into estate_map values (?RegionID, ?EstateID)"; + cmd.Parameters.AddWithValue("?RegionID", regionID); + cmd.Parameters.AddWithValue("?EstateID", estateID); + + if (cmd.ExecuteNonQuery() == 0) + { + dbcon.Close(); + return false; + } + } + + dbcon.Close(); + } + + return true; + } + + public List GetRegions(int estateID) + { + return new List(); + } + + public bool DeleteEstate(int estateID) + { + return false; + } } } diff --git a/OpenSim/Data/SQLite/SQLiteEstateData.cs b/OpenSim/Data/SQLite/SQLiteEstateData.cs index 4a447d2..5b6135e 100644 --- a/OpenSim/Data/SQLite/SQLiteEstateData.cs +++ b/OpenSim/Data/SQLite/SQLiteEstateData.cs @@ -320,5 +320,30 @@ namespace OpenSim.Data.SQLite return uuids.ToArray(); } + + public EstateSettings LoadEstateSettings(int estateID) + { + return new EstateSettings(); + } + + public List GetEstates(string search) + { + return new List(); + } + + public bool LinkRegion(UUID regionID, int estateID) + { + return false; + } + + public List GetRegions(int estateID) + { + return new List(); + } + + public bool DeleteEstate(int estateID) + { + return false; + } } } -- cgit v1.1