diff --git a/src/common/Config/ConfigDef.h b/src/common/Config/ConfigDef.h index 1f37b3d0..d2e74489 100644 --- a/src/common/Config/ConfigDef.h +++ b/src/common/Config/ConfigDef.h @@ -12,6 +12,7 @@ namespace Sapphire::Common::Config { std::string serverSecret; std::string dataPath; + std::string dataVersion; uint16_t worldID; uint8_t defaultGMRank; diff --git a/src/common/Config/ConfigMgr.cpp b/src/common/Config/ConfigMgr.cpp index b940cb18..5d95e17f 100644 --- a/src/common/Config/ConfigMgr.cpp +++ b/src/common/Config/ConfigMgr.cpp @@ -62,6 +62,7 @@ bool ConfigMgr::loadGlobalConfig( Common::Config::GlobalConfig& config, const st // params config.general.dataPath = getValue< std::string >( "General", "DataPath", "C:\\SquareEnix\\FINAL FANTASY XIV - A Realm Reborn\\game\\sqpack" ); + config.general.dataVersion = getValue< std::string >( "General", "DataVersion", "2016.07.05.0000.0001" ); config.general.serverSecret = getValue< std::string >( "General", "ServerSecret", "default" ); config.general.worldID = getValue< uint16_t >( "General", "WorldID", 67 ); config.general.defaultGMRank = getValue< uint8_t >( "General", "DefaultGMRank", 255 ); diff --git a/src/world/WorldServer.cpp b/src/world/WorldServer.cpp index 416f60b6..d471de17 100644 --- a/src/world/WorldServer.cpp +++ b/src/world/WorldServer.cpp @@ -126,6 +126,28 @@ bool WorldServer::loadSettings( int32_t argc, char* argv[] ) return true; } +std::string readFileToString( const std::string& filename ) +{ + // Open the file for reading + std::ifstream file( filename ); + + // Check if the file was opened successfully + if( !file ) + { + throw std::runtime_error( "Failed to open file" ); + } + + // Read the contents of the file into a string + std::string fileContents( ( std::istreambuf_iterator< char >( file ) ), + std::istreambuf_iterator< char >() ); + + // Close the file + file.close(); + + // Return the file contents as a string + return fileContents; +} + void WorldServer::run( int32_t argc, char* argv[] ) { using namespace Sapphire; @@ -146,6 +168,23 @@ void WorldServer::run( int32_t argc, char* argv[] ) Logger::info( "Setting up generated EXD data" ); auto pExdData = std::make_shared< Data::ExdData >(); auto dataPath = m_config.global.general.dataPath; + + try + { + auto verPath = dataPath + "/../ffxivgame.ver"; + auto verString = readFileToString( verPath ); + if( verString != m_config.global.general.dataVersion ) + { + Logger::fatal( "Sqpack version {} does not match expected version {}!", verString, m_config.global.general.dataVersion ); + return; + } + } + catch ( const std::exception& e ) + { + Logger::fatal( e.what() ); + return; + } + if( !pExdData->init( dataPath ) ) { Logger::fatal( "Error setting up generated EXD data. Make sure that DataPath is set correctly in global.ini" );