]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/coremods/core_xline/cmd_kline.cpp
core_whowas Switch from map to a hash map and from irc::string to std::string
[user/henk/code/inspircd.git] / src / coremods / core_xline / 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 #include "core_xline.h"
24
25 CommandKline::CommandKline(Module* parent)
26         : Command(parent, "KLINE", 1, 3)
27 {
28         flags_needed = 'o';
29         Penalty = 0;
30         syntax = "<ident@host> [<duration> :<reason>]";
31 }
32
33 /** Handle /KLINE
34  */
35 CmdResult CommandKline::Handle (const std::vector<std::string>& parameters, User *user)
36 {
37     std::string target = parameters[0];
38
39         if (parameters.size() >= 3)
40         {
41                 IdentHostPair ih;
42                 User* find = ServerInstance->FindNick(target);
43                 if ((find) && (find->registered == REG_ALL))
44                 {
45                         ih.first = "*";
46                         ih.second = find->GetIPString();
47                         target = std::string("*@") + find->GetIPString();
48                 }
49                 else
50                         ih = ServerInstance->XLines->IdentSplit(target);
51
52         if (ih.first.empty())
53         {
54             user->WriteNotice("*** Target not found");
55             return CMD_FAILURE;
56         }
57
58                 InsaneBan::IPHostMatcher matcher;
59                 if (InsaneBan::MatchesEveryone(ih.first+"@"+ih.second, matcher, user, "K", "hostmasks"))
60                         return CMD_FAILURE;
61
62                 if (target.find('!') != std::string::npos)
63                 {
64                         user->WriteNotice("*** K-Line cannot operate on nick!user@host masks");
65                         return CMD_FAILURE;
66                 }
67
68                 unsigned long duration = InspIRCd::Duration(parameters[1]);
69                 KLine* kl = new KLine(ServerInstance->Time(), duration, user->nick.c_str(), parameters[2].c_str(), ih.first.c_str(), ih.second.c_str());
70                 if (ServerInstance->XLines->AddLine(kl,user))
71                 {
72                         if (!duration)
73                         {
74                                 ServerInstance->SNO->WriteToSnoMask('x',"%s added permanent K-line for %s: %s",user->nick.c_str(),target.c_str(), parameters[2].c_str());
75                         }
76                         else
77                         {
78                                 time_t c_requires_crap = duration + ServerInstance->Time();
79                                 std::string timestr = InspIRCd::TimeString(c_requires_crap);
80                                 ServerInstance->SNO->WriteToSnoMask('x',"%s added timed K-line for %s, expires on %s: %s",user->nick.c_str(),target.c_str(),
81                                                 timestr.c_str(), parameters[2].c_str());
82                         }
83
84                         ServerInstance->XLines->ApplyLines();
85                 }
86                 else
87                 {
88                         delete kl;
89                         user->WriteNotice("*** K-Line for " + target + " already exists");
90                 }
91         }
92         else
93         {
94                 if (ServerInstance->XLines->DelLine(target.c_str(),"K",user))
95                 {
96                         ServerInstance->SNO->WriteToSnoMask('x',"%s removed K-line on %s",user->nick.c_str(),target.c_str());
97                 }
98                 else
99                 {
100                         user->WriteNotice("*** K-Line " + target + " not found in list, try /stats k.");
101                 }
102         }
103
104         return CMD_SUCCESS;
105 }