X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fmodmanager_static.cpp;h=d9ee07a257a7190754c299a76e4986b9da42da6e;hb=490446040d80d144e64ddf8e52515df1f40f1fd7;hp=3227036795a9b0015b87df8c7fda926ec47b9ab9;hpb=88b9ecb6b34d268f0761e6e961408871b6e91376;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/modmanager_static.cpp b/src/modmanager_static.cpp index 322703679..d9ee07a25 100644 --- a/src/modmanager_static.cpp +++ b/src/modmanager_static.cpp @@ -64,15 +64,20 @@ bool ModuleManager::Load(const char* name) { if ((**i).name == name) { + Module* c = NULL; try { - Module* c = (*(**i).init)(); + c = (*(**i).init)(); Modules[name] = c; + c->init(); FOREACH_MOD(I_OnLoadModule,OnLoadModule(c)); return true; } catch (CoreException& modexcept) { + if (c) + DoSafeUnload(c); + delete c; ServerInstance->Logs->Log("MODULE", DEFAULT, "Unable to load " + (**i).name + ": " + modexcept.GetReason()); } } @@ -80,12 +85,19 @@ bool ModuleManager::Load(const char* name) return false; } -bool ModuleManager::Unload(Module* mod) -{ - return false; -} - namespace { + struct UnloadAction : public HandlerBase0 + { + Module* const mod; + UnloadAction(Module* m) : mod(m) {} + void Call() + { + ServerInstance->Modules->DoSafeUnload(mod); + ServerInstance->GlobalCulls.Apply(); + ServerInstance->GlobalCulls.AddItem(this); + } + }; + struct ReloadAction : public HandlerBase0 { Module* const mod; @@ -104,6 +116,14 @@ namespace { }; } +bool ModuleManager::Unload(Module* mod) +{ + if (!CanUnload(mod)) + return false; + ServerInstance->AtomicActions.AddAction(new UnloadAction(mod)); + return true; +} + void ModuleManager::Reload(Module* mod, HandlerBase1* callback) { if (CanUnload(mod)) @@ -117,15 +137,21 @@ void ModuleManager::LoadAll() ModCount = 0; for(std::vector::iterator i = modlist->begin(); i != modlist->end(); ++i) { + Module* c = NULL; try { - Module* c = (*(**i).init)(); + c = (*(**i).init)(); c->ModuleSourceFile = (**i).name; + c->ModuleDLLManager = NULL; Modules[(**i).name] = c; + c->init(); FOREACH_MOD(I_OnLoadModule,OnLoadModule(c)); } catch (CoreException& modexcept) { + if (c) + DoSafeUnload(c); + delete c; ServerInstance->Logs->Log("MODULE", DEFAULT, "Unable to load " + (**i).name + ": " + modexcept.GetReason()); } }