]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - include/modules/ctctags.h
Use PushParam instead of PushParamRef in TagMessage#PushTarget.
[user/henk/code/inspircd.git] / include / modules / ctctags.h
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  *   Copyright (C) 2018 Sadie Powell <sadie@witchery.services>
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 private:
34         void PushTarget(const char* target, char status)
35         {
36                 if (status)
37                 {
38                         std::string rawtarget(1, status);
39                         rawtarget.append(target);
40                         PushParam(rawtarget);
41                 }
42                 else
43                         PushParam(target);
44         }
45
46  public:
47         TagMessage(User* source, const Channel* targetchan, const ClientProtocol::TagMap& Tags, char status = 0)
48                 : ClientProtocol::Message("TAGMSG", source)
49         {
50                 PushTarget(targetchan->name.c_str(), status);
51                 AddTags(Tags);
52         }
53
54         TagMessage(User* source, const User* targetuser, const ClientProtocol::TagMap& Tags)
55                 : ClientProtocol::Message("TAGMSG", source)
56         {
57                 if (targetuser->registered & REG_NICK)
58                         PushParamRef(targetuser->nick);
59                 else
60                         PushParam("*");
61                 AddTags(Tags);
62         }
63
64         TagMessage(User* source, const char* targetstr, const ClientProtocol::TagMap& Tags, char status = 0)
65                 : ClientProtocol::Message("TAGMSG", source)
66         {
67                 PushTarget(targetstr, status);
68                 AddTags(Tags);
69         }
70
71         TagMessage(const char* source, const char* targetstr, const ClientProtocol::TagMap& Tags, char status = 0)
72                 : ClientProtocol::Message("TAGMSG", source)
73         {
74                 PushTarget(targetstr, status);
75                 AddTags(Tags);
76         }
77 };
78
79 class CTCTags::TagMessageDetails
80 {
81  public:
82         /** Whether to echo the tags at all. */
83         bool echo;
84
85         /* Whether to send the original tags back to clients with echo-message support. */
86         bool echo_original;
87
88         /** The users who are exempted from receiving this message. */
89         CUList exemptions;
90
91         /** IRCv3 message tags sent to the server by the user. */
92         const ClientProtocol::TagMap tags_in;
93
94         /** IRCv3 message tags sent out to users who get this message. */
95         ClientProtocol::TagMap tags_out;
96
97         TagMessageDetails(const ClientProtocol::TagMap& tags)
98                 : echo(true)
99                 , echo_original(false)
100                 , tags_in(tags)
101         {
102         }
103 };
104
105 class CTCTags::EventListener
106         : public Events::ModuleEventListener
107 {
108  protected:
109         EventListener(Module* mod, unsigned int eventprio = DefaultPriority)
110                 : ModuleEventListener(mod, "event/tagmsg", eventprio)
111         {
112         }
113
114  public:
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
118          *               glob mask.
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.
123          */
124         virtual ModResult OnUserPreTagMessage(User* user, const MessageTarget& target, TagMessageDetails& details) { return MOD_RES_PASSTHRU; }
125         
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
129          *               glob mask.
130          * @param details Details about the message such as the message tags or whether to echo. See the
131          *                TagMessageDetails class for more information.
132          */
133         virtual void OnUserPostTagMessage(User* user, const MessageTarget& target, const TagMessageDetails& details) { }
134
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
138          *               glob mask.
139          * @param details Details about the message such as the message tags or whether to echo. See the
140          *                TagMessageDetails class for more information.
141          */
142         virtual void OnUserTagMessage(User* user, const MessageTarget& target, const TagMessageDetails& details) { }
143
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
147          *               glob mask.
148          * @param details Details about the message such as the message tags or whether to echo. See the
149          *                TagMessageDetails class for more information.
150          */
151         virtual void OnUserTagMessageBlocked(User* user, const MessageTarget& target, const TagMessageDetails& details) { }
152 };