From 331d1d0989acccf5247d34561d0c962f7a64adc2 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Tue, 13 Sep 2016 19:27:47 +0300 Subject: Add basic support for networkdb. --- src/CMakeLists.txt | 2 ++ src/Makefile.am | 2 ++ src/client.cpp | 3 ++ src/defaults.cpp | 3 ++ src/resources/db/networkdb.cpp | 65 ++++++++++++++++++++++++++++++++++++++++++ src/resources/db/networkdb.h | 48 +++++++++++++++++++++++++++++++ 6 files changed, 123 insertions(+) create mode 100644 src/resources/db/networkdb.cpp create mode 100644 src/resources/db/networkdb.h (limited to 'src') diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 1bd322e14..d04f82b52 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -708,6 +708,8 @@ SET(SRCS enums/resources/notifytypes.h resources/db/monsterdb.cpp resources/db/monsterdb.h + resources/db/networkdb.cpp + resources/db/networkdb.h resources/db/npcdb.cpp resources/db/npcdb.h resources/db/npcdialogdb.cpp diff --git a/src/Makefile.am b/src/Makefile.am index b3595ec94..b88c41eb7 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1260,6 +1260,8 @@ manaplus_SOURCES += main.cpp \ resources/db/moddb.h \ resources/db/monsterdb.cpp \ resources/db/monsterdb.h \ + resources/db/networkdb.cpp \ + resources/db/networkdb.h \ resources/db/npcdb.cpp \ resources/db/npcdb.h \ resources/db/npcdialogdb.cpp \ diff --git a/src/client.cpp b/src/client.cpp index 4b6b3118f..9ac6c0df5 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -118,6 +118,7 @@ #include "resources/db/mercenarydb.h" #include "resources/db/moddb.h" #include "resources/db/monsterdb.h" +#include "resources/db/networkdb.h" #include "resources/db/npcdb.h" #include "resources/db/npcdialogdb.h" #include "resources/db/palettedb.h" @@ -626,6 +627,7 @@ void Client::gameClear() PETDB::unload(); StatusEffectDB::unload(); ModDB::unload(); + NetworkDb::unload(); if (loginHandler) loginHandler->clearWorlds(); @@ -1325,6 +1327,7 @@ int Client::gameExec() AttributesEnum::init(); // Load XML databases + NetworkDb::load(); CharDB::load(); StatDb::load(); DeadDB::load(); diff --git a/src/defaults.cpp b/src/defaults.cpp index bd4ea9224..312c3a2fe 100644 --- a/src/defaults.cpp +++ b/src/defaults.cpp @@ -627,6 +627,9 @@ DefaultsData* getPathsDefaults() AddDEF("badgesFile", "badges.xml"); AddDEF("badgesPatchFile", "badges_patch.xml"); AddDEF("badgesPatchDir", "badges.d"); + AddDEF("networkFile", "network.xml"); + AddDEF("networkPatchFile", "network_patch.xml"); + AddDEF("networkPatchDir", "network.d"); AddDEF("statFile", "stats.xml"); AddDEF("statPatchFile", "stats_patch.xml"); AddDEF("statPatchDir", "stats.d"); diff --git a/src/resources/db/networkdb.cpp b/src/resources/db/networkdb.cpp new file mode 100644 index 000000000..afab56af3 --- /dev/null +++ b/src/resources/db/networkdb.cpp @@ -0,0 +1,65 @@ +/* + * The ManaPlus Client + * Copyright (C) 2011-2016 The ManaPlus Developers + * + * This file is part of The ManaPlus Client. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "resources/db/networkdb.h" + +#include "configuration.h" + +#include "utils/xmlutils.h" + +#include "resources/beingcommon.h" + +#include "debug.h" + +namespace +{ + bool mLoaded = false; + NetworkInfos mInPackets; +} // namespace + +void NetworkDb::load() +{ + if (mLoaded) + unload(); + + loadXmlFile(paths.getStringValue("networkFile"), SkipError_false); + loadXmlFile(paths.getStringValue("networkPatchFile"), SkipError_true); + loadXmlDir("networkPatchDir", loadXmlFile); + mLoaded = true; +} + +void NetworkDb::loadXmlFile(const std::string &fileName, + const SkipError skipError) +{ + readXmlIntMap(fileName, + "network", + "inpackets", + "fakepacket", + "id", + "len", + mInPackets, + skipError); +} + +void NetworkDb::unload() +{ + mInPackets.clear(); + mLoaded = false; +} diff --git a/src/resources/db/networkdb.h b/src/resources/db/networkdb.h new file mode 100644 index 000000000..822925fa0 --- /dev/null +++ b/src/resources/db/networkdb.h @@ -0,0 +1,48 @@ +/* + * The ManaPlus Client + * Copyright (C) 2011-2016 The ManaPlus Developers + * + * This file is part of The ManaPlus Client. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef RESOURCES_DB_NETWORKDB_H +#define RESOURCES_DB_NETWORKDB_H + +#include "enums/simpletypes/skiperror.h" + +#include +#include + +typedef std::map NetworkInfos; +typedef NetworkInfos::const_iterator NetworkInfosIter; + +namespace NetworkDb +{ + /** + * Loads the chars data. + */ + void load(); + + void loadXmlFile(const std::string &fileName, + const SkipError skipError); + + /** + * Clear the chars data + */ + void unload(); +} // namespace NetworkDb + +#endif // RESOURCES_DB_NETWORKDB_H -- cgit v1.2.3-60-g2f50