chore: Consolidate logger setup and add better handling of packets (#1389)

* Logger to Server class

Dont handle master packets from our clients

* move to namespace

Revert "remove extra headers"

This reverts commit ac7b901ece22165cdb0f38fca4be7d8fdf004de8.

remove extra headers

no changes otherwise.

* Merge branch 'main' into server_consolidation_of_work

* Update WorldServer.cpp

* fix submodule version

---------

Co-authored-by: Aaron Kimbre <aronwk.aaron@gmail.com>
This commit is contained in:
David Markowitz
2024-01-05 21:32:09 -08:00
committed by GitHub
parent 0dc6763a3c
commit 0c104e819d
12 changed files with 212 additions and 219 deletions

View File

@@ -9,7 +9,8 @@ add_executable(MasterServer "MasterServer.cpp")
add_compile_definitions(MasterServer PRIVATE PROJECT_VERSION="\"${PROJECT_VERSION}\"")
target_link_libraries(dMasterServer ${COMMON_LIBRARIES})
target_link_libraries(MasterServer ${COMMON_LIBRARIES} dMasterServer)
target_link_libraries(MasterServer ${COMMON_LIBRARIES} dMasterServer dServer)
target_include_directories(dMasterServer PRIVATE ${PROJECT_SOURCE_DIR}/dServer)
if(WIN32)
add_dependencies(MasterServer WorldServer AuthServer ChatServer)

View File

@@ -40,6 +40,7 @@
#include "FdbToSqlite.h"
#include "BitStreamUtils.h"
#include "Start.h"
#include "Server.h"
namespace Game {
Logger* logger = nullptr;
@@ -55,7 +56,6 @@ namespace Game {
bool shutdownSequenceStarted = false;
int ShutdownSequence(int32_t signal = -1);
int32_t FinalizeShutdown(int32_t signal = -1);
Logger* SetupLogger();
void HandlePacket(Packet* packet);
std::map<uint32_t, std::string> activeSessions;
SystemAddress authServerMasterPeerSysAddr;
@@ -77,8 +77,10 @@ int main(int argc, char** argv) {
std::signal(SIGINT, Game::OnSignal);
std::signal(SIGTERM, Game::OnSignal);
Game::config = new dConfig("masterconfig.ini");
//Create all the objects we need to run our service:
Game::logger = SetupLogger();
Server::SetupLogger("MasterServer");
if (!Game::logger) return EXIT_FAILURE;
if (!dConfig::Exists("authconfig.ini")) LOG("Could not find authconfig.ini, using default settings");
@@ -87,9 +89,6 @@ int main(int argc, char** argv) {
if (!dConfig::Exists("sharedconfig.ini")) LOG("Could not find sharedconfig.ini, using default settings");
if (!dConfig::Exists("worldconfig.ini")) LOG("Could not find worldconfig.ini, using default settings");
Game::config = new dConfig("masterconfig.ini");
Game::logger->SetLogToConsole(Game::config->GetValue("log_to_console") != "0");
Game::logger->SetLogDebugStatements(Game::config->GetValue("log_debug_statements") == "1");
uint32_t clientNetVersion = 171022;
const auto clientNetVersionString = Game::config->GetValue("client_net_version");
@@ -395,19 +394,6 @@ int main(int argc, char** argv) {
return ShutdownSequence(EXIT_SUCCESS);
}
Logger* SetupLogger() {
std::string logPath =
(BinaryPathFinder::GetBinaryDir() / ("logs/MasterServer_" + std::to_string(time(nullptr)) + ".log")).string();
bool logToConsole = false;
bool logDebugStatements = false;
#ifdef _DEBUG
logToConsole = true;
logDebugStatements = true;
#endif
return new Logger(logPath, logToConsole, logDebugStatements);
}
void HandlePacket(Packet* packet) {
if (packet->data[0] == ID_DISCONNECTION_NOTIFICATION) {
LOG("A server has disconnected");