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