How herculesws/hercules works
Purpose and runtime topology
Hercules is a C-based MMORPG server package descended from Athena. It runs as cooperating server processes rather than a web application: login authentication, character/account coordination, authoritative map/game simulation, and an optional HTTP API. Build targets are defined by CMakeLists.txt and src/CMakeLists.txt; operational launchers include login-server.sh, char-server.sh, map-server.sh, and api-server.sh.
Process entry points and control flow
1. Login server accepts client authentication, manages accounts and IP bans, then directs authenticated users onward. Core boundary: src/login/login.c, src/login/account.c, src/login/ipban.c.
2. Character server owns character-selection and inter-server persistence services; it mediates login↔map communication and manages durable features such as parties, guilds, mail, storage, and quests. Core paths: src/char/char.c, src/char/inter.c, src/char/mapif.c.
3. Map server is the gameplay authority: client packets enter through its client interface, then drive player, combat, skill, map, NPC, and world systems. Core paths: src/map/map.c, src/map/clif.c, src/map/pc.c.
4. Inter-process socket protocols separate login, character, and map responsibilities; packet contracts are centralized in src/common/charloginpackets.h, src/common/charmappackets.h, and src/common/mapcharpackets.h.
Map simulation and game domain
The map server is the largest bounded context. It combines spatial/map management, pathfinding, units, player state, mobs, items, statuses, and combat rules. Key implementation anchors are src/map/map.c, src/map/path.c, src/map/unit.c, src/map/mob.c, src/map/status.c, src/map/battle.c, src/map/skill.c, and src/map/itemdb.c. Client-version packet compatibility is a material integration boundary, represented by src/map/packets.h and versioned packet tables under src/common/packets/.
Content loading and scripting boundary
Runtime behavior is heavily data-driven. Server startup loads game database definitions from db/, collision/navigation map caches from maps/re/ or maps/pre-re/, and NPC scripts from npc/. The NPC scripting VM and parser are in src/map/script.c and src/map/npc.c; script inclusion roots are npc/scripts.conf and the ruleset-specific npc/re/scripts.conf / npc/pre-re/scripts.conf. Renewal (re) and pre-renewal (pre-re) are parallel content variants across database, NPC, and map-cache assets.
Persistence and configuration
MariaDB/MySQL is the primary external state store, configured through conf/global/sql_connection.conf; baseline schemas and migrations are under sql-files/main.sql, sql-files/logs.sql, and sql-files/upgrades/. The character and map services use SQL-facing persistence layers such as src/char/inter.c and src/map/mapreg_sql.c; common SQL abstraction is src/common/sql.c. Process-specific networking and behavior are configured in conf/login/login-server.conf, conf/char/char-server.conf, and conf/map/map-server.conf, with import templates supporting local overrides.
HTTP API and extensibility
The optional API server is a separate HTTP runtime with request parsing, routing/handlers, JSON serialization, and interfaces to the account/character side. Its core is src/api/api.c, src/api/httpparser.c, src/api/handlers.c, and src/api/jsonwriter.c; configuration is conf/api/api-server.conf. HTTP parsing depends on vendored parsers in 3rdparty/llhttp/ and 3rdparty/multipart-parser/. The Hercules Plugin Manager provides native extension hooks across server processes through src/common/HPM.c, src/plugins/HPMHooking/HPMHooking.c, and per-process HPM* modules.
Shared platform layer and delivery
src/common/ supplies lifecycle, sockets, timers, threading, configuration parsing, logging, memory management, packet primitives, and database access; architectural anchors are src/common/core.c, src/common/socket.c, src/common/timer.c, and src/common/conf.c. The project builds with CMake across GCC, Clang, and MSVC, and vendors libconfig plus protocol parsers in 3rdparty/. CI covers these platform/database combinations through workflows including .github/workflows/build.yml, .github/workflows/mariadb.yml, and .github/workflows/mysql.yml.
Main entry points: map.c Map simulation · char.c Character server · login.c Login server · core.c Common platform
Components 16
Server runtimes
Cooperating native server processes.
- Login server · Authenticates clients and enforces account/IP policies.
src/login/login.c - Character server · Owns character selection and inter-server persistence.
src/char/char.c - Map client interface · Accepts gameplay client packets.
src/map/clif.c - API server · Optional HTTP routing, handlers, and JSON responses.
src/api/api.c
Map gameplay
Authoritative game simulation and data-driven behavior.
- Map simulation · Runs player, combat, skill, unit, and world rules.
src/map/map.c - World navigation · Manages maps, collision data, and pathfinding.
src/map/path.c - NPC scripting · Parses and executes NPC-driven gameplay.
src/map/script.c - Ruleset content · Parallel renewal and pre-renewal databases, NPCs, and map caches.
Shared platform
Common runtime services and protocol contracts.
- Inter-server contracts · Login/char/map socket protocol contracts.
src/common/charloginpackets.h - Common platform · Lifecycle, sockets, timers, configuration, logging, and SQL abstractions.
src/common/core.c - Plugin manager · Native hooks available across server processes.
src/common/HPM.c
Persistence
SQL-backed durable state and schema assets.
- SQL persistence · Character and map persistence over the shared SQL abstraction.
src/char/inter.c - MariaDB/MySQL · Primary durable account and game state store.
conf/global/sql_connection.conf - Schemas & migrations
sql-files/main.sql
Other components
- CMake build
CMakeLists.txt - Server configuration · Per-process networking and behavior settings.
conf/login/login-server.conf
Connections 30
- CMake build → Login server: builds
- CMake build → Character server: builds
- CMake build → Map simulation: builds
- CMake build → API server: builds
- Login server → Character server: authenticated sessions
- Character server → Map simulation: map handoff
- Inter-server contracts → Login server: protocol
- Inter-server contracts → Character server: protocol
- Inter-server contracts → Map simulation: protocol
- Map client interface → Map simulation: client actions
- Map simulation → World navigation: spatial queries
- Map simulation → NPC scripting: script events
- Ruleset content → Map simulation: loads definitions
- Ruleset content → World navigation: loads map caches
- Ruleset content → NPC scripting: loads NPC scripts
- Character server → SQL persistence: characters and services
- Map simulation → SQL persistence: map state
- SQL persistence → MariaDB/MySQL: SQL
- Schemas & migrations → MariaDB/MySQL: initializes and upgrades
- API server → Character server: account/character interface
- Common platform → Login server: runtime services
- Common platform → Character server: runtime services
- Common platform → Map simulation: runtime services
- Common platform → API server: runtime services
- Plugin manager → Login server: native hooks
- Plugin manager → Character server: native hooks
- Plugin manager → Map simulation: native hooks
- Server configuration → Login server: configures
- Server configuration → Character server: configures
- Server configuration → Map simulation: configures