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 
44 
46  CUList exemptions;
47 
48  /* The original message as sent by the user. */
49  const std::string original_text;
50 
53 
56 
58  std::string text;
59 
61  MessageType type;
62 
69  virtual bool IsCTCP(std::string& name, std::string& body) const = 0;
70 
75  virtual bool IsCTCP(std::string& name) const = 0;
76 
78  virtual bool IsCTCP() const = 0;
79 
80  protected:
81  MessageDetails(MessageType mt, const std::string& msg, const ClientProtocol::TagMap& tags)
82  : echo(true)
83  , echo_original(false)
84  , update_idle(true)
85  , original_text(msg)
86  , tags_in(tags)
87  , text(msg)
88  , type(mt)
89  {
90  }
91 };
92 
94 class CoreExport MessageTarget
95 {
96  public:
99  {
102 
105 
107  TYPE_SERVER
108  };
109 
110  private:
112  void* dest;
113 
114  public:
116  char status;
117 
123 
128  MessageTarget(Channel* channel, char statuschar)
129  : dest(channel)
130  , status(statuschar)
131  , type(TYPE_CHANNEL)
132  {
133  }
134 
139  : dest(user)
140  , status(0)
141  , type(TYPE_USER)
142  {
143  }
144 
148  MessageTarget(std::string* server)
149  : dest(server)
150  , status(0)
151  , type(TYPE_SERVER)
152  {
153  }
154 
156  template<typename T>
157  T* Get() const
158  {
159  return static_cast<T*>(dest);
160  }
161 
163  const std::string& GetName() const
164  {
165  switch (type)
166  {
167  case TYPE_CHANNEL:
168  return Get<Channel>()->name;
169  case TYPE_USER:
170  return Get<User>()->nick;
171  case TYPE_SERVER:
172  return *Get<std::string>();
173  }
174 
175  // We should never reach this point during a normal execution but
176  // handle it just in case.
177  static const std::string target = "*";
178  return target;
179  }
180 };
MessageTarget
Definition: message.h:94
MessageTarget::TYPE_CHANNEL
@ TYPE_CHANNEL
Definition: message.h:104
MessageDetails::exemptions
CUList exemptions
Definition: message.h:46
MessageTarget::TargetType
TargetType
Definition: message.h:98
MessageDetails::tags_in
const ClientProtocol::TagMap tags_in
Definition: message.h:52
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:128
MessageDetails::update_idle
bool update_idle
Definition: message.h:43
MessageTarget::MessageTarget
MessageTarget(std::string *server)
Definition: message.h:148
MessageDetails::type
MessageType type
Definition: message.h:61
MessageDetails::text
std::string text
Definition: message.h:58
MessageDetails::tags_out
ClientProtocol::TagMap tags_out
Definition: message.h:55
MessageTarget::MessageTarget
MessageTarget(User *user)
Definition: message.h:138
Channel
Definition: channels.h:40
MessageTarget::type
MessageTarget::TargetType type
Definition: message.h:122
User
Definition: users.h:239
MessageTarget::GetName
const std::string & GetName() const
Definition: message.h:163
MessageTarget::status
char status
Definition: message.h:116
MessageTarget::Get
T * Get() const
Definition: message.h:157
MessageTarget::TYPE_USER
@ TYPE_USER
Definition: message.h:101