2 * InspIRCd -- Internet Relay Chat Daemon
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>
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.
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
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/>.
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
29 class CommandRehash : public Command
32 /** Constructor for rehash.
34 CommandRehash ( Module* parent) : Command(parent,"REHASH",0) { flags_needed = 'o'; Penalty = 2; syntax = "[<servermask>]"; }
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.
41 CmdResult Handle(const std::vector<std::string>& parameters, User *user);
44 CmdResult CommandRehash::Handle (const std::vector<std::string>& parameters, User *user)
46 std::string param = parameters.size() ? parameters[0] : "";
48 FOREACH_MOD(I_OnPreRehash,OnPreRehash(user, param));
52 // standard rehash of local server
54 else if (param.find_first_of("*.") != std::string::npos)
56 // rehash of servers by server name (with wildcard)
57 if (!InspIRCd::Match(ServerInstance->Config->ServerName, parameters[0]))
59 // Doesn't match us. PreRehash is already done, nothing left to do
65 // parameterized rehash
67 // the leading "-" is optional; remove it if present.
69 param = param.substr(1);
71 FOREACH_MOD(I_OnModuleRehash,OnModuleRehash(user, param));
75 // Rehash for me. Try to start the rehash thread
76 if (!ServerInstance->ConfigThread)
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);
82 user->WriteNumeric(RPL_REHASHING, "%s %s :Rehashing",
83 user->nick.c_str(),ServerConfig::CleanFilename(ServerInstance->ConfigFileName.c_str()));
85 ServerInstance->PI->SendUserNotice(user, std::string("*** Rehashing server ") +
86 ServerConfig::CleanFilename(ServerInstance->ConfigFileName.c_str()));
88 /* Don't do anything with the logs here -- logs are restarted
89 * after the config thread has completed.
91 FOREACH_MOD(I_OnGarbageCollect, OnGarbageCollect());
94 ServerInstance->ConfigThread = new ConfigReaderThread(user->uuid);
95 ServerInstance->Threads->Start(ServerInstance->ConfigThread);
100 * A rehash is already in progress! ahh shit.
101 * XXX, todo: we should find some way to kill runaway rehashes that are blocking, this is a major problem for unrealircd users
104 user->WriteServ("NOTICE %s :*** Could not rehash: A rehash is already in progress.", user->nick.c_str());
106 ServerInstance->PI->SendUserNotice(user, "*** Could not rehash: A rehash is already in progress.");
109 // Always return success so spanningtree forwards an incoming REHASH even if we failed
114 COMMAND_INIT(CommandRehash)