Made a small-scale test with the spdlog library. Incidentally added fmt.

This commit is contained in:
2023-12-30 10:30:52 +02:00
parent fc3f2f232c
commit 2c8cb0c857
14 changed files with 156 additions and 136 deletions

View File

@ -12,6 +12,10 @@ add_executable(${PROJECT_NAME} ${sources})
# Find dependencies
#
# vcpkg dependencies
#
# MySQL
find_package(unofficial-libmysql REQUIRED)
target_link_libraries(${PROJECT_NAME} unofficial::libmysql::libmysql)
@ -28,11 +32,6 @@ target_link_libraries (${PROJECT_NAME} Boost::boost)
find_package(Libevent CONFIG REQUIRED)
target_link_libraries(${PROJECT_NAME} libevent::core libevent::extra libevent::pthreads)
# DevIL
find_package(DevIL REQUIRED)
include_directories(${IL_INCLUDE_DIR})
target_link_libraries(${PROJECT_NAME} ${IL_LIBRARIES})
# LZO
find_package(LZO REQUIRED)
if (LZO_FOUND)
@ -40,6 +39,27 @@ if (LZO_FOUND)
target_link_libraries(${PROJECT_NAME} ${LZO_LIBRARIES})
endif (LZO_FOUND)
# effolkronium/random
find_package(effolkronium_random CONFIG REQUIRED)
target_link_libraries(${PROJECT_NAME} effolkronium_random)
# fmt
find_package(fmt CONFIG REQUIRED)
target_link_libraries(${PROJECT_NAME} fmt::fmt)
# spdlog
find_package(spdlog CONFIG REQUIRED)
target_link_libraries(${PROJECT_NAME} spdlog::spdlog)
#
# System-provided dependencies
#
# DevIL
find_package(DevIL REQUIRED)
include_directories(${IL_INCLUDE_DIR})
target_link_libraries(${PROJECT_NAME} ${IL_LIBRARIES})
# Pthreads
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
@ -48,8 +68,8 @@ target_link_libraries(${PROJECT_NAME} Threads::Threads)
# LibBSD
target_link_libraries(${PROJECT_NAME} bsd)
# effolkronium/random
find_package(effolkronium_random CONFIG REQUIRED)
target_link_libraries(${PROJECT_NAME} effolkronium_random)
#
# Project-provided dependencies
#
target_link_libraries(${PROJECT_NAME} libgame libpoly libsql libthecore liblua)

View File

@ -271,13 +271,13 @@ bool GetIPInfo()
{
char * ip = inet_ntoa(sai->sin_addr);
strlcpy(g_szInternalIP, ip, sizeof(g_szInternalIP));
fprintf(stderr, "Internal IP automatically configured: %s interface %s\n", ip, ifap->ifa_name);
SPDLOG_WARN("Internal IP automatically configured: {} interface {}", ip, ifap->ifa_name);
}
else if (g_szPublicIP[0] == '0')
{
char * ip = inet_ntoa(sai->sin_addr);
strlcpy(g_szPublicIP, ip, sizeof(g_szPublicIP));
fprintf(stderr, "Public IP automatically configured: %s interface %s\n", ip, ifap->ifa_name);
SPDLOG_WARN("Public IP automatically configured: {} interface {}", ip, ifap->ifa_name);
}
}
@ -396,7 +396,7 @@ void config_init(const string& st_localeServiceName)
TOKEN("hostname")
{
g_stHostname = value_string;
fprintf(stdout, "HOSTNAME: %s\n", g_stHostname.c_str());
SPDLOG_INFO("HOSTNAME: {}", g_stHostname);
continue;
}
@ -509,11 +509,11 @@ void config_init(const string& st_localeServiceName)
if (false == AccountDB::instance().IsConnected())
{
fprintf(stderr, "cannot start server while no common sql connected\n");
exit(1);
SPDLOG_CRITICAL("cannot start server while no common sql connected");
exit(EXIT_FAILURE);
}
fprintf(stdout, "CommonSQL connected\n");
SPDLOG_INFO("CommonSQL connected");
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
// <<3C><><EFBFBD><EFBFBD>> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD>ǹ<EFBFBD>(WHERE) <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>. (<28>ٸ<EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>ֽ<EFBFBD><D6BD>ϴ<EFBFBD>)

View File

