]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/coremods/core_oper/cmd_rehash.cpp
Make rehashing messages more consistent.
[user/henk/code/inspircd.git] / src / coremods / core_oper / 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 #include "core_oper.h"
24
25 CommandRehash::CommandRehash(Module* parent)
26         : Command(parent, "REHASH", 0)
27 {
28         flags_needed = 'o';
29         Penalty = 2;
30         syntax = "[<servermask>]";
31 }
32
33 CmdResult CommandRehash::Handle(User* user, const Params& parameters)
34 {
35         std::string param = parameters.size() ? parameters[0] : "";
36
37         FOREACH_MOD(OnPreRehash, (user, param));
38
39         if (param.empty())
40         {
41                 // standard rehash of local server
42         }
43         else if (param.find_first_of("*.") != std::string::npos)
44         {
45                 // rehash of servers by server name (with wildcard)
46                 if (!InspIRCd::Match(ServerInstance->Config->ServerName, parameters[0]))
47                 {
48                         // Doesn't match us. PreRehash is already done, nothing left to do
49                         return CMD_SUCCESS;
50                 }
51         }
52         else
53         {
54                 // parameterized rehash
55
56                 // the leading "-" is optional; remove it if present.
57                 if (param[0] == '-')
58                         param.erase(param.begin());
59
60                 FOREACH_MOD(OnModuleRehash, (user, param));
61                 return CMD_SUCCESS;
62         }
63
64         // Rehash for me. Try to start the rehash thread
65         if (!ServerInstance->ConfigThread)
66         {
67                 const std::string configfile = FileSystem::GetFileName(ServerInstance->ConfigFileName);
68                 user->WriteRemoteNumeric(RPL_REHASHING, configfile, "Rehashing " + ServerInstance->Config->ServerName);
69                 ServerInstance->SNO->WriteGlobalSno('a', "%s is rehashing %s on %s", user->nick.c_str(),
70                         configfile.c_str(), ServerInstance->Config->ServerName.c_str());
71
72                 /* Don't do anything with the logs here -- logs are restarted
73                  * after the config thread has completed.
74                  */
75                 ServerInstance->Rehash(user->uuid);
76         }
77         else
78         {
79                 /*
80                  * A rehash is already in progress! ahh shit.
81                  * XXX, todo: we should find some way to kill runaway rehashes that are blocking, this is a major problem for unrealircd users
82                  */
83                 user->WriteRemoteNotice("*** Could not rehash: A rehash is already in progress.");
84         }
85
86         // Always return success so spanningtree forwards an incoming REHASH even if we failed
87         return CMD_SUCCESS;
88 }