]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/commands/cmd_qline.cpp
Revert earlier time() -> SI->Time() diff for now, this causes problems with dns.cpp...
[user/henk/code/inspircd.git] / src / commands / cmd_qline.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_qline.h"
17
18
19
20 extern "C" DllExport Command* init_command(InspIRCd* Instance)
21 {
22         return new CommandQline(Instance);
23 }
24
25 CmdResult CommandQline::Handle (const std::vector<std::string>& parameters, User *user)
26 {
27         if (parameters.size() >= 3)
28         {
29                 if (ServerInstance->NickMatchesEveryone(parameters[0],user))
30                         return CMD_FAILURE;
31
32                 if (parameters[0].find('@') != std::string::npos || parameters[0].find('!') != std::string::npos || parameters[0].find('.') != std::string::npos)
33                 {
34                         user->WriteServ("NOTICE %s :*** A Q-Line only bans a nick pattern, not a nick!user@host pattern.",user->nick.c_str());
35                         return CMD_FAILURE;
36                 }
37
38                 long duration = ServerInstance->Duration(parameters[1].c_str());
39                 QLine* ql = new QLine(ServerInstance, ServerInstance->Time(), duration, user->nick.c_str(), parameters[2].c_str(), parameters[0].c_str());
40                 if (ServerInstance->XLines->AddLine(ql,user))
41                 {
42                         if (!duration)
43                         {
44                                 ServerInstance->SNO->WriteToSnoMask('x',"%s added permanent Q-line for %s.",user->nick.c_str(),parameters[0].c_str());
45                         }
46                         else
47                         {
48                                 time_t c_requires_crap = duration + ServerInstance->Time();
49                                 ServerInstance->SNO->WriteToSnoMask('x',"%s added timed Q-line for %s, expires on %s",user->nick.c_str(),parameters[0].c_str(),
50                                           ServerInstance->TimeString(c_requires_crap).c_str());
51                         }
52                         ServerInstance->XLines->ApplyLines();
53                 }
54                 else
55                 {
56                         delete ql;
57                         user->WriteServ("NOTICE %s :*** Q-Line for %s already exists",user->nick.c_str(),parameters[0].c_str());
58                 }
59         }
60         else
61         {
62                 if (ServerInstance->XLines->DelLine(parameters[0].c_str(), "Q", user))
63                 {
64                         ServerInstance->SNO->WriteToSnoMask('x',"%s Removed Q-line on %s.",user->nick.c_str(),parameters[0].c_str());
65                 }
66                 else
67                 {
68                         user->WriteServ("NOTICE %s :*** Q-Line %s not found in list, try /stats q.",user->nick.c_str(),parameters[0].c_str());
69                         return CMD_FAILURE;
70                 }
71         }
72
73         return CMD_SUCCESS;
74 }
75