diff options
author | Andreas Habel <mail@exceptionfault.de> | 2008-11-14 18:28:51 +0100 |
---|---|---|
committer | Andreas Habel <mail@exceptionfault.de> | 2008-11-14 18:28:51 +0100 |
commit | 0b920a390e7ffbe77575f0c29c19ac286785929b (patch) | |
tree | 5ecce4186e20267e239a6af8d4037b2c29bf0310 /src/account-server/dalstorage.cpp | |
parent | b5ef81d1bed0caa6fd71d63c9d6ae06e5fcd0d5e (diff) | |
download | manaserv-0b920a390e7ffbe77575f0c29c19ac286785929b.tar.gz manaserv-0b920a390e7ffbe77575f0c29c19ac286785929b.tar.bz2 manaserv-0b920a390e7ffbe77575f0c29c19ac286785929b.tar.xz manaserv-0b920a390e7ffbe77575f0c29c19ac286785929b.zip |
Added check for database version on startup of Accountserver.
The provided CreateTable.sql scripts store their versions inline of a database table. The account server checks this version number with its known
compatible version. If the numbers don't match, the account server raises an error and shuts down.
Diffstat (limited to 'src/account-server/dalstorage.cpp')
-rw-r--r-- | src/account-server/dalstorage.cpp | 31 |
1 files changed, 18 insertions, 13 deletions
diff --git a/src/account-server/dalstorage.cpp b/src/account-server/dalstorage.cpp index b0a02c4e..940f0ff7 100644 --- a/src/account-server/dalstorage.cpp +++ b/src/account-server/dalstorage.cpp @@ -17,7 +17,7 @@ * with The Mana World; if not, write to the Free Software Foundation, Inc., * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * - * $Id$ + * $Id: dalstorage.cpp 4924 2008-11-05 16:36:36Z Exceptionfault $ */ #include <cassert> @@ -41,6 +41,11 @@ // TODO: make data/items.xml a constant or read it from config file #define DEFAULT_ITEM_FILE "data/items.xml" +// defines the supported db version +#define DB_VERSION_PARAMETER "database_version" +#define SUPPORTED_DB_VERSION "1" + + /** * Constructor. @@ -87,7 +92,17 @@ void DALStorage::open() // open a connection to the database. mDb->connect(); - //TODO: check database version here + //check database version here + std::string dbversion = getWorldStateVar(DB_VERSION_PARAMETER); + if (dbversion != SUPPORTED_DB_VERSION) + { + std::ostringstream errmsg; + errmsg << "Database version is not supported. " << + "Needed version: " << SUPPORTED_DB_VERSION << ", current version: " << + dbversion; + LOG_ERROR(errmsg.str()); + throw errmsg.str(); + } // synchronize base data from xml files SyncDatabase(); @@ -1484,17 +1499,7 @@ void DALStorage::SyncDatabase(void) 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); - continue; - } - - // position 11 is the first numeric character in the SVN tag - mItemDbVersion = atoi(revision.substr(11).c_str()); + mItemDbVersion = atoi(revision.c_str()); LOG_INFO("Loading item database version " << mItemDbVersion); } |