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 /* +------------------------------------+
17 * | Inspire Internet Relay Chat Daemon |
18 * +------------------------------------+
20 * InspIRCd: (C) 2002-2009 InspIRCd Development Team
21 * See: http://wiki.inspircd.org/Credits
23 * This program is free but copyrighted software; see
24 * the file COPYING for details.
26 * ---------------------------------------------------
29 #ifndef __CMD_REHASH_H__
30 #define __CMD_REHASH_H__
32 // include the common header files
37 /** Handle /REHASH. These command handlers can be reloaded by the core,
38 * and handle basic RFC1459 commands. Commands within modules work
39 * the same way, however, they can be fully unloaded, where these
42 class CommandRehash : public Command
45 /** Constructor for rehash.
47 CommandRehash (InspIRCd* Instance, Module* parent) : Command(Instance,parent,"REHASH","o",0,false,3) { syntax = "[<servermask>]"; }
49 * @param parameters The parameters to the comamnd
50 * @param pcnt The number of parameters passed to teh command
51 * @param user The user issuing the command
52 * @return A value from CmdResult to indicate command success or failure.
54 CmdResult Handle(const std::vector<std::string>& parameters, User *user);
61 CmdResult CommandRehash::Handle (const std::vector<std::string>& parameters, User *user)
63 std::string param = parameters.size() ? parameters[0] : "";
65 FOREACH_MOD(I_OnPreRehash,OnPreRehash(user, param));
69 // standard rehash of local server
71 else if (param.find_first_of("*.") != std::string::npos)
73 // rehash of servers by server name (with wildcard)
74 if (!InspIRCd::Match(ServerInstance->Config->ServerName, parameters[0]))
76 // Doesn't match us. PreRehash is already done, nothing left to do
82 // parameterized rehash
84 // the leading "-" is optional; remove it if present.
86 param = param.substr(1);
88 FOREACH_MOD(I_OnModuleRehash,OnModuleRehash(user, param));
92 // Rehash for me. Try to start the rehash thread
93 if (!ServerInstance->ConfigThread)
95 std::string m = user->nick + " is rehashing config file " + ServerConfig::CleanFilename(ServerInstance->ConfigFileName) + " on " + ServerInstance->Config->ServerName;
96 ServerInstance->SNO->WriteGlobalSno('a', m);
99 user->WriteNumeric(RPL_REHASHING, "%s %s :Rehashing",
100 user->nick.c_str(),ServerConfig::CleanFilename(ServerInstance->ConfigFileName));
102 ServerInstance->PI->SendUserNotice(user, std::string("*** Rehashing server ") +
103 ServerConfig::CleanFilename(ServerInstance->ConfigFileName));
105 /* Don't do anything with the logs here -- logs are restarted
106 * after the config thread has completed.
109 ServerInstance->RehashUsersAndChans();
110 FOREACH_MOD(I_OnGarbageCollect, OnGarbageCollect());
113 ServerInstance->ConfigThread = new ConfigReaderThread(ServerInstance, user->uuid);
114 ServerInstance->Threads->Start(ServerInstance->ConfigThread);
121 * A rehash is already in progress! ahh shit.
122 * XXX, todo: we should find some way to kill runaway rehashes that are blocking, this is a major problem for unrealircd users
125 user->WriteServ("NOTICE %s :*** Could not rehash: A rehash is already in progress.", user->nick.c_str());
127 ServerInstance->PI->SendUserNotice(user, "*** Could not rehash: A rehash is already in progress.");
134 COMMAND_INIT(CommandRehash)