From d6ebf2d6cacd6341fb65b4c124d358aa8c1c86f8 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Sat, 10 Mar 2012 01:27:05 +0000 Subject: Add ability to specify a default estate to be used when creating regions. This is configured in the new [Estates] section of OpenSim.ini. If a default estate is configured then all new regions are automatically joined to it instead of asking the user. If the default estate does not already exist then it is created. Current default behaviour remains the same - the user is asked for estate details when necessary. Thanks to Frenando Oliveira for the patch which I adapated further. --- OpenSim/Region/Application/OpenSimBase.cs | 216 +++++++++++++++++++++--------- 1 file changed, 152 insertions(+), 64 deletions(-) (limited to 'OpenSim/Region/Application/OpenSimBase.cs') diff --git a/OpenSim/Region/Application/OpenSimBase.cs b/OpenSim/Region/Application/OpenSimBase.cs index d3c1102..c6956fc 100644 --- a/OpenSim/Region/Application/OpenSimBase.cs +++ b/OpenSim/Region/Application/OpenSimBase.cs @@ -28,6 +28,7 @@ using System; using System.Collections.Generic; using System.IO; +using System.Linq; using System.Net; using System.Reflection; using System.Text; @@ -67,6 +68,9 @@ namespace OpenSim private const string PLUGIN_ASSET_CACHE = "/OpenSim/AssetCache"; private const string PLUGIN_ASSET_SERVER_CLIENT = "/OpenSim/AssetClient"; + // OpenSim.ini Section name for ESTATES Settings + public const string ESTATE_SECTION_NAME = "Estates"; + protected string proxyUrl; protected int proxyOffset = 0; @@ -445,12 +449,42 @@ namespace OpenSim { RegionInfo regionInfo = scene.RegionInfo; + string estateOwnerFirstName = null; + string estateOwnerLastName = null; + string estateOwnerEMail = null; + string estateOwnerPassword = null; + string rawEstateOwnerUuid = null; + + if (m_config.Source.Configs[ESTATE_SECTION_NAME] != null) + { + string defaultEstateOwnerName + = m_config.Source.Configs[ESTATE_SECTION_NAME].GetString("DefaultEstateOwnerName", "").Trim(); + string[] ownerNames = defaultEstateOwnerName.Split(' '); + + if (ownerNames.Length >= 2) + { + estateOwnerFirstName = ownerNames[0]; + estateOwnerLastName = ownerNames[1]; + } + + // Info to be used only on Standalone Mode + rawEstateOwnerUuid = m_config.Source.Configs[ESTATE_SECTION_NAME].GetString("DefaultEstateOwnerUUID", null); + estateOwnerEMail = m_config.Source.Configs[ESTATE_SECTION_NAME].GetString("DefaultEstateOwnerEMail", null); + estateOwnerPassword = m_config.Source.Configs[ESTATE_SECTION_NAME].GetString("DefaultEstateOwnerPassword", null); + } + MainConsole.Instance.OutputFormat("Estate {0} has no owner set.", regionInfo.EstateSettings.EstateName); List excluded = new List(new char[1]{' '}); - string first = MainConsole.Instance.CmdPrompt("Estate owner first name", "Test", excluded); - string last = MainConsole.Instance.CmdPrompt("Estate owner last name", "User", excluded); - UserAccount account = scene.UserAccountService.GetUserAccount(regionInfo.ScopeID, first, last); + + if (estateOwnerFirstName == null || estateOwnerLastName == null) + { + estateOwnerFirstName = MainConsole.Instance.CmdPrompt("Estate owner first name", "Test", excluded); + estateOwnerLastName = MainConsole.Instance.CmdPrompt("Estate owner last name", "User", excluded); + } + + UserAccount account + = scene.UserAccountService.GetUserAccount(regionInfo.ScopeID, estateOwnerFirstName, estateOwnerLastName); if (account == null) { @@ -469,23 +503,35 @@ namespace OpenSim if (scene.UserAccountService is UserAccountService) { - string password = MainConsole.Instance.PasswdPrompt("Password"); - string email = MainConsole.Instance.CmdPrompt("Email", ""); + if (estateOwnerPassword == null) + estateOwnerPassword = MainConsole.Instance.PasswdPrompt("Password"); + + if (estateOwnerEMail == null) + estateOwnerEMail = MainConsole.Instance.CmdPrompt("Email"); - string rawPrincipalId = MainConsole.Instance.CmdPrompt("User ID", UUID.Random().ToString()); + if (rawEstateOwnerUuid == null) + rawEstateOwnerUuid = MainConsole.Instance.CmdPrompt("User ID", UUID.Random().ToString()); - UUID principalId = UUID.Zero; - if (!UUID.TryParse(rawPrincipalId, out principalId)) + UUID estateOwnerUuid = UUID.Zero; + if (!UUID.TryParse(rawEstateOwnerUuid, out estateOwnerUuid)) { - m_log.ErrorFormat("[OPENSIM]: ID {0} is not a valid UUID", rawPrincipalId); + m_log.ErrorFormat("[OPENSIM]: ID {0} is not a valid UUID", rawEstateOwnerUuid); return; } + // If we've been given a zero uuid then this signals that we should use a random user id + if (estateOwnerUuid == UUID.Zero) + estateOwnerUuid = UUID.Random(); + account = ((UserAccountService)scene.UserAccountService).CreateUser( - regionInfo.ScopeID, principalId, first, last, password, email); + regionInfo.ScopeID, + estateOwnerUuid, + estateOwnerFirstName, + estateOwnerLastName, + estateOwnerPassword, + estateOwnerEMail); } -// } } if (account == null) @@ -885,15 +931,21 @@ namespace OpenSim /// This method doesn't allow an estate to be created with the same name as existing estates. /// /// - /// A list of estate names that already exist. + /// A list of estate names that already exist. + /// Estate name to create if already known /// true if the estate was created, false otherwise - public bool CreateEstate(RegionInfo regInfo, List existingNames) + public bool CreateEstate(RegionInfo regInfo, Dictionary estatesByName, string estateName) { // Create a new estate regInfo.EstateSettings = EstateDataService.LoadEstateSettings(regInfo.RegionID, true); - string newName = MainConsole.Instance.CmdPrompt("New estate name", regInfo.EstateSettings.EstateName); - if (existingNames.Contains(newName)) + string newName; + if (estateName != null && estateName != "") + newName = estateName; + else + newName = MainConsole.Instance.CmdPrompt("New estate name", regInfo.EstateSettings.EstateName); + + if (estatesByName.ContainsKey(newName)) { MainConsole.Instance.OutputFormat("An estate named {0} already exists. Please try again.", newName); return false; @@ -920,66 +972,102 @@ namespace OpenSim if (EstateDataService != null) regInfo.EstateSettings = EstateDataService.LoadEstateSettings(regInfo.RegionID, false); - if (regInfo.EstateSettings.EstateID == 0) // No record at all + if (regInfo.EstateSettings.EstateID != 0) + return; + + m_log.WarnFormat("[ESTATE] Region {0} is not part of an estate.", regInfo.RegionName); + + List estates = EstateDataService.LoadEstateSettingsAll(); + Dictionary estatesByName = new Dictionary(); + + foreach (EstateSettings estate in estates) + estatesByName[estate.EstateName] = estate; + + string defaultEstateName = null; + + if (m_config.Source.Configs[ESTATE_SECTION_NAME] != null) { - m_log.WarnFormat("[ESTATE] Region {0} is not part of an estate.", regInfo.RegionName); - - List estates = EstateDataService.LoadEstateSettingsAll(); - List estateNames = new List(); - foreach (EstateSettings estate in estates) - estateNames.Add(estate.EstateName); - - while (true) + defaultEstateName = m_config.Source.Configs[ESTATE_SECTION_NAME].GetString("DefaultEstateName", null); + + if (defaultEstateName != null) { - if (estates.Count == 0) - { - m_log.Info("[ESTATE] No existing estates found. You must create a new one."); - - if (CreateEstate(regInfo, estateNames)) - break; + EstateSettings defaultEstate; + bool defaultEstateJoined = false; + + if (estatesByName.ContainsKey(defaultEstateName)) + { + defaultEstate = estatesByName[defaultEstateName]; + + if (EstateDataService.LinkRegion(regInfo.RegionID, (int)defaultEstate.EstateID)) + defaultEstateJoined = true; + } + else + { + if (CreateEstate(regInfo, estatesByName, defaultEstateName)) + defaultEstateJoined = true; + } + + if (defaultEstateJoined) + return; + else + m_log.ErrorFormat( + "[OPENSIM BASE]: Joining default estate {0} failed", defaultEstateName); + } + } + + // If we have no default estate or creation of the default estate failed then ask the user. + while (true) + { + if (estates.Count == 0) + { + m_log.Info("[ESTATE]: No existing estates found. You must create a new one."); + + if (CreateEstate(regInfo, estatesByName, null)) + break; + else + continue; + } + else + { + string response + = MainConsole.Instance.CmdPrompt( + string.Format( + "Do you wish to join region {0} to an existing estate (yes/no)?", regInfo.RegionName), + "yes", + new List() { "yes", "no" }); + + if (response == "no") + { + if (CreateEstate(regInfo, estatesByName, null)) + break; else continue; } else { - string response + string[] estateNames = estatesByName.Keys.ToArray(); + response = MainConsole.Instance.CmdPrompt( string.Format( - "Do you wish to join region {0} to an existing estate (yes/no)?", regInfo.RegionName), - "yes", - new List() { "yes", "no" }); - - if (response == "no") + "Name of estate to join. Existing estate names are ({0})", + string.Join(", ", estateNames)), + estateNames[0]); + + List estateIDs = EstateDataService.GetEstates(response); + if (estateIDs.Count < 1) { - if (CreateEstate(regInfo, estateNames)) - break; - else - continue; - } - else - { - response - = MainConsole.Instance.CmdPrompt( - string.Format( - "Name of estate to join. Existing estate names are ({0})", string.Join(", ", estateNames.ToArray())), - estateNames[0]); - - List estateIDs = EstateDataService.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]; - - regInfo.EstateSettings = EstateDataService.LoadEstateSettings(estateID); - - if (EstateDataService.LinkRegion(regInfo.RegionID, estateID)) - break; - - MainConsole.Instance.Output("Joining the estate failed. Please try again."); + MainConsole.Instance.Output("The name you have entered matches no known estate. Please try again."); + continue; } + + int estateID = estateIDs[0]; + + regInfo.EstateSettings = EstateDataService.LoadEstateSettings(estateID); + + if (EstateDataService.LinkRegion(regInfo.RegionID, estateID)) + break; + + MainConsole.Instance.Output("Joining the estate failed. Please try again."); } } } -- cgit v1.1