From 54c6a920baa0ef02a9ea09e08cc1effcef3b0a3a Mon Sep 17 00:00:00 2001 From: Melanie Thielker Date: Sat, 7 Feb 2009 12:25:39 +0000 Subject: Replace the console for all OpenSim apps with a new console featuring command line editing, context sensitive help (press ? at any time), command line history, a new plugin command system and new appender features thet let you type while the console is scrolling. Seamlessly integrates the ICommander interfaces. --- .../Framework/InterfaceCommander/Command.cs | 12 ++ .../Modules/World/Permissions/PermissionsModule.cs | 148 +++++++++++---------- 2 files changed, 93 insertions(+), 67 deletions(-) (limited to 'OpenSim/Region/Environment') diff --git a/OpenSim/Region/Environment/Modules/Framework/InterfaceCommander/Command.cs b/OpenSim/Region/Environment/Modules/Framework/InterfaceCommander/Command.cs index 0ad95ae..b6114e8 100644 --- a/OpenSim/Region/Environment/Modules/Framework/InterfaceCommander/Command.cs +++ b/OpenSim/Region/Environment/Modules/Framework/InterfaceCommander/Command.cs @@ -88,6 +88,18 @@ namespace OpenSim.Region.Environment.Modules.Framework.InterfaceCommander } } + public string ShortHelp() + { + string help = m_name; + + foreach (CommandArgument arg in m_args) + { + help += " <" + arg.Name + ">"; + } + + return help; + } + public void ShowConsoleHelp() { Console.WriteLine("== " + Name + " =="); diff --git a/OpenSim/Region/Environment/Modules/World/Permissions/PermissionsModule.cs b/OpenSim/Region/Environment/Modules/World/Permissions/PermissionsModule.cs index 060a4f4..e48ef13 100644 --- a/OpenSim/Region/Environment/Modules/World/Permissions/PermissionsModule.cs +++ b/OpenSim/Region/Environment/Modules/World/Permissions/PermissionsModule.cs @@ -32,21 +32,20 @@ using System.Collections; using System.Collections.Generic; using System.Reflection; using log4net; +using OpenSim; using OpenSim.Framework; using OpenSim.Region.Framework.Interfaces; using OpenSim.Region.Framework.Scenes; using OpenSim.Region.Environment.Modules.Framework; -using OpenSim.Region.Environment.Modules.Framework.InterfaceCommander; using OpenSim.Framework.Communications.Cache; namespace OpenSim.Region.Environment.Modules.World.Permissions { - public class PermissionsModule : IRegionModule, ICommandableModule + public class PermissionsModule : IRegionModule { private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); protected Scene m_scene; - private readonly Commander m_commander = new Commander("permissions"); #region Constants // These are here for testing. They will be taken out @@ -94,60 +93,6 @@ namespace OpenSim.Region.Environment.Modules.World.Permissions #endregion - #region ICommandableModule Members - - public ICommander CommandInterface - { - get { throw new System.NotImplementedException(); } - } - - private void InterfaceDebugPermissions(Object[] args) - { - if ((bool)args[0] == true) - { - m_debugPermissions = true; - m_log.Info("[PERMISSIONS]: Permissions Debugging Enabled."); - } - else - { - m_debugPermissions = false; - m_log.Info("[PERMISSIONS]: Permissions Debugging Disabled."); - } - } - - private void InterfaceBypassPermissions(Object[] args) - { - if ((bool)args[0] == true) - { - m_log.Info("[PERMISSIONS]: Permissions Bypass Enabled."); - m_bypassPermissionsValue = (bool)args[1]; - } - else - { - m_bypassPermissions = false; - m_log.Info("[PERMISSIONS]: Permissions Bypass Disabled. Normal Operation."); - } - } - - /// - /// Processes commandline input. Do not call directly. - /// - /// Commandline arguments - private void EventManager_OnPluginConsole(string[] args) - { - if (args[0] == "permissions") - { - string[] tmpArgs = new string[args.Length - 2]; - int i; - for (i = 2; i < args.Length; i++) - tmpArgs[i - 2] = args[i]; - - m_commander.ProcessConsoleCommand(args[1], tmpArgs); - } - } - - #endregion - #region IRegionModule Members public void Initialise(Scene scene, IConfigSource config) @@ -226,20 +171,89 @@ namespace OpenSim.Region.Environment.Modules.World.Permissions m_scene.Permissions.AddCanTeleportHandler(CanTeleport); //NOT YET IMPLEMENTED - //Register Debug Commands - Command bypassCommand = new Command("bypass", CommandIntentions.COMMAND_HAZARDOUS, InterfaceBypassPermissions, "Force the permissions a specific way to test permissions"); - bypassCommand.AddArgument("enable_bypass_perms", "true to enable bypassing all perms", "Boolean"); - bypassCommand.AddArgument("bypass_perms_value", "true/false: true will ignore all perms; false will restrict everything", "Boolean"); + m_scene.AddCommand("permissions", "bypass permissions", + "bypass permissions ", + "Bypass permission checks", + HandleBypassPermissions); + + m_scene.AddCommand("permissions", "force permissions", + "force permissions ", + "Force permissions on or off", + HandleForcePermissions); + + m_scene.AddCommand("permissions", "debug permissions", + "debug permissions ", + "Enable permissions debugging", + HandleDebugPermissions); + } + + public void HandleBypassPermissions(string module, string[] args) + { + if (m_scene.ConsoleScene() != null && + m_scene.ConsoleScene() != m_scene) + { + return; + } + + if (args.Length > 2) + { + bool val; + + if (!bool.TryParse(args[2], out val)) + return; + + m_bypassPermissions = val; + + m_log.InfoFormat("[PERMISSIONS] Set permissions bypass to {0} for {1}", m_bypassPermissions, m_scene.RegionInfo.RegionName); + } + } + + public void HandleForcePermissions(string module, string[] args) + { + if (m_scene.ConsoleScene() != null && + m_scene.ConsoleScene() != m_scene) + { + return; + } + + if (!m_bypassPermissions) + { + m_log.Error("[PERMISSIONS] Permissions can't be forced unless they are bypassed first"); + return; + } - m_commander.RegisterCommand("bypass", bypassCommand); + if (args.Length > 2) + { + bool val; - Command debugCommand = new Command("debug", CommandIntentions.COMMAND_STATISTICAL, InterfaceDebugPermissions, "Force the permissions a specific way to test permissions"); - debugCommand.AddArgument("enable_debug_perms", "true to enable debugging to console all perms", "Boolean"); + if (!bool.TryParse(args[2], out val)) + return; - m_commander.RegisterCommand("debug", debugCommand); - m_scene.RegisterModuleCommander(m_commander); + m_bypassPermissionsValue = val; - m_scene.EventManager.OnPluginConsole += new EventManager.OnPluginConsoleDelegate(EventManager_OnPluginConsole); + m_log.InfoFormat("[PERMISSIONS] Forced permissions to {0} in {1}", m_bypassPermissionsValue, m_scene.RegionInfo.RegionName); + } + } + + public void HandleDebugPermissions(string module, string[] args) + { + if (m_scene.ConsoleScene() != null && + m_scene.ConsoleScene() != m_scene) + { + return; + } + + if (args.Length > 2) + { + bool val; + + if (!bool.TryParse(args[2], out val)) + return; + + m_debugPermissions = val; + + m_log.InfoFormat("[PERMISSIONS] Set permissions debugging to {0} in {1}", m_debugPermissions, m_scene.RegionInfo.RegionName); + } } public void PostInitialise() -- cgit v1.1