]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/coremods/core_xline/cmd_zline.cpp
eda5b2a4623fa572da9eb02f73d22a1d5b3f47e1
[user/henk/code/inspircd.git] / src / coremods / core_xline / cmd_zline.cpp
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
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>
7  *
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.
11  *
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
15  * details.
16  *
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/>.
19  */
20
21
22 #include "inspircd.h"
23 #include "xline.h"
24 /** Handle /ZLINE.
25  */
26 class CommandZline : public Command
27 {
28  public:
29         /** Constructor for zline.
30          */
31         CommandZline ( Module* parent) : Command(parent,"ZLINE",1,3) { flags_needed = 'o'; Penalty = 0; syntax = "<ipmask> [<duration> :<reason>]"; }
32         /** Handle command.
33          * @param parameters The parameters to the command
34          * @param user The user issuing the command
35          * @return A value from CmdResult to indicate command success or failure.
36          */
37         CmdResult Handle(const std::vector<std::string>& parameters, User *user);
38 };
39
40 CmdResult CommandZline::Handle (const std::vector<std::string>& parameters, User *user)
41 {
42         std::string target = parameters[0];
43
44         if (parameters.size() >= 3)
45         {
46                 if (target.find('!') != std::string::npos)
47                 {
48                         user->WriteNotice("*** You cannot include a nickname in a zline, a zline must ban only an IP mask");
49                         return CMD_FAILURE;
50                 }
51
52                 User *u = ServerInstance->FindNick(target);
53
54                 if ((u) && (u->registered == REG_ALL))
55                 {
56                         target = u->GetIPString();
57                 }
58
59                 const char* ipaddr = target.c_str();
60
61                 if (strchr(ipaddr,'@'))
62                 {
63                         while (*ipaddr != '@')
64                                 ipaddr++;
65                         ipaddr++;
66                 }
67
68                 if (ServerInstance->IPMatchesEveryone(ipaddr,user))
69                         return CMD_FAILURE;
70
71                 unsigned long duration = InspIRCd::Duration(parameters[1]);
72                 ZLine* zl = new ZLine(ServerInstance->Time(), duration, user->nick.c_str(), parameters[2].c_str(), ipaddr);
73                 if (ServerInstance->XLines->AddLine(zl,user))
74                 {
75                         if (!duration)
76                         {
77                                 ServerInstance->SNO->WriteToSnoMask('x',"%s added permanent Z-line for %s: %s", user->nick.c_str(), ipaddr, parameters[2].c_str());
78                         }
79                         else
80                         {
81                                 time_t c_requires_crap = duration + ServerInstance->Time();
82                                 std::string timestr = InspIRCd::TimeString(c_requires_crap);
83                                 ServerInstance->SNO->WriteToSnoMask('x',"%s added timed Z-line for %s, expires on %s: %s",user->nick.c_str(),ipaddr,
84                                                 timestr.c_str(), parameters[2].c_str());
85                         }
86                         ServerInstance->XLines->ApplyLines();
87                 }
88                 else
89                 {
90                         delete zl;
91                         user->WriteNotice("*** Z-Line for " + std::string(ipaddr) + " already exists");
92                 }
93         }
94         else
95         {
96                 if (ServerInstance->XLines->DelLine(target.c_str(),"Z",user))
97                 {
98                         ServerInstance->SNO->WriteToSnoMask('x',"%s removed Z-line on %s",user->nick.c_str(),target.c_str());
99                 }
100                 else
101                 {
102                         user->WriteNotice("*** Z-Line " + target + " not found in list, try /stats Z.");
103                         return CMD_FAILURE;
104                 }
105         }
106
107         return CMD_SUCCESS;
108 }
109
110 COMMAND_INIT(CommandZline)