diff options
| author | Andreas Habel <mail@exceptionfault.de> | 2008-11-05 11:40:43 +0000 |
|---|---|---|
| committer | Andreas Habel <mail@exceptionfault.de> | 2008-11-05 11:40:43 +0000 |
| commit | 94bf187c196769b87fbbfa9a9c083f94def82ccf (patch) | |
| tree | cd18513307b2b230ae73e177f6286d40e6e52f3d /src/account-server/dalstorage.cpp | |
| parent | bdf512bbe314e301b55ed52b1628415fa55cebe5 (diff) | |
Added version information to item database. Gameserver reports its local version to account server during registration and gets notified if the version is up-to-date or outdated to prevent inconsistencies.
Diffstat (limited to 'src/account-server/dalstorage.cpp')
| -rw-r--r-- | src/account-server/dalstorage.cpp | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/src/account-server/dalstorage.cpp b/src/account-server/dalstorage.cpp index 5d3f957..a928d1b 100644 --- a/src/account-server/dalstorage.cpp +++ b/src/account-server/dalstorage.cpp @@ -36,6 +36,11 @@ #include "dal/dataproviderfactory.h" #include "utils/functors.h" #include "utils/logger.h" +#include "utils/xml.hpp" + +// TODO: make data/items.xml a constant or read it from config file +#define DEFAULT_ITEM_FILE "data/items.xml" + /** * Constructor. @@ -1440,3 +1445,51 @@ void DALStorage::deletePost(Letter* letter) LOG_ERROR("(DALStorage::deletePost) SQL query failure: " << e.what()); } } + +unsigned int DALStorage::getItemDatabaseVersion(void) +{ + int version; + + // TODO: make data/items.xml a constant or read it from config file + xmlDocPtr doc = xmlReadFile(DEFAULT_ITEM_FILE, NULL, 0); + if (!doc) + { + LOG_ERROR("Item Manager: Error while parsing item database (items.xml)!"); + return 0; + } + + xmlNodePtr node = xmlDocGetRootElement(doc); + if (!node || !xmlStrEqual(node->name, BAD_CAST "items")) + { + LOG_ERROR("Item Manager:(items.xml) is not a valid database file!"); + xmlFreeDoc(doc); + return 0; + } + + for (node = node->xmlChildrenNode; node != NULL; node = node->next) + { + // Try to load the version of the item database. The version is defined + // as subversion tag embedded as XML attribute. So every modification + // to the items.xml file will increase the revision automatically. + if (xmlStrEqual(node->name, BAD_CAST "version")) + { + std::string revision = XML::getProperty(node, "revision", std::string()); + size_t found = revision.find("$Revision: "); + + if (found == std::string::npos) + { + LOG_ERROR("Itemdatabase has wrong version format string!"); + xmlFreeDoc(doc); + return 0; + } + // position 11 is the first numeric character in the SVN tag + version = atoi(revision.substr(11).c_str()); + + LOG_INFO("Loading item database version " << version); + xmlFreeDoc(doc); + return version; + } + } + xmlFreeDoc(doc); + return 0; +} |
