summaryrefslogtreecommitdiff
path: root/src/modulemanager.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/modulemanager.cpp')
-rw-r--r--src/modulemanager.cpp43
1 files changed, 29 insertions, 14 deletions
diff --git a/src/modulemanager.cpp b/src/modulemanager.cpp
index a9f1eb2f0..b11ad2829 100644
--- a/src/modulemanager.cpp
+++ b/src/modulemanager.cpp
@@ -18,7 +18,7 @@ void ModuleManager::LoadModuleList(std::list<std::string> &ModuleList)
{
for (std::list<std::string>::iterator it = ModuleList.begin(); it != ModuleList.end(); ++it)
{
- Module *m = findModule(it->c_str());
+ Module *m = FindModule(*it);
if (!m)
ModuleManager::LoadModule(*it, NULL);
}
@@ -79,16 +79,13 @@ static int moduleCopyFile(const char *name, const char *output)
static bool IsOneOfModuleTypeLoaded(MODType mt)
{
- int idx = 0;
- ModuleHash *current = NULL;
int pmods = 0;
- for (idx = 0; idx != MAX_CMD_HASH; idx++)
+ for (std::deque<Module *>::iterator it = Modules.begin(); it != Modules.end(); ++it)
{
- for (current = MODULE_HASH[idx]; current; current = current->next)
+ if ((*it)->type == mt)
{
- if (current->m->type == mt)
- pmods++;
+ ++pmods;
}
}
@@ -127,7 +124,7 @@ int ModuleManager::LoadModule(const std::string &modname, User * u)
if (modname.empty())
return MOD_ERR_PARAMS;
- if (findModule(modname.c_str()) != NULL)
+ if (FindModule(modname) != NULL)
return MOD_ERR_EXISTS;
Alog(LOG_DEBUG) << "trying to load [" << modname << "]";
@@ -164,10 +161,10 @@ int ModuleManager::LoadModule(const std::string &modname, User * u)
}
ano_modclearerr();
- func = function_cast<Module *(*)(const std::string &, const std::string &)>(dlsym(handle, "init_module"));
+ func = function_cast<Module *(*)(const std::string &, const std::string &)>(dlsym(handle, "AnopeInit"));
if (func == NULL && (err = dlerror()) != NULL)
{
- Alog() << "No magical init function found, not an Anope module";
+ Alog() << "No init function found, not an Anope module";
dlclose(handle);
return MOD_ERR_NOLOAD;
}
@@ -235,7 +232,7 @@ int ModuleManager::LoadModule(const std::string &modname, User * u)
if (u)
{
- ircdproto->SendGlobops(findbot(Config.s_OperServ), "%s loaded module %s", u->nick.c_str(), modname.c_str());
+ ircdproto->SendGlobops(OperServ, "%s loaded module %s", u->nick.c_str(), modname.c_str());
notice_lang(Config.s_OperServ, u, OPER_MODULE_LOADED, modname.c_str());
/* If a user is loading this module, then the core databases have already been loaded
@@ -267,7 +264,7 @@ int ModuleManager::UnloadModule(Module *m, User *u)
if (u)
{
- ircdproto->SendGlobops(findbot(Config.s_OperServ), "%s unloaded module %s", u->nick.c_str(), m->name.c_str());
+ ircdproto->SendGlobops(OperServ, "%s unloaded module %s", u->nick.c_str(), m->name.c_str());
notice_lang(Config.s_OperServ, u, OPER_MODULE_UNLOADED, m->name.c_str());
}
@@ -292,10 +289,10 @@ void ModuleManager::DeleteModule(Module *m)
handle = m->handle;
ano_modclearerr();
- destroy_func = function_cast<void (*)(Module *)>(dlsym(m->handle, "destroy_module"));
+ destroy_func = function_cast<void (*)(Module *)>(dlsym(m->handle, "AnopeFini"));
if (destroy_func == NULL && (err = dlerror()) != NULL)
{
- Alog() << "No magical destroy function found, chancing delete...";
+ Alog() << "No destroy function found, chancing delete...";
delete m; /* we just have to chance they haven't overwrote the delete operator then... */
}
else
@@ -468,3 +465,21 @@ void ModuleManager::ClearCallBacks(Module *m)
delete m->CallBacks.front();
}
+/** Unloading all modules, NEVER call this when Anope isn't shutting down.
+ * Ever.
+ * @param unload_proto true to unload the protocol module
+ */
+void ModuleManager::UnloadAll(bool unload_proto)
+{
+ for (std::deque<Module *>::iterator it = Modules.begin(); it != Modules.end();)
+ {
+ Module *m = *it++;
+
+ if (unload_proto || m->type != PROTOCOL)
+ DeleteModule(m);
+
+ if (Modules.empty())
+ break;
+ }
+}
+