]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/commands/cmd_rehash.cpp
Put log-switching back into configreader
[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->WriteServ("382 %s %s :Rehashing",user->nick,ServerConfig::CleanFilename(ServerInstance->ConfigFileName));
28         std::string parameter;
29         std::string old_disabled = ServerInstance->Config->DisabledCommands;
30         if (pcnt)
31         {
32                 parameter = parameters[0];
33         }
34         else
35         {
36                 ServerInstance->SNO->WriteToSnoMask('A', "%s is rehashing config file %s",user->nick,ServerConfig::CleanFilename(ServerInstance->ConfigFileName));
37                 ServerInstance->Logs->CloseLogs();
38                 if (!ServerInstance->OpenLog(ServerInstance->Config->argv, ServerInstance->Config->argc))
39                         user->WriteServ("NOTICE %s :*** ERROR: Could not open logfile %s: %s", user->nick, ServerInstance->Config->logpath.c_str(), strerror(errno));
40                 ServerInstance->RehashUsersAndChans();
41                 FOREACH_MOD(I_OnGarbageCollect, OnGarbageCollect());
42                 if (!ServerInstance->ConfigThread)
43                 {
44                         ServerInstance->ConfigThread = new ConfigReaderThread(ServerInstance, false, user);
45                         ServerInstance->Threads->Create(ServerInstance->ConfigThread);
46                 }
47                 else
48                 {
49                         /* A rehash is already in progress! ahh shit. */
50                         user->WriteServ("*** NOTICE %s :*** Could not rehash: A rehash is already in progress.", user->nick);
51                         return CMD_FAILURE;
52                 }
53                 /* TODO:
54                  * ALL THIS STUFF HERE NEEDS TO BE HOOKED TO THE 'DEATH' OF THE REHASH THREAD
55                  * VIA SOME NOTIFICATION EVENT. WE CANT JUST CALL IT ALL HERE.
56                  * -- B
57                  */
58                 // Get XLine to do it's thing.
59                 /*ServerInstance->XLines->CheckELines();
60                 ServerInstance->XLines->ApplyLines();
61                 ServerInstance->Res->Rehash();
62                 ServerInstance->ResetMaxBans();*/
63         }
64
65         /* TODO: Same as above for all this stuff, really */
66         if (old_disabled != ServerInstance->Config->DisabledCommands)
67                 InitializeDisabledCommands(ServerInstance->Config->DisabledCommands, ServerInstance);
68
69         FOREACH_MOD(I_OnRehash,OnRehash(user, parameter));
70
71         ServerInstance->BuildISupport();
72
73         return CMD_SUCCESS;
74 }
75