diff --git a/common/database.cpp b/common/database.cpp index 0e5ed3ae5..38c286620 100644 --- a/common/database.cpp +++ b/common/database.cpp @@ -2065,10 +2065,11 @@ uint32 Database::GetGuildIDByCharID(uint32 character_id) return atoi(row[0]); } +/** + * @param log_settings + */ void Database::LoadLogSettings(EQEmuLogSys::LogSettings *log_settings) { - // log_settings previously initialized to '0' by EQEmuLogSys::LoadLogSettingsDefaults() - std::string query = "SELECT " "log_category_id, " @@ -2080,11 +2081,10 @@ void Database::LoadLogSettings(EQEmuLogSys::LogSettings *log_settings) "logsys_categories " "ORDER BY log_category_id"; - auto results = QueryDatabase(query); + auto results = QueryDatabase(query); + int log_category_id = 0; - int log_category_id = 0; - - int categories_in_database[1000] = {}; + int *categories_in_database = new int[1000]; for (auto row = results.begin(); row != results.end(); ++row) { log_category_id = atoi(row[0]); @@ -2124,15 +2124,14 @@ void Database::LoadLogSettings(EQEmuLogSys::LogSettings *log_settings) * Auto inject categories that don't exist in the database... */ for (int log_index = Logs::AA; log_index != Logs::MaxCategoryID; log_index++) { - if (!categories_in_database[log_index]) { + if (categories_in_database[log_index] != 1) { - Log(Logs::General, - Logs::Status, - "New Log Category '%s' doesn't exist... Automatically adding to `logsys_categories` table...", + LogInfo( + "New Log Category [{0}] doesn't exist... Automatically adding to [logsys_categories] table...", Logs::LogCategoryName[log_index] ); - std::string inject_query = StringFormat( + auto inject_query = fmt::format( "INSERT INTO logsys_categories " "(log_category_id, " "log_category_description, " @@ -2140,17 +2139,19 @@ void Database::LoadLogSettings(EQEmuLogSys::LogSettings *log_settings) "log_to_file, " "log_to_gmsay) " "VALUES " - "(%i, '%s', %i, %i, %i)", + "({0}, '{1}', {2}, {3}, {4})", log_index, - EscapeString(Logs::LogCategoryName[log_index]).c_str(), - log_settings[log_category_id].log_to_console, - log_settings[log_category_id].log_to_file, - log_settings[log_category_id].log_to_gmsay + EscapeString(Logs::LogCategoryName[log_index]), + std::to_string(log_settings[log_index].log_to_console), + std::to_string(log_settings[log_index].log_to_file), + std::to_string(log_settings[log_index].log_to_gmsay) ); QueryDatabase(inject_query); } } + + delete[] categories_in_database; } int Database::CountInvSnapshots() { diff --git a/common/eqemu_logsys.cpp b/common/eqemu_logsys.cpp index 8c1f619f1..aed5365f5 100644 --- a/common/eqemu_logsys.cpp +++ b/common/eqemu_logsys.cpp @@ -123,26 +123,26 @@ void EQEmuLogSys::LoadLogSettingsDefaults() /** * Set Defaults */ - log_settings[Logs::World_Server].log_to_console = Logs::General; - log_settings[Logs::Zone_Server].log_to_console = Logs::General; - log_settings[Logs::QS_Server].log_to_console = Logs::General; - log_settings[Logs::UCS_Server].log_to_console = Logs::General; - log_settings[Logs::Crash].log_to_console = Logs::General; - log_settings[Logs::MySQLError].log_to_console = Logs::General; - log_settings[Logs::Login_Server].log_to_console = Logs::General; - log_settings[Logs::Headless_Client].log_to_console = Logs::General; - log_settings[Logs::NPCScaling].log_to_gmsay = Logs::General; + log_settings[Logs::World_Server].log_to_console = static_cast(Logs::General); + log_settings[Logs::Zone_Server].log_to_console = static_cast(Logs::General); + log_settings[Logs::QS_Server].log_to_console = static_cast(Logs::General); + log_settings[Logs::UCS_Server].log_to_console = static_cast(Logs::General); + log_settings[Logs::Crash].log_to_console = static_cast(Logs::General); + log_settings[Logs::MySQLError].log_to_console = static_cast(Logs::General); + log_settings[Logs::Login_Server].log_to_console = static_cast(Logs::General); + log_settings[Logs::Headless_Client].log_to_console = static_cast(Logs::General); + log_settings[Logs::NPCScaling].log_to_gmsay = static_cast(Logs::General); /** * RFC 5424 */ - log_settings[Logs::Emergency].log_to_console = Logs::General; - log_settings[Logs::Alert].log_to_console = Logs::General; - log_settings[Logs::Critical].log_to_console = Logs::General; - log_settings[Logs::Error].log_to_console = Logs::General; - log_settings[Logs::Warning].log_to_console = Logs::General; - log_settings[Logs::Notice].log_to_console = Logs::General; - log_settings[Logs::Info].log_to_console = Logs::General; + log_settings[Logs::Emergency].log_to_console = static_cast(Logs::General); + log_settings[Logs::Alert].log_to_console = static_cast(Logs::General); + log_settings[Logs::Critical].log_to_console = static_cast(Logs::General); + log_settings[Logs::Error].log_to_console = static_cast(Logs::General); + log_settings[Logs::Warning].log_to_console = static_cast(Logs::General); + log_settings[Logs::Notice].log_to_console = static_cast(Logs::General); + log_settings[Logs::Info].log_to_console = static_cast(Logs::General); /** * Set Category enabled status on defaults diff --git a/loginserver/database.cpp b/loginserver/database.cpp index 0a873be3f..2bc6d9387 100644 --- a/loginserver/database.cpp +++ b/loginserver/database.cpp @@ -520,11 +520,10 @@ void Database::LoadLogSettings(EQEmuLogSys::LogSettings *log_settings) "logsys_categories " "ORDER BY log_category_id"; - auto results = QueryDatabase(query); + auto results = QueryDatabase(query); + int log_category_id = 0; - int log_category_id = 0; - - int categories_in_database[1000] = {}; + int *categories_in_database = new int[1000]; for (auto row = results.begin(); row != results.end(); ++row) { log_category_id = atoi(row[0]); @@ -564,15 +563,14 @@ void Database::LoadLogSettings(EQEmuLogSys::LogSettings *log_settings) * Auto inject categories that don't exist in the database... */ for (int log_index = Logs::AA; log_index != Logs::MaxCategoryID; log_index++) { - if (!categories_in_database[log_index]) { + if (categories_in_database[log_index] != 1) { - Log(Logs::General, - Logs::Status, - "New Log Category '%s' doesn't exist... Automatically adding to `logsys_categories` table...", + LogInfo( + "New Log Category [{0}] doesn't exist... Automatically adding to [logsys_categories] table...", Logs::LogCategoryName[log_index] ); - std::string inject_query = StringFormat( + auto inject_query = fmt::format( "INSERT INTO logsys_categories " "(log_category_id, " "log_category_description, " @@ -580,15 +578,17 @@ void Database::LoadLogSettings(EQEmuLogSys::LogSettings *log_settings) "log_to_file, " "log_to_gmsay) " "VALUES " - "(%i, '%s', %i, %i, %i)", + "({0}, '{1}', {2}, {3}, {4})", log_index, - EscapeString(Logs::LogCategoryName[log_index]).c_str(), - log_settings[log_category_id].log_to_console, - log_settings[log_category_id].log_to_file, - log_settings[log_category_id].log_to_gmsay + EscapeString(Logs::LogCategoryName[log_index]), + std::to_string(log_settings[log_index].log_to_console), + std::to_string(log_settings[log_index].log_to_file), + std::to_string(log_settings[log_index].log_to_gmsay) ); QueryDatabase(inject_query); } } + + delete[] categories_in_database; } \ No newline at end of file diff --git a/queryserv/database.cpp b/queryserv/database.cpp index fcda884e4..02d985a8b 100644 --- a/queryserv/database.cpp +++ b/queryserv/database.cpp @@ -397,44 +397,88 @@ void Database::GeneralQueryReceive(ServerPacket *pack) { safe_delete_array(queryBuffer); } -void Database::LoadLogSettings(EQEmuLogSys::LogSettings* log_settings){ +void Database::LoadLogSettings(EQEmuLogSys::LogSettings *log_settings) +{ std::string query = - "SELECT " - "log_category_id, " - "log_category_description, " - "log_to_console, " - "log_to_file, " - "log_to_gmsay " - "FROM " - "logsys_categories " - "ORDER BY log_category_id"; - auto results = QueryDatabase(query); + "SELECT " + "log_category_id, " + "log_category_description, " + "log_to_console, " + "log_to_file, " + "log_to_gmsay " + "FROM " + "logsys_categories " + "ORDER BY log_category_id"; - int log_category = 0; - LogSys.file_logs_enabled = false; + auto results = QueryDatabase(query); + int log_category_id = 0; + + int *categories_in_database = new int[1000]; for (auto row = results.begin(); row != results.end(); ++row) { - log_category = atoi(row[0]); - log_settings[log_category].log_to_console = atoi(row[2]); - log_settings[log_category].log_to_file = atoi(row[3]); - log_settings[log_category].log_to_gmsay = atoi(row[4]); + log_category_id = atoi(row[0]); + if (log_category_id <= Logs::None || log_category_id >= Logs::MaxCategoryID) { + continue; + } - /* Determine if any output method is enabled for the category - and set it to 1 so it can used to check if category is enabled */ - const bool log_to_console = log_settings[log_category].log_to_console > 0; - const bool log_to_file = log_settings[log_category].log_to_file > 0; - const bool log_to_gmsay = log_settings[log_category].log_to_gmsay > 0; + log_settings[log_category_id].log_to_console = static_cast(atoi(row[2])); + log_settings[log_category_id].log_to_file = static_cast(atoi(row[3])); + log_settings[log_category_id].log_to_gmsay = static_cast(atoi(row[4])); + + /** + * Determine if any output method is enabled for the category + * and set it to 1 so it can used to check if category is enabled + */ + const bool log_to_console = log_settings[log_category_id].log_to_console > 0; + const bool log_to_file = log_settings[log_category_id].log_to_file > 0; + const bool log_to_gmsay = log_settings[log_category_id].log_to_gmsay > 0; const bool is_category_enabled = log_to_console || log_to_file || log_to_gmsay; - if (is_category_enabled) - log_settings[log_category].is_category_enabled = 1; + if (is_category_enabled) { + log_settings[log_category_id].is_category_enabled = 1; + } - /* - This determines whether or not the process needs to actually file log anything. - If we go through this whole loop and nothing is set to any debug level, there is no point to create a file or keep anything open - */ - if (log_settings[log_category].log_to_file > 0){ + /** + * This determines whether or not the process needs to actually file log anything. + * If we go through this whole loop and nothing is set to any debug level, there is no point to create a file or keep anything open + */ + if (log_settings[log_category_id].log_to_file > 0) { LogSys.file_logs_enabled = true; } + + categories_in_database[log_category_id] = 1; } -} + + /** + * Auto inject categories that don't exist in the database... + */ + for (int log_index = Logs::AA; log_index != Logs::MaxCategoryID; log_index++) { + if (categories_in_database[log_index] != 1) { + + LogInfo( + "New Log Category [{0}] doesn't exist... Automatically adding to [logsys_categories] table...", + Logs::LogCategoryName[log_index] + ); + + auto inject_query = fmt::format( + "INSERT INTO logsys_categories " + "(log_category_id, " + "log_category_description, " + "log_to_console, " + "log_to_file, " + "log_to_gmsay) " + "VALUES " + "({0}, '{1}', {2}, {3}, {4})", + log_index, + EscapeString(Logs::LogCategoryName[log_index]), + std::to_string(log_settings[log_index].log_to_console), + std::to_string(log_settings[log_index].log_to_file), + std::to_string(log_settings[log_index].log_to_gmsay) + ); + + QueryDatabase(inject_query); + } + } + + delete[] categories_in_database; +} \ No newline at end of file diff --git a/ucs/database.cpp b/ucs/database.cpp index 5104c851d..00cad774d 100644 --- a/ucs/database.cpp +++ b/ucs/database.cpp @@ -581,44 +581,88 @@ void Database::GetFriendsAndIgnore(int charID, std::vector &friends } -void Database::LoadLogSettings(EQEmuLogSys::LogSettings* log_settings){ +void Database::LoadLogSettings(EQEmuLogSys::LogSettings *log_settings) +{ std::string query = - "SELECT " - "log_category_id, " - "log_category_description, " - "log_to_console, " - "log_to_file, " - "log_to_gmsay " - "FROM " - "logsys_categories " - "ORDER BY log_category_id"; - auto results = QueryDatabase(query); + "SELECT " + "log_category_id, " + "log_category_description, " + "log_to_console, " + "log_to_file, " + "log_to_gmsay " + "FROM " + "logsys_categories " + "ORDER BY log_category_id"; - int log_category = 0; - LogSys.file_logs_enabled = false; + auto results = QueryDatabase(query); + int log_category_id = 0; + + int *categories_in_database = new int[1000]; for (auto row = results.begin(); row != results.end(); ++row) { - log_category = atoi(row[0]); - log_settings[log_category].log_to_console = atoi(row[2]); - log_settings[log_category].log_to_file = atoi(row[3]); - log_settings[log_category].log_to_gmsay = atoi(row[4]); + log_category_id = atoi(row[0]); + if (log_category_id <= Logs::None || log_category_id >= Logs::MaxCategoryID) { + continue; + } - /* Determine if any output method is enabled for the category - and set it to 1 so it can used to check if category is enabled */ - const bool log_to_console = log_settings[log_category].log_to_console > 0; - const bool log_to_file = log_settings[log_category].log_to_file > 0; - const bool log_to_gmsay = log_settings[log_category].log_to_gmsay > 0; + log_settings[log_category_id].log_to_console = static_cast(atoi(row[2])); + log_settings[log_category_id].log_to_file = static_cast(atoi(row[3])); + log_settings[log_category_id].log_to_gmsay = static_cast(atoi(row[4])); + + /** + * Determine if any output method is enabled for the category + * and set it to 1 so it can used to check if category is enabled + */ + const bool log_to_console = log_settings[log_category_id].log_to_console > 0; + const bool log_to_file = log_settings[log_category_id].log_to_file > 0; + const bool log_to_gmsay = log_settings[log_category_id].log_to_gmsay > 0; const bool is_category_enabled = log_to_console || log_to_file || log_to_gmsay; - if (is_category_enabled) - log_settings[log_category].is_category_enabled = 1; + if (is_category_enabled) { + log_settings[log_category_id].is_category_enabled = 1; + } - /* - This determines whether or not the process needs to actually file log anything. - If we go through this whole loop and nothing is set to any debug level, there is no point to create a file or keep anything open - */ - if (log_settings[log_category].log_to_file > 0){ + /** + * This determines whether or not the process needs to actually file log anything. + * If we go through this whole loop and nothing is set to any debug level, there is no point to create a file or keep anything open + */ + if (log_settings[log_category_id].log_to_file > 0) { LogSys.file_logs_enabled = true; } + + categories_in_database[log_category_id] = 1; } + + /** + * Auto inject categories that don't exist in the database... + */ + for (int log_index = Logs::AA; log_index != Logs::MaxCategoryID; log_index++) { + if (categories_in_database[log_index] != 1) { + + LogInfo( + "New Log Category [{0}] doesn't exist... Automatically adding to [logsys_categories] table...", + Logs::LogCategoryName[log_index] + ); + + auto inject_query = fmt::format( + "INSERT INTO logsys_categories " + "(log_category_id, " + "log_category_description, " + "log_to_console, " + "log_to_file, " + "log_to_gmsay) " + "VALUES " + "({0}, '{1}', {2}, {3}, {4})", + log_index, + EscapeString(Logs::LogCategoryName[log_index]), + std::to_string(log_settings[log_index].log_to_console), + std::to_string(log_settings[log_index].log_to_file), + std::to_string(log_settings[log_index].log_to_gmsay) + ); + + QueryDatabase(inject_query); + } + } + + delete[] categories_in_database; }