]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/commands/cmd_zline.cpp
119519e744f3e898d9d8074f899dd5c4f416ad38
[user/henk/code/inspircd.git] / src / commands / cmd_zline.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2008 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                 if (ServerInstance->IPMatchesEveryone(target.c_str(),user))
45                         return CMD_FAILURE;
46
47                 long duration = ServerInstance->Duration(parameters[1].c_str());
48
49                 const char* ipaddr = target.c_str();
50                 User* find = ServerInstance->FindNick(target.c_str());
51
52                 if (find)
53                 {
54                         ipaddr = find->GetIPString();
55                 }
56                 else
57                 {
58                         if (strchr(ipaddr,'@'))
59                         {
60                                 while (*ipaddr != '@')
61                                         ipaddr++;
62                                 ipaddr++;
63                         }
64                 }
65                 ZLine* zl = new ZLine(ServerInstance, ServerInstance->Time(), duration, user->nick.c_str(), parameters[2].c_str(), ipaddr);
66                 if (ServerInstance->XLines->AddLine(zl,user))
67                 {
68                         if (!duration)
69                         {
70                                 ServerInstance->SNO->WriteToSnoMask('x',"%s added permanent Z-line for %s: %s", user->nick.c_str(), target.c_str(), parameters[2].c_str());
71                         }
72                         else
73                         {
74                                 time_t c_requires_crap = duration + ServerInstance->Time();
75                                 ServerInstance->SNO->WriteToSnoMask('x',"%s added timed Z-line for %s, expires on %s: %s",user->nick.c_str(),target.c_str(),
76                                                 ServerInstance->TimeString(c_requires_crap).c_str(), parameters[2].c_str());
77                         }
78                         ServerInstance->XLines->ApplyLines();
79                 }
80                 else
81                 {
82                         delete zl;
83                         user->WriteServ("NOTICE %s :*** Z-Line for %s already exists",user->nick.c_str(),target.c_str());
84                 }
85         }
86         else
87         {
88                 if (ServerInstance->XLines->DelLine(target.c_str(),"Z",user))
89                 {
90                         ServerInstance->SNO->WriteToSnoMask('x',"%s Removed Z-line on %s.",user->nick.c_str(),target.c_str());
91                 }
92                 else
93                 {
94                         user->WriteServ("NOTICE %s :*** Z-Line %s not found in list, try /stats Z.",user->nick.c_str(),target.c_str());
95                         return CMD_FAILURE;
96                 }
97         }
98
99         return CMD_SUCCESS;
100 }