1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2007 InspIRCd Development Team
6 * See: http://www.inspircd.org/wiki/index.php/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 (InspIRCd* Instance) : Command(Instance,"GLOADMODULE", 'o', 1)
25 this->source = "m_globalload.so";
26 syntax = "<modulename> [servermask]";
27 TRANSLATE3(TR_TEXT, TR_TEXT, TR_END);
30 CmdResult Handle (const char** parameters, int pcnt, User *user)
32 std::string servername = pcnt > 1 ? parameters[1] : "*";
34 if (ServerInstance->MatchText(ServerInstance->Config->ServerName, servername))
36 if (ServerInstance->Modules->Load(parameters[0]))
38 ServerInstance->WriteOpers("*** NEW MODULE '%s' GLOBALLY LOADED BY '%s'",parameters[0],user->nick);
39 user->WriteServ("975 %s %s :Module successfully loaded.",user->nick, parameters[0]);
43 user->WriteServ("974 %s %s :Failed to load module: %s",user->nick, parameters[0],ServerInstance->Modules->LastError());
47 ServerInstance->WriteOpers("*** MODULE '%s' GLOBAL LOAD BY '%s' (not loaded here)",parameters[0],user->nick);
53 /** Handle /GUNLOADMODULE
55 class CommandGunloadmodule : public Command
58 CommandGunloadmodule (InspIRCd* Instance) : Command(Instance,"GUNLOADMODULE", 'o', 1)
60 this->source = "m_globalload.so";
61 syntax = "<modulename> [servermask]";
64 CmdResult Handle (const char** parameters, int pcnt, User *user)
66 std::string servername = pcnt > 1 ? parameters[1] : "*";
68 if (ServerInstance->MatchText(ServerInstance->Config->ServerName, servername))
70 if (ServerInstance->Modules->Unload(parameters[0]))
72 ServerInstance->WriteOpers("*** MODULE '%s' GLOBALLY UNLOADED BY '%s'",parameters[0],user->nick);
73 user->WriteServ("973 %s %s :Module successfully unloaded.",user->nick, parameters[0]);
77 user->WriteServ("972 %s %s :Failed to unload module: %s",user->nick, parameters[0],ServerInstance->Modules->LastError());
81 ServerInstance->WriteOpers("*** MODULE '%s' GLOBAL UNLOAD BY '%s' (not unloaded here)",parameters[0],user->nick);
87 /** Handle /GRELOADMODULE
89 class CommandGreloadmodule : public Command
92 CommandGreloadmodule (InspIRCd* Instance) : Command(Instance, "GRELOADMODULE", 'o', 1)
94 this->source = "m_globalload.so";
95 syntax = "<modulename> [servermask]";
98 CmdResult Handle(const char** parameters, int pcnt, User *user)
100 std::string servername = pcnt > 1 ? parameters[1] : "*";
102 if (ServerInstance->MatchText(ServerInstance->Config->ServerName, servername))
104 if (!ServerInstance->Modules->Unload(parameters[0]))
106 user->WriteServ("972 %s %s :Failed to unload module: %s",user->nick, parameters[0],ServerInstance->Modules->LastError());
108 if (!ServerInstance->Modules->Load(parameters[0]))
110 user->WriteServ("974 %s %s :Failed to load module: %s",user->nick, parameters[0],ServerInstance->Modules->LastError());
112 ServerInstance->WriteOpers("*** MODULE '%s' GLOBALLY RELOADED BY '%s'",parameters[0],user->nick);
113 user->WriteServ("975 %s %s :Module successfully loaded.",user->nick, parameters[0]);
116 ServerInstance->WriteOpers("*** MODULE '%s' GLOBAL RELOAD BY '%s' (not reloaded here)",parameters[0],user->nick);
122 class ModuleGlobalLoad : public Module
124 CommandGloadmodule *mycommand;
125 CommandGunloadmodule *mycommand2;
126 CommandGreloadmodule *mycommand3;
129 ModuleGlobalLoad(InspIRCd* Me) : Module(Me)
132 mycommand = new CommandGloadmodule(ServerInstance);
133 mycommand2 = new CommandGunloadmodule(ServerInstance);
134 mycommand3 = new CommandGreloadmodule(ServerInstance);
135 ServerInstance->AddCommand(mycommand);
136 ServerInstance->AddCommand(mycommand2);
137 ServerInstance->AddCommand(mycommand3);
140 virtual ~ModuleGlobalLoad()
144 virtual Version GetVersion()
146 return Version(1, 1, 0, 0, VF_COMMON | VF_VENDOR, API_VERSION);
150 MODULE_INIT(ModuleGlobalLoad)