From 0b920a390e7ffbe77575f0c29c19ac286785929b Mon Sep 17 00:00:00 2001 From: Andreas Habel Date: Fri, 14 Nov 2008 18:28:51 +0100 Subject: 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. --- src/account-server/dalstorage.cpp | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) (limited to 'src/account-server/dalstorage.cpp') 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 @@ -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); } -- cgit v1.2.3-60-g2f50