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