]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/coremods/core_xline/cmd_gline.cpp
05068362fec3de3bd12e1968a1a7ac1d1c846fe6
[user/henk/code/inspircd.git] / src / coremods / core_xline / cmd_gline.cpp
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  *   Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org>
5  *   Copyright (C) 2007-2008 Robin Burchell <robin+git@viroteck.net>
6  *
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.
10  *
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
14  * details.
15  *
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/>.
18  */
19
20
21 #include "inspircd.h"
22 #include "xline.h"
23 #include "core_xline.h"
24
25 CommandGline::CommandGline(Module* parent)
26         : Command(parent, "GLINE", 1, 3)
27 {
28         flags_needed = 'o';
29         syntax = "<user@host> [<duration> :<reason>]";
30 }
31
32 /** Handle /GLINE
33  */
34 CmdResult CommandGline::Handle(User* user, const Params& parameters)
35 {
36         std::string target = parameters[0];
37
38         if (parameters.size() >= 3)
39         {
40                 IdentHostPair ih;
41                 User* find = ServerInstance->FindNick(target);
42                 if ((find) && (find->registered == REG_ALL))
43                 {
44                         ih.first = "*";
45                         ih.second = find->GetIPString();
46                         target = std::string("*@") + find->GetIPString();
47                 }
48                 else
49                         ih = ServerInstance->XLines->IdentSplit(target);
50
51                 if (ih.first.empty())
52                 {
53                         user->WriteNotice("*** Target not found.");
54                         return CMD_FAILURE;
55                 }
56
57                 InsaneBan::IPHostMatcher matcher;
58                 if (InsaneBan::MatchesEveryone(ih.first+"@"+ih.second, matcher, user, "G", "hostmasks"))
59                         return CMD_FAILURE;
60
61                 else if (target.find('!') != std::string::npos)
62                 {
63                         user->WriteNotice("*** G-line cannot operate on nick!user@host masks.");
64                         return CMD_FAILURE;
65                 }
66
67                 unsigned long duration;
68                 if (!InspIRCd::Duration(parameters[1], duration))
69                 {
70                         user->WriteNotice("*** Invalid duration for G-line.");
71                         return CMD_FAILURE;
72                 }
73                 GLine* gl = new GLine(ServerInstance->Time(), duration, user->nick.c_str(), parameters[2].c_str(), ih.first.c_str(), ih.second.c_str());
74                 if (ServerInstance->XLines->AddLine(gl, user))
75                 {
76                         if (!duration)
77                         {
78                                 ServerInstance->SNO->WriteToSnoMask('x', "%s added permanent G-line for %s: %s", user->nick.c_str(), target.c_str(), parameters[2].c_str());
79                         }
80                         else
81                         {
82                                 ServerInstance->SNO->WriteToSnoMask('x', "%s added timed G-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());
85                         }
86
87                         ServerInstance->XLines->ApplyLines();
88                 }
89                 else
90                 {
91                         delete gl;
92                         user->WriteNotice("** G-line for " + target + " already exists.");
93                 }
94
95         }
96         else
97         {
98                 std::string reason;
99
100                 if (ServerInstance->XLines->DelLine(target.c_str(), "G", reason, user))
101                 {
102                         ServerInstance->SNO->WriteToSnoMask('x', "%s removed G-line on %s: %s", user->nick.c_str(), target.c_str(), reason.c_str());
103                 }
104                 else
105                 {
106                         user->WriteNotice("*** G-line " + target + " not found on the list.");
107                 }
108         }
109
110         return CMD_SUCCESS;
111 }