9 Commits

16 changed files with 110 additions and 115 deletions

View File

@ -1,8 +1,5 @@
cmake_minimum_required(VERSION 3.12)
# Build mode debug/release?
set(CMAKE_BUILD_TYPE Debug)
# Set C++ standard to C++17
set(CMAKE_CXX_STANDARD 17)

View File

@ -3,9 +3,12 @@ WORKDIR /app
# Update the system and install various dependencies
RUN apt-get update && \
apt-get install -y git cmake build-essential tar curl zip unzip pkg-config autoconf python3 \
apt-get install -y git cmake ninja-build build-essential tar curl zip unzip pkg-config autoconf python3 \
libdevil-dev libncurses5-dev libbsd-dev
# Arm specific
ENV VCPKG_FORCE_SYSTEM_BINARIES=1
# Install vcpkg and the required libraries
RUN git clone https://github.com/Microsoft/vcpkg.git
RUN bash ./vcpkg/bootstrap-vcpkg.sh

View File

@ -39,7 +39,7 @@ Install `vcpkg` according to the [lastest instructions](https://vcpkg.io/en/gett
Build and install the required libraries:
```shell
vcpkg install boost-system cryptopp effolkronium-random libmysql libevent lzo
vcpkg install boost-system cryptopp effolkronium-random libmysql libevent lzo fmt spdlog
```
Then, it's time to build your binaries. Your commands should look along the lines of:
@ -80,6 +80,7 @@ goodies you wish. Also, a lot of time.
- Switched to the [effolkronium/random PRNG](https://github.com/effolkronium/random) instead of the standard C functions.
- Refactored macros to modern C++ functions.
- Network settings are manually configurable through the `PUBLIC_IP`, `PUBLIC_BIND_IP`, `INTERNAL_IP`, `INTERNAL_BIND_IP` settings in the `CONFIG` file. (Might need further work)
- Refactored logging to use [spdlog](https://github.com/gabime/spdlog) for more consistent function calls.
## 4. Bugfixes
**WARNING: This project is based on the "kraizy" leak. That was over 10 years ago.
@ -88,6 +89,7 @@ This is a very serious security risk and one of the reasons this project is stil
### Gameplay
- Fixed invisibility bug on login/respawn/teleport etc.
- Fixed player level not updating [(thread)](https://metin2.dev/topic/30612-official-level-update-fix-reversed/)
### Exploits
- See the warning above :(

View File

@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 3.8)
project(db CXX)
file(GLOB_RECURSE sources
src/*.cpp src/*.h
src/*.cpp src/*.h
)
# Add the src directory to the include path
@ -11,6 +11,15 @@ include_directories(src)
add_executable(${PROJECT_NAME} ${sources})
# Set the default log level based on the build type
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
message(STATUS "This is a debug build. Log level will be set to 'trace' for target '${PROJECT_NAME}'.")
target_compile_definitions(${PROJECT_NAME} PRIVATE SPDLOG_ACTIVE_LEVEL=SPDLOG_LEVEL_TRACE)
endif()
# Treat char variables as signed, especially useful for ARM builds
target_compile_options(${PROJECT_NAME} PUBLIC -fsigned-char)
# Find dependencies
#
@ -29,10 +38,6 @@ 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)
#
# System-provided dependencies
#

View File

@ -61,6 +61,7 @@ void emergency_sig(int sig)
int main()
{
WriteVersion();
log_init();
#ifdef __FreeBSD__
_malloc_options = "A";
@ -114,6 +115,8 @@ int main()
SPDLOG_DEBUG("WAITING_QUERY_COUNT {}", iCount);
}
log_destroy();
return 1;
}
@ -151,13 +154,11 @@ int Start()
return false;
}
log_set_expiration_days(3);
if (CConfig::instance().GetValue("LOG_KEEP_DAYS", &tmpValue))
if (CConfig::instance().GetValue("LOG_LEVEL", &tmpValue))
{
tmpValue = std::clamp(tmpValue, 3, 30);
log_set_expiration_days(tmpValue);
SPDLOG_INFO("Setting log keeping days to {}", tmpValue);
SPDLOG_INFO("Setting log level to {}", tmpValue);
tmpValue = std::clamp(tmpValue, SPDLOG_LEVEL_TRACE, SPDLOG_LEVEL_OFF);
log_set_level(tmpValue);
}
thecore_init(heart_beat, emptybeat);

View File

@ -3,13 +3,23 @@ cmake_minimum_required(VERSION 3.8)
project(game CXX)
file(GLOB_RECURSE sources
src/*.cpp src/*.h
src/*.cpp src/*.h
)
# Add the src directory to the include path
include_directories(src)
add_executable(${PROJECT_NAME} ${sources})
# Set the default log level based on the build type
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
message(STATUS "This is a debug build. Log level will be set to 'trace' for target '${PROJECT_NAME}'.")
target_compile_definitions(${PROJECT_NAME} PRIVATE SPDLOG_ACTIVE_LEVEL=SPDLOG_LEVEL_TRACE)
endif()
# Treat char variables as signed, especially useful for ARM builds
target_compile_options(${PROJECT_NAME} PUBLIC -fsigned-char)
# Find dependencies
#
@ -43,10 +53,6 @@ endif (LZO_FOUND)
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)
#
# System-provided dependencies
#

View File

@ -5851,7 +5851,7 @@ void CHARACTER::ResetPoint(int iLv)
{
BYTE bJob = GetJob();
PointChange(POINT_LEVEL, iLv - GetLevel());
PointChange(POINT_LEVEL, iLv - GetLevel(), false, true);
SetRealPoint(POINT_ST, JobInitialPoints[bJob].st);
SetPoint(POINT_ST, GetRealPoint(POINT_ST));

View File

@ -663,10 +663,6 @@ void config_init(const string& st_localeServiceName)
}
// END_SKILL_POWER_BY_LEVEL
// LOG_KEEP_DAYS_EXTEND
log_set_expiration_days(2);
// END_OF_LOG_KEEP_DAYS_EXTEND
while (fgets(buf, 256, fp))
{
parse_token(buf, token_string, value_string);
@ -692,11 +688,11 @@ void config_init(const string& st_localeServiceName)
continue;
}
TOKEN("log_keep_days")
TOKEN("log_level")
{
int i = 0;
str_to_number(i, value_string);
log_set_expiration_days(std::clamp(i, 1, 90));
log_set_level(std::clamp(i, SPDLOG_LEVEL_TRACE, SPDLOG_LEVEL_OFF));
continue;
}

View File

@ -332,6 +332,7 @@ int main(int argc, char **argv)
ilInit(); // DevIL Initialize
WriteVersion();
log_init();
SECTREE_MANAGER sectree_manager;
CHARACTER_MANAGER char_manager;
@ -486,6 +487,7 @@ int main(int argc, char **argv)
trafficProfiler.Flush();
destroy();
log_destroy();
#ifdef DEBUG_ALLOC
DebugAllocator::StaticTearDown();
@ -499,7 +501,6 @@ void usage()
printf("Option list\n"
"-p <port> : bind port number (port must be over 1024)\n"
"-l <level> : sets log level\n"
"-v : log to stdout\n"
"-r : do not load regen tables\n"
"-t : traffic proflie on\n");
}
@ -508,15 +509,13 @@ int start(int argc, char **argv)
{
std::string st_localeServiceName;
bool bVerbose = false;
//_malloc_options = "A";
#if defined(__FreeBSD__) && defined(DEBUG_ALLOC)
_malloc_message = WriteMallocMessage;
#endif
int ch;
while ((ch = getopt(argc, argv, "n:p:verl:tI:")) != -1)
while ((ch = getopt(argc, argv, "n:p:erl:tI:")) != -1)
{
char* ep = NULL;
@ -556,10 +555,6 @@ int start(int argc, char **argv)
break;
// END_OF_LOCALE_SERVICE
case 'v': // verbose
bVerbose = true;
break;
case 'r':
g_bNoRegen = true;
break;
@ -588,11 +583,6 @@ int start(int argc, char **argv)
config_init(st_localeServiceName);
// END_OF_LOCALE_SERVICE
#ifdef __WIN32__
// In Windows dev mode, "verbose" option is [on] by default.
bVerbose = true;
#endif
bool is_thecore_initialized = thecore_init(25, heartbeat);
if (!is_thecore_initialized)

View File

@ -862,7 +862,7 @@ namespace quest
ch->PointChange(POINT_SUB_SKILL, newLevel < 10 ? 0 : newLevel - std::max(ch->GetLevel(), 9));
ch->PointChange(POINT_STAT, ((std::clamp(newLevel, 1, 90) - ch->GetLevel()) * 3) + ch->GetPoint(POINT_LEVEL_STEP));
//<2F><><EFBFBD><EFBFBD>
ch->PointChange(POINT_LEVEL, newLevel - ch->GetLevel());
ch->PointChange(POINT_LEVEL, newLevel - ch->GetLevel(), false, true);
//HP, SP
ch->SetRandomHP((newLevel - 1) * Random::get(JobInitialPoints[ch->GetJob()].hp_per_lv_begin, JobInitialPoints[ch->GetJob()].hp_per_lv_end));
ch->SetRandomSP((newLevel - 1) * Random::get(JobInitialPoints[ch->GetJob()].sp_per_lv_begin, JobInitialPoints[ch->GetJob()].sp_per_lv_end));

View File

@ -41,7 +41,7 @@ EVENTFUNC(regen_mob_event)
int iMapIndex = info->dwMapIndex;
char filename[128];
char filename[256];
std::string szFilename(GetSungziMapPath());

View File

@ -14,7 +14,11 @@ include_directories("include")
# Create shared library
add_library(${PROJECT_NAME} STATIC ${SOURCES})
# Find dependencies
#
# vcpkg dependencies
#
# Boost
find_package(Boost REQUIRED)
include_directories(${Boost_INCLUDE_DIRS})
target_link_libraries(${PROJECT_NAME} PRIVATE ${Boost_LIBRARIES})

View File

@ -1,12 +1,6 @@
#pragma once
extern int log_init(void);
extern void log_destroy(void);
extern int log_init();
extern void log_destroy();
// <20>α<EFBFBD> <20><><EFBFBD><EFBFBD> ó<><C3B3> (<28><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> bitvector<6F><72> ó<><C3B3><EFBFBD>ȴ<EFBFBD>)
extern void log_set_level(unsigned int level);
extern void log_unset_level(unsigned int level);
// <20>α<EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>ŭ <20><><EFBFBD><EFBFBD><EFBFBD>ϴ°<CFB4><C2B0><EFBFBD> <20><><EFBFBD><EFBFBD> <20>Լ<EFBFBD>
extern void log_set_expiration_days(unsigned int days);
extern int log_get_expiration_days(void);

View File

@ -28,7 +28,6 @@
#include <bsd/string.h>
#define SPDLOG_ACTIVE_LEVEL SPDLOG_LEVEL_TRACE
#include <spdlog/spdlog.h>
#include <pthread.h>

View File

@ -1,39 +1,74 @@
#define __LIBTHECORE__
#include "stdafx.h"
#include "spdlog/sinks/stdout_color_sinks.h"
#include "spdlog/sinks/daily_file_sink.h"
#include "spdlog/sinks/stdout_sinks.h"
#define SYSLOG_FILENAME "syslog.txt"
#define SYSERR_FILENAME "syserr.txt"
unsigned int log_keep_days = 3;
void log_set_level(unsigned int bit)
int log_init()
{
}
void log_unset_level(unsigned int bit)
{
}
// Replace the default logger with a placeholder in order to avoid a name clash
spdlog::set_default_logger(spdlog::stderr_logger_mt("placeholder_name"));
void log_set_expiration_days(unsigned int days)
{
log_keep_days = days;
}
// Create the new logger
std::vector<spdlog::sink_ptr> sinks;
sinks.push_back(std::make_shared<spdlog::sinks::stdout_sink_mt>());
sinks.push_back(std::make_shared<spdlog::sinks::daily_file_sink_st>("log/daily", 23, 59));
auto combined_logger = std::make_shared<spdlog::logger>("", begin(sinks), end(sinks));
int log_get_expiration_days(void)
{
return log_keep_days;
}
//register it if you need to access it globally
//spdlog::register_logger(combined_logger);
int log_init(void)
{
//spdlog::set_level(spdlog::level::debug);
// Set the new logger as default
spdlog::set_default_logger(combined_logger);
// Set flush period and default log level
spdlog::flush_every(std::chrono::seconds(5));
spdlog::set_level(spdlog::level::info);
return 1;
}
void log_destroy(void)
void log_destroy()
{
spdlog::shutdown();
}
void log_set_level(unsigned int level)
{
spdlog::level::level_enum spdlog_level;
switch (level) {
case SPDLOG_LEVEL_TRACE:
spdlog_level = spdlog::level::trace;
break;
case SPDLOG_LEVEL_DEBUG:
spdlog_level = spdlog::level::debug;
break;
case SPDLOG_LEVEL_INFO:
spdlog_level = spdlog::level::info;
break;
case SPDLOG_LEVEL_WARN:
spdlog_level = spdlog::level::warn;
break;
case SPDLOG_LEVEL_ERROR:
spdlog_level = spdlog::level::err;
break;
case SPDLOG_LEVEL_CRITICAL:
spdlog_level = spdlog::level::critical;
break;
case SPDLOG_LEVEL_OFF:
spdlog_level = spdlog::level::off;
break;
default:
return;
}
spdlog::set_level(spdlog_level);
}

View File

@ -6,7 +6,6 @@
*/
#define __LIBTHECORE__
#include "stdafx.h"
#include "memory.h"
LPHEART thecore_heart = NULL;
@ -14,37 +13,6 @@ volatile int shutdowned = false;
volatile int tics = 0;
unsigned int thecore_profiler[NUM_PF];
static int pid_init(void)
{
#ifdef __WIN32__
return true;
#else
FILE* fp;
if ((fp = fopen("pid", "w")))
{
fprintf(fp, "%d", getpid());
fclose(fp);
SPDLOG_INFO("Start of pid: {}", getpid());
}
else
{
SPDLOG_ERROR("pid_init(): could not open file for writing. (filename: ./pid)");
return false;
}
return true;
#endif
}
static void pid_deinit(void)
{
#ifdef __WIN32__
return;
#else
remove("./pid");
SPDLOG_INFO("End of pid");
#endif
}
int thecore_init(int fps, HEARTFUNC heartbeat_func)
{
#if defined(__WIN32__) || defined(__linux__)
@ -55,9 +23,6 @@ int thecore_init(int fps, HEARTFUNC heartbeat_func)
#endif
signal_setup();
if (!log_init() || !pid_init())
return false;
thecore_heart = heart_new(1000000 / fps, heartbeat_func);
return true;
}
@ -89,8 +54,6 @@ int thecore_idle(void)
void thecore_destroy(void)
{
pid_deinit();
log_destroy();
}
int thecore_pulse(void)