2 * InspIRCd -- Internet Relay Chat Daemon
4 * Copyright (C) 2019 Sadie Powell <sadie@witchery.services>
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.
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
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/>.
22 #include "modules/cap.h"
35 /** Base class for standard replies. */
36 class IRCv3::Replies::Reply
39 /** The name of the command for this reply. */
40 const std::string cmd;
42 /** The event provider for this reply. */
43 ClientProtocol::EventProvider evprov;
45 /** Wraps a message in an event and sends it to a user.
46 * @param user The user to send the message to.
47 * @param msg The message to send to the user.
49 void SendInternal(LocalUser* user, ClientProtocol::Message& msg)
51 ClientProtocol::Event ev(evprov, msg);
55 void SendNoticeInternal(LocalUser* user, Command* command, const std::string& description)
57 user->WriteNotice(InspIRCd::Format("*** %s: %s", command->name.c_str(), description.c_str()));
61 /** Initializes a new instance of the Reply class.
62 * @param Creator The module which created this instance.
63 * @param Cmd The name of the command to reply with.
65 Reply(Module* Creator, const std::string& Cmd)
67 , evprov(Creator, Cmd)
73 * Sends a standard reply to the specified user.
74 * @param user The user to send the reply to.
75 * @param command The command that the reply relates to.
76 * @param code A machine readable code for this reply.
77 * @param description A human readable description of this reply.
79 void Send(LocalUser* user, Command* command, const std::string& code, const std::string& description)
81 ClientProtocol::Message msg(cmd.c_str(), ServerInstance->Config->ServerName);
82 msg.PushParamRef(command->name);
84 msg.PushParam(description);
85 SendInternal(user, msg);
89 void Send(LocalUser* user, Command* command, const std::string& code, const T1& p1, const std::string& description)
91 ClientProtocol::Message msg(cmd.c_str(), ServerInstance->Config->ServerName);
92 msg.PushParamRef(command->name);
94 msg.PushParam(ConvToStr(p1));
95 msg.PushParam(description);
96 SendInternal(user, msg);
99 template<typename T1, typename T2>
100 void Send(LocalUser* user, Command* command, const std::string& code, const T1& p1, const T2& p2,
101 const std::string& description)
103 ClientProtocol::Message msg(cmd.c_str(), ServerInstance->Config->ServerName);
104 msg.PushParamRef(command->name);
106 msg.PushParam(ConvToStr(p1));
107 msg.PushParam(ConvToStr(p2));
108 msg.PushParam(description);
109 SendInternal(user, msg);
112 template<typename T1, typename T2, typename T3>
113 void Send(LocalUser* user, Command* command, const std::string& code, const T1& p1, const T2& p2,
114 const T3& p3, const std::string& description)
116 ClientProtocol::Message msg(cmd.c_str(), ServerInstance->Config->ServerName);
117 msg.PushParamRef(command->name);
119 msg.PushParam(ConvToStr(p1));
120 msg.PushParam(ConvToStr(p2));
121 msg.PushParam(ConvToStr(p3));
122 msg.PushParam(description);
123 SendInternal(user, msg);
126 template<typename T1, typename T2, typename T3, typename T4>
127 void Send(LocalUser* user, Command* command, const std::string& code, const T1& p1, const T2& p2,
128 const T3& p3, const T4& p4, const std::string& description)
130 ClientProtocol::Message msg(cmd.c_str(), ServerInstance->Config->ServerName);
131 msg.PushParamRef(command->name);
133 msg.PushParam(ConvToStr(p1));
134 msg.PushParam(ConvToStr(p2));
135 msg.PushParam(ConvToStr(p3));
136 msg.PushParam(ConvToStr(p4));
137 msg.PushParam(description);
138 SendInternal(user, msg);
141 template<typename T1, typename T2, typename T3, typename T4, typename T5>
142 void Send(LocalUser* user, Command* command, const std::string& code, const T1& p1, const T2& p2,
143 const T3& p3, const T4& p4, const T5& p5, const std::string& description)
145 ClientProtocol::Message msg(cmd.c_str(), ServerInstance->Config->ServerName);
146 msg.PushParamRef(command->name);
148 msg.PushParam(ConvToStr(p1));
149 msg.PushParam(ConvToStr(p2));
150 msg.PushParam(ConvToStr(p3));
151 msg.PushParam(ConvToStr(p4));
152 msg.PushParam(ConvToStr(p5));
153 msg.PushParam(description);
154 SendInternal(user, msg);
158 * Sends a standard reply to the specified user if they have the specified cap
159 * or a notice if they do not.
160 * @param user The user to send the reply to.
161 * @param command The command that the reply relates to.
162 * @param code A machine readable code for this reply.
163 * @param description A human readable description of this reply.
165 void SendIfCap(LocalUser* user, const Cap::Capability& cap, Command* command, const std::string& code,
166 const std::string& description)
169 Send(user, command, code, description);
171 SendNoticeInternal(user, command, description);
174 template<typename T1>
175 void SendIfCap(LocalUser* user, const Cap::Capability& cap, Command* command, const std::string& code,
176 const T1& p1, const std::string& description)
179 Send(user, command, code, p1, description);
181 SendNoticeInternal(user, command, description);
184 template<typename T1, typename T2>
185 void SendIfCap(LocalUser* user, const Cap::Capability& cap, Command* command, const std::string& code,
186 const T1& p1, const T2& p2, const std::string& description)
189 Send(user, command, code, p1, p2, description);
191 SendNoticeInternal(user, command, description);
194 template<typename T1, typename T2, typename T3>
195 void SendIfCap(LocalUser* user, const Cap::Capability& cap, Command* command, const std::string& code,
196 const T1& p1, const T2& p2, const T3& p3, const std::string& description)
199 Send(user, command, code, p1, p2, p3, description);
201 SendNoticeInternal(user, command, description);
204 template<typename T1, typename T2, typename T3, typename T4>
205 void SendIfCap(LocalUser* user, const Cap::Capability& cap, Command* command, const std::string& code,
206 const T1& p1, const T2& p2, const T3& p3, const T4& p4, const std::string& description)
209 Send(user, command, code, p1, p2, p3, p4, description);
211 SendNoticeInternal(user, command, description);
214 template<typename T1, typename T2, typename T3, typename T4, typename T5>
215 void SendIfCap(LocalUser* user, const Cap::Capability& cap, Command* command, const std::string& code,
216 const T1& p1, const T2& p2, const T3& p3, const T4& p4, const T5& p5, const std::string& description)
219 Send(user, command, code, p1, p2, p3, p4, p5, description);
221 SendNoticeInternal(user, command, description);
225 /** Sends a FAIL standard reply. */
226 class IRCv3::Replies::Fail
227 : public IRCv3::Replies::Reply
230 /** Initializes a new instance of the Fail class.
231 * @param Creator The module which created this instance.
233 Fail(Module* Creator)
234 : Reply(Creator, "FAIL")
239 /** Sends a NOTE standard reply. */
240 class IRCv3::Replies::Note
241 : public IRCv3::Replies::Reply
244 /** Initializes a new instance of the Note class.
245 * @param Creator The module which created this instance.
247 Note(Module* Creator)
248 : Reply(Creator, "NOTE")
253 /** Sends a WARN standard reply. */
254 class IRCv3::Replies::Warn
255 : public IRCv3::Replies::Reply
258 /** Initializes a new instance of the Warn class.
259 * @param Creator The module which created this instance.
261 Warn(Module* Creator)
262 : Reply(Creator, "WARN")