InspIRCd  4.0
message.h
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  * Copyright (C) 2018 Attila Molnar <[email protected]>
5  * Copyright (C) 2017-2018, 2020 Sadie Powell <[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 = true;
38 
39  /* Whether to send the original message back to clients with echo-message support. */
40  bool echo_original = false;
41 
43  bool update_idle = true;
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_view& name, std::string_view& body) const = 0;
70 
75  virtual bool IsCTCP(std::string_view& 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  : original_text(msg)
83  , tags_in(tags)
84  , text(msg)
85  , type(mt)
86  {
87  }
88 };
89 
91 class CoreExport MessageTarget
92 {
93  public:
96  {
99 
102 
104  TYPE_SERVER
105  };
106 
107  private:
109  void* dest;
110 
111  public:
113  char status = 0;
114 
120 
125  MessageTarget(Channel* channel, char statuschar)
126  : dest(channel)
127  , status(statuschar)
128  , type(TYPE_CHANNEL)
129  {
130  }
131 
136  : dest(user)
137  , type(TYPE_USER)
138  {
139  }
140 
144  MessageTarget(std::string* server)
145  : dest(server)
146  , type(TYPE_SERVER)
147  {
148  }
149 
151  template<typename T>
152  T* Get() const
153  {
154  return static_cast<T*>(dest);
155  }
156 
158  const std::string& GetName() const
159  {
160  switch (type)
161  {
162  case TYPE_CHANNEL:
163  return Get<Channel>()->name;
164  case TYPE_USER:
165  return Get<User>()->nick;
166  case TYPE_SERVER:
167  return *Get<std::string>();
168  }
169 
170  // We should never reach this point during a normal execution but
171  // handle it just in case.
172  static const std::string target = "*";
173  return target;
174  }
175 };
Definition: channels.h:41
Definition: message.h:34
const ClientProtocol::TagMap tags_in
Definition: message.h:52
ClientProtocol::TagMap tags_out
Definition: message.h:55
virtual bool IsCTCP() const =0
MessageType type
Definition: message.h:61
std::string text
Definition: message.h:58
virtual bool IsCTCP(std::string_view &name, std::string_view &body) const =0
CUList exemptions
Definition: message.h:46
virtual bool IsCTCP(std::string_view &name) const =0
Definition: message.h:92
MessageTarget(Channel *channel, char statuschar)
Definition: message.h:125
T * Get() const
Definition: message.h:152
MessageTarget(User *user)
Definition: message.h:135
TargetType
Definition: message.h:96
@ TYPE_USER
Definition: message.h:98
@ TYPE_CHANNEL
Definition: message.h:101
MessageTarget::TargetType type
Definition: message.h:119
const std::string & GetName() const
Definition: message.h:158
MessageTarget(std::string *server)
Definition: message.h:144
Definition: users.h:238