ManaPlus
Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes
GuildManager Class Reference

#include <guildmanager.h>

Public Member Functions

 GuildManager ()
 
 ~GuildManager ()
 
void chat (const std::string &msg)
 
void requestGuildInfo ()
 
void updateList ()
 
void createTab (Guild *const guild)
 
void reload ()
 
bool afterRemove ()
 
void slowLogic ()
 
bool havePower () const
 
ChatTabgetTab ()
 
bool processGuildMessage (const std::string &msg)
 

Static Public Member Functions

static void init ()
 
static void send (const std::string &msg)
 
static void getNames (StringVect &names)
 
static bool getEnableGuildBot ()
 
static void kick (const std::string &msg)
 
static void invite (const std::string &msg)
 
static void leave ()
 
static void notice (const std::string &msg)
 
static GuildcreateGuild ()
 
static void clear ()
 
static void inviteResponse (const bool response)
 

Private Member Functions

bool process (std::string msg)
 

Private Attributes

bool mGotInfo
 
bool mGotName
 
bool mSentInfoRequest
 
bool mSentNameRequest
 
bool mHavePower
 
StringVect mTempList
 
EmulateGuildTabmTab
 
bool mRequest
 
time_t mRequestTime
 
bool mGotOnlineInfo
 

Static Private Attributes

static bool mEnableGuildBot = false
 

Detailed Description

Definition at line 35 of file guildmanager.h.

Constructor & Destructor Documentation

◆ GuildManager()

GuildManager::GuildManager ( )

Definition at line 54 of file guildmanager.cpp.

54  :
55  mGotInfo(false),
56  mGotName(false),
57  mSentInfoRequest(false),
58  mSentNameRequest(false),
59  mHavePower(false),
60  mTempList(),
61  mTab(nullptr),
62  mRequest(false),
64  mGotOnlineInfo(false)
65 {
66 }
volatile time_t cur_time
Definition: timer.cpp:58
StringVect mTempList
Definition: guildmanager.h:97
bool mGotOnlineInfo
Definition: guildmanager.h:101
bool mSentNameRequest
Definition: guildmanager.h:95
bool mSentInfoRequest
Definition: guildmanager.h:94
time_t mRequestTime
Definition: guildmanager.h:100
EmulateGuildTab * mTab
Definition: guildmanager.h:98

Referenced by init().

◆ ~GuildManager()

GuildManager::~GuildManager ( )

Definition at line 68 of file guildmanager.cpp.

69 {
70  delete2(mTab)
71 }
#define delete2(var)
Definition: delete2.h:25

References delete2, and mTab.

Member Function Documentation

◆ afterRemove()

bool GuildManager::afterRemove ( )

Definition at line 519 of file guildmanager.cpp.

520 {
521  Guild *const guild = createGuild();
522  if (guild == nullptr)
523  return false;
524  guild->removeFromMembers();
525  guild->clearMembers();
526  if (localPlayer != nullptr)
527  {
530  }
532  delete2(mTab)
533 
534  if (socialWindow != nullptr)
536  if (actorManager != nullptr)
537  {
540  }
541  reload();
542  return true;
543 }
ActorManager * actorManager
void updatePlayerColors() const
void updatePlayerGuild() const
void setGuildName(const std::string &name)
Definition: being.cpp:1196
void clearGuilds()
Definition: being.cpp:1289
static Guild * createGuild()
Definition: guild.h:70
bool removeTab(Guild *const guild)
LocalPlayer * localPlayer
uint32_t guild
void notify(const unsigned int message)
SocialWindow * socialWindow

References actorManager, Being::clearGuilds(), createGuild(), delete2, guild, NotifyTypes::GUILD_LEFT, localPlayer, mTab, NotifyManager::notify(), reload(), SocialWindow::removeTab(), Being::setGuildName(), socialWindow, ActorManager::updatePlayerColors(), and ActorManager::updatePlayerGuild().

Referenced by process().

◆ chat()

void GuildManager::chat ( const std::string &  msg)

Definition at line 124 of file guildmanager.cpp.

