Move rest of logging to FMT and move config options into more finite categories

This commit is contained in:
Akkadius 2019-07-14 22:16:26 -05:00
parent 949e7adff8
commit ce09aad28a
7 changed files with 115 additions and 92 deletions

View File

@ -317,6 +317,8 @@ std::string EQEmuLogSys::GetLinuxConsoleColorFromCategory(uint16 log_category)
case Logs::Normal: case Logs::Normal:
return LC_YELLOW; return LC_YELLOW;
case Logs::MySQLError: case Logs::MySQLError:
case Logs::Warning:
case Logs::Critical:
case Logs::Error: case Logs::Error:
return LC_RED; return LC_RED;
case Logs::MySQLQuery: case Logs::MySQLQuery:

View File

@ -46,7 +46,7 @@ bool Client::Process()
EQApplicationPacket *app = connection->PopPacket(); EQApplicationPacket *app = connection->PopPacket();
while (app) { while (app) {
if (server.options.IsTraceOn()) { if (server.options.IsTraceOn()) {
Log(Logs::General, Logs::Netcode, "Application packet received from client (size %u)", app->Size()); LogDebug("Application packet received from client (size {0})", app->Size());
} }
if (server.options.IsDumpInPacketsOn()) { if (server.options.IsDumpInPacketsOn()) {
@ -62,19 +62,19 @@ bool Client::Process()
switch (app->GetOpcode()) { switch (app->GetOpcode()) {
case OP_SessionReady: { case OP_SessionReady: {
if (server.options.IsTraceOn()) { if (server.options.IsTraceOn()) {
LogInfo("Session ready received from client."); LogInfo("Session ready received from client");
} }
Handle_SessionReady((const char *) app->pBuffer, app->Size()); Handle_SessionReady((const char *) app->pBuffer, app->Size());
break; break;
} }
case OP_Login: { case OP_Login: {
if (app->Size() < 20) { if (app->Size() < 20) {
LogError("Login received but it is too small, discarding."); LogError("Login received but it is too small, discarding");
break; break;
} }
if (server.options.IsTraceOn()) { if (server.options.IsTraceOn()) {
LogInfo("Login received from client."); LogInfo("Login received from client");
} }
Handle_Login((const char *) app->pBuffer, app->Size()); Handle_Login((const char *) app->pBuffer, app->Size());
@ -82,12 +82,12 @@ bool Client::Process()
} }
case OP_ServerListRequest: { case OP_ServerListRequest: {
if (app->Size() < 4) { if (app->Size() < 4) {
LogError("Server List Request received but it is too small, discarding."); LogError("Server List Request received but it is too small, discarding");
break; break;
} }
if (server.options.IsTraceOn()) { if (server.options.IsTraceOn()) {
LogDebug("Server list request received from client."); LogDebug("Server list request received from client");
} }
SendServerListPacket(*(uint32_t *) app->pBuffer); SendServerListPacket(*(uint32_t *) app->pBuffer);
@ -95,7 +95,7 @@ bool Client::Process()
} }
case OP_PlayEverquestRequest: { case OP_PlayEverquestRequest: {
if (app->Size() < sizeof(PlayEverquestRequest_Struct)) { if (app->Size() < sizeof(PlayEverquestRequest_Struct)) {
LogError("Play received but it is too small, discarding."); LogError("Play received but it is too small, discarding");
break; break;
} }
@ -127,12 +127,12 @@ bool Client::Process()
void Client::Handle_SessionReady(const char *data, unsigned int size) void Client::Handle_SessionReady(const char *data, unsigned int size)
{ {
if (status != cs_not_sent_session_ready) { if (status != cs_not_sent_session_ready) {
LogError("Session ready received again after already being received."); LogError("Session ready received again after already being received");
return; return;
} }
if (size < sizeof(unsigned int)) { if (size < sizeof(unsigned int)) {
LogError("Session ready was too small."); LogError("Session ready was too small");
return; return;
} }
@ -210,7 +210,7 @@ void Client::Handle_Login(const char *data, unsigned int size)
std::string outbuffer; std::string outbuffer;
outbuffer.resize(size - 12); outbuffer.resize(size - 12);
if (outbuffer.length() == 0) { if (outbuffer.length() == 0) {
LogError("Corrupt buffer sent to server, no length."); LogError("Corrupt buffer sent to server, no length");
return; return;
} }
@ -224,7 +224,7 @@ void Client::Handle_Login(const char *data, unsigned int size)
std::string user(&outbuffer[0]); std::string user(&outbuffer[0]);
if (user.length() >= outbuffer.length()) { if (user.length() >= outbuffer.length()) {
LogError("Corrupt buffer sent to server, preventing buffer overflow."); LogError("Corrupt buffer sent to server, preventing buffer overflow");
return; return;
} }
@ -306,7 +306,7 @@ void Client::Handle_Login(const char *data, unsigned int size)
void Client::Handle_Play(const char *data) void Client::Handle_Play(const char *data)
{ {
if (status != cs_logged_in) { if (status != cs_logged_in) {
LogError("Client sent a play request when they were not logged in, discarding."); LogError("Client sent a play request when they were not logged in, discarding");
return; return;
} }
@ -347,7 +347,7 @@ void Client::SendServerListPacket(uint32 seq)
void Client::SendPlayResponse(EQApplicationPacket *outapp) void Client::SendPlayResponse(EQApplicationPacket *outapp)
{ {
if (server.options.IsTraceOn()) { if (server.options.IsTraceOn()) {
Log(Logs::General, Logs::Netcode, "Sending play response for %s.", GetAccountName().c_str()); LogDebug("Sending play response for {0}", GetAccountName());
// server_log->LogPacket(log_network_trace, (const char*)outapp->pBuffer, outapp->size); // server_log->LogPacket(log_network_trace, (const char*)outapp->pBuffer, outapp->size);
} }
connection->QueuePacket(outapp); connection->QueuePacket(outapp);

View File

@ -28,7 +28,7 @@ extern bool run_server;
ClientManager::ClientManager() ClientManager::ClientManager()
{ {
int titanium_port = server.config.GetVariableInt("Titanium", "port", 5998); int titanium_port = server.config.GetVariableInt("client_configuration", "titanium_port", 5998);
EQStreamManagerInterfaceOptions titanium_opts(titanium_port, false, false); EQStreamManagerInterfaceOptions titanium_opts(titanium_port, false, false);
@ -36,14 +36,14 @@ ClientManager::ClientManager()
titanium_ops = new RegularOpcodeManager; titanium_ops = new RegularOpcodeManager;
if (!titanium_ops->LoadOpcodes( if (!titanium_ops->LoadOpcodes(
server.config.GetVariableString( server.config.GetVariableString(
"Titanium", "client_configuration",
"opcodes", "titanium_opcodes",
"login_opcodes.conf" "login_opcodes.conf"
).c_str())) { ).c_str())) {
LogError( LogError(
"ClientManager fatal error: couldn't load opcodes for Titanium file [{0}]", "ClientManager fatal error: couldn't load opcodes for Titanium file [{0}]",
server.config.GetVariableString("Titanium", "opcodes", "login_opcodes.conf") server.config.GetVariableString("client_configuration", "titanium_opcodes", "login_opcodes.conf")
); );
run_server = false; run_server = false;
@ -63,15 +63,22 @@ ClientManager::ClientManager()
} }
); );
int sod_port = server.config.GetVariableInt("SoD", "port", 5999); int sod_port = server.config.GetVariableInt("client_configuration", "sod_port", 5999);
EQStreamManagerInterfaceOptions sod_opts(sod_port, false, false); EQStreamManagerInterfaceOptions sod_opts(sod_port, false, false);
sod_stream = new EQ::Net::EQStreamManager(sod_opts); sod_stream = new EQ::Net::EQStreamManager(sod_opts);
sod_ops = new RegularOpcodeManager; sod_ops = new RegularOpcodeManager;
if (!sod_ops->LoadOpcodes(server.config.GetVariableString("SoD", "opcodes", "login_opcodes.conf").c_str())) { if (
!sod_ops->LoadOpcodes(
server.config.GetVariableString(
"client_configuration",
"sod_opcodes",
"login_opcodes.conf"
).c_str()
)) {
LogError( LogError(
"ClientManager fatal error: couldn't load opcodes for SoD file {0}", "ClientManager fatal error: couldn't load opcodes for SoD file {0}",
server.config.GetVariableString("SoD", "opcodes", "login_opcodes.conf").c_str() server.config.GetVariableString("client_configuration", "sod_opcodes", "login_opcodes.conf").c_str()
); );
run_server = false; run_server = false;
@ -118,7 +125,7 @@ void ClientManager::Process()
auto iter = clients.begin(); auto iter = clients.begin();
while (iter != clients.end()) { while (iter != clients.end()) {
if ((*iter)->Process() == false) { if ((*iter)->Process() == false) {
Log(Logs::General, Logs::Debug, "Client had a fatal error and had to be removed from the login."); LogWarning("Client had a fatal error and had to be removed from the login");
delete (*iter); delete (*iter);
iter = clients.erase(iter); iter = clients.erase(iter);
} }
@ -134,7 +141,7 @@ void ClientManager::ProcessDisconnect()
while (iter != clients.end()) { while (iter != clients.end()) {
std::shared_ptr<EQStreamInterface> c = (*iter)->GetConnection(); std::shared_ptr<EQStreamInterface> c = (*iter)->GetConnection();
if (c->CheckState(CLOSED)) { if (c->CheckState(CLOSED)) {
LogInfo("Client disconnected from the server, removing client."); LogInfo("Client disconnected from the server, removing client");
delete (*iter); delete (*iter);
iter = clients.erase(iter); iter = clients.erase(iter);
} }

View File

@ -62,7 +62,7 @@ Database::Database(
errbuf errbuf
) )
) { ) {
Log(Logs::General, Logs::Error, "Failed to connect to database: Error: %s", errbuf); LogError("Failed to connect to database: Error: [{0}]", errbuf);
exit(1); exit(1);
} }
else { else {

View File

@ -55,13 +55,25 @@ int main(int argc, char** argv)
server.config = EQ::JsonConfigFile::Load("login.json"); server.config = EQ::JsonConfigFile::Load("login.json");
LogInfo("Config System Init"); LogInfo("Config System Init");
server.options.Trace(server.config.GetVariableBool("general", "trace", false)); /**
server.options.WorldTrace(server.config.GetVariableBool("general", "world_trace", false)); * options: logging
server.options.DumpInPackets(server.config.GetVariableBool("general", "dump_packets_in", false)); */
server.options.DumpOutPackets(server.config.GetVariableBool("general", "dump_packets_out", false)); server.options.Trace(server.config.GetVariableBool("logging", "trace", false));
server.options.RejectDuplicateServers(server.config.GetVariableBool("general", "reject_duplicate_servers", false)); server.options.WorldTrace(server.config.GetVariableBool("logging", "world_trace", false));
server.options.AutoCreateAccounts(server.config.GetVariableBool("general", "auto_create_accounts", true)); server.options.DumpInPackets(server.config.GetVariableBool("logging", "dump_packets_in", false));
server.options.AutoLinkAccounts(server.config.GetVariableBool("general", "auto_link_accounts", false)); server.options.DumpOutPackets(server.config.GetVariableBool("logging", "dump_packets_out", false));
/**
* options: worldservers
*/
server.options.RejectDuplicateServers(server.config.GetVariableBool("worldservers", "reject_duplicate_servers", false));
server.options.AllowUnregistered(server.config.GetVariableBool("worldservers", "unregistered_allowed", true));
/**
* options: account
*/
server.options.AutoCreateAccounts(server.config.GetVariableBool("account", "auto_create_accounts", true));
server.options.AutoLinkAccounts(server.config.GetVariableBool("account", "auto_link_accounts", false));
#ifdef LSPX #ifdef LSPX
server.options.EQEmuLoginServerAddress( server.options.EQEmuLoginServerAddress(
@ -88,7 +100,6 @@ int main(int argc, char** argv)
server.options.EncryptionMode(server.config.GetVariableInt("security", "mode", 6)); server.options.EncryptionMode(server.config.GetVariableInt("security", "mode", 6));
#endif #endif
server.options.AllowUnregistered(server.config.GetVariableBool("security", "unregistered_allowed", true));
server.options.AllowTokenLogin(server.config.GetVariableBool("security", "allow_token_login", false)); server.options.AllowTokenLogin(server.config.GetVariableBool("security", "allow_token_login", false));
server.options.AllowPasswordLogin(server.config.GetVariableBool("security", "allow_password_login", true)); server.options.AllowPasswordLogin(server.config.GetVariableBool("security", "allow_password_login", true));
server.options.UpdateInsecurePasswords( server.options.UpdateInsecurePasswords(
@ -177,18 +188,18 @@ int main(int argc, char** argv)
LoginserverCommandHandler::CommandHandler(argc, argv); LoginserverCommandHandler::CommandHandler(argc, argv);
LogInfo("[Config] IsTraceOn [{0}]", server.options.IsTraceOn()); LogInfo("[Config] [Logging] IsTraceOn [{0}]", server.options.IsTraceOn());
LogInfo("[Config] IsWorldTraceOn [{0}]", server.options.IsWorldTraceOn()); LogInfo("[Config] [Logging] IsWorldTraceOn [{0}]", server.options.IsWorldTraceOn());
LogInfo("[Config] IsDumpInPacketsOn [{0}]", server.options.IsDumpInPacketsOn()); LogInfo("[Config] [Logging] IsDumpInPacketsOn [{0}]", server.options.IsDumpInPacketsOn());
LogInfo("[Config] IsDumpOutPacketsOn [{0}]", server.options.IsDumpOutPacketsOn()); LogInfo("[Config] [Logging] IsDumpOutPacketsOn [{0}]", server.options.IsDumpOutPacketsOn());
LogInfo("[Config] IsRejectingDuplicateServers [{0}]", server.options.IsRejectingDuplicateServers()); LogInfo("[Config] [Account] CanAutoCreateAccounts [{0}]", server.options.CanAutoCreateAccounts());
LogInfo("[Config] CanAutoCreateAccounts [{0}]", server.options.CanAutoCreateAccounts()); LogInfo("[Config] [Account] CanAutoLinkAccounts [{0}]", server.options.CanAutoLinkAccounts());
LogInfo("[Config] CanAutoLinkAccounts [{0}]", server.options.CanAutoLinkAccounts()); LogInfo("[Config] [WorldServer] IsRejectingDuplicateServers [{0}]", server.options.IsRejectingDuplicateServers());
LogInfo("[Config] GetEncryptionMode [{0}]", server.options.GetEncryptionMode()); LogInfo("[Config] [WorldServer] IsUnregisteredAllowed [{0}]", server.options.IsUnregisteredAllowed());
LogInfo("[Config] IsUnregisteredAllowed [{0}]", server.options.IsUnregisteredAllowed()); LogInfo("[Config] [Security] GetEncryptionMode [{0}]", server.options.GetEncryptionMode());
LogInfo("[Config] IsTokenLoginAllowed [{0}]", server.options.IsTokenLoginAllowed()); LogInfo("[Config] [Security] IsTokenLoginAllowed [{0}]", server.options.IsTokenLoginAllowed());
LogInfo("[Config] IsPasswordLoginAllowed [{0}]", server.options.IsPasswordLoginAllowed()); LogInfo("[Config] [Security] IsPasswordLoginAllowed [{0}]", server.options.IsPasswordLoginAllowed());
LogInfo("[Config] IsUpdatingInsecurePasswords [{0}]", server.options.IsUpdatingInsecurePasswords()); LogInfo("[Config] [Security] IsUpdatingInsecurePasswords [{0}]", server.options.IsUpdatingInsecurePasswords());
while (run_server) { while (run_server) {
Timer::SetCurrentTime(); Timer::SetCurrentTime();

View File

@ -77,10 +77,10 @@ ServerManager::ServerManager()
auto iter = world_servers.begin(); auto iter = world_servers.begin();
while (iter != world_servers.end()) { while (iter != world_servers.end()) {
if ((*iter)->GetConnection()->GetUUID() == c->GetUUID()) { if ((*iter)->GetConnection()->GetUUID() == c->GetUUID()) {
LogF(Logs::General, LogInfo(
Logs::World_Server,
"World server {0} has been disconnected, removing.", "World server {0} has been disconnected, removing.",
(*iter)->GetServerLongName().c_str()); (*iter)->GetServerLongName()
);
world_servers.erase(iter); world_servers.erase(iter);
return; return;
} }

View File

@ -95,11 +95,11 @@ void WorldServer::Reset()
void WorldServer::ProcessNewLSInfo(uint16_t opcode, const EQ::Net::Packet &packet) void WorldServer::ProcessNewLSInfo(uint16_t opcode, const EQ::Net::Packet &packet)
{ {
if (server.options.IsWorldTraceOn()) { if (server.options.IsWorldTraceOn()) {
Log(Logs::General, LogDebug(
Logs::Netcode, "Application packet received from server: {0}, (size {1})",
"Application packet received from server: 0x%.4X, (size %u)",
opcode, opcode,
packet.Length()); packet.Length()
);
} }
if (server.options.IsDumpInPacketsOn()) { if (server.options.IsDumpInPacketsOn()) {
@ -189,11 +189,11 @@ void WorldServer::ProcessLSStatus(uint16_t opcode, const EQ::Net::Packet &packet
void WorldServer::ProcessUserToWorldResponseLegacy(uint16_t opcode, const EQ::Net::Packet &packet) void WorldServer::ProcessUserToWorldResponseLegacy(uint16_t opcode, const EQ::Net::Packet &packet)
{ {
if (server.options.IsWorldTraceOn()) { if (server.options.IsWorldTraceOn()) {
Log(Logs::General, LogDebug(
Logs::Netcode, "Application packet received from server: {0}, (size {1})",
"Application packet received from server: 0x%.4X, (size %u)",
opcode, opcode,
packet.Length()); packet.Length()
);
} }
if (server.options.IsDumpInPacketsOn()) { if (server.options.IsDumpInPacketsOn()) {
@ -213,7 +213,7 @@ void WorldServer::ProcessUserToWorldResponseLegacy(uint16_t opcode, const EQ::Ne
//Because this is a part of the client login procedure it makes tracking client errors //Because this is a part of the client login procedure it makes tracking client errors
//While keeping world server spam with multiple servers connected almost impossible. //While keeping world server spam with multiple servers connected almost impossible.
if (server.options.IsTraceOn()) { if (server.options.IsTraceOn()) {
Log(Logs::General, Logs::Netcode, "User-To-World Response received"); LogDebug("User-To-World Response received");
} }
auto *user_to_world_response = (UsertoWorldResponseLegacy_Struct *) packet.Data(); auto *user_to_world_response = (UsertoWorldResponseLegacy_Struct *) packet.Data();
@ -266,8 +266,8 @@ void WorldServer::ProcessUserToWorldResponseLegacy(uint16_t opcode, const EQ::Ne
break; break;
} }
LogF(Logs::General, if (server.options.IsWorldTraceOn()) {
Logs::Netcode, LogDebug(
"Sending play response: allowed [{0}] sequence [{1}] server number [{2}] message [{3}]", "Sending play response: allowed [{0}] sequence [{1}] server number [{2}] message [{3}]",
per->Allowed, per->Allowed,
per->Sequence, per->Sequence,
@ -275,7 +275,8 @@ void WorldServer::ProcessUserToWorldResponseLegacy(uint16_t opcode, const EQ::Ne
per->Message per->Message
); );
Log(Logs::General, Logs::Netcode, "[Size: %u] %s", outapp->size, DumpPacketToString(outapp).c_str()); LogDebug("[Size: {0}] {1}", outapp->size, DumpPacketToString(outapp));
}
if (server.options.IsDumpOutPacketsOn()) { if (server.options.IsDumpOutPacketsOn()) {
DumpPacket(outapp); DumpPacket(outapp);
@ -299,11 +300,11 @@ void WorldServer::ProcessUserToWorldResponseLegacy(uint16_t opcode, const EQ::Ne
void WorldServer::ProcessUserToWorldResponse(uint16_t opcode, const EQ::Net::Packet &packet) void WorldServer::ProcessUserToWorldResponse(uint16_t opcode, const EQ::Net::Packet &packet)
{ {
if (server.options.IsWorldTraceOn()) { if (server.options.IsWorldTraceOn()) {
Log(Logs::General, LogDebug(
Logs::Netcode,
"Application packet received from server: 0x%.4X, (size %u)", "Application packet received from server: 0x%.4X, (size %u)",
opcode, opcode,
packet.Length()); packet.Length()
);
} }
if (server.options.IsDumpInPacketsOn()) { if (server.options.IsDumpInPacketsOn()) {
@ -323,7 +324,7 @@ void WorldServer::ProcessUserToWorldResponse(uint16_t opcode, const EQ::Net::Pac
//Because this is a part of the client login procedure it makes tracking client errors //Because this is a part of the client login procedure it makes tracking client errors
//While keeping world server spam with multiple servers connected almost impossible. //While keeping world server spam with multiple servers connected almost impossible.
if (server.options.IsTraceOn()) { if (server.options.IsTraceOn()) {
Log(Logs::General, Logs::Netcode, "User-To-World Response received"); LogDebug("User-To-World Response received");
} }
auto user_to_world_response = (UsertoWorldResponse_Struct *) packet.Data(); auto user_to_world_response = (UsertoWorldResponse_Struct *) packet.Data();
@ -355,7 +356,7 @@ void WorldServer::ProcessUserToWorldResponse(uint16_t opcode, const EQ::Net::Pac
client->GetPlayServerID() client->GetPlayServerID()
); );
Log(Logs::General, Logs::Netcode, "[Size: %u] %s", outapp->size, DumpPacketToString(outapp).c_str()); LogDebug("[Size: {0}] {1}", outapp->size, DumpPacketToString(outapp));
if (user_to_world_response->response > 0) { if (user_to_world_response->response > 0) {
per->Allowed = 1; per->Allowed = 1;
@ -387,14 +388,14 @@ void WorldServer::ProcessUserToWorldResponse(uint16_t opcode, const EQ::Net::Pac
} }
if (server.options.IsTraceOn()) { if (server.options.IsTraceOn()) {
Log(Logs::General, LogDebug(
Logs::Netcode, "Sending play response with following data, allowed {0}, sequence {1}, server number {2}, message {3}",
"Sending play response with following data, allowed %u, sequence %u, server number %u, message %u",
per->Allowed, per->Allowed,
per->Sequence, per->Sequence,
per->ServerNumber, per->ServerNumber,
per->Message); per->Message
Log(Logs::General, Logs::Netcode, "[Size: %u] %s", outapp->size, DumpPacketToString(outapp).c_str()); );
LogDebug("[Size: {0}] {1}", outapp->size, DumpPacketToString(outapp));
} }
if (server.options.IsDumpOutPacketsOn()) { if (server.options.IsDumpOutPacketsOn()) {
@ -419,11 +420,11 @@ void WorldServer::ProcessUserToWorldResponse(uint16_t opcode, const EQ::Net::Pac
void WorldServer::ProcessLSAccountUpdate(uint16_t opcode, const EQ::Net::Packet &packet) void WorldServer::ProcessLSAccountUpdate(uint16_t opcode, const EQ::Net::Packet &packet)
{ {
if (server.options.IsWorldTraceOn()) { if (server.options.IsWorldTraceOn()) {
Log(Logs::General, LogDebug(
Logs::Netcode, "Application packet received from server: {0}, (size {1})",
"Application packet received from server: 0x%.4X, (size %u)",
opcode, opcode,
packet.Length()); packet.Length()
);
} }
if (server.options.IsDumpInPacketsOn()) { if (server.options.IsDumpInPacketsOn()) {
@ -439,7 +440,9 @@ void WorldServer::ProcessLSAccountUpdate(uint16_t opcode, const EQ::Net::Packet
return; return;
} }
Log(Logs::General, Logs::Netcode, "ServerOP_LSAccountUpdate packet received from: %s", short_name.c_str()); if (server.options.IsWorldTraceOn()) {
LogDebug("ServerOP_LSAccountUpdate packet received from [{0}]", short_name);
}
auto *loginserver_update = (ServerLSAccountUpdate_Struct *) packet.Data(); auto *loginserver_update = (ServerLSAccountUpdate_Struct *) packet.Data();
if (IsServerTrusted()) { if (IsServerTrusted()) {