diff options
author | BlueWall | 2012-10-06 11:48:21 -0400 |
---|---|---|
committer | BlueWall | 2012-10-06 11:48:21 -0400 |
commit | 440726250cc2a523463f575b682a6ddb6242408c (patch) | |
tree | f782c828486b4de6eb978f4c9664e6936b734899 /OpenSim/Server | |
parent | Remove duplicate files (diff) | |
download | opensim-SC_OLD-440726250cc2a523463f575b682a6ddb6242408c.zip opensim-SC_OLD-440726250cc2a523463f575b682a6ddb6242408c.tar.gz opensim-SC_OLD-440726250cc2a523463f575b682a6ddb6242408c.tar.bz2 opensim-SC_OLD-440726250cc2a523463f575b682a6ddb6242408c.tar.xz |
Added parts to manage repositories and plugin management
This is working - more testing to follow, then soem documentation
Diffstat (limited to 'OpenSim/Server')
-rw-r--r-- | OpenSim/Server/Base/CommandManager.cs | 353 | ||||
-rw-r--r-- | OpenSim/Server/Base/PluginManager.cs | 555 | ||||
-rw-r--r-- | OpenSim/Server/Base/ServerUtils.cs | 106 | ||||
-rw-r--r-- | OpenSim/Server/Handlers/Base/ServerConnector.cs | 4 | ||||
-rw-r--r-- | OpenSim/Server/ServerMain.cs | 10 |
5 files changed, 1028 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 | ||
diff --git a/OpenSim/Server/Base/PluginManager.cs b/OpenSim/Server/Base/PluginManager.cs new file mode 100644 index 0000000..6248e74 --- /dev/null +++ b/OpenSim/Server/Base/PluginManager.cs | |||
@@ -0,0 +1,555 @@ | |||
1 | |||
2 | /* | ||
3 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
4 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
5 | * | ||
6 | * Redistribution and use in source and binary forms, with or without | ||
7 | * modification, are permitted provided that the following conditions are met: | ||
8 | * * Redistributions of source code must retain the above copyright | ||
9 | * notice, this list of conditions and the following disclaimer. | ||
10 | * * Redistributions in binary form must reproduce the above copyright | ||
11 | * notice, this list of conditions and the following disclaimer in the | ||
12 | * documentation and/or other materials provided with the distribution. | ||
13 | * * Neither the name of the OpenSimulator Project nor the | ||
14 | * names of its contributors may be used to endorse or promote products | ||
15 | * derived from this software without specific prior written permission. | ||
16 | * | ||
17 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
18 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
19 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
20 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
21 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
22 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
23 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
24 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
26 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
27 | */ | ||
28 | |||
29 | |||
30 | using System; | ||
31 | using System.Text; | ||
32 | using System.Linq; | ||
33 | using System.Collections; | ||
34 | using System.Collections.Generic; | ||
35 | using System.Collections.ObjectModel; | ||
36 | using Mono.Addins; | ||
37 | using Mono.Addins.Setup; | ||
38 | using Mono.Addins.Description; | ||
39 | using OpenSim.Framework; | ||
40 | |||
41 | namespace OpenSim.Server.Base | ||
42 | { | ||
43 | public class PluginManager : SetupService | ||
44 | { | ||
45 | protected AddinRegistry PluginRegistry; | ||
46 | |||
47 | internal PluginManager(AddinRegistry registry): base (registry) | ||
48 | { | ||
49 | PluginRegistry = registry; | ||
50 | |||
51 | } | ||
52 | |||
53 | /// <summary> | ||
54 | /// Installs the plugin. | ||
55 | /// </summary> | ||
56 | /// <returns> | ||
57 | /// The plugin. | ||
58 | /// </returns> | ||
59 | /// <param name='args'> | ||
60 | /// Arguments. | ||
61 | /// </param> | ||
62 | public bool InstallPlugin(int ndx, out Dictionary<string, object> result) | ||
63 | { | ||
64 | Dictionary<string, object> res = new Dictionary<string, object>(); | ||
65 | |||
66 | PackageCollection pack = new PackageCollection(); | ||
67 | PackageCollection toUninstall; | ||
68 | DependencyCollection unresolved; | ||
69 | |||
70 | IProgressStatus ps = new ConsoleProgressStatus(false); | ||
71 | |||
72 | AddinRepositoryEntry[] available = GetSortedAvailbleAddins(); | ||
73 | |||
74 | if (ndx > (available.Length - 1)) | ||
75 | { | ||
76 | MainConsole.Instance.Output("Selection out of range"); | ||
77 | result = res; | ||
78 | return false; | ||
79 | } | ||
80 | |||
81 | AddinRepositoryEntry aentry = available[ndx]; | ||
82 | |||
83 | Package p = Package.FromRepository(aentry); | ||
84 | pack.Add(p); | ||
85 | |||
86 | ResolveDependencies(ps, pack, out toUninstall, out unresolved); | ||
87 | |||
88 | // Attempt to install the plugin disabled | ||
89 | if (Install(ps, pack) == true) | ||
90 | { | ||
91 | PluginRegistry.Update(ps); | ||
92 | Addin addin = PluginRegistry.GetAddin(aentry.Addin.Id); | ||
93 | PluginRegistry.DisableAddin(addin.Id); | ||
94 | addin.Enabled = false; | ||
95 | |||
96 | MainConsole.Instance.Output("Installation Success"); | ||
97 | ListInstalledAddins(out res); | ||
98 | result = res; | ||
99 | return true; | ||
100 | } | ||
101 | else | ||
102 | { | ||
103 | MainConsole.Instance.Output("Installation Failed"); | ||
104 | result = res; | ||
105 | return false; | ||
106 | } | ||
107 | } | ||
108 | |||
109 | // Remove plugin | ||
110 | /// <summary> | ||
111 | /// Uns the install. | ||
112 | /// </summary> | ||
113 | /// <param name='args'> | ||
114 | /// Arguments. | ||
115 | /// </param> | ||
116 | public void UnInstall(int ndx) | ||
117 | { | ||
118 | Addin[] addins = GetSortedAddinList("RobustPlugin"); | ||
119 | |||
120 | if (ndx > (addins.Length -1)) | ||
121 | { | ||
122 | MainConsole.Instance.Output("Selection out of range"); | ||
123 | return; | ||
124 | } | ||
125 | |||
126 | Addin addin = addins[ndx]; | ||
127 | MainConsole.Instance.OutputFormat("Uninstalling plugin {0}", addin.Id); | ||
128 | AddinManager.Registry.DisableAddin(addin.Id); | ||
129 | addin.Enabled = false; | ||
130 | IProgressStatus ps = new ConsoleProgressStatus(false); | ||
131 | Uninstall(ps, addin.Id); | ||
132 | MainConsole.Instance.Output("Uninstall Success - restart to complete operation"); | ||
133 | return; | ||
134 | } | ||
135 | |||
136 | /// <summary> | ||
137 | /// Checks the installed. | ||
138 | /// </summary> | ||
139 | /// <returns> | ||
140 | /// The installed. | ||
141 | /// </returns> | ||
142 | public string CheckInstalled() | ||
143 | { | ||
144 | return "CheckInstall"; | ||
145 | } | ||
146 | |||
147 | /// <summary> | ||
148 | /// Lists the installed addins. | ||
149 | /// </summary> | ||
150 | /// <param name='result'> | ||
151 | /// Result. | ||
152 | /// </param> | ||
153 | public void ListInstalledAddins(out Dictionary<string, object> result) | ||
154 | { | ||
155 | Dictionary<string, object> res = new Dictionary<string, object>(); | ||
156 | |||
157 | Addin[] addins = GetSortedAddinList("RobustPlugin"); | ||
158 | if(addins.Count() < 1) | ||
159 | { | ||
160 | MainConsole.Instance.Output("Error!"); | ||
161 | } | ||
162 | int count = 0; | ||
163 | foreach (Addin addin in addins) | ||
164 | { | ||
165 | Dictionary<string, object> r = new Dictionary<string, object>(); | ||
166 | r["enabled"] = addin.Enabled == true ? true : false; | ||
167 | r["name"] = addin.LocalId; | ||
168 | r["version"] = addin.Version; | ||
169 | |||
170 | res.Add(count.ToString(), r); | ||
171 | |||
172 | count++; | ||
173 | } | ||
174 | result = res; | ||
175 | return; | ||
176 | } | ||
177 | |||
178 | // List compatible plugins in registered repositories | ||
179 | /// <summary> | ||
180 | /// Lists the available. | ||
181 | /// </summary> | ||
182 | /// <param name='result'> | ||
183 | /// Result. | ||
184 | /// </param> | ||
185 | public void ListAvailable(out Dictionary<string, object> result) | ||
186 | { | ||
187 | Dictionary<string, object> res = new Dictionary<string, object>(); | ||
188 | |||
189 | AddinRepositoryEntry[] addins = GetSortedAvailbleAddins(); | ||
190 | |||
191 | int count = 0; | ||
192 | foreach (AddinRepositoryEntry addin in addins) | ||
193 | { | ||
194 | Dictionary<string, object> r = new Dictionary<string, object>(); | ||
195 | r["name"] = addin.Addin.Name; | ||
196 | r["version"] = addin.Addin.Version; | ||
197 | r["repository"] = addin.RepositoryName; | ||
198 | |||
199 | res.Add(count.ToString(), r); | ||
200 | count++; | ||
201 | } | ||
202 | result = res; | ||
203 | return; | ||
204 | } | ||
205 | |||
206 | // List available updates ** 1 | ||
207 | /// <summary> | ||
208 | /// Lists the updates. | ||
209 | /// </summary> | ||
210 | public void ListUpdates() | ||
211 | { | ||
212 | IProgressStatus ps = new ConsoleProgressStatus(true); | ||
213 | Console.WriteLine ("Looking for updates..."); | ||
214 | Repositories.UpdateAllRepositories (ps); | ||
215 | Console.WriteLine ("Available add-in updates:"); | ||
216 | bool found = false; | ||
217 | AddinRepositoryEntry[] entries = Repositories.GetAvailableUpdates(); | ||
218 | |||
219 | foreach (AddinRepositoryEntry entry in entries) | ||
220 | { | ||
221 | Console.WriteLine(String.Format("{0}",entry.Addin.Id)); | ||
222 | } | ||
223 | } | ||
224 | |||
225 | // Sync to repositories | ||
226 | /// <summary> | ||
227 | /// Update this instance. | ||
228 | /// </summary> | ||
229 | public string Update() | ||
230 | { | ||
231 | IProgressStatus ps = new ConsoleProgressStatus(true); | ||
232 | Repositories.UpdateAllRepositories(ps); | ||
233 | return "Update"; | ||
234 | } | ||
235 | |||
236 | // Register a repository | ||
237 | /// <summary> | ||
238 | /// Register a repository with our server. | ||
239 | /// </summary> | ||
240 | /// <returns> | ||
241 | /// result of the action | ||
242 | /// </returns> | ||
243 | /// <param name='repo'> | ||
244 | /// The URL of the repository we want to add | ||
245 | /// </param> | ||
246 | public bool AddRepository(string repo) | ||
247 | { | ||
248 | Repositories.RegisterRepository(null, repo, true); | ||
249 | return true; | ||
250 | } | ||
251 | |||
252 | /// <summary> | ||
253 | /// Gets the repository. | ||
254 | /// </summary> | ||
255 | public void GetRepository() | ||
256 | { | ||
257 | Repositories.UpdateAllRepositories(new ConsoleProgressStatus(false)); | ||
258 | } | ||
259 | |||
260 | // Remove a repository from the list | ||
261 | /// <summary> | ||
262 | /// Removes the repository. | ||
263 | /// </summary> | ||
264 | /// <param name='args'> | ||
265 | /// Arguments. | ||
266 | /// </param> | ||
267 | public void RemoveRepository(string[] args) | ||
268 | { | ||
269 | AddinRepository[] reps = Repositories.GetRepositories(); | ||
270 | Array.Sort(reps, (r1,r2) => r1.Title.CompareTo(r2.Title)); | ||
271 | if (reps.Length == 0) | ||
272 | { | ||
273 | MainConsole.Instance.Output("No repositories have been registered."); | ||
274 | return; | ||
275 | } | ||
276 | |||
277 | int n = Convert.ToInt16(args[2]); | ||
278 | if (n > (reps.Length -1)) | ||
279 | { | ||
280 | MainConsole.Instance.Output("Selection out of range"); | ||
281 | return; | ||
282 | } | ||
283 | |||
284 | AddinRepository rep = reps[n]; | ||
285 | Repositories.RemoveRepository(rep.Url); | ||
286 | return; | ||
287 | } | ||
288 | |||
289 | // Enable repository | ||
290 | /// <summary> | ||
291 | /// Enables the repository. | ||
292 | /// </summary> | ||
293 | /// <param name='args'> | ||
294 | /// Arguments. | ||
295 | /// </param> | ||
296 | public void EnableRepository(string[] args) | ||
297 | { | ||
298 | AddinRepository[] reps = Repositories.GetRepositories(); | ||
299 | Array.Sort(reps, (r1,r2) => r1.Title.CompareTo(r2.Title)); | ||
300 | if (reps.Length == 0) | ||
301 | { | ||
302 | MainConsole.Instance.Output("No repositories have been registered."); | ||
303 | return; | ||
304 | } | ||
305 | |||
306 | int n = Convert.ToInt16(args[2]); | ||
307 | if (n > (reps.Length -1)) | ||
308 | { | ||
309 | MainConsole.Instance.Output("Selection out of range"); | ||
310 | return; | ||
311 | } | ||
312 | |||
313 | AddinRepository rep = reps[n]; | ||
314 | Repositories.SetRepositoryEnabled(rep.Url, true); | ||
315 | return; | ||
316 | } | ||
317 | |||
318 | // Disable a repository | ||
319 | /// <summary> | ||
320 | /// Disables the repository. | ||
321 | /// </summary> | ||
322 | /// <param name='args'> | ||
323 | /// Arguments. | ||
324 | /// </param> | ||
325 | public void DisableRepository(string[] args) | ||
326 | { | ||
327 | AddinRepository[] reps = Repositories.GetRepositories(); | ||
328 | Array.Sort(reps, (r1,r2) => r1.Title.CompareTo(r2.Title)); | ||
329 | if (reps.Length == 0) | ||
330 | { | ||
331 | MainConsole.Instance.Output("No repositories have been registered."); | ||
332 | return; | ||
333 | } | ||
334 | |||
335 | int n = Convert.ToInt16(args[2]); | ||
336 | if (n > (reps.Length -1)) | ||
337 | { | ||
338 | MainConsole.Instance.Output("Selection out of range"); | ||
339 | return; | ||
340 | } | ||
341 | |||
342 | AddinRepository rep = reps[n]; | ||
343 | Repositories.SetRepositoryEnabled(rep.Url, false); | ||
344 | return; | ||
345 | } | ||
346 | |||
347 | // List registered repositories | ||
348 | /// <summary> | ||
349 | /// Lists the repositories. | ||
350 | /// </summary> | ||
351 | /// <param name='result'> | ||
352 | /// Result. | ||
353 | /// </param> | ||
354 | public void ListRepositories(out Dictionary<string, object> result) | ||
355 | { | ||
356 | Dictionary<string, object> res = new Dictionary<string, object>(); | ||
357 | result = res; | ||
358 | |||
359 | AddinRepository[] reps = GetSortedAddinRepo(); | ||
360 | if (reps.Length == 0) | ||
361 | { | ||
362 | MainConsole.Instance.Output("No repositories have been registered."); | ||
363 | return; | ||
364 | } | ||
365 | |||
366 | int count = 0; | ||
367 | foreach (AddinRepository rep in reps) | ||
368 | { | ||
369 | Dictionary<string, object> r = new Dictionary<string, object>(); | ||
370 | r["enabled"] = rep.Enabled == true ? true : false; | ||
371 | r["name"] = rep.Name; | ||
372 | r["url"] = rep.Url; | ||
373 | |||
374 | res.Add(count.ToString(), r); | ||
375 | count++; | ||
376 | } | ||
377 | return; | ||
378 | } | ||
379 | |||
380 | /// <summary> | ||
381 | /// Updates the registry. | ||
382 | /// </summary> | ||
383 | public void UpdateRegistry() | ||
384 | { | ||
385 | PluginRegistry.Update(); | ||
386 | } | ||
387 | |||
388 | // Show plugin info | ||
389 | /// <summary> | ||
390 | /// Addins the info. | ||
391 | /// </summary> | ||
392 | /// <returns> | ||
393 | /// The info. | ||
394 | /// </returns> | ||
395 | /// <param name='args'> | ||
396 | /// Arguments. | ||
397 | /// </param> | ||
398 | public bool AddinInfo(int ndx, out Dictionary<string, object> result) | ||
399 | { | ||
400 | Dictionary<string, object> res = new Dictionary<string, object>(); | ||
401 | result = res; | ||
402 | |||
403 | Addin[] addins = GetSortedAddinList("RobustPlugin"); | ||
404 | |||
405 | if (ndx > (addins.Length - 1)) | ||
406 | { | ||
407 | MainConsole.Instance.Output("Selection out of range"); | ||
408 | return false; | ||
409 | } | ||
410 | // author category description | ||
411 | Addin addin = addins[ndx]; | ||
412 | |||
413 | res["author"] = addin.Description.Author; | ||
414 | res["category"] = addin.Description.Category; | ||
415 | res["description"] = addin.Description.Description; | ||
416 | res["name"] = addin.Name; | ||
417 | res["url"] = addin.Description.Url; | ||
418 | res["file_name"] = addin.Description.FileName; | ||
419 | |||
420 | result = res; | ||
421 | return true; | ||
422 | } | ||
423 | |||
424 | // Disable a plugin | ||
425 | /// <summary> | ||
426 | /// Disables the plugin. | ||
427 | /// </summary> | ||
428 | /// <param name='args'> | ||
429 | /// Arguments. | ||
430 | /// </param> | ||
431 | public void DisablePlugin(string[] args) | ||
432 | { | ||
433 | Addin[] addins = GetSortedAddinList("RobustPlugin"); | ||
434 | |||
435 | int n = Convert.ToInt16(args[2]); | ||
436 | if (n > (addins.Length -1)) | ||
437 | { | ||
438 | MainConsole.Instance.Output("Selection out of range"); | ||
439 | return; | ||
440 | } | ||
441 | |||
442 | Addin addin = addins[n]; | ||
443 | AddinManager.Registry.DisableAddin(addin.Id); | ||
444 | addin.Enabled = false; | ||
445 | return; | ||
446 | } | ||
447 | |||
448 | // Enable plugin | ||
449 | /// <summary> | ||
450 | /// Enables the plugin. | ||
451 | /// </summary> | ||
452 | /// <param name='args'> | ||
453 | /// Arguments. | ||
454 | /// </param> | ||
455 | public void EnablePlugin(string[] args) | ||
456 | { | ||
457 | Addin[] addins = GetSortedAddinList("RobustPlugin"); | ||
458 | |||
459 | int n = Convert.ToInt16(args[2]); | ||
460 | if (n > (addins.Length -1)) | ||
461 | { | ||
462 | MainConsole.Instance.Output("Selection out of range"); | ||
463 | return; | ||
464 | } | ||
465 | |||
466 | Addin addin = addins[n]; | ||
467 | |||
468 | addin.Enabled = true; | ||
469 | AddinManager.Registry.EnableAddin(addin.Id); | ||
470 | // AddinManager.Registry.Update(); | ||
471 | if(PluginRegistry.IsAddinEnabled(addin.Id)) | ||
472 | { | ||
473 | ConsoleProgressStatus ps = new ConsoleProgressStatus(false); | ||
474 | if (!AddinManager.AddinEngine.IsAddinLoaded(addin.Id)) | ||
475 | { | ||
476 | AddinManager.Registry.Rebuild(ps); | ||
477 | AddinManager.AddinEngine.LoadAddin(ps, addin.Id); | ||
478 | } | ||
479 | } | ||
480 | else | ||
481 | { | ||
482 | MainConsole.Instance.OutputFormat("Not Enabled in this domain {0}", addin.Name); | ||
483 | } | ||
484 | return; | ||
485 | } | ||
486 | |||
487 | |||
488 | |||
489 | #region Util | ||
490 | private void Testing() | ||
491 | { | ||
492 | Addin[] list = Registry.GetAddins(); | ||
493 | |||
494 | var addins = list.Where( a => a.Description.Category == "RobustPlugin"); | ||
495 | |||
496 | foreach (Addin addin in addins) | ||
497 | { | ||
498 | MainConsole.Instance.OutputFormat("Addin {0}", addin.Name); | ||
499 | } | ||
500 | } | ||
501 | |||
502 | // These will let us deal with numbered lists instead | ||
503 | // of needing to type in the full ids | ||
504 | private AddinRepositoryEntry[] GetSortedAvailbleAddins() | ||
505 | { | ||
506 | ArrayList list = new ArrayList(); | ||
507 | list.AddRange(Repositories.GetAvailableAddins()); | ||
508 | |||
509 | AddinRepositoryEntry[] addins = list.ToArray(typeof(AddinRepositoryEntry)) as AddinRepositoryEntry[]; | ||
510 | |||
511 | Array.Sort(addins,(r1,r2) => r1.Addin.Id.CompareTo(r2.Addin.Id)); | ||
512 | |||
513 | return addins; | ||
514 | } | ||
515 | |||
516 | private AddinRepository[] GetSortedAddinRepo() | ||
517 | { | ||
518 | ArrayList list = new ArrayList(); | ||
519 | list.AddRange(Repositories.GetRepositories()); | ||
520 | |||
521 | AddinRepository[] repos = list.ToArray(typeof(AddinRepository)) as AddinRepository[]; | ||
522 | Array.Sort (repos,(r1,r2) => r1.Name.CompareTo(r2.Name)); | ||
523 | |||
524 | return repos; | ||
525 | } | ||
526 | |||
527 | private Addin[] GetSortedAddinList(string category) | ||
528 | { | ||
529 | |||
530 | ArrayList xlist = new ArrayList(); | ||
531 | ArrayList list = new ArrayList(); | ||
532 | try | ||
533 | { | ||
534 | list.AddRange(PluginRegistry.GetAddins()); | ||
535 | } | ||
536 | catch(Exception e) | ||
537 | { | ||
538 | Addin[] x = xlist.ToArray(typeof(Addin)) as Addin[]; | ||
539 | return x; | ||
540 | } | ||
541 | |||
542 | foreach (Addin addin in list) | ||
543 | { | ||
544 | if (addin.Description.Category == category) | ||
545 | xlist.Add(addin); | ||
546 | } | ||
547 | |||
548 | Addin[] addins = xlist.ToArray(typeof(Addin)) as Addin[]; | ||
549 | Array.Sort(addins,(r1,r2) => r1.Id.CompareTo(r2.Id)); | ||
550 | |||
551 | return addins; | ||
552 | } | ||
553 | #endregion Util | ||
554 | } | ||
555 | } \ No newline at end of file | ||
diff --git a/OpenSim/Server/Base/ServerUtils.cs b/OpenSim/Server/Base/ServerUtils.cs index 4a696c4..6c6af62 100644 --- a/OpenSim/Server/Base/ServerUtils.cs +++ b/OpenSim/Server/Base/ServerUtils.cs | |||
@@ -36,9 +36,115 @@ using log4net; | |||
36 | using Nini.Config; | 36 | using Nini.Config; |
37 | using OpenSim.Framework; | 37 | using OpenSim.Framework; |
38 | using OpenMetaverse; | 38 | using OpenMetaverse; |
39 | using Mono.Addins; | ||
40 | using OpenSim.Framework.Servers.HttpServer; | ||
41 | using OpenSim.Framework.Servers; | ||
39 | 42 | ||
43 | |||
44 | [assembly:AddinRoot("Robust", "0.1")] | ||
40 | namespace OpenSim.Server.Base | 45 | namespace OpenSim.Server.Base |
41 | { | 46 | { |
47 | [TypeExtensionPoint(Path="/Robust/Connector", Name="RobustConnector")] | ||
48 | public interface IRobustConnector | ||
49 | { | ||
50 | string ConfigName | ||
51 | { | ||
52 | get; | ||
53 | } | ||
54 | |||
55 | bool Enabled | ||
56 | { | ||
57 | get; | ||
58 | } | ||
59 | |||
60 | string PluginPath | ||
61 | { | ||
62 | get; | ||
63 | set; | ||
64 | } | ||
65 | |||
66 | uint Configure(IConfigSource config); | ||
67 | void Initialize(IHttpServer server); | ||
68 | } | ||
69 | |||
70 | public class PluginLoader | ||
71 | { | ||
72 | static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
73 | |||
74 | public AddinRegistry Registry | ||
75 | { | ||
76 | get; | ||
77 | private set; | ||
78 | } | ||
79 | |||
80 | public IConfigSource Config | ||
81 | { | ||
82 | get; | ||
83 | private set; | ||
84 | } | ||
85 | |||
86 | public PluginLoader(IConfigSource config, string registryPath) | ||
87 | { | ||
88 | Config = config; | ||
89 | |||
90 | Registry = new AddinRegistry(registryPath, "."); | ||
91 | AddinManager.Initialize(registryPath); | ||
92 | AddinManager.Registry.Update(); | ||
93 | CommandManager commandmanager = new CommandManager(Registry); | ||
94 | AddinManager.AddExtensionNodeHandler("/Robust/Connector", OnExtensionChanged); | ||
95 | } | ||
96 | |||
97 | private void OnExtensionChanged(object s, ExtensionNodeEventArgs args) | ||
98 | { | ||
99 | IRobustConnector connector = (IRobustConnector)args.ExtensionObject; | ||
100 | |||
101 | Addin a = Registry.GetAddin(args.ExtensionNode.Addin.Id); | ||
102 | m_log.InfoFormat("[SERVER]: Extension Change: {0}/{1}", Registry.DefaultAddinsFolder, a.Name.Replace(',', '.')); | ||
103 | |||
104 | switch(args.Change) | ||
105 | { | ||
106 | case ExtensionChange.Add: | ||
107 | connector.PluginPath = String.Format("{0}/{1}", Registry.DefaultAddinsFolder, a.Name.Replace(',', '.')); | ||
108 | LoadPlugin(connector); | ||
109 | break; | ||
110 | case ExtensionChange.Remove: | ||
111 | UnloadPlugin(connector); | ||
112 | break; | ||
113 | } | ||
114 | } | ||
115 | |||
116 | private void LoadPlugin(IRobustConnector connector) | ||
117 | { | ||
118 | IHttpServer server = null; | ||
119 | uint port = connector.Configure(Config); | ||
120 | |||
121 | if(connector.Enabled) | ||
122 | { | ||
123 | server = GetServer(connector, port); | ||
124 | m_log.InfoFormat("[SERVER]: Path is {0}", connector.PluginPath); | ||
125 | connector.Initialize(server); | ||
126 | } | ||
127 | else | ||
128 | m_log.InfoFormat("[SERVER]: {0} Disabled.", connector.ConfigName); | ||
129 | } | ||
130 | |||
131 | private void UnloadPlugin(IRobustConnector connector) | ||
132 | { | ||
133 | } | ||
134 | |||
135 | private IHttpServer GetServer(IRobustConnector connector, uint port) | ||
136 | { | ||
137 | IHttpServer server; | ||
138 | |||
139 | if(port != 0) | ||
140 | server = MainServer.GetHttpServer(port); | ||
141 | else | ||
142 | server = MainServer.Instance; | ||
143 | |||
144 | return server; | ||
145 | } | ||
146 | } | ||
147 | |||
42 | public static class ServerUtils | 148 | public static class ServerUtils |
43 | { | 149 | { |
44 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | 150 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
diff --git a/OpenSim/Server/Handlers/Base/ServerConnector.cs b/OpenSim/Server/Handlers/Base/ServerConnector.cs index 951cd89..067fd2a 100644 --- a/OpenSim/Server/Handlers/Base/ServerConnector.cs +++ b/OpenSim/Server/Handlers/Base/ServerConnector.cs | |||
@@ -63,6 +63,10 @@ namespace OpenSim.Server.Handlers.Base | |||
63 | protected set; | 63 | protected set; |
64 | } | 64 | } |
65 | 65 | ||
66 | public ServiceConnector() | ||
67 | { | ||
68 | } | ||
69 | |||
66 | public ServiceConnector(IConfigSource config, IHttpServer server, string configName) | 70 | public ServiceConnector(IConfigSource config, IHttpServer server, string configName) |
67 | { | 71 | { |
68 | } | 72 | } |
diff --git a/OpenSim/Server/ServerMain.cs b/OpenSim/Server/ServerMain.cs index 21fb678..575d560 100644 --- a/OpenSim/Server/ServerMain.cs +++ b/OpenSim/Server/ServerMain.cs | |||
@@ -34,6 +34,7 @@ using OpenSim.Framework.Servers; | |||
34 | using OpenSim.Framework.Servers.HttpServer; | 34 | using OpenSim.Framework.Servers.HttpServer; |
35 | using OpenSim.Server.Base; | 35 | using OpenSim.Server.Base; |
36 | using OpenSim.Server.Handlers.Base; | 36 | using OpenSim.Server.Handlers.Base; |
37 | using Mono.Addins; | ||
37 | 38 | ||
38 | namespace OpenSim.Server | 39 | namespace OpenSim.Server |
39 | { | 40 | { |
@@ -48,9 +49,13 @@ namespace OpenSim.Server | |||
48 | protected static List<IServiceConnector> m_ServiceConnectors = | 49 | protected static List<IServiceConnector> m_ServiceConnectors = |
49 | new List<IServiceConnector>(); | 50 | new List<IServiceConnector>(); |
50 | 51 | ||
52 | protected static PluginLoader loader; | ||
53 | |||
51 | public static int Main(string[] args) | 54 | public static int Main(string[] args) |
52 | { | 55 | { |
53 | m_Server = new HttpServerBase("R.O.B.U.S.T.", args); | 56 | m_Server = new HttpServerBase("R.O.B.U.S.T.", args); |
57 | |||
58 | string registryLocation; | ||
54 | 59 | ||
55 | IConfig serverConfig = m_Server.Config.Configs["Startup"]; | 60 | IConfig serverConfig = m_Server.Config.Configs["Startup"]; |
56 | if (serverConfig == null) | 61 | if (serverConfig == null) |
@@ -61,6 +66,8 @@ namespace OpenSim.Server | |||
61 | 66 | ||
62 | string connList = serverConfig.GetString("ServiceConnectors", String.Empty); | 67 | string connList = serverConfig.GetString("ServiceConnectors", String.Empty); |
63 | string[] conns = connList.Split(new char[] {',', ' '}); | 68 | string[] conns = connList.Split(new char[] {',', ' '}); |
69 | |||
70 | registryLocation = serverConfig.GetString("RegistryLocation","."); | ||
64 | 71 | ||
65 | // int i = 0; | 72 | // int i = 0; |
66 | foreach (string c in conns) | 73 | foreach (string c in conns) |
@@ -123,6 +130,9 @@ namespace OpenSim.Server | |||
123 | m_log.InfoFormat("[SERVER]: Failed to load {0}", conn); | 130 | m_log.InfoFormat("[SERVER]: Failed to load {0}", conn); |
124 | } | 131 | } |
125 | } | 132 | } |
133 | |||
134 | loader = new PluginLoader(m_Server.Config, registryLocation); | ||
135 | |||
126 | int res = m_Server.Run(); | 136 | int res = m_Server.Run(); |
127 | 137 | ||
128 | Environment.Exit(res); | 138 | Environment.Exit(res); |