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