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