ManaPlus
Public Member Functions | Static Protected Member Functions
EAthena::ChatHandler Class Reference

#include <chathandler.h>

Inheritance diagram for EAthena::ChatHandler:
Ea::ChatHandler Net::ChatHandler

Public Member Functions

 ChatHandler ()
 
 ~ChatHandler ()
 
void talk (const std::string &text) const
 
void talkRaw (const std::string &text) const
 
void privateMessage (const std::string &recipient, const std::string &text) const
 
void channelMessage (const std::string &channel, const std::string &text) const
 
void joinChannel (const std::string &channel) const
 
void who () const
 
void sendRaw (const std::string &args) const
 
void ignoreAll () const
 
void unIgnoreAll () const
 
void createChatRoom (const std::string &title, const std::string &password, const int limit, const bool isPublic) const
 
void ignore (const std::string &nick) const
 
void unIgnore (const std::string &nick) const
 
void requestIgnoreList () const
 
void battleTalk (const std::string &text) const
 
void joinChat (const ChatObject *const chat, const std::string &password) const
 
void partChannel (const std::string &channel) const
 
void talkPet (const std::string &text) const
 
void leaveChatRoom () const
 
void setChatRoomOptions (const int limit, const bool isPublic, const std::string &password, const std::string &title) const
 
void setChatRoomOwner (const std::string &nick) const
 
void kickFromChatRoom (const std::string &nick) const
 
- Public Member Functions inherited from Ea::ChatHandler
 ChatHandler ()
 
void me (const std::string &text) const
 
void clear () const
 
- Public Member Functions inherited from Net::ChatHandler
 ChatHandler ()
 

Static Protected Member Functions

static void processRaw (MessageOut &outMsg, const std::string &line)
 

Detailed Description

Definition at line 33 of file chathandler.h.

Constructor & Destructor Documentation

◆ ChatHandler()

EAthena::ChatHandler::ChatHandler ( )

Definition at line 47 of file chathandler.cpp.

47  :
49 {
50  chatHandler = this;
51 }
Net::ChatHandler * chatHandler
Definition: net.cpp:86

References chatHandler.

◆ ~ChatHandler()

EAthena::ChatHandler::~ChatHandler ( )
virtual

Reimplemented from Ea::ChatHandler.

Definition at line 53 of file chathandler.cpp.

54 {
55  chatHandler = nullptr;
56 }

References chatHandler.

Member Function Documentation

◆ battleTalk()

void EAthena::ChatHandler::battleTalk ( const std::string &  text) const
virtual

Implements Net::ChatHandler.

Definition at line 235 of file chathandler.cpp.

236 {
237  if (localPlayer == nullptr)
238  return;
239 
240  const std::string mes = std::string(localPlayer->getName()).append(
241  " : ").append(text);
242 
243  createOutPacket(CMSG_BATTLE_CHAT_MESSAGE);
244  if (packetVersion >= 20151001)
245  {
246  outMsg.writeInt16(CAST_S16(mes.length() + 4), "len");
247  outMsg.writeString(mes, CAST_S32(mes.length()), "message");
248  }
249  else
250  {
251  // Added + 1 in order to let eAthena parse admin commands correctly
252  outMsg.writeInt16(CAST_S16(mes.length() + 4 + 1), "len");
253  outMsg.writeString(mes, CAST_S32(mes.length() + 1), "message");
254  }
255 }
#define CAST_S16
Definition: cast.h:28
#define CAST_S32
Definition: cast.h:30
const std::string & getName() const
Definition: being.h:232
int packetVersion
Definition: client.cpp:125
LocalPlayer * localPlayer
#define createOutPacket(name)
Definition: messageout.h:37

References CAST_S16, CAST_S32, createOutPacket, Being::getName(), localPlayer, and packetVersion.

◆ channelMessage()

void EAthena::ChatHandler::channelMessage ( const std::string &  channel,
const std::string &  text 
) const
virtual

Implements Net::ChatHandler.

Definition at line 107 of file chathandler.cpp.

109 {
110  privateMessage(channel, text);
111 }
void privateMessage(const std::string &recipient, const std::string &text) const
Definition: chathandler.cpp:87

References privateMessage().

Referenced by joinChannel().

◆ createChatRoom()

