ManaPlus
Typedefs | Functions
GroupDb Namespace Reference

Typedefs

typedef std::map< int, GroupInfo * > GroupInfos
 
typedef GroupInfos::iterator GroupInfosIter
 

Functions

void load ()
 
void unload ()
 
void loadXmlFile (const std::string &fileName, const SkipError skipError)
 
const std::string & getName (const int id)
 
const std::string & getLongName (const int id)
 
bool getShowBadge (const int id)
 
bool getHighlightName (const int id)
 
const std::string & getBadge (const int id)
 
const GroupInfogetGroup (const int id)
 
bool isAllowCommand (const ServerCommandTypeT command)
 

Typedef Documentation

◆ GroupInfos

typedef std::map<int, GroupInfo*> GroupDb::GroupInfos

Definition at line 52 of file groupdb.h.

◆ GroupInfosIter

typedef GroupInfos::iterator GroupDb::GroupInfosIter

Definition at line 53 of file groupdb.h.

Function Documentation

◆ getBadge()

const std::string & GroupDb::getBadge ( const int  id)

Definition at line 388 of file groupdb.cpp.

389 {
390  GroupInfos::const_iterator it = mGroups.find(id);
391  if (it == mGroups.end())
392  {
393  reportAlways("Unknown group id requested: %d", id)
394  return mEmptyGroup.badge;
395  }
396  return (*it).second->badge;
397 }
#define reportAlways(...)
Definition: checkutils.h:253
GroupDb::GroupInfos mGroups
Definition: groupdb.cpp:41
std::string badge
Definition: groupinfo.h:47

References GroupInfo::badge, anonymous_namespace{groupdb.cpp}::mEmptyGroup, anonymous_namespace{groupdb.cpp}::mGroups, and reportAlways.

Referenced by Being::showGmBadge().

◆ getGroup()

const GroupInfo * GroupDb::getGroup ( const int  id)

Definition at line 399 of file groupdb.cpp.

400 {
401  GroupInfos::const_iterator it = mGroups.find(id);
402  if (it == mGroups.end())
403  {
404  reportAlways("Unknown group id requested: %d", id)
405  return &mEmptyGroup;
406  }
407  return (*it).second;
408 }

References anonymous_namespace{groupdb.cpp}::mEmptyGroup, anonymous_namespace{groupdb.cpp}::mGroups, and reportAlways.

Referenced by PopupMenu::initPopup(), and isAllowCommand().

◆ getHighlightName()

bool GroupDb::getHighlightName ( const int  id)

Definition at line 377 of file groupdb.cpp.

378 {
379  GroupInfos::const_iterator it = mGroups.find(id);
380  if (it == mGroups.end())
381  {
382  reportAlways("Unknown group id requested: %d", id)
383  return mEmptyGroup.highlightName;
384  }
385  return (*it).second->highlightName;
386 }
bool highlightName
Definition: groupinfo.h:49

References GroupInfo::highlightName, anonymous_namespace{groupdb.cpp}::mEmptyGroup, anonymous_namespace{groupdb.cpp}::mGroups, and reportAlways.

Referenced by Being::setGroupId(), and OnlinePlayer::setText().

◆ getLongName()

const std::string & GroupDb::getLongName ( const int  id)

Definition at line 355 of file groupdb.cpp.

356 {
357  GroupInfos::const_iterator it = mGroups.find(id);
358  if (it == mGroups.end())
359  {
360  reportAlways("Unknown group id requested: %d", id)
361  return mEmptyGroup.longName;
362  }
363  return (*it).second->longName;
364 }
std::string longName
Definition: groupinfo.h:46

References GroupInfo::longName, anonymous_namespace{groupdb.cpp}::mEmptyGroup, anonymous_namespace{groupdb.cpp}::mGroups, and reportAlways.

Referenced by BeingPopup::show().

◆ getName()

const std::string & GroupDb::getName ( const int  id)

Definition at line 344 of file groupdb.cpp.

345 {
346  GroupInfos::const_iterator it = mGroups.find(id);
347  if (it == mGroups.end())
348  {
349  reportAlways("Unknown group id requested: %d", id)
350  return mEmptyGroup.name;
351  }
352  return (*it).second->name;
353 }
std::string name
Definition: groupinfo.h:45

