diff options
-rw-r--r-- | include/modules.h | 6 | ||||
-rw-r--r-- | src/modules.cpp | 31 |
2 files changed, 20 insertions, 17 deletions
diff --git a/include/modules.h b/include/modules.h index 4f18524c8..02460a38e 100644 --- a/include/modules.h +++ b/include/modules.h @@ -1037,6 +1037,12 @@ class CoreExport ModuleManager : public fakederef<ModuleManager> */ bool PrioritizeHooks(); + /** Unregister all user modes or all channel modes owned by a module + * @param mod Module whose modes to unregister + * @param modetype MODETYPE_USER to unregister user modes, MODETYPE_CHANNEL to unregister channel modes + */ + void UnregisterModes(Module* mod, ModeType modetype); + public: typedef std::map<std::string, Module*> ModuleMap; diff --git a/src/modules.cpp b/src/modules.cpp index 18f2dc4d1..567aa917c 100644 --- a/src/modules.cpp +++ b/src/modules.cpp @@ -342,6 +342,18 @@ bool ModuleManager::CanUnload(Module* mod) return true; } +void ModuleManager::UnregisterModes(Module* mod, ModeType modetype) +{ + const ModeParser::ModeHandlerMap& modes = ServerInstance->Modes.GetModes(modetype); + for (ModeParser::ModeHandlerMap::const_iterator i = modes.begin(); i != modes.end(); ) + { + ModeHandler* const mh = i->second; + ++i; + if (mh->creator == mod) + this->DelService(*mh); + } +} + void ModuleManager::DoSafeUnload(Module* mod) { // First, notify all modules that a module is about to be unloaded, so in case @@ -376,23 +388,8 @@ void ModuleManager::DoSafeUnload(Module* mod) user->doUnhookExtensions(items); } - const ModeParser::ModeHandlerMap& usermodes = ServerInstance->Modes->GetModes(MODETYPE_USER); - for (ModeParser::ModeHandlerMap::const_iterator i = usermodes.begin(); i != usermodes.end(); ) - { - ModeHandler* mh = i->second; - ++i; - if (mh->creator == mod) - this->DelService(*mh); - } - - const ModeParser::ModeHandlerMap& chanmodes = ServerInstance->Modes->GetModes(MODETYPE_CHANNEL); - for (ModeParser::ModeHandlerMap::const_iterator i = chanmodes.begin(); i != chanmodes.end(); ) - { - ModeHandler* mh = i->second; - ++i; - if (mh->creator == mod) - this->DelService(*mh); - } + UnregisterModes(mod, MODETYPE_USER); + UnregisterModes(mod, MODETYPE_CHANNEL); for(std::multimap<std::string, ServiceProvider*>::iterator i = DataProviders.begin(); i != DataProviders.end(); ) { |