]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/coremods/core_user/core_user.h
Extract RFC modes from the core to core_channel and core_user.
[user/henk/code/inspircd.git] / src / coremods / core_user / core_user.h
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  *   Copyright (C) 2014 Attila Molnar <attilamolnar@hush.com>
5  *   Copyright (C) 2008 Robin Burchell <robin+git@viroteck.net>
6  *   Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
7  *   Copyright (C) 2006 Craig Edwards <craigedwards@brainbox.cc>
8  *
9  * This file is part of InspIRCd.  InspIRCd is free software: you can
10  * redistribute it and/or modify it under the terms of the GNU General Public
11  * License as published by the Free Software Foundation, version 2.
12  *
13  * This program is distributed in the hope that it will be useful, but WITHOUT
14  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
20  */
21
22
23 #pragma once
24
25 #include "inspircd.h"
26 #include "listmode.h"
27
28 class MessageWrapper
29 {
30         std::string prefix;
31         std::string suffix;
32         bool fixed;
33
34  public:
35         /**
36          * Wrap the given message according to the config rules
37          * @param message The message to wrap
38          * @param out String where the result is placed
39          */
40         void Wrap(const std::string& message, std::string& out);
41
42         /**
43          * Read the settings from the given config keys (options block)
44          * @param prefixname Name of the config key to read the prefix from
45          * @param suffixname Name of the config key to read the suffix from
46          * @param fixedname Name of the config key to read the fixed string string from.
47          * If this key has a non-empty value, all messages will be replaced with it.
48          */
49         void ReadConfig(const char* prefixname, const char* suffixname, const char* fixedname);
50 };
51
52 /** Handle /AWAY.
53  */
54 class CommandAway : public Command
55 {
56  public:
57         /** Constructor for away.
58          */
59         CommandAway(Module* parent);
60         /** Handle command.
61          * @param parameters The parameters to the command
62          * @param user The user issuing the command
63          * @return A value from CmdResult to indicate command success or failure.
64          */
65         CmdResult Handle(const std::vector<std::string>& parameters, User* user) CXX11_OVERRIDE;
66         RouteDescriptor GetRouting(User* user, const std::vector<std::string>& parameters) CXX11_OVERRIDE;
67 };
68
69 class CommandMode : public Command
70 {
71         unsigned int sent[256];
72         unsigned int seq;
73
74         /** Show the list of one or more list modes to a user.
75          * @param user User to send to.
76          * @param chan Channel whose lists to show.
77          * @param mode_sequence Mode letters to show the lists of.
78          */
79         void DisplayListModes(User* user, Channel* chan, const std::string& mode_sequence);
80
81         /** Show the current modes of a channel or a user to a user.
82          * @param user User to show the modes to.
83          * @param targetuser User whose modes to show. NULL if showing the modes of a channel.
84          * @param targetchannel Channel whose modes to show. NULL if showing the modes of a user.
85          */
86         void DisplayCurrentModes(User* user, User* targetuser, Channel* targetchannel);
87
88  public:
89         /** Constructor for mode.
90          */
91         CommandMode(Module* parent);
92
93         /** Handle command.
94          * @param parameters The parameters to the command
95          * @param user The user issuing the command
96          * @return A value from CmdResult to indicate command success or failure.
97          */
98         CmdResult Handle(const std::vector<std::string>& parameters, User* user) CXX11_OVERRIDE;
99
100         RouteDescriptor GetRouting(User* user, const std::vector<std::string>& parameters) CXX11_OVERRIDE;
101 };
102
103 /** Handle /NICK.
104  */
105 class CommandNick : public SplitCommand
106 {
107  public:
108         /** Constructor for nick.
109          */
110         CommandNick(Module* parent);
111
112         /** Handle command.
113          * @param parameters The parameters to the command
114          * @param user The user issuing the command
115          * @return A value from CmdResult to indicate command success or failure.
116          */
117         CmdResult HandleLocal(const std::vector<std::string>& parameters, LocalUser* user) CXX11_OVERRIDE;
118 };
119
120 /** Handle /PART.
121  */
122 class CommandPart : public Command
123 {
124  public:
125         MessageWrapper msgwrap;
126
127         /** Constructor for part.
128          */
129         CommandPart(Module* parent);
130
131         /** Handle command.
132          * @param parameters The parameters to the command
133          * @param user The user issuing the command
134          * @return A value from CmdResult to indicate command success or failure.
135          */
136         CmdResult Handle(const std::vector<std::string>& parameters, User* user) CXX11_OVERRIDE;
137         RouteDescriptor GetRouting(User* user, const std::vector<std::string>& parameters) CXX11_OVERRIDE;
138 };
139
140 /** Handle /QUIT.
141  */
142 class CommandQuit : public Command
143 {
144  private:
145         StringExtItem operquit;
146
147  public:
148         MessageWrapper msgwrap;
149
150         /** Constructor for quit.
151          */
152         CommandQuit(Module* parent);
153
154         /** Handle command.
155          * @param parameters The parameters to the command
156          * @param user The user issuing the command
157          * @return A value from CmdResult to indicate command success or failure.
158          */
159         CmdResult Handle(const std::vector<std::string>& parameters, User* user) CXX11_OVERRIDE;
160
161         RouteDescriptor GetRouting(User* user, const std::vector<std::string>& parameters) CXX11_OVERRIDE;
162 };
163
164 /** Handle /USER.
165  */
166 class CommandUser : public SplitCommand
167 {
168  public:
169         /** Constructor for user.
170          */
171         CommandUser(Module* parent);
172
173         /** Handle command.
174          * @param parameters The parameters to the command
175          * @param user The user issuing the command
176          * @return A value from CmdResult to indicate command success or failure.
177          */
178         CmdResult HandleLocal(const std::vector<std::string>& parameters, LocalUser* user) CXX11_OVERRIDE;
179
180         /** Run the OnUserRegister hook if the user has sent both NICK and USER. Called after an unregistered user
181          * successfully executes the USER or the NICK command.
182          * @param user User to inspect and possibly pass to the OnUserRegister hook
183          * @return CMD_FAILURE if OnUserRegister was called and it returned MOD_RES_DENY, CMD_SUCCESS in every other case
184          * (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
185          * a non-MOD_RES_DENY result).
186          */
187         static CmdResult CheckRegister(LocalUser* user);
188 };
189
190 /** User mode +s
191  */
192 class ModeUserServerNoticeMask : public ModeHandler
193 {
194         /** Process a snomask modifier string, e.g. +abc-de
195          * @param user The target user
196          * @param input A sequence of notice mask characters
197          * @return The cleaned mode sequence which can be output,
198          * e.g. in the above example if masks c and e are not
199          * valid, this function will return +ab-d
200          */
201         std::string ProcessNoticeMasks(User* user, const std::string& input);
202
203  public:
204         ModeUserServerNoticeMask(Module* Creator);
205         ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string &parameter, bool adding) CXX11_OVERRIDE;
206         void OnParameterMissing(User* user, User* dest, Channel* channel) CXX11_OVERRIDE;
207
208         /** Create a displayable mode string of the snomasks set on a given user
209          * @param user The user whose notice masks to format
210          * @return The notice mask character sequence
211          */
212         std::string GetUserParameter(const User* user) const CXX11_OVERRIDE;
213 };
214
215 /** User mode +o
216  */
217 class ModeUserOperator : public ModeHandler
218 {
219  public:
220         ModeUserOperator(Module* Creator);
221         ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string &parameter, bool adding) CXX11_OVERRIDE;
222 };