ManaPlus
Functions
DeadDB Namespace Reference

Functions

void load ()
 
void loadXmlFile (const std::string &fileName, const SkipError skipError)
 
void unload ()
 
std::string getRandomString ()
 

Detailed Description

Char information database.

Function Documentation

◆ getRandomString()

std::string DeadDB::getRandomString ( )

Definition at line 103 of file deaddb.cpp.

104 {
105  const size_t sz = mMessages.size();
106  if (sz == 0U)
107  return std::string();
108  return translator->getStr(mMessages[rand() % sz]);
109 }
const std::string getStr(const std::string &str)
Definition: podict.cpp:45
std::vector< std::string > mMessages
Definition: deaddb.cpp:36
PoDict * translator
Definition: podict.cpp:28

References PoDict::getStr(), anonymous_namespace{deaddb.cpp}::mMessages, and translator.

Referenced by DialogsManager::playerDeath().

◆ load()

void DeadDB::load ( )

Loads the chars data.

Definition at line 39 of file deaddb.cpp.

40 {
41  if (mLoaded)
42  unload();
43 
44  logger->log1("Initializing dead database...");
45 
46  loadXmlFile(paths.getStringValue("deadMessagesFile"), SkipError_false);
47  loadXmlFile(paths.getStringValue("deadMessagesPatchFile"), SkipError_true);
48  loadXmlDir("deadMessagesPatchDir", loadXmlFile)
49  mLoaded = true;
50 }
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{deaddb.cpp}::mLoaded, paths, SkipError_false, SkipError_true, and Net::unload().

Referenced by DbManager::loadDb().

◆ loadXmlFile()

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

Definition at line 52 of file deaddb.cpp.

54 {
57  skipError);
58  XmlNodeConstPtrConst root = doc->rootNode();
59 
60  if ((root == nullptr) || !xmlNameEqual(root, "messages"))
61  {
62  logger->log("DeadDB: Failed to parse %s.",
63  paths.getStringValue("deadMessagesFile").c_str());
64  delete doc;
65  return;
66  }
67 
68  for_each_xml_child_node(node, root)
69  {
70  if (xmlNameEqual(node, "include"))
71  {
72  const std::string name = XML::getProperty(node, "name", "");
73  if (!name.empty())
74  loadXmlFile(name, skipError);
75  continue;
76  }
77  else if (xmlNameEqual(node, "message"))
78  {
79  XmlChar *const data = reinterpret_cast<XmlChar*>(
80  XmlNodeGetContent(node));
81  if (data == nullptr)
82  continue;
83  if (*data == 0)
84  {
85  XmlFree(data);
86  continue;
87  }
88  mMessages.push_back(data);
89  XmlFree(data);
90  }
91  }
92 
93  delete doc;
94 }
void log(const char *const log_text,...)
Definition: logger.cpp:269
xmlNodePtr rootNode()
Definition: libxml.cpp:169
#define for_each_xml_child_node(var, parent)
Definition: libxml.h:161
uint32_t data
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 data, fileName, for_each_xml_child_node, XML::getProperty(), Configuration::getStringValue(), loadXmlFile(), Logger::log(), logger, anonymous_namespace{deaddb.cpp}::mMessages, paths, XML::Document::rootNode(), and UseVirtFs_true.

◆ unload()

void DeadDB::unload ( )

Clear the chars data

Definition at line 96 of file deaddb.cpp.

97 {
98  logger->log1("Unloading dead database...");
99  mMessages.clear();
100  mLoaded = false;
101 }

References Logger::log1(), logger, anonymous_namespace{deaddb.cpp}::mLoaded, and anonymous_namespace{deaddb.cpp}::mMessages.

Referenced by DbManager::unloadDb().