Network, the public list, browsers

The ports, again

The game is one UDP port ([server] port, 32887 for 1.0, 32897 for the 0.75 profile). Browsers and join codes use a second UDP port ([webrtc] port, the game’s + 1). The remote console is a TCP port that stays on the machine. The table with the firewall commands is in Installing and first start.

The server listens on one IPv6 socket that also answers IPv4: a host or a player with IPv6 alone can play, and a machine without IPv6 falls back to IPv4 (Listening on UDP port n over IPv4 and IPv6|IPv4 only). An IPv4 peer arrives mapped (::ffff:a.b.c.d) and is unmapped before anything reads it; an IPv6 player is banned by its /64. The LAN broadcast stays IPv4.

The public list (the master)

[master]
enabled = true
url = "https://master.shootanddestroy.obex.pw"
country = "BR"
key_file = "master.key"
connect_tokens = true

With [master] enabled, the server announces itself to our master server every 30 seconds over IPv4 and IPv6 and on every change (name, map, mode, players). The announce is signed with an Ed25519 key, master.key in the data folder, made at the first start: it is the server’s identity on the list, so back it up and keep it secret. The master probes the server’s UDP port to check it is reachable. leave is sent on shutdown.

Connect tokens

A player joining from the internet over UDP needs a token from the master, which ngspades-client asks for by itself (one per join, tied to the server’s key and the handshake). A flood of joins therefore goes through the master’s per-address limit (30 a minute). LAN players, players on this machine, browsers, and every join while the server has not reached the master for two minutes need no token. [master] connect_tokens = false turns it off (a server not on the list has it off anyway); SP_CONNECT_TOKENS=0|1|all overrides it (all asks local addresses too).

Join codes: playing with a friend

A match started from ngspades-client’s menu with “Friends join by code” gets a fresh six-character code (XXX - XXX). The server announces it to the master (the row stays off the public list unless the host also ticks “List on the server list”), and a friend types the code in the server list’s address box. No port forwarding is needed: the join goes over WebRTC through the master’s signalling. A dedicated server can set one with --join-code or SP_JOIN_CODE, but join codes are meant for listen servers.

Browsers: WebRTC

Browser players connect with WebRTC DataChannels, the same two channels and the same packets as native clients (reliable and unreliable map to ENet channels 0 and 1), on one UDP port shared by every peer.

[webrtc]
enabled = true
# port = 32888                    # default: the game's port + 1
stun = "stun:stun.l.google.com:19302"

What the server limits by itself

The server cannot stop a volume attack (gigabits of UDP fill the machine’s link before the program sees a packet), but it keeps one abusive client or a small flood from hurting the match.

Per playerRateBurstKicked after (drops in 10 s)
packets400 / s8002000
chat lines1 / s515
commands (GenericCommand)20 / s40200

A client over a limit has the excess dropped, is warned at the first drop and kicked when it keeps going. Bots are exempt; staff are exempt from the chat and command limits.

Only the per-address guard and max_players are settings; the other rates are fixed in the program (Flood.c, Ping.c).

Picking a host

Note A volume attack can only be stopped by the network in front of the machine. Pick a provider that filters attacks in its network at no extra cost: OVHcloud (every server sits behind its anti-DDoS; the game dedicated servers add “Anti-DDoS Game”, a filter made for UDP game traffic), Hetzner (DDoS protection is included on every server), Path.net based hosts, or Cloudflare Spectrum (TCP and UDP, paid). A home connection works for friends, but it exposes the home address.

The server needs very little: 128 players measured at 50-80 MB of memory and about 5% of one core, so the smallest VPS with 1 vCPU and 1 GB is enough. Prefer a location near your players (latency). The bandwidth to each player is about 26 KB/s with 127 bots on a large map; a full server’s upload is what that figure times the players.

Network behaviour worth knowing