mirror of
https://github.com/EQEmu/Server.git
synced 2025-12-14 11:31:30 +00:00
Load log settings from the database
This commit is contained in:
parent
feea52f79e
commit
ffd652a643
@ -2065,7 +2065,8 @@ uint32 Database::GetGuildIDByCharID(uint32 character_id)
|
|||||||
return atoi(row[0]);
|
return atoi(row[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Database::LoadLogSettings(EQEmuLogSys::LogSettings* log_settings) {
|
void Database::LoadLogSettings(EQEmuLogSys::LogSettings *log_settings)
|
||||||
|
{
|
||||||
// log_settings previously initialized to '0' by EQEmuLogSys::LoadLogSettingsDefaults()
|
// log_settings previously initialized to '0' by EQEmuLogSys::LoadLogSettingsDefaults()
|
||||||
|
|
||||||
std::string query =
|
std::string query =
|
||||||
|
|||||||
@ -508,3 +508,92 @@ bool Database::CreateWorldRegistration(std::string long_name, std::string short_
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param 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);
|
||||||
|
|
||||||
|
int log_category_id = 0;
|
||||||
|
|
||||||
|
int categories_in_database[1000] = {};
|
||||||
|
|
||||||
|
for (auto row = results.begin(); row != results.end(); ++row) {
|
||||||
|
log_category_id = atoi(row[0]);
|
||||||
|
if (log_category_id <= Logs::None || log_category_id >= Logs::MaxCategoryID) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
log_settings[log_category_id].log_to_console = static_cast<uint8>(atoi(row[2]));
|
||||||
|
log_settings[log_category_id].log_to_file = static_cast<uint8>(atoi(row[3]));
|
||||||
|
log_settings[log_category_id].log_to_gmsay = static_cast<uint8>(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_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_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]) {
|
||||||
|
|
||||||
|
Log(Logs::General,
|
||||||
|
Logs::Status,
|
||||||
|
"New Log Category '%s' doesn't exist... Automatically adding to `logsys_categories` table...",
|
||||||
|
Logs::LogCategoryName[log_index]
|
||||||
|
);
|
||||||
|
|
||||||
|
std::string inject_query = StringFormat(
|
||||||
|
"INSERT INTO logsys_categories "
|
||||||
|
"(log_category_id, "
|
||||||
|
"log_category_description, "
|
||||||
|
"log_to_console, "
|
||||||
|
"log_to_file, "
|
||||||
|
"log_to_gmsay) "
|
||||||
|
"VALUES "
|
||||||
|
"(%i, '%s', %i, %i, %i)",
|
||||||
|
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
|
||||||
|
);
|
||||||
|
|
||||||
|
QueryDatabase(inject_query);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -22,6 +22,7 @@
|
|||||||
#define EQEMU_DATABASEMYSQL_H
|
#define EQEMU_DATABASEMYSQL_H
|
||||||
|
|
||||||
#include "../common/dbcore.h"
|
#include "../common/dbcore.h"
|
||||||
|
#include "../common/eqemu_logsys.h"
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
@ -126,6 +127,7 @@ public:
|
|||||||
void UpdateLSAccountInfo(unsigned int id, std::string name, std::string password, std::string email);
|
void UpdateLSAccountInfo(unsigned int id, std::string name, std::string password, std::string email);
|
||||||
void UpdateWorldRegistration(unsigned int id, std::string long_name, std::string ip_address);
|
void UpdateWorldRegistration(unsigned int id, std::string long_name, std::string ip_address);
|
||||||
bool CreateWorldRegistration(std::string long_name, std::string short_name, unsigned int &id);
|
bool CreateWorldRegistration(std::string long_name, std::string short_name, unsigned int &id);
|
||||||
|
void LoadLogSettings(EQEmuLogSys::LogSettings *log_settings);
|
||||||
protected:
|
protected:
|
||||||
std::string user, pass, host, port, name;
|
std::string user, pass, host, port, name;
|
||||||
MYSQL *database;
|
MYSQL *database;
|
||||||
|
|||||||
@ -48,17 +48,6 @@ int main()
|
|||||||
|
|
||||||
LogSys.LoadLogSettingsDefaults();
|
LogSys.LoadLogSettingsDefaults();
|
||||||
|
|
||||||
LogSys.log_settings[Logs::Error].log_to_console = Logs::General;
|
|
||||||
LogSys.log_settings[Logs::Error].is_category_enabled = 1;
|
|
||||||
LogSys.log_settings[Logs::MySQLError].log_to_console = Logs::General;
|
|
||||||
LogSys.log_settings[Logs::MySQLError].is_category_enabled = 1;
|
|
||||||
LogSys.log_settings[Logs::MySQLQuery].log_to_console = Logs::General;
|
|
||||||
LogSys.log_settings[Logs::MySQLQuery].is_category_enabled = 1;
|
|
||||||
LogSys.log_settings[Logs::Netcode].log_to_console = Logs::General;
|
|
||||||
LogSys.log_settings[Logs::Netcode].is_category_enabled = Logs::General;
|
|
||||||
|
|
||||||
LogSys.log_settings[Logs::Login_Server].log_to_console = Logs::Detail;
|
|
||||||
|
|
||||||
LogLoginserver("Logging System Init");
|
LogLoginserver("Logging System Init");
|
||||||
|
|
||||||
server.config = EQ::JsonConfigFile::Load("login.json");
|
server.config = EQ::JsonConfigFile::Load("login.json");
|
||||||
@ -141,6 +130,8 @@ int main()
|
|||||||
server.config.GetVariableString("database", "db", "peq")
|
server.config.GetVariableString("database", "db", "peq")
|
||||||
);
|
);
|
||||||
|
|
||||||
|
server.db->LoadLogSettings(LogSys.log_settings);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* make sure our database got created okay, otherwise cleanup and exit
|
* make sure our database got created okay, otherwise cleanup and exit
|
||||||
*/
|
*/
|
||||||
|
|||||||
@ -440,7 +440,10 @@ void WorldServer::ProcessLSAccountUpdate(uint16_t opcode, const EQ::Net::Packet
|
|||||||
|
|
||||||
auto *loginserver_update = (ServerLSAccountUpdate_Struct *) packet.Data();
|
auto *loginserver_update = (ServerLSAccountUpdate_Struct *) packet.Data();
|
||||||
if (is_server_trusted) {
|
if (is_server_trusted) {
|
||||||
Log(Logs::General, Logs::Netcode, "ServerOP_LSAccountUpdate update processed for: %s", loginserver_update->useraccount);
|
Log(Logs::General,
|
||||||
|
Logs::Netcode,
|
||||||
|
"ServerOP_LSAccountUpdate update processed for: %s",
|
||||||
|
loginserver_update->useraccount);
|
||||||
std::string name = "";
|
std::string name = "";
|
||||||
std::string password = "";
|
std::string password = "";
|
||||||
std::string email = "";
|
std::string email = "";
|
||||||
@ -698,18 +701,18 @@ void WorldServer::Handle_NewLSInfo(ServerNewLSInfo_Struct *new_world_server_info
|
|||||||
* this is the second of two cases where we should deny access even if unregistered is allowed
|
* this is the second of two cases where we should deny access even if unregistered is allowed
|
||||||
*/
|
*/
|
||||||
if (server_account_name.size() > 0 || server_account_password.size() > 0) {
|
if (server_account_name.size() > 0 || server_account_password.size() > 0) {
|
||||||
Log(Logs::General,
|
LogLoginserver(
|
||||||
Logs::World_Server,
|
"Server [{0}] [{1}] did not login but this server required a password to login",
|
||||||
"Server %s(%s) did not attempt to log in but this server requires a password.",
|
long_name,
|
||||||
long_name.c_str(),
|
short_name
|
||||||
short_name.c_str());
|
);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Log(Logs::General,
|
LogLoginserver(
|
||||||
Logs::World_Server,
|
"Server [{0}] [{1}] did not login but unregistered servers are allowed",
|
||||||
"Server %s(%s) did not attempt to log in but unregistered servers are allowed.",
|
long_name,
|
||||||
long_name.c_str(),
|
short_name
|
||||||
short_name.c_str());
|
);
|
||||||
|
|
||||||
is_server_authorized = true;
|
is_server_authorized = true;
|
||||||
SetRuntimeID(server_id);
|
SetRuntimeID(server_id);
|
||||||
@ -718,8 +721,7 @@ void WorldServer::Handle_NewLSInfo(ServerNewLSInfo_Struct *new_world_server_info
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
LogF(Logs::General,
|
LogLoginserver(
|
||||||
Logs::World_Server,
|
|
||||||
"Server [{0}] ({1}) is not registered but unregistered servers are allowed",
|
"Server [{0}] ({1}) is not registered but unregistered servers are allowed",
|
||||||
long_name,
|
long_name,
|
||||||
short_name
|
short_name
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user