diff options
Diffstat (limited to 'src/modulemanager.cpp')
-rw-r--r-- | src/modulemanager.cpp | 56 |
1 files changed, 42 insertions, 14 deletions
diff --git a/src/modulemanager.cpp b/src/modulemanager.cpp index 823fda868..211304cae 100644 --- a/src/modulemanager.cpp +++ b/src/modulemanager.cpp @@ -11,6 +11,7 @@ #include "modules.h" #include "users.h" #include "regchannel.h" +#include "config.h" #include <sys/types.h> #include <sys/stat.h> @@ -23,6 +24,7 @@ std::list<Module *> ModuleManager::Modules; std::vector<Module *> ModuleManager::EventHandlers[I_END]; +#ifdef _WIN32 void ModuleManager::CleanupRuntimeDirectory() { Anope::string dirbuf = Anope::DataDir + "/runtime"; @@ -108,6 +110,7 @@ static ModuleReturn moduleCopyFile(const Anope::string &name, Anope::string &out return !source.fail() && !target.fail() ? MOD_ERR_OK : MOD_ERR_FILE_IO; } +#endif /* This code was found online at http://www.linuxjournal.com/article/3687#comment-26593 * @@ -133,8 +136,9 @@ ModuleReturn ModuleManager::LoadModule(const Anope::string &modname, User *u) if (FindModule(modname)) return MOD_ERR_EXISTS; - Log(LOG_DEBUG) << "trying to load [" << modname << "]"; + Log(LOG_DEBUG) << "Trying to load module: " << modname; +#ifdef _WIN32 /* Generate the filename for the temporary copy of the module */ Anope::string pbuf = Anope::DataDir + "/runtime/" + modname + ".so.XXXXXX"; @@ -148,6 +152,9 @@ ModuleReturn ModuleManager::LoadModule(const Anope::string &modname, User *u) Log(LOG_TERMINAL) << "Error while loading " << modname << " (file IO error, check file permissions and diskspace)"; return ret; } +#else + Anope::string pbuf = Anope::ModuleDir + "/modules/" + modname + ".so"; +#endif dlerror(); void *handle = dlopen(pbuf.c_str(), RTLD_NOW); @@ -219,7 +226,23 @@ ModuleReturn ModuleManager::LoadModule(const Anope::string &modname, User *u) else Log(LOG_DEBUG_2) << "Module " << modname << " is compiled against current version of Anope " << Anope::VersionShort(); - Log(LOG_DEBUG) << "Module loaded."; + /* If the module is hooked to the reload event it wants to initialize its config here */ + if (std::find(EventHandlers[I_OnReload].begin(), EventHandlers[I_OnReload].end(), m) != EventHandlers[I_OnReload].end()) + { + try + { + m->OnReload(Config); + } + catch (const ConfigException &ex) + { + Log() << "Module " << modname << " couldn't load due to configuration problems: " << ex.GetReason(); + DeleteModule(m); + return MOD_ERR_EXCEPTION; + } + } + + Log(LOG_DEBUG) << "Module " << modname << " loaded."; + FOREACH_MOD(I_OnModuleLoad, OnModuleLoad(u, m)); return MOD_ERR_OK; @@ -254,7 +277,7 @@ Module *ModuleManager::FindFirstOf(ModType type) { Module *m = *it; - if (m->type == type) + if (m->type & type) return m; } @@ -309,8 +332,10 @@ ModuleReturn ModuleManager::DeleteModule(Module *m) if (dlclose(handle)) Log() << dlerror(); +#ifdef _WIN32 if (!filename.empty()) unlink(filename.c_str()); +#endif return MOD_ERR_OK; } @@ -439,7 +464,7 @@ bool ModuleManager::SetPriority(Module *mod, Implementation i, Priority s, Modul for (unsigned j = source; j != swap_pos; j += incrmnt) { - if (j + incrmnt > EventHandlers[i].size() - 1 || j + incrmnt < 0) + if (j + incrmnt > EventHandlers[i].size() - 1 || (!j && incrmnt == -1)) continue; std::swap(EventHandlers[i][j], EventHandlers[i][j + incrmnt]); @@ -451,17 +476,20 @@ bool ModuleManager::SetPriority(Module *mod, Implementation i, Priority s, Modul void ModuleManager::UnloadAll() { - std::vector<Anope::string> modules[MT_END]; - for (std::list<Module *>::iterator it = Modules.begin(), it_end = Modules.end(); it != it_end; ++it) - if ((*it)->type != PROTOCOL && !(*it)->GetPermanent()) - modules[(*it)->type].push_back((*it)->name); - - for (size_t i = MT_BEGIN + 1; i != MT_END; ++i) - for (unsigned j = 0; j < modules[i].size(); ++j) + std::vector<Anope::string> modules; + for (size_t i = 1, j = 0; i != MT_END; i <<= 1, j |= i) + for (std::list<Module *>::iterator it = Modules.begin(), it_end = Modules.end(); it != it_end; ++it) { - Module *m = FindModule(modules[i][j]); - if (m != NULL) - UnloadModule(m, NULL); + Module *m = *it; + if ((m->type & j) == m->type) + modules.push_back(m->name); } + + for (unsigned i = 0; i < modules.size(); ++i) + { + Module *m = FindModule(modules[i]); + if (m != NULL) + UnloadModule(m, NULL); + } } |