Module* ModuleManager::Find(const std::string &name) { std::map<std::string, Module*>::const_iterator modfind = Modules.find(ExpandModName(name)); if (modfind == Modules.end()) return NULL; else return modfind->second; }
bool ModuleManager::Load(const std::string& modname, bool defer) { /* Don't allow people to specify paths for modules, it doesn't work as expected */ if (modname.find('/') != std::string::npos) { LastModuleError = "You can't load modules with a path: " + modname; return false; } const std::string filename = ExpandModName(modname); const std::string moduleFile = ServerInstance->Config->Paths.PrependModule(filename); if (!FileSystem::FileExists(moduleFile)) { LastModuleError = "Module file could not be found: " + filename; ServerInstance->Logs->Log("MODULE", LOG_DEFAULT, LastModuleError); return false; } if (Modules.find(filename) != Modules.end()) { LastModuleError = "Module " + filename + " is already loaded, cannot load a module twice!"; ServerInstance->Logs->Log("MODULE", LOG_DEFAULT, LastModuleError); return false; } Module* newmod = NULL; DLLManager* newhandle = new DLLManager(moduleFile.c_str()); ServiceList newservices; if (!defer) this->NewServices = &newservices; try { newmod = newhandle->CallInit(); this->NewServices = NULL; if (newmod) { newmod->ModuleSourceFile = filename; newmod->ModuleDLLManager = newhandle; newmod->dying = false; Modules[filename] = newmod; std::string version = newhandle->GetVersion(); if (defer) { ServerInstance->Logs->Log("MODULE", LOG_DEFAULT, "New module introduced: %s (Module version %s)", filename.c_str(), version.c_str()); } else { ConfigStatus confstatus; AttachAll(newmod); AddServices(newservices); newmod->init(); newmod->ReadConfig(confstatus); Version v = newmod->GetVersion(); ServerInstance->Logs->Log("MODULE", LOG_DEFAULT, "New module introduced: %s (Module version %s)%s", filename.c_str(), version.c_str(), (!(v.Flags & VF_VENDOR) ? " [3rd Party]" : " [Vendor]")); } } else { LastModuleError = "Unable to load " + filename + ": " + newhandle->LastError(); ServerInstance->Logs->Log("MODULE", LOG_DEFAULT, LastModuleError); delete newhandle; return false; } } catch (CoreException& modexcept) { this->NewServices = NULL; // failure in module constructor if (newmod) { DoSafeUnload(newmod); ServerInstance->GlobalCulls.AddItem(newhandle); } else delete newhandle; LastModuleError = "Unable to load " + filename + ": " + modexcept.GetReason(); ServerInstance->Logs->Log("MODULE", LOG_DEFAULT, LastModuleError); return false; } if (defer) return true; FOREACH_MOD(OnLoadModule, (newmod)); PrioritizeHooks(); ServerInstance->ISupport.Build(); return true; }