From 992674362c5f64bdb8e1942eeaa7612524529cd6 Mon Sep 17 00:00:00 2001 From: attilamolnar Date: Sun, 26 May 2013 19:44:13 +0200 Subject: Automatically register ServiceProviders created by modules --- src/modmanager_static.cpp | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) (limited to 'src/modmanager_static.cpp') diff --git a/src/modmanager_static.cpp b/src/modmanager_static.cpp index 7d6c89258..76f16fa92 100644 --- a/src/modmanager_static.cpp +++ b/src/modmanager_static.cpp @@ -58,7 +58,6 @@ class AllModule : public Module { Command* c = (*i)(this); cmds.push_back(c); - ServerInstance->Modules->AddService(*c); } } catch (...) @@ -88,6 +87,11 @@ bool ModuleManager::Load(const std::string& name, bool defer) if (it == modlist->end()) return false; Module* mod = NULL; + + ServiceList newservices; + if (!defer) + this->NewServices = &newservices; + try { mod = (*it->second->init)(); @@ -95,6 +99,7 @@ bool ModuleManager::Load(const std::string& name, bool defer) mod->ModuleDLLManager = NULL; mod->dying = false; Modules[name] = mod; + this->NewServices = NULL; if (defer) { ServerInstance->Logs->Log("MODULE", LOG_DEFAULT, "New module introduced: %s", name.c_str()); @@ -105,12 +110,15 @@ bool ModuleManager::Load(const std::string& name, bool defer) ConfigStatus confstatus; AttachAll(mod); + AddServices(newservices); mod->init(); mod->ReadConfig(confstatus); } } catch (CoreException& modexcept) { + this->NewServices = NULL; + if (mod) DoSafeUnload(mod); ServerInstance->Logs->Log("MODULE", LOG_DEFAULT, "Unable to load " + name + ": " + modexcept.GetReason()); @@ -123,12 +131,18 @@ bool ModuleManager::Load(const std::string& name, bool defer) return true; } -void ModuleManager::LoadCoreModules() +void ModuleManager::LoadCoreModules(std::map& servicemap) { - Load("cmd_all.so", true); - Load("cmd_whowas.so", true); - Load("cmd_lusers.so", true); - Load("cmd_privmsg.so", true); + for (modmap::const_iterator i = modlist->begin(); i != modlist->end(); ++i) + { + const std::string modname = i->first; + if (modname[0] == 'c') + { + this->NewServices = &servicemap[modname]; + Load(modname, true); + } + } + this->NewServices = NULL; } #endif -- cgit v1.2.3