2 * InspIRCd -- Internet Relay Chat Daemon
4 * Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org>
5 * Copyright (C) 2009 Matt Smith <dz@inspircd.org>
6 * Copyright (C) 2007-2008 Robin Burchell <robin+git@viroteck.net>
8 * This file is part of InspIRCd. InspIRCd is free software: you can
9 * redistribute it and/or modify it under the terms of the GNU General Public
10 * License as published by the Free Software Foundation, version 2.
12 * This program is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
24 #include "core_xline.h"
26 CommandZline::CommandZline(Module* parent)
27 : Command(parent, "ZLINE", 1, 3)
31 syntax = "<ipmask> [<duration> :<reason>]";
34 CmdResult CommandZline::Handle (const std::vector<std::string>& parameters, User *user)
36 std::string target = parameters[0];
38 if (parameters.size() >= 3)
40 if (target.find('!') != std::string::npos)
42 user->WriteNotice("*** You cannot include a nickname in a zline, a zline must ban only an IP mask");
46 User *u = ServerInstance->FindNick(target);
48 if ((u) && (u->registered == REG_ALL))
50 target = u->GetIPString();
53 const char* ipaddr = target.c_str();
55 if (strchr(ipaddr,'@'))
57 while (*ipaddr != '@')
63 if (InsaneBan::MatchesEveryone(ipaddr, matcher, user, "Z", "ipmasks"))
66 unsigned long duration = InspIRCd::Duration(parameters[1]);
67 ZLine* zl = new ZLine(ServerInstance->Time(), duration, user->nick.c_str(), parameters[2].c_str(), ipaddr);
68 if (ServerInstance->XLines->AddLine(zl,user))
72 ServerInstance->SNO->WriteToSnoMask('x',"%s added permanent Z-line for %s: %s", user->nick.c_str(), ipaddr, parameters[2].c_str());
76 time_t c_requires_crap = duration + ServerInstance->Time();
77 std::string timestr = InspIRCd::TimeString(c_requires_crap);
78 ServerInstance->SNO->WriteToSnoMask('x',"%s added timed Z-line for %s, expires on %s: %s",user->nick.c_str(),ipaddr,
79 timestr.c_str(), parameters[2].c_str());
81 ServerInstance->XLines->ApplyLines();
86 user->WriteNotice("*** Z-Line for " + std::string(ipaddr) + " already exists");
91 if (ServerInstance->XLines->DelLine(target.c_str(),"Z",user))
93 ServerInstance->SNO->WriteToSnoMask('x',"%s removed Z-line on %s",user->nick.c_str(),target.c_str());
97 user->WriteNotice("*** Z-Line " + target + " not found in list, try /stats Z.");
105 bool CommandZline::IPMatcher::Check(User* user, const std::string& ip) const
107 return InspIRCd::Match(user->GetIPString(), ip, ascii_case_insensitive_map);