]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/commands/cmd_rehash.cpp
Read multiple GnuTLS records in one RawSocketRead operation
[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 #include "commands/cmd_rehash.h"
17
18
19 extern "C" DllExport Command* init_command(InspIRCd* Instance)
20 {
21         return new CommandRehash(Instance);
22 }
23
24 CmdResult CommandRehash::Handle (const std::vector<std::string>& parameters, User *user)
25 {
26         std::string param = parameters.size() ? parameters[0] : "";
27
28         FOREACH_MOD(I_OnPreRehash,OnPreRehash(user, param));
29
30         if (param.empty())
31         {
32                 // standard rehash of local server
33         }
34         else if (param.find_first_of("*.") != std::string::npos)
35         {
36                 // rehash of servers by server name (with wildcard)
37                 if (!InspIRCd::Match(ServerInstance->Config->ServerName, parameters[0]))
38                 {
39                         // Doesn't match us. PreRehash is already done, nothing left to do
40                         return CMD_SUCCESS;
41                 }
42         }
43         else
44         {
45                 // parameterized rehash
46
47                 // the leading "-" is optional; remove it if present.
48                 if (param[0] == '-')
49                         param = param.substr(1);
50
51                 FOREACH_MOD(I_OnModuleRehash,OnModuleRehash(user, param));
52                 return CMD_SUCCESS;
53         }
54
55         // Rehash for me. Try to start the rehash thread
56         if (!ServerInstance->ConfigThread)
57         {
58                 std::string m = user->nick + " is rehashing config file " + ServerConfig::CleanFilename(ServerInstance->ConfigFileName) + " on " + ServerInstance->Config->ServerName;
59                 ServerInstance->SNO->WriteGlobalSno('a', m);
60
61                 if (IS_LOCAL(user))
62                         user->WriteNumeric(RPL_REHASHING, "%s %s :Rehashing",
63                                 user->nick.c_str(),ServerConfig::CleanFilename(ServerInstance->ConfigFileName));
64                 else
65                         ServerInstance->PI->SendUserNotice(user, std::string("*** Rehashing server ") +
66                                 ServerConfig::CleanFilename(ServerInstance->ConfigFileName));
67
68                 /* Don't do anything with the logs here -- logs are restarted
69                  * after the config thread has completed.
70                  */
71
72                 ServerInstance->RehashUsersAndChans();
73                 FOREACH_MOD(I_OnGarbageCollect, OnGarbageCollect());
74
75
76                 ServerInstance->ConfigThread = new ConfigReaderThread(ServerInstance, user->uuid);
77                 ServerInstance->Threads->Start(ServerInstance->ConfigThread);
78
79                 return CMD_SUCCESS;
80         }
81         else
82         {
83                 /*
84                  * A rehash is already in progress! ahh shit.
85                  * XXX, todo: we should find some way to kill runaway rehashes that are blocking, this is a major problem for unrealircd users
86                  */
87                 if (IS_LOCAL(user))
88                         user->WriteServ("NOTICE %s :*** Could not rehash: A rehash is already in progress.", user->nick.c_str());
89                 else
90                         ServerInstance->PI->SendUserNotice(user, "*** Could not rehash: A rehash is already in progress.");
91
92                 return CMD_FAILURE;
93         }
94 }
95