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/>.
19 // IMPORTANT: The contents of this file are experimental and are not presently
20 // covered by the InspIRCd API stability guarantee.
25 #include "modules/cap.h"
38 /** Base class for standard replies. */
39 class IRCv3::Replies::Reply
42 /** The name of the command for this reply. */
45 /** The event provider for this reply. */
46 ClientProtocol::EventProvider evprov;
48 /** Wraps a message in an event and sends it to a user.
49 * @param user The user to send the message to.
50 * @param msg The message to send to the user.
52 void SendInternal(LocalUser* user, ClientProtocol::Message& msg)
54 ClientProtocol::Event ev(evprov, msg);
59 /** Initializes a new instance of the Reply class.
60 * @param Creator The module which created this instance.
61 * @param Cmd The name of the command to reply with.
63 Reply(Module* Creator, const std::string& Cmd)
65 , evprov(Creator, Cmd)
71 * Sends a standard reply to the specified user.
72 * @param user The user to send the reply to.
73 * @param command The command that the reply relates to.
74 * @param code A machine readable code for this reply.
75 * @param description A human readable description of this reply.
77 void Send(LocalUser* user, Command* command, const std::string& code, const std::string& description)
79 ClientProtocol::Message msg(cmd.c_str(), ServerInstance->Config->ServerName);
80 msg.PushParamRef(command->name);
82 msg.PushParam(description);
83 SendInternal(user, msg);
87 void Send(LocalUser* user, Command* command, const std::string& code, const T1& p1, const std::string& description)
89 ClientProtocol::Message msg(cmd.c_str(), ServerInstance->Config->ServerName);
90 msg.PushParamRef(command->name);
92 msg.PushParam(ConvToStr(p1));
93 msg.PushParam(description);
94 SendInternal(user, msg);
97 template<typename T1, typename T2>
98 void Send(LocalUser* user, Command* command, const std::string& code, const T1& p1, const T2& p2,
99 const std::string& description)
101 ClientProtocol::Message msg(cmd.c_str(), ServerInstance->Config->ServerName);
102 msg.PushParamRef(command->name);
104 msg.PushParam(ConvToStr(p1));
105 msg.PushParam(ConvToStr(p2));
106 msg.PushParam(description);
107 SendInternal(user, msg);
110 template<typename T1, typename T2, typename T3>
111 void Send(LocalUser* user, Command* command, const std::string& code, const T1& p1, const T2& p2,
112 const T3& p3, const std::string& description)
114 ClientProtocol::Message msg(cmd.c_str(), ServerInstance->Config->ServerName);
115 msg.PushParamRef(command->name);
117 msg.PushParam(ConvToStr(p1));
118 msg.PushParam(ConvToStr(p2));
119 msg.PushParam(ConvToStr(p3));
120 msg.PushParam(description);
121 SendInternal(user, msg);
124 template<typename T1, typename T2, typename T3, typename T4>
125 void Send(LocalUser* user, Command* command, const std::string& code, const T1& p1, const T2& p2,
126 const T3& p3, const T4& p4, const std::string& description)
128 ClientProtocol::Message msg(cmd.c_str(), ServerInstance->Config->ServerName);
129 msg.PushParamRef(command->name);
131 msg.PushParam(ConvToStr(p1));
132 msg.PushParam(ConvToStr(p2));
133 msg.PushParam(ConvToStr(p3));
134 msg.PushParam(ConvToStr(p4));
135 msg.PushParam(description);
136 SendInternal(user, msg);
139 template<typename T1, typename T2, typename T3, typename T4, typename T5>
140 void Send(LocalUser* user, Command* command, const std::string& code, const T1& p1, const T2& p2,
141 const T3& p3, const T4& p4, const T5& p5, const std::string& description)
143 ClientProtocol::Message msg(cmd.c_str(), ServerInstance->Config->ServerName);
144 msg.PushParamRef(command->name);
146 msg.PushParam(ConvToStr(p1));
147 msg.PushParam(ConvToStr(p2));
148 msg.PushParam(ConvToStr(p3));
149 msg.PushParam(ConvToStr(p4));
150 msg.PushParam(ConvToStr(p5));
151 msg.PushParam(description);
152 SendInternal(user, msg);
156 * Sends a standard reply to the specified user if they have the specified cap
157 * or a notice if they do not.
158 * @param user The user to send the reply to.
159 * @param command The command that the reply relates to.
160 * @param code A machine readable code for this reply.
161 * @param description A human readable description of this reply.
163 void SendIfCap(LocalUser* user, const Cap::Capability& cap, Command* command, const std::string& code,
164 const std::string& description)
167 Send(user, command, code, description);
169 user->WriteNotice(InspIRCd::Format("*** %s: %s", command->name.c_str(), description.c_str()));
173 /** Sends a FAIL standard reply. */
174 class IRCv3::Replies::Fail
175 : public IRCv3::Replies::Reply
178 /** Initializes a new instance of the Fail class.
179 * @param Creator The module which created this instance.
181 Fail(Module* Creator)
182 : Reply(Creator, "FAIL")
187 /** Sends a NOTE standard reply. */
188 class IRCv3::Replies::Note
189 : public IRCv3::Replies::Reply
192 /** Initializes a new instance of the Note class.
193 * @param Creator The module which created this instance.
195 Note(Module* Creator)
196 : Reply(Creator, "NOTE")
201 /** Sends a WARN standard reply. */
202 class IRCv3::Replies::Warn
203 : public IRCv3::Replies::Reply
206 /** Initializes a new instance of the Warn class.
207 * @param Creator The module which created this instance.
209 Warn(Module* Creator)
210 : Reply(Creator, "WARN")