]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/commands/cmd_zline.cpp
e701867fb7c56c7dbad4244c8f984cf4641944ee
[user/henk/code/inspircd.git] / src / commands / cmd_zline.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2007 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                 if (strchr(ipaddr,'@'))
42                 {
43                         while (*ipaddr != '@')
44                                 ipaddr++;
45                         ipaddr++;
46                 }
47                 ZLine* zl = new ZLine(ServerInstance, ServerInstance->Time(), duration, user->nick, parameters[2], ipaddr);
48                 if (ServerInstance->XLines->AddLine(zl,user))
49                 {
50                         if (!duration)
51                         {
52                                 ServerInstance->SNO->WriteToSnoMask('x',"%s added permanent Z-line for %s.",user->nick,parameters[0]);
53                         }
54                         else
55                         {
56                                 time_t c_requires_crap = duration + ServerInstance->Time();
57                                 ServerInstance->SNO->WriteToSnoMask('x',"%s added timed Z-line for %s, expires on %s",user->nick,parameters[0],
58                                                 ServerInstance->TimeString(c_requires_crap).c_str());
59                         }
60                         ServerInstance->XLines->ApplyLines();
61                 }
62                 else
63                 {
64                         delete zl;
65                         user->WriteServ("NOTICE %s :*** Z-Line for %s already exists",user->nick,parameters[0]);
66                 }
67         }
68         else
69         {
70                 if (ServerInstance->XLines->DelLine(parameters[0],'Z',user))
71                 {
72                         ServerInstance->SNO->WriteToSnoMask('x',"%s Removed Z-line on %s.",user->nick,parameters[0]);
73                 }
74                 else
75                 {
76                         user->WriteServ("NOTICE %s :*** Z-Line %s not found in list, try /stats Z.",user->nick,parameters[0]);
77                         return CMD_FAILURE;
78                 }
79         }
80
81         return CMD_SUCCESS;
82 }