Urgent.News

What's breaking now, across thousands of outlets.

Tech

Two friends pressed "Play" at the same time and both got a bot: lessons from building a browser 1v1 game

I build TagKing.io on my own: a two player game of tag that runs in a browser tab. One player is "it", touching the other passes it on, and whoever is "it" when thirty seconds run out loses. There is a ranked ladder, so it has to work online between strangers. This week I finally got a friend on a call to play me, and it took far longer than it should have. Three things broke, and each one taught…

Building a browser-based 1v1 tag game, TagKing.io, taught the creator many lessons the hard way. The first challenge was when two players pressed "Play" simultaneously, resulting in each receiving a bot instead of connecting with each other. This issue stemmed from the server only checking for an opponent once upon receiving a "Play" request.

To resolve this, the creator added a polling mechanism that checked for an opponent every second, preventing both players from claiming each other as opponents at the same time. Additionally, the match would sometimes freeze and then fast-forward as if the other player had teleported. This occurred due to the game sending position updates over a WebRTC data channel with unordered delivery and no retransmission.

When the connection couldn't keep up, the browser buffered frames, delivering a backlog of outdated positions. The solution was to check the frame buffer size before sending, skipping a frame if necessary to ensure the most recent position was sent. Lastly, the creator discovered that running ad-hoc queries on the game's SQLite database using excessive resources led to exceeding the free tier's daily allowance.

This caused sign-in failures for real players until the daily limit reset. The creator learned to only run single-table counts over a limited time window and to monitor the number of rows each query reads to avoid overusing the available resources.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Tech

How to Record Matches on Club Courts Automatically

Ask any club that has put a camera on a court what happened next, and you will hear a version of the same story. The camera works. The footage exists.

  • Camera must stream using RTMP protocol
  • Players opt-in to recording during booking
  • Video delivered automatically to booking member

More from Monday 14 September →