]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/commands/cmd_rehash.cpp
41b6936f6c249bb8c083ae76bf73ed8b270ca377
[user/henk/code/inspircd.git] / src / commands / cmd_rehash.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2008 InspIRCd Development Team
6  * See: http://www.inspircd.org/wiki/index.php/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 char* const* parameters, int pcnt, User *user)
26 {
27         user->WriteNumeric(382, "%s %s :Rehashing",user->nick,ServerConfig::CleanFilename(ServerInstance->ConfigFileName));
28         std::string old_disabled = ServerInstance->Config->DisabledCommands;
29
30         ServerInstance->Logs->Log("fuckingrehash", DEBUG, "parc %d p0 %s", pcnt, parameters[0]);
31         if (pcnt && parameters[0][0] != '-')
32         {
33                 if (!ServerInstance->MatchText(ServerInstance->Config->ServerName, parameters[0]))
34                 {
35                         ServerInstance->Logs->Log("fuckingrehash", DEBUG, "rehash for a server, and not for us");
36                         FOREACH_MOD(I_OnRehash,OnRehash(user, parameters[0]));
37                         return CMD_SUCCESS; // rehash for a server, and not for us
38                 }
39         }
40         else if (pcnt)
41         {
42                 ServerInstance->Logs->Log("fuckingrehash", DEBUG, "rehash for a subsystem, ignoring");
43                 FOREACH_MOD(I_OnRehash,OnRehash(user, parameters[0]));
44                 return CMD_SUCCESS;
45         }
46
47         // Rehash for me.
48         FOREACH_MOD(I_OnRehash,OnRehash(user, ""));
49
50         std::string m = std::string(user->nick) + " is rehashing config file " + ServerConfig::CleanFilename(ServerInstance->ConfigFileName);
51         ServerInstance->SNO->WriteToSnoMask('A', m);
52         ServerInstance->PI->SendSNONotice("A", m);
53         ServerInstance->Logs->CloseLogs();
54
55         if (!ServerInstance->OpenLog(ServerInstance->Config->argv, ServerInstance->Config->argc))
56         {
57                 m = std::string("ERROR: Could not open logfile ") + ServerInstance->Config->logpath + ":" + strerror(errno);
58                 ServerInstance->SNO->WriteToSnoMask('A', m);
59                 ServerInstance->PI->SendSNONotice("A", m);
60         }
61
62         ServerInstance->RehashUsersAndChans();
63         FOREACH_MOD(I_OnGarbageCollect, OnGarbageCollect());
64
65         if (!ServerInstance->ConfigThread)
66         {
67                 ServerInstance->Config->RehashUser = user;
68                 ServerInstance->Config->RehashParameter = pcnt ? parameters[0] : "";
69
70                 ServerInstance->ConfigThread = new ConfigReaderThread(ServerInstance, false, user);
71                 ServerInstance->Threads->Create(ServerInstance->ConfigThread);
72         }
73         else
74         {
75                 /* A rehash is already in progress! ahh shit. */
76                 if (IS_LOCAL(user))
77                         user->WriteServ("NOTICE %s :*** Could not rehash: A rehash is already in progress.", user->nick);
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