]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - include/modules/ctctags.h
Implement support for IRCv3 client-to-client tags.
[user/henk/code/inspircd.git] / include / modules / ctctags.h
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  *   Copyright (C) 2019 Peter Powell <petpow@saberuk.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 "event.h"
23
24 namespace CTCTags
25 {
26         class EventListener;
27         class TagMessage;
28         class TagMessageDetails;
29 }
30
31 class CTCTags::TagMessage : public ClientProtocol::Message
32 {
33  public:
34         TagMessage(User* source, const Channel* targetchan, const ClientProtocol::TagMap& Tags)
35                 : ClientProtocol::Message("TAGMSG", source)
36         {
37                 PushParamRef(targetchan->name);
38                 AddTags(Tags);
39                 SetSideEffect(true);
40         }
41
42         TagMessage(User* source, const User* targetuser, const ClientProtocol::TagMap& Tags)
43                 : ClientProtocol::Message("TAGMSG", source)
44         {
45                 if (targetuser->registered & REG_NICK)
46                         PushParamRef(targetuser->nick);
47                 else
48                         PushParam("*");
49                 AddTags(Tags);
50                 SetSideEffect(true);
51         }
52
53         TagMessage(User* source, const char* targetstr, const ClientProtocol::TagMap& Tags)
54                 : ClientProtocol::Message("TAGMSG", source)
55         {
56                 PushParam(targetstr);
57                 AddTags(Tags);
58                 SetSideEffect(true);
59         }
60 };
61
62 class CTCTags::TagMessageDetails
63 {
64  public:
65         /** Whether to echo the tags at all. */
66         bool echo;
67
68         /* Whether to send the original tags back to clients with echo-message support. */
69         bool echo_original;
70
71         /** The users who are exempted from receiving this message. */
72         CUList exemptions;
73
74         /** IRCv3 message tags sent to the server by the user. */
75         const ClientProtocol::TagMap tags_in;
76
77         /** IRCv3 message tags sent out to users who get this message. */
78         ClientProtocol::TagMap tags_out;
79
80         TagMessageDetails(const ClientProtocol::TagMap& tags)
81                 : echo(true)
82                 , echo_original(false)
83                 , tags_in(tags)
84         {
85         }
86 };
87
88 class CTCTags::EventListener
89         : public Events::ModuleEventListener
90 {
91  protected:
92         EventListener(Module* mod, unsigned int eventprio = DefaultPriority)
93                 : ModuleEventListener(mod, "event/tagmsg", eventprio)
94         {
95         }
96
97  public:
98         /** Called before a user sends a tag message to a channel, a user, or a server glob mask.
99          * @param user The user sending the message.
100          * @param target The target of the message. This can either be a channel, a user, or a server
101          *               glob mask.
102          * @param details Details about the message such as the message tags or whether to echo. See the
103          *                TagMessageDetails class for more information.
104          * @return MOD_RES_ALLOW to explicitly allow the message, MOD_RES_DENY to explicitly deny the
105          *         message, or MOD_RES_PASSTHRU to let another module handle the event.
106          */
107         virtual ModResult OnUserPreTagMessage(User* user, const MessageTarget& target, TagMessageDetails& details) { return MOD_RES_PASSTHRU; }
108         
109         /** Called immediately after a user sends a tag message to a channel, a user, or a server glob mask.
110          * @param user The user sending the message.
111          * @param target The target of the message. This can either be a channel, a user, or a server
112          *               glob mask.
113          * @param details Details about the message such as the message tags or whether to echo. See the
114          *                TagMessageDetails class for more information.
115          */
116         virtual void OnUserPostTagMessage(User* user, const MessageTarget& target, const TagMessageDetails& details) { }
117
118         /** Called immediately before a user sends a tag message to a channel, a user, or a server glob mask.
119          * @param user The user sending the message.
120          * @param target The target of the message. This can either be a channel, a user, or a server
121          *               glob mask.
122          * @param details Details about the message such as the message tags or whether to echo. See the
123          *                TagMessageDetails class for more information.
124          */
125         virtual void OnUserTagMessage(User* user, const MessageTarget& target, const TagMessageDetails& details) { }
126
127         /** Called when a tag message sent by a user to a channel, a user, or a server glob mask is blocked.
128          * @param user The user sending the message.
129          * @param target The target of the message. This can either be a channel, a user, or a server
130          *               glob mask.
131          * @param details Details about the message such as the message tags or whether to echo. See the
132          *                TagMessageDetails class for more information.
133          */
134         virtual void OnUserTagMessageBlocked(User* user, const MessageTarget& target, const TagMessageDetails& details) { }
135 };