]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modmanager_static.cpp
Add a short message at the top of permchannel DB, and ensure config format is compat
[user/henk/code/inspircd.git] / src / modmanager_static.cpp
index 3227036795a9b0015b87df8c7fda926ec47b9ab9..ee9dc21078e248b40064965be454fde575b74be3 100644 (file)
@@ -58,21 +58,26 @@ class AllModule : public Module
 
 MODULE_INIT(AllModule)
 
-bool ModuleManager::Load(const char* name)
+bool ModuleManager::Load(const std::string& name, bool)
 {
        for(std::vector<AllModuleList*>::iterator i = modlist->begin(); i != modlist->end(); ++i)
        {
                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<void>
+       {
+               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<void>
        {
                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<void, bool>* callback)
 {
        if (CanUnload(mod))
@@ -117,15 +137,20 @@ void ModuleManager::LoadAll()
        ModCount = 0;
        for(std::vector<AllModuleList*>::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;
-                       FOREACH_MOD(I_OnLoadModule,OnLoadModule(c));
+                       c->init();
                }
                catch (CoreException& modexcept)
                {
+                       if (c)
+                               DoSafeUnload(c);
+                       delete c;
                        ServerInstance->Logs->Log("MODULE", DEFAULT, "Unable to load " + (**i).name + ": " + modexcept.GetReason());
                }
        }
@@ -151,7 +176,6 @@ void ModuleManager::LoadAll()
 
 void ModuleManager::UnloadAll()
 {
-       // TODO don't really need this, who cares if we leak on exit?
 }
 
 #endif