ManaPlus
Functions
chatutils.h File Reference

(986a3bf)

#include <string>

Go to the source code of this file.

Functions

void outStringNormal (ChatTab *const tab, const std::string &str, const std::string &def)
 
void replaceVars (std::string &str)
 
std::string textToMe (const std::string &str)
 

Function Documentation

◆ outStringNormal()

void outStringNormal ( ChatTab *const  tab,
const std::string &  str,
const std::string &  def 
)

Definition at line 47 of file chatutils.cpp.

50 {
51  if (localPlayer == nullptr)
52  return;
53 
54  if (tab == nullptr)
55  {
56  chatHandler->talk(str);
57  return;
58  }
59 
60  switch (tab->getType())
61  {
62  case ChatTabType::CLAN:
63  {
64  clanHandler->chat(str);
65  break;
66  }
67  case ChatTabType::PARTY:
68  {
69  partyHandler->chat(str);
70  break;
71  }
72  case ChatTabType::GUILD:
73  {
74  const Guild *const guild = localPlayer->getGuild();
75  if (guild != nullptr)
76  {
77 #ifdef TMWA_SUPPORT
78  if (guild->getServerGuild())
79  {
81  return;
82  guildHandler->chat(str);
83  }
84  else if (guildManager != nullptr)
85  {
86  guildManager->chat(str);
87  }
88 #else // TMWA_SUPPORT
89 
90  if (guild->getServerGuild())
91  guildHandler->chat(str);
92 #endif // TMWA_SUPPORT
93  }
94  break;
95  }
97  {
98  const WhisperTab *const whisper
99  = static_cast<const WhisperTab *>(tab);
100  tab->chatLog(localPlayer->getName(), str);
101  chatHandler->privateMessage(whisper->getNick(), str);
102  break;
103  }
104  case ChatTabType::DEBUG:
105  case ChatTabType::BATTLE:
106  break;
107  default:
109  case ChatTabType::INPUT:
110  case ChatTabType::TRADE:
111  case ChatTabType::LANG:
112  case ChatTabType::GM:
114  chatHandler->talk(def);
115  break;
116  }
117 }
Net::ChatHandler * chatHandler
Definition: net.cpp:86
Net::ClanHandler * clanHandler
Definition: net.cpp:87
const Guild * getGuild(const std::string &guildName) const
Definition: being.cpp:1258
const std::string & getName() const
Definition: being.h:232
ChatTabTypeT getType() const
Definition: chattab.h:145
void chatLog(std::string line, ChatMsgTypeT own, const IgnoreRecord ignoreRecord, const TryRemoveColors tryRemoveColors)
Definition: chattab.cpp:111
void chat(const std::string &msg)
Definition: guild.h:70
virtual void talk(const std::string &text) const =0
virtual void privateMessage(const std::string &recipient, const std::string &text) const =0
virtual void chat(const std::string &text) const =0
virtual void chat(const std::string &text) const =0
virtual void chat(const std::string &text) const =0
const std::string & getNick() const
Definition: whispertab.h:37
Net::GuildHandler * guildHandler
Definition: net.cpp:92
GuildManager * guildManager
LocalPlayer * localPlayer
uint32_t guild
ServerTypeT getNetworkType()
Definition: net.cpp:189
Net::PartyHandler * partyHandler
Definition: net.cpp:94

References ChatTabType::BATTLE, ChatTabType::CHANNEL, GuildManager::chat(), Net::ClanHandler::chat(), Net::GuildHandler::chat(), Net::PartyHandler::chat(), chatHandler, ChatTab::chatLog(), ChatTabType::CLAN, clanHandler, ChatTabType::DEBUG, Being::getGuild(), Being::getName(), Net::getNetworkType(), WhisperTab::getNick(), ChatTab::getType(), ChatTabType::GM, ChatTabType::GUILD, guild, guildHandler, guildManager, ChatTabType::INPUT, ChatTabType::LANG, localPlayer, ChatTabType::PARTY, partyHandler, Net::ChatHandler::privateMessage(), Net::ChatHandler::talk(), ServerType::TMWATHENA, ChatTabType::TRADE, ChatTabType::UNKNOWN, and ChatTabType::WHISPER.

