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 +++ .../Framework/Interfaces/IEstateDataStore.cs | 6 + OpenSim/Region/Framework/Scenes/Scene.cs | 115 +++++++++++++- OpenSim/Services/Interfaces/IUserAccountService.cs | 4 +- 6 files changed, 302 insertions(+), 48 deletions(-) (limited to 'OpenSim') 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; + } } } diff --git a/OpenSim/Region/Framework/Interfaces/IEstateDataStore.cs b/OpenSim/Region/Framework/Interfaces/IEstateDataStore.cs index 6861544..87c7a05 100644 --- a/OpenSim/Region/Framework/Interfaces/IEstateDataStore.cs +++ b/OpenSim/Region/Framework/Interfaces/IEstateDataStore.cs @@ -25,6 +25,7 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +using System.Collections.Generic; using OpenMetaverse; using OpenSim.Framework; @@ -35,6 +36,11 @@ namespace OpenSim.Region.Framework.Interfaces void Initialise(string connectstring); EstateSettings LoadEstateSettings(UUID regionID, bool create); + EstateSettings LoadEstateSettings(int estateID); void StoreEstateSettings(EstateSettings es); + List GetEstates(string search); + bool LinkRegion(UUID regionID, int estateID); + List GetRegions(int estateID); + bool DeleteEstate(int estateID); } } diff --git a/OpenSim/Region/Framework/Scenes/Scene.cs b/OpenSim/Region/Framework/Scenes/Scene.cs index 078cf03..da81c03 100644 --- a/OpenSim/Region/Framework/Scenes/Scene.cs +++ b/OpenSim/Region/Framework/Scenes/Scene.cs @@ -604,7 +604,44 @@ namespace OpenSim.Region.Framework.Scenes m_regInfo.RegionSettings = m_storageManager.DataStore.LoadRegionSettings(m_regInfo.RegionID); if (m_storageManager.EstateDataStore != null) { - m_regInfo.EstateSettings = m_storageManager.EstateDataStore.LoadEstateSettings(m_regInfo.RegionID, true); + m_regInfo.EstateSettings = m_storageManager.EstateDataStore.LoadEstateSettings(m_regInfo.RegionID, false); + if (m_regInfo.EstateSettings.EstateID == 0) // No record at all + { + MainConsole.Instance.Output("Your region is not part of an estate."); + while (true) + { + string response = MainConsole.Instance.CmdPrompt("Do you wish to join an existing estate?", "no", new List() {"yes", "no"}); + if (response == "no") + { + // Create a new estate + m_regInfo.EstateSettings = m_storageManager.EstateDataStore.LoadEstateSettings(m_regInfo.RegionID, true); + + m_regInfo.EstateSettings.EstateName = MainConsole.Instance.CmdPrompt("New estate name", m_regInfo.EstateSettings.EstateName); + m_regInfo.EstateSettings.Save(); + break; + } + else + { + response = MainConsole.Instance.CmdPrompt("Estate name to join", "None"); + if (response == "None") + continue; + + List estateIDs = m_storageManager.EstateDataStore.GetEstates(response); + if (estateIDs.Count < 1) + { + MainConsole.Instance.Output("The name you have entered matches no known estate. Please try again"); + continue; + } + + int estateID = estateIDs[0]; + + if (m_storageManager.EstateDataStore.LinkRegion(m_regInfo.RegionID, estateID)) + break; + + MainConsole.Instance.Output("Joining the estate failed. Please try again."); + } + } + } } //Bind Storage Manager functions to some land manager functions for this scene @@ -1215,6 +1252,82 @@ namespace OpenSim.Region.Framework.Scenes m_dialogModule = RequestModuleInterface(); m_capsModule = RequestModuleInterface(); m_teleportModule = RequestModuleInterface(); + + // Shoving this in here for now, because we have the needed + // interfaces at this point + // + // TODO: Find a better place for this + // + while (m_regInfo.EstateSettings.EstateOwner == UUID.Zero) + { + MainConsole.Instance.Output("The current estate has no owner set."); + string first = MainConsole.Instance.CmdPrompt("Estate owner first name", "Test"); + string last = MainConsole.Instance.CmdPrompt("Estate owner last name", "User"); + + UserAccount account = UserAccountService.GetUserAccount(m_regInfo.ScopeID, first, last); + + if (account == null) + { + account = new UserAccount(m_regInfo.ScopeID, first, last, String.Empty); + if (account.ServiceURLs == null || (account.ServiceURLs != null && account.ServiceURLs.Count == 0)) + { + account.ServiceURLs = new Dictionary(); + account.ServiceURLs["HomeURI"] = string.Empty; + account.ServiceURLs["GatekeeperURI"] = string.Empty; + account.ServiceURLs["InventoryServerURI"] = string.Empty; + account.ServiceURLs["AssetServerURI"] = string.Empty; + } + + if (UserAccountService.StoreUserAccount(account)) + { + string password = MainConsole.Instance.PasswdPrompt("Password"); + string email = MainConsole.Instance.CmdPrompt("Email", ""); + + account.Email = email; + UserAccountService.StoreUserAccount(account); + + bool success = false; + success = AuthenticationService.SetPassword(account.PrincipalID, password); + if (!success) + m_log.WarnFormat("[USER ACCOUNT SERVICE]: Unable to set password for account {0} {1}.", + first, last); + + GridRegion home = null; + if (GridService != null) + { + List defaultRegions = GridService.GetDefaultRegions(UUID.Zero); + if (defaultRegions != null && defaultRegions.Count >= 1) + home = defaultRegions[0]; + + if (PresenceService != null && home != null) + PresenceService.SetHomeLocation(account.PrincipalID.ToString(), home.RegionID, new Vector3(128, 128, 0), new Vector3(0, 1, 0)); + else + m_log.WarnFormat("[USER ACCOUNT SERVICE]: Unable to set home for account {0} {1}.", + first, last); + + } + else + m_log.WarnFormat("[USER ACCOUNT SERVICE]: Unable to retrieve home region for account {0} {1}.", + first, last); + + if (InventoryService != null) + success = InventoryService.CreateUserInventory(account.PrincipalID); + if (!success) + m_log.WarnFormat("[USER ACCOUNT SERVICE]: Unable to create inventory for account {0} {1}.", + first, last); + + + m_log.InfoFormat("[USER ACCOUNT SERVICE]: Account {0} {1} created successfully", first, last); + + m_regInfo.EstateSettings.EstateOwner = account.PrincipalID; + m_regInfo.EstateSettings.Save(); + } + } + else + { + MainConsole.Instance.Output("You appear to be connected to a grid and can't create users from here. Please enter the name of an existing user"); + } + } } #endregion diff --git a/OpenSim/Services/Interfaces/IUserAccountService.cs b/OpenSim/Services/Interfaces/IUserAccountService.cs index a45bf8c..befd14e 100644 --- a/OpenSim/Services/Interfaces/IUserAccountService.cs +++ b/OpenSim/Services/Interfaces/IUserAccountService.cs @@ -150,10 +150,10 @@ namespace OpenSim.Services.Interfaces List GetUserAccounts(UUID scopeID, string query); /// - /// Store the data given, wich replaces the sotred data, therefore must be complete. + /// Store the data given, wich replaces the stored data, therefore must be complete. /// /// /// bool StoreUserAccount(UserAccount data); } -} \ No newline at end of file +} -- cgit v1.1