1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2009 InspIRCd Development Team
6 * See: http://wiki.inspircd.org/Credits
8 * This program is free but copyrighted software; see
9 * the file COPYING for details.
11 * ---------------------------------------------------
16 /** Handle /REHASH. These command handlers can be reloaded by the core,
17 * and handle basic RFC1459 commands. Commands within modules work
18 * the same way, however, they can be fully unloaded, where these
21 class CommandRehash : public Command
24 /** Constructor for rehash.
26 CommandRehash ( Module* parent) : Command(parent,"REHASH",0) { flags_needed = 'o'; Penalty = 2; syntax = "[<servermask>]"; }
28 * @param parameters The parameters to the comamnd
29 * @param pcnt The number of parameters passed to teh command
30 * @param user The user issuing the command
31 * @return A value from CmdResult to indicate command success or failure.
33 CmdResult Handle(const std::vector<std::string>& parameters, User *user);
36 CmdResult CommandRehash::Handle (const std::vector<std::string>& parameters, User *user)
38 std::string param = parameters.size() ? parameters[0] : "";
40 FOREACH_MOD(I_OnPreRehash,OnPreRehash(user, param));
44 // standard rehash of local server
46 else if (param.find_first_of("*.") != std::string::npos)
48 // rehash of servers by server name (with wildcard)
49 if (!InspIRCd::Match(ServerInstance->Config->ServerName, parameters[0]))
51 // Doesn't match us. PreRehash is already done, nothing left to do
57 // parameterized rehash
59 // the leading "-" is optional; remove it if present.
61 param = param.substr(1);
63 FOREACH_MOD(I_OnModuleRehash,OnModuleRehash(user, param));
67 // Rehash for me. Try to start the rehash thread
68 if (!ServerInstance->ConfigThread)
70 std::string m = user->nick + " is rehashing config file " + ServerConfig::CleanFilename(ServerInstance->ConfigFileName.c_str()) + " on " + ServerInstance->Config->ServerName;
71 ServerInstance->SNO->WriteGlobalSno('a', m);
74 user->WriteNumeric(RPL_REHASHING, "%s %s :Rehashing",
75 user->nick.c_str(),ServerConfig::CleanFilename(ServerInstance->ConfigFileName.c_str()));
77 ServerInstance->PI->SendUserNotice(user, std::string("*** Rehashing server ") +
78 ServerConfig::CleanFilename(ServerInstance->ConfigFileName.c_str()));
80 /* Don't do anything with the logs here -- logs are restarted
81 * after the config thread has completed.
84 ServerInstance->RehashUsersAndChans();
85 FOREACH_MOD(I_OnGarbageCollect, OnGarbageCollect());
88 ServerInstance->ConfigThread = new ConfigReaderThread(user->uuid);
89 ServerInstance->Threads->Start(ServerInstance->ConfigThread);
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
100 user->WriteServ("NOTICE %s :*** Could not rehash: A rehash is already in progress.", user->nick.c_str());
102 ServerInstance->PI->SendUserNotice(user, "*** Could not rehash: A rehash is already in progress.");
109 COMMAND_INIT(CommandRehash)