summaryrefslogtreecommitdiff
path: root/src/commands
diff options
context:
space:
mode:
authordanieldg <danieldg@e03df62e-2008-0410-955e-edbf42e46eb7>2009-05-24 02:53:45 +0000
committerdanieldg <danieldg@e03df62e-2008-0410-955e-edbf42e46eb7>2009-05-24 02:53:45 +0000
commit0da6b3a13def40e8fd002b9fc60f955467f6372d (patch)
treed4aa39ece30255afe7447fb46f39c45c39d679a3 /src/commands
parent5f309503fa985faa5b255246fc0415455c1c65ee (diff)
OnRehash changes: split to multiple hooks to clarify use and prevent explosion of rehashes on a /REHASH *
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@11388 e03df62e-2008-0410-955e-edbf42e46eb7
Diffstat (limited to 'src/commands')
-rw-r--r--src/commands/cmd_rehash.cpp48
1 files changed, 29 insertions, 19 deletions
diff --git a/src/commands/cmd_rehash.cpp b/src/commands/cmd_rehash.cpp
index b58d6035a..9ee71838b 100644
--- a/src/commands/cmd_rehash.cpp
+++ b/src/commands/cmd_rehash.cpp
@@ -16,7 +16,6 @@
#include "commands/cmd_rehash.h"
-
extern "C" DllExport Command* init_command(InspIRCd* Instance)
{
return new CommandRehash(Instance);
@@ -24,36 +23,48 @@ extern "C" DllExport Command* init_command(InspIRCd* Instance)
CmdResult CommandRehash::Handle (const std::vector<std::string>& parameters, User *user)
{
- std::string old_disabled = ServerInstance->Config->DisabledCommands;
+ std::string param = parameters.size() ? parameters[0] : "";
+
+ FOREACH_MOD(I_OnPreRehash,OnPreRehash(user, param));
- if (parameters.size() && parameters[0][0] != '-')
+ if (param.empty())
{
+ // standard rehash of local server
+ }
+ else if (param.find_first_of("*.") != std::string::npos)
+ {
+ // rehash of servers by server name (with wildcard)
if (!InspIRCd::Match(ServerInstance->Config->ServerName, parameters[0]))
{
- FOREACH_MOD(I_OnRehash,OnRehash(user, parameters[0]));
- return CMD_SUCCESS; // rehash for a server, and not for us
+ // Doesn't match us. PreRehash is already done, nothing left to do
+ return CMD_SUCCESS;
}
}
- else if (parameters.size())
+ else
{
- FOREACH_MOD(I_OnRehash,OnRehash(user, parameters[0]));
- return CMD_SUCCESS;
- }
+ // parameterized rehash
- // Rehash for me.
- FOREACH_MOD(I_OnRehash,OnRehash(user, ""));
-
- if (IS_LOCAL(user))
- user->WriteNumeric(RPL_REHASHING, "%s %s :Rehashing",user->nick.c_str(),ServerConfig::CleanFilename(ServerInstance->ConfigFileName));
- else
- ServerInstance->PI->SendUserNotice(user, std::string("*** Rehashing server ") + ServerInstance->ConfigFileName);
+ // the leading "-" is optional; remove it if present.
+ if (param[0] == '-')
+ param = param.substr(1);
+ FOREACH_MOD(I_OnModuleRehash,OnModuleRehash(user, param));
+ return CMD_SUCCESS;
+ }
+ // Rehash for me. Try to start the rehash thread
if (!ServerInstance->ConfigThread)
{
std::string m = user->nick + " is rehashing config file " + ServerConfig::CleanFilename(ServerInstance->ConfigFileName) + " on " + ServerInstance->Config->ServerName;
ServerInstance->SNO->WriteGlobalSno('a', m);
+ if (IS_LOCAL(user))
+ user->WriteNumeric(RPL_REHASHING, "%s %s :Rehashing",
+ user->nick.c_str(),ServerConfig::CleanFilename(ServerInstance->ConfigFileName));
+ else
+ ServerInstance->PI->SendUserNotice(user, std::string("*** Rehashing server ") +
+ ServerConfig::CleanFilename(ServerInstance->ConfigFileName));
+
/* Don't do anything with the logs here -- logs are restarted
* after the config thread has completed.
*/
@@ -63,10 +74,11 @@ CmdResult CommandRehash::Handle (const std::vector<std::string>& parameters, Use
ServerInstance->Config->RehashUserUID = user->uuid;
- ServerInstance->Config->RehashParameter = parameters.size() ? parameters[0] : "";
ServerInstance->ConfigThread = new ConfigReaderThread(ServerInstance, false, ServerInstance->Config->RehashUserUID);
ServerInstance->Threads->Start(ServerInstance->ConfigThread);
+
+ return CMD_SUCCESS;
}
else
{
@@ -81,7 +93,5 @@ CmdResult CommandRehash::Handle (const std::vector<std::string>& parameters, Use
return CMD_FAILURE;
}
-
- return CMD_SUCCESS;
}