wavelength 1.0.0
Loading...
Searching...
No Matches
chatmsg.h
Go to the documentation of this file.
1#pragma once
2
3#include <librtmedius.h>
4
5#include "app/msgsink.h"
6#include "msg/message.h"
7#include "os/mem.h"
8
15extern int g_nChatMsgType;
16
24class ChatMsg : public Message {
25public:
36 ChatMsg(int nAccountId, int nPlayer, const char *pszText, const char *pszSender)
37 : mAccountId(nAccountId), mPlayer(nPlayer), mText(pszText), mSender(pszSender) {
38 }
39
46 void *operator new(size_t nSize) {
47 return PoolMemAlloc(static_cast<int>(nSize), "ChatMsg", 0);
48 }
49
55 void operator delete(void *pBlock) {
56 PoolMemFree(pBlock);
57 }
58
64 Message *Clone() override {
65 return new ChatMsg(*this);
66 }
67
73 int Type() override {
74 return g_nChatMsgType;
75 }
76
82 const char *GetName() const override {
83 return "ChatMsg";
84 }
85
97 static void AddHandler(int nChannel, MsgSink *pHandler);
98
108 static void RemoveSink(int nChannel);
109
123 static bool Send(int nChannel, int nRecipient, const char *pszText, int nEcho);
124
136 static void SendPrivate(int nChannel, int nAccountId, const char *pszText);
137
146 static void ClearPartialMessages();
147
160 static void
161 OnLobbyChat(int nConnection, int nType, int nSize, const rtMediusChatMessage *pMessage);
162
170 void PrintExtra(PrnStream &stream) const override;
171
173 int GetAccountId() const {
174 return mAccountId;
175 }
176
178 int GetPlayer() const {
179 return mPlayer;
180 }
181
183 const char *GetSender() const {
184 return mSender;
185 }
186
188 const char *GetText() const {
189 return mText;
190 }
191
192private:
203 static MsgSink *FindHandler(int nChannel);
204
215 static bool AllowLine();
216
217 int mAccountId;
218 int mPlayer;
219 const char *mText;
220 const char *mSender;
221};
int g_nChatMsgType
Identity that ChatMsg::Type() reports.
ChatMsg(int nAccountId, int nPlayer, const char *pszText, const char *pszSender)
Construct a line.
Definition chatmsg.h:36
static void AddHandler(int nChannel, MsgSink *pHandler)
Register the sink that receives the chat of a channel.
int Type() override
Report this message's registered identity.
Definition chatmsg.h:73
Message * Clone() override
Produce a heap copy of this message.
Definition chatmsg.h:64
static void SendPrivate(int nChannel, int nAccountId, const char *pszText)
Send a line of chat to one account only.
static void OnLobbyChat(int nConnection, int nType, int nSize, const rtMediusChatMessage *pMessage)
Deliver a line of chat from the lobby server to the sink of its channel.
int GetAccountId() const
Definition chatmsg.h:173
static void RemoveSink(int nChannel)
Forget the sink of a channel.
static void ClearPartialMessages()
Discard the lines whose remaining parts have not arrived.
void PrintExtra(PrnStream &stream) const override
Write the channel and the text.
int GetPlayer() const
Definition chatmsg.h:178
static bool Send(int nChannel, int nRecipient, const char *pszText, int nEcho)
Send a line of chat.
const char * GetSender() const
Definition chatmsg.h:183
const char * GetName() const override
Report this message's class name.
Definition chatmsg.h:82
const char * GetText() const
Definition chatmsg.h:188
Base of every event the game passes between a MsgSource and a MsgSink.
Definition message.h:40
Receiver of engine messages.
Definition msgsink.h:21
Text output stream.
Definition prnstream.h:16
void * PoolMemAlloc(int nSize, const char *pszTag, int nAlign)
Allocate a block from the pool heaps and bill it to a tag.
void PoolMemFree(void *pBlock)
Return a block PoolMemAlloc() handed out to the pool heap that owns it.