]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/commands/cmd_gline.cpp
Remove InspIRCd* parameters and fields
[user/henk/code/inspircd.git] / src / commands / cmd_gline.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2009 InspIRCd Development Team
6  * See: http://wiki.inspircd.org/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
17 /** Handle /GLINE. These command handlers can be reloaded by the core,
18  * and handle basic RFC1459 commands. Commands within modules work
19  * the same way, however, they can be fully unloaded, where these
20  * may not.
21  */
22 class CommandGline : public Command
23 {
24  public:
25         /** Constructor for gline.
26          */
27         CommandGline (Module* parent) : Command(parent,"GLINE",1,3) { flags_needed = 'o'; Penalty = 0; syntax = "<ident@host> [<duration> :<reason>]"; }
28         /** Handle command.
29          * @param parameters The parameters to the comamnd
30          * @param pcnt The number of parameters passed to teh command
31          * @param user The user issuing the command
32          * @return A value from CmdResult to indicate command success or failure.
33          */
34         CmdResult Handle(const std::vector<std::string>& parameters, User *user);
35 };
36
37
38 /** Handle /GLINE
39  */
40 CmdResult CommandGline::Handle (const std::vector<std::string>& parameters, User *user)
41 {
42         std::string target = parameters[0];
43
44         if (parameters.size() >= 3)
45         {
46                 IdentHostPair ih;
47                 User* find = ServerInstance->FindNick(target.c_str());
48                 if (find)
49                 {
50                         ih.first = "*";
51                         ih.second = find->GetIPString();
52                         target = std::string("*@") + find->GetIPString();
53                 }
54                 else
55                         ih = ServerInstance->XLines->IdentSplit(target.c_str());
56
57                 if (ih.first.empty())
58                 {
59                         user->WriteServ("NOTICE %s :*** Target not found", user->nick.c_str());
60                         return CMD_FAILURE;
61                 }
62
63                 if (ServerInstance->HostMatchesEveryone(ih.first+"@"+ih.second,user))
64                         return CMD_FAILURE;
65
66                 else if (target.find('!') != std::string::npos)
67                 {
68                         user->WriteServ("NOTICE %s :*** G-Line cannot operate on nick!user@host masks",user->nick.c_str());
69                         return CMD_FAILURE;
70                 }
71
72                 long duration = ServerInstance->Duration(parameters[1].c_str());
73                 GLine* gl = new GLine(ServerInstance->Time(), duration, user->nick.c_str(), parameters[2].c_str(), ih.first.c_str(), ih.second.c_str());
74                 if (ServerInstance->XLines->AddLine(gl, user))
75                 {
76                         if (!duration)
77                         {
78                                 ServerInstance->SNO->WriteToSnoMask('x',"%s added permanent G-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                                 ServerInstance->SNO->WriteToSnoMask('x',"%s added timed G-line for %s, expires on %s: %s",user->nick.c_str(),target.c_str(),
84                                                 ServerInstance->TimeString(c_requires_crap).c_str(), parameters[2].c_str());
85                         }
86
87                         ServerInstance->XLines->ApplyLines();
88                 }
89                 else
90                 {
91                         delete gl;
92                         user->WriteServ("NOTICE %s :*** G-Line for %s already exists",user->nick.c_str(),target.c_str());
93                 }
94
95         }
96         else
97         {
98                 if (ServerInstance->XLines->DelLine(target.c_str(),"G",user))
99                 {
100                         ServerInstance->SNO->WriteToSnoMask('x',"%s removed G-line on %s",user->nick.c_str(),target.c_str());
101                 }
102                 else
103                 {
104                         user->WriteServ("NOTICE %s :*** G-line %s not found in list, try /stats g.",user->nick.c_str(),target.c_str());
105                 }
106         }
107
108         return CMD_SUCCESS;
109 }
110
111 COMMAND_INIT(CommandGline)