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.
This commit is contained in:
TheMatt2 2022-01-17 15:13:30 -05:00
parent 7dd7fdaf71
commit df77997b0b

View File

@ -5,6 +5,7 @@
#include <map>
#include <string>
#include <thread>
#include <filesystem>
#ifdef _WIN32
#include <bcrypt/BCrypt.hpp>
@ -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");