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