2 * InspIRCd -- Internet Relay Chat Daemon
4 * Copyright (C) 2018, 2020 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/>.
28 class TagMessageDetails;
31 class CTCTags::TagMessage : public ClientProtocol::Message
34 void PushTarget(const char* target, char status)
38 std::string rawtarget(1, status);
39 rawtarget.append(target);
47 TagMessage(User* source, const Channel* targetchan, const ClientProtocol::TagMap& Tags, char status = 0)
48 : ClientProtocol::Message("TAGMSG", source)
50 PushTarget(targetchan->name.c_str(), status);
54 TagMessage(User* source, const User* targetuser, const ClientProtocol::TagMap& Tags)
55 : ClientProtocol::Message("TAGMSG", source)
57 if (targetuser->registered & REG_NICK)
58 PushParamRef(targetuser->nick);
64 TagMessage(User* source, const char* targetstr, const ClientProtocol::TagMap& Tags, char status = 0)
65 : ClientProtocol::Message("TAGMSG", source)
67 PushTarget(targetstr, status);
71 TagMessage(const char* source, const char* targetstr, const ClientProtocol::TagMap& Tags, char status = 0)
72 : ClientProtocol::Message("TAGMSG", source)
74 PushTarget(targetstr, status);
79 class CTCTags::TagMessageDetails
82 /** Whether to echo the tags at all. */
85 /* Whether to send the original tags back to clients with echo-message support. */
88 /** The users who are exempted from receiving this message. */
91 /** IRCv3 message tags sent to the server by the user. */
92 const ClientProtocol::TagMap tags_in;
94 /** IRCv3 message tags sent out to users who get this message. */
95 ClientProtocol::TagMap tags_out;
97 TagMessageDetails(const ClientProtocol::TagMap& tags)
99 , echo_original(false)
105 class CTCTags::EventListener
106 : public Events::ModuleEventListener
109 EventListener(Module* mod, unsigned int eventprio = DefaultPriority)
110 : ModuleEventListener(mod, "event/tagmsg", eventprio)
115 /** Called before a user sends a tag message to a channel, a user, or a server glob mask.
116 * @param user The user sending the message.
117 * @param target The target of the message. This can either be a channel, a user, or a server
119 * @param details Details about the message such as the message tags or whether to echo. See the
120 * TagMessageDetails class for more information.
121 * @return MOD_RES_ALLOW to explicitly allow the message, MOD_RES_DENY to explicitly deny the
122 * message, or MOD_RES_PASSTHRU to let another module handle the event.
124 virtual ModResult OnUserPreTagMessage(User* user, const MessageTarget& target, TagMessageDetails& details) { return MOD_RES_PASSTHRU; }
126 /** Called immediately after a user sends a tag message to a channel, a user, or a server glob mask.
127 * @param user The user sending the message.
128 * @param target The target of the message. This can either be a channel, a user, or a server
130 * @param details Details about the message such as the message tags or whether to echo. See the
131 * TagMessageDetails class for more information.
133 virtual void OnUserPostTagMessage(User* user, const MessageTarget& target, const TagMessageDetails& details) { }
135 /** Called immediately before a user sends a tag message to a channel, a user, or a server glob mask.
136 * @param user The user sending the message.
137 * @param target The target of the message. This can either be a channel, a user, or a server
139 * @param details Details about the message such as the message tags or whether to echo. See the
140 * TagMessageDetails class for more information.
142 virtual void OnUserTagMessage(User* user, const MessageTarget& target, const TagMessageDetails& details) { }
144 /** Called when a tag message sent by a user to a channel, a user, or a server glob mask is blocked.
145 * @param user The user sending the message.
146 * @param target The target of the message. This can either be a channel, a user, or a server
148 * @param details Details about the message such as the message tags or whether to echo. See the
149 * TagMessageDetails class for more information.
151 virtual void OnUserTagMessageBlocked(User* user, const MessageTarget& target, const TagMessageDetails& details) { }