]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/commands/cmd_rehash.cpp
e3405161129be0d15349d679078ccf7486693923
[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
20 extern "C" DllExport Command* init_command(InspIRCd* Instance)
21 {
22         return new CommandRehash(Instance);
23 }
24
25 CmdResult CommandRehash::Handle (const std::vector<std::string>& parameters, User *user)
26 {
27         std::string old_disabled = ServerInstance->Config->DisabledCommands;
28
29         if (parameters.size() && parameters[0][0] != '-')
30         {
31                 if (!InspIRCd::Match(ServerInstance->Config->ServerName, parameters[0]))
32                 {
33                         FOREACH_MOD(I_OnRehash,OnRehash(user, parameters[0]));
34                         return CMD_SUCCESS; // rehash for a server, and not for us
35                 }
36         }
37         else if (parameters.size())
38         {
39                 FOREACH_MOD(I_OnRehash,OnRehash(user, parameters[0]));
40                 return CMD_SUCCESS;
41         }
42
43         // Rehash for me.
44         FOREACH_MOD(I_OnRehash,OnRehash(user, ""));
45
46         if (IS_LOCAL(user))
47                 user->WriteNumeric(RPL_REHASHING, "%s %s :Rehashing",user->nick.c_str(),ServerConfig::CleanFilename(ServerInstance->ConfigFileName));
48         else
49                 ServerInstance->PI->SendUserNotice(user, std::string("*** Rehashing server ") + ServerInstance->ConfigFileName);
50
51
52         std::string m = user->nick + " is rehashing config file " + ServerConfig::CleanFilename(ServerInstance->ConfigFileName) + " on " + ServerInstance->Config->ServerName;
53         ServerInstance->SNO->WriteToSnoMask('a', m);
54
55         /* Don't do anything with the logs here -- logs are restarted
56          * after the config thread has completed.
57          */
58
59         ServerInstance->RehashUsersAndChans();
60         FOREACH_MOD(I_OnGarbageCollect, OnGarbageCollect());
61
62         if (!ServerInstance->ConfigThread)
63         {
64                 ServerInstance->Config->RehashUserUID = user->uuid;
65                 ServerInstance->Config->RehashParameter = parameters.size() ? parameters[0] : "";
66
67                 ServerInstance->ConfigThread = new ConfigReaderThread(ServerInstance, false, ServerInstance->Config->RehashUserUID);
68                 ServerInstance->Threads->Start(ServerInstance->ConfigThread);
69         }
70         else
71         {
72                 /*
73                  * A rehash is already in progress! ahh shit.
74                  * XXX, todo: we should find some way to kill runaway rehashes that are blocking, this is a major problem for unrealircd users
75                  */
76                 if (IS_LOCAL(user))
77                         user->WriteServ("NOTICE %s :*** Could not rehash: A rehash is already in progress.", user->nick.c_str());
78                 else
79                         ServerInstance->PI->SendUserNotice(user, "*** Could not rehash: A rehash is already in progress.");
80
81                 return CMD_FAILURE;
82         }
83
84         return CMD_SUCCESS;
85 }
86