diff --git a/OpenSim/Data/MSSQL/MSSQLEstateData.cs b/OpenSim/Data/MSSQL/MSSQLEstateData.cs index 1624f56a20..474f706ed3 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 e94dcda2bb..7fe1fcc9cc 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; + + foreach (string name in FieldList) { - found = true; - - 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 4a447d26d1..5b6135edd4 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 6861544c84..87c7a05f6d 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 078cf030e2..da81c032e6 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 a45bf8c79b..befd14e02a 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 +}