From dd6f580502ebaa8a0faf8eccb5f52f43b1a4d128 Mon Sep 17 00:00:00 2001 From: rburchell Date: Fri, 14 Nov 2008 20:04:11 +0000 Subject: [PATCH] Fix: make the module type checks more generic (removing a copy of code), and make them actually work properly.. that is, there should no longer be an error about protocol modules on startup. Sorry Sazpimon! git-svn-id: http://anope.svn.sourceforge.net/svnroot/anope/trunk@1672 5417fbe8-f217-4b02-8779-1006273d7864 --- src/modulemanager.cpp | 57 +++++++++++++++++-------------------------- 1 file changed, 22 insertions(+), 35 deletions(-) diff --git a/src/modulemanager.cpp b/src/modulemanager.cpp index f38a9eade..529a2e799 100644 --- a/src/modulemanager.cpp +++ b/src/modulemanager.cpp @@ -94,42 +94,29 @@ static int moduleCopyFile(const char *name, const char *output) return MOD_ERR_OK; } -/** - * Search all loaded modules looking for a protocol module. - * @return 1 if one is found. - **/ -static int protocolModuleLoaded() +static bool IsOneOfModuleTypeLoaded(MODType mt) { - int idx = 0; - ModuleHash *current = NULL; + int idx = 0; + ModuleHash *current = NULL; + int pmods = 0; + + for (idx = 0; idx != MAX_CMD_HASH; idx++) + { + for (current = MODULE_HASH[idx]; current; current = current->next) + { + if (current->m->type == mt) + pmods++; + } + } - for (idx = 0; idx != MAX_CMD_HASH; idx++) { - for (current = MODULE_HASH[idx]; current; current = current->next) { - if (current->m->type == PROTOCOL) { - return 1; - } - } - } - return 0; -} + /* + * 2, because module constructors now add modules to the hash.. so 1 (original module) + * and 2 (this module). -- w00t + */ + if (pmods == 2) + return true; -/** - * Search all loaded modules looking for an encryption module. - * @ return 1 if one is loaded - **/ -static int encryptionModuleLoaded() -{ - int idx = 0; - ModuleHash *current = NULL; - - for (idx = 0; idx != MAX_CMD_HASH; idx++) { - for (current = MODULE_HASH[idx]; current; current = current->next) { - if (current->m->type == ENCRYPTION) { - return 1; - } - } - } - return 0; + return false; } int ModuleManager::LoadModule(const std::string &modname, User * u) @@ -218,13 +205,13 @@ int ModuleManager::LoadModule(const std::string &modname, User * u) m->filename = pbuf; m->handle = handle; - if (m->type == PROTOCOL && protocolModuleLoaded()) + if (m->type == PROTOCOL && IsOneOfModuleTypeLoaded(PROTOCOL)) { delete m; alog("You cannot load two protocol modules"); return MOD_STOP; } - else if (m->type == ENCRYPTION && encryptionModuleLoaded()) + else if (m->type == ENCRYPTION && IsOneOfModuleTypeLoaded(ENCRYPTION)) { delete m; alog("You cannot load two encryption modules");