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