From 43eab5e16338b37defc2ae7113f41f2b37690718 Mon Sep 17 00:00:00 2001 From: Dev Random Date: Tue, 1 Apr 2014 08:56:05 -0400 Subject: Console command to rename Estate --- .../World/Estate/EstateManagementCommands.cs | 223 +++++++++++++-------- 1 file changed, 140 insertions(+), 83 deletions(-) (limited to 'OpenSim/Region/CoreModules/World/Estate/EstateManagementCommands.cs') diff --git a/OpenSim/Region/CoreModules/World/Estate/EstateManagementCommands.cs b/OpenSim/Region/CoreModules/World/Estate/EstateManagementCommands.cs index 59dd3bb..4c65ce3 100644 --- a/OpenSim/Region/CoreModules/World/Estate/EstateManagementCommands.cs +++ b/OpenSim/Region/CoreModules/World/Estate/EstateManagementCommands.cs @@ -54,14 +54,9 @@ namespace OpenSim.Region.CoreModules.World.Estate protected Commander m_commander = new Commander("estate"); - // variable used in processing "estate set owner" - private static string[] m_ownerCmd = null; - - // variable used in processing "estate set owner" - private static UserAccount m_ownerAccount; - - // variable used in processing "estate set owner" - private static List m_ownerEstates; + // used to prevent multiple processing of commands when called from root region + private static string[] m_currentCmd = null; + private static EstateSettings m_estateSettings = null; public EstateManagementCommands(EstateManagementModule module) { @@ -92,18 +87,22 @@ namespace OpenSim.Region.CoreModules.World.Estate "Specify -1 in or to wildcard that coordinate.", consoleSetWaterHeight); - m_module.Scene.AddCommand( "Estates", m_module, "estate show", "estate show", "Shows all estates on the simulator.", ShowEstatesCommand); m_module.Scene.AddCommand( - "Estates", m_module, "estate set owner", "estate set owner [ | ]", - "Sets the owner of the current region's estate to the specified UUID or user. " + - "If called from root region, all estates will be prompted for change.", SetEstateOwnerCommand); + "Estates", m_module, "estate set owner", "estate set owner [ | ]", + "Sets the owner of the specified estate to the specified UUID or user. ", SetEstateOwnerCommand); + + m_module.Scene.AddCommand( + "Estates", m_module, "estate set name", "estate set name ", + "Sets the name of the specified estate to the specified value. " + + "New name must be unique.", SetEstateNameCommand); } public void Close() {} - + + #region CommandHandlers protected void consoleSetTerrainTexture(string module, string[] args) { string num = args[3]; @@ -248,112 +247,170 @@ namespace OpenSim.Region.CoreModules.World.Estate EstateSettings es = m_module.Scene.RegionInfo.EstateSettings; - if(args != m_ownerCmd) + if (args == m_currentCmd) { - // new command... clear out the old values - m_ownerCmd = args; - m_ownerEstates = new List(); - m_ownerAccount = null; - } + // HACK to propagate new estate info to Scene Regions + if (m_estateSettings != null && es.EstateID == m_estateSettings.EstateID) + es.EstateOwner = m_estateSettings.EstateOwner; - if (MainConsole.Instance.ConsoleScene == null) - { - if(m_ownerEstates.Contains(es.EstateID)) - { - // already checked this one - return; - } - else if(m_ownerEstates.Count > 0 && m_ownerAccount == null) - { - // lookup will have been tried and not found. - return; - } - // flag this estate, so it is not tried multiple times - m_ownerEstates.Add(es.EstateID); + return; } - else if(MainConsole.Instance.ConsoleScene != m_module.Scene) + + // new command... clear out the old value + m_currentCmd = args; + + if (args.Length == 3) { - // trying to process a single region, and this isn't it - return; + response = "No estate specified."; } - UserAccount account = null; - if(m_ownerAccount == null) + else { - if(args.Length == 3) + int estateId; + if (!int.TryParse(args[3], out estateId)) { - response = "No user specified."; + response = String.Format("\"{0}\" is not a valid ID for an Estate", args[3]); } else { - // TODO: Is there a better choice here? - UUID scopeID = UUID.Zero; - - string s1 = args[3]; - if(args.Length == 4) + if (args.Length == 4) { - // attempt to get account by UUID - UUID u; - if(UUID.TryParse(s1, out u)) + response = "No user specified."; + } + else + { + UserAccount account = null; + + // TODO: Is there a better choice here? + UUID scopeID = UUID.Zero; + + string s1 = args[4]; + if (args.Length == 5) { - account = m_module.Scene.UserAccountService.GetUserAccount(scopeID, u); - if(account == null) + // attempt to get account by UUID + UUID u; + if (UUID.TryParse(s1, out u)) + { + account = m_module.Scene.UserAccountService.GetUserAccount(scopeID, u); + if (account == null) + response = String.Format("Could not find user {0}", s1); + } + else { - response = String.Format("Could not find user {0}", s1); + response = String.Format("Invalid UUID {0}", s1); } } else { - response = String.Format("Invalid UUID {0}", s1); - account = null; + // attempt to get account by Firstname, Lastname + string s2 = args[5]; + account = m_module.Scene.UserAccountService.GetUserAccount(scopeID, s1, s2); + if (account == null) + response = String.Format("Could not find user {0} {1}", s1, s2); } - } - else - { - // attempt to get account by Firstname, Lastname - string s2 = args[4]; - account = m_module.Scene.UserAccountService.GetUserAccount(scopeID, s1, s2); - if(account == null) + + // If it's valid, send it off for processing. + if (account != null) + response = m_module.SetEstateOwner(estateId, account); + + if (response == String.Empty) + { + response = String.Format("Estate owner changed to {0} ({1} {2})", account.PrincipalID, account.FirstName, account.LastName); + + // save data for propagation to other Scene Regions + m_estateSettings = new EstateSettings(); + m_estateSettings.EstateID = (uint)estateId; + m_estateSettings.EstateOwner = account.PrincipalID; + + // update current Scene Region if appropriate + if (es.EstateID == estateId) + es.EstateOwner = account.PrincipalID; + } + else { - response = String.Format("Could not find user {0} {1}", s1, s2); + m_estateSettings = null; } } } } - else + + // give the user some feedback + if (response != null) + MainConsole.Instance.Output(response); + } + + protected void SetEstateNameCommand(string module, string[] args) + { + string response = null; + + EstateSettings es = m_module.Scene.RegionInfo.EstateSettings; + + if (args == m_currentCmd) { - account = m_ownerAccount; + // HACK to propagate new estate info to Scene Regions + if (m_estateSettings != null && es.EstateID == m_estateSettings.EstateID) + es.EstateName = m_estateSettings.EstateName; + + return; } - if(account != null) - { - if (MainConsole.Instance.ConsoleScene == null) - m_ownerAccount = account; - string choice; - do - { - // Get user confirmation, in case there are multiple estates involved (from root) - choice = MainConsole.Instance.CmdPrompt( - string.Format("Change owner of Estate {0} ({1}) [y/n]? ",es.EstateID, es.EstateName), - "Y"); + // new command... clear out the old value + m_currentCmd = args; - if("y".Equals(choice, StringComparison.OrdinalIgnoreCase)) + if (args.Length == 3) + { + response = "No estate specified."; + } + else + { + int estateId; + if (!int.TryParse(args[3], out estateId)) + { + response = String.Format("\"{0}\" is not a valid ID for an Estate", args[3]); + } + else + { + if (args.Length == 4) { - response = m_module.setEstateOwner((int)es.EstateID, account); + response = "No name specified."; } - else if(!"n".Equals(choice, StringComparison.OrdinalIgnoreCase)) + else { - MainConsole.Instance.Output("Invalid response. Please select y or n."); - choice = null; + // everything after the estate ID is "name" + StringBuilder sb = new StringBuilder(args[4]); + for (int i = 5; i < args.Length; i++) + sb.Append (" " + args[i]); + + string estateName = sb.ToString(); + + // send it off for processing. + response = m_module.SetEstateName(estateId, estateName); + + if (response == String.Empty) + { + response = String.Format("Estate {0} renamed from \"{1}\" to \"{2}\"", estateId, es.EstateName, estateName); + + // save data for propagation to other Scene Regions + m_estateSettings = new EstateSettings(); + m_estateSettings.EstateID = (uint)estateId; + m_estateSettings.EstateName = estateName; + + // update current Scene Region if appropriate + if (es.EstateID == estateId) + es.EstateName = estateName; + } + else + { + m_estateSettings = null; + } } } - while(choice == null); } - - // Give the user some feedback - if(response != null) + // give the user some feedback + if (response != null) MainConsole.Instance.Output(response); } + #endregion } } \ No newline at end of file -- cgit v1.1