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