]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/commands/cmd_kline.cpp
Fix mistakenly using Clang instead of GCC on older FreeBSD versions.
[user/henk/code/inspircd.git] / src / commands / cmd_kline.cpp
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  *   Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org>
5  *   Copyright (C) 2007-2008 Robin Burchell <robin+git@viroteck.net>
6  *
7  * This file is part of InspIRCd.  InspIRCd is free software: you can
8  * redistribute it and/or modify it under the terms of the GNU General Public
9  * License as published by the Free Software Foundation, version 2.
10  *
11  * This program is distributed in the hope that it will be useful, but WITHOUT
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
14  * details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18  */
19
20
21 #include "inspircd.h"
22 #include "xline.h"
23
24 /** Handle /KLINE. These command handlers can be reloaded by the core,
25  * and handle basic RFC1459 commands. Commands within modules work
26  * the same way, however, they can be fully unloaded, where these
27  * may not.
28  */
29 class CommandKline : public Command
30 {
31  public:
32         /** Constructor for kline.
33          */
34         CommandKline ( Module* parent) : Command(parent,"KLINE",1,3) { flags_needed = 'o'; Penalty = 0; syntax = "<ident@host> [<duration> :<reason>]"; }
35         /** Handle command.
36          * @param parameters The parameters to the comamnd
37          * @param pcnt The number of parameters passed to teh command
38          * @param user The user issuing the command
39          * @return A value from CmdResult to indicate command success or failure.
40          */
41         CmdResult Handle(const std::vector<std::string>& parameters, User *user);
42 };
43
44
45 /** Handle /KLINE
46  */
47 CmdResult CommandKline::Handle (const std::vector<std::string>& parameters, User *user)
48 {
49     std::string target = parameters[0];
50
51         if (parameters.size() >= 3)
52         {
53                 IdentHostPair ih;
54                 User* find = ServerInstance->FindNick(target);
55                 if ((find) && (find->registered == REG_ALL))
56                 {
57                         ih.first = "*";
58                         ih.second = find->GetIPString();
59                         target = std::string("*@") + find->GetIPString();
60                 }
61                 else
62                         ih = ServerInstance->XLines->IdentSplit(target);
63
64         if (ih.first.empty())
65         {
66             user->WriteServ("NOTICE %s :*** Target not found", user->nick.c_str());
67             return CMD_FAILURE;
68         }
69
70                 if (ServerInstance->HostMatchesEveryone(ih.first+"@"+ih.second,user))
71                         return CMD_FAILURE;
72
73                 if (target.find('!') != std::string::npos)
74                 {
75                         user->WriteServ("NOTICE %s :*** K-Line cannot operate on nick!user@host masks",user->nick.c_str());
76                         return CMD_FAILURE;
77                 }
78
79                 long duration = ServerInstance->Duration(parameters[1].c_str());
80                 KLine* kl = new KLine(ServerInstance->Time(), duration, user->nick.c_str(), parameters[2].c_str(), ih.first.c_str(), ih.second.c_str());
81                 if (ServerInstance->XLines->AddLine(kl,user))
82                 {
83                         if (!duration)
84                         {
85                                 ServerInstance->SNO->WriteToSnoMask('x',"%s added permanent K-line for %s: %s",user->nick.c_str(),target.c_str(), parameters[2].c_str());
86                         }
87                         else
88                         {
89                                 time_t c_requires_crap = duration + ServerInstance->Time();
90                                 std::string timestr = ServerInstance->TimeString(c_requires_crap);
91                                 ServerInstance->SNO->WriteToSnoMask('x',"%s added timed K-line for %s, expires on %s: %s",user->nick.c_str(),target.c_str(),
92                                                 timestr.c_str(), parameters[2].c_str());
93                         }
94
95                         ServerInstance->XLines->ApplyLines();
96                 }
97                 else
98                 {
99                         delete kl;
100                         user->WriteServ("NOTICE %s :*** K-Line for %s already exists",user->nick.c_str(),target.c_str());
101                 }
102         }
103         else
104         {
105                 if (ServerInstance->XLines->DelLine(target.c_str(),"K",user))
106                 {
107                         ServerInstance->SNO->WriteToSnoMask('x',"%s removed K-line on %s",user->nick.c_str(),target.c_str());
108                 }
109                 else
110                 {
111                         user->WriteServ("NOTICE %s :*** K-Line %s not found in list, try /stats k.",user->nick.c_str(),target.c_str());
112                 }
113         }
114
115         return CMD_SUCCESS;
116 }
117
118 COMMAND_INIT(CommandKline)