Back to Devlog

Devlog 4 min read

Who gets to decide that you won

A player joining a match used to win the instant the map finished loading, because "nothing of theirs is left" is trivially true on a client whose actor list is still empty. Moving every victory condition to the server, and what it taught about writing them.

Two forces meeting in front of a camp

A joining player used to win immediately. Not sometimes — reliably, the moment the map finished loading.

The bug is funny once you see it, and it is the kind that only exists in multiplayer. A client’s list of actors is not there at the start: the server fills it over the first seconds of the match. A victory condition written as “nothing of theirs is left standing” is therefore true on a machine that has not yet been told about anything. The client checked, found an empty world, declared victory, and the host carried on playing.

One place, and only one

The match now ends in exactly one function. It refuses any caller that is not the server, it is idempotent, and it broadcasts the result to everyone — including the host, which receives its own message through its local connection so that host and client cannot end up showing different winners.

Every condition funnels through it: a wiped enemy in solo, a fallen nexus, the last player standing, a completed mission. Four phrasings, one exit.

That “including the host” detail is the one worth copying. The host is a player and the server, and code written for the host is the code most likely to look fine while being wrong for everybody else. Making the host go through the same message as a remote client removes an entire class of disagreement.

Conditions written from somebody’s point of view

The nexus condition said: the local player wins once every enemy nexus is down. Read it again with three players on the map and the problem appears — “enemy” relative to whom, and “the local player” on whose machine?

In practice it only ever fired in one game mode. In a one-against-one it fired for nobody: both machines were waiting for a statement about a local player that the match had no notion of.

It is now stated without a point of view: the last alliance holding a standing nexus wins. No “you”, no “enemy”, no local anything. It is a fact about the board, and every peer computes the same fact.

A line of fighters advancing across open ground
The same board, two machines. A victory condition that mentions 'you' has already picked one of them.

Missions had the same disease, twice

Missions are the match’s shared objective, so only the server advances them, and it tells every peer where the shared mission stands. A player joining late adopts the server’s step instead of starting their own count — which is what used to happen.

The second one was worse because it was invisible. The side a mission was written for was read live, from whichever actor you were currently controlling. In co-op, each player carries their own team identity, so naming a single team showed the other player a defeat they had not suffered. The mission now captures the side it belongs to once, when it starts, and the winners are that side plus its allies.

Some steps only a player can do: talk to someone, craft an item, open a panel. Those fire on that player’s machine, so the client reports it and the server revalidates the mission and the step before advancing through the normal path.

The rule I took away

Write the condition as a fact about the world, not as a sentence about a player. Every victory bug in this list came from a phrasing with a “you” in it — the local player, the enemy, my team. The fix was never more code; it was saying the same thing without a point of view, and then making exactly one machine the one allowed to say it.

The other half of the same lesson is a loop that runs on every machine and quietly does server-only work on all of them: the bug that only existed for the guest.

Get the game on Steam Play the free demo

Keep reading