Skip to content
Cassette

Blog

How to add multiplayer to your vibe-coded game

Your agent can write the netcode. The decisions are yours: who runs the game, what happens when they leave, who keeps the servers on. With Third Faction, a 64-player shooter, as the case.

You made a game with an agent and now you want your friends in it. You type “add multiplayer”, the agent writes for a while, and soon two tabs on your laptop are moving the same character around. It feels done.

That was the easy part. Multiplayer is a handful of decisions, and the agent just made all of them for you, in whatever way got two tabs working on one laptop. Each one comes back later with a cost. This post goes through them in the order they tend to hurt, so you know what to ask your agent and what each answer costs.

The example is Third Faction, a 32 versus 32 shooter that runs in a browser tab. On a Saturday its big mode was single-player, against bots. By Monday evening anyone could click Play and land in the same battle. A lot broke in between.

Who runs the game

When two players grab the last health pack at the same moment, something has to decide who got it. That something is the authority, and where it lives is the first decision.

Three ways to run a multiplayer game, drawn with Third Faction players’ screens. One player hosts: their tab runs the world, it costs nothing, and it leaves when they do. Every player runs it: each tab replays the same inputs, there is no host, and all wait for the slowest. A server runs it: a machine you rent runs the world, nobody’s tab matters, and you pay for it.

One player hosts. One browser runs the real game. The others send it what they want to do and draw what it tells them. There is no server, and the game you already have is most of the host. The costs: the host can cheat, everyone depends on the host’s connection, and the host can leave.

Every player runs it. Each browser runs the whole game and they only exchange inputs. It suits turn-based and strategy games. The catch is that every machine has to compute exactly the same result every time, and when one drifts, the players are in two different games and nobody is told.

A server runs it. A machine you rent runs the game. Nobody’s tab matters and cheating gets much harder, but it is a second program to write, a monthly bill, and something to keep running at 3 am.

For a game made with an agent I’d start with a player hosting. That is what Third Faction does: one player’s browser runs the solo game, unchanged, as the referee. Everyone else runs the same code with the simulation switched off and draws what the referee publishes.

“Switched off” is where our worst bug came from. In the first real session every player crashed inside the physics engine. When a tank was destroyed, each player’s copy of the game started its own 20 second timer to clear the wreck. If the host brought the tank back after that timer fired, the player was left with a tank that was half there. With one authority, nobody else’s copy should decide anything on its own clock.

What happens when the host leaves

This is the question that gets skipped. The host is a person. They close the laptop, or their wifi drops.

The match can end, which is fine for a five-minute round between friends if the game says so. It can pause while someone picks it up from a snapshot. Or the role can move without anyone noticing, and for that the next host has to be holding the world already.

How the host role moves. The host runs the world, and two other players get a full copy of it once a second. The host closes the tab: Cassette notices and hands the role to one of those two. The match goes on: the new host carries on from its copy and nobody starts over.

Third Faction does the third, through Cassette. The host’s world is copied to two other players once a second, and when the host goes, one of them carries on. The players get one line at the bottom of the screen.

A signed-out guest’s screen in Third Faction moments after the host role moved. Another guest, tagged “Guest 5CLHT”, stands a few metres ahead, and a notice at the bottom reads “The host left or paused. Another player is hosting.”

Test this on purpose. One of our tests printed PASS and then crashed while it was closing the browsers. The one we kept is three players: close the host, close the next one, keep the last, and take the verdict only after everything has closed. With the wreck bug it crashed in 3 of 5 rounds. After the fix, 0 of 12.

Real time or turns

If your game is played in turns, a move can arrive half a second late and nobody minds. Send the moves in order and make sure none gets lost.

In a real-time game every message arrives late, and the player must not feel it. So you move on your own screen right away, the authority confirms what matters afterwards, and everyone else is drawn slightly in the past. Send what changed, about 20 times a second, to the players who can see it.

In Third Faction each player owns their own position. Shots are different: the player sends the direction of each bullet, and the host fires it again in the real world and decides what it hit.

A tank firing across Hollow Creek Valley in Third Faction, dust kicked up behind it. In an online match the host’s browser runs this tank and decides what its shell hits.

The map is about a kilometre across, cut into squares of 140 metres, and a player only receives the squares around them. In a load test with 57 simulated players in one room, each player downloaded about 9 KB a second and the host uploaded about 32. A home connection carries that.

How players find each other

