]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/commands/cmd_reloadmodule.cpp
Don't submit a reload worker if the module doing the reload is scheduled for unload
[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 comamnd
31          * @param pcnt The number of parameters passed to teh command
32          * @param user The user issuing the command
33          * @return A value from CmdResult to indicate command success or failure.
34          */
35         CmdResult Handle(const std::vector<std::string>& parameters, User *user);
36 };
37
38 class ReloadModuleWorker : public HandlerBase1<void, bool>
39 {
40  public:
41         const std::string name;
42         const std::string uid;
43         ReloadModuleWorker(const std::string& uuid, const std::string& modn)
44                 : name(modn), uid(uuid) {}
45         void Call(bool result)
46         {
47                 ServerInstance->SNO->WriteGlobalSno('a', "RELOAD MODULE: %s %ssuccessfully reloaded",
48                         name.c_str(), result ? "" : "un");
49                 User* user = ServerInstance->FindNick(uid);
50                 if (user)
51                         user->WriteNumeric(975, "%s %s :Module %ssuccessfully reloaded.",
52                                 user->nick.c_str(), name.c_str(), result ? "" : "un");
53                 ServerInstance->GlobalCulls.AddItem(this);
54         }
55 };
56
57 CmdResult CommandReloadmodule::Handle (const std::vector<std::string>& parameters, User *user)
58 {
59         if (parameters[0] == "cmd_reloadmodule.so")
60         {
61                 user->WriteNumeric(975, "%s %s :You cannot reload cmd_reloadmodule.so (unload and load it)",
62                         user->nick.c_str(), parameters[0].c_str());
63                 return CMD_FAILURE;
64         }
65
66         Module* m = ServerInstance->Modules->Find(parameters[0]);
67         if (m)
68         {
69                 ServerInstance->Modules->Reload(m, (creator->dying ? NULL : new ReloadModuleWorker(user->uuid, parameters[0])));
70                 return CMD_SUCCESS;
71         }
72         else
73         {
74                 user->WriteNumeric(975, "%s %s :Could not find module by that name", user->nick.c_str(), parameters[0].c_str());
75                 return CMD_FAILURE;
76         }
77 }
78
79 COMMAND_INIT(CommandReloadmodule)