ManaPlus
networkdb.cpp
Go to the documentation of this file.
1 /*
2  * The ManaPlus Client
3  * Copyright (C) 2011-2019 The ManaPlus Developers
4  * Copyright (C) 2019-2021 Andrei Karas
5  *
6  * This file is part of The ManaPlus Client.
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program. If not, see <http://www.gnu.org/licenses/>.
20  */
21 
22 #include "resources/db/networkdb.h"
23 
24 #include "configuration.h"
25 #include "logger.h"
26 
27 #include "utils/xmlutils.h"
28 
29 #include "resources/beingcommon.h"
30 
31 #include "debug.h"
32 
33 namespace
34 {
35  bool mLoaded = false;
38 } // namespace
39 
41 {
42  if (mLoaded)
43  unload();
44 
45  logger->log1("Initializing network database...");
47  loadXmlFile(paths.getStringValue("networkPatchFile"), SkipError_true);
48  loadXmlDir("networkPatchDir", loadXmlFile)
49  mLoaded = true;
50 }
51 
52 void NetworkDb::loadXmlFile(const std::string &fileName,
53  const SkipError skipError)
54 {
56  "network",
57  "inpackets",
58  "fakepacket",
59  "id",
60  "len",
61  mInPackets,
62  skipError);
63 
65  "network",
66  "inpackets",
67  "removepacket",
68  "id",
70  skipError);
71 }
72 
74 {
75  logger->log1("Unloading network database...");
76  mInPackets.clear();
77  mRemovePackets.clear();
78  mLoaded = false;
79 }
80 
82 {
83  return mInPackets;
84 }
85 
87 {
88  return mRemovePackets;
89 }
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
void loadXmlFile(const std::string &fileName, const SkipError skipError)
Definition: networkdb.cpp:52
void load()
Definition: networkdb.cpp:40
const NetworkRemovePacketInfos & getRemovePackets()
Definition: networkdb.cpp:86
const NetworkInPacketInfos & getFakePackets()
Definition: networkdb.cpp:81
void unload()
Definition: networkdb.cpp:73
NetworkInPacketInfos mInPackets
Definition: networkdb.cpp:36
NetworkRemovePacketInfos mRemovePackets
Definition: networkdb.cpp:37
std::map< int32_t, int32_t > NetworkInPacketInfos
Definition: networkdb.h:32
std::vector< int > NetworkRemovePacketInfos
Definition: networkdb.h:34
const bool SkipError_false
Definition: skiperror.h:30
const bool SkipError_true
Definition: skiperror.h:30
bool SkipError
Definition: skiperror.h:30
std::string fileName
Definition: testmain.cpp:39
void readXmlIntMap(const std::string &fileName, const std::string &rootName, const std::string &sectionName, const std::string &itemName, const std::string &attributeKeyName, const std::string &attributeValueName, std::map< int32_t, int32_t > &arr, const SkipError skipError)
Definition: xmlutils.cpp:134
void readXmlIntVector(const std::string &fileName, const std::string &rootName, const std::string &sectionName, const std::string &itemName, const std::string &attributeName, std::vector< int > &arr, const SkipError skipError)
Definition: xmlutils.cpp:30