]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/commands/cmd_kline.cpp
Fake lag on nick change, thanks pLaYa
[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;
30                 User* find = ServerInstance->FindNick(parameters[0]);
31                 if (find)
32                 {
33                         ih.first = "*";
34                         ih.second = find->GetIPString();
35                 }
36                 else
37                         ih = ServerInstance->XLines->IdentSplit(parameters[0]);
38
39                 if (ServerInstance->HostMatchesEveryone(ih.first+"@"+ih.second,user))
40                         return CMD_FAILURE;
41
42                 if (!strchr(parameters[0],'@'))
43                 {       
44                         user->WriteServ("NOTICE %s :*** K-Line must contain a username, e.g. *@%s",user->nick,parameters[0]);
45                         return CMD_FAILURE;
46                 }
47                 else if (strchr(parameters[0],'!'))
48                 {
49                         user->WriteServ("NOTICE %s :*** K-Line cannot contain a nickname!",user->nick);
50                         return CMD_FAILURE;
51                 }
52
53                 long duration = ServerInstance->Duration(parameters[1]);
54                 KLine* kl = new KLine(ServerInstance, ServerInstance->Time(), duration, user->nick, parameters[2], ih.first.c_str(), ih.second.c_str());
55                 if (ServerInstance->XLines->AddLine(kl,user))
56                 {
57                         if (!duration)
58                         {
59                                 ServerInstance->SNO->WriteToSnoMask('x',"%s added permanent K-line for %s.",user->nick,parameters[0]);
60                         }
61                         else
62                         {
63                                 time_t c_requires_crap = duration + ServerInstance->Time();
64                                 ServerInstance->SNO->WriteToSnoMask('x',"%s added timed K-line for %s, expires on %s",user->nick,parameters[0],
65                                                 ServerInstance->TimeString(c_requires_crap).c_str());
66                         }
67
68                         ServerInstance->XLines->ApplyLines();
69                 }
70                 else
71                 {
72                         delete kl;
73                         user->WriteServ("NOTICE %s :*** K-Line for %s already exists",user->nick,parameters[0]);
74                 }
75         }
76         else
77         {
78                 if (ServerInstance->XLines->DelLine(parameters[0],"K",user))
79                 {
80                         ServerInstance->SNO->WriteToSnoMask('x',"%s Removed K-line on %s.",user->nick,parameters[0]);
81                 }
82                 else
83                 {
84                         user->WriteServ("NOTICE %s :*** K-Line %s not found in list, try /stats k.",user->nick,parameters[0]);
85                 }
86         }
87
88         return CMD_SUCCESS;
89 }
90