]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/commands/cmd_kline.cpp
Conversion of command handler params from "const char* const* parameters, int pcnt...
[user/henk/code/inspircd.git] / src / commands / cmd_kline.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_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 std::vector<std::string>& parameters, User *user)
26 {
27     std::string target = parameters[0];
28
29         if (parameters.size() >= 3)
30         {
31                 IdentHostPair ih;
32                 User* find = ServerInstance->FindNick(target.c_str());
33                 if (find)
34                 {
35                         ih.first = "*";
36                         ih.second = find->GetIPString();
37                         target = std::string("*@") + find->GetIPString();
38                 }
39                 else
40                         ih = ServerInstance->XLines->IdentSplit(target.c_str());
41                         
42         if (ih.first.empty())
43         {
44             user->WriteServ("NOTICE %s :*** Target not found", user->nick);
45             return CMD_FAILURE;
46         }
47
48                 if (ServerInstance->HostMatchesEveryone(ih.first+"@"+ih.second,user))
49                         return CMD_FAILURE;
50
51                 if (target.find('!') != std::string::npos)
52                 {
53                         user->WriteServ("NOTICE %s :*** K-Line cannot operate on nick!user@host masks",user->nick);
54                         return CMD_FAILURE;
55                 }
56
57                 long duration = ServerInstance->Duration(parameters[1].c_str());
58                 KLine* kl = new KLine(ServerInstance, ServerInstance->Time(), duration, user->nick, parameters[2].c_str(), ih.first.c_str(), ih.second.c_str());
59                 if (ServerInstance->XLines->AddLine(kl,user))
60                 {
61                         if (!duration)
62                         {
63                                 ServerInstance->SNO->WriteToSnoMask('x',"%s added permanent K-line for %s.",user->nick,target.c_str());
64                         }
65                         else
66                         {
67                                 time_t c_requires_crap = duration + ServerInstance->Time();
68                                 ServerInstance->SNO->WriteToSnoMask('x',"%s added timed K-line for %s, expires on %s",user->nick,target.c_str(),
69                                                 ServerInstance->TimeString(c_requires_crap).c_str());
70                         }
71
72                         ServerInstance->XLines->ApplyLines();
73                 }
74                 else
75                 {
76                         delete kl;
77                         user->WriteServ("NOTICE %s :*** K-Line for %s already exists",user->nick,target.c_str());
78                 }
79         }
80         else
81         {
82                 if (ServerInstance->XLines->DelLine(target.c_str(),"K",user))
83                 {
84                         ServerInstance->SNO->WriteToSnoMask('x',"%s Removed K-line on %s.",user->nick,target.c_str());
85                 }
86                 else
87                 {
88                         user->WriteServ("NOTICE %s :*** K-Line %s not found in list, try /stats k.",user->nick,target.c_str());
89                 }
90         }
91
92         return CMD_SUCCESS;
93 }
94