]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/commands/cmd_qline.cpp
Remove InspIRCd* parameters and fields
[user/henk/code/inspircd.git] / src / commands / cmd_qline.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
17 /** Handle /QLINE.  */
18 class CommandQline : public Command
19 {
20  public:
21         /** Constructor for qline.
22          */
23         CommandQline ( Module* parent) : Command(parent,"QLINE",1,3) { flags_needed = 'o'; Penalty = 0; syntax = "<nick> [<duration> :<reason>]"; }
24         /** Handle command.
25          * @param parameters The parameters to the comamnd
26          * @param pcnt The number of parameters passed to the command
27          * @param user The user issuing the command
28          * @return A value from CmdResult to indicate command success or failure.
29          */
30         CmdResult Handle(const std::vector<std::string>& parameters, User *user);
31 };
32
33
34 CmdResult CommandQline::Handle (const std::vector<std::string>& parameters, User *user)
35 {
36         if (parameters.size() >= 3)
37         {
38                 if (ServerInstance->NickMatchesEveryone(parameters[0],user))
39                         return CMD_FAILURE;
40
41                 if (parameters[0].find('@') != std::string::npos || parameters[0].find('!') != std::string::npos || parameters[0].find('.') != std::string::npos)
42                 {
43                         user->WriteServ("NOTICE %s :*** A Q-Line only bans a nick pattern, not a nick!user@host pattern.",user->nick.c_str());
44                         return CMD_FAILURE;
45                 }
46
47                 long duration = ServerInstance->Duration(parameters[1].c_str());
48                 QLine* ql = new QLine(ServerInstance->Time(), duration, user->nick.c_str(), parameters[2].c_str(), parameters[0].c_str());
49                 if (ServerInstance->XLines->AddLine(ql,user))
50                 {
51                         if (!duration)
52                         {
53                                 ServerInstance->SNO->WriteToSnoMask('x',"%s added permanent Q-line for %s: %s",user->nick.c_str(), parameters[0].c_str(), parameters[2].c_str());
54                         }
55                         else
56                         {
57                                 time_t c_requires_crap = duration + ServerInstance->Time();
58                                 ServerInstance->SNO->WriteToSnoMask('x',"%s added timed Q-line for %s, expires on %s: %s",user->nick.c_str(),parameters[0].c_str(),
59                                           ServerInstance->TimeString(c_requires_crap).c_str(), parameters[2].c_str());
60                         }
61                         ServerInstance->XLines->ApplyLines();
62                 }
63                 else
64                 {
65                         delete ql;
66                         user->WriteServ("NOTICE %s :*** Q-Line for %s already exists",user->nick.c_str(),parameters[0].c_str());
67                 }
68         }
69         else
70         {
71                 if (ServerInstance->XLines->DelLine(parameters[0].c_str(), "Q", user))
72                 {
73                         ServerInstance->SNO->WriteToSnoMask('x',"%s removed Q-line on %s",user->nick.c_str(),parameters[0].c_str());
74                 }
75                 else
76                 {
77                         user->WriteServ("NOTICE %s :*** Q-Line %s not found in list, try /stats q.",user->nick.c_str(),parameters[0].c_str());
78                         return CMD_FAILURE;
79                 }
80         }
81
82         return CMD_SUCCESS;
83 }
84
85
86 COMMAND_INIT(CommandQline)