Hi everyone!
I'd like to share a project I'm working on: a complete rewrite of the TMP4 game server in the Rust programming language.
What is this, in simple words?
A Metin2 private server has two parts:
The client: the game you launch on your PC.
The server: the program that handles accounts, monsters, fights, items, quests and saving your character.
TMP4 is a well-known server base written in C++. I'm rewriting that server in Rust, a modern and safer language.
Same client: you keep the normal, unmodified TMP4 client and play as usual.
Same data: maps, quests, items, monsters and the MySQL database all come from TMP4.
Same behaviour: every system is copied from the original TMP4 code, with the same formulas, drops and messages.
The goal is to reach 100% of what TMP4 does first, then improve from there.
TMP4 vs Rust: stability and security
Bad packets sent by cheaters
TMP4: a badly formed packet can crash the server
Rust: every packet is checked. All 55 client packet types were tested with random garbage, and nothing crashed.
Memory bugs (a classic source of crashes and exploits)
TMP4: possible anywhere in the code, and compiler warnings are turned off
Rust: impossible by design. Only 4 small "unsafe" spots exist, all in the Lua quest bridge.
Database hacking (SQL injection)
TMP4: about 30 database queries are built by hand from text
Rust: every query is protected automatically
Passwords
TMP4: old MySQL hashing
Rust: modern hashing (argon2)
A bug during one player's action
TMP4: can take the whole server down
Rust: only that player is disconnected, and everyone else keeps playing
Item duplication when saving
TMP4: depends on a separate cache program
Rust: every item keeps a fixed ID, and saves stay safe even when many players log out at once (0 errors in my tests)
Where it runs
TMP4: FreeBSD only, 32 bits, so 4 GB of memory at most
Rust: Windows and Linux, 64 bits
How to build it
TMP4: complex Makefiles and old libraries
Rust: one command, cargo build
Is it fast?
I tested it with 500 fake players (bots) on one PC with a Ryzen 9 (8 cores). The server, the database and the bots all ran on that same PC.
I made the test hard on purpose: around 250 players packed into each starting village, all walking, attacking and chatting at the same time.
11 ms reaction time for 95% of actions (anything under 50 ms feels instant)
29 ms at worst
About 300 MB of memory used
0 disconnects or errors
1.6 seconds to start with all 65 maps and ~52,000 monsters
7.5 ms to save a character with 100 items
To be honest: I couldn't run the original TMP4 on the same PC, because it needs 32-bit FreeBSD. So there is no measured speed comparison yet. A fair side-by-side test on the same hardware is planned.
What already works?
done · partly done · not yet
Login and characters
Login, character creation / deletion / rename, empire choice
Guild emblems (upload and display)
The world
All 65 maps, walls, safe zones in towns, portals
All monster spawns (~52,000 monsters)
Monsters chase you and use skills
Archers and mages attack from range
Bosses have their special abilities
Dungeons: flame dungeon, catacombs, devil tower, spider queen, heaven's cave…
Quests
All 237 TMP4 quests work, from the tutorial to the level 99+ story
Your character
Stats, all bonuses, buffs, level-up, exp
All 77 skills, including training up to Perfect Master
PvP duels, PK mode, alignment
Polymorph (marbles), horse (visible, feed it, ride it), pets
Items
Inventory with real item sizes, belt inventory
Drops, upgrades +0 to +9, bonuses up to 7, stones in sockets
NPC shops, your own private shop, trading, storage, item mall
Crafting (cube), full Dragon Soul, fishing, mining
Playing with others
Party with exp sharing and roles
Guild ranks, skills and exp donations
Guild wars with scores, spectators and bets
Guild land and buildings
Friends list, private messages, shout
Marriage: engagement, wedding ceremony, couple bonuses
Events
GM event flags (bonus exp / drop / gold)
Event drops (Halloween, Easter, Christmas…)
OX quiz, duel arena, three-kingdoms war
Castle siege, Blue Dragon boss
Monarch (emperor) system: written, being integrated and tested
Server administration
GM commands: the main ones work, some specialised ones are still missing
Full action logs (gold, item and login history)
Account and IP bans
All of TMP4's configuration options
Multi-channel: each channel is separate for now, so you can't whisper a friend on another channel yet
How do I know it works?
About 2,100 automatic tests
Many of them simulate real players connecting with the real TMP4 data: dungeons, weddings, guild wars, fishing, trading, logging out and back in
Every change must pass all of them before it goes in
What's next?
Finish integrating the monarch system
Remaining GM commands, logs, bans and config options
Multi-channel
A fair speed comparison against TMP4 on the same PC
An open test with real players
Questions, ideas and feedback are very welcome, especially if you know TMP4's weird little behaviours!