summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Habel <mail@exceptionfault.de>2008-11-14 18:28:51 +0100
committerAndreas Habel <mail@exceptionfault.de>2008-11-14 18:28:51 +0100
commit0b920a390e7ffbe77575f0c29c19ac286785929b (patch)
tree5ecce4186e20267e239a6af8d4037b2c29bf0310
parentb5ef81d1bed0caa6fd71d63c9d6ae06e5fcd0d5e (diff)
downloadmanaserv-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.
-rw-r--r--src/account-server/dalstorage.cpp31
-rw-r--r--src/game-server/itemmanager.cpp10
-rw-r--r--src/sql/mysql/createTables.sql4
-rw-r--r--src/sql/sqlite/createTables.sql5
-rw-r--r--src/sql/sqlite/tmw.dbbin51200 -> 51200 bytes
5 files changed, 26 insertions, 24 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);
}
diff --git a/src/game-server/itemmanager.cpp b/src/game-server/itemmanager.cpp
index a86a01ed..3fbd13e0 100644
--- a/src/game-server/itemmanager.cpp
+++ b/src/game-server/itemmanager.cpp
@@ -87,15 +87,7 @@ void ItemManager::reload()
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!");
- continue;
- }
- // position 11 is the first numeric character in the SVN tag
- itemDatabaseVersion = atoi(revision.substr(11).c_str());
+ itemDatabaseVersion = atoi(revision.c_str());
LOG_INFO("Loading item database version " << itemDatabaseVersion);
continue;
diff --git a/src/sql/mysql/createTables.sql b/src/sql/mysql/createTables.sql
index ba0cb251..79510792 100644
--- a/src/sql/mysql/createTables.sql
+++ b/src/sql/mysql/createTables.sql
@@ -156,6 +156,10 @@ CREATE TABLE IF NOT EXISTS `tmw_world_states` (
) ENGINE=InnoDB
DEFAULT CHARSET=utf8;
+INSERT INTO tmw_world_states VALUES('accountserver_startup',NULL,NULL,1226042339);
+INSERT INTO tmw_world_states VALUES('accountserver_version',NULL,NULL,1226042339);
+INSERT INTO tmw_world_states VALUES('database_version', NULL,'1', 1226042339);
+
--
-- table: `tmw_guilds`
--
diff --git a/src/sql/sqlite/createTables.sql b/src/sql/sqlite/createTables.sql
index 253750a8..d22ba99b 100644
--- a/src/sql/sqlite/createTables.sql
+++ b/src/sql/sqlite/createTables.sql
@@ -140,8 +140,9 @@ CREATE TABLE tmw_world_states
moddate INTEGER NOT NULL
);
-INSERT INTO "tmw_world_states" VALUES('accountserver_startup',NULL,NULL,1221633910);
-INSERT INTO "tmw_world_states" VALUES('accountserver_version',NULL,NULL,1221633910);
+INSERT INTO tmw_world_states VALUES('accountserver_startup',NULL,NULL,1226042339);
+INSERT INTO tmw_world_states VALUES('accountserver_version',NULL,NULL,1226042339);
+INSERT INTO tmw_world_states VALUES('database_version', NULL,'1', 1226042339);
CREATE TABLE tmw_auctions
(
diff --git a/src/sql/sqlite/tmw.db b/src/sql/sqlite/tmw.db
index 93ae76d5..6e2da247 100644
--- a/src/sql/sqlite/tmw.db
+++ b/src/sql/sqlite/tmw.db
Binary files differ