1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2010 InspIRCd Development Team
6 * See: http://wiki.inspircd.org/Credits
8 * This program is free but copyrighted software; see
9 * the file COPYING for details.
11 * ---------------------------------------------------
14 /* $ModDesc: Allows global loading of a module. */
18 /** Handle /GLOADMODULE
20 class CommandGloadmodule : public Command
23 CommandGloadmodule(Module* Creator) : Command(Creator,"GLOADMODULE", 1)
26 syntax = "<modulename> [servermask]";
27 TRANSLATE3(TR_TEXT, TR_TEXT, TR_END);
30 CmdResult Handle (const std::vector<std::string> ¶meters, User *user)
32 std::string servername = parameters.size() > 1 ? parameters[1] : "*";
34 if (InspIRCd::Match(ServerInstance->Config->ServerName.c_str(), servername))
36 if (ServerInstance->Modules->Load(parameters[0].c_str()))
38 ServerInstance->SNO->WriteToSnoMask('a', "NEW MODULE '%s' GLOBALLY LOADED BY '%s'",parameters[0].c_str(), user->nick.c_str());
39 user->WriteNumeric(975, "%s %s :Module successfully loaded.",user->nick.c_str(), parameters[0].c_str());
43 user->WriteNumeric(974, "%s %s :%s",user->nick.c_str(), parameters[0].c_str(), ServerInstance->Modules->LastError().c_str());
47 ServerInstance->SNO->WriteToSnoMask('a', "MODULE '%s' GLOBAL LOAD BY '%s' (not loaded here)",parameters[0].c_str(), user->nick.c_str());
52 RouteDescriptor GetRouting(User* user, const std::vector<std::string>& parameters)
54 return ROUTE_BROADCAST;
58 /** Handle /GUNLOADMODULE
60 class CommandGunloadmodule : public Command
63 CommandGunloadmodule(Module* Creator) : Command(Creator,"GUNLOADMODULE", 1)
66 syntax = "<modulename> [servermask]";
69 CmdResult Handle (const std::vector<std::string> ¶meters, User *user)
71 std::string servername = parameters.size() > 1 ? parameters[1] : "*";
73 if (InspIRCd::Match(ServerInstance->Config->ServerName.c_str(), servername))
75 Module* m = ServerInstance->Modules->Find(parameters[0]);
76 if (m && ServerInstance->Modules->Unload(m))
78 ServerInstance->SNO->WriteToSnoMask('a', "MODULE '%s' GLOBALLY UNLOADED BY '%s'",parameters[0].c_str(), user->nick.c_str());
79 user->SendText(":%s 973 %s %s :Module successfully unloaded.",
80 ServerInstance->Config->ServerName.c_str(), user->nick.c_str(), parameters[0].c_str());
84 user->WriteNumeric(972, "%s %s :%s",user->nick.c_str(), parameters[0].c_str(), ServerInstance->Modules->LastError().c_str());
88 ServerInstance->SNO->WriteToSnoMask('a', "MODULE '%s' GLOBAL UNLOAD BY '%s' (not unloaded here)",parameters[0].c_str(), user->nick.c_str());
93 RouteDescriptor GetRouting(User* user, const std::vector<std::string>& parameters)
95 return ROUTE_BROADCAST;
99 class GReloadModuleWorker : public HandlerBase1<void, bool>
102 const std::string nick;
103 const std::string name;
104 const std::string uid;
105 GReloadModuleWorker(const std::string& usernick, const std::string& uuid, const std::string& modn)
106 : nick(usernick), name(modn), uid(uuid) {}
107 void Call(bool result)
109 ServerInstance->SNO->WriteToSnoMask('a', "MODULE '%s' GLOBALLY RELOADED BY '%s'%s", name.c_str(), nick.c_str(), result ? "" : " (failed here)");
110 User* user = ServerInstance->FindNick(uid);
112 user->WriteNumeric(975, "%s %s :Module %ssuccessfully reloaded.",
113 user->nick.c_str(), name.c_str(), result ? "" : "un");
114 ServerInstance->GlobalCulls.AddItem(this);
118 /** Handle /GRELOADMODULE
120 class CommandGreloadmodule : public Command
123 CommandGreloadmodule(Module* Creator) : Command(Creator, "GRELOADMODULE", 1)
125 flags_needed = 'o'; syntax = "<modulename> [servermask]";
128 CmdResult Handle(const std::vector<std::string> ¶meters, User *user)
130 std::string servername = parameters.size() > 1 ? parameters[1] : "*";
132 if (InspIRCd::Match(ServerInstance->Config->ServerName.c_str(), servername))
134 Module* m = ServerInstance->Modules->Find(parameters[0]);
136 ServerInstance->Modules->Reload(m, new GReloadModuleWorker(user->nick, user->uuid, parameters[0]));
139 user->WriteNumeric(975, "%s %s :Could not find module by that name", user->nick.c_str(), parameters[0].c_str());
144 ServerInstance->SNO->WriteToSnoMask('a', "MODULE '%s' GLOBAL RELOAD BY '%s' (not reloaded here)",parameters[0].c_str(), user->nick.c_str());
149 RouteDescriptor GetRouting(User* user, const std::vector<std::string>& parameters)
151 return ROUTE_BROADCAST;
155 class ModuleGlobalLoad : public Module
157 CommandGloadmodule cmd1;
158 CommandGunloadmodule cmd2;
159 CommandGreloadmodule cmd3;
163 : cmd1(this), cmd2(this), cmd3(this)
165 ServerInstance->AddCommand(&cmd1);
166 ServerInstance->AddCommand(&cmd2);
167 ServerInstance->AddCommand(&cmd3);
176 return Version("Allows global loading of a module.", VF_COMMON | VF_VENDOR);
180 MODULE_INIT(ModuleGlobalLoad)