diff options
Diffstat (limited to 'OpenSim/Server/Base/CommandManager.cs')
-rw-r--r-- | OpenSim/Server/Base/CommandManager.cs | 353 |
1 files changed, 353 insertions, 0 deletions
diff --git a/OpenSim/Server/Base/CommandManager.cs b/OpenSim/Server/Base/CommandManager.cs new file mode 100644 index 0000000..45652b3 --- /dev/null +++ b/OpenSim/Server/Base/CommandManager.cs | |||
@@ -0,0 +1,353 @@ | |||
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 OpenSimulator 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 | |||
29 | using System; | ||
30 | using System.Text; | ||
31 | using System.Linq; | ||
32 | using System.Collections; | ||
33 | using System.Collections.Generic; | ||
34 | using System.Collections.ObjectModel; | ||
35 | using Mono.Addins; | ||
36 | using Mono.Addins.Setup; | ||
37 | using Mono.Addins.Description; | ||
38 | using OpenSim.Framework; | ||
39 | |||
40 | namespace OpenSim.Server.Base | ||
41 | { | ||
42 | public class CommandManager | ||
43 | { | ||
44 | protected AddinRegistry PluginRegistry; | ||
45 | protected PluginManager PluginManager; | ||
46 | |||
47 | public CommandManager(AddinRegistry registry) | ||
48 | { | ||
49 | PluginRegistry = registry; | ||
50 | PluginManager = new PluginManager(PluginRegistry); | ||
51 | AddManagementCommands(); | ||
52 | } | ||
53 | |||
54 | private void AddManagementCommands() | ||
55 | { | ||
56 | // add plugin | ||
57 | MainConsole.Instance.Commands.AddCommand("Plugin", true, | ||
58 | "plugin add", "plugin add \"plugin index\"", | ||
59 | "Install plugin from repository.", | ||
60 | HandleConsoleInstallPlugin); | ||
61 | |||
62 | // remove plugin | ||
63 | MainConsole.Instance.Commands.AddCommand("Plugin", true, | ||
64 | "plugin remove", "plugin remove \"plugin index\"", | ||
65 | "Remove plugin from repository", | ||
66 | HandleConsoleUnInstallPlugin); | ||
67 | |||
68 | // list installed plugins | ||
69 | MainConsole.Instance.Commands.AddCommand("Plugin", true, | ||
70 | "plugin list installed", | ||
71 | "plugin list installed","List install plugins", | ||
72 | HandleConsoleListInstalledPlugin); | ||
73 | |||
74 | // list plugins available from registered repositories | ||
75 | MainConsole.Instance.Commands.AddCommand("Plugin", true, | ||
76 | "plugin list available", | ||
77 | "plugin list available","List available plugins", | ||
78 | HandleConsoleListAvailablePlugin); | ||
79 | // List available updates | ||
80 | MainConsole.Instance.Commands.AddCommand("Plugin", true, | ||
81 | "plugin updates", "plugin updates","List availble updates", | ||
82 | HandleConsoleListUpdates); | ||
83 | |||
84 | // Update plugin | ||
85 | MainConsole.Instance.Commands.AddCommand("Plugin", true, | ||
86 | "plugin update", "plugin update \"plugin index\"","Update the plugin", | ||
87 | HandleConsoleUpdatePlugin); | ||
88 | |||
89 | // Add repository | ||
90 | MainConsole.Instance.Commands.AddCommand("Repository", true, | ||
91 | "repo add", "repo add \"url\"","Add repository", | ||
92 | HandleConsoleAddRepo); | ||
93 | |||
94 | // Refresh repo | ||
95 | MainConsole.Instance.Commands.AddCommand("Repository", true, | ||
96 | "repo refresh", "repo refresh \"url\"", "Sync with a registered repository", | ||
97 | HandleConsoleGetRepo); | ||
98 | |||
99 | // Remove repository from registry | ||
100 | MainConsole.Instance.Commands.AddCommand("Repository", true, | ||
101 | "repo remove", | ||
102 | "repo remove \"[url | index]\"", | ||
103 | "Remove repository from registry", | ||
104 | HandleConsoleRemoveRepo); | ||
105 | |||
106 | // Enable repo | ||
107 | MainConsole.Instance.Commands.AddCommand("Repository", true, | ||
108 | "repo enable", "repo enable \"[url | index]\"", | ||
109 | "Enable registered repository", | ||
110 | HandleConsoleEnableRepo); | ||
111 | |||
112 | // Disable repo | ||
113 | MainConsole.Instance.Commands.AddCommand("Repository", true, | ||
114 | "repo disable", "repo disable\"[url | index]\"", | ||
115 | "Disable registered repository", | ||
116 | HandleConsoleDisableRepo); | ||
117 | |||
118 | // List registered repositories | ||
119 | MainConsole.Instance.Commands.AddCommand("Repository", true, | ||
120 | "repo list", "repo list", | ||
121 | "List registered repositories", | ||
122 | HandleConsoleListRepos); | ||
123 | |||
124 | // * | ||
125 | MainConsole.Instance.Commands.AddCommand("Plugin", true, | ||
126 | "plugin info", "plugin info \"plugin index\"","Show detailed information for plugin", | ||
127 | HandleConsoleShowAddinInfo); | ||
128 | |||
129 | // Plugin disable | ||
130 | MainConsole.Instance.Commands.AddCommand("Plugin", true, | ||
131 | "plugin disable", "plugin disable \"plugin index\"", | ||
132 | "Disable a plugin", | ||
133 | HandleConsoleDisablePlugin); | ||
134 | |||
135 | // Enable plugin | ||
136 | MainConsole.Instance.Commands.AddCommand("Plugin", true, | ||
137 | "plugin enable", "plugin enable \"plugin index\"", | ||
138 | "Enable the selected plugin plugin", | ||
139 | HandleConsoleEnablePlugin); | ||
140 | } | ||
141 | |||
142 | #region console handlers | ||
143 | // Handle our console commands | ||
144 | // | ||
145 | // Install plugin from registered repository | ||
146 | /// <summary> | ||
147 | /// Handles the console install plugin command. Attempts to install the selected plugin | ||
148 | /// and | ||
149 | /// </summary> | ||
150 | /// <param name='module'> | ||
151 | /// Module. | ||
152 | /// </param> | ||
153 | /// <param name='cmd'> | ||
154 | /// Cmd. | ||
155 | /// </param> | ||
156 | private void HandleConsoleInstallPlugin(string module, string[] cmd) | ||
157 | { | ||
158 | Dictionary<string, object> result = new Dictionary<string, object>(); | ||
159 | |||
160 | if (cmd.Length == 3) | ||
161 | { | ||
162 | int ndx = Convert.ToInt16(cmd[2]); | ||
163 | if (PluginManager.InstallPlugin(ndx, out result) == true) | ||
164 | { | ||
165 | ArrayList s = new ArrayList(); | ||
166 | s.AddRange(result.Keys); | ||
167 | s.Sort(); | ||
168 | |||
169 | var list = result.Keys.ToList(); | ||
170 | list.Sort(); | ||
171 | foreach (var k in list) | ||
172 | { | ||
173 | Dictionary<string, object> plugin = (Dictionary<string, object>)result[k]; | ||
174 | bool enabled = (bool)plugin["enabled"]; | ||
175 | MainConsole.Instance.OutputFormat("{0}) {1} {2} rev. {3}", | ||
176 | k, | ||
177 | enabled == true ? "[ ]" : "[X]", | ||
178 | plugin["name"], plugin["version"]); | ||
179 | } | ||
180 | } | ||
181 | } | ||
182 | return; | ||
183 | } | ||
184 | |||
185 | // Remove installed plugin | ||
186 | private void HandleConsoleUnInstallPlugin(string module, string[] cmd) | ||
187 | { | ||
188 | if (cmd.Length == 3) | ||
189 | { | ||
190 | int ndx = Convert.ToInt16(cmd[2]); | ||
191 | PluginManager.UnInstall(ndx); | ||
192 | } | ||
193 | return; | ||
194 | } | ||
195 | |||
196 | // List installed plugins | ||
197 | private void HandleConsoleListInstalledPlugin(string module, string[] cmd) | ||
198 | { | ||
199 | Dictionary<string, object> result = new Dictionary<string, object>(); | ||
200 | PluginManager.ListInstalledAddins(out result); | ||
201 | |||
202 | ArrayList s = new ArrayList(); | ||
203 | s.AddRange(result.Keys); | ||
204 | s.Sort(); | ||
205 | |||
206 | var list = result.Keys.ToList(); | ||
207 | list.Sort(); | ||
208 | foreach (var k in list) | ||
209 | { | ||
210 | Dictionary<string, object> plugin = (Dictionary<string, object>)result[k]; | ||
211 | bool enabled = (bool)plugin["enabled"]; | ||
212 | MainConsole.Instance.OutputFormat("{0}) {1} {2} rev. {3}", | ||
213 | k, | ||
214 | enabled == true ? "[ ]" : "[X]", | ||
215 | plugin["name"], plugin["version"]); | ||
216 | } | ||
217 | return; | ||
218 | } | ||
219 | |||
220 | // List available plugins on registered repositories | ||
221 | private void HandleConsoleListAvailablePlugin(string module, string[] cmd) | ||
222 | { | ||
223 | Dictionary<string, object> result = new Dictionary<string, object>(); | ||
224 | PluginManager.ListAvailable(out result); | ||
225 | |||
226 | var list = result.Keys.ToList(); | ||
227 | list.Sort(); | ||
228 | foreach (var k in list) | ||
229 | { | ||
230 | // name, version, repository | ||
231 | Dictionary<string, object> plugin = (Dictionary<string, object>)result[k]; | ||
232 | MainConsole.Instance.OutputFormat("{0}) {1} rev. {2} {3}", | ||
233 | k, | ||
234 | plugin["name"], | ||
235 | plugin["version"], | ||
236 | plugin["repository"]); | ||
237 | } | ||
238 | return; | ||
239 | } | ||
240 | |||
241 | // List available updates **not ready | ||
242 | private void HandleConsoleListUpdates(string module, string[] cmd) | ||
243 | { | ||
244 | PluginManager.ListUpdates(); | ||
245 | return; | ||
246 | } | ||
247 | |||
248 | // Update plugin **not ready | ||
249 | private void HandleConsoleUpdatePlugin(string module, string[] cmd) | ||
250 | { | ||
251 | MainConsole.Instance.Output(PluginManager.Update()); | ||
252 | return; | ||
253 | } | ||
254 | |||
255 | // Register repository | ||
256 | private void HandleConsoleAddRepo(string module, string[] cmd) | ||
257 | { | ||
258 | if ( cmd.Length == 3) | ||
259 | { | ||
260 | PluginManager.AddRepository(cmd[2]); | ||
261 | } | ||
262 | return; | ||
263 | } | ||
264 | |||
265 | // Get repository status **not working | ||
266 | private void HandleConsoleGetRepo(string module, string[] cmd) | ||
267 | { | ||
268 | PluginManager.GetRepository(); | ||
269 | return; | ||
270 | } | ||
271 | |||
272 | // Remove registered repository | ||
273 | private void HandleConsoleRemoveRepo(string module, string[] cmd) | ||
274 | { | ||
275 | if (cmd.Length == 3) | ||
276 | PluginManager.RemoveRepository(cmd); | ||
277 | return; | ||
278 | } | ||
279 | |||
280 | // Enable repository | ||
281 | private void HandleConsoleEnableRepo(string module, string[] cmd) | ||
282 | { | ||
283 | PluginManager.EnableRepository(cmd); | ||
284 | return; | ||
285 | } | ||
286 | |||
287 | // Disable repository | ||
288 | private void HandleConsoleDisableRepo(string module, string[] cmd) | ||
289 | { | ||
290 | PluginManager.DisableRepository(cmd); | ||
291 | return; | ||
292 | } | ||
293 | |||
294 | // List repositories | ||
295 | private void HandleConsoleListRepos(string module, string[] cmd) | ||
296 | { | ||
297 | Dictionary<string, object> result = new Dictionary<string, object>(); | ||
298 | PluginManager.ListRepositories(out result); | ||
299 | |||
300 | var list = result.Keys.ToList(); | ||
301 | list.Sort(); | ||
302 | foreach (var k in list) | ||
303 | { | ||
304 | Dictionary<string, object> repo = (Dictionary<string, object>)result[k]; | ||
305 | bool enabled = (bool)repo["enabled"]; | ||
306 | MainConsole.Instance.OutputFormat("{0}) {1} {2}", | ||
307 | k, | ||
308 | enabled == true ? "[ ]" : "[X]", | ||
309 | repo["name"], repo["url"]); | ||
310 | } | ||
311 | |||
312 | return; | ||
313 | } | ||
314 | |||
315 | // Show description information | ||
316 | private void HandleConsoleShowAddinInfo(string module, string[] cmd) | ||
317 | { | ||
318 | if (cmd.Length >= 3) | ||
319 | { | ||
320 | |||
321 | Dictionary<string, object> result = new Dictionary<string, object>(); | ||
322 | |||
323 | int ndx = Convert.ToInt16(cmd[2]); | ||
324 | PluginManager.AddinInfo(ndx, out result); | ||
325 | |||
326 | MainConsole.Instance.OutputFormat("Name: {0}\nURL: {1}\nFile: {2}\nAuthor: {3}\nCategory: {4}\nDesc: {5}", | ||
327 | result["name"], | ||
328 | result["url"], | ||
329 | result["file_name"], | ||
330 | result["author"], | ||
331 | result["category"], | ||
332 | result["description"]); | ||
333 | |||
334 | return; | ||
335 | } | ||
336 | } | ||
337 | |||
338 | // Disable plugin | ||
339 | private void HandleConsoleDisablePlugin(string module, string[] cmd) | ||
340 | { | ||
341 | PluginManager.DisablePlugin(cmd); | ||
342 | return; | ||
343 | } | ||
344 | |||
345 | // Enable plugin | ||
346 | private void HandleConsoleEnablePlugin(string module, string[] cmd) | ||
347 | { | ||
348 | PluginManager.EnablePlugin(cmd); | ||
349 | return; | ||
350 | } | ||
351 | #endregion | ||
352 | } | ||
353 | } \ No newline at end of file | ||