void EAthena::ChatHandler::createChatRoom ( const std::string &  title,
const std::string &  password,
const int  limit,
const bool  isPublic 
) const
virtual

Implements Net::ChatHandler.

Definition at line 220 of file chathandler.cpp.

224 {
225  createOutPacket(CMSG_CREAYE_CHAT_ROOM);
226  outMsg.writeInt16(CAST_S16(
227  7 + 8 + 36), "len");
228  outMsg.writeInt16(CAST_S16(limit), "limit");
229  outMsg.writeInt8(CAST_S8(isPublic ? 1 : 0), "public");
230  outMsg.writeString(password, 8, "password");
231  outMsg.writeString(title, 36, "title");
232  ChatRecv::mChatRoom = title;
233 }
#define CAST_S8
Definition: cast.h:26
std::string mChatRoom
Definition: chatrecv.cpp:61

References CAST_S16, CAST_S8, createOutPacket, and EAthena::ChatRecv::mChatRoom.

◆ ignore()

void EAthena::ChatHandler::ignore ( const std::string &  nick) const
virtual

Implements Net::ChatHandler.

Definition at line 201 of file chathandler.cpp.

202 {
203  createOutPacket(CMSG_IGNORE_NICK);
204  outMsg.writeString(nick, 24, "nick");
205  outMsg.writeInt8(0, "flag");
206 }

References createOutPacket.

◆ ignoreAll()

void EAthena::ChatHandler::ignoreAll ( ) const
virtual

Implements Net::ChatHandler.

Definition at line 188 of file chathandler.cpp.

189 {
190  createOutPacket(CMSG_IGNORE_ALL);
191  outMsg.writeInt8(0, "flag");
192 }

References createOutPacket.

◆ joinChannel()

void EAthena::ChatHandler::joinChannel ( const std::string &  channel) const
virtual

Implements Net::ChatHandler.

Definition at line 268 of file chathandler.cpp.

269 {
271  {
272  createOutPacket(CMSG_CHAT_JOIN_CHANNEL);
273  outMsg.writeString(channel, 24, "channel name");
274  }
275  else
276  {
277  channelMessage(channel, "\302\202\302");
278  }
279 }
void channelMessage(const std::string &channel, const std::string &text) const
virtual bool haveJoinChannel() const =0
Net::ServerFeatures * serverFeatures
Definition: net.cpp:101

References channelMessage(), createOutPacket, Net::ServerFeatures::haveJoinChannel(), and serverFeatures.

◆ joinChat()

void EAthena::ChatHandler::joinChat ( const ChatObject *const  chat,
const std::string &  password 
) const
virtual

Implements Net::ChatHandler.

Definition at line 257 of file chathandler.cpp.

259 {
260  if (chat == nullptr)
261  return;
262 
263  createOutPacket(CMSG_CHAT_ROOM_JOIN);
264  outMsg.writeInt32(chat->chatId, "chat id");
265  outMsg.writeString(password, 8, "password");
266 }
int chatId
Definition: chatobject.h:47

References ChatObject::chatId, and createOutPacket.

◆ kickFromChatRoom()

void EAthena::ChatHandler::kickFromChatRoom ( const std::string &  nick) const
virtual

Implements Net::ChatHandler.

Definition at line 331 of file chathandler.cpp.

332 {
333  createOutPacket(CMSG_KICK_FROM_CHAT_ROOM);
334  outMsg.writeString(nick, 24, "nick");
335 }

References createOutPacket.

◆ leaveChatRoom()

void EAthena::ChatHandler::leaveChatRoom ( ) const
virtual

Implements Net::ChatHandler.

Definition at line 305 of file chathandler.cpp.

306 {
307  createOutPacket(CMSG_LEAVE_CHAT_ROOM);
308 }

References createOutPacket.

◆ partChannel()

void EAthena::ChatHandler::partChannel ( const std::string &  channel) const
virtual

Implements Net::ChatHandler.

Definition at line 281 of file chathandler.cpp.

282 {
284  {
285  createOutPacket(CMSG_CHAT_PART_CHANNEL);
286  outMsg.writeString(channel, 24, "channel name");
287  }
288 }

References createOutPacket, Net::ServerFeatures::haveJoinChannel(), and serverFeatures.

◆ privateMessage()

void EAthena::ChatHandler::privateMessage ( const std::string &  recipient,
const std::string &  text 
) const
virtual

