From d9b28d9fb48e8634670850729d576eaa2051561c Mon Sep 17 00:00:00 2001 From: Yohann Ferreira Date: Tue, 30 Aug 2011 20:35:51 +0200 Subject: Made the db version an official pre-requisite. It was uneasy to not miss something when updating the db. And as the db version is somewhat corresponding to a certain protocol version, adding it in the protocol file sounds relevant to me, and helps when updating it. --- src/account-server/main-account.cpp | 5 +++-- src/account-server/storage.cpp | 11 +++++++---- src/common/manaserv_protocol.h | 5 ++++- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/account-server/main-account.cpp b/src/account-server/main-account.cpp index 5520fb8e..6d46ec49 100644 --- a/src/account-server/main-account.cpp +++ b/src/account-server/main-account.cpp @@ -364,8 +364,9 @@ int main(int argc, char *argv[]) LOG_INFO("The Mana Account+Chat Server (unknown version)"); #endif LOG_INFO("Manaserv Protocol version " << ManaServ::PROTOCOL_VERSION - << ", " << "Enet version " << ENET_VERSION_MAJOR << "." - << ENET_VERSION_MINOR << "." << ENET_VERSION_PATCH); + << ", Enet version " << ENET_VERSION_MAJOR << "." + << ENET_VERSION_MINOR << "." << ENET_VERSION_PATCH + << ", Database version " << ManaServ::SUPPORTED_DB_VERSION); if (!options.verbosityChanged) options.verbosity = static_cast( diff --git a/src/account-server/storage.cpp b/src/account-server/storage.cpp index ef66c020..4f22964b 100644 --- a/src/account-server/storage.cpp +++ b/src/account-server/storage.cpp @@ -28,10 +28,12 @@ #include "chat-server/guild.h" #include "chat-server/post.h" #include "common/configuration.h" +#include "common/manaserv_protocol.h" #include "dal/dalexcept.h" #include "dal/dataproviderfactory.h" #include "utils/functors.h" #include "utils/point.h" +#include "utils/string.h" #include "utils/throwerror.h" #include "utils/xml.h" @@ -41,7 +43,6 @@ static const char *DEFAULT_ITEM_FILE = "items.xml"; // Defines the supported db version static const char *DB_VERSION_PARAMETER = "database_version"; -static const char *SUPPORTED_DB_VERSION = "15"; /* * MySQL specificities: @@ -118,12 +119,14 @@ void Storage::open() mDb->connect(); // Check database version here - std::string dbversion = getWorldStateVar(DB_VERSION_PARAMETER); - if (dbversion != SUPPORTED_DB_VERSION) + int dbversion = utils::stringToInt( + getWorldStateVar(DB_VERSION_PARAMETER)); + int supportedDbVersion = ManaServ::SUPPORTED_DB_VERSION; + if (dbversion != supportedDbVersion) { std::ostringstream errmsg; errmsg << "Database version is not supported. " - << "Needed version: '" << SUPPORTED_DB_VERSION + << "Needed version: '" << supportedDbVersion << "', current version: '" << dbversion << "'"; utils::throwError(errmsg.str()); } diff --git a/src/common/manaserv_protocol.h b/src/common/manaserv_protocol.h index 2a340b89..e1e1f885 100644 --- a/src/common/manaserv_protocol.h +++ b/src/common/manaserv_protocol.h @@ -24,7 +24,10 @@ namespace ManaServ { -enum { PROTOCOL_VERSION = 1 }; +enum { + PROTOCOL_VERSION = 1, + SUPPORTED_DB_VERSION = 15 +}; /** * Enumerated type for communicated messages: -- cgit v1.2.3-70-g09d2