From df77997b0bc3f227eff8aa1a321ff8fd887ce2df Mon Sep 17 00:00:00 2001 From: TheMatt2 Date: Mon, 17 Jan 2022 15:13:30 -0500 Subject: [PATCH] Clearer Error Message on Misconfiguration Checks if CDServer.sqlite exists before attempting to open it. Otherwise Sqlite will create an empty file only cause a crash when CDClientManager tries to Initialize. Also catches error if CDClientManager tries to initialize, in case an empty CDServer.sqlite file already exists. --- dMasterServer/MasterServer.cpp | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/dMasterServer/MasterServer.cpp b/dMasterServer/MasterServer.cpp index c90a1175..5152fe73 100644 --- a/dMasterServer/MasterServer.cpp +++ b/dMasterServer/MasterServer.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #ifdef _WIN32 #include @@ -77,9 +78,16 @@ int main(int argc, char** argv) { Game::logger->SetLogToConsole(bool(std::stoi(config.GetValue("log_to_console")))); Game::logger->SetLogDebugStatements(config.GetValue("log_debug_statements") == "1"); + //Check CDClient exists + const std::string cdclient_path = "./res/CDServer.sqlite"; + if (!std::filesystem::is_regular_file(cdclient_path)) { + Game::logger->Log("WorldServer", "%s does not exist\n", cdclient_path.c_str()); + return -1; + } + //Connect to CDClient try { - CDClientDatabase::Connect("./res/CDServer.sqlite"); + CDClientDatabase::Connect(cdclient_path); } catch (CppSQLite3Exception& e) { Game::logger->Log("WorldServer", "Unable to connect to CDServer SQLite Database\n"); Game::logger->Log("WorldServer", "Error: %s\n", e.errorMessage()); @@ -87,7 +95,16 @@ int main(int argc, char** argv) { return -1; } - CDClientManager::Instance()->Initialize(); + //Get CDClient initial information + try { + CDClientManager::Instance()->Initialize(); + } catch (CppSQLite3Exception& e) { + Game::logger->Log("WorldServer", "Failed to initialize CDServer SQLite Database\n"); + Game::logger->Log("WorldServer", "May be caused by corrupted file: %s\n", cdclient_path.c_str()); + Game::logger->Log("WorldServer", "Error: %s\n", e.errorMessage()); + Game::logger->Log("WorldServer", "Error Code: %i\n", e.errorCode()); + return -1; + } //Connect to the MySQL Database std::string mysql_host = config.GetValue("mysql_host");