125 {
126  if ((localPlayer == nullptr) || (mTab == nullptr))
127  return;
128 
129  chatHandler->privateMessage("guild", msg);
131 }
Net::ChatHandler * chatHandler
Definition: net.cpp:86
const std::string & getName() const
Definition: being.h:232
void chatLog(std::string line, ChatMsgTypeT own, const IgnoreRecord ignoreRecord, const TryRemoveColors tryRemoveColors)
Definition: chattab.cpp:111
virtual void privateMessage(const std::string &recipient, const std::string &text) const =0
bool msg(InputEvent &event)
Definition: chat.cpp:39

References chatHandler, ChatTab::chatLog(), Being::getName(), localPlayer, Actions::msg(), mTab, and Net::ChatHandler::privateMessage().

Referenced by EmulateGuildTab::handleInput(), Actions::outString(), and outStringNormal().

◆ clear()

void GuildManager::clear ( )
static

Definition at line 501 of file guildmanager.cpp.

502 {
503  if (socialWindow != nullptr)
504  {
505  Guild *const guild = Guild::getGuild(1);
506  if (guild != nullptr)
508  }
509 }
static Guild * getGuild(const int16_t id)
Definition: guild.cpp:374

References Guild::getGuild(), guild, SocialWindow::removeTab(), and socialWindow.

Referenced by destroyGuiWindows().

◆ createGuild()

Guild * GuildManager::createGuild ( )
static

Definition at line 244 of file guildmanager.cpp.

245 {
246  Guild *const guild = Guild::getGuild(1);
247  if (guild == nullptr)
248  return nullptr;
249 
250  guild->setServerGuild(false);
251  return guild;
252 }

References Guild::getGuild(), and guild.

Referenced by afterRemove(), getNames(), and process().

◆ createTab()

void GuildManager::createTab ( Guild *const  guild)

Definition at line 232 of file guildmanager.cpp.

233 {
234  if (mTab == nullptr)
235  {
237  if (config.getBoolValue("showChatHistory"))
238  mTab->loadFromLogFile("#Guild");
239  if (localPlayer != nullptr)
241  }
242 }
ChatWindow * chatWindow
Definition: chatwindow.cpp:94
void addGuild(Guild *const guild)
Definition: being.cpp:1237
void loadFromLogFile(const std::string &name)
Definition: chattab.cpp:510
bool getBoolValue(const std::string &key) const
Configuration config

References Being::addGuild(), chatWindow, config, Configuration::getBoolValue(), guild, ChatTab::loadFromLogFile(), localPlayer, and mTab.

Referenced by process(), and updateList().

◆ getEnableGuildBot()

static bool GuildManager::getEnableGuildBot ( )
inlinestatic

◆ getNames()

void GuildManager::getNames ( StringVect names)
static

Definition at line 133 of file guildmanager.cpp.

134 {
135  const Guild *const guild = createGuild();
136  if (guild != nullptr)
137  guild->getNames(names);
138 }

References createGuild(), and guild.

Referenced by EmulateGuildTab::getAutoCompleteList().

◆ getTab()

ChatTab * GuildManager::getTab ( )

Definition at line 545 of file guildmanager.cpp.

546 {
547  return mTab;
548 }

References mTab.

Referenced by NotifyManager::getGuildTab().

◆ havePower()

bool GuildManager::havePower ( ) const
inline

Definition at line 81 of file guildmanager.h.

82  { return mHavePower; }

References mHavePower.

Referenced by PopupMenu::showChatPopup(), PopupMenu::showPlayerPopup(), and PopupMenu::showPopup().

◆ init()

void GuildManager::init ( )
static

Definition at line 73 of file guildmanager.cpp.

74 {
75  int val = serverConfig.getValue("enableGuildBot", -1);
76  if (val == -1)
77  {
78  if (Client::isTmw())
79  val = 1;
80  else
81  val = 0;
82  serverConfig.setValue("enableGuildBot", val);
83  }
84  mEnableGuildBot = (val != 0);
85  if (mEnableGuildBot)
86  {
87  if (guildManager == nullptr)
89  else
91  }
92  else if (guildManager != nullptr)
93  {
95  }
96 }
static bool isTmw()
Definition: client.cpp:838
std::string getValue(const std::string &key, const std::string &deflt) const
void setValue(const std::string &key, const std::string &value)
Configuration serverConfig
GuildManager * guildManager

