mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2025-08-04 01:34:07 +00:00
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:
6
dServer/CMakeLists.txt
Normal file
6
dServer/CMakeLists.txt
Normal file
@@ -0,0 +1,6 @@
|
||||
set(DSERVER_SOURCES
|
||||
"Server.cpp")
|
||||
|
||||
add_library(dServer STATIC ${DSERVER_SOURCES})
|
||||
|
||||
target_include_directories(dServer PUBLIC ".")
|
29
dServer/Server.cpp
Normal file
29
dServer/Server.cpp
Normal file
@@ -0,0 +1,29 @@
|
||||
#include "Server.h"
|
||||
|
||||
#include "BinaryPathFinder.h"
|
||||
#include "Game.h"
|
||||
#include "Logger.h"
|
||||
#include "dConfig.h"
|
||||
|
||||
void Server::SetupLogger(const std::string_view serviceName) {
|
||||
if (Game::logger) {
|
||||
LOG("A logger has already been setup, skipping.");
|
||||
return;
|
||||
}
|
||||
|
||||
const auto logsDir = BinaryPathFinder::GetBinaryDir() / "logs";
|
||||
|
||||
if (!std::filesystem::exists(logsDir)) std::filesystem::create_directory(logsDir);
|
||||
|
||||
std::string logPath = (logsDir / serviceName).string() + "_" + std::to_string(time(nullptr)) + ".log";
|
||||
bool logToConsole = false;
|
||||
bool logDebugStatements = false;
|
||||
#ifdef _DEBUG
|
||||
logToConsole = true;
|
||||
logDebugStatements = true;
|
||||
#endif
|
||||
Game::logger = new Logger(logPath, logToConsole, logDebugStatements);
|
||||
|
||||
Game::logger->SetLogToConsole(Game::config->GetValue("log_to_console") != "0");
|
||||
Game::logger->SetLogDebugStatements(Game::config->GetValue("log_debug_statements") == "1");
|
||||
}
|
10
dServer/Server.h
Normal file
10
dServer/Server.h
Normal file
@@ -0,0 +1,10 @@
|
||||
#ifndef __SERVER__H__
|
||||
#define __SERVER__H__
|
||||
|
||||
#include <string_view>
|
||||
|
||||
namespace Server {
|
||||
void SetupLogger(const std::string_view serviceName);
|
||||
};
|
||||
|
||||
#endif //!__SERVER__H__
|
Reference in New Issue
Block a user