References anonymous_namespace{groupdb.cpp}::mEmptyGroup, anonymous_namespace{groupdb.cpp}::mGroups, GroupInfo::name, and reportAlways.

Referenced by ItemDB::getNamesStr(), EAthena::HomunculusRecv::processHomunculusFood(), EAthena::PartyRecv::processPartyInfo(), TmwAthena::PartyRecv::processPartyInfo(), Graphics::setMainFlags(), OnlinePlayer::setText(), and StatusWindow::updateLevelLabel().

◆ getShowBadge()

bool GroupDb::getShowBadge ( const int  id)

Definition at line 366 of file groupdb.cpp.

367 {
368  GroupInfos::const_iterator it = mGroups.find(id);
369  if (it == mGroups.end())
370  {
371  reportAlways("Unknown group id requested: %d", id)
372  return mEmptyGroup.showBadge;
373  }
374  return (*it).second->showBadge;
375 }
bool showBadge
Definition: groupinfo.h:48

References anonymous_namespace{groupdb.cpp}::mEmptyGroup, anonymous_namespace{groupdb.cpp}::mGroups, reportAlways, and GroupInfo::showBadge.

Referenced by OnlinePlayer::setText(), and Being::showGmBadge().

◆ isAllowCommand()

bool GroupDb::isAllowCommand ( const ServerCommandTypeT  command)

Definition at line 410 of file groupdb.cpp.

411 {
412  if (localPlayer == nullptr)
413  return false;
414  const int groupId = localPlayer->getGroupId();
415  const GroupInfo *const group = GroupDb::getGroup(groupId);
416 
417 #ifdef TMWA_SUPPORT
418  // allow any commands for legacy if group > 0
420  localPlayer->isGM())
421  {
422  return true;
423  }
424 #endif
425  if (group->mPermissions[CAST_SIZE(ServerPermissionType::all_commands)] ==
426  Enable_true)
427  {
428  return true;
429  }
430  const ServerCommandEnable::Type enabled =
431  group->mCommands[CAST_SIZE(command)];
432  return (enabled & ServerCommandEnable::Self) != 0;
433 }
#define CAST_SIZE
Definition: cast.h:34
int getGroupId() const
Definition: being.h:1087
bool isGM() const
Definition: being.h:659
const bool Enable_true
Definition: enable.h:30
LocalPlayer * localPlayer
const GroupInfo * getGroup(const int id)
Definition: groupdb.cpp:399
ServerTypeT getNetworkType()
Definition: net.cpp:189
Enable mPermissions[static_cast< size_t >(ServerPermissionType::Max)]
Definition: groupinfo.h:44
ServerCommandEnable::Type mCommands[static_cast< size_t >(ServerCommandType::Max)]
Definition: groupinfo.h:43

References CAST_SIZE, Enable_true, getGroup(), Being::getGroupId(), Net::getNetworkType(), Being::isGM(), localPlayer, GroupInfo::mCommands, GroupInfo::mPermissions, ServerCommandEnable::Self, and ServerType::TMWATHENA.

Referenced by DialogsManager::playerDeath().

◆ load()

void GroupDb::load ( )

Definition at line 46 of file groupdb.cpp.

47 {
48  if (mLoaded)
49  unload();
50 
51  logger->log1("Initializing group database...");
52 
54  loadXmlFile(paths.getStringValue("groupsPatchFile"), SkipError_true);
55  loadXmlDir("groupsPatchDir", loadXmlFile)
56  mLoaded = true;
57 }
static void loadXmlFile(const std::string &file, const std::string &name, BadgesInfos &arr, const SkipError skipError)
Definition: badgesdb.cpp:43
#define loadXmlDir(name, function)
Definition: beingcommon.h:39
std::string getStringValue(const std::string &key) const
void log1(const char *const log_text)
Definition: logger.cpp:238
Configuration paths
Logger * logger
Definition: logger.cpp:89
void unload()
Definition: net.cpp:180
const bool SkipError_false
Definition: skiperror.h:30
const bool SkipError_true
Definition: skiperror.h:30

References Configuration::getStringValue(), loadXmlDir, loadXmlFile(), Logger::log1(), logger, anonymous_namespace{groupdb.cpp}::mLoaded, paths, SkipError_false, SkipError_true, and Net::unload().

