1
0
Fork 0

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

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

View File

@ -9,7 +9,7 @@ RUN apt-get update && \
# Install vcpkg and the required libraries
RUN git clone https://github.com/Microsoft/vcpkg.git
RUN bash ./vcpkg/bootstrap-vcpkg.sh
RUN ./vcpkg/vcpkg install boost-system cryptopp effolkronium-random libmysql libevent lzo
RUN ./vcpkg/vcpkg install boost-system cryptopp effolkronium-random libmysql libevent lzo fmt spdlog
COPY . .

View File

@ -102,7 +102,6 @@ This is a very serious security risk and one of the reasons this project is stil
- Migrate `conf.txt` and `CONFIG` to a modern dotenv-like format, which would enable pretty nice Docker images.
- Add a health check to the Docker image.
- Use the [fmt](https://fmt.dev/latest/index.html) library for safe and modern string formatting.
- Use a modern logging library to clean up the current mess.
- Handle kernel signals (SIGTERM, SIGHUP etc.) for gracefully shutting down the game server.
- Improve memory safety.
- Use fixed width integer types instead of Microsoft-style typedefs.

View File

@ -10,6 +10,6 @@
#define __COMPILER__ "@METIN2_COMPILER@"
#define __CPU_TARGET__ "@METIN2_CPU_TARGET@"
void WriteVersion(std::ostream& out);
void WriteVersion();
#endif

View File

@ -12,17 +12,15 @@ include_directories(src)
add_executable(${PROJECT_NAME} ${sources})
# Find dependencies
#
# vcpkg dependencies
#
# Boost
find_package(Boost COMPONENTS system REQUIRED)
target_link_libraries (${PROJECT_NAME} PRIVATE Boost::boost Boost::system)
# Pthreads
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
target_link_libraries(${PROJECT_NAME} PRIVATE Threads::Threads)
# LibBSD
target_link_libraries(${PROJECT_NAME} PRIVATE bsd)
# Libevent
find_package(Libevent CONFIG REQUIRED)
target_link_libraries(${PROJECT_NAME} PRIVATE libevent::core libevent::extra libevent::pthreads)
@ -31,4 +29,24 @@ target_link_libraries(${PROJECT_NAME} PRIVATE libevent::core libevent::extra lib
find_package(effolkronium_random CONFIG REQUIRED)
target_link_libraries(${PROJECT_NAME} PRIVATE effolkronium_random)
# fmt
find_package(fmt CONFIG REQUIRED)
target_link_libraries(${PROJECT_NAME} PRIVATE fmt::fmt)
# spdlog
find_package(spdlog CONFIG REQUIRED)
target_link_libraries(${PROJECT_NAME} PRIVATE spdlog::spdlog)
#
# System-provided dependencies
#
# Pthreads
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
target_link_libraries(${PROJECT_NAME} PRIVATE Threads::Threads)
# LibBSD
target_link_libraries(${PROJECT_NAME} PRIVATE bsd)
target_link_libraries(${PROJECT_NAME} PRIVATE libpoly libsql libthecore)

View File

@ -98,7 +98,7 @@ int CDBManager::Connect(int iSlot, const char * db_address, const int db_port, c
if (iSlot < 0 || iSlot >= SQL_MAX_NUM)
return false;
sys_log(0, "CREATING DIRECT_SQL");
SPDLOG_INFO("CREATING DIRECT_SQL");
m_directSQL[iSlot] = new CAsyncSQL2;
if (!m_directSQL[iSlot]->Setup(db_address, user, pwd, db_name, g_stLocale.c_str(), true, db_port))
{
@ -107,7 +107,7 @@ int CDBManager::Connect(int iSlot, const char * db_address, const int db_port, c
}
sys_log(0, "CREATING MAIN_SQL");
SPDLOG_INFO("CREATING MAIN_SQL");
m_mainSQL[iSlot] = new CAsyncSQL2;
if (!m_mainSQL[iSlot]->Setup(db_address, user, pwd, db_name, g_stLocale.c_str(), false, db_port))
{
@ -115,7 +115,7 @@ int CDBManager::Connect(int iSlot, const char * db_address, const int db_port, c
return false;
}
sys_log(0, "CREATING ASYNC_SQL");
SPDLOG_INFO("CREATING ASYNC_SQL");
m_asyncSQL[iSlot] = new CAsyncSQL2;
if (!m_asyncSQL[iSlot]->Setup(db_address, user, pwd, db_name, g_stLocale.c_str(), false, db_port))
{
@ -166,14 +166,14 @@ unsigned int CDBManager::EscapeString(void *to, const void *from, unsigned int l
void CDBManager::SetLocale(const char * szLocale)
{
const std::string stLocale(szLocale);
sys_log(0, "SetLocale start" );
SPDLOG_DEBUG("SetLocale start");
for (int n = 0; n < SQL_MAX_NUM; ++n)
{
m_mainSQL[n]->SetLocale(stLocale);
m_directSQL[n]->SetLocale(stLocale);
m_asyncSQL[n]->SetLocale(stLocale);
}
sys_log(0, "End setlocale %s", szLocale);
SPDLOG_DEBUG("End setlocale {}", szLocale);
}
void CDBManager::QueryLocaleSet()

View File

@ -62,7 +62,7 @@ void emergency_sig(int sig)
int main()
{
WriteVersion(std::cout);
WriteVersion();
#ifdef __FreeBSD__
_malloc_options = "A";
@ -133,26 +133,26 @@ int Start()
{
if (!CConfig::instance().LoadFile("conf.txt"))
{
fprintf(stderr, "Loading conf.txt failed.\n");
SPDLOG_ERROR("Loading conf.txt failed.");
return false;
}
if (!CConfig::instance().GetValue("TEST_SERVER", &g_test_server))
{
fprintf(stderr, "Real Server\n");
SPDLOG_INFO("Real Server");
}
else
fprintf(stderr, "Test Server\n");
SPDLOG_INFO("Test Server");
if (!CConfig::instance().GetValue("LOG", &g_log))
{
fprintf(stderr, "Log Off");
SPDLOG_INFO("Log Off");
g_log= 0;
}
else
{
g_log = 1;
fprintf(stderr, "Log On");
SPDLOG_INFO("Log On");
}
@ -161,7 +161,7 @@ int Start()
int heart_beat = 50;
if (!CConfig::instance().GetValue("CLIENT_HEART_FPS", &heart_beat))
{
fprintf(stderr, "Cannot find CLIENT_HEART_FPS configuration.\n");
SPDLOG_ERROR("Cannot find CLIENT_HEART_FPS configuration.");
return false;
}
@ -171,7 +171,7 @@ int Start()
{
tmpValue = std::clamp(tmpValue, 3, 30);
log_set_expiration_days(tmpValue);
fprintf(stderr, "Setting log keeping days to %d\n", tmpValue);
SPDLOG_INFO("Setting log keeping days to {}", tmpValue);
}
thecore_init(heart_beat, emptybeat);
@ -182,12 +182,12 @@ int Start()
if (CConfig::instance().GetValue("LOCALE", szBuf, 256))
{
g_stLocale = szBuf;
sys_log(0, "LOCALE set to %s", g_stLocale.c_str());
SPDLOG_INFO("LOCALE set to {}", g_stLocale.c_str());
// CHINA_DISABLE_HOTBACKUP
if ("gb2312" == g_stLocale)
{
sys_log(0, "CIBN_LOCALE: DISABLE_HOTBACKUP");
SPDLOG_INFO("CIBN_LOCALE: DISABLE_HOTBACKUP");
g_bHotBackup = false;
}
// END_OF_CHINA_DISABLE_HOTBACKUP
@ -198,7 +198,7 @@ int Start()
{
if (iDisableHotBackup)
{
sys_log(0, "CONFIG: DISABLE_HOTBACKUP");
SPDLOG_INFO("CONFIG: DISABLE_HOTBACKUP");
g_bHotBackup = false;
}
}
@ -206,7 +206,7 @@ int Start()
if (!CConfig::instance().GetValue("TABLE_POSTFIX", szBuf, 256))
{
sys_err("TABLE_POSTFIX not configured use default");
SPDLOG_WARN("TABLE_POSTFIX not configured use default");
szBuf[0] = '\0';
}
@ -215,20 +215,20 @@ int Start()
if (CConfig::instance().GetValue("PLAYER_CACHE_FLUSH_SECONDS", szBuf, 256))
{
str_to_number(g_iPlayerCacheFlushSeconds, szBuf);
sys_log(0, "PLAYER_CACHE_FLUSH_SECONDS: %d", g_iPlayerCacheFlushSeconds);
SPDLOG_INFO("PLAYER_CACHE_FLUSH_SECONDS: {}", g_iPlayerCacheFlushSeconds);
}
if (CConfig::instance().GetValue("ITEM_CACHE_FLUSH_SECONDS", szBuf, 256))
{
str_to_number(g_iItemCacheFlushSeconds, szBuf);
sys_log(0, "ITEM_CACHE_FLUSH_SECONDS: %d", g_iItemCacheFlushSeconds);
SPDLOG_INFO("ITEM_CACHE_FLUSH_SECONDS: {}", g_iItemCacheFlushSeconds);
}
// MYSHOP_PRICE_LIST
if (CConfig::instance().GetValue("ITEM_PRICELIST_CACHE_FLUSH_SECONDS", szBuf, 256))
{
str_to_number(g_iItemPriceListTableCacheFlushSeconds, szBuf);
sys_log(0, "ITEM_PRICELIST_CACHE_FLUSH_SECONDS: %d", g_iItemPriceListTableCacheFlushSeconds);
SPDLOG_INFO("ITEM_PRICELIST_CACHE_FLUSH_SECONDS: {}", g_iItemPriceListTableCacheFlushSeconds);
}
// END_OF_MYSHOP_PRICE_LIST
//
@ -241,7 +241,7 @@ int Start()
int iIDStart;
if (!CConfig::instance().GetValue("PLAYER_ID_START", &iIDStart))
{
sys_err("PLAYER_ID_START not configured");
SPDLOG_ERROR("PLAYER_ID_START not configured");
return false;
}
@ -249,7 +249,7 @@ int Start()
if (CConfig::instance().GetValue("NAME_COLUMN", szBuf, 256))
{
fprintf(stderr, "%s %s", g_stLocaleNameColumn.c_str(), szBuf);
SPDLOG_INFO("{} {}", g_stLocaleNameColumn, szBuf);
g_stLocaleNameColumn = szBuf;
}
@ -260,7 +260,7 @@ int Start()
if (CConfig::instance().GetValue("SQL_PLAYER", line, 256))
{
sscanf(line, " %s %s %s %s %d ", szAddr, szDB, szUser, szPassword, &iPort);
sys_log(0, "connecting to MySQL server (player)");
SPDLOG_DEBUG("Connecting to MySQL server (player)");
int iRetry = 5;
@ -268,20 +268,18 @@ int Start()
{
if (CDBManager::instance().Connect(SQL_PLAYER, szAddr, iPort, szDB, szUser, szPassword))
{
sys_log(0, " OK");
SPDLOG_INFO("Connected to MySQL server (player)");
break;
}
sys_log(0, " failed, retrying in 5 seconds");
fprintf(stderr, " failed, retrying in 5 seconds");
SPDLOG_ERROR("Connection to MySQL server (player) failed, retrying in 5 seconds");
sleep(5);
} while (iRetry--);
fprintf(stderr, "Success PLAYER\n");
SetPlayerDBName(szDB);
}
else
{
sys_err("SQL_PLAYER not configured");
SPDLOG_ERROR("SQL_PLAYER not configured");
return false;
}
@ -368,19 +366,17 @@ int Start()
return false;
}
sys_log(0, "ClientManager initialization.. ");
if (!CClientManager::instance().Initialize())
{
sys_log(0, " failed");
SPDLOG_ERROR("ClientManager initialization failed");
return false;
}
sys_log(0, " OK");
SPDLOG_INFO("ClientManager initialization OK");
if (!PlayerHB::instance().Initialize())
{
sys_err("cannot initialize player hotbackup");
SPDLOG_ERROR("cannot initialize player hotbackup");
return false;
}

View File

@ -17,6 +17,8 @@
#include <common/stl.h>
#include <common/service.h>
#include <spdlog/spdlog.h>
#include <memory>
#include <algorithm>
#include <iostream>

View File

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

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");
// 로케일 정보를 가져오자
// <경고> 쿼리문에 절대 조건문(WHERE) 달지 마세요. (다른 지역에서 문제가 생길수 있습니다)

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__);
}