InspIRCd  3.0
message.h
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  * Copyright (C) 2017-2018, 2020 Sadie Powell <[email protected]>
5  * Copyright (C) 2017-2018 Attila Molnar <[email protected]>
6  *
7  * This file is part of InspIRCd. InspIRCd is free software: you can
8  * redistribute it and/or modify it under the terms of the GNU General Public
9  * License as published by the Free Software Foundation, version 2.
10  *
11  * This program is distributed in the hope that it will be useful, but WITHOUT
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
14  * details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 
21 #pragma once
22 
24 enum MessageType
25 {
27  MSG_PRIVMSG,
28 
30  MSG_NOTICE
31 };
32 
33 class CoreExport MessageDetails
34 {
35  public:
37  bool echo;
38 
39  /* Whether to send the original message back to clients with echo-message support. */
40  bool echo_original;
41 
43  CUList exemptions;
44 
45  /* The original message as sent by the user. */
46  const std::string original_text;
47 
50 
53 
55  std::string text;
56 
58  const MessageType type;
59 
66  virtual bool IsCTCP(std::string& name, std::string& body) const = 0;
67 
72  virtual bool IsCTCP(std::string& name) const = 0;
73 
75  virtual bool IsCTCP() const = 0;
76 
77  protected:
78  MessageDetails(MessageType mt, const std::string& msg, const ClientProtocol::TagMap& tags)
79  : echo(true)
80  , echo_original(false)
81  , original_text(msg)
82  , tags_in(tags)
83  , text(msg)
84  , type(mt)
85  {
86  }
87 };
88 
90 class CoreExport MessageTarget
91 {
92  public:
95  {
98 
101 
103  TYPE_SERVER
104  };
105 
106  private:
108  void* dest;
109 
110  public:
112  char status;
113 
119 
124  MessageTarget(Channel* channel, char statuschar)
125  : dest(channel)
126  , status(statuschar)
127  , type(TYPE_CHANNEL)
128  {
129  }
130 
135  : dest(user)
136  , status(0)
137  , type(TYPE_USER)
138  {
139  }
140 
144  MessageTarget(std::string* server)
145  : dest(server)
146  , status(0)
147  , type(TYPE_SERVER)
148  {
149  }
150 
152  template<typename T>
153  T* Get() const
154  {
155  return static_cast<T*>(dest);
156  }
157 
159  const std::string& GetName() const
160  {
161  switch (type)
162  {
163  case TYPE_CHANNEL:
164  return Get<Channel>()->name;
165  case TYPE_USER:
166  return Get<User>()->nick;
167  case TYPE_SERVER:
168  return *Get<std::string>();
169  }
170 
171  // We should never reach this point during a normal execution but
172  // handle it just in case.
173  static const std::string target = "*";
174  return target;
175  }
176 };
MessageTarget
Definition: message.h:90
MessageTarget::TYPE_CHANNEL
@ TYPE_CHANNEL
Definition: message.h:100
MessageDetails::exemptions
CUList exemptions
Definition: message.h:43
MessageTarget::TargetType
TargetType
Definition: message.h:94
MessageDetails::tags_in
const ClientProtocol::TagMap tags_in
Definition: message.h:49
MessageDetails
Definition: message.h:33
MessageDetails::echo
bool echo
Definition: message.h:37
insp::flat_map< std::string, MessageTagData, std::greater< std::string > >
MessageTarget::MessageTarget
MessageTarget(Channel *channel, char statuschar)
Definition: message.h:124
MessageTarget::MessageTarget
MessageTarget(std::string *server)
Definition: message.h:144
MessageDetails::text
std::string text
Definition: message.h:55
MessageDetails::tags_out
ClientProtocol::TagMap tags_out
Definition: message.h:52
MessageDetails::type
const MessageType type
Definition: message.h:58
MessageTarget::MessageTarget
MessageTarget(User *user)
Definition: message.h:134
Channel
Definition: channels.h:40
MessageTarget::type
MessageTarget::TargetType type
Definition: message.h:118
User
Definition: users.h:233
MessageTarget::GetName
const std::string & GetName() const
Definition: message.h:159
MessageTarget::status
char status
Definition: message.h:112
MessageTarget::Get
T * Get() const
Definition: message.h:153
MessageTarget::TYPE_USER
@ TYPE_USER
Definition: message.h:97