]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - include/message.h
Use meaningful variable names in consolecolors.
[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         /** Determines whether the specified message is a CTCP. If the specified message
60          * is a CTCP then the CTCP name and CTCP body are extracted and stored in the
61          * name and body references.
62          * @param name The location to store the parsed CTCP name.
63          * @param body The location to store the parsed CTCP body.
64          */
65         virtual bool IsCTCP(std::string& name, std::string& body) const = 0;
66
67         /** Determines whether the specified message is a CTCP. If the specified message
68          * is a CTCP then the CTCP name is extracted and stored in the name reference.
69          * @param name The location to store the parsed CTCP name.
70          */
71         virtual bool IsCTCP(std::string& name) const = 0;
72
73         /** Determines whether the specified message is a CTCP. */
74         virtual bool IsCTCP() const = 0;
75
76  protected:
77         MessageDetails(MessageType mt, const std::string& msg, const ClientProtocol::TagMap& tags)
78                 : echo(true)
79                 , echo_original(false)
80                 , original_text(msg)
81                 , tags_in(tags)
82                 , text(msg)
83                 , type(mt)
84         {
85         }
86 };
87
88 /** Represents the target of a message (NOTICE, PRIVMSG, etc). */
89 class CoreExport MessageTarget
90 {
91  public:
92         /** An enumeration of possible message target types. */
93         enum TargetType
94         {
95                 /** The target of the message is a user. */
96                 TYPE_USER,
97
98                 /** The target of the message is a channel. */
99                 TYPE_CHANNEL,
100
101                 /** The target of the message is a server. */
102                 TYPE_SERVER
103         };
104
105  private:
106         /** The target of the message. */
107         void* dest;
108
109  public:
110         /** If type is TYPE_CHANNEL and the user specified a status rank. */
111         char status;
112
113         /** The type of the target of the message. If this is TYPE_CHANNEL then dest
114          * is a Channel*, TYPE_USER then dest is a User*, and TYPE_SERVER then dest is
115          * a std::string* containing a server glob.
116          */
117         MessageTarget::TargetType type;
118
119         /** Initialises a new channel message target.
120          * @param channel The channel which is the target of the message.
121          * @param statuschar The lowest status rank that the message is being sent to.
122          */
123         MessageTarget(Channel* channel, char statuschar)
124                 : dest(channel)
125                 , status(statuschar)
126                 , type(TYPE_CHANNEL)
127         {
128         }
129
130         /** Initialises a new user message target.
131          * @param user The user which is the target of the message.
132          */
133         MessageTarget(User* user)
134                 : dest(user)
135                 , status(0)
136                 , type(TYPE_USER)
137         {
138         }
139
140         /** Initialises a new server message target.
141          * @param server The server glob which is the target of the message.
142          */
143         MessageTarget(std::string* server)
144                 : dest(server)
145                 , status(0)
146                 , type(TYPE_SERVER)
147         {
148         }
149
150         /** Retrieves the target of this message. */
151         template<typename T>
152         T* Get() const
153         {
154                 return static_cast<T*>(dest);
155         }
156 };