Lesson 8 of 9 · 29m
Server-Side Validation for Movement, Combat, and Economy
Turn anti-cheat principles into concrete validators for movement physics, weapon actions, object interactions, and transactional economies.
The difference between a principled netcode design and an anti-cheat slide deck is a validator that runs in the hot path. Validation has to be fast enough for every tick, precise enough not to punish honest lag, and strict enough that impossible input does not become advantage. This is game-specific engineering, not a library you import.
Movement validation is a constraint system
Do not try to prove that every movement packet is legitimate in the abstract. Constrain the simulation the server performs: speed, acceleration, jump state, collision, slope, teleport distance, and time since the last accepted input.
MAX_SPEED = 7.2 # meters per second
MAX_SNAP_ERROR = 0.35 # tolerated prediction/collision mismatch
def validate_move(player, cmd, dt):
desired = integrate_movement(player.state, cmd, dt)
if desired.horizontal_speed > MAX_SPEED * dt_slack(dt):
desired.clamp_horizontal_speed(MAX_SPEED)
resolved = collision_sweep(player.state, desired)
if resolved.displacement.length() > plausible_distance(cmd, dt):
flag(player, "movement_distance", resolved.displacement.length())
return resolvedTolerance matters. A strict equality check punishes packet loss and floating-point variation. A loose check creates cheat budget. Record how often honest players approach limits before tightening them.
Teleports and corrections need explicit grammar
A legitimate teleport, spawn, ladder snap, vehicle entry, or server correction can look like cheating if your validator only understands walking. Encode discontinuities as server events and exempt only the exact transition they describe. "Large movement is fine sometimes" becomes an exploit primitive.
Combat validation combines timing, geometry, and state
For every damaging action, validate attacker state, weapon state, cooldown, ammunition, range, line of sight where appropriate, target state, and the rewind window. A compact decision record helps:
attacker alive=true weapon=rifle ammo=17 cooldown_ready=true
command_seq=8841 server_tick=99120 rewind_tick=99116
range=18.2m los=true target_alive=true damage=27 result=acceptedRejected actions need categories: stale input, impossible timing, blocked geometry, invalid state, rate limit, or deserialization failure. Without categories you cannot tell cheats from network weather.
Economy bugs are duplication machines
Competitive cheating gets attention, but economy exploits ruin games quietly. Inventory, currency, crafting, trading, and marketplace operations must be transactional and idempotent. If two concurrent requests can consume the same item or grant the same reward twice, latency becomes a money printer.
BEGIN;
SELECT balance FROM accounts WHERE id = $1 FOR UPDATE;
UPDATE accounts SET balance = balance - $2
WHERE id = $1 AND balance >= $2;
INSERT INTO purchases(idempotency_key, account_id, item_id)
VALUES ($3, $1, $4)
ON CONFLICT (idempotency_key) DO NOTHING;
COMMIT;The exact schema varies; the principles do not. Lock or atomically update the constrained resource, enforce the invariant in the database or authoritative service, and make retries safe.
Rate-limit actions, not just packets
A player can send legal-looking messages at abusive frequency: emotes, voice pings, inventory moves, report submissions, market searches, matchmaking joins. Validation should include action budgets tied to gameplay meaning. Human input is irregular; perfect automation often reveals itself through timing distributions and impossible consistency.
Validation failures are telemetry, not instant guilt
One impossible movement can be packet loss, a collision edge case, or a bad correction. Repeated improbable behavior is evidence. Aggregate counters by player, server build, map, region, and network quality. A sudden spike after a patch may mean your game changed, not that thousands of players simultaneously installed cheats.
Field notes
- Never silently clamp abusive state forever without recording it; hidden correction can mask exploitation and confuse hit registration.
- Rejecting input too aggressively makes high-packet-loss honest players rubber-band and can become a denial-of-service surface.
- Put economy invariants as close to authoritative storage as possible. Service-level convenience checks are bypassed by retries and races.
- Validation should be testable in replay: same inputs, same tick, same accepted or rejected result.
Was this lesson helpful?