From 635f3f77abcc159ceb2848496a34efdcd8b296a9 Mon Sep 17 00:00:00 2001 From: Dev Random Date: Fri, 28 Mar 2014 21:41:09 -0400 Subject: Console command to change Estate owner Signed-off-by: Michael Cerquoni --- .../World/Estate/EstateManagementCommands.cs | 135 ++++++++++++++++++++- .../World/Estate/EstateManagementModule.cs | 25 ++++ 2 files changed, 157 insertions(+), 3 deletions(-) diff --git a/OpenSim/Region/CoreModules/World/Estate/EstateManagementCommands.cs b/OpenSim/Region/CoreModules/World/Estate/EstateManagementCommands.cs index 1659493..59dd3bb 100644 --- a/OpenSim/Region/CoreModules/World/Estate/EstateManagementCommands.cs +++ b/OpenSim/Region/CoreModules/World/Estate/EstateManagementCommands.cs @@ -39,6 +39,7 @@ using OpenSim.Framework.Console; using OpenSim.Region.CoreModules.Framework.InterfaceCommander; using OpenSim.Region.Framework.Interfaces; using OpenSim.Region.Framework.Scenes; +using OpenSim.Services.Interfaces; namespace OpenSim.Region.CoreModules.World.Estate { @@ -50,9 +51,18 @@ namespace OpenSim.Region.CoreModules.World.Estate private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); protected EstateManagementModule m_module; - + 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; + public EstateManagementCommands(EstateManagementModule module) { m_module = module; @@ -85,7 +95,12 @@ namespace OpenSim.Region.CoreModules.World.Estate 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); + } public void Close() {} @@ -226,5 +241,119 @@ namespace OpenSim.Region.CoreModules.World.Estate MainConsole.Instance.Output(report.ToString()); } + + protected void SetEstateOwnerCommand(string module, string[] args) + { + string response = null; + + EstateSettings es = m_module.Scene.RegionInfo.EstateSettings; + + if(args != m_ownerCmd) + { + // new command... clear out the old values + m_ownerCmd = args; + m_ownerEstates = new List(); + m_ownerAccount = null; + } + + 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); + } + else if(MainConsole.Instance.ConsoleScene != m_module.Scene) + { + // trying to process a single region, and this isn't it + return; + } + UserAccount account = null; + if(m_ownerAccount == null) + { + if(args.Length == 3) + { + response = "No user specified."; + } + else + { + // TODO: Is there a better choice here? + UUID scopeID = UUID.Zero; + + string s1 = args[3]; + if(args.Length == 4) + { + // 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("Invalid UUID {0}", s1); + account = null; + } + } + else + { + // attempt to get account by Firstname, Lastname + string s2 = args[4]; + account = m_module.Scene.UserAccountService.GetUserAccount(scopeID, s1, s2); + if(account == null) + { + response = String.Format("Could not find user {0} {1}", s1, s2); + } + } + } + } + else + { + account = m_ownerAccount; + } + 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"); + + if("y".Equals(choice, StringComparison.OrdinalIgnoreCase)) + { + response = m_module.setEstateOwner((int)es.EstateID, account); + } + else if(!"n".Equals(choice, StringComparison.OrdinalIgnoreCase)) + { + MainConsole.Instance.Output("Invalid response. Please select y or n."); + choice = null; + } + } + while(choice == null); + } + + + // Give the user some feedback + if(response != null) + MainConsole.Instance.Output(response); + } + } } \ No newline at end of file diff --git a/OpenSim/Region/CoreModules/World/Estate/EstateManagementModule.cs b/OpenSim/Region/CoreModules/World/Estate/EstateManagementModule.cs index cb9ad4a..9e6d0fc 100644 --- a/OpenSim/Region/CoreModules/World/Estate/EstateManagementModule.cs +++ b/OpenSim/Region/CoreModules/World/Estate/EstateManagementModule.cs @@ -40,6 +40,7 @@ using OpenMetaverse; using OpenSim.Framework; using OpenSim.Region.Framework.Interfaces; using OpenSim.Region.Framework.Scenes; +using OpenSim.Services.Interfaces; using RegionFlags = OpenMetaverse.RegionFlags; namespace OpenSim.Region.CoreModules.World.Estate @@ -1202,6 +1203,30 @@ namespace OpenSim.Region.CoreModules.World.Estate sendRegionInfoPacketToAll(); } + public string setEstateOwner(int estateID, UserAccount account) + { + string response; + + // get the current settings from DB + EstateSettings dbSettings = Scene.EstateDataService.LoadEstateSettings(estateID); + if(account.PrincipalID != dbSettings.EstateOwner) { + dbSettings.EstateOwner = account.PrincipalID; + dbSettings.Save(); + response = String.Format("Estate owner changed to {0} ({1} {2})", account.PrincipalID, account.FirstName, account.LastName); + + // make sure there's a log entry to document the change + m_log.InfoFormat("[ESTATE]: Estate Owner for {0} changed to {1} ({2} {3})", dbSettings.EstateName, + account.PrincipalID, account.FirstName, account.LastName); + + TriggerEstateInfoChange(); + } + else + { + response = String.Format("Estate already belongs to {0} ({1} {2})", account.PrincipalID, account.FirstName, account.LastName); + } + return response; + } + #endregion private void EventManager_OnNewClient(IClientAPI client) -- cgit v1.1