]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/commands/cmd_zline.cpp
Strip a zline target of anything resembling an ident prior to sanity checking rather...
[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://www.inspircd.org/wiki/index.php/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 #include "commands/cmd_zline.h"
17
18
19
20 extern "C" DllExport Command* init_command(InspIRCd* Instance)
21 {
22         return new CommandZline(Instance);
23 }
24
25 CmdResult CommandZline::Handle (const std::vector<std::string>& parameters, User *user)
26 {
27         std::string target = parameters[0];
28
29         if (parameters.size() >= 3)
30         {
31                 if (target.find('!') != std::string::npos)
32                 {
33                         user->WriteServ("NOTICE %s :*** You cannot include a nickname in a zline, a zline must ban only an IP mask",user->nick.c_str());
34                         return CMD_FAILURE;
35                 }
36
37                 User *u = ServerInstance->FindNick(target.c_str());
38
39                 if (u)
40                 {
41                         target = u->GetIPString();
42                 }
43
44                 const char* ipaddr = target.c_str();
45
46                 if (strchr(ipaddr,'@'))
47                 {
48                         while (*ipaddr != '@')
49                                 ipaddr++;
50                         ipaddr++;
51                 }
52
53                 if (ServerInstance->IPMatchesEveryone(ipaddr,user))
54                         return CMD_FAILURE;
55
56                 long duration = ServerInstance->Duration(parameters[1].c_str());
57
58                 ZLine* zl = new ZLine(ServerInstance, ServerInstance->Time(), duration, user->nick.c_str(), parameters[2].c_str(), ipaddr);
59                 if (ServerInstance->XLines->AddLine(zl,user))
60                 {
61                         if (!duration)
62                         {
63                                 ServerInstance->SNO->WriteToSnoMask('x',"%s added permanent Z-line for %s: %s", user->nick.c_str(), target.c_str(), parameters[2].c_str());
64                         }
65                         else
66                         {
67                                 time_t c_requires_crap = duration + ServerInstance->Time();
68                                 ServerInstance->SNO->WriteToSnoMask('x',"%s added timed Z-line for %s, expires on %s: %s",user->nick.c_str(),target.c_str(),
69                                                 ServerInstance->TimeString(c_requires_crap).c_str(), parameters[2].c_str());
70                         }
71                         ServerInstance->XLines->ApplyLines();
72                 }
73                 else
74                 {
75                         delete zl;
76                         user->WriteServ("NOTICE %s :*** Z-Line for %s already exists",user->nick.c_str(),target.c_str());
77                 }
78         }
79         else
80         {
81                 if (ServerInstance->XLines->DelLine(target.c_str(),"Z",user))
82                 {
83                         ServerInstance->SNO->WriteToSnoMask('x',"%s Removed Z-line on %s.",user->nick.c_str(),target.c_str());
84                 }
85                 else
86                 {
87                         user->WriteServ("NOTICE %s :*** Z-Line %s not found in list, try /stats Z.",user->nick.c_str(),target.c_str());
88                         return CMD_FAILURE;
89                 }
90         }
91
92         return CMD_SUCCESS;
93 }