Files
ROSS/CMakeLists.txt
T
92thmsandClaude Sonnet 5 764fcb3b3f Port server to Linux and add Docker Compose deployment
Rebuilds (not Wine) the login/char/world servers natively for Linux via
CMake, and ships a single Docker image plus docker-compose stack (MariaDB +
3 servers) with all settings configurable via .env.

Linux portability:
- Src/Common/compat.h shims MSVC-only CRT calls (fopen_s, _strdup,
  strncpy_s, sprintf_s, SYSTEMTIME/GetLocalTime, WSAGetLastError, __cdecl)
  and adds a case-insensitive/backslash-tolerant path resolver for the
  Windows-authored STB/AIP data file paths.
- Fixed case-sensitive header includes and filenames (charserver.h vs
  CharServer.h, worldserver.h vs WorldServer.h, ../common vs ../Common).
- rose_inet_addr() resolves hostnames (not just literal IPs) for the
  server-to-server links, so docker-compose service names work.

Fixed three real bugs that only crashed on 64-bit Linux (silently tolerated
on 32-bit Windows):
- CIntStb::LoadSTB had an inverted fopen success/failure check, so STB game
  data (zones, items, etc.) was never actually loaded.
- GenerateCryptTables allocated its pointer table with sizeof(unsigned)
  instead of sizeof(unsigned*) -- a 1x vs 2x-size heap overflow on 64-bit.
- Crypto bit-twiddling relies throughout on signed-overflow-as-wraparound,
  which is UB in C++; GCC's -O3 exploited it and miscompiled
  GenerateCryptTables (Release-only crash). Fixed via -fwrapv.
Plus smaller fixes: off-by-one array bounds (inventory/storage/sell data),
SO_REUSEADDR on server sockets (containers restarting in the same netns hit
TIME_WAIT otherwise), and a va_list reused across multiple vprintf/vfprintf
calls in Log() that garbled every formatted log line on the Linux ABI.

Docker:
- CMakeLists.txt builds all three servers + shared Common code.
- Dockerfile: multi-stage build, one runtime image for all three servers,
  server role selected via `command: [login|char|world]`.
