Merge pull request #416 from Marcono1234/MasterServer-closing-db

Fix MasterServer not always closing database connection on exit
This commit is contained in:
Gie "Max" Vanommeslaeghe 2022-04-03 11:31:53 +02:00 committed by GitHub
commit 5e5fefb501
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -67,7 +67,7 @@ int main(int argc, char** argv) {
//Create all the objects we need to run our service:
Game::logger = SetupLogger();
if (!Game::logger) return 0;
if (!Game::logger) return EXIT_FAILURE;
Game::logger->Log("MasterServer", "Starting Master server...\n");
Game::logger->Log("MasterServer", "Version: %i.%i\n", PROJECT_VERSION_MAJOR, PROJECT_VERSION_MINOR);
@ -84,7 +84,7 @@ int main(int argc, char** argv) {
std::ifstream cdclient_fd(cdclient_path);
if (!cdclient_fd.good()) {
Game::logger->Log("WorldServer", "%s could not be opened\n", cdclient_path.c_str());
return -1;
return EXIT_FAILURE;
}
cdclient_fd.close();
@ -95,7 +95,7 @@ int main(int argc, char** argv) {
Game::logger->Log("WorldServer", "Unable to connect to CDServer SQLite Database\n");
Game::logger->Log("WorldServer", "Error: %s\n", e.errorMessage());
Game::logger->Log("WorldServer", "Error Code: %i\n", e.errorCode());
return -1;
return EXIT_FAILURE;
}
//Get CDClient initial information
@ -106,7 +106,7 @@ int main(int argc, char** argv) {
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;
return EXIT_FAILURE;
}
//Connect to the MySQL Database
@ -119,7 +119,7 @@ int main(int argc, char** argv) {
Database::Connect(mysql_host, mysql_database, mysql_username, mysql_password);
} catch (sql::SQLException& ex) {
Game::logger->Log("MasterServer", "Got an error while connecting to the database: %s\n", ex.what());
return 0;
return EXIT_FAILURE;
}
//If the first command line argument is -a or --account then make the user
@ -167,7 +167,11 @@ int main(int argc, char** argv) {
delete statement;
std::cout << "Account created successfully!\n";
return 0;
Database::Destroy();
delete Game::logger;
return EXIT_SUCCESS;
}
int maxClients = 999;
@ -267,7 +271,8 @@ int main(int argc, char** argv) {
//10m shutdown for universe kill command
if (shouldShutdown) {
if (framesSinceKillUniverseCommand >= 40000) {
std::exit(0);
//Break main loop and exit
break;
}
else
framesSinceKillUniverseCommand++;
@ -320,7 +325,7 @@ int main(int argc, char** argv) {
delete Game::server;
delete Game::logger;
return 0;
return EXIT_SUCCESS;
}
dLogger* SetupLogger() {