Applying Zero-Trust Validation on the Game Core
In high-population Metin2 servers, nearly all economy exploits and core crashes originate from trusting client-supplied packet payloads. Every incoming packet must be validated deterministically on the C++20 server before state mutation occurs.
1. Strict Packet Length & Subheader Bounds
Inside CInputMain and custom module handlers (Offline Shop, Shop Search, Trade, Cube), verify that both fixed header sizes and dynamic variable-length payloads match exact buffer bounds before deserializing.
2. Arithmetic Overflow, Cooldown & Distance Guards
- Overflow Prevention: Check item counts (`count == 0` or exceeding stack limits) and perform safe 64-bit checked arithmetic before multiplying unit prices by stack quantities.
- State Mutual Exclusion: Reject conflicting actions immediately via early returns whenever a character has an active exchange, safebox, or dead state.
- Millisecond Rate Limiting: Enforce per-character flood cooldowns on high-cost operations like full-catalog search queries, refine attempts, and dungeon entries.
Client obfuscation slows down casual tampering, while airtight C++ server validation makes packet injection mathematically impossible to abuse.