2 * InspIRCd -- Internet Relay Chat Daemon
4 * Copyright (C) 2009-2010 Daniel De Graaf <danieldg@inspircd.org>
6 * This file is part of InspIRCd. InspIRCd is free software: you can
7 * redistribute it and/or modify it under the terms of the GNU General Public
8 * License as published by the Free Software Foundation, version 2.
10 * This program is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 #define MODNAME "cmd_all"
23 #include "exitcodes.h"
28 typedef std::map<std::string, AllModuleList*> modmap;
29 static std::vector<AllCommandList::fn>* cmdlist = NULL;
30 static modmap* modlist = NULL;
32 AllCommandList::AllCommandList(fn cmd)
35 cmdlist = new std::vector<AllCommandList::fn>();
36 cmdlist->push_back(cmd);
39 AllModuleList::AllModuleList(AllModuleList::fn mod, const std::string& Name) : init(mod), name(Name)
42 modlist = new modmap();
43 modlist->insert(std::make_pair(Name, this));
46 class AllModule : public Module
48 std::vector<Command*> cmds;
56 cmds.reserve(cmdlist->size());
57 for(std::vector<AllCommandList::fn>::iterator i = cmdlist->begin(); i != cmdlist->end(); ++i)
59 Command* c = (*i)(this);
65 this->AllModule::~AllModule();
72 stdalgo::delete_all(cmds);
77 return Version("All commands", VF_VENDOR|VF_CORE);
81 MODULE_INIT(AllModule)
83 bool ModuleManager::Load(const std::string& name, bool defer)
85 modmap::iterator it = modlist->find(name);
86 if (it == modlist->end())
90 ServiceList newservices;
92 this->NewServices = &newservices;
96 mod = (*it->second->init)();
97 mod->ModuleSourceFile = name;
98 mod->ModuleDLLManager = NULL;
101 this->NewServices = NULL;
104 ServerInstance->Logs->Log("MODULE", LOG_DEFAULT, "New module introduced: %s", name.c_str());
109 ConfigStatus confstatus;
112 AddServices(newservices);
114 mod->ReadConfig(confstatus);
117 catch (CoreException& modexcept)
119 this->NewServices = NULL;
123 ServerInstance->Logs->Log("MODULE", LOG_DEFAULT, "Unable to load " + name + ": " + modexcept.GetReason());
127 FOREACH_MOD(OnLoadModule, (mod));
129 ServerInstance->ISupport.Build();
133 void ModuleManager::LoadCoreModules(std::map<std::string, ServiceList>& servicemap)
135 for (modmap::const_iterator i = modlist->begin(); i != modlist->end(); ++i)
137 const std::string modname = i->first;
138 if (modname[0] == 'c')
140 this->NewServices = &servicemap[modname];
144 this->NewServices = NULL;