- printf("\n");
- }
-
- ConfigTagList tags = ServerInstance->Config->ConfTags("module");
- for(ConfigIter i = tags.first; i != tags.second; ++i)
- {
- ConfigTag* tag = i->second;
- std::string name = tag->getString("name");
- printf_c("[\033[1;32m*\033[0m] Loading module:\t\033[1;32m%s\033[0m\n",name.c_str());
-
- if (!this->Load(name, true))
- {
- ServerInstance->Logs->Log("MODULE", DEFAULT, this->LastError());
- printf_c("\n[\033[1;31m*\033[0m] %s\n\n", this->LastError().c_str());
- ServerInstance->Exit(EXIT_STATUS_MODULE);
- }
- }
-
- for(std::map<std::string, Module*>::iterator i = Modules.begin(); i != Modules.end(); i++)
- {
- Module* mod = i->second;
- try
- {
- mod->init();
- }
- catch (CoreException& modexcept)
- {
- LastModuleError = "Unable to initialize " + mod->ModuleSourceFile + ": " + modexcept.GetReason();
- ServerInstance->Logs->Log("MODULE", DEFAULT, LastModuleError);
- printf_c("\n[\033[1;31m*\033[0m] %s\n\n", LastModuleError.c_str());
- ServerInstance->Exit(EXIT_STATUS_MODULE);
- }
- }
-
- /* We give every module a chance to re-prioritize when we introduce a new one,
- * not just the one thats loading, as the new module could affect the preference
- * of others
- */
- for(int tries = 0; tries < 20; tries++)
- {
- prioritizationState = tries > 0 ? PRIO_STATE_LAST : PRIO_STATE_FIRST;
- for (std::map<std::string, Module*>::iterator n = Modules.begin(); n != Modules.end(); ++n)
- n->second->Prioritize();
-
- if (prioritizationState == PRIO_STATE_LAST)
- break;
- if (tries == 19)
- {
- ServerInstance->Logs->Log("MODULE", DEFAULT, "Hook priority dependency loop detected");
- ServerInstance->Exit(EXIT_STATUS_MODULE);
- }
- }
-}
-
-void ModuleManager::UnloadAll()
-{
- /* We do this more than once, so that any service providers get a
- * chance to be unhooked by the modules using them, but then get
- * a chance to be removed themsleves.
- *
- * Note: this deliberately does NOT delete the DLLManager objects
- */
- for (int tries = 0; tries < 4; tries++)
- {
- std::map<std::string, Module*>::iterator i = Modules.begin();
- while (i != Modules.end())
- {
- std::map<std::string, Module*>::iterator me = i++;
- if (CanUnload(me->second))
- {
- DoSafeUnload(me->second);
- }
- }
- ServerInstance->GlobalCulls.Apply();