Back to projects
cat blast-arena

Blast Arena

Secure real-time multiplayer over DDS (Data Distribution Service)

A Bomberman-style multiplayer game for 2 to 5 players, written in C on Cyclone DDS, OpenGL and GLFW. It started from the Low-Level Programming course baseline, and we rebuilt it into a server-authoritative, encrypted, smooth-running real-time simulation. Team of 2, with Soh Wei Jie.

  • C
  • Cyclone DDS
  • DDS Security
  • OpenGL
  • GLFW
  • Linux and WSL
  • CMake
0.3%server CPU when idle
0movement freezes under 45 ms of network jitter
116automated checks across game rules and interpolation
60 Hzserver simulation, with 30 snapshots a second
blast-arena

The starting point

The course gave us a working but basic client and server. It had three problems we set out to fix.

  • Both programs busy-waited, so an empty server used about two full CPU cores just spinning.
  • Movement depended on when messages happened to arrive, so players froze and then jumped forward, which looks like rubberbanding.
  • There was no security. Anyone on the network could join, read every message, or send fake game state.

Architecture

One authoritative server and up to five clients share a single DDS domain. Nobody sends to an address. Each program publishes samples on named topics, and every reader of that topic receives them. Clients only send their keys, and the server decides movement, bombs, explosions and deaths, so a modified client cannot cheat.

Diagram of the server and clients sharing one DDS domain through five topics
The five topics and who reads or writes each one.

Each topic gets the Quality of Service (QoS) that fits its job.

TopicDirectionQoSWhy
JoinRequestclient to serverreliable, keep last 1must arrive
JoinResponseserver to clientsreliable, keep last 1each client reads only the reply matching its own random nonce
Inputclient to serverreliable, keep last 1only the newest input matters, and disposing it means the player left
GameStateserver to clientsbest effort, keep last 1a lost snapshot is replaced 33 ms later, so resending would only add lag
MapStateserver to clientsreliable, transient localsent only when a tile changes, and late joiners still get the current map

Neither program busy-waits any more. The server sleeps to an absolute deadline for a steady 60 Hz tick, and both programs block their network thread on a DDS WaitSet until data arrives.

Smooth movement without rubberbanding

Snapshots leave the server every 33 ms but arrive unevenly, anywhere from 15 to 80 ms apart on WSL. Drawing them as they arrived made players freeze whenever one was late, then jump to catch up. The fix is the approach most real-time games use.

  1. Keep the last 8 snapshots in a ring buffer, each tagged with its server tick.
  2. Estimate the offset between the server clock and the local clock from the fastest arrivals, and adjust it by at most 1 ms per snapshot so corrections are invisible.
  3. Draw the world 80 ms in the past, interpolating between the two snapshots around that moment. A late snapshot is not needed yet, so nothing freezes.
  4. Draw bombs, flames, the map and the HUD from the same delayed snapshot, so a bomb never appears before the player who dropped it.

Measured with a simulated walk at 60 fps and random delivery jitter.

JitterBefore: freezesBefore: biggest jumpAfter: freezesAfter: biggest jump
0 to 10 ms02.1x a normal step01.0x
0 to 30 ms543.9x01.06x
0 to 45 ms965.1x01.12x

Bomb presses are sent as a counter rather than a pressed flag. With keep last 1, a quick tap between two messages could be overwritten, but a counter cannot lose a press, and a repeated message never drops a second bomb.

Performance

198%baseline server CPU with no players, two threads spinning
0.3%our server CPU with no players
  • Inputs are sent only when keys change, plus a 1 second heartbeat, instead of every 10 ms while a key is held.
  • One GameState message carries every player, and the map has its own topic that is only sent when it changes.
  • The lock is held only for in-memory copies, never across network calls.
  • Messages use fixed-size arrays and bounded strings, so there is no heap allocation per sample.
  • Movement is frame-rate independent, measured in tiles per second.
perf stat output for the baseline server showing 1.898 CPUs utilized
Baseline server under perf stat: about 1.9 CPUs busy doing nothing.
perf stat output for the new server showing 0.007 CPUs utilized
Our server under the same test: 0.007 CPUs.

Security

DDS Security adds three layers, turned on with a single config file and no changes to the game code.

Diagram of DDS Security authentication, access control and cryptography, and what an attacker gets
Authentication, access control and encryption, and what each stops.
ThreatProtection
An unknown program joins the gameOnly participants with a certificate signed by our certificate authority are accepted
Someone reads the network trafficDiscovery and all topic data are encrypted with AES-GCM
A client sends a fake map or game stateSigned permissions only let the server publish game state, map and join replies
A valid client controls another playerEach player slot is bound to the participant that joined, and mismatched inputs are rejected and logged
Tampered permission filesBoth files are signed, and DDS refuses to start if a signature fails
Malformed messagesPlayer ids are bounds-checked, unknown key bits rejected, and names truncated and made printable
access_check tool output showing allowed and denied topic operations and PASS
An access check tool confirms a client can send input but cannot forge game state, forge the map, or spy on other inputs.
tcpdump captures showing the player name 283 times without security and 0 times with security
Recorded network traffic: the name Alice appears 283 times without security, and 0 times with it.

New players join with a one-time code. The host hands out a player certificate only to someone with the right code, and stops after 20 wrong tries.

Testing

  • 13 tests with 99 checks on the game rules, covering the map, movement, bombs, explosions, chain reactions, power-ups, rounds, timeouts and snapshots.
  • 17 checks on interpolation, including reordering, server restart, respawn and the jitter simulation.
  • Every certificate verified with strict OpenSSL checks, an intruder without a certificate shown never joining, and a one-character change to the permissions file shown stopping the server.
  • Builds with AddressSanitizer and UndefinedBehaviorSanitizer, and runs under Valgrind.

Known limitations

  • There is no client-side prediction, and the world is drawn 80 ms in the past, so your own player reacts about 100 ms after a key press. That is fine on a LAN.
  • All clients share one certificate authority whose key stays on the host, so the host can sign anything.
  • The join code is about 40 bits, stretched with PBKDF2. Someone recording the exchange could try to guess it offline, which is acceptable for a LAN game but is why a real system would use TLS or a PAKE.