Referenced by DbManager::loadDb().

◆ loadXmlFile()

void GroupDb::loadXmlFile ( const std::string &  fileName,
const SkipError  skipError 
)

Definition at line 256 of file groupdb.cpp.

258 {
261  skipError);
262  XmlNodeConstPtrConst rootNode = doc.rootNode();
263 
264  if (rootNode == nullptr ||
265  !xmlNameEqual(rootNode, "groups"))
266  {
267  if (skipError == SkipError_true)
268  {
269  logger->log("GroupsDb: Error while loading %s!",
270  fileName.c_str());
271  }
272  else
273  {
274  reportAlways("GroupsDb: Error while loading %s!",
275  fileName.c_str())
276  }
277  return;
278  }
279 
280  for_each_xml_child_node(node, rootNode)
281  {
282  if (xmlNameEqual(node, "include"))
283  {
284  const std::string name = XML::getProperty(node, "name", "");
285  if (!name.empty())
286  loadXmlFile(name, skipError);
287  continue;
288  }
289  if (xmlNameEqual(node, "group"))
290  {
291  const int id = XML::getProperty(node,
292  "id",
293  -1);
294  if (id < 0)
295  {
296  reportAlways("Empty id field in GroupDb")
297  continue;
298  }
299  GroupInfosIter it = mGroups.find(id);
300  GroupInfo *group = nullptr;
301  if (it != mGroups.end())
302  {
303  reportAlways("GroupDb: group with id %d already added",
304  id)
305  group = (*it).second;
306  }
307  else
308  {
309  group = new GroupInfo;
310  mGroups[id] = group;
311  }
312  group->name = XML::langProperty(node,
313  "name",
314  "");
315  group->longName = XML::langProperty(node,
316  "longName",
317  "");
318  group->badge = XML::langProperty(node,
319  "badge",
320  paths.getStringValue("gmbadge"));
321  group->showBadge = XML::getBoolProperty(node,
322  "showBadge",
323  false);
324  group->highlightName = XML::getBoolProperty(node,
325  "highlightName",
326  false);
327  loadSubNodes(node, id, group);
328  parseInherit(node, id, group);
329  }
330  }
331 }
void log(const char *const log_text,...)
Definition: logger.cpp:269
if(!vert) return
static void loadSubNodes(xmlNodePtr groupNode, const int id, GroupInfo *groupInfo)
Definition: groupdb.cpp:205
static void parseInherit(xmlNodePtr groupNode, const int id, GroupInfo *groupInfo)
Definition: groupdb.cpp:221
#define for_each_xml_child_node(var, parent)
Definition: libxml.h:161
bool find(const std::string &key)
GroupInfos::iterator GroupInfosIter
Definition: groupdb.h:53
std::string langProperty(const xmlNodePtr node, const char *const name, const std::string &def)
Definition: libxml.cpp:258
bool getBoolProperty(const xmlNodePtr node, const char *const name, const bool def)
Definition: libxml.cpp:269
int getProperty(const xmlNodePtr node, const char *const name, int def)
Definition: libxml.cpp:174
std::string fileName
Definition: testmain.cpp:39
const bool UseVirtFs_true
Definition: usevirtfs.h:30

References GroupInfo::badge, fileName, for_each_xml_child_node, XML::getBoolProperty(), XML::getProperty(), Configuration::getStringValue(), GroupInfo::highlightName, XML::langProperty(), loadSubNodes(), loadXmlFile(), Logger::log(), logger, GroupInfo::longName, anonymous_namespace{groupdb.cpp}::mGroups, GroupInfo::name, parseInherit(), paths, reportAlways, XML::Document::rootNode(), GroupInfo::showBadge, SkipError_true, and UseVirtFs_true.

◆ unload()

void GroupDb::unload ( )

Definition at line 333 of file groupdb.cpp.

334 {
335  logger->log1("Unloading group database...");
337  {
338  delete (*it).second;
339  }
340  mGroups.clear();
341  mLoaded = false;
342 }
#define FOR_EACH(type, iter, array)
Definition: foreach.h:25

References FOR_EACH, Logger::log1(), logger, anonymous_namespace{groupdb.cpp}::mGroups, and anonymous_namespace{groupdb.cpp}::mLoaded.

Referenced by DbManager::unloadDb().