]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/coremods/core_user/core_user.cpp
c862c0eb1a3b711f3355c86cb52b7c746de3c253
[user/henk/code/inspircd.git] / src / coremods / core_user / core_user.cpp
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  *   Copyright (C) 2014 Attila Molnar <attilamolnar@hush.com>
5  *
6  * This file is part of InspIRCd.  InspIRCd is free software: you can
7  * redistribute it and/or modify it under the terms of the GNU General Public
8  * License as published by the Free Software Foundation, version 2.
9  *
10  * This program is distributed in the hope that it will be useful, but WITHOUT
11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
13  * details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
17  */
18
19
20 #include "inspircd.h"
21 #include "core_user.h"
22
23 class CommandMode : public Command
24 {
25  public:
26         /** Constructor for mode.
27          */
28         CommandMode(Module* parent)
29                 : Command(parent, "MODE", 1)
30         {
31                 syntax = "<target> <modes> {<mode-parameters>}";
32         }
33
34         /** Handle command.
35          * @param parameters The parameters to the command
36          * @param user The user issuing the command
37          * @return A value from CmdResult to indicate command success or failure.
38          */
39         CmdResult Handle(const std::vector<std::string>& parameters, User* user)
40         {
41                 ServerInstance->Modes->Process(parameters, user, (IS_LOCAL(user) ? ModeParser::MODE_NONE : ModeParser::MODE_LOCALONLY));
42                 return CMD_SUCCESS;
43         }
44
45         RouteDescriptor GetRouting(User* user, const std::vector<std::string>& parameters)
46         {
47                 return (IS_LOCAL(user) ? ROUTE_LOCALONLY : ROUTE_BROADCAST);
48         }
49 };
50
51 /** Handle /PASS.
52  */
53 class CommandPass : public SplitCommand
54 {
55  public:
56         /** Constructor for pass.
57          */
58         CommandPass(Module* parent)
59                 : SplitCommand(parent, "PASS", 1, 1)
60         {
61                 works_before_reg = true;
62                 Penalty = 0;
63                 syntax = "<password>";
64         }
65
66         /** Handle command.
67          * @param parameters The parameters to the command
68          * @param user The user issuing the command
69          * @return A value from CmdResult to indicate command success or failure.
70          */
71         CmdResult HandleLocal(const std::vector<std::string>& parameters, LocalUser *user)
72         {
73                 // Check to make sure they haven't registered -- Fix by FCS
74                 if (user->registered == REG_ALL)
75                 {
76                         user->WriteNumeric(ERR_ALREADYREGISTERED, ":You may not reregister");
77                         return CMD_FAILURE;
78                 }
79                 user->password = parameters[0];
80
81                 return CMD_SUCCESS;
82         }
83 };
84
85 /** Handle /PING.
86  */
87 class CommandPing : public Command
88 {
89  public:
90         /** Constructor for ping.
91          */
92         CommandPing(Module* parent)
93                 : Command(parent, "PING", 1, 2)
94         {
95                 Penalty = 0;
96                 syntax = "<servername> [:<servername>]";
97         }
98
99         /** Handle command.
100          * @param parameters The parameters to the command
101          * @param user The user issuing the command
102          * @return A value from CmdResult to indicate command success or failure.
103          */
104         CmdResult Handle(const std::vector<std::string>& parameters, User* user)
105         {
106                 user->WriteServ("PONG %s :%s", ServerInstance->Config->ServerName.c_str(), parameters[0].c_str());
107                 return CMD_SUCCESS;
108         }
109 };
110
111 /** Handle /PONG.
112  */
113 class CommandPong : public Command
114 {
115  public:
116         /** Constructor for pong.
117          */
118         CommandPong(Module* parent)
119                 : Command(parent, "PONG", 0, 1)
120         {
121                 Penalty = 0;
122                 syntax = "<ping-text>";
123         }
124
125         /** Handle command.
126          * @param parameters The parameters to the command
127          * @param user The user issuing the command
128          * @return A value from CmdResult to indicate command success or failure.
129          */
130         CmdResult Handle(const std::vector<std::string>& parameters, User* user)
131         {
132                 // set the user as alive so they survive to next ping
133                 if (IS_LOCAL(user))
134                         IS_LOCAL(user)->lastping = 1;
135                 return CMD_SUCCESS;
136         }
137 };
138
139 class CoreModUser : public Module
140 {
141         CommandAway cmdaway;
142         CommandMode cmdmode;
143         CommandNick cmdnick;
144         CommandPart cmdpart;
145         CommandPass cmdpass;
146         CommandPing cmdping;
147         CommandPong cmdpong;
148         CommandQuit cmdquit;
149         CommandUser cmduser;
150
151  public:
152         CoreModUser()
153                 : cmdaway(this), cmdmode(this), cmdnick(this), cmdpart(this), cmdpass(this), cmdping(this)
154                 , cmdpong(this), cmdquit(this), cmduser(this)
155         {
156         }
157
158         Version GetVersion() CXX11_OVERRIDE
159         {
160                 return Version("Provides the AWAY, MODE, NICK, PART, PASS, PING, PONG, QUIT and USER commands", VF_VENDOR|VF_CORE);
161         }
162 };
163
164 MODULE_INIT(CoreModUser)