]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/commands/cmd_zline.cpp
Remove InspIRCd* parameters and fields
[user/henk/code/inspircd.git] / src / commands / cmd_zline.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2009 InspIRCd Development Team
6  * See: http://wiki.inspircd.org/Credits
7  *
8  * This program is free but copyrighted software; see
9  *          the file COPYING for details.
10  *
11  * ---------------------------------------------------
12  */
13
14 #include "inspircd.h"
15 #include "xline.h"
16 /** Handle /ZLINE. These command handlers can be reloaded by the core,
17  * and handle basic RFC1459 commands. Commands within modules work
18  * the same way, however, they can be fully unloaded, where these
19  * may not.
20  */
21 class CommandZline : public Command
22 {
23  public:
24         /** Constructor for zline.
25          */
26         CommandZline ( Module* parent) : Command(parent,"ZLINE",1,3) { flags_needed = 'o'; Penalty = 0; syntax = "<ipmask> [<duration> :<reason>]"; }
27         /** Handle command.
28          * @param parameters The parameters to the comamnd
29          * @param pcnt The number of parameters passed to teh command
30          * @param user The user issuing the command
31          * @return A value from CmdResult to indicate command success or failure.
32          */
33         CmdResult Handle(const std::vector<std::string>& parameters, User *user);
34 };
35
36 CmdResult CommandZline::Handle (const std::vector<std::string>& parameters, User *user)
37 {
38         std::string target = parameters[0];
39
40         if (parameters.size() >= 3)
41         {
42                 if (target.find('!') != std::string::npos)
43                 {
44                         user->WriteServ("NOTICE %s :*** You cannot include a nickname in a zline, a zline must ban only an IP mask",user->nick.c_str());
45                         return CMD_FAILURE;
46                 }
47
48                 User *u = ServerInstance->FindNick(target.c_str());
49
50                 if (u)
51                 {
52                         target = u->GetIPString();
53                 }
54
55                 const char* ipaddr = target.c_str();
56
57                 if (strchr(ipaddr,'@'))
58                 {
59                         while (*ipaddr != '@')
60                                 ipaddr++;
61                         ipaddr++;
62                 }
63
64                 if (ServerInstance->IPMatchesEveryone(ipaddr,user))
65                         return CMD_FAILURE;
66
67                 long duration = ServerInstance->Duration(parameters[1].c_str());
68
69                 ZLine* zl = new ZLine(ServerInstance->Time(), duration, user->nick.c_str(), parameters[2].c_str(), ipaddr);
70                 if (ServerInstance->XLines->AddLine(zl,user))
71                 {
72                         if (!duration)
73                         {
74                                 ServerInstance->SNO->WriteToSnoMask('x',"%s added permanent Z-line for %s: %s", user->nick.c_str(), ipaddr, parameters[2].c_str());
75                         }
76                         else
77                         {
78                                 time_t c_requires_crap = duration + ServerInstance->Time();
79                                 ServerInstance->SNO->WriteToSnoMask('x',"%s added timed Z-line for %s, expires on %s: %s",user->nick.c_str(),ipaddr,
80                                                 ServerInstance->TimeString(c_requires_crap).c_str(), parameters[2].c_str());
81                         }
82                         ServerInstance->XLines->ApplyLines();
83                 }
84                 else
85                 {
86                         delete zl;
87                         user->WriteServ("NOTICE %s :*** Z-Line for %s already exists",user->nick.c_str(),ipaddr);
88                 }
89         }
90         else
91         {
92                 if (ServerInstance->XLines->DelLine(target.c_str(),"Z",user))
93                 {
94                         ServerInstance->SNO->WriteToSnoMask('x',"%s removed Z-line on %s",user->nick.c_str(),target.c_str());
95                 }
96                 else
97                 {
98                         user->WriteServ("NOTICE %s :*** Z-Line %s not found in list, try /stats Z.",user->nick.c_str(),target.c_str());
99                         return CMD_FAILURE;
100                 }
101         }
102
103         return CMD_SUCCESS;
104 }
105
106 COMMAND_INIT(CommandZline)