Implements Net::ChatHandler.

Definition at line 87 of file chathandler.cpp.

89 {
90  createOutPacket(CMSG_CHAT_WHISPER);
91  if (packetVersion >= 20151001)
92  {
93  outMsg.writeInt16(CAST_S16(text.length() + 28), "len");
94  outMsg.writeString(recipient, 24, "recipient nick");
95  outMsg.writeString(text, CAST_S32(text.length()), "message");
96  }
97  else
98  {
99  outMsg.writeInt16(CAST_S16(text.length() + 28 + 1), "len");
100  outMsg.writeString(recipient, 24, "recipient nick");
101  outMsg.writeString(text, CAST_S32(text.length()), "message");
102  outMsg.writeInt8(0, "null char");
103  }
104  Ea::ChatRecv::mSentWhispers.push(recipient);
105 }
WhisperQueue mSentWhispers
Definition: chatrecv.cpp:49

References CAST_S16, CAST_S32, createOutPacket, Ea::ChatRecv::mSentWhispers, and packetVersion.

Referenced by channelMessage().

◆ processRaw()

void EAthena::ChatHandler::processRaw ( MessageOut outMsg,
const std::string &  line 
)
staticprotected

Definition at line 159 of file chathandler.cpp.

161 {
162  if (line.size() < 2)
163  return;
164 
165  const uint32_t i = parseNumber(line.substr(1));
166  switch (tolower(line[0]))
167  {
168  case 'b':
169  {
170  outMsg.writeInt8(CAST_U8(i), "raw");
171  break;
172  }
173  case 'w':
174  {
175  outMsg.writeInt16(CAST_S16(i), "raw");
176  break;
177  }
178  case 'l':
179  {
180  outMsg.writeInt32(CAST_S32(i), "raw");
181  break;
182  }
183  default:
184  break;
185  }
186 }
#define CAST_U8
Definition: cast.h:27
uint32_t parseNumber(const std::string &str)

References CAST_S16, CAST_S32, CAST_U8, and parseNumber().

Referenced by sendRaw().

◆ requestIgnoreList()

void EAthena::ChatHandler::requestIgnoreList ( ) const
virtual

Implements Net::ChatHandler.

Definition at line 215 of file chathandler.cpp.

216 {
217  createOutPacket(CMSG_REQUEST_IGNORE_LIST);
218 }

References createOutPacket.

◆ sendRaw()

void EAthena::ChatHandler::sendRaw ( const std::string &  args) const
virtual

Implements Net::ChatHandler.

Definition at line 118 of file chathandler.cpp.

119 {
120  std::string line = args;
121  std::string str;
122  MessageOut *outMsg = nullptr;
123 
124  if (line.empty())
125  return;
126 
127  size_t pos = line.find(' ');
128  if (pos != std::string::npos)
129  {
130  str = line.substr(0, pos);
131 
132  const int16_t id = CAST_S16(parseNumber(str));
133  outMsg = new MessageOut(id);
134  outMsg->writeInt16(id, "packet id");
135  line = line.substr(pos + 1);
136  pos = line.find(' ');
137  }
138  else
139  {
140  const int16_t id = CAST_S16(parseNumber(line));
141  outMsg = new MessageOut(id);
142  outMsg->writeInt16(id, "packet id");
143  delete outMsg;
144  return;
145  }
146 
147  while (pos != std::string::npos)
148  {
149  str = line.substr(0, pos);
150  processRaw(*outMsg, str);
151  line = line.substr(pos + 1);
152  pos = line.find(' ');
153  }
154  if (!line.empty())
155  processRaw(*outMsg, line);
156  delete outMsg;
157 }
static void processRaw(MessageOut &outMsg, const std::string &line)

References CAST_S16, parseNumber(), processRaw(), and Net::MessageOut::writeInt16().

◆ setChatRoomOptions()

void EAthena::ChatHandler::setChatRoomOptions ( const int  limit,
const bool  isPublic,
const std::string &  password,
const std::string &  title 
) const
virtual

Implements Net::ChatHandler.

Definition at line 310 of file chathandler.cpp.

