]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/commands/cmd_rehash.cpp
Remove out of date doc and fix typo in commands/cmd_*.cpp
[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.
25  */
26 class CommandRehash : public Command
27 {
28  public:
29         /** Constructor for rehash.
30          */
31         CommandRehash ( Module* parent) : Command(parent,"REHASH",0) { flags_needed = 'o'; Penalty = 2; syntax = "[<servermask>]"; }
32         /** Handle command.
33          * @param parameters The parameters to the command
34          * @param user The user issuing the command
35          * @return A value from CmdResult to indicate command success or failure.
36          */
37         CmdResult Handle(const std::vector<std::string>& parameters, User *user);
38 };
39
40 CmdResult CommandRehash::Handle (const std::vector<std::string>& parameters, User *user)
41 {
42         std::string param = parameters.size() ? parameters[0] : "";
43
44         FOREACH_MOD(OnPreRehash, (user, param));
45
46         if (param.empty())
47         {
48                 // standard rehash of local server
49         }
50         else if (param.find_first_of("*.") != std::string::npos)
51         {
52                 // rehash of servers by server name (with wildcard)
53                 if (!InspIRCd::Match(ServerInstance->Config->ServerName, parameters[0]))
54                 {
55                         // Doesn't match us. PreRehash is already done, nothing left to do
56                         return CMD_SUCCESS;
57                 }
58         }
59         else
60         {
61                 // parameterized rehash
62
63                 // the leading "-" is optional; remove it if present.
64                 if (param[0] == '-')
65                         param = param.substr(1);
66
67                 FOREACH_MOD(OnModuleRehash, (user, param));
68                 return CMD_SUCCESS;
69         }
70
71         // Rehash for me. Try to start the rehash thread
72         if (!ServerInstance->ConfigThread)
73         {
74                 std::string m = user->nick + " is rehashing config file " + FileSystem::GetFileName(ServerInstance->ConfigFileName) + " on " + ServerInstance->Config->ServerName;
75                 ServerInstance->SNO->WriteGlobalSno('a', m);
76
77                 if (IS_LOCAL(user))
78                         user->WriteNumeric(RPL_REHASHING, "%s :Rehashing", FileSystem::GetFileName(ServerInstance->ConfigFileName).c_str());
79                 else
80                         ServerInstance->PI->SendUserNotice(user, "*** Rehashing server " + FileSystem::GetFileName(ServerInstance->ConfigFileName));
81
82                 /* Don't do anything with the logs here -- logs are restarted
83                  * after the config thread has completed.
84                  */
85                 ServerInstance->Rehash(user->uuid);
86         }
87         else
88         {
89                 /*
90                  * A rehash is already in progress! ahh shit.
91                  * XXX, todo: we should find some way to kill runaway rehashes that are blocking, this is a major problem for unrealircd users
92                  */
93                 if (IS_LOCAL(user))
94                         user->WriteNotice("*** Could not rehash: A rehash is already in progress.");
95                 else
96                         ServerInstance->PI->SendUserNotice(user, "*** Could not rehash: A rehash is already in progress.");
97         }
98
99         // Always return success so spanningtree forwards an incoming REHASH even if we failed
100         return CMD_SUCCESS;
101 }
102
103
104 COMMAND_INIT(CommandRehash)