summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2018-02-11 01:50:51 +0300
committerAndrei Karas <akaras@inbox.ru>2018-02-11 04:28:43 +0300
commite27ab1c594b8ab927708a769c8ee3d58f51a89a3 (patch)
treeba038da1c40a368aad9f3d77d4554b99efa918cf /src
parentce34b402281f75cb1e9d214c925382fdc522455b (diff)
downloadManaVerse-e27ab1c594b8ab927708a769c8ee3d58f51a89a3.tar.gz
ManaVerse-e27ab1c594b8ab927708a769c8ee3d58f51a89a3.tar.bz2
ManaVerse-e27ab1c594b8ab927708a769c8ee3d58f51a89a3.tar.xz
ManaVerse-e27ab1c594b8ab927708a769c8ee3d58f51a89a3.zip
Add clandb support.
Diffstat (limited to 'src')
-rw-r--r--src/CMakeLists.txt3
-rw-r--r--src/Makefile.am3
-rw-r--r--src/being/localclan.h3
-rw-r--r--src/net/eathena/clanrecv.cpp14
-rw-r--r--src/resources/claninfo.h41
-rw-r--r--src/resources/db/clandb.cpp135
-rw-r--r--src/resources/db/clandb.h49
-rw-r--r--src/resources/dbmanager.cpp3
8 files changed, 251 insertions, 0 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 68eeb7eb4..e748661dd 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -636,8 +636,11 @@ SET(SRCS
resources/beingslot.h
resources/chatobject.cpp
resources/chatobject.h
+ resources/claninfo.h
resources/db/chardb.cpp
resources/db/chardb.h
+ resources/db/clandb.cpp
+ resources/db/clandb.h
resources/db/colordb.cpp
resources/db/colordb.h
resources/db/commandsdb.cpp
diff --git a/src/Makefile.am b/src/Makefile.am
index 216655796..b7d86b47d 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1412,6 +1412,8 @@ SRC = ${BASE_SRC} \
resources/db/badgesdb.h \
resources/db/chardb.cpp \
resources/db/chardb.h \
+ resources/db/clandb.cpp \
+ resources/db/clandb.h \
resources/db/colordb.cpp \
resources/db/colordb.h \
resources/db/commandsdb.cpp \
@@ -1503,6 +1505,7 @@ SRC = ${BASE_SRC} \
resources/beingslot.h \
resources/chatobject.cpp \
resources/chatobject.h \
+ resources/claninfo.h \
resources/delayedmanager.cpp \
resources/delayedmanager.h \
resources/effectdescription.h \
diff --git a/src/being/localclan.h b/src/being/localclan.h
index e8292136f..5259e997f 100644
--- a/src/being/localclan.h
+++ b/src/being/localclan.h
@@ -37,6 +37,7 @@ struct LocalClan final
name(),
masterName(),
mapName(),
+ stats(),
id(0),
onlineMembers(0),
totalMembers(0)
@@ -52,6 +53,7 @@ struct LocalClan final
name.clear();
masterName.clear();
mapName.clear();
+ stats.clear();
id = 0;
onlineMembers = 0;
totalMembers = 0;
@@ -62,6 +64,7 @@ struct LocalClan final
std::string name;
std::string masterName;
std::string mapName;
+ std::string stats;
int id;
int onlineMembers;
int totalMembers;
diff --git a/src/net/eathena/clanrecv.cpp b/src/net/eathena/clanrecv.cpp
index 1eebb1581..a46cf4f57 100644
--- a/src/net/eathena/clanrecv.cpp
+++ b/src/net/eathena/clanrecv.cpp
@@ -34,6 +34,10 @@
#include "utils/checkutils.h"
#include "utils/delete2.h"
+#include "resources/claninfo.h"
+
+#include "resources/db/clandb.h"
+
#include "debug.h"
namespace EAthena
@@ -58,6 +62,16 @@ void ClanRecv::processClanInfo(Net::MessageIn &msg)
localClan.antagonistClans.push_back(
msg.readString(24, "antagonist clan name"));
}
+ const ClanInfo *const info = ClanDb::get(localClan.id);
+ if (info == nullptr)
+ {
+ reportAlways("missing clan %d in clandb",
+ localClan.id);
+ }
+ else
+ {
+ localClan.stats = info->stats;
+ }
createTab();
}
diff --git a/src/resources/claninfo.h b/src/resources/claninfo.h
new file mode 100644
index 000000000..3e510dcbf
--- /dev/null
+++ b/src/resources/claninfo.h
@@ -0,0 +1,41 @@
+/*
+ * The ManaPlus Client
+ * Copyright (C) 2011-2018 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 <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef RESOURCES_CLANINFO_H
+#define RESOURCES_CLANINFO_H
+
+#include <string>
+
+#include "localconsts.h"
+
+struct ClanInfo final
+{
+ ClanInfo() :
+ stats(),
+ id(0)
+ { }
+
+ A_DELETE_COPY(ClanInfo)
+
+ std::string stats;
+ int id;
+};
+
+#endif // RESOURCES_CLANINFO_H
diff --git a/src/resources/db/clandb.cpp b/src/resources/db/clandb.cpp
new file mode 100644
index 000000000..ac32b4ea7
--- /dev/null
+++ b/src/resources/db/clandb.cpp
@@ -0,0 +1,135 @@
+/*
+ * The ManaPlus Client
+ * Copyright (C) 2004-2009 The Mana World Development Team
+ * Copyright (C) 2009-2010 The Mana Developers
+ * Copyright (C) 2011-2018 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 <http://www.gnu.org/licenses/>.
+ */
+
+#include "resources/db/clandb.h"
+
+#include "configuration.h"
+
+#include "resources/beingcommon.h"
+#include "resources/claninfo.h"
+
+#include "resources/db/itemfielddb.h"
+
+#include "utils/checkutils.h"
+#include "utils/dtor.h"
+#include "utils/gettext.h"
+#include "utils/itemxmlutils.h"
+
+#include "debug.h"
+
+namespace
+{
+ std::map<int, ClanInfo *> mClansInfos;
+ bool mLoaded = false;
+} // namespace
+
+void ClanDb::load()
+{
+ if (mLoaded)
+ unload();
+
+ logger->log1("Initializing clans database...");
+ loadXmlFile(paths.getStringValue("clansFile"), SkipError_false);
+ loadXmlFile(paths.getStringValue("clansPatchFile"), SkipError_true);
+ loadXmlDir("clansPatchDir", loadXmlFile);
+
+ mLoaded = true;
+}
+
+void ClanDb::loadXmlFile(const std::string &fileName,
+ const SkipError skipError)
+{
+ XML::Document doc(fileName, UseVirtFs_true, skipError);
+ XmlNodeConstPtr rootNode = doc.rootNode();
+
+ if ((rootNode == nullptr) || !xmlNameEqual(rootNode, "clans"))
+ {
+ logger->log("Clans database: Error while loading %s!",
+ paths.getStringValue("clansFile").c_str());
+ mLoaded = true;
+ return;
+ }
+
+ const ItemFieldInfos &addFields =
+ ItemFieldDb::getAddFields();
+
+ // iterate <clan>s
+ for_each_xml_child_node(clanNode, rootNode)
+ {
+ if (xmlNameEqual(clanNode, "include"))
+ {
+ const std::string name = XML::getProperty(
+ clanNode, "name", "");
+ if (!name.empty())
+ loadXmlFile(name, skipError);
+ continue;
+ }
+ if (!xmlNameEqual(clanNode, "clan"))
+ continue;
+
+ const int id = XML::getProperty(clanNode, "id", 0);
+ ClanInfo *clanInfo = nullptr;
+ if (mClansInfos.find(id) != mClansInfos.end())
+ {
+ reportAlways("ClanDb: Redefinition of clan ID %d", id);
+ clanInfo = mClansInfos[id];
+ }
+ if (clanInfo == nullptr)
+ clanInfo = new ClanInfo;
+
+ clanInfo->id = id;
+
+ readItemStatsString(clanInfo->stats,
+ clanNode,
+ addFields);
+
+ mClansInfos[id] = clanInfo;
+ }
+}
+
+void ClanDb::unload()
+{
+ logger->log1("Unloading clans database...");
+ delete_all(mClansInfos);
+ mClansInfos.clear();
+
+ mLoaded = false;
+}
+
+const ClanInfo *ClanDb::get(const int clanId)
+{
+ std::map<int, ClanInfo *>::const_iterator i =
+ mClansInfos.find(clanId);
+
+ if (i == mClansInfos.end())
+ {
+ i = mClansInfos.find(clanId);
+ if (i == mClansInfos.end())
+ {
+ reportAlways("ClanDb: Warning, unknown clan ID "
+ "%d requested",
+ clanId);
+ return nullptr;
+ }
+ }
+ return i->second;
+}
diff --git a/src/resources/db/clandb.h b/src/resources/db/clandb.h
new file mode 100644
index 000000000..ea20d5e46
--- /dev/null
+++ b/src/resources/db/clandb.h
@@ -0,0 +1,49 @@
+/*
+ * The ManaPlus Client
+ * Copyright (C) 2004-2009 The Mana World Development Team
+ * Copyright (C) 2009-2010 The Mana Developers
+ * Copyright (C) 2011-2018 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 <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef RESOURCES_DB_CLANDB_H
+#define RESOURCES_DB_CLANDB_H
+
+#include "enums/simpletypes/skiperror.h"
+
+#include "localconsts.h"
+
+#include <string>
+
+struct ClanInfo;
+
+/**
+ * Clan information database.
+ */
+namespace ClanDb
+{
+ void load();
+
+ void unload();
+
+ void loadXmlFile(const std::string &fileName,
+ const SkipError skipError);
+
+ const ClanInfo *get(const int clanId) A_WARN_UNUSED;
+} // namespace ClanDb
+
+#endif // RESOURCES_DB_CLANDB_H
diff --git a/src/resources/dbmanager.cpp b/src/resources/dbmanager.cpp
index b7997130f..350ea5fa3 100644
--- a/src/resources/dbmanager.cpp
+++ b/src/resources/dbmanager.cpp
@@ -28,6 +28,7 @@
#include "resources/db/avatardb.h"
#include "resources/db/badgesdb.h"
#include "resources/db/chardb.h"
+#include "resources/db/clandb.h"
#include "resources/db/colordb.h"
#include "resources/db/deaddb.h"
#include "resources/db/elementaldb.h"
@@ -86,6 +87,7 @@ void DbManager::loadDb()
ElementalDb::load();
SkillUnitDb::load();
HorseDB::load();
+ ClanDb::load();
}
MonsterDB::load();
AvatarDB::load();
@@ -120,6 +122,7 @@ void DbManager::unloadDb()
{
MercenaryDB::unload();
HomunculusDB::unload();
+ ClanDb::unload();
ElementalDb::unload();
SkillUnitDb::unload();
HorseDB::unload();