]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/coremods/core_user/core_user.cpp
Improve the descriptions of various core modules.
[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(LocalUser* user, const Params& parameters) CXX11_OVERRIDE
44         {
45                 // Check to make sure they haven't registered -- Fix by FCS
46                 if (user->registered == REG_ALL)
47                 {
48                         user->CommandFloodPenalty += 1000;
49                         user->WriteNumeric(ERR_ALREADYREGISTERED, "You may not reregister");
50                         return CMD_FAILURE;
51                 }
52                 user->password = parameters[0];
53
54                 return CMD_SUCCESS;
55         }
56 };
57
58 /** Handle /PING.
59  */
60 class CommandPing : public SplitCommand
61 {
62  public:
63         /** Constructor for ping.
64          */
65         CommandPing(Module* parent)
66                 : SplitCommand(parent, "PING", 1, 2)
67         {
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 HandleLocal(LocalUser* user, const Params& parameters) CXX11_OVERRIDE
77         {
78                 ClientProtocol::Messages::Pong pong(parameters[0]);
79                 user->Send(ServerInstance->GetRFCEvents().pong, pong);
80                 return CMD_SUCCESS;
81         }
82 };
83
84 /** Handle /PONG.
85  */
86 class CommandPong : public Command
87 {
88  public:
89         /** Constructor for pong.
90          */
91         CommandPong(Module* parent)
92                 : Command(parent, "PONG", 0, 1)
93         {
94                 Penalty = 0;
95                 syntax = "<ping-text>";
96         }
97
98         /** Handle command.
99          * @param parameters The parameters to the command
100          * @param user The user issuing the command
101          * @return A value from CmdResult to indicate command success or failure.
102          */
103         CmdResult Handle(User* user, const Params& parameters) CXX11_OVERRIDE
104         {
105                 // set the user as alive so they survive to next ping
106                 LocalUser* localuser = IS_LOCAL(user);
107                 if (localuser)
108                 {
109                         // Increase penalty unless we've sent a PING and this is the reply
110                         if (localuser->lastping)
111                                 localuser->CommandFloodPenalty += 1000;
112                         else
113                                 localuser->lastping = 1;
114                 }
115                 return CMD_SUCCESS;
116         }
117 };
118
119 void MessageWrapper::Wrap(const std::string& message, std::string& out)
120 {
121         // If there is a fixed message, it is stored in prefix. Otherwise prefix contains
122         // only the prefix, so append the message and the suffix
123         out.assign(prefix);
124         if (!fixed)
125                 out.append(message).append(suffix);
126 }
127
128 void MessageWrapper::ReadConfig(const char* prefixname, const char* suffixname, const char* fixedname)
129 {
130         ConfigTag* tag = ServerInstance->Config->ConfValue("options");
131         prefix = tag->getString(fixedname);
132         fixed = (!prefix.empty());
133         if (!fixed)
134         {
135                 prefix = tag->getString(prefixname);
136                 suffix = tag->getString(suffixname);
137         }
138 }
139
140 class CoreModUser : public Module
141 {
142         CommandAway cmdaway;
143         CommandNick cmdnick;
144         CommandPart cmdpart;
145         CommandPass cmdpass;
146         CommandPing cmdping;
147         CommandPong cmdpong;
148         CommandQuit cmdquit;
149         CommandUser cmduser;
150         CommandIson cmdison;
151         CommandUserhost cmduserhost;
152         SimpleUserModeHandler invisiblemode;
153         ModeUserOperator operatormode;
154         ModeUserServerNoticeMask snomaskmode;
155
156  public:
157         CoreModUser()
158                 : cmdaway(this)
159                 , cmdnick(this)
160                 , cmdpart(this)
161                 , cmdpass(this)
162                 , cmdping(this)
163                 , cmdpong(this)
164                 , cmdquit(this)
165                 , cmduser(this)
166                 , cmdison(this)
167                 , cmduserhost(this)
168                 , invisiblemode(this, "invisible", 'i')
169                 , operatormode(this)
170                 , snomaskmode(this)
171         {
172         }
173
174         void ReadConfig(ConfigStatus& status) CXX11_OVERRIDE
175         {
176                 cmdpart.msgwrap.ReadConfig("prefixpart", "suffixpart", "fixedpart");
177                 cmdquit.msgwrap.ReadConfig("prefixquit", "suffixquit", "fixedquit");
178         }
179
180         Version GetVersion() CXX11_OVERRIDE
181         {
182                 return Version("Provides the AWAY, ISON, NICK, PART, PASS, PING, PONG, QUIT, USERHOST, and USER commands", VF_VENDOR|VF_CORE);
183         }
184 };
185
186 MODULE_INIT(CoreModUser)