- if (modfind != Modules.end())
- {
- if (modfind->second.second->GetVersion().Flags & VF_STATIC)
- {
- LastModuleError = "Module " + filename_str + " not unloadable (marked static)";
- Instance->Logs->Log("MODULE", DEFAULT, LastModuleError);
- return false;
- }
- std::pair<int,std::string> intercount = GetInterfaceInstanceCount(modfind->second.second);
- if (intercount.first > 0)
- {
- LastModuleError = "Failed to unload module " + filename_str + ", being used by " + ConvToStr(intercount.first) + " other(s) via interface '" + intercount.second + "'";
- Instance->Logs->Log("MODULE", DEFAULT, LastModuleError);
- 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++)
- {
- modfind->second.second->OnCleanup(TYPE_CHANNEL,c->second);
- }
- for (user_hash::iterator u = Instance->Users->clientlist->begin(); u != Instance->Users->clientlist->end(); u++)
- {
- modfind->second.second->OnCleanup(TYPE_USER,u->second);
- }
-
- /* Tidy up any dangling resolvers */
- Instance->Res->CleanResolvers(modfind->second.second);
-
-
- FOREACH_MOD_I(Instance,I_OnUnloadModule,OnUnloadModule(modfind->second.second, modfind->first));
-
- this->DetachAll(modfind->second.second);
-
- Instance->Parser->RemoveCommands(modfind->second.second);
- Extensible::UnRegister(modfind->second.second);
-
- delete modfind->second.second;
- delete modfind->second.first;
- Modules.erase(modfind);
-
- Instance->Logs->Log("MODULE", DEFAULT,"Module %s unloaded",filename);
- this->ModCount--;
- Instance->BuildISupport();
- return true;
- }
-
- LastModuleError = "Module " + filename_str + " is not loaded, cannot unload it!";
- Instance->Logs->Log("MODULE", DEFAULT, LastModuleError);
- return false;