diff options
-rw-r--r-- | OpenSim/Region/Application/OpenSim.cs | 209 |
1 files changed, 132 insertions, 77 deletions
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 | |||
58 | 58 | ||
59 | private string m_timedScript = "disabled"; | 59 | private string m_timedScript = "disabled"; |
60 | private Timer m_scriptTimer; | 60 | private Timer m_scriptTimer; |
61 | /// <summary> | ||
62 | /// List of Console Plugin Commands | ||
63 | /// </summary> | ||
64 | private static List<ConsolePluginCommand> m_PluginCommandInfos = new List<ConsolePluginCommand>(); | ||
61 | 65 | ||
62 | public OpenSim(IConfigSource configSource) : base(configSource) | 66 | public OpenSim(IConfigSource configSource) : base(configSource) |
63 | { | 67 | { |
@@ -226,7 +230,6 @@ namespace OpenSim | |||
226 | break; | 230 | break; |
227 | 231 | ||
228 | case "help": | 232 | case "help": |
229 | RunPluginCommandHelp(CombineParams(cmdparams, 0),m_console); | ||
230 | m_console.Notice("alert - send alert to a designated user or all users."); | 233 | m_console.Notice("alert - send alert to a designated user or all users."); |
231 | m_console.Notice(" alert [First] [Last] [Message] - send an alert to a user. Case sensitive."); | 234 | m_console.Notice(" alert [First] [Last] [Message] - send an alert to a user. Case sensitive."); |
232 | m_console.Notice(" alert general [Message] - send an alert to all users."); | 235 | m_console.Notice(" alert general [Message] - send an alert to all users."); |
@@ -259,6 +262,7 @@ namespace OpenSim | |||
259 | m_console.Notice("config get section field - get a config value"); | 262 | m_console.Notice("config get section field - get a config value"); |
260 | m_console.Notice("config save - save OpenSim.ini"); | 263 | m_console.Notice("config save - save OpenSim.ini"); |
261 | m_console.Notice("terrain help - show help for terrain commands."); | 264 | m_console.Notice("terrain help - show help for terrain commands."); |
265 | ShowPluginCommandsHelp(CombineParams(cmdparams, 0), m_console); | ||
262 | break; | 266 | break; |
263 | 267 | ||
264 | case "threads": | 268 | case "threads": |
@@ -673,97 +677,148 @@ namespace OpenSim | |||
673 | return result; | 677 | return result; |
674 | } | 678 | } |
675 | 679 | ||
680 | /// <summary> | ||
681 | /// Runs the best matching plugin command | ||
682 | /// | ||
683 | /// returns true if a match was found, false otherwise. | ||
684 | /// </summary> | ||
685 | public bool RunPluginCommands(string cmdWithParams) | ||
686 | { | ||
687 | ConsolePluginCommand bestMatch = null; | ||
688 | int bestLength = 0; | ||
689 | foreach (ConsolePluginCommand cmdinfo in m_PluginCommandInfos) | ||
690 | { | ||
691 | int matchLen = cmdinfo.matchLength(cmdWithParams); | ||
692 | if (matchLen > bestLength) | ||
693 | { | ||
694 | bestMatch = cmdinfo; | ||
695 | bestLength = matchLen; | ||
696 | } | ||
697 | } | ||
698 | if (bestMatch == null) return false; | ||
699 | bestMatch.Run(cmdWithParams.Substring(bestLength)); | ||
700 | return true; | ||
701 | } | ||
702 | |||
703 | /// <summary> | ||
704 | /// Show the matching plugins command help | ||
705 | /// </summary> | ||
706 | public void ShowPluginCommandsHelp(string cmdWithParams, ConsoleBase console) | ||
707 | { | ||
708 | foreach (ConsolePluginCommand cmdinfo in m_PluginCommandInfos) | ||
709 | { | ||
710 | if (cmdinfo.IsHelpfull(cmdWithParams)) | ||
711 | { | ||
712 | cmdinfo.ShowHelp(console); | ||
713 | } | ||
714 | } | ||
715 | } | ||
716 | |||
717 | /// <summary> | ||
718 | /// Registers a new console plugin command | ||
719 | /// </summary> | ||
720 | public static void RegisterCmd(string cmd, ConsoleCommand deligate, string help) | ||
721 | { | ||
722 | RegisterConsolePluginCommand(new ConsolePluginCommand(cmd, deligate, help)); | ||
723 | } | ||
724 | /// <summary> | ||
725 | /// Registers a new console plugin command | ||
726 | /// </summary> | ||
727 | public static void RegisterConsolePluginCommand(ConsolePluginCommand pluginCommand) | ||
728 | { | ||
729 | m_PluginCommandInfos.Add(pluginCommand); | ||
730 | } | ||
676 | #endregion | 731 | #endregion |
677 | 732 | ||
678 | static private List<ConsolePluginCommand> m_PluginCommandInfos = new List<ConsolePluginCommand>(); | 733 | } |
734 | /// <summary> | ||
735 | /// Holder object for a new console plugin command | ||
736 | /// | ||
737 | /// Override the methods like Run and IsHelpfull (but the defaults might work ok.) | ||
738 | /// </summary> | ||
739 | public class ConsolePluginCommand | ||
740 | { | ||
741 | /// <summary> | ||
742 | /// command delegate used in running | ||
743 | /// </summary> | ||
744 | private ConsoleCommand m_commandDelegate; | ||
745 | /// <summary> | ||
746 | /// help text displayed | ||
747 | /// </summary> | ||
748 | private string m_helpText; | ||
749 | /// <summary> | ||
750 | /// command in the form of "showme new commands" | ||
751 | /// </summary> | ||
752 | private string m_cmdText; | ||
679 | 753 | ||
680 | public bool RunPluginCommands(string cmd) | 754 | /// <summary> |
755 | /// Construct a new ConsolePluginCommand | ||
756 | /// | ||
757 | /// for use with OpenSim.RegisterConsolePluginCommand(myCmd); | ||
758 | /// | ||
759 | /// </summary> | ||
760 | /// <param name="command">in the form of "showme new commands"</param> | ||
761 | /// <param name="dlg">ommand delegate used in running</param> | ||
762 | /// <param name="help">the text displayed in "help showme new commands"</param> | ||
763 | public ConsolePluginCommand(string command, ConsoleCommand dlg, string help) | ||
681 | { | 764 | { |
682 | ConsolePluginCommand bestMatch = null; | 765 | m_cmdText = command; |
683 | int bestLength = 0; | 766 | m_commandDelegate = dlg; |
684 | foreach (ConsolePluginCommand cmdinfo in m_PluginCommandInfos) | 767 | m_helpText = help; |
685 | { | ||
686 | int matchLen = cmdinfo.matchLength(cmd); | ||
687 | if (matchLen > bestLength) | ||
688 | { | ||
689 | bestMatch = cmdinfo; | ||
690 | bestLength = matchLen; | ||
691 | } | ||
692 | } | ||
693 | if (bestMatch == null) | ||
694 | { | ||
695 | return false; | ||
696 | } | ||
697 | bestMatch.Run(cmd); | ||
698 | return true; | ||
699 | } | 768 | } |
700 | public bool RunPluginCommandHelp(string cmd, ConsoleBase console) | 769 | |
770 | /// <summary> | ||
771 | /// Returns the match length this command has upon the 'cmdWithParams' | ||
772 | /// At least a higher number for "show plugin status" then "show" would return | ||
773 | /// This is used to have multi length command verbs | ||
774 | /// | ||
775 | /// @see OopenSim.RunPluginCommands | ||
776 | /// It will only run the one with the highest number | ||
777 | /// | ||
778 | /// </summary> | ||
779 | public int matchLength(string cmdWithParams) | ||
701 | { | 780 | { |
702 | ConsolePluginCommand bestMatch = null; | 781 | // QUESTION: have a case insensitive flag? |
703 | int bestLength = 0; | 782 | cmdWithParams = cmdWithParams.ToLower().Trim(); |
704 | foreach (ConsolePluginCommand cmdinfo in m_PluginCommandInfos) | 783 | string matchText = m_cmdText.ToLower().Trim(); |
784 | if (cmdWithParams.StartsWith(matchText)) | ||
705 | { | 785 | { |
706 | int matchLen = cmdinfo.matchLength(cmd); | 786 | // QUESTION Instead return cmdText.Length; ? |
707 | if (matchLen > bestLength) | 787 | return matchText.Length; |
708 | { | ||
709 | bestMatch = cmdinfo; | ||
710 | bestLength = matchLen; | ||
711 | } | ||
712 | } | 788 | } |
713 | if (bestMatch == null) | 789 | return 0; |
714 | { | ||
715 | return false; | ||
716 | } | ||
717 | bestMatch.ShowHelp(console); | ||
718 | return true; | ||
719 | } | ||
720 | public static void RegisterCmd(string cmd, ConsoleCommand deligate, string hlp) | ||
721 | { | ||
722 | m_PluginCommandInfos.Add(new ConsolePluginCommand(cmd, deligate, hlp)); | ||
723 | } | 790 | } |
724 | 791 | ||
725 | public class ConsolePluginCommand | 792 | /// <summary> |
793 | /// Run the delegate the incomming string may contain the command, if so, it is chopped off | ||
794 | /// </summary> | ||
795 | public void Run(string cmdParams) | ||
726 | { | 796 | { |
727 | private ConsoleCommand m_commandDelegate; | 797 | string targetText = m_cmdText.ToLower(); |
728 | private string m_helpText; | 798 | string matchText = cmdParams.ToLower(); |
729 | private string m_cmdText; | 799 | if (targetText.StartsWith(matchText)) |
730 | |||
731 | public int matchLength(string targetText) | ||
732 | { | 800 | { |
733 | // QUESTION: have a case insensitive flag? | 801 | cmdParams = cmdParams.Substring(matchText.Length); |
734 | targetText = targetText.ToLower(); | ||
735 | string matchText = m_cmdText.ToLower(); | ||
736 | if (targetText.StartsWith(matchText)) | ||
737 | { | ||
738 | // TODO return cmdText.Length; ? | ||
739 | return matchText.Length; | ||
740 | } | ||
741 | return 0; | ||
742 | } | ||
743 | public ConsolePluginCommand(string cmd, ConsoleCommand del, string help) | ||
744 | { | ||
745 | m_cmdText = cmd; | ||
746 | m_commandDelegate = del; | ||
747 | m_helpText = help; | ||
748 | } | 802 | } |
803 | m_commandDelegate(cmdParams.Split(new char[] { ' ' })); | ||
804 | } | ||
749 | 805 | ||
750 | public void Run(string incomming) | 806 | /// <summary> |
751 | { | 807 | /// Shows help information on the console's Notice method |
752 | string targetText = m_cmdText.ToLower(); | 808 | /// </summary> |
753 | string matchText = incomming.ToLower(); | 809 | public void ShowHelp(ConsoleBase console) |
754 | 810 | { | |
755 | if (targetText.StartsWith(matchText)) | 811 | console.Notice(m_cmdText + " - " + m_helpText); |
756 | { | 812 | } |
757 | incomming = incomming.Substring(matchText.Length); | ||
758 | } | ||
759 | m_commandDelegate(incomming.Split(new char[] {' '})); | ||
760 | } | ||
761 | 813 | ||
762 | public void ShowHelp(ConsoleBase console) | 814 | /// <summary> |
763 | { | 815 | /// return true if the ShowHelp(..) method might be helpfull |
764 | console.Notice(m_cmdText + ": " + m_helpText); | 816 | /// </summary> |
765 | // throw new Exception("The method or operation is not implemented."); | 817 | public bool IsHelpfull(string cmdWithParams) |
766 | } | 818 | { |
819 | cmdWithParams = cmdWithParams.ToLower(); | ||
820 | return cmdWithParams.Contains(m_cmdText.ToLower()) || m_helpText.ToLower().Contains(cmdWithParams); | ||
767 | } | 821 | } |
768 | } | 822 | } |
823 | |||
769 | } | 824 | } |