References delete2, ConfigurationObject::getValue(), guildManager, GuildManager(), Client::isTmw(), mEnableGuildBot, reload(), serverConfig, and Configuration::setValue().

Referenced by initEngines(), and Client::stateConnectServer1().

◆ invite()

void GuildManager::invite ( const std::string &  msg)
static

Definition at line 483 of file guildmanager.cpp.

484 {
485  send("!invite " + msg);
486 }
static void send(const std::string &msg)

References Actions::msg(), and send().

Referenced by EmulateGuildTab::handleCommand().

◆ inviteResponse()

void GuildManager::inviteResponse ( const bool  response)
static

Definition at line 511 of file guildmanager.cpp.

512 {
513  if (response)
514  send("yes");
515  else
516  send("no");
517 }

References send().

Referenced by SocialWindow::action().

◆ kick()

void GuildManager::kick ( const std::string &  msg)
static

Definition at line 478 of file guildmanager.cpp.

479 {
480  send("!remove " + msg);
481 }

References Actions::msg(), and send().

Referenced by EmulateGuildTab::handleCommand().

◆ leave()

void GuildManager::leave ( )
static

Definition at line 488 of file guildmanager.cpp.

489 {
490  send("!leave");
491 }

References send().

Referenced by EmulateGuildTab::handleCommand().

◆ notice()

void GuildManager::notice ( const std::string &  msg)
static

Definition at line 493 of file guildmanager.cpp.

494 {
495  if (msg.empty())
496  send("!removemotd");
497  else
498  send("!setmotd " + msg);
499 }

References Actions::msg(), and send().

Referenced by EmulateGuildTab::handleCommand().

◆ process()

bool GuildManager::process ( std::string  msg)
private

Definition at line 264 of file guildmanager.cpp.

