]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/coremods/core_oper/cmd_rehash.cpp
Sync helpop chmodes s and p with docs
[user/henk/code/inspircd.git] / src / coremods / core_oper / cmd_rehash.cpp
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  *   Copyright (C) 2018-2019 Sadie Powell <sadie@witchery.services>
5  *   Copyright (C) 2013 Adam <Adam@anope.org>
6  *   Copyright (C) 2012-2015 Attila Molnar <attilamolnar@hush.com>
7  *   Copyright (C) 2012 Robby <robby@chatbelgie.be>
8  *   Copyright (C) 2009 Matt Smith <dz@inspircd.org>
9  *   Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org>
10  *   Copyright (C) 2008 Robin Burchell <robin+git@viroteck.net>
11  *   Copyright (C) 2007-2008, 2010 Craig Edwards <brain@inspircd.org>
12  *   Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
13  *
14  * This file is part of InspIRCd.  InspIRCd is free software: you can
15  * redistribute it and/or modify it under the terms of the GNU General Public
16  * License as published by the Free Software Foundation, version 2.
17  *
18  * This program is distributed in the hope that it will be useful, but WITHOUT
19  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
20  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
21  * details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
25  */
26
27
28 #include "inspircd.h"
29 #include "core_oper.h"
30
31 CommandRehash::CommandRehash(Module* parent)
32         : Command(parent, "REHASH", 0)
33 {
34         flags_needed = 'o';
35         Penalty = 2;
36         syntax = "[<servermask>]";
37 }
38
39 CmdResult CommandRehash::Handle(User* user, const Params& parameters)
40 {
41         std::string param = parameters.size() ? parameters[0] : "";
42
43         FOREACH_MOD(OnPreRehash, (user, param));
44
45         if (param.empty())
46         {
47                 // standard rehash of local server
48         }
49         else if (param.find_first_of("*.") != std::string::npos)
50         {
51                 // rehash of servers by server name (with wildcard)
52                 if (!InspIRCd::Match(ServerInstance->Config->ServerName, parameters[0]))
53                 {
54                         // Doesn't match us. PreRehash is already done, nothing left to do
55                         return CMD_SUCCESS;
56                 }
57         }
58         else
59         {
60                 // parameterized rehash
61
62                 // the leading "-" is optional; remove it if present.
63                 if (param[0] == '-')
64                         param.erase(param.begin());
65
66                 FOREACH_MOD(OnModuleRehash, (user, param));
67                 return CMD_SUCCESS;
68         }
69
70         // Rehash for me. Try to start the rehash thread
71         if (!ServerInstance->ConfigThread)
72         {
73                 const std::string configfile = FileSystem::GetFileName(ServerInstance->ConfigFileName);
74                 user->WriteRemoteNumeric(RPL_REHASHING, configfile, "Rehashing " + ServerInstance->Config->ServerName);
75                 ServerInstance->SNO->WriteGlobalSno('a', "%s is rehashing %s on %s", user->nick.c_str(),
76                         configfile.c_str(), ServerInstance->Config->ServerName.c_str());
77
78                 /* Don't do anything with the logs here -- logs are restarted
79                  * after the config thread has completed.
80                  */
81                 ServerInstance->Rehash(user->uuid);
82         }
83         else
84         {
85                 /*
86                  * A rehash is already in progress! ahh shit.
87                  * XXX, todo: we should find some way to kill runaway rehashes that are blocking, this is a major problem for unrealircd users
88                  */
89                 user->WriteRemoteNotice("*** Could not rehash: A rehash is already in progress.");
90         }
91
92         // Always return success so spanningtree forwards an incoming REHASH even if we failed
93         return CMD_SUCCESS;
94 }