From b867a2171fc776759edffb335426b19efafe2e55 Mon Sep 17 00:00:00 2001 From: Aleos Date: Tue, 3 Jan 2023 16:22:30 -0500 Subject: [PATCH] Adds char_server config for clearing parties (#7523) * Adds a character server config to clear empty parties at start up. * The commented code was hidden in the source and is pretty useless unless you are digging for it. --- conf/char_athena.conf | 3 +++ src/char/char.cpp | 4 ++++ src/char/char.hpp | 1 + src/char/int_party.cpp | 14 ++++++++------ 4 files changed, 16 insertions(+), 6 deletions(-) diff --git a/conf/char_athena.conf b/conf/char_athena.conf index 5bb23fa65e..7eb58c947d 100644 --- a/conf/char_athena.conf +++ b/conf/char_athena.conf @@ -198,6 +198,9 @@ char_del_restriction: 3 // Uncomment to customize the restriction //allowed_job_flag: 3 +// Should parties that don't have any members be cleared from the party_db table at start up? +clear_parties: no + // Folder that contains the database files. db_path: db diff --git a/src/char/char.cpp b/src/char/char.cpp index 2a78b5dd7d..6fb4dd5425 100644 --- a/src/char/char.cpp +++ b/src/char/char.cpp @@ -2822,6 +2822,8 @@ void char_set_defaults(){ #else charserv_config.allowed_job_flag = 1; #endif + + charserv_config.clear_parties = 0; } /** @@ -3109,6 +3111,8 @@ bool char_config_read(const char* cfgName, bool normal){ charserv_config.mail_return_empty = config_switch(w2); } else if (strcmpi(w1, "allowed_job_flag") == 0) { charserv_config.allowed_job_flag = atoi(w2); + } else if (strcmpi(w1, "clear_parties") == 0) { + charserv_config.clear_parties = config_switch(w2); } else if (strcmpi(w1, "import") == 0) { char_config_read(w2, normal); } diff --git a/src/char/char.hpp b/src/char/char.hpp index c09545ce7e..7b4813a658 100644 --- a/src/char/char.hpp +++ b/src/char/char.hpp @@ -206,6 +206,7 @@ struct CharServ_Config { int mail_return_empty; int allowed_job_flag; + int clear_parties; }; extern struct CharServ_Config charserv_config; diff --git a/src/char/int_party.cpp b/src/char/int_party.cpp index a4ada414bb..433c72ceab 100644 --- a/src/char/int_party.cpp +++ b/src/char/int_party.cpp @@ -268,12 +268,14 @@ int inter_party_sql_init(void) exit(EXIT_FAILURE); } - /* Uncomment the following if you want to do a party_db cleanup (remove parties with no members) on startup.[Skotlex] - ShowStatus("cleaning party table...\n"); - if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` USING `%s` LEFT JOIN `%s` ON `%s`.leader_id =`%s`.account_id AND `%s`.leader_char = `%s`.char_id WHERE `%s`.account_id IS NULL", - party_db, party_db, char_db, party_db, char_db, party_db, char_db, char_db) ) - Sql_ShowDebug(sql_handle); - */ + // Remove parties with no members on startup from party_db. [Skotlex] + if (charserv_config.clear_parties) { + ShowStatus("Cleaning party table...\n"); + if (SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` USING `%s` LEFT JOIN `%s` ON `%s`.leader_id =`%s`.account_id AND `%s`.leader_char = `%s`.char_id WHERE `%s`.account_id IS NULL", + schema_config.party_db, schema_config.party_db, schema_config.char_db, schema_config.party_db, schema_config.char_db, schema_config.party_db, schema_config.char_db, schema_config.char_db)) + Sql_ShowDebug(sql_handle); + } + return 0; }