Commit Graph
5 Commits
Author SHA1 Message Date
ThomasandClaude Sonnet 5 725620e23c Fix respawn/spawn timers racing ahead under multi-threading
POSIX clock() sums CPU time across every thread in the process, unlike
Windows' clock() which tracks wall-clock milliseconds. With several
worker threads running, respawn/spawn/AI timers based on clock() raced
far ahead of real elapsed time. Switch spawn-timer bookkeeping to
time(NULL)/time_t (seconds) throughout the world server, and add a
portable clock() shim in sockets.h (backed by CLOCK_MONOTONIC,
millisecond resolution) for remaining call sites so CLOCKS_PER_SEC==1000
still holds like it did on Windows.

Also: fix MapDelay/VisualDelay/WorldDelay being passed to usleep() (us)
without converting from their configured milliseconds; fix the shutdown
timer likewise; stop leaking the temporary actor used to run an NPC's
AIP script; fix CleanDrops() skipping the element that shifts into
position after an erase.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-07-09 06:35:05 +02:00
92thmsandClaude Sonnet 5 1f626c6b93 Fix DB warning and a client-connection-blocking accept() busy-loop
- runtime.sql: widen starttime to varchar(32). ctime() produces 25 chars;
  MariaDB's default strict mode rejects the 20-char column instead of
  silently truncating like the original MySQL 5.0 target did.

- SocketServer.cpp/SocketBase.cpp: the accept-loop's select() used `maxfd`
  set only from `sock`, never updated for the ISC sockets (sckISC/sckISCII).
  Any fd beyond nfds is left however FD_SET last set it, since select()
  never examines it -- so those bits stayed permanently "set", and the
  server treated them as always-ready.  For the login server specifically
  this was fatal: its sckISC is created but never listen()'d (the login
  server has no inbound ISC use), so accept() on it returned EINVAL on
  every single loop iteration, spinning the login server's CPU and
  spamming the log without ever getting to the real client-facing accept()
  in a timely way. Root-caused with a real client connecting for the first
  time (this path was never exercised end-to-end before). Fixed by
  including the ISC sockets in maxfd and skipping the ISC accept branch
  entirely for the login server. Also initialize sckISC/sckISCII to
  INVALID_SOCKET in the constructor -- they were previously left
  uninitialized for server types that never touch them.

- tools/rose_login_test.cpp: protocol-level login smoke test. Links
  directly against Src/Common/rosecrypt.cpp (the server's own encryption
  code) rather than reimplementing the crypto, so there's no risk of a
  second, subtly-wrong implementation. Documents the wire handshake
  (0x703 encryption request -> 0x7FF -> 0x708 login, password[32]+username[16]
  payload) for future reference.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-07-08 07:12:52 +00:00
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
purpleyouko a320bbe470 Modified packet logging to include server name and save both in and out to the same file 2025-12-26 14:28:59 -06:00
purpleyouko cfdc19df45 added source folders 2025-08-11 11:09:09 -05:00