265 {
266  if (msg.size() > 4 && msg[0] == '#' && msg[1] == '#')
267  msg = msg.substr(3);
268 
269  const bool haveNick = (msg.find(": ") != std::string::npos);
270 
271  if (!haveNick && findCutLast(msg, " is now Offline."))
272  {
273  Guild *const guild = createGuild();
274  if (guild == nullptr)
275  return false;
276  if (msg.size() < 4)
277  return false;
278  if (msg[0] == '#' && msg[1] == '#')
279  msg = msg.substr(3);
280 
281  GuildMember *const m = guild->addMember(msg);
282  if (m != nullptr)
283  m->setOnline(false);
284  guild->sort();
285  mRequest = false;
286  if (mTab != nullptr)
288  if (socialWindow != nullptr)
290  return true;
291  }
292  else if (!haveNick && findCutLast(msg, " is now Online."))
293  {
294  Guild *const guild = createGuild();
295  if (guild == nullptr)
296  return false;
297  if (msg.size() < 4)
298  return false;
299  if (msg[0] == '#' && msg[1] == '#')
300  msg = msg.substr(3);
301  GuildMember *const m = guild->addMember(msg);
302  if (m != nullptr)
303  m->setOnline(true);
304  guild->sort();
305  mRequest = false;
306  if (mTab != nullptr)
308  if (socialWindow != nullptr)
310  return true;
311  }
312  else if (findCutFirst(msg, "Welcome to the "))
313  {
314  Guild *const guild = createGuild();
315  if (guild == nullptr)
316  return false;
317 // logger->log("welcome message: %s", msg.c_str());
318  const size_t pos = msg.find("! (");
319  if (pos == std::string::npos)
320  return false;
321  msg = msg.substr(0, pos);
322  guild->setName(msg);
323  if (localPlayer != nullptr)
325  mGotName = true;
326  mSentNameRequest = false;
327  mRequest = false;
328  return true;
329  }
330  else if (findCutFirst(msg, "Player name: "))
331  {
332  Guild *const guild = createGuild();
333  if (guild == nullptr)
334  return false;
335  size_t pos = msg.find("Access Level: ");
336  if (pos == std::string::npos)
337  return false;
338 
339  msg = msg.substr(pos);
340  if (!findCutFirst(msg, "Access Level: "))
341  return false;
342 
343  pos = msg.find(", Guild:");
344  if (pos == std::string::npos)
345  return false;
346 
347  const int level = atoi(msg.substr(0, pos).c_str());
348  if (level >= 10)
349  mHavePower = true;
350  else
351  mHavePower = false;
352 
353  msg = msg.substr(pos + strlen(", Guild:"));
354  pos = msg.find(", No. Of Online Players: ");
355  if (pos == std::string::npos)
356  return false;
357 
358  msg = msg.substr(0, pos);
359 // logger->log("guild name: %s", msg.c_str());
360 
361  guild->setName(msg);
362  if (localPlayer != nullptr)
364  mGotName = true;
365  mSentNameRequest = false;
366  mRequest = false;
367  return true;
368  }
369  else if (findCutFirst(msg, "OL#"))
370  {
371 // logger->log("OL");
372  mTempList.clear();
374  if (msg.empty() || msg[msg.size() - 1] != '#')
375  updateList();
376  mRequest = false;
377  mGotOnlineInfo = true;
378  return true;
379  }
380  else if (findCutFirst(msg, "oL#"))
381  {
382 // logger->log("oL");
384  if (msg.empty() || msg[msg.size() - 1] != '#')
385  updateList();
386  mRequest = false;
387  mGotOnlineInfo = true;
388  return true;
389  }
390  else if (msg == "You are currently not in a guild. For more information "
391  "or to discuss the possibility of adding you own guild "
392  "please contact Jero.")
393  {
394  mRequest = true;
395  return true;
396  }
397  else if (findCutFirst(msg, "You have been invited to the ")
398  && findCutLast(msg, " guild chat. If you would like to accept "
399  "this invitation please reply \"yes\" and if not then \"no\" ."))
400  {
401  if (socialWindow != nullptr)
403  return true;
404  }
405  else if (!haveNick && (findCutLast(msg, " has been removed "
406  "from the Guild.") || findCutLast(msg, " has left the Guild.")))
407  {
408  Guild *const guild = createGuild();
409  if (guild == nullptr)
410  return false;
411  if (msg.size() < 4)
412  return false;
413  if (msg[0] == '#' && msg[1] == '#')
414  msg = msg.substr(3);
415 
416  if (actorManager != nullptr)
417  {
418  Being *const b = actorManager->findBeingByName(
420 
421  if (b != nullptr)
422  {
423  b->clearGuilds();
424  b->setGuildName("");
425  b->updateColors();
426  }
427  }
428 
429  guild->removeMember(msg);
430  return true;
431  }
432  else if (msg == "You have been removed from the Guild" ||
433  msg == "You have left the Guild")
434  {
435  return afterRemove();
436  }
437  Guild *const guild = createGuild();
438  if (guild == nullptr)
439  return false;
440  if (mTab == nullptr)
441  {
442  createTab(guild);
443  }
444  if (mTab != nullptr)
445  {
446  const size_t pos = msg.find(": ", 0);
447  if (pos != std::string::npos)
448  {
449  const std::string sender_name = msg.substr(0, pos);
450  if (guild->getMember(sender_name) == nullptr)
451  {
452  mTab->chatLog(msg,
456  return true;
457  }
458 
459  msg.erase(0, pos + 2);
460  if (msg.size() > 3 && msg[0] == '#' && msg[1] == '#')
461  msg.erase(0, 3);
462 
463  trim(msg);
464  mTab->chatLog(sender_name, msg);
465  }
466  else
467  {
468  mTab->chatLog(msg,
472  }
473  return true;
474  }
475  return false;
476 }
Being * findBeingByName(const std::string &name, const ActorTypeT type) const
void setOnline(const bool online)
Definition: avatar.h:87
Definition: being.h:96
void updateColors()
Definition: being.cpp:2663
void showOnline(const std::string &nick, const Online online)
Definition: chattab.cpp:547
void createTab(Guild *const guild)
bool afterRemove()
void updateGuildCounter(const int online, const int total)
void showGuildInvite(const std::string &guildName, const int guildId, const std::string &inviterName)
const bool IgnoreRecord_false
Definition: ignorerecord.h:30
std::string trim(std::string const &str)
const bool Online_false
Definition: online.h:30
const bool Online_true
Definition: online.h:30
void splitToStringVector(StringVect &tokens, const std::string &text, const char separator)
bool findCutFirst(std::string &str1, const std::string &str2)
bool findCutLast(std::string &str1, const std::string &str2)
const bool TryRemoveColors_true

References actorManager, afterRemove(), ChatMsgType::BY_SERVER, ChatTab::chatLog(), Being::clearGuilds(), createGuild(), createTab(), ActorManager::findBeingByName(), findCutFirst(), findCutLast(), guild, IgnoreRecord_false, localPlayer, mGotName, mGotOnlineInfo, mHavePower, mRequest, mSentNameRequest, Actions::msg(), mTab, mTempList, Online_false, Online_true, ActorType::Player, Being::setGuildName(), Avatar::setOnline(), SocialWindow::showGuildInvite(), ChatTab::showOnline(), socialWindow, splitToStringVector(), Catch::trim(), TryRemoveColors_true, Being::updateColors(), SocialWindow::updateGuildCounter(), and updateList().

Referenced by processGuildMessage().

◆ processGuildMessage()

bool GuildManager::processGuildMessage ( const std::string &  msg)

Definition at line 254 of file guildmanager.cpp.

255 {
256  const bool res = process(msg);
257 
258  if (!mRequest)
260 
261  return res;
262 }
bool process(std::string msg)
void requestGuildInfo()

References mRequest, Actions::msg(), process(), and requestGuildInfo().

Referenced by TmwAthena::ChatRecv::processWhisperContinue().

◆ reload()

void GuildManager::reload ( )

Definition at line 98 of file guildmanager.cpp.

99 {
100  mGotInfo = false;
101  mGotName = false;
102  mHavePower = false;
103  mRequest = false;
104  mSentNameRequest = false;
105  mSentInfoRequest = false;
106  mGotOnlineInfo = false;
107  mRequestTime = 0;
108  mTempList.clear();
109 
110  if (socialWindow != nullptr)
111  {
112  Guild *const guild = Guild::getGuild(1);
113  if ((guild != nullptr) && (socialWindow != nullptr))
115  }
116  delete2(mTab)
117 }

References delete2, Guild::getGuild(), guild, mGotInfo, mGotName, mGotOnlineInfo, mHavePower, mRequest, mRequestTime, mSentInfoRequest, mSentNameRequest, mTab, mTempList, SocialWindow::removeTab(), and socialWindow.

Referenced by afterRemove(), destroyGuiWindows(), and init().

◆ requestGuildInfo()

void GuildManager::requestGuildInfo ( )

Definition at line 140 of file guildmanager.cpp.

141 {
142  if (mRequest && mRequestTime + 15 < cur_time)
143  return;
144 
145  if (!mGotName && !mSentNameRequest)
146  {
148  return;
149  send("!info " + toString(tick_time));
150  mRequest = true;
151  mSentNameRequest = true;
153  }
154  else if (!mGotInfo && !mSentInfoRequest && !mSentNameRequest)
155  {
157  return;
158  send("!getonlineinfo " + toString(tick_time));
159  mRequest = true;
160  mSentInfoRequest = true;
162  }
163 }
static const int requestTimeout
volatile int tick_time
Definition: timer.cpp:53
std::string toString(T const &value)
converts any type to a string
Definition: catch.hpp:1774
bool limitPackets(const PacketTypeT type)
@ PACKET_WHISPER
Definition: packettype.h:41

References cur_time, PacketLimiter::limitPackets(), mGotInfo, mGotName, mRequest, mRequestTime, mSentInfoRequest, mSentNameRequest, PacketType::PACKET_WHISPER, requestTimeout, send(), tick_time, and Catch::toString().

Referenced by Game::Game(), and processGuildMessage().

◆ send()

void GuildManager::send ( const std::string &  msg)
static

◆ slowLogic()

void GuildManager::slowLogic ( )

◆ updateList()

void GuildManager::updateList ( )

Definition at line 178 of file guildmanager.cpp.

179 {
180  Guild *const guild = Guild::getGuild(1);
181  if (guild != nullptr)
182  {
183  guild->setServerGuild(false);
184  StringVectCIter it = mTempList.begin();
185  const StringVectCIter it_end = mTempList.end();
186  int i = 0;
187  while (it != it_end)
188  {
189  std::string name = *it;
190  const size_t sz = name.size();
191  if (sz > 1)
192  {
193  const int status = atoi(name.substr(sz - 1).c_str());
194 
195  name = name.substr(0, sz - 1);
196  GuildMember *const m = guild->addMember(
197  fromInt(i, BeingId), 0, name);
198  if (m != nullptr)
199  {
200  m->setOnline((status & 1) != 0);
202  if ((status & 2) != 0)
203  m->setPos(10);
204  else
205  m->setPos(0);
206  if (localPlayer != nullptr &&
207  name == localPlayer->getName())
208  {
209  mHavePower = ((status & 2) != 0);
210  m->setOnline(true);
211  }
212  }
213  }
214  ++ it;
215  i ++;
216  }
217  guild->sort();
218  createTab(guild);
219  if (actorManager != nullptr)
220  {
223  }
224  if (socialWindow != nullptr)
226  }
227  mTempList.clear();
228  mSentInfoRequest = false;
229  mGotInfo = true;
230 }
int BeingId
Definition: beingid.h:30
void setGender(const GenderT g)
Definition: avatar.h:165
void setPos(const int pos)
Definition: guild.h:50
#define fromInt(val, name)
Definition: intdefines.h:46
@ UNSPECIFIED
Definition: gender.h:33
StringVect::const_iterator StringVectCIter
Definition: stringvector.h:31

References actorManager, createTab(), fromInt, Guild::getGuild(), Being::getName(), guild, localPlayer, mGotInfo, mHavePower, mSentInfoRequest, mTempList, Avatar::setGender(), Avatar::setOnline(), GuildMember::setPos(), socialWindow, Gender::UNSPECIFIED, SocialWindow::updateGuildCounter(), ActorManager::updatePlayerColors(), and ActorManager::updatePlayerGuild().

Referenced by process().

Field Documentation

◆ mEnableGuildBot

bool GuildManager::mEnableGuildBot = false
staticprivate

Definition at line 91 of file guildmanager.h.

Referenced by getEnableGuildBot(), and init().

◆ mGotInfo

bool GuildManager::mGotInfo
private

Definition at line 92 of file guildmanager.h.

Referenced by reload(), requestGuildInfo(), and updateList().

◆ mGotName

bool GuildManager::mGotName
private

Definition at line 93 of file guildmanager.h.

Referenced by process(), reload(), requestGuildInfo(), and slowLogic().

◆ mGotOnlineInfo

bool GuildManager::mGotOnlineInfo
private

Definition at line 101 of file guildmanager.h.

Referenced by process(), reload(), and slowLogic().

◆ mHavePower

bool GuildManager::mHavePower
private

Definition at line 96 of file guildmanager.h.

Referenced by havePower(), process(), reload(), and updateList().

◆ mRequest

bool GuildManager::mRequest
private

Definition at line 99 of file guildmanager.h.

Referenced by process(), processGuildMessage(), reload(), requestGuildInfo(), and slowLogic().

◆ mRequestTime

time_t GuildManager::mRequestTime
private

Definition at line 100 of file guildmanager.h.

Referenced by reload(), requestGuildInfo(), and slowLogic().

◆ mSentInfoRequest

bool GuildManager::mSentInfoRequest
private

Definition at line 94 of file guildmanager.h.

Referenced by reload(), requestGuildInfo(), slowLogic(), and updateList().

◆ mSentNameRequest

bool GuildManager::mSentNameRequest
private

Definition at line 95 of file guildmanager.h.

Referenced by process(), reload(), and requestGuildInfo().

◆ mTab

EmulateGuildTab* GuildManager::mTab
private

Definition at line 98 of file guildmanager.h.

Referenced by afterRemove(), chat(), createTab(), getTab(), process(), reload(), and ~GuildManager().

◆ mTempList

StringVect GuildManager::mTempList
private

Definition at line 97 of file guildmanager.h.

Referenced by process(), reload(), and updateList().


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