diff options
Diffstat (limited to 'OpenSim/Region/Environment/ModuleLoader.cs')
-rw-r--r-- | OpenSim/Region/Environment/ModuleLoader.cs | 93 |
1 files changed, 93 insertions, 0 deletions
diff --git a/OpenSim/Region/Environment/ModuleLoader.cs b/OpenSim/Region/Environment/ModuleLoader.cs new file mode 100644 index 0000000..8e42d90 --- /dev/null +++ b/OpenSim/Region/Environment/ModuleLoader.cs | |||
@@ -0,0 +1,93 @@ | |||
1 | using System; | ||
2 | using System.Collections.Generic; | ||
3 | using System.Reflection; | ||
4 | using System.Text; | ||
5 | using OpenSim.Region.Environment.Scenes; | ||
6 | using OpenSim.Region.Environment.Interfaces; | ||
7 | using OpenSim.Region.Environment.Modules; | ||
8 | |||
9 | namespace OpenSim.Region.Environment | ||
10 | { | ||
11 | public class ModuleLoader | ||
12 | { | ||
13 | |||
14 | public Dictionary<string, Assembly> LoadedAssemblys = new Dictionary<string, Assembly>(); | ||
15 | |||
16 | public ModuleLoader() | ||
17 | { | ||
18 | |||
19 | } | ||
20 | |||
21 | /// <summary> | ||
22 | /// Really just a test method for loading a set of currently internal modules | ||
23 | /// </summary> | ||
24 | /// <param name="scene"></param> | ||
25 | public void LoadInternalModules(Scene scene) | ||
26 | { | ||
27 | //Testing IRegionModule ideas | ||
28 | XferModule xferManager = new XferModule(); | ||
29 | xferManager.Initialise(scene); | ||
30 | scene.AddModule(xferManager.GetName(), xferManager); | ||
31 | |||
32 | ChatModule chatModule = new ChatModule(); | ||
33 | chatModule.Initialise(scene); | ||
34 | scene.AddModule(chatModule.GetName(), chatModule); | ||
35 | |||
36 | AvatarProfilesModule avatarProfiles = new AvatarProfilesModule(); | ||
37 | avatarProfiles.Initialise(scene); | ||
38 | scene.AddModule(avatarProfiles.GetName(), avatarProfiles); | ||
39 | |||
40 | // Post Initialise Modules | ||
41 | xferManager.PostInitialise(); | ||
42 | // chatModule.PostInitialise(); //for now leave this disabled as it would start up a partially working irc bot | ||
43 | avatarProfiles.PostInitialise(); | ||
44 | } | ||
45 | |||
46 | public void LoadModule(string dllName, string moduleName, Scene scene) | ||
47 | { | ||
48 | Assembly pluginAssembly = null; | ||
49 | if (LoadedAssemblys.ContainsKey(dllName)) | ||
50 | { | ||
51 | pluginAssembly = LoadedAssemblys[dllName]; | ||
52 | } | ||
53 | else | ||
54 | { | ||
55 | pluginAssembly = Assembly.LoadFrom(dllName); | ||
56 | this.LoadedAssemblys.Add(dllName, pluginAssembly); | ||
57 | } | ||
58 | |||
59 | IRegionModule module = null; | ||
60 | foreach (Type pluginType in pluginAssembly.GetTypes()) | ||
61 | { | ||
62 | if (pluginType.IsPublic) | ||
63 | { | ||
64 | if (!pluginType.IsAbstract) | ||
65 | { | ||
66 | Type typeInterface = pluginType.GetInterface("IRegionModule", true); | ||
67 | |||
68 | if (typeInterface != null) | ||
69 | { | ||
70 | module = (IRegionModule)Activator.CreateInstance(pluginAssembly.GetType(pluginType.ToString())); | ||
71 | break; | ||
72 | } | ||
73 | typeInterface = null; | ||
74 | } | ||
75 | } | ||
76 | } | ||
77 | pluginAssembly = null; | ||
78 | |||
79 | if (module.GetName() == moduleName) | ||
80 | { | ||
81 | module.Initialise(scene); | ||
82 | scene.AddModule(moduleName, module); | ||
83 | module.PostInitialise(); //shouldn't be done here | ||
84 | } | ||
85 | |||
86 | } | ||
87 | |||
88 | public void ClearCache() | ||
89 | { | ||
90 | this.LoadedAssemblys.Clear(); | ||
91 | } | ||
92 | } | ||
93 | } | ||