]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/commands/cmd_kline.cpp
3ec2461b4f3b93ddf73146d14aec21efae6e19b2
[user/henk/code/inspircd.git] / src / commands / cmd_kline.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 /KLINE. These command handlers can be reloaded by the core,
18  * and handle basic RFC1459 commands. Commands within modules work
19  * the same way, however, they can be fully unloaded, where these
20  * may not.
21  */
22 class CommandKline : public Command
23 {
24  public:
25         /** Constructor for kline.
26          */
27         CommandKline ( Module* parent) : Command(parent,"KLINE",1,3) { flags_needed = 'o'; Penalty = 0; syntax = "<ident@host> [<duration> :<reason>]"; }
28         /** Handle command.
29          * @param parameters The parameters to the comamnd
30          * @param pcnt The number of parameters passed to teh command
31          * @param user The user issuing the command
32          * @return A value from CmdResult to indicate command success or failure.
33          */
34         CmdResult Handle(const std::vector<std::string>& parameters, User *user);
35 };
36
37
38 /** Handle /KLINE
39  */
40 CmdResult CommandKline::Handle (const std::vector<std::string>& parameters, User *user)
41 {
42     std::string target = parameters[0];
43
44         if (parameters.size() >= 3)
45         {
46                 IdentHostPair ih;
47                 User* find = ServerInstance->FindNick(target.c_str());
48                 if (find)
49                 {
50                         ih.first = "*";
51                         ih.second = find->GetIPString();
52                         target = std::string("*@") + find->GetIPString();
53                 }
54                 else
55                         ih = ServerInstance->XLines->IdentSplit(target.c_str());
56
57         if (ih.first.empty())
58         {
59             user->WriteServ("NOTICE %s :*** Target not found", user->nick.c_str());
60             return CMD_FAILURE;
61         }
62
63                 if (ServerInstance->HostMatchesEveryone(ih.first+"@"+ih.second,user))
64                         return CMD_FAILURE;
65
66                 if (target.find('!') != std::string::npos)
67                 {
68                         user->WriteServ("NOTICE %s :*** K-Line cannot operate on nick!user@host masks",user->nick.c_str());
69                         return CMD_FAILURE;
70                 }
71
72                 long duration = ServerInstance->Duration(parameters[1].c_str());
73                 KLine* kl = new KLine(ServerInstance, ServerInstance->Time(), duration, user->nick.c_str(), parameters[2].c_str(), ih.first.c_str(), ih.second.c_str());
74                 if (ServerInstance->XLines->AddLine(kl,user))
75                 {
76                         if (!duration)
77                         {
78                                 ServerInstance->SNO->WriteToSnoMask('x',"%s added permanent K-line for %s: %s",user->nick.c_str(),target.c_str(), parameters[2].c_str());
79                         }
80                         else
81                         {
82                                 time_t c_requires_crap = duration + ServerInstance->Time();
83                                 ServerInstance->SNO->WriteToSnoMask('x',"%s added timed K-line for %s, expires on %s: %s",user->nick.c_str(),target.c_str(),
84                                                 ServerInstance->TimeString(c_requires_crap).c_str(), parameters[2].c_str());
85                         }
86
87                         ServerInstance->XLines->ApplyLines();
88                 }
89                 else
90                 {
91                         delete kl;
92                         user->WriteServ("NOTICE %s :*** K-Line for %s already exists",user->nick.c_str(),target.c_str());
93                 }
94         }
95         else
96         {
97                 if (ServerInstance->XLines->DelLine(target.c_str(),"K",user))
98                 {
99                         ServerInstance->SNO->WriteToSnoMask('x',"%s removed K-line on %s",user->nick.c_str(),target.c_str());
100                 }
101                 else
102                 {
103                         user->WriteServ("NOTICE %s :*** K-Line %s not found in list, try /stats k.",user->nick.c_str(),target.c_str());
104                 }
105         }
106
107         return CMD_SUCCESS;
108 }
109
110 COMMAND_INIT(CommandKline)