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

#include <chathandler.h>

Inheritance diagram for TmwAthena::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()

TmwAthena::ChatHandler::ChatHandler ( )

Definition at line 45 of file chathandler.cpp.

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

References chatHandler.

◆ ~ChatHandler()

TmwAthena::ChatHandler::~ChatHandler ( )
virtual

Reimplemented from Ea::ChatHandler.

Definition at line 51 of file chathandler.cpp.

52 {
53  chatHandler = nullptr;
54 }

References chatHandler.

Member Function Documentation

◆ battleTalk()

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

Implements Net::ChatHandler.

Definition at line 216 of file chathandler.cpp.

217 {
218 }

◆ channelMessage()

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

Implements Net::ChatHandler.

Definition at line 97 of file chathandler.cpp.

99 {
100  if (channel == TRADE_CHANNEL)
101  talk("\302\202" + text);
102  else if (channel == GM_CHANNEL)
103  Gm::runCommand("wgm", text);
104 }
void talk(const std::string &text) const
Definition: chathandler.cpp:56
const std::string TRADE_CHANNEL
Definition: chat.h:31
const std::string GM_CHANNEL
Definition: chat.h:30
void runCommand(const std::string &command, const std::string &params)
Definition: gmfunctions.cpp:35

References GM_CHANNEL, Gm::runCommand(), talk(), and TRADE_CHANNEL.

◆ createChatRoom()

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

Implements Net::ChatHandler.

Definition at line 209 of file chathandler.cpp.

213 {
214 }

◆ ignore()

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

Implements Net::ChatHandler.

Definition at line 191 of file chathandler.cpp.

192 {
193  createOutPacket(CMSG_IGNORE_NICK);
194  outMsg.writeString(nick, 24, "nick");
195  outMsg.writeInt8(0, "flag");
196 }
#define createOutPacket(name)
Definition: messageout.h:37

References createOutPacket.

◆ ignoreAll()

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

Implements Net::ChatHandler.

Definition at line 183 of file chathandler.cpp.

184 {
185 }

◆ joinChannel()

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

Implements Net::ChatHandler.

Definition at line 225 of file chathandler.cpp.

226 {
227 }

◆ joinChat()

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

Implements Net::ChatHandler.

Definition at line 220 of file chathandler.cpp.

222 {
223 }

◆ kickFromChatRoom()

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

Implements Net::ChatHandler.

Definition at line 255 of file chathandler.cpp.

256 {
257 }

◆ leaveChatRoom()

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

Implements Net::ChatHandler.

Definition at line 240 of file chathandler.cpp.

241 {
242 }

◆ partChannel()

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

Implements Net::ChatHandler.

Definition at line 229 of file chathandler.cpp.

230 {
231 }

◆ privateMessage()

void TmwAthena::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  outMsg.writeInt16(CAST_S16(text.length() + 28), "len");
92  outMsg.writeString(recipient, 24, "recipient nick");
93  outMsg.writeString(text, CAST_S32(text.length()), "message");
94  Ea::ChatRecv::mSentWhispers.push(recipient);
95 }
#define CAST_S16
Definition: cast.h:28
#define CAST_S32
Definition: cast.h:30
WhisperQueue mSentWhispers
Definition: chatrecv.cpp:49

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

◆ processRaw()

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

Definition at line 154 of file chathandler.cpp.

156 {
157  if (line.size() < 2)
158  return;
159 
160  const uint32_t i = parseNumber(line.substr(1));
161  switch (tolower(line[0]))
162  {
163  case 'b':
164  {
165  outMsg.writeInt8(CAST_U8(i), "raw");
166  break;
167  }
168  case 'w':
169  {
170  outMsg.writeInt16(CAST_S16(i), "raw");
171  break;
172  }
173  case 'l':
174  {
175  outMsg.writeInt32(CAST_S32(i), "raw");
176  break;
177  }
178  default:
179  break;
180  }
181 }
#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 TmwAthena::ChatHandler::requestIgnoreList ( ) const
virtual

Implements Net::ChatHandler.

Definition at line 205 of file chathandler.cpp.

206 {
207 }

◆ sendRaw()

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

Implements Net::ChatHandler.

Definition at line 114 of file chathandler.cpp.

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

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

◆ setChatRoomOptions()

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

Implements Net::ChatHandler.

Definition at line 244 of file chathandler.cpp.

248 {
249 }

◆ setChatRoomOwner()

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

Implements Net::ChatHandler.

Definition at line 251 of file chathandler.cpp.

252 {
253 }

◆ talk()

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

Implements Net::ChatHandler.

Definition at line 56 of file chathandler.cpp.

57 {
58  if (localPlayer == nullptr)
59  return;
60 
61  if (tmwServerVersion >= 0x100408)
62  {
63  createOutPacket(CMSG_CHAT_MESSAGE);
64  // Added + 1 in order to let eAthena parse admin commands correctly
65  outMsg.writeInt16(CAST_S16(text.length() + 4 + 1), "len");
66  outMsg.writeString(text, CAST_S32(text.length() + 1), "message");
67  }
68  else
69  {
70  const std::string mes = std::string(localPlayer->getName()).append(
71  " : ").append(text);
72 
73  createOutPacket(CMSG_CHAT_MESSAGE);
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 }
const std::string & getName() const
Definition: being.h:232
LocalPlayer * localPlayer
unsigned int tmwServerVersion
Definition: client.cpp:134

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

Referenced by channelMessage(), and talkPet().

◆ talkPet()

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

Implements Net::ChatHandler.

Definition at line 233 of file chathandler.cpp.

234 {
235  // here need string duplication
236  std::string action = strprintf("\302\202\303 %s", text.c_str());
237  talk(action);
238 }
std::string strprintf(const char *const format,...)

References strprintf(), and talk().

◆ talkRaw()

void TmwAthena::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 TmwAthena::ChatHandler::unIgnore ( const std::string &  nick) const
virtual

Implements Net::ChatHandler.

Definition at line 198 of file chathandler.cpp.

199 {
200  createOutPacket(CMSG_IGNORE_NICK);
201  outMsg.writeString(nick, 24, "nick");
202  outMsg.writeInt8(1, "flag");
203 }

References createOutPacket.

◆ unIgnoreAll()

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

Implements Net::ChatHandler.

Definition at line 187 of file chathandler.cpp.

188 {
189 }

◆ who()

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

Implements Net::ChatHandler.

Definition at line 106 of file chathandler.cpp.

107 {
108  if (tmwServerVersion >= 0x0e0b0b)
109  return;
110 
111  createOutPacket(CMSG_WHO_REQUEST);
112 }

References createOutPacket, and tmwServerVersion.


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