]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/commands/cmd_rehash.cpp
1fa72696243ef9d8fcf087b44ba4372aff61428f
[user/henk/code/inspircd.git] / src / commands / cmd_rehash.cpp
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  *   Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org>
5  *   Copyright (C) 2007-2008 Robin Burchell <robin+git@viroteck.net>
6  *   Copyright (C) 2008 Craig Edwards <craigedwards@brainbox.cc>
7  *
8  * This file is part of InspIRCd.  InspIRCd is free software: you can
9  * redistribute it and/or modify it under the terms of the GNU General Public
10  * License as published by the Free Software Foundation, version 2.
11  *
12  * This program is distributed in the hope that it will be useful, but WITHOUT
13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
15  * details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
19  */
20
21
22 #include "inspircd.h"
23
24 /** Handle /REHASH. These command handlers can be reloaded by the core,
25  * and handle basic RFC1459 commands. Commands within modules work
26  * the same way, however, they can be fully unloaded, where these
27  * may not.
28  */
29 class CommandRehash : public Command
30 {
31  public:
32         /** Constructor for rehash.
33          */
34         CommandRehash ( Module* parent) : Command(parent,"REHASH",0) { flags_needed = 'o'; Penalty = 2; syntax = "[<servermask>]"; }
35         /** Handle command.
36          * @param parameters The parameters to the comamnd
37          * @param pcnt The number of parameters passed to teh command
38          * @param user The user issuing the command
39          * @return A value from CmdResult to indicate command success or failure.
40          */
41         CmdResult Handle(const std::vector<std::string>& parameters, User *user);
42 };
43
44 CmdResult CommandRehash::Handle (const std::vector<std::string>& parameters, User *user)
45 {
46         std::string param = parameters.size() ? parameters[0] : "";
47
48         FOREACH_MOD(OnPreRehash, (user, param));
49
50         if (param.empty())
51         {
52                 // standard rehash of local server
53         }
54         else if (param.find_first_of("*.") != std::string::npos)
55         {
56                 // rehash of servers by server name (with wildcard)
57                 if (!InspIRCd::Match(ServerInstance->Config->ServerName, parameters[0]))
58                 {
59                         // Doesn't match us. PreRehash is already done, nothing left to do
60                         return CMD_SUCCESS;
61                 }
62         }
63         else
64         {
65                 // parameterized rehash
66
67                 // the leading "-" is optional; remove it if present.
68                 if (param[0] == '-')
69                         param = param.substr(1);
70
71                 FOREACH_MOD(OnModuleRehash, (user, param));
72                 return CMD_SUCCESS;
73         }
74
75         // Rehash for me. Try to start the rehash thread
76         if (!ServerInstance->ConfigThread)
77         {
78                 std::string m = user->nick + " is rehashing config file " + ServerConfig::CleanFilename(ServerInstance->ConfigFileName.c_str()) + " on " + ServerInstance->Config->ServerName;
79                 ServerInstance->SNO->WriteGlobalSno('a', m);
80
81                 if (IS_LOCAL(user))
82                         user->WriteNumeric(RPL_REHASHING, "%s :Rehashing",
83                                 ServerConfig::CleanFilename(ServerInstance->ConfigFileName.c_str()));
84                 else
85                         ServerInstance->PI->SendUserNotice(user, std::string("*** Rehashing server ") +
86                                 ServerConfig::CleanFilename(ServerInstance->ConfigFileName.c_str()));
87
88                 /* Don't do anything with the logs here -- logs are restarted
89                  * after the config thread has completed.
90                  */
91                 ServerInstance->Rehash(user->uuid);
92         }
93         else
94         {
95                 /*
96                  * A rehash is already in progress! ahh shit.
97                  * XXX, todo: we should find some way to kill runaway rehashes that are blocking, this is a major problem for unrealircd users
98                  */
99                 if (IS_LOCAL(user))
100                         user->WriteNotice("*** Could not rehash: A rehash is already in progress.");
101                 else
102                         ServerInstance->PI->SendUserNotice(user, "*** Could not rehash: A rehash is already in progress.");
103         }
104
105         // Always return success so spanningtree forwards an incoming REHASH even if we failed
106         return CMD_SUCCESS;
107 }
108
109
110 COMMAND_INIT(CommandRehash)