]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/coremods/core_xline/cmd_qline.cpp
Sync helpop chmodes s and p with docs
[user/henk/code/inspircd.git] / src / coremods / core_xline / cmd_qline.cpp
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
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) 2014 Attila Molnar <attilamolnar@hush.com>
8  *   Copyright (C) 2012, 2019 Robby <robby@chatbelgie.be>
9  *   Copyright (C) 2009 Uli Schlachter <psychon@inspircd.org>
10  *   Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org>
11  *   Copyright (C) 2008 Thomas Stagner <aquanight@inspircd.org>
12  *   Copyright (C) 2007 Robin Burchell <robin+git@viroteck.net>
13  *   Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
14  *   Copyright (C) 2006-2008, 2010 Craig Edwards <brain@inspircd.org>
15  *
16  * This file is part of InspIRCd.  InspIRCd is free software: you can
17  * redistribute it and/or modify it under the terms of the GNU General Public
18  * License as published by the Free Software Foundation, version 2.
19  *
20  * This program is distributed in the hope that it will be useful, but WITHOUT
21  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
22  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
23  * details.
24  *
25  * You should have received a copy of the GNU General Public License
26  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
27  */
28
29
30 #include "inspircd.h"
31 #include "xline.h"
32 #include "core_xline.h"
33
34 CommandQline::CommandQline(Module* parent)
35         : Command(parent, "QLINE", 1, 3)
36 {
37         flags_needed = 'o';
38         syntax = "<nickmask> [<duration> :<reason>]";
39 }
40
41 CmdResult CommandQline::Handle(User* user, const Params& parameters)
42 {
43         if (parameters.size() >= 3)
44         {
45                 NickMatcher matcher;
46                 if (InsaneBan::MatchesEveryone(parameters[0], matcher, user, "Q", "nickmasks"))
47                         return CMD_FAILURE;
48
49                 if (parameters[0].find('@') != std::string::npos || parameters[0].find('!') != std::string::npos || parameters[0].find('.') != std::string::npos)
50                 {
51                         user->WriteNotice("*** A Q-line only bans a nick pattern, not a nick!user@host pattern.");
52                         return CMD_FAILURE;
53                 }
54
55                 unsigned long duration;
56                 if (!InspIRCd::Duration(parameters[1], duration))
57                 {
58                         user->WriteNotice("*** Invalid duration for Q-line.");
59                         return CMD_FAILURE;
60                 }
61                 QLine* ql = new QLine(ServerInstance->Time(), duration, user->nick.c_str(), parameters[2].c_str(), parameters[0].c_str());
62                 if (ServerInstance->XLines->AddLine(ql,user))
63                 {
64                         if (!duration)
65                         {
66                                 ServerInstance->SNO->WriteToSnoMask('x', "%s added permanent Q-line for %s: %s", user->nick.c_str(), parameters[0].c_str(), parameters[2].c_str());
67                         }
68                         else
69                         {
70                                 ServerInstance->SNO->WriteToSnoMask('x', "%s added timed Q-line for %s, expires in %s (on %s): %s",
71                                         user->nick.c_str(), parameters[0].c_str(), InspIRCd::DurationString(duration).c_str(),
72                                         InspIRCd::TimeString(ServerInstance->Time() + duration).c_str(), parameters[2].c_str());
73                         }
74                         ServerInstance->XLines->ApplyLines();
75                 }
76                 else
77                 {
78                         delete ql;
79                         user->WriteNotice("*** Q-line for " + parameters[0] + " already exists.");
80                 }
81         }
82         else
83         {
84                 std::string reason;
85
86                 if (ServerInstance->XLines->DelLine(parameters[0].c_str(), "Q", reason, user))
87                 {
88                         ServerInstance->SNO->WriteToSnoMask('x', "%s removed Q-line on %s: %s", user->nick.c_str(), parameters[0].c_str(), reason.c_str());
89                 }
90                 else
91                 {
92                         user->WriteNotice("*** Q-line " + parameters[0] + " not found on the list.");
93                         return CMD_FAILURE;
94                 }
95         }
96
97         return CMD_SUCCESS;
98 }
99
100 bool CommandQline::NickMatcher::Check(User* user, const std::string& nick) const
101 {
102         return InspIRCd::Match(user->nick, nick);
103 }