]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - include/message.h
Add support for the IRCv3 account-tag specification.
[user/henk/code/inspircd.git] / include / message.h
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  *   Copyright (C) 2017 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 /** Whether message was a PRIVMSG or a NOTICE. */
23 enum MessageType
24 {
25         /** The message is a PRIVMSG. */
26         MSG_PRIVMSG,
27
28         /** The message is a NOTICE. */
29         MSG_NOTICE
30 };
31
32 class CoreExport MessageDetails
33 {
34  public:
35         /* Whether to send the original message back to clients with echo-message support. */
36         bool echooriginal;
37
38          /** The users who are exempted from receiving this message. */
39         CUList exemptions;
40
41         /* The original message as sent by the user. */
42         const std::string originaltext;
43
44         /** IRCv3 message tags sent to the server by the user. */
45         const ClientProtocol::TagMap tags_in;
46
47         /** IRCv3 message tags sent out to users who get this message. */
48         ClientProtocol::TagMap tags_out;
49
50         /** The message which will be sent to clients. */
51         std::string text;
52
53         /** The type of message. */
54         const MessageType type;
55
56         MessageDetails(MessageType mt, const std::string& msg, const ClientProtocol::TagMap& tags)
57                 : echooriginal(false)
58                 , originaltext(msg)
59                 , tags_in(tags)
60                 , text(msg)
61                 , type(mt)
62         {
63         }
64 };
65
66 /** Represents the target of a message (NOTICE, PRIVMSG, etc). */
67 class CoreExport MessageTarget
68 {
69  public:
70         /** An enumeration of possible message target types. */
71         enum TargetType
72         {
73                 /** The target of the message is a user. */
74                 TYPE_USER,
75
76                 /** The target of the message is a channel. */
77                 TYPE_CHANNEL,
78
79                 /** The target of the message is a server. */
80                 TYPE_SERVER
81         };
82
83  private:
84         /** The target of the message. */
85         void* dest;
86
87  public:
88         /** If type is TYPE_CHANNEL and the user specified a status rank. */
89         char status;
90
91         /** The type of the target of the message. If this is TYPE_CHANNEL then dest
92          * is a Channel*, TYPE_USER then dest is a User*, and TYPE_SERVER then dest is
93          * a std::string* containing a server glob.
94          */
95         MessageTarget::TargetType type;
96
97         /** Initialises a new channel message target.
98          * @param channel The channel which is the target of the message.
99          * @param statuschar The lowest status rank that the message is being sent to.
100          */
101         MessageTarget(Channel* channel, char statuschar)
102                 : dest(channel)
103                 , status(statuschar)
104                 , type(TYPE_CHANNEL)
105         {
106         }
107
108         /** Initialises a new user message target.
109          * @param user The user which is the target of the message.
110          */
111         MessageTarget(User* user)
112                 : dest(user)
113                 , status(0)
114                 , type(TYPE_USER)
115         {
116         }
117
118         /** Initialises a new server message target.
119          * @param server The server glob which is the target of the message.
120          */
121         MessageTarget(std::string* server)
122                 : dest(server)
123                 , status(0)
124                 , type(TYPE_SERVER)
125         {
126         }
127
128         /** Retrieves the target of this message. */
129         template<typename T>
130         T* Get() const
131         {
132                 return static_cast<T*>(dest);
133         }
134 };