ManaPlus
Functions | Variables
TmwAthena::ChatRecv Namespace Reference

Functions

void processChat (Net::MessageIn &msg)
 
void processChatContinue (std::string chatMsg)
 
void processGmChat (Net::MessageIn &msg)
 
void processWhisper (Net::MessageIn &msg)
 
void processWhisperResponse (Net::MessageIn &msg)
 
void processWhisperContinue (const std::string &nick, std::string chatMsg)
 
void processBeingChat (Net::MessageIn &msg)
 
void processScriptMessage (Net::MessageIn &msg)
 

Variables

std::string mShopRequestName
 

Function Documentation

◆ processBeingChat()

void TmwAthena::ChatRecv::processBeingChat ( Net::MessageIn msg)

Definition at line 336 of file chatrecv.cpp.

337 {
338  if (actorManager == nullptr)
339  return;
340 
341  BLOCK_START("ChatRecv::processBeingChat")
342  const int chatMsgLength = msg.readInt16("len") - 8;
343  const BeingId beingId = msg.readBeingId("being id");
344  Being *const being = actorManager->findBeing(beingId);
345 
346  if (chatMsgLength <= 0)
347  {
348  BLOCK_END("ChatRecv::processBeingChat")
349  return;
350  }
351 
352  std::string chatMsg = msg.readRawString(chatMsgLength, "message");
353 
354  if ((being != nullptr) && being->getType() == ActorType::Player)
355  being->setTalkTime();
356 
357  const size_t pos = chatMsg.find(" : ", 0);
358  std::string sender_name = ((pos == std::string::npos)
359  ? "" : chatMsg.substr(0, pos));
360 
361  if (serverFeatures->haveIncompleteChatMessages())
362  {
363  // work around for "new" tmw server
364  if (being != nullptr)
365  sender_name = being->getName();
366  if (sender_name.empty())
367  {
368  sender_name = "?" + toString(CAST_S32(beingId));
369  const std::string name = actorManager->getSeenPlayerById(beingId);
370  if (!name.empty())
371  sender_name.append(" ").append(name);
372  }
373  }
374  else if ((being != nullptr) &&
375  sender_name != being->getName() &&
376  being->getType() == ActorType::Player)
377  {
378  if (!being->getName().empty())
379  sender_name = being->getName();
380  }
381  else
382  {
383  chatMsg.erase(0, pos + 3);
384  }
385 
386  trim(chatMsg);
387 
388  bool allow(true);
389  // We use getIgnorePlayer instead of ignoringPlayer here
390  // because ignorePlayer' side effects are triggered
391  // right below for Being::IGNORE_SPEECH_FLOAT.
392  if ((playerRelations.checkPermissionSilently(sender_name,
393  PlayerRelation::SPEECH_LOG) != 0U) &&
394  (chatWindow != nullptr))
395  {
396  allow = chatWindow->resortChatLog(
397  removeColors(sender_name).append(" : ").append(chatMsg),
402  }
403 
404  if (allow &&
405  (being != nullptr) &&
406  playerRelations.hasPermission(sender_name,
408  {
409  being->setSpeech(chatMsg);
410  }
411  BLOCK_END("ChatRecv::processBeingChat")
412 }
ActorManager * actorManager
int BeingId
Definition: beingid.h:30
#define CAST_S32
Definition: cast.h:30
ChatWindow * chatWindow
Definition: chatwindow.cpp:94
std::string getSeenPlayerById(const BeingId id) const
Definition: being.h:96
bool resortChatLog(std::string line, ChatMsgTypeT own, const std::string &channel, const IgnoreRecord ignoreRecord, const TryRemoveColors tryRemoveColors)
bool hasPermission(const Being *const being, const unsigned int flags) const
unsigned int checkPermissionSilently(const std::string &player_name, const unsigned int flags) const
const std::string GENERAL_CHANNEL
Definition: chat.h:29
if(!vert) return
const bool IgnoreRecord_false
Definition: ignorerecord.h:30
bool msg(InputEvent &event)
Definition: chat.cpp:39
static Being * findBeing(const std::string &name, const bool npc)
Definition: actions.cpp:212
bool find(const std::string &key)
std::string trim(std::string const &str)
std::string toString(T const &value)
converts any type to a string
Definition: catch.hpp:1774
Net::ServerFeatures * serverFeatures
Definition: net.cpp:101
#define BLOCK_END(name)
Definition: perfomance.h:80
#define BLOCK_START(name)
Definition: perfomance.h:79
PlayerRelationsManager playerRelations
std::string removeColors(std::string msg)
static const unsigned int SPEECH_FLOAT
static const unsigned int SPEECH_LOG
const bool TryRemoveColors_true

References actorManager, BLOCK_END, BLOCK_START, ChatMsgType::BY_OTHER, CAST_S32, chatWindow, PlayerRelationsManager::checkPermissionSilently(), ActorManager::findBeing(), GENERAL_CHANNEL, Being::getName(), ActorManager::getSeenPlayerById(), Being::getType(), PlayerRelationsManager::hasPermission(), Net::ServerFeatures::haveIncompleteChatMessages(), IgnoreRecord_false, Actions::msg(), ActorType::Player, playerRelations, removeColors(), ChatWindow::resortChatLog(), serverFeatures, Being::setSpeech(), Being::setTalkTime(), PlayerRelation::SPEECH_FLOAT, PlayerRelation::SPEECH_LOG, Catch::toString(), Catch::trim(), and TryRemoveColors_true.

◆ processChat()

void TmwAthena::ChatRecv::processChat ( Net::MessageIn msg)

Definition at line 60 of file chatrecv.cpp.

61 {
62  BLOCK_START("ChatRecv::processChat")
63  const int chatMsgLength = msg.readInt16("len") - 4;
64  if (chatMsgLength <= 0)
65  {
66  BLOCK_END("ChatRecv::processChat")
67  return;
68  }
69 
70  processChatContinue(msg.readRawString(chatMsgLength, "message"));
71 }
void processChatContinue(std::string chatMsg, const ChatMsgTypeT own)
Definition: chatrecv.cpp:279

References BLOCK_END, BLOCK_START, Actions::msg(), and EAthena::ChatRecv::processChatContinue().

◆ processChatContinue()

void TmwAthena::ChatRecv::processChatContinue ( std::string  chatMsg)

Definition at line 73 of file chatrecv.cpp.

74 {
75  const size_t pos = chatMsg.find(" : ", 0);
76 
77  bool allow(true);
78  if (chatWindow != nullptr)
79  {
80  allow = chatWindow->resortChatLog(chatMsg,
85  }
86 
87  const std::string senseStr("You sense the following: ");
88  if ((actorManager != nullptr) && (chatMsg.find(senseStr) == 0U))
89  {
91  chatMsg.substr(senseStr.size()));
92  }
93 
94  if (pos == std::string::npos &&
97  {
98  // skip motd from "new" tmw server
99  if (Ea::ChatRecv::mMotdTime == 0)
100  {
102  }
103  else if (Ea::ChatRecv::mMotdTime == cur_time ||
105  {
106  Ea::ChatRecv::mSkipping = false;
107  }
108  BLOCK_END("ChatRecv::processChat")
109  return;
110  }
111 
112  if (pos != std::string::npos)
113  chatMsg.erase(0, pos + 3);
114 
115  trim(chatMsg);
116 
117  if (localPlayer != nullptr)
118  {
119  if ((chatWindow != nullptr || Ea::ChatRecv::mShowMotd) && allow)
120  localPlayer->setSpeech(chatMsg);
121  }
122  BLOCK_END("ChatRecv::processChat")
123 }
volatile time_t cur_time
Definition: timer.cpp:58
void parseLevels(std::string levels) const
void setSpeech(const std::string &text)
Definition: being.cpp:572
LocalPlayer * localPlayer
time_t mMotdTime
Definition: chatrecv.cpp:50
bool mShowMotd
Definition: chatrecv.cpp:52
bool mSkipping
Definition: chatrecv.cpp:53

References actorManager, BLOCK_END, ChatMsgType::BY_PLAYER, chatWindow, cur_time, GENERAL_CHANNEL, IgnoreRecord_false, localPlayer, Ea::ChatRecv::mMotdTime, Ea::ChatRecv::mShowMotd, Ea::ChatRecv::mSkipping, ActorManager::parseLevels(), ChatWindow::resortChatLog(), Being::setSpeech(), Catch::trim(), and TryRemoveColors_true.

◆ processGmChat()

void TmwAthena::ChatRecv::processGmChat ( Net::MessageIn msg)

Definition at line 125 of file chatrecv.cpp.

126 {
127  BLOCK_START("ChatRecv::processChat")
128  const int chatMsgLength = msg.readInt16("len") - 4;
129  if (chatMsgLength <= 0)
130  {
131  BLOCK_END("ChatRecv::processChat")
132  return;
133  }
134 
135  if (localChatTab != nullptr &&
136  chatWindow != nullptr)
137  {
138  std::string chatMsg = msg.readRawString(chatMsgLength, "message");
139  chatWindow->addGlobalMessage(chatMsg);
140  }
141  else
142  {
143  msg.readRawString(chatMsgLength, "message");
144  }
145  BLOCK_END("ChatRecv::processChat")
146 }
ChatTab * localChatTab
Definition: chattab.cpp:62
void addGlobalMessage(const std::string &line)

References ChatWindow::addGlobalMessage(), BLOCK_END, BLOCK_START, chatWindow, localChatTab, and Actions::msg().

◆ processScriptMessage()

void TmwAthena::ChatRecv::processScriptMessage ( Net::MessageIn msg)

Definition at line 414 of file chatrecv.cpp.

415 {
416  const int sz = msg.readInt16("len") - 5;
417  msg.readUInt8("message type");
418  const std::string message = msg.readString(sz, "message");
419  localChatTab->chatLog(message,
423 }
void chatLog(std::string line, ChatMsgTypeT own, const IgnoreRecord ignoreRecord, const TryRemoveColors tryRemoveColors)
Definition: chattab.cpp:111

References ChatMsgType::BY_SERVER, ChatTab::chatLog(), IgnoreRecord_false, localChatTab, Actions::msg(), and TryRemoveColors_true.

◆ processWhisper()

void TmwAthena::ChatRecv::processWhisper ( Net::MessageIn msg)

Definition at line 148 of file chatrecv.cpp.

149 {
150  BLOCK_START("ChatRecv::processWhisper")
151  const int chatMsgLength = msg.readInt16("len") - 28;
152  std::string nick = msg.readString(24, "nick");
153 
154  if (chatMsgLength <= 0)
155  {
156  BLOCK_END("ChatRecv::processWhisper")
157  return;
158  }
159 
160  processWhisperContinue(nick, msg.readString(chatMsgLength, "message"));
161 }
void processWhisperContinue(const std::string &nick, std::string chatMsg)
Definition: chatrecv.cpp:522

References BLOCK_END, BLOCK_START, Actions::msg(), and EAthena::ChatRecv::processWhisperContinue().

◆ processWhisperContinue()

void TmwAthena::ChatRecv::processWhisperContinue ( const std::string &  nick,
std::string  chatMsg 
)

Definition at line 171 of file chatrecv.cpp.

173 {
174  // ignoring future whisper messages
175  if (chatMsg.find("\302\202G") == 0 || chatMsg.find("\302\202A") == 0)
176  {
177  BLOCK_END("ChatRecv::processWhisper")
178  return;
179  }
180  // remove first unicode space if this is may be whisper command.
181  if (chatMsg.find("\302\202!") == 0)
182  chatMsg = chatMsg.substr(2);
183 
184  if (nick != "Server")
185  {
186  if ((guildManager != nullptr) && GuildManager::getEnableGuildBot()
187  && nick == "guild" && guildManager->processGuildMessage(chatMsg))
188  {
189  BLOCK_END("ChatRecv::processWhisper")
190  return;
191  }
192 
193  if (playerRelations.hasPermission(nick, PlayerRelation::WHISPER))
194  {
195  const bool tradeBot = config.getBoolValue("tradebot");
196  const bool showMsg = !config.getBoolValue("hideShopMessages");
198  {
199  if (shopWindow != nullptr)
200  { // commands to shop from player
201  if (chatMsg.find("!selllist ") == 0)
202  {
203  if (tradeBot)
204  {
205  if (showMsg && (chatWindow != nullptr))
206  {
207  chatWindow->addWhisper(nick,
208  chatMsg,
210  }
212  }
213  }
214  else if (chatMsg.find("!buylist ") == 0)
215  {
216  if (tradeBot)
217  {
218  if (showMsg && chatWindow != nullptr)
219  {
220  chatWindow->addWhisper(nick,
221  chatMsg,
223  }
225  }
226  }
227  else if (chatMsg.find("!buyitem ") == 0)
228  {
229  if (showMsg && chatWindow != nullptr)
230  {
231  chatWindow->addWhisper(nick,
232  chatMsg,
234  }
235  if (tradeBot)
236  {
237  shopWindow->processRequest(nick, chatMsg,
239  }
240  }
241  else if (chatMsg.find("!sellitem ") == 0)
242  {
243  if (showMsg && chatWindow != nullptr)
244  {
245  chatWindow->addWhisper(nick,
246  chatMsg,
248  }
249  if (tradeBot)
250  {
251  shopWindow->processRequest(nick, chatMsg,
253  }
254  }
255  else if (chatMsg.length() > 3
256  && chatMsg.find("\302\202") == 0)
257  {
258  chatMsg = chatMsg.erase(0, 2);
259  if (mShopRequestName != nick)
260  {
262  // TRANSLATORS: message about spam player
263  _("Detected spam from: %s"),
264  nick.c_str()))
265  BLOCK_END("ChatRecv::processWhisper")
266  return;
267  }
269  if (showMsg && chatWindow != nullptr)
270  {
271  chatWindow->addWhisper(nick,
272  chatMsg,
274  }
275  if (chatMsg.find("B1") == 0 || chatMsg.find("S1") == 0)
276  ShopWindow::showList(nick, chatMsg);
277  }
278  else if (chatWindow != nullptr)
279  {
280  chatWindow->addWhisper(nick,
281  chatMsg,
283  }
284  }
285  else if (chatWindow != nullptr)
286  {
287  chatWindow->addWhisper(nick,
288  chatMsg,
290  }
291  }
292  else
293  {
294  if (chatWindow != nullptr &&
295  (showMsg ||
296  (chatMsg.find("!selllist") != 0 &&
297  chatMsg.find("!buylist") != 0)))
298  {
299  chatWindow->addWhisper(nick,
300  chatMsg,
302  }
303  }
304  }
305  }
306  else if (localChatTab != nullptr)
307  {
308  if ((gmChatTab != nullptr) && strStartWith(chatMsg, "[GM] "))
309  {
310  chatMsg = chatMsg.substr(5);
311  const size_t pos = chatMsg.find(": ", 0);
312  if (pos == std::string::npos)
313  {
314  gmChatTab->chatLog(chatMsg,
318  }
319  else
320  {
321  gmChatTab->chatLog(chatMsg.substr(0, pos),
322  chatMsg.substr(pos + 2));
323  }
324  }
325  else
326  {
327  localChatTab->chatLog(chatMsg,
331  }
332  }
333  BLOCK_END("ChatRecv::processWhisper")
334 }
#define debugMsg(str)
Definition: chattab.h:42
void addWhisper(const std::string &nick, const std::string &mes, const ChatMsgTypeT own)
bool getBoolValue(const std::string &key) const
static bool getEnableGuildBot()
Definition: guildmanager.h:56
bool processGuildMessage(const std::string &msg)
void giveList(const std::string &nick, const int mode)
Definition: shopwindow.cpp:759
static void showList(const std::string &nick, std::string data)
Definition: shopwindow.cpp:854
void processRequest(const std::string &nick, std::string data, const int mode)
Definition: shopwindow.cpp:924
Configuration config
#define _(s)
Definition: gettext.h:35
GmTab * gmChatTab
Definition: gmtab.cpp:34
GuildManager * guildManager
void processWhisper(Net::MessageIn &msg)
Definition: chatrecv.cpp:347
void clear()
Definition: playerinfo.cpp:452
std::string mShopRequestName
Definition: chatrecv.cpp:57
ShopWindow * shopWindow
Definition: shopwindow.cpp:101
std::string strprintf(const char *const format,...)
bool strStartWith(const std::string &str1, const std::string &str2)
static const unsigned int TRADE

References _, ChatWindow::addWhisper(), BLOCK_END, ShopWindow::BUY, ChatMsgType::BY_OTHER, ChatMsgType::BY_SERVER, ChatTab::chatLog(), chatWindow, config, debugMsg, Configuration::getBoolValue(), GuildManager::getEnableGuildBot(), ShopWindow::giveList(), gmChatTab, guildManager, PlayerRelationsManager::hasPermission(), IgnoreRecord_false, localChatTab, mShopRequestName, playerRelations, GuildManager::processGuildMessage(), ShopWindow::processRequest(), ShopWindow::SELL, shopWindow, ShopWindow::showList(), strprintf(), strStartWith(), PlayerRelation::TRADE, TryRemoveColors_true, and PlayerRelation::WHISPER.

◆ processWhisperResponse()

void TmwAthena::ChatRecv::processWhisperResponse ( Net::MessageIn msg)

Definition at line 163 of file chatrecv.cpp.

164 {
165  BLOCK_START("ChatRecv::processWhisperResponse")
166 
167  const uint8_t type = msg.readUInt8("response");
168  Ea::ChatRecv::processWhisperResponseContinue(msg, type);
169 }
void processWhisperResponseContinue(Net::MessageIn &msg, const uint8_t type)
Definition: chatrecv.cpp:81

References BLOCK_START, Actions::msg(), and Ea::ChatRecv::processWhisperResponseContinue().

Variable Documentation

◆ mShopRequestName

std::string TmwAthena::ChatRecv::mShopRequestName