- docker-compose.yml: MariaDB (auto-imports database sql files/ on first
  run) + login/char/world (single channel), config rendered from
  docker/conf/*.conf.tmpl via envsubst at container start.
- .env.example documents every setting (ports, server names, rates,
  inter-server passwords, PUBLIC_HOST for internet-facing deployments).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-07-08 06:32:39 +00:00

151 lines
5.0 KiB
CMake

cmake_minimum_required(VERSION 3.16)
project(ROSEServers CXX)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS ON)
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release)
endif()
find_package(Threads REQUIRED)
# MariaDB/MySQL client library and headers (provided by the distro, e.g.
# libmariadb-dev). Falls back to pkg-config if the CMake package isn't found.
find_path(MYSQL_INCLUDE_DIR
NAMES mysql.h
PATH_SUFFIXES mysql mariadb
)
find_library(MYSQL_LIBRARY
NAMES mariadb mysqlclient
)
if(NOT MYSQL_INCLUDE_DIR OR NOT MYSQL_LIBRARY)
find_package(PkgConfig REQUIRED)
pkg_check_modules(MYSQL REQUIRED libmariadb)
endif()
add_compile_options(
-Wno-write-strings
-Wno-narrowing
# This 2006-era codebase relies throughout on signed-integer overflow
# wrapping (packet/crypto bit twiddling). That's UB in C++; at -O2/-O3
# GCC exploits it and miscompiles (observed: GenerateCryptTables SIGSEGV
# in Release builds only). -fwrapv makes overflow well-defined instead
# of auditing every arithmetic expression in the tree.
-fwrapv
-include "${CMAKE_SOURCE_DIR}/Src/Common/compat.h"
)
add_compile_definitions(_CRT_SECURE_NO_WARNINGS)
set(COMMON_SOURCES
"Src/Common/config.cpp"
"Src/Common/database/database.cpp"
"Src/Common/globals.cpp"
"Src/Common/log.cpp"
"Src/Common/rosecrypt.cpp"
"Src/Common/seh.cpp"
"Src/Common/SocketBase.cpp"
"Src/Common/SocketClient.cpp"
"Src/Common/SocketServer.cpp"
)
set(COMMON_INCLUDES
"${CMAKE_SOURCE_DIR}/Src/Common"
"${CMAKE_SOURCE_DIR}/Src/Common/database"
${MYSQL_INCLUDE_DIR}
${MYSQL_INCLUDE_DIRS}
)
set(COMMON_LIBS
Threads::Threads
${MYSQL_LIBRARY}
${MYSQL_LIBRARIES}
)
# ---------------------------------------------------------------------------
# Login Server
# ---------------------------------------------------------------------------
add_executable(loginserver
${COMMON_SOURCES}
"Src/Login Server/extrafunction.cpp"
"Src/Login Server/loginclient.cpp"
"Src/Login Server/loginpackets.cpp"
"Src/Login Server/loginserver.cpp"
"Src/Login Server/main.cpp"
"Src/Login Server/signal.cpp"
)
target_include_directories(loginserver PRIVATE ${COMMON_INCLUDES} "${CMAKE_SOURCE_DIR}/Src/Login Server")
target_link_libraries(loginserver PRIVATE ${COMMON_LIBS})
# ---------------------------------------------------------------------------
# Char Server
# ---------------------------------------------------------------------------
add_executable(charserver
${COMMON_SOURCES}
"Src/Char Server/charclient.cpp"
"Src/Char Server/charpackets.cpp"
"Src/Char Server/charserver.cpp"
"Src/Char Server/clan.cpp"
"Src/Char Server/community.cpp"
"Src/Char Server/extrafunctions.cpp"
"Src/Char Server/main.cpp"
"Src/Char Server/signal.cpp"
)
target_include_directories(charserver PRIVATE ${COMMON_INCLUDES} "${CMAKE_SOURCE_DIR}/Src/Char Server")
target_link_libraries(charserver PRIVATE ${COMMON_LIBS})
# ---------------------------------------------------------------------------
# World Server
# ---------------------------------------------------------------------------
add_executable(worldserver
${COMMON_SOURCES}
"Src/World Server/aip/AiActions.cpp"
"Src/World Server/aip/AiConditions.cpp"
"Src/World Server/aip/Aip.cpp"
"Src/World Server/battle.cpp"
"Src/World Server/Buff.cpp"
"Src/World Server/character.cpp"
"Src/World Server/charevent.cpp"
"Src/World Server/charfunctions.cpp"
"Src/World Server/charstats.cpp"
"Src/World Server/clan.cpp"
"Src/World Server/extrafunctions.cpp"
"Src/World Server/gmcmds.cpp"
"Src/World Server/itemdata.cpp"
"Src/World Server/main.cpp"
"Src/World Server/MainProcess.cpp"
"Src/World Server/mapfunctions.cpp"
"Src/World Server/Monster.cpp"
"Src/World Server/MonsterDamage.cpp"
"Src/World Server/MonsterEvents.cpp"
"Src/World Server/monsterfunctions.cpp"
"Src/World Server/MonsterStats.cpp"
"Src/World Server/Party.cpp"
"Src/World Server/partyfunctions.cpp"
"Src/World Server/player.cpp"
"Src/World Server/playerdata.cpp"
"Src/World Server/playerfunctions.cpp"
"Src/World Server/playerquest.cpp"
"Src/World Server/playerstats.cpp"
"Src/World Server/quest/QuestActions.cpp"
"Src/World Server/quest/QuestConditions.cpp"
"Src/World Server/quest/Quests.cpp"
"Src/World Server/ServerFunctions.cpp"
"Src/World Server/Signal.cpp"
"Src/World Server/startup.cpp"
"Src/World Server/stbhandler.cpp"
"Src/World Server/stb_manager.cpp"
"Src/World Server/stlhandler.cpp"
"Src/World Server/strhashing.cpp"
"Src/World Server/worldmap.cpp"
"Src/World Server/WorldMonster.cpp"
"Src/World Server/worldpackets.cpp"
"Src/World Server/Worldprocess.cpp"
"Src/World Server/worldserver.cpp"
)
target_include_directories(worldserver PRIVATE ${COMMON_INCLUDES} "${CMAKE_SOURCE_DIR}/Src/World Server")
target_link_libraries(worldserver PRIVATE ${COMMON_LIBS})
install(TARGETS loginserver charserver worldserver RUNTIME DESTINATION bin)