]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/coremods/core_user/core_user.h
Update copyright headers.
[user/henk/code/inspircd.git] / src / coremods / core_user / core_user.h
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  *   Copyright (C) 2017-2020 Sadie Powell <sadie@witchery.services>
5  *   Copyright (C) 2014 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 #pragma once
22
23 #include "inspircd.h"
24 #include "listmode.h"
25 #include "modules/away.h"
26
27 enum
28 {
29         // From RFC 1459.
30         ERR_NOORIGIN = 409
31 };
32
33 class MessageWrapper
34 {
35         std::string prefix;
36         std::string suffix;
37         bool fixed;
38
39  public:
40         /**
41          * Wrap the given message according to the config rules
42          * @param message The message to wrap
43          * @param out String where the result is placed
44          */
45         void Wrap(const std::string& message, std::string& out);
46
47         /**
48          * Read the settings from the given config keys (options block)
49          * @param prefixname Name of the config key to read the prefix from
50          * @param suffixname Name of the config key to read the suffix from
51          * @param fixedname Name of the config key to read the fixed string string from.
52          * If this key has a non-empty value, all messages will be replaced with it.
53          */
54         void ReadConfig(const char* prefixname, const char* suffixname, const char* fixedname);
55 };
56
57 /** Handle /AWAY.
58  */
59 class CommandAway : public Command
60 {
61  private:
62         Away::EventProvider awayevprov;
63
64  public:
65         /** Constructor for away.
66          */
67         CommandAway(Module* parent);
68         /** Handle command.
69          * @param parameters The parameters to the command
70          * @param user The user issuing the command
71          * @return A value from CmdResult to indicate command success or failure.
72          */
73         CmdResult Handle(User* user, const Params& parameters) CXX11_OVERRIDE;
74         RouteDescriptor GetRouting(User* user, const Params& parameters) CXX11_OVERRIDE;
75 };
76
77 /** Handle /ISON.
78  */
79 class CommandIson : public SplitCommand
80 {
81  public:
82         /** Constructor for ison.
83          */
84         CommandIson(Module* parent)
85                 : SplitCommand(parent, "ISON", 1)
86         {
87                 allow_empty_last_param = false;
88                 syntax = "<nick> [<nick>]+";
89         }
90         /** Handle command.
91          * @param parameters The parameters to the command
92          * @param user The user issuing the command
93          * @return A value from CmdResult to indicate command success or failure.
94          */
95         CmdResult HandleLocal(LocalUser* user, const Params& parameters) CXX11_OVERRIDE;
96 };
97
98
99 /** Handle /NICK.
100  */
101 class CommandNick : public SplitCommand
102 {
103  public:
104         /** Constructor for nick.
105          */
106         CommandNick(Module* parent);
107
108         /** Handle command.
109          * @param parameters The parameters to the command
110          * @param user The user issuing the command
111          * @return A value from CmdResult to indicate command success or failure.
112          */
113         CmdResult HandleLocal(LocalUser* user, const Params& parameters) CXX11_OVERRIDE;
114 };
115
116 /** Handle /PART.
117  */
118 class CommandPart : public Command
119 {
120  public:
121         MessageWrapper msgwrap;
122
123         /** Constructor for part.
124          */
125         CommandPart(Module* parent);
126
127         /** Handle command.
128          * @param parameters The parameters to the command
129          * @param user The user issuing the command
130          * @return A value from CmdResult to indicate command success or failure.
131          */
132         CmdResult Handle(User* user, const Params& parameters) CXX11_OVERRIDE;
133         RouteDescriptor GetRouting(User* user, const Params& parameters) CXX11_OVERRIDE;
134 };
135
136 /** Handle /QUIT.
137  */
138 class CommandQuit : public Command
139 {
140  private:
141         StringExtItem operquit;
142
143  public:
144         MessageWrapper msgwrap;
145
146         /** Constructor for quit.
147          */
148         CommandQuit(Module* parent);
149
150         /** Handle command.
151          * @param parameters The parameters to the command
152          * @param user The user issuing the command
153          * @return A value from CmdResult to indicate command success or failure.
154          */
155         CmdResult Handle(User* user, const Params& parameters) CXX11_OVERRIDE;
156
157         RouteDescriptor GetRouting(User* user, const Params& parameters) CXX11_OVERRIDE;
158 };
159
160 /** Handle /USER.
161  */
162 class CommandUser : public SplitCommand
163 {
164  public:
165         /** Constructor for user.
166          */
167         CommandUser(Module* parent);
168
169         /** Handle command.
170          * @param parameters The parameters to the command
171          * @param user The user issuing the command
172          * @return A value from CmdResult to indicate command success or failure.
173          */
174         CmdResult HandleLocal(LocalUser* user, const Params& parameters) CXX11_OVERRIDE;
175
176         /** Run the OnUserRegister hook if the user has sent both NICK and USER. Called after an unregistered user
177          * successfully executes the USER or the NICK command.
178          * @param user User to inspect and possibly pass to the OnUserRegister hook
179          * @return CMD_FAILURE if OnUserRegister was called and it returned MOD_RES_DENY, CMD_SUCCESS in every other case
180          * (i.e. if the hook wasn't fired because the user still needs to send NICK/USER or if it was fired and finished with
181          * a non-MOD_RES_DENY result).
182          */
183         static CmdResult CheckRegister(LocalUser* user);
184 };
185
186 /** Handle /USERHOST.
187  */
188 class CommandUserhost : public Command
189 {
190         UserModeReference hideopermode;
191
192  public:
193         /** Constructor for userhost.
194          */
195         CommandUserhost(Module* parent)
196                 : Command(parent,"USERHOST", 1)
197                 , hideopermode(parent, "hideoper")
198         {
199                 allow_empty_last_param = false;
200                 syntax = "<nick> [<nick>]+";
201         }
202         /** Handle command.
203          * @param parameters The parameters to the command
204          * @param user The user issuing the command
205          * @return A value from CmdResult to indicate command success or failure.
206          */
207         CmdResult Handle(User* user, const Params& parameters) CXX11_OVERRIDE;
208 };
209
210 /** User mode +s
211  */
212 class ModeUserServerNoticeMask : public ModeHandler
213 {
214         /** Process a snomask modifier string, e.g. +abc-de
215          * @param user The target user
216          * @param input A sequence of notice mask characters
217          * @return The cleaned mode sequence which can be output,
218          * e.g. in the above example if masks c and e are not
219          * valid, this function will return +ab-d
220          */
221         std::string ProcessNoticeMasks(User* user, const std::string& input);
222
223  public:
224         ModeUserServerNoticeMask(Module* Creator);
225         ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string &parameter, bool adding) CXX11_OVERRIDE;
226
227         /** Create a displayable mode string of the snomasks set on a given user
228          * @param user The user whose notice masks to format
229          * @return The notice mask character sequence
230          */
231         std::string GetUserParameter(const User* user) const CXX11_OVERRIDE;
232 };
233
234 /** User mode +o
235  */
236 class ModeUserOperator : public ModeHandler
237 {
238  public:
239         ModeUserOperator(Module* Creator);
240         ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string &parameter, bool adding) CXX11_OVERRIDE;
241 };