]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/commands/cmd_qline.cpp
ebd1d6b3158662578165303235a4626e047aebe4
[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  *       | Inspire Internet Relay Chat Daemon |
18  *       +------------------------------------+
19  *
20  *  InspIRCd: (C) 2002-2009 InspIRCd Development Team
21  * See: http://wiki.inspircd.org/Credits
22  *
23  * This program is free but copyrighted software; see
24  *      the file COPYING for details.
25  *
26  * ---------------------------------------------------
27  */
28
29 #ifndef __CMD_QLINE_H__
30 #define __CMD_QLINE_H__
31
32 // include the common header files
33
34 #include "users.h"
35 #include "channels.h"
36
37 /** Handle /QLINE. These command handlers can be reloaded by the core,
38  * and handle basic RFC1459 commands. Commands within modules work
39  * the same way, however, they can be fully unloaded, where these
40  * may not.
41  */
42 class CommandQline : public Command
43 {
44  public:
45         /** Constructor for qline.
46          */
47         CommandQline (InspIRCd* Instance, Module* parent) : Command(Instance,parent,"QLINE","o",1,3,false,0) { syntax = "<nick> [<duration> :<reason>]"; }
48         /** Handle command.
49          * @param parameters The parameters to the comamnd
50          * @param pcnt The number of parameters passed to teh command
51          * @param user The user issuing the command
52          * @return A value from CmdResult to indicate command success or failure.
53          */
54         CmdResult Handle(const std::vector<std::string>& parameters, User *user);
55 };
56
57 #endif
58
59
60
61
62 CmdResult CommandQline::Handle (const std::vector<std::string>& parameters, User *user)
63 {
64         if (parameters.size() >= 3)
65         {
66                 if (ServerInstance->NickMatchesEveryone(parameters[0],user))
67                         return CMD_FAILURE;
68
69                 if (parameters[0].find('@') != std::string::npos || parameters[0].find('!') != std::string::npos || parameters[0].find('.') != std::string::npos)
70                 {
71                         user->WriteServ("NOTICE %s :*** A Q-Line only bans a nick pattern, not a nick!user@host pattern.",user->nick.c_str());
72                         return CMD_FAILURE;
73                 }
74
75                 long duration = ServerInstance->Duration(parameters[1].c_str());
76                 QLine* ql = new QLine(ServerInstance, ServerInstance->Time(), duration, user->nick.c_str(), parameters[2].c_str(), parameters[0].c_str());
77                 if (ServerInstance->XLines->AddLine(ql,user))
78                 {
79                         if (!duration)
80                         {
81                                 ServerInstance->SNO->WriteToSnoMask('x',"%s added permanent Q-line for %s: %s",user->nick.c_str(), parameters[0].c_str(), parameters[2].c_str());
82                         }
83                         else
84                         {
85                                 time_t c_requires_crap = duration + ServerInstance->Time();
86                                 ServerInstance->SNO->WriteToSnoMask('x',"%s added timed Q-line for %s, expires on %s: %s",user->nick.c_str(),parameters[0].c_str(),
87                                           ServerInstance->TimeString(c_requires_crap).c_str(), parameters[2].c_str());
88                         }
89                         ServerInstance->XLines->ApplyLines();
90                 }
91                 else
92                 {
93                         delete ql;
94                         user->WriteServ("NOTICE %s :*** Q-Line for %s already exists",user->nick.c_str(),parameters[0].c_str());
95                 }
96         }
97         else
98         {
99                 if (ServerInstance->XLines->DelLine(parameters[0].c_str(), "Q", user))
100                 {
101                         ServerInstance->SNO->WriteToSnoMask('x',"%s Removed Q-line on %s.",user->nick.c_str(),parameters[0].c_str());
102                 }
103                 else
104                 {
105                         user->WriteServ("NOTICE %s :*** Q-Line %s not found in list, try /stats q.",user->nick.c_str(),parameters[0].c_str());
106                         return CMD_FAILURE;
107                 }
108         }
109
110         return CMD_SUCCESS;
111 }
112
113
114 COMMAND_INIT(CommandQline)