]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/coremods/core_user/core_user.h
2a1ba7bfdf635167c01d4ec8fdaa811c2ebdbeb9
[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  *
6  * This file is part of InspIRCd.  InspIRCd is free software: you can
7  * redistribute it and/or modify it under the terms of the GNU General Public
8  * License as published by the Free Software Foundation, version 2.
9  *
10  * This program is distributed in the hope that it will be useful, but WITHOUT
11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
13  * details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
17  */
18
19
20 #pragma once
21
22 #include "inspircd.h"
23
24 class MessageWrapper
25 {
26         std::string prefix;
27         std::string suffix;
28         bool fixed;
29
30  public:
31         /**
32          * Wrap the given message according to the config rules
33          * @param message The message to wrap
34          * @param out String where the result is placed
35          */
36         void Wrap(const std::string& message, std::string& out);
37
38         /**
39          * Read the settings from the given config keys (options block)
40          * @param prefixname Name of the config key to read the prefix from
41          * @param suffixname Name of the config key to read the suffix from
42          * @param fixedname Name of the config key to read the fixed string string from.
43          * If this key has a non-empty value, all messages will be replaced with it.
44          */
45         void ReadConfig(const char* prefixname, const char* suffixname, const char* fixedname);
46 };
47
48 /** Handle /AWAY.
49  */
50 class CommandAway : public Command
51 {
52  public:
53         /** Constructor for away.
54          */
55         CommandAway(Module* parent);
56         /** Handle command.
57          * @param parameters The parameters to the command
58          * @param user The user issuing the command
59          * @return A value from CmdResult to indicate command success or failure.
60          */
61         CmdResult Handle(const std::vector<std::string>& parameters, User* user) CXX11_OVERRIDE;
62         RouteDescriptor GetRouting(User* user, const std::vector<std::string>& parameters) CXX11_OVERRIDE;
63 };
64
65 class CommandMode : public Command
66 {
67         unsigned int sent[256];
68         unsigned int seq;
69
70         /** Show the list of one or more list modes to a user.
71          * @param user User to send to.
72          * @param chan Channel whose lists to show.
73          * @param mode_sequence Mode letters to show the lists of.
74          */
75         void DisplayListModes(User* user, Channel* chan, const std::string& mode_sequence);
76
77         /** Show the current modes of a channel or a user to a user.
78          * @param user User to show the modes to.
79          * @param targetuser User whose modes to show. NULL if showing the modes of a channel.
80          * @param targetchannel Channel whose modes to show. NULL if showing the modes of a user.
81          */
82         void DisplayCurrentModes(User* user, User* targetuser, Channel* targetchannel);
83
84  public:
85         /** Constructor for mode.
86          */
87         CommandMode(Module* parent);
88
89         /** Handle command.
90          * @param parameters The parameters to the command
91          * @param user The user issuing the command
92          * @return A value from CmdResult to indicate command success or failure.
93          */
94         CmdResult Handle(const std::vector<std::string>& parameters, User* user) CXX11_OVERRIDE;
95
96         RouteDescriptor GetRouting(User* user, const std::vector<std::string>& parameters) CXX11_OVERRIDE;
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(const std::vector<std::string>& parameters, LocalUser* user) 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(const std::vector<std::string>& parameters, User* user) CXX11_OVERRIDE;
133         RouteDescriptor GetRouting(User* user, const std::vector<std::string>& 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(const std::vector<std::string>& parameters, User* user) CXX11_OVERRIDE;
156
157         RouteDescriptor GetRouting(User* user, const std::vector<std::string>& 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(const std::vector<std::string>& parameters, LocalUser* user) 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 };