ManaPlus
Functions
ClanDb Namespace Reference

Functions

void load ()
 
void unload ()
 
void loadXmlFile (const std::string &fileName, const SkipError skipError)
 
const ClanInfoget (const int clanId)
 

Detailed Description

Clan information database.

Function Documentation

◆ get()

const ClanInfo * ClanDb::get ( const int  clanId)

Definition at line 122 of file clandb.cpp.

123 {
124  std::map<int, ClanInfo *>::const_iterator i =
125  mClansInfos.find(clanId);
126 
127  if (i == mClansInfos.end())
128  {
129  i = mClansInfos.find(clanId);
130  if (i == mClansInfos.end())
131  {
132  reportAlways("ClanDb: Warning, unknown clan ID "
133  "%d requested",
134  clanId)
135  return nullptr;
136  }
137  }
138  return i->second;
139 }
#define reportAlways(...)
Definition: checkutils.h:253
std::map< int, ClanInfo * > mClansInfos
Definition: clandb.cpp:42

References anonymous_namespace{clandb.cpp}::mClansInfos, and reportAlways.

Referenced by EAthena::BeingRecv::processBeingAttrs(), and EAthena::ClanRecv::processClanInfo().

◆ load()

void ClanDb::load ( )

Definition at line 46 of file clandb.cpp.

47 {
48  if (mLoaded)
49  unload();
50 
51  logger->log1("Initializing clans database...");
53  loadXmlFile(paths.getStringValue("clansPatchFile"), SkipError_true);
54  loadXmlDir("clansPatchDir", loadXmlFile)
55 
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{clandb.cpp}::mLoaded, paths, SkipError_false, SkipError_true, and Net::unload().

Referenced by DbManager::loadDb().

◆ loadXmlFile()

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

Definition at line 59 of file clandb.cpp.

61 {
62  XML::Document doc(fileName, UseVirtFs_true, skipError);
63  XmlNodeConstPtr rootNode = doc.rootNode();
64 
65  if ((rootNode == nullptr) || !xmlNameEqual(rootNode, "clans"))
66  {
67  logger->log("Clans database: Error while loading %s!",
68  paths.getStringValue("clansFile").c_str());
69  mLoaded = true;
70  return;
71  }
72 
73  const ItemFieldInfos &addFields =
75 
76  // iterate <clan>s
77  for_each_xml_child_node(clanNode, rootNode)
78  {
79  if (xmlNameEqual(clanNode, "include"))
80  {
81  const std::string name = XML::getProperty(
82  clanNode, "name", "");
83  if (!name.empty())
84  loadXmlFile(name, skipError);
85  continue;
86  }
87  if (!xmlNameEqual(clanNode, "clan"))
88  continue;
89 
90  const int id = XML::getProperty(clanNode, "id", 0);
91  ClanInfo *clanInfo = nullptr;
92  if (mClansInfos.find(id) != mClansInfos.end())
93  {
94  reportAlways("ClanDb: Redefinition of clan ID %d", id)
95  clanInfo = mClansInfos[id];
96  }
97  if (clanInfo == nullptr)
98  clanInfo = new ClanInfo;
99 
100  clanInfo->id = id;
101  clanInfo->name = XML::langProperty(
102  // TRANSLATORS: unknown clan name
103  clanNode, "name", _("unnamed"));
104 
105  readItemStatsVector(clanInfo->stats,
106  clanNode,
107  addFields);
108 
109  mClansInfos[id] = clanInfo;
110  }
111 }
void log(const char *const log_text,...)
Definition: logger.cpp:269
#define _(s)
Definition: gettext.h:35
std::map< std::string, ItemFieldType * > ItemFieldInfos
void readItemStatsVector(std::vector< std::string > &effect, const xmlNodePtr node, const ItemFieldInfos &fields)
#define for_each_xml_child_node(var, parent)
Definition: libxml.h:161
const ItemFieldInfos & getAddFields()
std::string langProperty(const xmlNodePtr node, const char *const name, const std::string &def)
Definition: libxml.cpp:258
int getProperty(const xmlNodePtr node, const char *const name, int def)
Definition: libxml.cpp:174
int id
Definition: claninfo.h:43
std::vector< std::string > stats
Definition: claninfo.h:41
std::string name
Definition: claninfo.h:42
std::string fileName
Definition: testmain.cpp:39
const bool UseVirtFs_true
Definition: usevirtfs.h:30

References _, fileName, for_each_xml_child_node, ItemFieldDb::getAddFields(), XML::getProperty(), Configuration::getStringValue(), ClanInfo::id, XML::langProperty(), loadXmlFile(), Logger::log(), logger, anonymous_namespace{clandb.cpp}::mClansInfos, anonymous_namespace{clandb.cpp}::mLoaded, ClanInfo::name, paths, readItemStatsVector(), reportAlways, XML::Document::rootNode(), ClanInfo::stats, and UseVirtFs_true.

◆ unload()

void ClanDb::unload ( )

Definition at line 113 of file clandb.cpp.

114 {
115  logger->log1("Unloading clans database...");
117  mClansInfos.clear();
118 
119  mLoaded = false;
120 }
void delete_all(Container &c)
Definition: dtor.h:56

References delete_all(), Logger::log1(), logger, anonymous_namespace{clandb.cpp}::mClansInfos, and anonymous_namespace{clandb.cpp}::mLoaded.

Referenced by DbManager::unloadDb().