]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/coremods/core_user/core_user.cpp
Change glob matching to be configurable
[user/henk/code/inspircd.git] / src / coremods / core_user / core_user.cpp
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  *   Copyright (C) 2017-2019 Sadie Powell <sadie@witchery.services>
5  *   Copyright (C) 2014-2016, 2018 Attila Molnar <attilamolnar@hush.com>
6  *
7  * This file is part of InspIRCd.  InspIRCd is free software: you can
8  * redistribute it and/or modify it under the terms of the GNU General Public
9  * License as published by the Free Software Foundation, version 2.
10  *
11  * This program is distributed in the hope that it will be useful, but WITHOUT
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
14  * details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18  */
19
20
21 #include "inspircd.h"
22 #include "core_user.h"
23
24 /** Handle /PASS.
25  */
26 class CommandPass : public SplitCommand
27 {
28  public:
29         /** Constructor for pass.
30          */
31         CommandPass(Module* parent)
32                 : SplitCommand(parent, "PASS", 1, 1)
33         {
34                 works_before_reg = true;
35                 Penalty = 0;
36                 syntax = "<password>";
37         }
38
39         /** Handle command.
40          * @param parameters The parameters to the command
41          * @param user The user issuing the command
42          * @return A value from CmdResult to indicate command success or failure.
43          */
44         CmdResult HandleLocal(LocalUser* user, const Params& parameters) CXX11_OVERRIDE
45         {
46                 // Check to make sure they haven't registered -- Fix by FCS
47                 if (user->registered == REG_ALL)
48                 {
49                         user->CommandFloodPenalty += 1000;
50                         user->WriteNumeric(ERR_ALREADYREGISTERED, "You may not reregister");
51                         return CMD_FAILURE;
52                 }
53                 user->password = parameters[0];
54
55                 return CMD_SUCCESS;
56         }
57 };
58
59 /** Handle /PING.
60  */
61 class CommandPing : public SplitCommand
62 {
63  public:
64         /** Constructor for ping.
65          */
66         CommandPing(Module* parent)
67                 : SplitCommand(parent, "PING", 1, 2)
68         {
69                 syntax = "<servername> [:<servername>]";
70         }
71
72         /** Handle command.
73          * @param parameters The parameters to the command
74          * @param user The user issuing the command
75          * @return A value from CmdResult to indicate command success or failure.
76          */
77         CmdResult HandleLocal(LocalUser* user, const Params& parameters) CXX11_OVERRIDE
78         {
79                 ClientProtocol::Messages::Pong pong(parameters[0]);
80                 user->Send(ServerInstance->GetRFCEvents().pong, pong);
81                 return CMD_SUCCESS;
82         }
83 };
84
85 /** Handle /PONG.
86  */
87 class CommandPong : public Command
88 {
89  public:
90         /** Constructor for pong.
91          */
92         CommandPong(Module* parent)
93                 : Command(parent, "PONG", 0, 1)
94         {
95                 Penalty = 0;
96                 syntax = "<ping-text>";
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(User* user, const Params& parameters) CXX11_OVERRIDE
105         {
106                 // set the user as alive so they survive to next ping
107                 LocalUser* localuser = IS_LOCAL(user);
108                 if (localuser)
109                 {
110                         // Increase penalty unless we've sent a PING and this is the reply
111                         if (localuser->lastping)
112                                 localuser->CommandFloodPenalty += 1000;
113                         else
114                                 localuser->lastping = 1;
115                 }
116                 return CMD_SUCCESS;
117         }
118 };
119
120 void MessageWrapper::Wrap(const std::string& message, std::string& out)
121 {
122         // If there is a fixed message, it is stored in prefix. Otherwise prefix contains
123         // only the prefix, so append the message and the suffix
124         out.assign(prefix);
125         if (!fixed)
126                 out.append(message).append(suffix);
127 }
128
129 void MessageWrapper::ReadConfig(const char* prefixname, const char* suffixname, const char* fixedname)
130 {
131         ConfigTag* tag = ServerInstance->Config->ConfValue("options");
132         prefix = tag->getString(fixedname);
133         fixed = (!prefix.empty());
134         if (!fixed)
135         {
136                 prefix = tag->getString(prefixname);
137                 suffix = tag->getString(suffixname);
138         }
139 }
140
141 class CoreModUser : public Module
142 {
143         CommandAway cmdaway;
144         CommandNick cmdnick;
145         CommandPart cmdpart;
146         CommandPass cmdpass;
147         CommandPing cmdping;
148         CommandPong cmdpong;
149         CommandQuit cmdquit;
150         CommandUser cmduser;
151         CommandIson cmdison;
152         CommandUserhost cmduserhost;
153         SimpleUserModeHandler invisiblemode;
154         ModeUserOperator operatormode;
155         ModeUserServerNoticeMask snomaskmode;
156
157  public:
158         CoreModUser()
159                 : cmdaway(this)
160                 , cmdnick(this)
161                 , cmdpart(this)
162                 , cmdpass(this)
163                 , cmdping(this)
164                 , cmdpong(this)
165                 , cmdquit(this)
166                 , cmduser(this)
167                 , cmdison(this)
168                 , cmduserhost(this)
169                 , invisiblemode(this, "invisible", 'i')
170                 , operatormode(this)
171                 , snomaskmode(this)
172         {
173         }
174
175         void ReadConfig(ConfigStatus& status) CXX11_OVERRIDE
176         {
177                 cmdpart.msgwrap.ReadConfig("prefixpart", "suffixpart", "fixedpart");
178                 cmdquit.msgwrap.ReadConfig("prefixquit", "suffixquit", "fixedquit");
179         }
180
181         Version GetVersion() CXX11_OVERRIDE
182         {
183                 return Version("Provides the AWAY, ISON, NICK, PART, PASS, PING, PONG, QUIT, USERHOST, and USER commands", VF_VENDOR|VF_CORE);
184         }
185 };
186
187 MODULE_INIT(CoreModUser)