diff options
author | rburchell <rburchell@5417fbe8-f217-4b02-8779-1006273d7864> | 2008-11-14 20:04:11 +0000 |
---|---|---|
committer | rburchell <rburchell@5417fbe8-f217-4b02-8779-1006273d7864> | 2008-11-14 20:04:11 +0000 |
commit | dd6f580502ebaa8a0faf8eccb5f52f43b1a4d128 (patch) | |
tree | 36294895cfe28c9a1300cca6f62289f2cec58b44 /src/modulemanager.cpp | |
parent | f75ebf8d0db6e8eeea9b7f53e520f99740365bf1 (diff) |
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
Diffstat (limited to 'src/modulemanager.cpp')
-rw-r--r-- | src/modulemanager.cpp | 59 |
1 files changed, 23 insertions, 36 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; - - 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; -} + 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++; + } + } -/** - * 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; + /* + * 2, because module constructors now add modules to the hash.. so 1 (original module) + * and 2 (this module). -- w00t + */ + if (pmods == 2) + return true; + + 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"); |