]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/commands/cmd_eline.cpp
Replace hardcoded mode letters, part 3
[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 /** Handle /ELINE. These command handlers can be reloaded by the core,
25  * and handle basic RFC1459 commands. Commands within modules work
26  * the same way, however, they can be fully unloaded, where these
27  * may not.
28  */
29 class CommandEline : public Command
30 {
31  public:
32         /** Constructor for eline.
33          */
34         CommandEline ( Module* parent) : Command(parent,"ELINE",1,3) { flags_needed = 'o'; syntax = "<ident@host> [<duration> :<reason>]"; }
35         /** Handle command.
36          * @param parameters The parameters to the comamnd
37          * @param pcnt The number of parameters passed to teh command
38          * @param user The user issuing the command
39          * @return A value from CmdResult to indicate command success or failure.
40          */
41         CmdResult Handle(const std::vector<std::string>& parameters, User *user);
42 };
43
44 /** Handle /ELINE
45  */
46 CmdResult CommandEline::Handle (const std::vector<std::string>& parameters, User *user)
47 {
48         std::string target = parameters[0];
49
50         if (parameters.size() >= 3)
51         {
52                 IdentHostPair ih;
53                 User* find = ServerInstance->FindNick(target);
54                 if ((find) && (find->registered == REG_ALL))
55                 {
56                         ih.first = "*";
57                         ih.second = find->GetIPString();
58                         target = std::string("*@") + find->GetIPString();
59                 }
60                 else
61                         ih = ServerInstance->XLines->IdentSplit(target);
62
63                 if (ih.first.empty())
64                 {
65                         user->WriteNotice("*** Target not found");
66                         return CMD_FAILURE;
67                 }
68
69                 if (ServerInstance->HostMatchesEveryone(ih.first+"@"+ih.second,user))
70                         return CMD_FAILURE;
71
72                 unsigned long duration = InspIRCd::Duration(parameters[1]);
73                 ELine* el = new ELine(ServerInstance->Time(), duration, user->nick.c_str(), parameters[2].c_str(), ih.first.c_str(), ih.second.c_str());
74                 if (ServerInstance->XLines->AddLine(el, user))
75                 {
76                         if (!duration)
77                         {
78                                 ServerInstance->SNO->WriteToSnoMask('x',"%s added permanent E-line for %s: %s", user->nick.c_str(), target.c_str(), parameters[2].c_str());
79                         }
80                         else
81                         {
82                                 time_t c_requires_crap = duration + ServerInstance->Time();
83                                 std::string timestr = ServerInstance->TimeString(c_requires_crap);
84                                 ServerInstance->SNO->WriteToSnoMask('x',"%s added timed E-line for %s, expires on %s: %s",user->nick.c_str(),target.c_str(),
85                                                 timestr.c_str(), parameters[2].c_str());
86                         }
87                 }
88                 else
89                 {
90                         delete el;
91                         user->WriteNotice("*** E-Line for " + target + " already exists");
92                 }
93         }
94         else
95         {
96                 if (ServerInstance->XLines->DelLine(target.c_str(), "E", user))
97                 {
98                         ServerInstance->SNO->WriteToSnoMask('x',"%s removed E-line on %s",user->nick.c_str(),target.c_str());
99                 }
100                 else
101                 {
102                         user->WriteNotice("*** E-Line " + target + " not found in list, try /stats e");
103                 }
104         }
105
106         return CMD_SUCCESS;
107 }
108
109 COMMAND_INIT(CommandEline)