+
+ 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);
+ }
+ }