2 * InspIRCd -- Internet Relay Chat Daemon
4 * Copyright (C) 2019 Matt Schatz <genius3000@g3k.solutions>
5 * Copyright (C) 2018 linuxdaemon <linuxdaemon.irc@gmail.com>
6 * Copyright (C) 2018 Sadie Powell <sadie@witchery.services>
7 * Copyright (C) 2012, 2018-2019 Robby <robby@chatbelgie.be>
8 * Copyright (C) 2012, 2014 Attila Molnar <attilamolnar@hush.com>
9 * Copyright (C) 2009 Uli Schlachter <psychon@inspircd.org>
10 * Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org>
11 * Copyright (C) 2007-2008 Robin Burchell <robin+git@viroteck.net>
12 * Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
13 * Copyright (C) 2006-2008, 2010 Craig Edwards <brain@inspircd.org>
15 * This file is part of InspIRCd. InspIRCd is free software: you can
16 * redistribute it and/or modify it under the terms of the GNU General Public
17 * License as published by the Free Software Foundation, version 2.
19 * This program is distributed in the hope that it will be useful, but WITHOUT
20 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
21 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
24 * You should have received a copy of the GNU General Public License
25 * along with this program. If not, see <http://www.gnu.org/licenses/>.
31 #include "core_xline.h"
33 CommandKline::CommandKline(Module* parent)
34 : Command(parent, "KLINE", 1, 3)
37 syntax = "<user@host> [<duration> :<reason>]";
42 CmdResult CommandKline::Handle(User* user, const Params& parameters)
44 std::string target = parameters[0];
46 if (parameters.size() >= 3)
49 User* find = ServerInstance->FindNick(target);
50 if ((find) && (find->registered == REG_ALL))
53 ih.second = find->GetIPString();
54 target = std::string("*@") + find->GetIPString();
57 ih = ServerInstance->XLines->IdentSplit(target);
61 user->WriteNotice("*** Target not found.");
65 InsaneBan::IPHostMatcher matcher;
66 if (InsaneBan::MatchesEveryone(ih.first+"@"+ih.second, matcher, user, "K", "hostmasks"))
69 if (target.find('!') != std::string::npos)
71 user->WriteNotice("*** K-line cannot operate on nick!user@host masks.");
75 unsigned long duration;
76 if (!InspIRCd::Duration(parameters[1], duration))
78 user->WriteNotice("*** Invalid duration for K-line.");
81 KLine* kl = new KLine(ServerInstance->Time(), duration, user->nick.c_str(), parameters[2].c_str(), ih.first.c_str(), ih.second.c_str());
82 if (ServerInstance->XLines->AddLine(kl,user))
86 ServerInstance->SNO->WriteToSnoMask('x', "%s added permanent K-line for %s: %s", user->nick.c_str(), target.c_str(), parameters[2].c_str());
90 ServerInstance->SNO->WriteToSnoMask('x', "%s added timed K-line for %s, expires in %s (on %s): %s",
91 user->nick.c_str(), target.c_str(), InspIRCd::DurationString(duration).c_str(),
92 InspIRCd::TimeString(ServerInstance->Time() + duration).c_str(), parameters[2].c_str());
95 ServerInstance->XLines->ApplyLines();
100 user->WriteNotice("*** K-line for " + target + " already exists.");
107 if (ServerInstance->XLines->DelLine(target.c_str(), "K", reason, user))
109 ServerInstance->SNO->WriteToSnoMask('x', "%s removed K-line on %s: %s", user->nick.c_str(), target.c_str(), reason.c_str());
113 user->WriteNotice("*** K-line " + target + " not found on the list.");