]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/commands/cmd_eline.cpp
Merge pull request #92 from Robby-/insp20-headers
[user/henk/code/inspircd.git] / src / commands / cmd_eline.cpp
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  *   Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org>
5  *   Copyright (C) 2007-2008 Robin Burchell <robin+git@viroteck.net>
6  *
7  * This file is part of InspIRCd.  InspIRCd is free software: you can
8  * redistribute it and/or modify it under the terms of the GNU General Public
9  * License as published by the Free Software Foundation, version 2.
10  *
11  * This program is distributed in the hope that it will be useful, but WITHOUT
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
14  * details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18  */
19
20
21 #include "inspircd.h"
22 #include "xline.h"
23
24 #ifndef CMD_ELINE_H
25 #define CMD_ELINE_H
26
27 // include the common header files
28
29 #include "users.h"
30 #include "channels.h"
31
32 /** Handle /ELINE. These command handlers can be reloaded by the core,
33  * and handle basic RFC1459 commands. Commands within modules work
34  * the same way, however, they can be fully unloaded, where these
35  * may not.
36  */
37 class CommandEline : public Command
38 {
39  public:
40         /** Constructor for eline.
41          */
42         CommandEline ( Module* parent) : Command(parent,"ELINE",1,3) { flags_needed = 'o'; syntax = "<ident@host> [<duration> :<reason>]"; }
43         /** Handle command.
44          * @param parameters The parameters to the comamnd
45          * @param pcnt The number of parameters passed to teh command
46          * @param user The user issuing the command
47          * @return A value from CmdResult to indicate command success or failure.
48          */
49         CmdResult Handle(const std::vector<std::string>& parameters, User *user);
50 };
51
52 #endif
53
54
55 /** Handle /ELINE
56  */
57 CmdResult CommandEline::Handle (const std::vector<std::string>& parameters, User *user)
58 {
59         std::string target = parameters[0];
60
61         if (parameters.size() >= 3)
62         {
63                 IdentHostPair ih;
64                 User* find = ServerInstance->FindNick(target.c_str());
65                 if (find)
66                 {
67                         ih.first = "*";
68                         ih.second = find->GetIPString();
69                         target = std::string("*@") + find->GetIPString();
70                 }
71                 else
72                         ih = ServerInstance->XLines->IdentSplit(target.c_str());
73
74         if (ih.first.empty())
75         {
76             user->WriteServ("NOTICE %s :*** Target not found", user->nick.c_str());
77             return CMD_FAILURE;
78         }
79
80                 if (ServerInstance->HostMatchesEveryone(ih.first+"@"+ih.second,user))
81                         return CMD_FAILURE;
82
83                 long duration = ServerInstance->Duration(parameters[1].c_str());
84
85                 ELine* el = new ELine(ServerInstance->Time(), duration, user->nick.c_str(), parameters[2].c_str(), ih.first.c_str(), ih.second.c_str());
86                 if (ServerInstance->XLines->AddLine(el, user))
87                 {
88                         if (!duration)
89                         {
90                                 ServerInstance->SNO->WriteToSnoMask('x',"%s added permanent E-line for %s: %s", user->nick.c_str(), target.c_str(), parameters[2].c_str());
91                         }
92                         else
93                         {
94                                 time_t c_requires_crap = duration + ServerInstance->Time();
95                                 ServerInstance->SNO->WriteToSnoMask('x',"%s added timed E-line for %s, expires on %s: %s",user->nick.c_str(),target.c_str(),
96                                                 ServerInstance->TimeString(c_requires_crap).c_str(), parameters[2].c_str());
97                         }
98                 }
99                 else
100                 {
101                         delete el;
102                         user->WriteServ("NOTICE %s :*** E-Line for %s already exists",user->nick.c_str(),target.c_str());
103                 }
104         }
105         else
106         {
107                 if (ServerInstance->XLines->DelLine(target.c_str(), "E", user))
108                 {
109                         ServerInstance->SNO->WriteToSnoMask('x',"%s removed E-line on %s",user->nick.c_str(),target.c_str());
110                 }
111                 else
112                 {
113                         user->WriteServ("NOTICE %s :*** E-Line %s not found in list, try /stats e.",user->nick.c_str(),target.c_str());
114                 }
115         }
116
117         return CMD_SUCCESS;
118 }
119
120 COMMAND_INIT(CommandEline)