]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/commands/cmd_rehash.cpp
Remove InspIRCd* parameters and fields
[user/henk/code/inspircd.git] / src / commands / cmd_rehash.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2009 InspIRCd Development Team
6  * See: http://wiki.inspircd.org/Credits
7  *
8  * This program is free but copyrighted software; see
9  *            the file COPYING for details.
10  *
11  * ---------------------------------------------------
12  */
13
14 #include "inspircd.h"
15 #include "xline.h"
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
19  * may not.
20  */
21 class CommandRehash : public Command
22 {
23  public:
24         /** Constructor for rehash.
25          */
26         CommandRehash ( Module* parent) : Command(parent,"REHASH",0) { flags_needed = 'o'; Penalty = 2; syntax = "[<servermask>]"; }
27         /** Handle command.
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.
32          */
33         CmdResult Handle(const std::vector<std::string>& parameters, User *user);
34 };
35
36 CmdResult CommandRehash::Handle (const std::vector<std::string>& parameters, User *user)
37 {
38         std::string param = parameters.size() ? parameters[0] : "";
39
40         FOREACH_MOD(I_OnPreRehash,OnPreRehash(user, param));
41
42         if (param.empty())
43         {
44                 // standard rehash of local server
45         }
46         else if (param.find_first_of("*.") != std::string::npos)
47         {
48                 // rehash of servers by server name (with wildcard)
49                 if (!InspIRCd::Match(ServerInstance->Config->ServerName, parameters[0]))
50                 {
51                         // Doesn't match us. PreRehash is already done, nothing left to do
52                         return CMD_SUCCESS;
53                 }
54         }
55         else
56         {
57                 // parameterized rehash
58
59                 // the leading "-" is optional; remove it if present.
60                 if (param[0] == '-')
61                         param = param.substr(1);
62
63                 FOREACH_MOD(I_OnModuleRehash,OnModuleRehash(user, param));
64                 return CMD_SUCCESS;
65         }
66
67         // Rehash for me. Try to start the rehash thread
68         if (!ServerInstance->ConfigThread)
69         {
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);
72
73                 if (IS_LOCAL(user))
74                         user->WriteNumeric(RPL_REHASHING, "%s %s :Rehashing",
75                                 user->nick.c_str(),ServerConfig::CleanFilename(ServerInstance->ConfigFileName.c_str()));
76                 else
77                         ServerInstance->PI->SendUserNotice(user, std::string("*** Rehashing server ") +
78                                 ServerConfig::CleanFilename(ServerInstance->ConfigFileName.c_str()));
79
80                 /* Don't do anything with the logs here -- logs are restarted
81                  * after the config thread has completed.
82                  */
83
84                 ServerInstance->RehashUsersAndChans();
85                 FOREACH_MOD(I_OnGarbageCollect, OnGarbageCollect());
86
87
88                 ServerInstance->ConfigThread = new ConfigReaderThread(user->uuid);
89                 ServerInstance->Threads->Start(ServerInstance->ConfigThread);
90
91                 return CMD_SUCCESS;
92         }
93         else
94         {
95                 /*
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
98                  */
99                 if (IS_LOCAL(user))
100                         user->WriteServ("NOTICE %s :*** Could not rehash: A rehash is already in progress.", user->nick.c_str());
101                 else
102                         ServerInstance->PI->SendUserNotice(user, "*** Could not rehash: A rehash is already in progress.");
103
104                 return CMD_FAILURE;
105         }
106 }
107
108
109 COMMAND_INIT(CommandRehash)