Referenced by Actions::uploadUpdate().

◆ replaceVars()

void replaceVars ( std::string &  str)

Definition at line 119 of file chatutils.cpp.

120 {
121  if ((localPlayer == nullptr) || (actorManager == nullptr))
122  return;
123 
124  if (str.find("<PLAYER>") != std::string::npos)
125  {
126  const Being *target = localPlayer->getTarget();
127  if ((target == nullptr) || target->getType() != ActorType::Player)
128  {
131  }
132  if (target != nullptr)
133  replaceAll(str, "<PLAYER>", target->getName());
134  else
135  replaceAll(str, "<PLAYER>", "");
136  }
137  if (str.find("<MONSTER>") != std::string::npos)
138  {
139  const Being *target = localPlayer->getTarget();
140  if ((target == nullptr) || target->getType() != ActorType::Monster)
141  {
144  }
145  if (target != nullptr)
146  replaceAll(str, "<MONSTER>", target->getName());
147  else
148  replaceAll(str, "<MONSTER>", "");
149  }
150  if (str.find("<PEOPLE>") != std::string::npos)
151  {
152  StringVect names;
153  std::string newStr;
155  FOR_EACH (StringVectCIter, it, names)
156  {
157  if (*it != localPlayer->getName())
158  newStr.append(*it).append(",");
159  }
160  if (!newStr.empty())
161  {
162  if (newStr[newStr.size() - 1] == ',')
163  newStr = newStr.substr(0, newStr.size() - 1);
164  replaceAll(str, "<PEOPLE>", newStr);
165  }
166  else
167  {
168  replaceAll(str, "<PEOPLE>", "");
169  }
170  }
171  if (str.find("<PARTY>") != std::string::npos)
172  {
173  StringVect names;
174  std::string newStr;
175  const Party *party = nullptr;
176  if (localPlayer->isInParty() &&
177  ((party = localPlayer->getParty()) != nullptr))
178  {
179  party->getNames(names);
180  FOR_EACH (StringVectCIter, it, names)
181  {
182  if (*it != localPlayer->getName())
183  newStr.append(*it).append(",");
184  }
185  if (!newStr.empty())
186  {
187  if (newStr[newStr.size() - 1] == ',')
188  newStr = newStr.substr(0, newStr.size() - 1);
189  replaceAll(str, "<PARTY>", newStr);
190  }
191  else
192  {
193  replaceAll(str, "<PARTY>", "");
194  }
195  }
196  else
197  {
198  replaceAll(str, "<PARTY>", "");
199  }
200  }
201 }
ActorManager * actorManager
const bool AllowSort_true
Definition: allowsort.h:30
Being * findNearestLivingBeing(const int x, const int y, int maxTileDist, const ActorTypeT type, const Being *const excluded) const
void getPlayerNames(StringVect &names, const NpcNames npcNames) const
Definition: being.h:96
Party * getParty() const
Definition: being.h:330
bool isInParty() const
Definition: being.h:321
ActorTypeT getType() const
Definition: being.h:116
Being * getTarget() const
Definition: party.h:63
#define FOR_EACH(type, iter, array)
Definition: foreach.h:25
uint32_t party
const bool NpcNames_false
Definition: npcnames.h:30
std::string & replaceAll(std::string &context, const std::string &from, const std::string &to)
StringVect::const_iterator StringVectCIter
Definition: stringvector.h:31
std::vector< std::string > StringVect
Definition: stringvector.h:29

References actorManager, AllowSort_true, ActorManager::findNearestLivingBeing(), FOR_EACH, Being::getName(), Being::getParty(), ActorManager::getPlayerNames(), LocalPlayer::getTarget(), Being::getType(), Being::isInParty(), localPlayer, ActorType::Monster, NpcNames_false, party, ActorType::Player, and replaceAll().

◆ textToMe()

std::string textToMe ( const std::string &  str)

Definition at line 203 of file chatutils.cpp.

204 {
205  return strprintf("*%s*", str.c_str());
206 }
std::string strprintf(const char *const format,...)

References strprintf().

Referenced by WhisperTab::handleCommandStr().