]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/commands/cmd_kline.cpp
Remove Implements() method from every module. booya.
[user/henk/code/inspircd.git] / src / commands / cmd_kline.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_kline.h"
17
18 extern "C" DllExport Command* init_command(InspIRCd* Instance)
19 {
20         return new CommandKline(Instance);
21 }
22
23 /** Handle /KLINE
24  */
25 CmdResult CommandKline::Handle (const char** parameters, int pcnt, User *user)
26 {
27         if (pcnt >= 3)
28         {
29                 IdentHostPair ih = ServerInstance->XLines->IdentSplit(parameters[0]);
30                 if (ServerInstance->HostMatchesEveryone(ih.first+"@"+ih.second,user))
31                         return CMD_FAILURE;
32
33                 if (!strchr(parameters[0],'@'))
34                 {       
35                         user->WriteServ("NOTICE %s :*** K-Line must contain a username, e.g. *@%s",user->nick,parameters[0]);
36                         return CMD_FAILURE;
37                 }
38                 else if (strchr(parameters[0],'!'))
39                 {
40                         user->WriteServ("NOTICE %s :*** K-Line cannot contain a nickname!",user->nick);
41                         return CMD_FAILURE;
42                 }
43
44                 long duration = ServerInstance->Duration(parameters[1]);
45                 KLine* kl = new KLine(ServerInstance, ServerInstance->Time(), duration, user->nick, parameters[2], ih.first.c_str(), ih.second.c_str());
46                 if (ServerInstance->XLines->AddLine(kl,user))
47                 {
48                         if (!duration)
49                         {
50                                 ServerInstance->SNO->WriteToSnoMask('x',"%s added permanent K-line for %s.",user->nick,parameters[0]);
51                         }
52                         else
53                         {
54                                 time_t c_requires_crap = duration + ServerInstance->Time();
55                                 ServerInstance->SNO->WriteToSnoMask('x',"%s added timed K-line for %s, expires on %s",user->nick,parameters[0],
56                                                 ServerInstance->TimeString(c_requires_crap).c_str());
57                         }
58
59                         ServerInstance->XLines->ApplyLines();
60                 }
61                 else
62                 {
63                         delete kl;
64                         user->WriteServ("NOTICE %s :*** K-Line for %s already exists",user->nick,parameters[0]);
65                 }
66         }
67         else
68         {
69                 if (ServerInstance->XLines->DelLine(parameters[0],"K",user))
70                 {
71                         ServerInstance->SNO->WriteToSnoMask('x',"%s Removed K-line on %s.",user->nick,parameters[0]);
72                 }
73                 else
74                 {
75                         user->WriteServ("NOTICE %s :*** K-Line %s not found in list, try /stats k.",user->nick,parameters[0]);
76                 }
77         }
78
79         return CMD_SUCCESS;
80 }
81