diff options
author | Justin Clarke Casey | 2008-07-12 19:29:49 +0000 |
---|---|---|
committer | Justin Clarke Casey | 2008-07-12 19:29:49 +0000 |
commit | 451c3d1dd7bd7fc64e741882040ae44f8c47518f (patch) | |
tree | 86d4c8a2c89d6c45ea3677b5874ed7e5688d9936 /OpenSim | |
parent | * Make archive default tar file modes more permissive (diff) | |
download | opensim-SC-451c3d1dd7bd7fc64e741882040ae44f8c47518f.zip opensim-SC-451c3d1dd7bd7fc64e741882040ae44f8c47518f.tar.gz opensim-SC-451c3d1dd7bd7fc64e741882040ae44f8c47518f.tar.bz2 opensim-SC-451c3d1dd7bd7fc64e741882040ae44f8c47518f.tar.xz |
* Hive off ConsolePluginCommand into its own framework class
Diffstat (limited to 'OpenSim')
-rw-r--r-- | OpenSim/Framework/Console/ConsolePluginCommand.cs | 139 | ||||
-rw-r--r-- | OpenSim/Region/Application/OpenSim.cs | 109 | ||||
-rw-r--r-- | OpenSim/Region/Application/OpenSimBase.cs | 1 |
3 files changed, 140 insertions, 109 deletions
diff --git a/OpenSim/Framework/Console/ConsolePluginCommand.cs b/OpenSim/Framework/Console/ConsolePluginCommand.cs new file mode 100644 index 0000000..b3f1c93 --- /dev/null +++ b/OpenSim/Framework/Console/ConsolePluginCommand.cs | |||
@@ -0,0 +1,139 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSim Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | |||
30 | namespace OpenSim.Framework.Console | ||
31 | { | ||
32 | public delegate void ConsoleCommand(string[] comParams); | ||
33 | |||
34 | /// <summary> | ||
35 | /// Holder object for a new console plugin command | ||
36 | /// | ||
37 | /// Override the methods like Run and IsHelpfull (but the defaults might work ok.) | ||
38 | /// </summary> | ||
39 | public class ConsolePluginCommand | ||
40 | { | ||
41 | /// <summary> | ||
42 | /// command delegate used in running | ||
43 | /// </summary> | ||
44 | private ConsoleCommand m_commandDelegate; | ||
45 | /// <summary> | ||
46 | /// help text displayed | ||
47 | /// </summary> | ||
48 | private string m_helpText; | ||
49 | /// <summary> | ||
50 | /// command in the form of "showme new commands" | ||
51 | /// </summary> | ||
52 | private string[] m_cmdText; | ||
53 | |||
54 | /// <summary> | ||
55 | /// Construct a new ConsolePluginCommand | ||
56 | /// | ||
57 | /// for use with OpenSim.RegisterConsolePluginCommand(myCmd); | ||
58 | /// | ||
59 | /// </summary> | ||
60 | /// <param name="command">in the form of "showme new commands"</param> | ||
61 | /// <param name="dlg">ommand delegate used in running</param> | ||
62 | /// <param name="help">the text displayed in "help showme new commands"</param> | ||
63 | public ConsolePluginCommand(string command, ConsoleCommand dlg, string help) | ||
64 | { | ||
65 | m_cmdText = command.Split(new char[] { ' ' }); | ||
66 | m_commandDelegate = dlg; | ||
67 | m_helpText = help; | ||
68 | } | ||
69 | |||
70 | /// <summary> | ||
71 | /// Returns the match length this command has upon the 'cmdWithParams' | ||
72 | /// At least a higher number for "show plugin status" then "show" would return | ||
73 | /// This is used to have multi length command verbs | ||
74 | /// | ||
75 | /// @see OopenSim.RunPluginCommands | ||
76 | /// It will only run the one with the highest number | ||
77 | /// | ||
78 | /// </summary> | ||
79 | public int matchLength(string cmdWithParams) | ||
80 | { | ||
81 | // QUESTION: have a case insensitive flag? | ||
82 | cmdWithParams = cmdWithParams.ToLower().Trim(); | ||
83 | string matchText = String.Join(" ",m_cmdText).ToLower().Trim(); | ||
84 | if (cmdWithParams.StartsWith(matchText)) | ||
85 | { | ||
86 | // QUESTION Instead return cmdText.Length; ? | ||
87 | return matchText.Length; | ||
88 | } | ||
89 | return 0; | ||
90 | } | ||
91 | |||
92 | /// <summary> | ||
93 | /// Run the delegate the incomming string may contain the command, if so, it is chopped off the cmdParams[] | ||
94 | /// </summary> | ||
95 | public void Run(string cmd, string[] cmdParams) | ||
96 | { | ||
97 | int skipParams = 0; | ||
98 | if (m_cmdText.Length > 1) | ||
99 | { | ||
100 | int currentParam = 1; | ||
101 | while (currentParam < m_cmdText.Length) | ||
102 | { | ||
103 | if (cmdParams[skipParams].ToLower().Equals(m_cmdText[currentParam].ToLower())) | ||
104 | { | ||
105 | skipParams++; | ||
106 | } | ||
107 | currentParam++; | ||
108 | } | ||
109 | |||
110 | } | ||
111 | string[] sendCmdParams = cmdParams; | ||
112 | if (skipParams > 0) | ||
113 | { | ||
114 | sendCmdParams = new string[cmdParams.Length-skipParams]; | ||
115 | for (int i=0;i<sendCmdParams.Length;i++) { | ||
116 | sendCmdParams[i] = cmdParams[skipParams++]; | ||
117 | } | ||
118 | } | ||
119 | m_commandDelegate(sendCmdParams);//.Trim().Split(new char[] { ' ' })); | ||
120 | } | ||
121 | |||
122 | /// <summary> | ||
123 | /// Shows help information on the console's Notice method | ||
124 | /// </summary> | ||
125 | public void ShowHelp(ConsoleBase console) | ||
126 | { | ||
127 | console.Notice(String.Join(" ", m_cmdText) + " - " + m_helpText); | ||
128 | } | ||
129 | |||
130 | /// <summary> | ||
131 | /// return true if the ShowHelp(..) method might be helpfull | ||
132 | /// </summary> | ||
133 | public bool IsHelpfull(string cmdWithParams) | ||
134 | { | ||
135 | cmdWithParams = cmdWithParams.ToLower(); | ||
136 | return cmdWithParams.Contains(String.Join(" ", m_cmdText).ToLower()) || m_helpText.ToLower().Contains(cmdWithParams); | ||
137 | } | ||
138 | } | ||
139 | } | ||
diff --git a/OpenSim/Region/Application/OpenSim.cs b/OpenSim/Region/Application/OpenSim.cs index 0616812..d4c7e70 100644 --- a/OpenSim/Region/Application/OpenSim.cs +++ b/OpenSim/Region/Application/OpenSim.cs | |||
@@ -44,8 +44,6 @@ using Timer=System.Timers.Timer; | |||
44 | 44 | ||
45 | namespace OpenSim | 45 | namespace OpenSim |
46 | { | 46 | { |
47 | public delegate void ConsoleCommand(string[] comParams); | ||
48 | |||
49 | /// <summary> | 47 | /// <summary> |
50 | /// Interactive OpenSim region server | 48 | /// Interactive OpenSim region server |
51 | /// </summary> | 49 | /// </summary> |
@@ -760,111 +758,4 @@ namespace OpenSim | |||
760 | } | 758 | } |
761 | #endregion | 759 | #endregion |
762 | } | 760 | } |
763 | |||
764 | /// <summary> | ||
765 | /// Holder object for a new console plugin command | ||
766 | /// | ||
767 | /// Override the methods like Run and IsHelpfull (but the defaults might work ok.) | ||
768 | /// </summary> | ||
769 | public class ConsolePluginCommand | ||
770 | { | ||
771 | /// <summary> | ||
772 | /// command delegate used in running | ||
773 | /// </summary> | ||
774 | private ConsoleCommand m_commandDelegate; | ||
775 | /// <summary> | ||
776 | /// help text displayed | ||
777 | /// </summary> | ||
778 | private string m_helpText; | ||
779 | /// <summary> | ||
780 | /// command in the form of "showme new commands" | ||
781 | /// </summary> | ||
782 | private string[] m_cmdText; | ||
783 | |||
784 | /// <summary> | ||
785 | /// Construct a new ConsolePluginCommand | ||
786 | /// | ||
787 | /// for use with OpenSim.RegisterConsolePluginCommand(myCmd); | ||
788 | /// | ||
789 | /// </summary> | ||
790 | /// <param name="command">in the form of "showme new commands"</param> | ||
791 | /// <param name="dlg">ommand delegate used in running</param> | ||
792 | /// <param name="help">the text displayed in "help showme new commands"</param> | ||
793 | public ConsolePluginCommand(string command, ConsoleCommand dlg, string help) | ||
794 | { | ||
795 | m_cmdText = command.Split(new char[] { ' ' }); | ||
796 | m_commandDelegate = dlg; | ||
797 | m_helpText = help; | ||
798 | } | ||
799 | |||
800 | /// <summary> | ||
801 | /// Returns the match length this command has upon the 'cmdWithParams' | ||
802 | /// At least a higher number for "show plugin status" then "show" would return | ||
803 | /// This is used to have multi length command verbs | ||
804 | /// | ||
805 | /// @see OopenSim.RunPluginCommands | ||
806 | /// It will only run the one with the highest number | ||
807 | /// | ||
808 | /// </summary> | ||
809 | public int matchLength(string cmdWithParams) | ||
810 | { | ||
811 | // QUESTION: have a case insensitive flag? | ||
812 | cmdWithParams = cmdWithParams.ToLower().Trim(); | ||
813 | string matchText = String.Join(" ",m_cmdText).ToLower().Trim(); | ||
814 | if (cmdWithParams.StartsWith(matchText)) | ||
815 | { | ||
816 | // QUESTION Instead return cmdText.Length; ? | ||
817 | return matchText.Length; | ||
818 | } | ||
819 | return 0; | ||
820 | } | ||
821 | |||
822 | /// <summary> | ||
823 | /// Run the delegate the incomming string may contain the command, if so, it is chopped off the cmdParams[] | ||
824 | /// </summary> | ||
825 | public void Run(string cmd, string[] cmdParams) | ||
826 | { | ||
827 | int skipParams = 0; | ||
828 | if (m_cmdText.Length > 1) | ||
829 | { | ||
830 | int currentParam = 1; | ||
831 | while (currentParam < m_cmdText.Length) | ||
832 | { | ||
833 | if (cmdParams[skipParams].ToLower().Equals(m_cmdText[currentParam].ToLower())) | ||
834 | { | ||
835 | skipParams++; | ||
836 | } | ||
837 | currentParam++; | ||
838 | } | ||
839 | |||
840 | } | ||
841 | string[] sendCmdParams = cmdParams; | ||
842 | if (skipParams > 0) | ||
843 | { | ||
844 | sendCmdParams = new string[cmdParams.Length-skipParams]; | ||
845 | for (int i=0;i<sendCmdParams.Length;i++) { | ||
846 | sendCmdParams[i] = cmdParams[skipParams++]; | ||
847 | } | ||
848 | } | ||
849 | m_commandDelegate(sendCmdParams);//.Trim().Split(new char[] { ' ' })); | ||
850 | } | ||
851 | |||
852 | /// <summary> | ||
853 | /// Shows help information on the console's Notice method | ||
854 | /// </summary> | ||
855 | public void ShowHelp(ConsoleBase console) | ||
856 | { | ||
857 | console.Notice(String.Join(" ", m_cmdText) + " - " + m_helpText); | ||
858 | } | ||
859 | |||
860 | /// <summary> | ||
861 | /// return true if the ShowHelp(..) method might be helpfull | ||
862 | /// </summary> | ||
863 | public bool IsHelpfull(string cmdWithParams) | ||
864 | { | ||
865 | cmdWithParams = cmdWithParams.ToLower(); | ||
866 | return cmdWithParams.Contains(String.Join(" ", m_cmdText).ToLower()) || m_helpText.ToLower().Contains(cmdWithParams); | ||
867 | } | ||
868 | } | ||
869 | |||
870 | } | 761 | } |
diff --git a/OpenSim/Region/Application/OpenSimBase.cs b/OpenSim/Region/Application/OpenSimBase.cs index c6061e1..c9cc062 100644 --- a/OpenSim/Region/Application/OpenSimBase.cs +++ b/OpenSim/Region/Application/OpenSimBase.cs | |||
@@ -38,6 +38,7 @@ using Mono.Addins; | |||
38 | using Nini.Config; | 38 | using Nini.Config; |
39 | using OpenSim.Framework; | 39 | using OpenSim.Framework; |
40 | using OpenSim.Framework.Communications.Cache; | 40 | using OpenSim.Framework.Communications.Cache; |
41 | using OpenSim.Framework.Console; | ||
41 | using OpenSim.Framework.Servers; | 42 | using OpenSim.Framework.Servers; |
42 | using OpenSim.Framework.Statistics; | 43 | using OpenSim.Framework.Statistics; |
43 | using OpenSim.Region.ClientStack; | 44 | using OpenSim.Region.ClientStack; |