]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/commands/cmd_reloadmodule.cpp
...because every now and again, i have to do a massive commit.
[user/henk/code/inspircd.git] / src / commands / cmd_reloadmodule.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2010 InspIRCd Development Team
6  * See: http://wiki.inspircd.org/Credits
7  *
8  * This program is free but copyrighted software; see
9  *            the file COPYING for details.
10  *
11  * ---------------------------------------------------
12  */
13
14 #include "inspircd.h"
15
16 class CommandReloadmodule : public Command
17 {
18  public:
19         /** Constructor for reloadmodule.
20          */
21         CommandReloadmodule ( Module* parent) : Command( parent, "RELOADMODULE",1) { flags_needed = 'o'; syntax = "<modulename>"; }
22         /** Handle command.
23          * @param parameters The parameters to the comamnd
24          * @param pcnt The number of parameters passed to teh command
25          * @param user The user issuing the command
26          * @return A value from CmdResult to indicate command success or failure.
27          */
28         CmdResult Handle(const std::vector<std::string>& parameters, User *user);
29 };
30
31 class ReloadModuleWorker : public HandlerBase1<void, bool>
32 {
33  public:
34         const std::string name;
35         const std::string uid;
36         ReloadModuleWorker(const std::string& uuid, const std::string& modn)
37                 : name(modn), uid(uuid) {}
38         void Call(bool result)
39         {
40                 ServerInstance->SNO->WriteGlobalSno('a', "RELOAD MODULE: %s %ssuccessfully reloaded",
41                         name.c_str(), result ? "" : "un");
42                 User* user = ServerInstance->FindNick(uid);
43                 if (user)
44                         user->WriteNumeric(975, "%s %s :Module %ssuccessfully reloaded.",
45                                 user->nick.c_str(), name.c_str(), result ? "" : "un");
46                 ServerInstance->GlobalCulls.AddItem(this);
47         }
48 };
49
50 CmdResult CommandReloadmodule::Handle (const std::vector<std::string>& parameters, User *user)
51 {
52         if (parameters[0] == "cmd_reloadmodule.so")
53         {
54                 user->WriteNumeric(975, "%s %s :You cannot reload cmd_reloadmodule.so (unload and load it)",
55                         user->nick.c_str(), parameters[0].c_str());
56                 return CMD_FAILURE;
57         }
58
59         Module* m = ServerInstance->Modules->Find(parameters[0]);
60         if (m)
61         {
62                 ServerInstance->Modules->Reload(m, new ReloadModuleWorker(user->uuid, parameters[0]));
63                 return CMD_SUCCESS;
64         }
65         else
66         {
67                 user->WriteNumeric(975, "%s %s :Could not find module by that name", user->nick.c_str(), parameters[0].c_str());
68                 return CMD_FAILURE;
69         }
70 }
71
72 COMMAND_INIT(CommandReloadmodule)