From 4ea9183b66890328afb0ac97fbdd9bad064207cf Mon Sep 17 00:00:00 2001
From: Charles Krinke
Date: Sun, 8 Jun 2008 00:34:00 +0000
Subject: Mantis#1499. Thank you kindly, DMiles for a patch that: was
incorrectly sending the command along with the args to the CommandDelegate
help was getting lost on top of normal help & help was getting missed except
in an exact match (and only returning the first)
---
OpenSim/Region/Application/OpenSim.cs | 209 +++++++++++++++++++++-------------
1 file changed, 132 insertions(+), 77 deletions(-)
(limited to 'OpenSim/Region/Application')
diff --git a/OpenSim/Region/Application/OpenSim.cs b/OpenSim/Region/Application/OpenSim.cs
index 3c37e90..a903fd8 100644
--- a/OpenSim/Region/Application/OpenSim.cs
+++ b/OpenSim/Region/Application/OpenSim.cs
@@ -58,6 +58,10 @@ namespace OpenSim
private string m_timedScript = "disabled";
private Timer m_scriptTimer;
+ ///
+ /// List of Console Plugin Commands
+ ///
+ private static List m_PluginCommandInfos = new List();
public OpenSim(IConfigSource configSource) : base(configSource)
{
@@ -226,7 +230,6 @@ namespace OpenSim
break;
case "help":
- RunPluginCommandHelp(CombineParams(cmdparams, 0),m_console);
m_console.Notice("alert - send alert to a designated user or all users.");
m_console.Notice(" alert [First] [Last] [Message] - send an alert to a user. Case sensitive.");
m_console.Notice(" alert general [Message] - send an alert to all users.");
@@ -259,6 +262,7 @@ namespace OpenSim
m_console.Notice("config get section field - get a config value");
m_console.Notice("config save - save OpenSim.ini");
m_console.Notice("terrain help - show help for terrain commands.");
+ ShowPluginCommandsHelp(CombineParams(cmdparams, 0), m_console);
break;
case "threads":
@@ -673,97 +677,148 @@ namespace OpenSim
return result;
}
+ ///
+ /// Runs the best matching plugin command
+ ///
+ /// returns true if a match was found, false otherwise.
+ ///
+ public bool RunPluginCommands(string cmdWithParams)
+ {
+ ConsolePluginCommand bestMatch = null;
+ int bestLength = 0;
+ foreach (ConsolePluginCommand cmdinfo in m_PluginCommandInfos)
+ {
+ int matchLen = cmdinfo.matchLength(cmdWithParams);
+ if (matchLen > bestLength)
+ {
+ bestMatch = cmdinfo;
+ bestLength = matchLen;
+ }
+ }
+ if (bestMatch == null) return false;
+ bestMatch.Run(cmdWithParams.Substring(bestLength));
+ return true;
+ }
+
+ ///
+ /// Show the matching plugins command help
+ ///
+ public void ShowPluginCommandsHelp(string cmdWithParams, ConsoleBase console)
+ {
+ foreach (ConsolePluginCommand cmdinfo in m_PluginCommandInfos)
+ {
+ if (cmdinfo.IsHelpfull(cmdWithParams))
+ {
+ cmdinfo.ShowHelp(console);
+ }
+ }
+ }
+
+ ///
+ /// Registers a new console plugin command
+ ///
+ public static void RegisterCmd(string cmd, ConsoleCommand deligate, string help)
+ {
+ RegisterConsolePluginCommand(new ConsolePluginCommand(cmd, deligate, help));
+ }
+ ///
+ /// Registers a new console plugin command
+ ///
+ public static void RegisterConsolePluginCommand(ConsolePluginCommand pluginCommand)
+ {
+ m_PluginCommandInfos.Add(pluginCommand);
+ }
#endregion
- static private List m_PluginCommandInfos = new List();
+ }
+ ///
+ /// Holder object for a new console plugin command
+ ///
+ /// Override the methods like Run and IsHelpfull (but the defaults might work ok.)
+ ///
+ public class ConsolePluginCommand
+ {
+ ///
+ /// command delegate used in running
+ ///
+ private ConsoleCommand m_commandDelegate;
+ ///
+ /// help text displayed
+ ///
+ private string m_helpText;
+ ///
+ /// command in the form of "showme new commands"
+ ///
+ private string m_cmdText;
- public bool RunPluginCommands(string cmd)
+ ///
+ /// Construct a new ConsolePluginCommand
+ ///
+ /// for use with OpenSim.RegisterConsolePluginCommand(myCmd);
+ ///
+ ///
+ /// in the form of "showme new commands"
+ /// ommand delegate used in running
+ /// the text displayed in "help showme new commands"
+ public ConsolePluginCommand(string command, ConsoleCommand dlg, string help)
{
- ConsolePluginCommand bestMatch = null;
- int bestLength = 0;
- foreach (ConsolePluginCommand cmdinfo in m_PluginCommandInfos)
- {
- int matchLen = cmdinfo.matchLength(cmd);
- if (matchLen > bestLength)
- {
- bestMatch = cmdinfo;
- bestLength = matchLen;
- }
- }
- if (bestMatch == null)
- {
- return false;
- }
- bestMatch.Run(cmd);
- return true;
+ m_cmdText = command;
+ m_commandDelegate = dlg;
+ m_helpText = help;
}
- public bool RunPluginCommandHelp(string cmd, ConsoleBase console)
+
+ ///
+ /// Returns the match length this command has upon the 'cmdWithParams'
+ /// At least a higher number for "show plugin status" then "show" would return
+ /// This is used to have multi length command verbs
+ ///
+ /// @see OopenSim.RunPluginCommands
+ /// It will only run the one with the highest number
+ ///
+ ///
+ public int matchLength(string cmdWithParams)
{
- ConsolePluginCommand bestMatch = null;
- int bestLength = 0;
- foreach (ConsolePluginCommand cmdinfo in m_PluginCommandInfos)
+ // QUESTION: have a case insensitive flag?
+ cmdWithParams = cmdWithParams.ToLower().Trim();
+ string matchText = m_cmdText.ToLower().Trim();
+ if (cmdWithParams.StartsWith(matchText))
{
- int matchLen = cmdinfo.matchLength(cmd);
- if (matchLen > bestLength)
- {
- bestMatch = cmdinfo;
- bestLength = matchLen;
- }
+ // QUESTION Instead return cmdText.Length; ?
+ return matchText.Length;
}
- if (bestMatch == null)
- {
- return false;
- }
- bestMatch.ShowHelp(console);
- return true;
- }
- public static void RegisterCmd(string cmd, ConsoleCommand deligate, string hlp)
- {
- m_PluginCommandInfos.Add(new ConsolePluginCommand(cmd, deligate, hlp));
+ return 0;
}
- public class ConsolePluginCommand
+ ///
+ /// Run the delegate the incomming string may contain the command, if so, it is chopped off
+ ///
+ public void Run(string cmdParams)
{
- private ConsoleCommand m_commandDelegate;
- private string m_helpText;
- private string m_cmdText;
-
- public int matchLength(string targetText)
+ string targetText = m_cmdText.ToLower();
+ string matchText = cmdParams.ToLower();
+ if (targetText.StartsWith(matchText))
{
- // QUESTION: have a case insensitive flag?
- targetText = targetText.ToLower();
- string matchText = m_cmdText.ToLower();
- if (targetText.StartsWith(matchText))
- {
- // TODO return cmdText.Length; ?
- return matchText.Length;
- }
- return 0;
- }
- public ConsolePluginCommand(string cmd, ConsoleCommand del, string help)
- {
- m_cmdText = cmd;
- m_commandDelegate = del;
- m_helpText = help;
+ cmdParams = cmdParams.Substring(matchText.Length);
}
+ m_commandDelegate(cmdParams.Split(new char[] { ' ' }));
+ }
- public void Run(string incomming)
- {
- string targetText = m_cmdText.ToLower();
- string matchText = incomming.ToLower();
-
- if (targetText.StartsWith(matchText))
- {
- incomming = incomming.Substring(matchText.Length);
- }
- m_commandDelegate(incomming.Split(new char[] {' '}));
- }
+ ///
+ /// Shows help information on the console's Notice method
+ ///
+ public void ShowHelp(ConsoleBase console)
+ {
+ console.Notice(m_cmdText + " - " + m_helpText);
+ }
- public void ShowHelp(ConsoleBase console)
- {
- console.Notice(m_cmdText + ": " + m_helpText);
- // throw new Exception("The method or operation is not implemented.");
- }
+ ///
+ /// return true if the ShowHelp(..) method might be helpfull
+ ///
+ public bool IsHelpfull(string cmdWithParams)
+ {
+ cmdWithParams = cmdWithParams.ToLower();
+ return cmdWithParams.Contains(m_cmdText.ToLower()) || m_helpText.ToLower().Contains(cmdWithParams);
}
}
+
}
--
cgit v1.1