]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/commands/cmd_zline.cpp
Add -Wshadow to cflags, and fix a bunch of warnings that come with it. Add a note...
[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                 User *u = ServerInstance->FindNick(parameters[0]);
36                 
37                 if (u)
38                 {
39                         parameters[0] = u->GetIPString();
40                 }
41
42                 if (ServerInstance->IPMatchesEveryone(parameters[0],user))
43                         return CMD_FAILURE;
44
45                 long duration = ServerInstance->Duration(parameters[1]);
46
47                 const char* ipaddr = parameters[0];
48                 User* find = ServerInstance->FindNick(parameters[0]);
49
50                 if (find)
51                 {
52                         ipaddr = find->GetIPString();
53                 }
54                 else
55                 {
56                         if (strchr(ipaddr,'@'))
57                         {
58                                 while (*ipaddr != '@')
59                                         ipaddr++;
60                                 ipaddr++;
61                         }
62                 }
63                 ZLine* zl = new ZLine(ServerInstance, ServerInstance->Time(), duration, user->nick, parameters[2], ipaddr);
64                 if (ServerInstance->XLines->AddLine(zl,user))
65                 {
66                         if (!duration)
67                         {
68                                 ServerInstance->SNO->WriteToSnoMask('x',"%s added permanent Z-line for %s.",user->nick,parameters[0]);
69                         }
70                         else
71                         {
72                                 time_t c_requires_crap = duration + ServerInstance->Time();
73                                 ServerInstance->SNO->WriteToSnoMask('x',"%s added timed Z-line for %s, expires on %s",user->nick,parameters[0],
74                                                 ServerInstance->TimeString(c_requires_crap).c_str());
75                         }
76                         ServerInstance->XLines->ApplyLines();
77                 }
78                 else
79                 {
80                         delete zl;
81                         user->WriteServ("NOTICE %s :*** Z-Line for %s already exists",user->nick,parameters[0]);
82                 }
83         }
84         else
85         {
86                 if (ServerInstance->XLines->DelLine(parameters[0],"Z",user))
87                 {
88                         ServerInstance->SNO->WriteToSnoMask('x',"%s Removed Z-line on %s.",user->nick,parameters[0]);
89                 }
90                 else
91                 {
92                         user->WriteServ("NOTICE %s :*** Z-Line %s not found in list, try /stats Z.",user->nick,parameters[0]);
93                         return CMD_FAILURE;
94                 }
95         }
96
97         return CMD_SUCCESS;
98 }