A room code or an invite link is right for friends. Quick match is right for strangers, but only when strangers are online at the same moment, and at the beginning they won’t be.

The first online build of Third Faction had a full lobby: create a battle, find a battle, type a room code. It lasted until the first time I opened it. A new game has a handful of players, and every choice on that screen splits them into smaller rooms. Now there is one button. Play puts everyone into the same battle until it has 64 players, and only then opens a second one.

Every seat no human has taken is played by a bot, and a human who joins takes over a bot’s seat. So the first person to arrive is in a full battle from the first second.

A street in Hollow Creek during a Third Faction battle: bots fight a group of zombies, with an APC further up the road.

That makes the bots most of your multiplayer early on. Ours were parking tanks on flags their own team already held, for around nine minutes at a time. After the fix the longest stop is about two.

Then accounts. Every screen between the link and the game loses people, and the first version asked for a sign-in before Play. Now somebody who has never heard of Cassette clicks Play and is in the battle as “Guest K93TN”. A guest’s save stays in that browser, and scores and trophies wait until they sign in. We offer that from a menu, never in front of Play.

From 2 players to 64

With two players you can send everything to the other one. With 64, “everything to everyone” is 4,032 streams. Players can no longer connect directly to each other, so the traffic goes through a relay. Nobody gets the whole world, only their surroundings. And the host’s upload becomes the limit.

An attack helicopter over the town in Hollow Creek Valley, with the river and fields beyond.

Rare things also become normal. Our tests ran 57 simulated players on a pretend network, and they all passed. Then three real browsers joined over the real one, and one of them stood frozen for everyone else. A speed limit we had set against teleporting was throwing away that player’s honest position updates.

Chasing it turned up joiners who never got a seat. The host welcomed each new player once, and the welcome could arrive before their game was listening. Now a joining player asks again every second until it is answered. Any message can arrive early, late, twice or never, so nothing should depend on one message arriving at the right moment.

Cheating, saves and leaderboards

Whoever is the authority can lie. A hosting player can, and if each player owns their own position, a modified copy of the game can move wherever it likes. Between friends, ignore it. With strangers and a leaderboard, have the host check what counts (hits, kills, scores). With money or a ranked ladder, you need a server.

The match lives in the host’s tab and is gone when the last player leaves, so anything that has to outlive it (unlocks, settings, stats) belongs in each player’s own save.

A score that comes from a browser can be forged. Give every board a sane range and have a way to remove entries.

Six questions for your agent

Paste this before it writes a line:

Before you write any multiplayer code, answer these and wait for me:
1. Who decides what is true: one player's browser, every browser, or a server?
2. What happens to the match when that player closes the tab?
3. What do we send, how often, and to whom?
4. How do players find each other, and do they need an account?
5. What can a cheating player do, and do we care?
6. What needs a server, who pays for it, and who restarts it?

What your agent can’t do alone

Your agent can write everything above. What it can’t do is be somewhere on the internet.

Two browsers at home usually can’t connect to each other, because home routers refuse incoming connections. They need a meeting point with a public address, and a relay for when a direct connection fails. Those are servers: somebody pays for them every month and somebody restarts them. An agent can set them up if you hand it a cloud account and a card, and then you are running infrastructure, which is a different hobby from making a game.

Even for us it wasn’t only code. With Third Faction written and tested, opening its rooms to everyone still took a firewall rule at our hosting provider, a public address for the relay, and a setting the next deploy would have quietly erased.

Let Cassette carry that part

Rooms are part of Cassette, and a game gets one by asking:

const room = await cassette.rooms.quickMatch({ maxPlayers: 4 })
const state = room.shared({ players: {}, score: 0 })

state.players[room.self.id] = { x: 100, y: 300 }   // yours, and everyone sees it
if (room.isHost) state.score += 1                  // the host's

That is the networking. There is no server to rent, no key and no connection to manage. Players join by a five-character code, an invite link or quick match, without an account. When the host leaves, Cassette moves the role to another player. Chat is filtered, players can block and report each other, and hosting is free.

A room holds up to 8 players. Bigger rooms, up to 128, are what Third Faction runs on, and for now we turn them on game by game.

Tell your agent:

Add multiplayer rooms to my game on cassette.gg

It reads the multiplayer page we wrote for agents and works through the questions above with you. If the game isn’t on Cassette yet, start with “Publish my game to cassette.gg”.

Third Faction is one click away. Press Play and you are in the battle.

All posts