2 * InspIRCd -- Internet Relay Chat Daemon
4 * Copyright (C) 2011 Jackmcbarn <jackmcbarn@jackmcbarn.no-ip.org>
5 * Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org>
6 * Copyright (C) 2006-2008 Craig Edwards <craigedwards@brainbox.cc>
7 * Copyright (C) 2007-2008 Dennis Friis <peavey@inspircd.org>
8 * Copyright (C) 2006-2007 Robin Burchell <robin+git@viroteck.net>
9 * Copyright (C) 2006 John Brooks <john.brooks@dereferenced.net>
11 * This file is part of InspIRCd. InspIRCd is free software: you can
12 * redistribute it and/or modify it under the terms of the GNU General Public
13 * License as published by the Free Software Foundation, version 2.
15 * This program is distributed in the hope that it will be useful, but WITHOUT
16 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
20 * You should have received a copy of the GNU General Public License
21 * along with this program. If not, see <http://www.gnu.org/licenses/>.
25 /* $ModDesc: Allows global loading of a module. */
29 /** Handle /GLOADMODULE
31 class CommandGloadmodule : public Command
34 CommandGloadmodule(Module* Creator) : Command(Creator,"GLOADMODULE", 1)
37 syntax = "<modulename> [servermask]";
38 TRANSLATE3(TR_TEXT, TR_TEXT, TR_END);
41 CmdResult Handle (const std::vector<std::string> ¶meters, User *user)
43 std::string servername = parameters.size() > 1 ? parameters[1] : "*";
45 if (InspIRCd::Match(ServerInstance->Config->ServerName.c_str(), servername))
47 if (ServerInstance->Modules->Load(parameters[0].c_str()))
49 ServerInstance->SNO->WriteToSnoMask('a', "NEW MODULE '%s' GLOBALLY LOADED BY '%s'",parameters[0].c_str(), user->nick.c_str());
50 user->WriteNumeric(975, "%s %s :Module successfully loaded.",user->nick.c_str(), parameters[0].c_str());
54 user->WriteNumeric(974, "%s %s :%s",user->nick.c_str(), parameters[0].c_str(), ServerInstance->Modules->LastError().c_str());
58 ServerInstance->SNO->WriteToSnoMask('a', "MODULE '%s' GLOBAL LOAD BY '%s' (not loaded here)",parameters[0].c_str(), user->nick.c_str());
63 RouteDescriptor GetRouting(User* user, const std::vector<std::string>& parameters)
65 return ROUTE_BROADCAST;
69 /** Handle /GUNLOADMODULE
71 class CommandGunloadmodule : public Command
74 CommandGunloadmodule(Module* Creator) : Command(Creator,"GUNLOADMODULE", 1)
77 syntax = "<modulename> [servermask]";
80 CmdResult Handle (const std::vector<std::string> ¶meters, User *user)
82 std::string servername = parameters.size() > 1 ? parameters[1] : "*";
84 if (InspIRCd::Match(ServerInstance->Config->ServerName.c_str(), servername))
86 Module* m = ServerInstance->Modules->Find(parameters[0]);
87 if (m && ServerInstance->Modules->Unload(m))
89 ServerInstance->SNO->WriteToSnoMask('a', "MODULE '%s' GLOBALLY UNLOADED BY '%s'",parameters[0].c_str(), user->nick.c_str());
90 user->SendText(":%s 973 %s %s :Module successfully unloaded.",
91 ServerInstance->Config->ServerName.c_str(), user->nick.c_str(), parameters[0].c_str());
95 user->WriteNumeric(972, "%s %s :%s",user->nick.c_str(), parameters[0].c_str(), ServerInstance->Modules->LastError().c_str());
99 ServerInstance->SNO->WriteToSnoMask('a', "MODULE '%s' GLOBAL UNLOAD BY '%s' (not unloaded here)",parameters[0].c_str(), user->nick.c_str());
104 RouteDescriptor GetRouting(User* user, const std::vector<std::string>& parameters)
106 return ROUTE_BROADCAST;
110 class GReloadModuleWorker : public HandlerBase1<void, bool>
113 const std::string nick;
114 const std::string name;
115 const std::string uid;
116 GReloadModuleWorker(const std::string& usernick, const std::string& uuid, const std::string& modn)
117 : nick(usernick), name(modn), uid(uuid) {}
118 void Call(bool result)
120 ServerInstance->SNO->WriteToSnoMask('a', "MODULE '%s' GLOBALLY RELOADED BY '%s'%s", name.c_str(), nick.c_str(), result ? "" : " (failed here)");
121 User* user = ServerInstance->FindNick(uid);
123 user->WriteNumeric(975, "%s %s :Module %ssuccessfully reloaded.",
124 user->nick.c_str(), name.c_str(), result ? "" : "un");
125 ServerInstance->GlobalCulls.AddItem(this);
129 /** Handle /GRELOADMODULE
131 class CommandGreloadmodule : public Command
134 CommandGreloadmodule(Module* Creator) : Command(Creator, "GRELOADMODULE", 1)
136 flags_needed = 'o'; syntax = "<modulename> [servermask]";
139 CmdResult Handle(const std::vector<std::string> ¶meters, User *user)
141 std::string servername = parameters.size() > 1 ? parameters[1] : "*";
143 if (InspIRCd::Match(ServerInstance->Config->ServerName.c_str(), servername))
145 Module* m = ServerInstance->Modules->Find(parameters[0]);
147 ServerInstance->Modules->Reload(m, new GReloadModuleWorker(user->nick, user->uuid, parameters[0]));
150 user->WriteNumeric(975, "%s %s :Could not find module by that name", user->nick.c_str(), parameters[0].c_str());
155 ServerInstance->SNO->WriteToSnoMask('a', "MODULE '%s' GLOBAL RELOAD BY '%s' (not reloaded here)",parameters[0].c_str(), user->nick.c_str());
160 RouteDescriptor GetRouting(User* user, const std::vector<std::string>& parameters)
162 return ROUTE_BROADCAST;
166 class ModuleGlobalLoad : public Module
168 CommandGloadmodule cmd1;
169 CommandGunloadmodule cmd2;
170 CommandGreloadmodule cmd3;
174 : cmd1(this), cmd2(this), cmd3(this)
176 ServerInstance->AddCommand(&cmd1);
177 ServerInstance->AddCommand(&cmd2);
178 ServerInstance->AddCommand(&cmd3);
187 return Version("Allows global loading of a module.", VF_COMMON | VF_VENDOR);
191 MODULE_INIT(ModuleGlobalLoad)