314 {
315  createOutPacket(CMSG_SET_CHAT_ROOM_OPTIONS);
316  const int sz = CAST_S32(title.size());
317  outMsg.writeInt16(CAST_S16(15 + sz), "len");
318  outMsg.writeInt16(CAST_S16(limit), "limit");
319  outMsg.writeInt8(CAST_S8(isPublic ? 1 : 0), "type");
320  outMsg.writeString(password, 8, "password");
321  outMsg.writeString(title, sz, "title");
322 }

References CAST_S16, CAST_S32, CAST_S8, and createOutPacket.

◆ setChatRoomOwner()

void EAthena::ChatHandler::setChatRoomOwner ( const std::string &  nick) const
virtual

Implements Net::ChatHandler.

Definition at line 324 of file chathandler.cpp.

325 {
326  createOutPacket(CMSG_SET_CHAT_ROOM_OWNER);
327  outMsg.writeInt32(0, "role (unused)");
328  outMsg.writeString(nick, 24, "nick");
329 }

References createOutPacket.

◆ talk()

void EAthena::ChatHandler::talk ( const std::string &  text) const
virtual

Implements Net::ChatHandler.

Definition at line 58 of file chathandler.cpp.

59 {
60  if (localPlayer == nullptr)
61  return;
62 
63  const std::string mes = std::string(localPlayer->getName()).append(
64  " : ").append(text);
65 
66  createOutPacket(CMSG_CHAT_MESSAGE);
67  if (packetVersion >= 20151001)
68  {
69  outMsg.writeInt16(CAST_S16(mes.length() + 4), "len");
70  outMsg.writeString(mes, CAST_S32(mes.length()), "message");
71  }
72  else
73  {
74  // Added + 1 in order to let eAthena parse admin commands correctly
75  outMsg.writeInt16(CAST_S16(mes.length() + 4 + 1), "len");
76  outMsg.writeString(mes, CAST_S32(mes.length() + 1), "message");
77  }
78 }

References CAST_S16, CAST_S32, createOutPacket, Being::getName(), localPlayer, and packetVersion.

◆ talkPet()

void EAthena::ChatHandler::talkPet ( const std::string &  text) const
virtual

Implements Net::ChatHandler.

Definition at line 290 of file chathandler.cpp.

291 {
292  if (text.empty())
293  return;
294  std::string msg = text;
295  if (msg.size() > 500)
296  msg = msg.substr(0, 500);
297  const size_t sz = msg.size();
298 
299  createOutPacket(CMSG_PET_TALK);
300  outMsg.writeInt16(CAST_S16(sz + 4 + 1), "len");
301  outMsg.writeString(msg, CAST_S32(sz), "message");
302  outMsg.writeInt8(0, "zero byte");
303 }
bool msg(InputEvent &event)
Definition: chat.cpp:39

References CAST_S16, CAST_S32, createOutPacket, and Actions::msg().

◆ talkRaw()

void EAthena::ChatHandler::talkRaw ( const std::string &  text) const
virtual

Implements Net::ChatHandler.

Definition at line 80 of file chathandler.cpp.

81 {
82  createOutPacket(CMSG_CHAT_MESSAGE);
83  outMsg.writeInt16(CAST_S16(mes.length() + 4), "len");
84  outMsg.writeString(mes, CAST_S32(mes.length()), "message");
85 }

References CAST_S16, CAST_S32, and createOutPacket.

◆ unIgnore()

void EAthena::ChatHandler::unIgnore ( const std::string &  nick) const
virtual

Implements Net::ChatHandler.

Definition at line 208 of file chathandler.cpp.

209 {
210  createOutPacket(CMSG_IGNORE_NICK);
211  outMsg.writeString(nick, 24, "nick");
212  outMsg.writeInt8(1, "flag");
213 }

References createOutPacket.

◆ unIgnoreAll()

void EAthena::ChatHandler::unIgnoreAll ( ) const
virtual

Implements Net::ChatHandler.

Definition at line 194 of file chathandler.cpp.

195 {
196  createOutPacket(CMSG_IGNORE_ALL);
197  outMsg.writeInt8(1, "flag");
198 }

References createOutPacket.

◆ who()

void EAthena::ChatHandler::who ( ) const
virtual

Implements Net::ChatHandler.

Definition at line 113 of file chathandler.cpp.

114 {
115  createOutPacket(CMSG_WHO_REQUEST);
116 }

References createOutPacket.


The documentation for this class was generated from the following files: