]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/commands/cmd_rehash.cpp
Membership* changes
[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 /*       +------------------------------------+
17  *       | Inspire Internet Relay Chat Daemon |
18  *       +------------------------------------+
19  *
20  *  InspIRCd: (C) 2002-2009 InspIRCd Development Team
21  * See: http://wiki.inspircd.org/Credits
22  *
23  * This program is free but copyrighted software; see
24  *      the file COPYING for details.
25  *
26  * ---------------------------------------------------
27  */
28
29 #ifndef __CMD_REHASH_H__
30 #define __CMD_REHASH_H__
31
32 // include the common header files
33
34 #include "users.h"
35 #include "channels.h"
36
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
40  * may not.
41  */
42 class CommandRehash : public Command
43 {
44  public:
45         /** Constructor for rehash.
46          */
47         CommandRehash (InspIRCd* Instance, Module* parent) : Command(Instance,parent,"REHASH","o",0,false,3) { syntax = "[<servermask>]"; }
48         /** Handle command.
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.
53          */
54         CmdResult Handle(const std::vector<std::string>& parameters, User *user);
55 };
56
57 #endif
58
59
60
61 CmdResult CommandRehash::Handle (const std::vector<std::string>& parameters, User *user)
62 {
63         std::string param = parameters.size() ? parameters[0] : "";
64
65         FOREACH_MOD(I_OnPreRehash,OnPreRehash(user, param));
66
67         if (param.empty())
68         {
69                 // standard rehash of local server
70         }
71         else if (param.find_first_of("*.") != std::string::npos)
72         {
73                 // rehash of servers by server name (with wildcard)
74                 if (!InspIRCd::Match(ServerInstance->Config->ServerName, parameters[0]))
75                 {
76                         // Doesn't match us. PreRehash is already done, nothing left to do
77                         return CMD_SUCCESS;
78                 }
79         }
80         else
81         {
82                 // parameterized rehash
83
84                 // the leading "-" is optional; remove it if present.
85                 if (param[0] == '-')
86                         param = param.substr(1);
87
88                 FOREACH_MOD(I_OnModuleRehash,OnModuleRehash(user, param));
89                 return CMD_SUCCESS;
90         }
91
92         // Rehash for me. Try to start the rehash thread
93         if (!ServerInstance->ConfigThread)
94         {
95                 std::string m = user->nick + " is rehashing config file " + ServerConfig::CleanFilename(ServerInstance->ConfigFileName) + " on " + ServerInstance->Config->ServerName;
96                 ServerInstance->SNO->WriteGlobalSno('a', m);
97
98                 if (IS_LOCAL(user))
99                         user->WriteNumeric(RPL_REHASHING, "%s %s :Rehashing",
100                                 user->nick.c_str(),ServerConfig::CleanFilename(ServerInstance->ConfigFileName));
101                 else
102                         ServerInstance->PI->SendUserNotice(user, std::string("*** Rehashing server ") +
103                                 ServerConfig::CleanFilename(ServerInstance->ConfigFileName));
104
105                 /* Don't do anything with the logs here -- logs are restarted
106                  * after the config thread has completed.
107                  */
108
109                 ServerInstance->RehashUsersAndChans();
110                 FOREACH_MOD(I_OnGarbageCollect, OnGarbageCollect());
111
112
113                 ServerInstance->ConfigThread = new ConfigReaderThread(ServerInstance, user->uuid);
114                 ServerInstance->Threads->Start(ServerInstance->ConfigThread);
115
116                 return CMD_SUCCESS;
117         }
118         else
119         {
120                 /*
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
123                  */
124                 if (IS_LOCAL(user))
125                         user->WriteServ("NOTICE %s :*** Could not rehash: A rehash is already in progress.", user->nick.c_str());
126                 else
127                         ServerInstance->PI->SendUserNotice(user, "*** Could not rehash: A rehash is already in progress.");
128
129                 return CMD_FAILURE;
130         }
131 }
132
133
134 COMMAND_INIT(CommandRehash)