-bool ModuleManager::Unload(const char* filename)
-{
- std::string filename_str = filename;
- for (unsigned int j = 0; j != Instance->Config->module_names.size(); j++)
- {
- if (Instance->Config->module_names[j] == filename_str)
- {
- if (modules[j]->GetVersion().Flags & VF_STATIC)
- {
- Instance->Log(DEFAULT,"Failed to unload STATIC module %s",filename);
- snprintf(MODERR,MAXBUF,"Module not unloadable (marked static)");
- return false;
- }
- std::pair<int,std::string> intercount = GetInterfaceInstanceCount(modules[j]);
- if (intercount.first > 0)
- {
- Instance->Log(DEFAULT,"Failed to unload module %s, being used by %d other(s) via interface '%s'",filename, intercount.first, intercount.second.c_str());
- snprintf(MODERR,MAXBUF,"Module not unloadable (Still in use by %d other module%s which %s using its interface '%s') -- unload dependent modules first!",
- intercount.first,
- intercount.first > 1 ? "s" : "",
- intercount.first > 1 ? "are" : "is",
- intercount.second.c_str());
- return false;
- }
- /* Give the module a chance to tidy out all its metadata */
- for (chan_hash::iterator c = Instance->chanlist->begin(); c != Instance->chanlist->end(); c++)
- {
- modules[j]->OnCleanup(TYPE_CHANNEL,c->second);
- }
- for (user_hash::iterator u = Instance->clientlist->begin(); u != Instance->clientlist->end(); u++)
- {
- modules[j]->OnCleanup(TYPE_USER,u->second);
- }