@ -1233,11 +1233,11 @@ bool AccountDB::IsConnected()
bool AccountDB::Connect(const char * host, const int port, const char * user, const char * pwd, const char * db)
{
m_IsConnect = m_sql_direct.Setup(host, user, pwd, db, "", true, port);
m_IsConnect = m_sql_direct.Setup(host, user, pwd, db, nullptr, true, port);
if (false == m_IsConnect)
{
fprintf(stderr, "cannot open direct sql connection to host: %s user: %s db: %s\n", host, user, db);
SPDLOG_ERROR("cannot open direct sql connection to host: {} user: {} db: {}", host, user, db);
return false;
}

View File

@ -162,7 +162,7 @@ void ShutdownOnFatalError()
{
if (!g_bShutdown)
{
sys_err("ShutdownOnFatalError!!!!!!!!!!");
SPDLOG_CRITICAL("ShutdownOnFatalError!!!!!!!!!!");
{
char buf[256];
@ -258,7 +258,7 @@ void heartbeat(LPHEART ht, int pulse)
if (++count > 50)
{
sys_log(0, "FLUSH_SENT");
SPDLOG_DEBUG("FLUSH_SENT");
break;
}
}
@ -273,7 +273,7 @@ void heartbeat(LPHEART ht, int pulse)
for (int i = 0; i < count; ++i, ++save_idx)
db_clientdesc->DBPacket(HEADER_GD_PLAYER_SAVE, 0, &g_vec_save[save_idx], sizeof(TPlayerTable));
sys_log(0, "SAVE_FLUSH %d", count);
SPDLOG_DEBUG("SAVE_FLUSH {}", count);
}
}
}
@ -331,7 +331,7 @@ int main(int argc, char **argv)
ilInit(); // DevIL Initialize
WriteVersion(std::cout);
WriteVersion();
SECTREE_MANAGER sectree_manager;
CHARACTER_MANAGER char_manager;
@ -419,12 +419,12 @@ int main(int argc, char **argv)
const std::string strPackageCryptInfoDir = "package/";
if( !desc_manager.LoadClientPackageCryptInfo( strPackageCryptInfoDir.c_str() ) )
{
sys_err("Failed to Load ClientPackageCryptInfo File(%s)", strPackageCryptInfoDir.c_str());
SPDLOG_WARN("Failed to Load ClientPackageCryptInfo Files ({})", strPackageCryptInfoDir);
}
while (idle());
sys_log(0, "<shutdown> Starting...");
SPDLOG_INFO("<shutdown> Starting...");
g_bShutdown = true;
g_bNoMoreClient = true;
@ -438,7 +438,7 @@ int main(int argc, char **argv)
do
{
DWORD dwCount = DBManager::instance().CountQuery();
sys_log(0, "Queries %u", dwCount);
SPDLOG_DEBUG("Queries {}", dwCount);
if (dwCount == 0)
break;
@ -451,38 +451,38 @@ int main(int argc, char **argv)
} while (1);
}
sys_log(0, "<shutdown> Destroying CArenaManager...");
SPDLOG_INFO("<shutdown> Destroying CArenaManager...");
arena_manager.Destroy();
sys_log(0, "<shutdown> Destroying COXEventManager...");
SPDLOG_INFO("<shutdown> Destroying COXEventManager...");
OXEvent_manager.Destroy();
sys_log(0, "<shutdown> Disabling signal timer...");
SPDLOG_INFO("<shutdown> Disabling signal timer...");
signal_timer_disable();
sys_log(0, "<shutdown> Shutting down CHARACTER_MANAGER...");
SPDLOG_INFO("<shutdown> Shutting down CHARACTER_MANAGER...");
char_manager.GracefulShutdown();
sys_log(0, "<shutdown> Shutting down ITEM_MANAGER...");
SPDLOG_INFO("<shutdown> Shutting down ITEM_MANAGER...");
item_manager.GracefulShutdown();
sys_log(0, "<shutdown> Flushing db_clientdesc...");
SPDLOG_INFO("<shutdown> Flushing db_clientdesc...");
db_clientdesc->FlushOutput();
sys_log(0, "<shutdown> Flushing p2p_manager...");
SPDLOG_INFO("<shutdown> Flushing p2p_manager...");
p2p_manager.FlushOutput();
sys_log(0, "<shutdown> Destroying CShopManager...");
SPDLOG_INFO("<shutdown> Destroying CShopManager...");
shop_manager.Destroy();
sys_log(0, "<shutdown> Destroying CHARACTER_MANAGER...");
SPDLOG_INFO("<shutdown> Destroying CHARACTER_MANAGER...");
char_manager.Destroy();
sys_log(0, "<shutdown> Destroying ITEM_MANAGER...");
SPDLOG_INFO("<shutdown> Destroying ITEM_MANAGER...");
item_manager.Destroy();
sys_log(0, "<shutdown> Destroying DESC_MANAGER...");
SPDLOG_INFO("<shutdown> Destroying DESC_MANAGER...");
desc_manager.Destroy();
sys_log(0, "<shutdown> Destroying quest::CQuestManager...");
SPDLOG_INFO("<shutdown> Destroying quest::CQuestManager...");
quest_manager.Destroy();
sys_log(0, "<shutdown> Destroying building::CManager...");
SPDLOG_INFO("<shutdown> Destroying building::CManager...");
building_manager.Destroy();
sys_log(0, "<shutdown> Flushing TrafficProfiler...");
SPDLOG_INFO("<shutdown> Flushing TrafficProfiler...");
trafficProfiler.Flush();
destroy();
@ -592,23 +592,21 @@ int start(int argc, char **argv)
// In Windows dev mode, "verbose" option is [on] by default.
bVerbose = true;
#endif
if (!bVerbose)
freopen("stdout", "a", stdout);
bool is_thecore_initialized = thecore_init(25, heartbeat);
if (!is_thecore_initialized)
{
fprintf(stderr, "Could not initialize thecore, check owner of pid, syslog\n");
exit(0);
SPDLOG_CRITICAL("Could not initialize thecore, check owner of pid, syslog");
exit(EXIT_FAILURE);
}
if (false == CThreeWayWar::instance().LoadSetting("forkedmapindex.txt"))
{
if (false == g_bAuthServer)
{
fprintf(stderr, "Could not Load ThreeWayWar Setting file");
exit(0);
SPDLOG_CRITICAL("Could not Load ThreeWayWar Setting file");
exit(EXIT_FAILURE);
}
}
@ -618,25 +616,25 @@ int start(int argc, char **argv)
// Check if the public and internal IP addresses were configured
if (g_szInternalIP[0] == '0') {
fprintf(stderr, "Public IP address could not be automatically detected. Manually set the IP and try again.");
return 0;
SPDLOG_CRITICAL("Public IP address could not be automatically detected. Manually set the IP and try again.");
exit(EXIT_FAILURE);
}
if (g_szPublicIP[0] == '0') {
fprintf(stderr, "Public IP address could not be automatically detected. Manually set the IP and try again.");
return 0;
SPDLOG_CRITICAL("Public IP address could not be automatically detected. Manually set the IP and try again.");
exit(EXIT_FAILURE);
}
// Create a new libevent base and listen for new connections
ev_base = event_base_new();
if (!ev_base) {
sys_err("Libevent base initialization FAILED!");
return 0;
SPDLOG_CRITICAL("Libevent base initialization FAILED!");
exit(EXIT_FAILURE);
}
dns_base = evdns_base_new(ev_base, 1);
if (!dns_base) {
sys_err("Libevent DNS base initialization FAILED!");
return 0;
SPDLOG_CRITICAL("Libevent DNS base initialization FAILED!");
exit(EXIT_FAILURE);
}
sockaddr_in sin = {};
@ -653,10 +651,10 @@ int start(int argc, char **argv)
(const sockaddr*)&sin, sizeof(sin)
);
if (!tcp_listener) {
sys_err("TCP listener initialization FAILED!");
return 0;
SPDLOG_CRITICAL("TCP listener initialization FAILED!");
exit(EXIT_FAILURE);
}
fprintf(stdout, "TCP listening on %s:%u\n", g_szPublicBindIP, mother_port);
SPDLOG_INFO("TCP listening on {}:{}", g_szPublicBindIP, mother_port);
evconnlistener_set_error_cb(tcp_listener, AcceptError);
// Game P2P listener
@ -671,10 +669,10 @@ int start(int argc, char **argv)
(const sockaddr*)&sin, sizeof(sin)
);
if (!p2p_listener) {
sys_err("P2P listener initialization FAILED!");
return 0;
SPDLOG_CRITICAL("P2P listener initialization FAILED!");
exit(EXIT_FAILURE);
}
fprintf(stdout, "P2P listening on %s:%u\n", g_szInternalBindIP, p2p_port);
SPDLOG_INFO("P2P listening on {}:{}", g_szInternalBindIP, p2p_port);
evconnlistener_set_error_cb(p2p_listener, AcceptError);
// Create client connections
@ -687,7 +685,7 @@ int start(int argc, char **argv)
{
if (g_stAuthMasterIP.length() != 0)
{
fprintf(stderr, "SlaveAuth");
SPDLOG_INFO("SlaveAuth");
g_pkAuthMasterDesc = DESC_MANAGER::instance().CreateConnectionDesc(ev_base, dns_base, g_stAuthMasterIP.c_str(), g_wAuthMasterPort, PHASE_P2P, true);
P2P_MANAGER::instance().RegisterConnector(g_pkAuthMasterDesc);
g_pkAuthMasterDesc->SetP2P(g_wAuthMasterPort, g_bChannel);
@ -695,7 +693,7 @@ int start(int argc, char **argv)
}
else
{
fprintf(stderr, "MasterAuth %d", LC_GetLocalType());
SPDLOG_INFO("MasterAuth {}", (int) LC_GetLocalType());
}
}
/* game server to teen server */
@ -708,7 +706,7 @@ int start(int argc, char **argv)
extern unsigned int g_uiSpamBlockScore;
extern unsigned int g_uiSpamReloadCycle;
sys_log(0, "SPAM_CONFIG: duration %u score %u reload cycle %u\n",
SPDLOG_INFO("SPAM_CONFIG: duration {} score {} reload cycle {}",
g_uiSpamBlockDuration, g_uiSpamBlockScore, g_uiSpamReloadCycle);
extern void LoadSpamDB();
@ -721,13 +719,13 @@ int start(int argc, char **argv)
void destroy()
{
sys_log(0, "<shutdown> Canceling ReloadSpamEvent...");
SPDLOG_INFO("<shutdown> Canceling ReloadSpamEvent...");
CancelReloadSpamEvent();
sys_log(0, "<shutdown> regen_free()...");
SPDLOG_INFO("<shutdown> regen_free()...");
regen_free();
sys_log(0, "<shutdown> Closing network stack...");
SPDLOG_INFO("<shutdown> Closing network stack...");
if (tcp_listener) {
evconnlistener_free(tcp_listener);
tcp_listener = nullptr;
@ -748,13 +746,13 @@ void destroy()
ev_base = nullptr;
}
sys_log(0, "<shutdown> event_destroy()...");
SPDLOG_INFO("<shutdown> event_destroy()...");
event_destroy();
sys_log(0, "<shutdown> CTextFileLoader::DestroySystem()...");
SPDLOG_INFO("<shutdown> CTextFileLoader::DestroySystem()...");
CTextFileLoader::DestroySystem();
sys_log(0, "<shutdown> thecore_destroy()...");
SPDLOG_INFO("<shutdown> thecore_destroy()...");
thecore_destroy();
}
@ -840,8 +838,7 @@ int idle()
static void AcceptError(evconnlistener *listener, void *ctx) {
struct event_base *base = evconnlistener_get_base(listener);
int err = EVUTIL_SOCKET_ERROR();
fprintf(stderr, "Got an error %d (%s) on the listener. "
"Shutting down.\n", err, evutil_socket_error_to_string(err));
SPDLOG_CRITICAL("Got an error {} ({}) on the listener. Shutting down.", err, evutil_socket_error_to_string(err));
event_base_loopexit(base, nullptr);
ShutdownOnFatalError();

View File

@ -14,6 +14,8 @@
#include <common/utils.h>
#include <common/service.h>
#include <spdlog/spdlog.h>
#include <iostream>
#include <algorithm>
#include <cmath>

View File

@ -1,15 +1,8 @@
#include <fmt/core.h>
#include <version.h>
void WriteVersion(std::ostream& out) {
out << "Metin2 Game Server version " << __COMMIT_TAG__ << " "
<< "(rev. " << __REVISION__ << ", date: " << __COMMIT_DATE__ << ")"
<< std::endl;
out << "OS: " << __OS_NAME__ << ", "
<< "target arch: " << __CPU_TARGET__ << ", "
<< "compiler: " << __COMPILER__
<< std::endl;
out << std::endl;
void WriteVersion() {
fmt::println("Metin2 Game Server version {} (rev. {}, date: {})", __COMMIT_TAG__, __REVISION__, __COMMIT_DATE__);
fmt::println("OS: {}, target arch: {}, compiler: {}", __OS_NAME__, __CPU_TARGET__, __COMPILER__);
}