]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/commands/cmd_reloadmodule.cpp
765c465fde6dec30f97c30b6a10a2e9079fa660b
[user/henk/code/inspircd.git] / src / commands / cmd_reloadmodule.cpp
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  *   Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org>
5  *   Copyright (C) 2007 Robin Burchell <robin+git@viroteck.net>
6  *
7  * This file is part of InspIRCd.  InspIRCd is free software: you can
8  * redistribute it and/or modify it under the terms of the GNU General Public
9  * License as published by the Free Software Foundation, version 2.
10  *
11  * This program is distributed in the hope that it will be useful, but WITHOUT
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
14  * details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18  */
19
20
21 #include "inspircd.h"
22
23 class CommandReloadmodule : public Command
24 {
25  public:
26         /** Constructor for reloadmodule.
27          */
28         CommandReloadmodule ( Module* parent) : Command( parent, "RELOADMODULE",1) { flags_needed = 'o'; syntax = "<modulename>"; }
29         /** Handle command.
30          * @param parameters The parameters to the command
31          * @param user The user issuing the command
32          * @return A value from CmdResult to indicate command success or failure.
33          */
34         CmdResult Handle(const std::vector<std::string>& parameters, User *user);
35 };
36
37 class ReloadModuleWorker : public HandlerBase1<void, bool>
38 {
39  public:
40         const std::string name;
41         const std::string uid;
42         ReloadModuleWorker(const std::string& uuid, const std::string& modn)
43                 : name(modn), uid(uuid) {}
44         void Call(bool result)
45         {
46                 ServerInstance->SNO->WriteGlobalSno('a', "RELOAD MODULE: %s %ssuccessfully reloaded",
47                         name.c_str(), result ? "" : "un");
48                 User* user = ServerInstance->FindNick(uid);
49                 if (user)
50                         user->WriteNumeric(RPL_LOADEDMODULE, "%s :Module %ssuccessfully reloaded.",
51                                 name.c_str(), result ? "" : "un");
52                 ServerInstance->GlobalCulls.AddItem(this);
53         }
54 };
55
56 CmdResult CommandReloadmodule::Handle (const std::vector<std::string>& parameters, User *user)
57 {
58         if (parameters[0] == "cmd_reloadmodule.so")
59         {
60                 user->WriteNumeric(RPL_LOADEDMODULE, "%s :You cannot reload cmd_reloadmodule.so (unload and load it)",
61                         parameters[0].c_str());
62                 return CMD_FAILURE;
63         }
64
65         Module* m = ServerInstance->Modules->Find(parameters[0]);
66         if (m)
67         {
68                 ServerInstance->Modules->Reload(m, new ReloadModuleWorker(user->uuid, parameters[0]));
69                 return CMD_SUCCESS;
70         }
71         else
72         {
73                 user->WriteNumeric(RPL_LOADEDMODULE, "%s :Could not find module by that name", parameters[0].c_str());
74                 return CMD_FAILURE;
75         }
76 }
77
78 COMMAND_INIT(CommandReloadmodule)