Behind every game client there's a C++ game server processing hundreds of events every second. MMOs like Metin2 work exactly this way: a core written in C++ for performance talks to clients over the network. In this post I give a high-level look at the architecture my own server Runa2 is built on — to understand the big picture before writing any code.
Why C++?
A game server has to process the movement, combat and items of thousands of players within milliseconds. C++ makes this low latency possible by controlling memory and CPU directly. That's why the Metin2 core is written in C++ (and C for the low-level parts).
The main loop: the server's heart
At the centre of every game server is a main loop. It endlessly does three things: read incoming packets, update the world, and send replies.
// Basitlestirilmis ana dongu (game loop)
while (server_is_running) {
process_network_events(); // gelen paketleri oku ve coz
update_game_world(delta); // NPC, savas, hareket, sureler
flush_outgoing_packets(); // istemcilere yaniti gonder
}
This loop spins many times per second; the more efficient it is, the more players the server can carry.
The network layer
Clients talk to the server over TCP sockets. The server listens to each player's connection, decodes the incoming bytes into meaningful packets (move, attack, chat…) and writes the right reply back. In Metin2 this is built on core libraries like libthecore.
Game logic and world management
The core keeps characters, NPCs, maps and combat math in memory. When an attack arrives, damage is calculated, health updated, and the result broadcast to the relevant players. The database (MySQL) stores persistent data (characters, items); the db core bridges the game and the database.
Performance principles
- Non-blocking I/O — network operations must not lock the main loop.
- Memory management — use pools for frequently allocated objects; leaks kill a long-running server.
- Splitting into channels — spread load across multiple channel cores (ch1, ch2…).
Frequently asked questions
Do I need advanced C++ to write a game server?
To modify an existing core, intermediate C++ and patience are enough. Writing one from scratch requires deep knowledge of networking, concurrency and memory.
Why channels instead of one giant server?
To split the load. Each channel is a separate core; when one is busy, players spread to another and performance holds.
Is data lost if the server crashes?
Regular database writes and backups protect persistent data; that's why the db core and backups are critical.
Want to talk game server architecture? I can help with the Metin2 core, balance and infrastructure — get in touch.