2 * InspIRCd -- Internet Relay Chat Daemon
4 * Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org>
5 * Copyright (C) 2007-2008 Robin Burchell <robin+git@viroteck.net>
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.
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
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/>.
23 #include "core_xline.h"
25 CommandKline::CommandKline(Module* parent)
26 : Command(parent, "KLINE", 1, 3)
29 syntax = "<user@host> [<duration> :<reason>]";
34 CmdResult CommandKline::Handle(User* user, const Params& parameters)
36 std::string target = parameters[0];
38 if (parameters.size() >= 3)
41 User* find = ServerInstance->FindNick(target);
42 if ((find) && (find->registered == REG_ALL))
45 ih.second = find->GetIPString();
46 target = std::string("*@") + find->GetIPString();
49 ih = ServerInstance->XLines->IdentSplit(target);
53 user->WriteNotice("*** Target not found.");
57 InsaneBan::IPHostMatcher matcher;
58 if (InsaneBan::MatchesEveryone(ih.first+"@"+ih.second, matcher, user, "K", "hostmasks"))
61 if (target.find('!') != std::string::npos)
63 user->WriteNotice("*** K-line cannot operate on nick!user@host masks.");
67 unsigned long duration;
68 if (!InspIRCd::Duration(parameters[1], duration))
70 user->WriteNotice("*** Invalid duration for K-line.");
73 KLine* kl = new KLine(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))
78 ServerInstance->SNO->WriteToSnoMask('x', "%s added permanent K-line for %s: %s", user->nick.c_str(), target.c_str(), parameters[2].c_str());
82 ServerInstance->SNO->WriteToSnoMask('x', "%s added timed K-line for %s, expires in %s (on %s): %s",
83 user->nick.c_str(), target.c_str(), InspIRCd::DurationString(duration).c_str(),
84 InspIRCd::TimeString(ServerInstance->Time() + duration).c_str(), parameters[2].c_str());
87 ServerInstance->XLines->ApplyLines();
92 user->WriteNotice("*** K-line for " + target + " already exists.");
99 if (ServerInstance->XLines->DelLine(target.c_str(), "K", reason, user))
101 ServerInstance->SNO->WriteToSnoMask('x', "%s removed K-line on %s: %s", user->nick.c_str(), target.c_str(), reason.c_str());
105 user->WriteNotice("*** K-line " + target + " not found on the list.");