X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fmodmanager_dynamic.cpp;h=1fcf3aa566b2f246288a45e5a768a57e8467ccd6;hb=235864add961270140c956647d783fa79b5f7120;hp=f6b4617a0657ed2cf0c84fd0bbd6bf9094b136d3;hpb=cd712c40e1b352c05e7ae0f72e0a5e84cdf64323;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/modmanager_dynamic.cpp b/src/modmanager_dynamic.cpp index f6b4617a0..1fcf3aa56 100644 --- a/src/modmanager_dynamic.cpp +++ b/src/modmanager_dynamic.cpp @@ -82,18 +82,19 @@ bool ModuleManager::Load(const char* filename) try { - newmod = newhandle->callInit(); + newmod = newhandle->CallInit(); if (newmod) { newmod->ModuleSourceFile = filename_str; newmod->ModuleDLLManager = newhandle; Version v = newmod->GetVersion(); + Modules[filename_str] = newmod; - ServerInstance->Logs->Log("MODULE", DEFAULT,"New module introduced: %s (Module version %s)%s", - filename, v.version.c_str(), (!(v.Flags & VF_VENDOR) ? " [3rd Party]" : " [Vendor]")); + newmod->init(); - Modules[filename_str] = newmod; + ServerInstance->Logs->Log("MODULE", DEFAULT,"New module introduced: %s (Module version %s)%s", + filename, newhandle->GetVersion().c_str(), (!(v.Flags & VF_VENDOR) ? " [3rd Party]" : " [Vendor]")); } else { @@ -106,6 +107,8 @@ bool ModuleManager::Load(const char* filename) catch (CoreException& modexcept) { // failure in module constructor + if (newmod) + DoSafeUnload(newmod); delete newmod; delete newhandle; LastModuleError = "Unable to load " + filename_str + ": " + modexcept.GetReason(); @@ -136,79 +139,6 @@ bool ModuleManager::Load(const char* filename) return true; } -bool ModuleManager::CanUnload(Module* mod) -{ - std::map::iterator modfind = Modules.find(mod->ModuleSourceFile); - - if (modfind == Modules.end() || modfind->second != mod) - { - LastModuleError = "Module " + mod->ModuleSourceFile + " is not loaded, cannot unload it!"; - ServerInstance->Logs->Log("MODULE", DEFAULT, LastModuleError); - return false; - } - if (mod->GetVersion().Flags & VF_STATIC) - { - LastModuleError = "Module " + mod->ModuleSourceFile + " not unloadable (marked static)"; - ServerInstance->Logs->Log("MODULE", DEFAULT, LastModuleError); - return false; - } - return true; -} - -void ModuleManager::DoSafeUnload(Module* mod) -{ - std::map::iterator modfind = Modules.find(mod->ModuleSourceFile); - - std::vector > items; - ServerInstance->Extensions.BeginUnregister(modfind->second, items); - /* Give the module a chance to tidy out all its metadata */ - for (chan_hash::iterator c = ServerInstance->chanlist->begin(); c != ServerInstance->chanlist->end(); c++) - { - mod->OnCleanup(TYPE_CHANNEL,c->second); - c->second->doUnhookExtensions(items); - const UserMembList* users = c->second->GetUsers(); - for(UserMembCIter mi = users->begin(); mi != users->end(); mi++) - mi->second->doUnhookExtensions(items); - } - for (user_hash::iterator u = ServerInstance->Users->clientlist->begin(); u != ServerInstance->Users->clientlist->end(); u++) - { - mod->OnCleanup(TYPE_USER,u->second); - u->second->doUnhookExtensions(items); - } - for(char m='A'; m <= 'z'; m++) - { - ModeHandler* mh; - mh = ServerInstance->Modes->FindMode(m, MODETYPE_USER); - if (mh && mh->creator == mod) - ServerInstance->Modes->DelMode(mh); - mh = ServerInstance->Modes->FindMode(m, MODETYPE_CHANNEL); - if (mh && mh->creator == mod) - ServerInstance->Modes->DelMode(mh); - } - for(std::multimap::iterator i = DataProviders.begin(); i != DataProviders.end(); ) - { - std::multimap::iterator curr = i++; - if (curr->second->creator == mod) - DataProviders.erase(curr); - } - for(unsigned int i = 0; i < ServerInstance->Modules->ActiveDynrefs.size(); i++) - ServerInstance->Modules->ActiveDynrefs[i]->ClearCache(); - - /* Tidy up any dangling resolvers */ - ServerInstance->Res->CleanResolvers(mod); - - FOREACH_MOD(I_OnUnloadModule,OnUnloadModule(mod)); - - DetachAll(mod); - - Modules.erase(modfind); - ServerInstance->GlobalCulls.AddItem(mod); - - ServerInstance->Logs->Log("MODULE", DEFAULT,"Module %s unloaded",mod->ModuleSourceFile.c_str()); - this->ModCount--; - ServerInstance->BuildISupport(); -} - namespace { struct UnloadAction : public HandlerBase0 {