Contents
Morvek is a session-based medieval real-time strategy game: in one match, two to eight players command hundreds of units on the same map, from a browser, a desktop client or a phone. That needed a sync model in which every player sees the same battle, and nobody sees more than their own units have scouted.
The problem
Most classic RTS games use a lockstep model: every client simulates the full game state and they only send each other the commands. That uses little bandwidth, but it was not viable for us, for three reasons:
- Cheating: if the client knows the full state, units hidden in the fog are still in its memory. A simple memory reader can turn scouting off.
- Mixed clients: browser, desktop and mobile clients share the same match. If a weak phone falls behind, lockstep holds everyone else back.
- Drops and reconnection: in a 20–120 minute match, someone’s connection will almost certainly break. The full battle then has to be restored quickly and in a way that can be checked.
Meanwhile the lobby, the friend list and invitations also have to stay live, but they show a completely different load pattern from a 20 Hz simulation.
The solution
Two separate real-time channels
We split the system into two planes that do not depend on each other:
- Control plane: Laravel and AnyCable. Laravel handles accounts, lobbies, match tickets and settlement. AnyCable-Go carries live updates of the lobby list, room state and friend list over WebSocket, on signed streams. The JWT travels in the WebSocket subprotocol, not in the URL. Laravel publishes to AnyCable with an internal HTTP call, and that endpoint is not reachable from outside. If the real-time layer is down, the client falls back to polling every ten seconds, so the lobby stays usable.
- Match plane: server-side simulation. The battle itself runs on a Node.js Colyseus worker, at 20 steps per second. Laravel does not compute a single simulation step: its job is to start and close the match.
The client only sends intent
The client never claims where a unit is or how much gold it has. It only sends what it wants: “these 12 units should go there”. An envelope protects the command, with a protocol version, a sequence number and an expiry step. The server schedules it with a delay of two steps (100 ms) and only decides whether it is still valid at the moment of execution. Unit ownership, resources and the outcome of the match exist only on the server.
A fog-filtered view: snapshot, then delta
- On connect, the player receives a compressed, fog-filtered snapshot in chunks, with a SHA-256 checksum. The client checks it and acknowledges that it applied it.
- After that it only receives Protobuf deltas: which units appeared, disappeared or moved, and which fog cells changed.
- Hidden units, internal identifiers and the secrets of map generation never leave the server. What the client was not given cannot be read out of it with a cheat tool.
Reconnection and resync
- After a drop, the player has 90 seconds of simulation time to return. Until then a caretaker keeps the village working and defended, but it does not make strategic decisions for them.
- Every client has its own replication queue. If the queue fills up or a gap appears, the server does not drop a delta. It resynchronizes with a full snapshot.
- If the client’s checksum does not match, or there is a gap in the view clock, the client itself asks for a resync.
The bug we learned the most from
Under load, the server first caught up on several late steps at once and only sent the last view. The simulation itself kept running at a healthy 20 Hz, but to the players the units jumped at about 2.5 Hz. After the fix, one flush computes exactly one step, and every step’s view is sent. An automated test guards this today.
Measured results
20 Hz
Server-side simulation
50 ms step time, every step’s view is sent to the clients
2–8
Players in one match
browser, desktop and mobile clients mixed
2.5 → 20 Hz
Visible movement updates
after fixing the step-batching bug
90 s
Reconnection window
a caretaker defends the player’s village in the meantime
- Map-hack cheating is structurally excluded: the client only receives the fog-filtered view.
- No silent drift: a gap or a checksum mismatch always triggers a full, checked resync.
- The game server’s behaviour is pinned down by 214 test files, and the lobby and control plane by more than 240 Laravel tests.
The lesson: a real-time system is not a single technology, but the right split of jobs. State that changes rarely and concerns many people gets a cheap broadcast. Fast state that differs per player gets a server that knows everything, but only tells as much as it must.