]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/coremods/core_xline/cmd_gline.cpp
Move src/commands/cmd_*.cpp to src/coremods[/core_*]/
[user/henk/code/inspircd.git] / src / coremods / core_xline / cmd_gline.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 /GLINE.
25  */
26 class CommandGline : public Command
27 {
28  public:
29         /** Constructor for gline.
30          */
31         CommandGline (Module* parent) : Command(parent,"GLINE",1,3) { flags_needed = 'o'; Penalty = 0; syntax = "<ident@host> [<duration> :<reason>]"; }
32         /** Handle command.
33          * @param parameters The parameters to the command
34          * @param user The user issuing the command
35          * @return A value from CmdResult to indicate command success or failure.
36          */
37         CmdResult Handle(const std::vector<std::string>& parameters, User *user);
38 };
39
40
41 /** Handle /GLINE
42  */
43 CmdResult CommandGline::Handle (const std::vector<std::string>& parameters, User *user)
44 {
45         std::string target = parameters[0];
46
47         if (parameters.size() >= 3)
48         {
49                 IdentHostPair ih;
50                 User* find = ServerInstance->FindNick(target);
51                 if ((find) && (find->registered == REG_ALL))
52                 {
53                         ih.first = "*";
54                         ih.second = find->GetIPString();
55                         target = std::string("*@") + find->GetIPString();
56                 }
57                 else
58                         ih = ServerInstance->XLines->IdentSplit(target);
59
60                 if (ih.first.empty())
61                 {
62                         user->WriteNotice("*** Target not found");
63                         return CMD_FAILURE;
64                 }
65
66                 if (ServerInstance->HostMatchesEveryone(ih.first+"@"+ih.second,user))
67                         return CMD_FAILURE;
68
69                 else if (target.find('!') != std::string::npos)
70                 {
71                         user->WriteNotice("*** G-Line cannot operate on nick!user@host masks");
72                         return CMD_FAILURE;
73                 }
74
75                 unsigned long duration = InspIRCd::Duration(parameters[1]);
76                 GLine* gl = new GLine(ServerInstance->Time(), duration, user->nick.c_str(), parameters[2].c_str(), ih.first.c_str(), ih.second.c_str());
77                 if (ServerInstance->XLines->AddLine(gl, user))
78                 {
79                         if (!duration)
80                         {
81                                 ServerInstance->SNO->WriteToSnoMask('x',"%s added permanent G-line for %s: %s",user->nick.c_str(),target.c_str(), parameters[2].c_str());
82                         }
83                         else
84                         {
85                                 time_t c_requires_crap = duration + ServerInstance->Time();
86                                 std::string timestr = InspIRCd::TimeString(c_requires_crap);
87                                 ServerInstance->SNO->WriteToSnoMask('x',"%s added timed G-line for %s, expires on %s: %s",user->nick.c_str(),target.c_str(),
88                                                 timestr.c_str(), parameters[2].c_str());
89                         }
90
91                         ServerInstance->XLines->ApplyLines();
92                 }
93                 else
94                 {
95                         delete gl;
96                         user->WriteNotice("** G-Line for " + target + " already exists");
97                 }
98
99         }
100         else
101         {
102                 if (ServerInstance->XLines->DelLine(target.c_str(),"G",user))
103                 {
104                         ServerInstance->SNO->WriteToSnoMask('x',"%s removed G-line on %s",user->nick.c_str(),target.c_str());
105                 }
106                 else
107                 {
108                         user->WriteNotice("*** G-Line " + target + " not found in list, try /stats g.");
109                 }
110         }
111
112         return CMD_SUCCESS;
113 }
114
115 COMMAND_INIT(CommandGline)