diff --git a/src/Zirconium/Core/App.cs b/src/Zirconium/Core/App.cs index b970ce4..349f9c6 100644 --- a/src/Zirconium/Core/App.cs +++ b/src/Zirconium/Core/App.cs @@ -24,6 +24,8 @@ namespace Zirconium.Core Router = new Router(this); HostModuleAPI = new HostModuleAPI(this, Router); AuthManager = new AuthManager(this); + ModuleManager = new ModuleManager(HostModuleAPI); + ModuleManager.LoadModules(config.PluginsDirPath, config.EnabledPlugins); Log.Info("Zirconium is initialized successfully"); } diff --git a/src/Zirconium/Core/Modules/ModuleManager.cs b/src/Zirconium/Core/Modules/ModuleManager.cs index 58882b7..640dc8e 100644 --- a/src/Zirconium/Core/Modules/ModuleManager.cs +++ b/src/Zirconium/Core/Modules/ModuleManager.cs @@ -23,8 +23,13 @@ namespace Zirconium.Core.Modules _moduleMutex = new Mutex(); } - public void LoadModules(string folderPath) { + public void LoadModules(string folderPath, string[] enabledModules) + { var loaders = new List(); + if (folderPath == "") { + Logging.Log.Warning("Plugins folder path is not specified!"); + return; + } // create module loaders foreach (var dir in Directory.GetDirectories(folderPath)) @@ -33,18 +38,21 @@ namespace Zirconium.Core.Modules var pluginDll = Path.Combine(dir, dirName + ".dll"); if (File.Exists(pluginDll)) { - var loader = PluginLoader.CreateFromAssemblyFile( - pluginDll, - sharedTypes: new[] { - typeof(IModuleAPI), - typeof(IHostModuleAPI), - typeof(IC2SMessageHandler), - typeof(ICoreEventHandler), - typeof(BaseMessage), - typeof(CoreEvent) - } - ); - loaders.Add(loader); + if (enabledModules.Where(x => x == pluginDll).FirstOrDefault() != null) + { + var loader = PluginLoader.CreateFromAssemblyFile( + pluginDll, + sharedTypes: new[] { + typeof(IModuleAPI), + typeof(IHostModuleAPI), + typeof(IC2SMessageHandler), + typeof(ICoreEventHandler), + typeof(BaseMessage), + typeof(CoreEvent) + } + ); + loaders.Add(loader); + } } }