]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/commands/cmd_zline.cpp
bc71b9e1e4eb20df4de479587f8001c347c37de9
[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 char** parameters, int pcnt, User *user)
26 {
27         if (pcnt >= 3)
28         {
29                 if (strchr(parameters[0],'@') || strchr(parameters[0],'!'))
30                 {
31                         user->WriteServ("NOTICE %s :*** You cannot include a username or nickname in a zline, a zline must ban only an IP mask",user->nick);
32                         return CMD_FAILURE;
33                 }
34
35                 if (ServerInstance->IPMatchesEveryone(parameters[0],user))
36                         return CMD_FAILURE;
37
38                 long duration = ServerInstance->Duration(parameters[1]);
39
40                 const char* ipaddr = parameters[0];
41                 User* find = ServerInstance->FindNick(parameters[0]);
42
43                 if (find)
44                 {
45                         ipaddr = find->GetIPString();
46                 }
47                 else
48                 {
49                         if (strchr(ipaddr,'@'))
50                         {
51                                 while (*ipaddr != '@')
52                                         ipaddr++;
53                                 ipaddr++;
54                         }
55                 }
56                 ZLine* zl = new ZLine(ServerInstance, ServerInstance->Time(), duration, user->nick, parameters[2], ipaddr);
57                 if (ServerInstance->XLines->AddLine(zl,user))
58                 {
59                         if (!duration)
60                         {
61                                 ServerInstance->SNO->WriteToSnoMask('x',"%s added permanent Z-line for %s.",user->nick,parameters[0]);
62                         }
63                         else
64                         {
65                                 time_t c_requires_crap = duration + ServerInstance->Time();
66                                 ServerInstance->SNO->WriteToSnoMask('x',"%s added timed Z-line for %s, expires on %s",user->nick,parameters[0],
67                                                 ServerInstance->TimeString(c_requires_crap).c_str());
68                         }
69                         ServerInstance->XLines->ApplyLines();
70                 }
71                 else
72                 {
73                         delete zl;
74                         user->WriteServ("NOTICE %s :*** Z-Line for %s already exists",user->nick,parameters[0]);
75                 }
76         }
77         else
78         {
79                 if (ServerInstance->XLines->DelLine(parameters[0],"Z",user))
80                 {
81                         ServerInstance->SNO->WriteToSnoMask('x',"%s Removed Z-line on %s.",user->nick,parameters[0]);
82                 }
83                 else
84                 {
85                         user->WriteServ("NOTICE %s :*** Z-Line %s not found in list, try /stats Z.",user->nick,parameters[0]);
86                         return CMD_FAILURE;
87                 }
88         }
89
90         return CMD_SUCCESS;
91 }