]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/coremods/core_user/core_user.cpp
core_user Expand the MODE handler into its own file
[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 /** Handle /PASS.
24  */
25 class CommandPass : public SplitCommand
26 {
27  public:
28         /** Constructor for pass.
29          */
30         CommandPass(Module* parent)
31                 : SplitCommand(parent, "PASS", 1, 1)
32         {
33                 works_before_reg = true;
34                 Penalty = 0;
35                 syntax = "<password>";
36         }
37
38         /** Handle command.
39          * @param parameters The parameters to the command
40          * @param user The user issuing the command
41          * @return A value from CmdResult to indicate command success or failure.
42          */
43         CmdResult HandleLocal(const std::vector<std::string>& parameters, LocalUser *user)
44         {
45                 // Check to make sure they haven't registered -- Fix by FCS
46                 if (user->registered == REG_ALL)
47                 {
48                         user->WriteNumeric(ERR_ALREADYREGISTERED, ":You may not reregister");
49                         return CMD_FAILURE;
50                 }
51                 user->password = parameters[0];
52
53                 return CMD_SUCCESS;
54         }
55 };
56
57 /** Handle /PING.
58  */
59 class CommandPing : public Command
60 {
61  public:
62         /** Constructor for ping.
63          */
64         CommandPing(Module* parent)
65                 : Command(parent, "PING", 1, 2)
66         {
67                 Penalty = 0;
68                 syntax = "<servername> [:<servername>]";
69         }
70
71         /** Handle command.
72          * @param parameters The parameters to the command
73          * @param user The user issuing the command
74          * @return A value from CmdResult to indicate command success or failure.
75          */
76         CmdResult Handle(const std::vector<std::string>& parameters, User* user)
77         {
78                 user->WriteServ("PONG %s :%s", ServerInstance->Config->ServerName.c_str(), parameters[0].c_str());
79                 return CMD_SUCCESS;
80         }
81 };
82
83 /** Handle /PONG.
84  */
85 class CommandPong : public Command
86 {
87  public:
88         /** Constructor for pong.
89          */
90         CommandPong(Module* parent)
91                 : Command(parent, "PONG", 0, 1)
92         {
93                 Penalty = 0;
94                 syntax = "<ping-text>";
95         }
96
97         /** Handle command.
98          * @param parameters The parameters to the command
99          * @param user The user issuing the command
100          * @return A value from CmdResult to indicate command success or failure.
101          */
102         CmdResult Handle(const std::vector<std::string>& parameters, User* user)
103         {
104                 // set the user as alive so they survive to next ping
105                 if (IS_LOCAL(user))
106                         IS_LOCAL(user)->lastping = 1;
107                 return CMD_SUCCESS;
108         }
109 };
110
111 void MessageWrapper::Wrap(const std::string& message, std::string& out)
112 {
113         // If there is a fixed message, it is stored in prefix. Otherwise prefix contains
114         // only the prefix, so append the message and the suffix
115         out.assign(prefix);
116         if (!fixed)
117                 out.append(message).append(suffix);
118 }
119
120 void MessageWrapper::ReadConfig(const char* prefixname, const char* suffixname, const char* fixedname)
121 {
122         ConfigTag* tag = ServerInstance->Config->ConfValue("options");
123         prefix = tag->getString(fixedname);
124         fixed = (!prefix.empty());
125         if (!fixed)
126         {
127                 prefix = tag->getString(prefixname);
128                 suffix = tag->getString(suffixname);
129         }
130 }
131
132 class CoreModUser : public Module
133 {
134         CommandAway cmdaway;
135         CommandMode cmdmode;
136         CommandNick cmdnick;
137         CommandPart cmdpart;
138         CommandPass cmdpass;
139         CommandPing cmdping;
140         CommandPong cmdpong;
141         CommandQuit cmdquit;
142         CommandUser cmduser;
143
144  public:
145         CoreModUser()
146                 : cmdaway(this), cmdmode(this), cmdnick(this), cmdpart(this), cmdpass(this), cmdping(this)
147                 , cmdpong(this), cmdquit(this), cmduser(this)
148         {
149         }
150
151         void ReadConfig(ConfigStatus& status) CXX11_OVERRIDE
152         {
153                 cmdpart.msgwrap.ReadConfig("prefixpart", "suffixpart", "fixedpart");
154                 cmdquit.msgwrap.ReadConfig("prefixquit", "suffixquit", "fixedquit");
155         }
156
157         Version GetVersion() CXX11_OVERRIDE
158         {
159                 return Version("Provides the AWAY, MODE, NICK, PART, PASS, PING, PONG, QUIT and USER commands", VF_VENDOR|VF_CORE);
160         }
161 };
162
163 MODULE_INIT(CoreModUser)