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)0.6.0-stable
parent
0e5f2b3293
commit
4ea9183b66
|
@ -58,6 +58,10 @@ namespace OpenSim
|
||||||
|
|
||||||
private string m_timedScript = "disabled";
|
private string m_timedScript = "disabled";
|
||||||
private Timer m_scriptTimer;
|
private Timer m_scriptTimer;
|
||||||
|
/// <summary>
|
||||||
|
/// List of Console Plugin Commands
|
||||||
|
/// </summary>
|
||||||
|
private static List<ConsolePluginCommand> m_PluginCommandInfos = new List<ConsolePluginCommand>();
|
||||||
|
|
||||||
public OpenSim(IConfigSource configSource) : base(configSource)
|
public OpenSim(IConfigSource configSource) : base(configSource)
|
||||||
{
|
{
|
||||||
|
@ -226,7 +230,6 @@ namespace OpenSim
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "help":
|
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 - 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 [First] [Last] [Message] - send an alert to a user. Case sensitive.");
|
||||||
m_console.Notice(" alert general [Message] - send an alert to all users.");
|
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 get section field - get a config value");
|
||||||
m_console.Notice("config save - save OpenSim.ini");
|
m_console.Notice("config save - save OpenSim.ini");
|
||||||
m_console.Notice("terrain help - show help for terrain commands.");
|
m_console.Notice("terrain help - show help for terrain commands.");
|
||||||
|
ShowPluginCommandsHelp(CombineParams(cmdparams, 0), m_console);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "threads":
|
case "threads":
|
||||||
|
@ -673,97 +677,148 @@ namespace OpenSim
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Runs the best matching plugin command
|
||||||
|
///
|
||||||
|
/// returns true if a match was found, false otherwise.
|
||||||
|
/// </summary>
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Show the matching plugins command help
|
||||||
|
/// </summary>
|
||||||
|
public void ShowPluginCommandsHelp(string cmdWithParams, ConsoleBase console)
|
||||||
|
{
|
||||||
|
foreach (ConsolePluginCommand cmdinfo in m_PluginCommandInfos)
|
||||||
|
{
|
||||||
|
if (cmdinfo.IsHelpfull(cmdWithParams))
|
||||||
|
{
|
||||||
|
cmdinfo.ShowHelp(console);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Registers a new console plugin command
|
||||||
|
/// </summary>
|
||||||
|
public static void RegisterCmd(string cmd, ConsoleCommand deligate, string help)
|
||||||
|
{
|
||||||
|
RegisterConsolePluginCommand(new ConsolePluginCommand(cmd, deligate, help));
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Registers a new console plugin command
|
||||||
|
/// </summary>
|
||||||
|
public static void RegisterConsolePluginCommand(ConsolePluginCommand pluginCommand)
|
||||||
|
{
|
||||||
|
m_PluginCommandInfos.Add(pluginCommand);
|
||||||
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
static private List<ConsolePluginCommand> m_PluginCommandInfos = new List<ConsolePluginCommand>();
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Holder object for a new console plugin command
|
||||||
|
///
|
||||||
|
/// Override the methods like Run and IsHelpfull (but the defaults might work ok.)
|
||||||
|
/// </summary>
|
||||||
|
public class ConsolePluginCommand
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// command delegate used in running
|
||||||
|
/// </summary>
|
||||||
|
private ConsoleCommand m_commandDelegate;
|
||||||
|
/// <summary>
|
||||||
|
/// help text displayed
|
||||||
|
/// </summary>
|
||||||
|
private string m_helpText;
|
||||||
|
/// <summary>
|
||||||
|
/// command in the form of "showme new commands"
|
||||||
|
/// </summary>
|
||||||
|
private string m_cmdText;
|
||||||
|
|
||||||
public bool RunPluginCommands(string cmd)
|
/// <summary>
|
||||||
|
/// Construct a new ConsolePluginCommand
|
||||||
|
///
|
||||||
|
/// for use with OpenSim.RegisterConsolePluginCommand(myCmd);
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="command">in the form of "showme new commands"</param>
|
||||||
|
/// <param name="dlg">ommand delegate used in running</param>
|
||||||
|
/// <param name="help">the text displayed in "help showme new commands"</param>
|
||||||
|
public ConsolePluginCommand(string command, ConsoleCommand dlg, string help)
|
||||||
{
|
{
|
||||||
ConsolePluginCommand bestMatch = null;
|
m_cmdText = command;
|
||||||
int bestLength = 0;
|
m_commandDelegate = dlg;
|
||||||
foreach (ConsolePluginCommand cmdinfo in m_PluginCommandInfos)
|
m_helpText = help;
|
||||||
{
|
|
||||||
int matchLen = cmdinfo.matchLength(cmd);
|
|
||||||
if (matchLen > bestLength)
|
|
||||||
{
|
|
||||||
bestMatch = cmdinfo;
|
|
||||||
bestLength = matchLen;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (bestMatch == null)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
bestMatch.Run(cmd);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
public bool RunPluginCommandHelp(string cmd, ConsoleBase console)
|
|
||||||
{
|
|
||||||
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.ShowHelp(console);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
public static void RegisterCmd(string cmd, ConsoleCommand deligate, string hlp)
|
|
||||||
{
|
|
||||||
m_PluginCommandInfos.Add(new ConsolePluginCommand(cmd, deligate, hlp));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public class ConsolePluginCommand
|
/// <summary>
|
||||||
|
/// 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
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
public int matchLength(string cmdWithParams)
|
||||||
{
|
{
|
||||||
private ConsoleCommand m_commandDelegate;
|
// QUESTION: have a case insensitive flag?
|
||||||
private string m_helpText;
|
cmdWithParams = cmdWithParams.ToLower().Trim();
|
||||||
private string m_cmdText;
|
string matchText = m_cmdText.ToLower().Trim();
|
||||||
|
if (cmdWithParams.StartsWith(matchText))
|
||||||
public int matchLength(string targetText)
|
|
||||||
{
|
{
|
||||||
// QUESTION: have a case insensitive flag?
|
// QUESTION Instead return cmdText.Length; ?
|
||||||
targetText = targetText.ToLower();
|
return matchText.Length;
|
||||||
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)
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Run the delegate the incomming string may contain the command, if so, it is chopped off
|
||||||
|
/// </summary>
|
||||||
|
public void Run(string cmdParams)
|
||||||
|
{
|
||||||
|
string targetText = m_cmdText.ToLower();
|
||||||
|
string matchText = cmdParams.ToLower();
|
||||||
|
if (targetText.StartsWith(matchText))
|
||||||
{
|
{
|
||||||
m_cmdText = cmd;
|
cmdParams = cmdParams.Substring(matchText.Length);
|
||||||
m_commandDelegate = del;
|
|
||||||
m_helpText = help;
|
|
||||||
}
|
}
|
||||||
|
m_commandDelegate(cmdParams.Split(new char[] { ' ' }));
|
||||||
|
}
|
||||||
|
|
||||||
public void Run(string incomming)
|
/// <summary>
|
||||||
{
|
/// Shows help information on the console's Notice method
|
||||||
string targetText = m_cmdText.ToLower();
|
/// </summary>
|
||||||
string matchText = incomming.ToLower();
|
public void ShowHelp(ConsoleBase console)
|
||||||
|
{
|
||||||
|
console.Notice(m_cmdText + " - " + m_helpText);
|
||||||
|
}
|
||||||
|
|
||||||
if (targetText.StartsWith(matchText))
|
/// <summary>
|
||||||
{
|
/// return true if the ShowHelp(..) method might be helpfull
|
||||||
incomming = incomming.Substring(matchText.Length);
|
/// </summary>
|
||||||
}
|
public bool IsHelpfull(string cmdWithParams)
|
||||||
m_commandDelegate(incomming.Split(new char[] {' '}));
|
{
|
||||||
}
|
cmdWithParams = cmdWithParams.ToLower();
|
||||||
|
return cmdWithParams.Contains(m_cmdText.ToLower()) || m_helpText.ToLower().Contains(cmdWithParams);
|
||||||
public void ShowHelp(ConsoleBase console)
|
|
||||||
{
|
|
||||||
console.Notice(m_cmdText + ": " + m_helpText);
|
|
||||||
// throw new Exception("The method or operation is not implemented.");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue