Skip to content

Port the server onto ngnet (WebRTC transport and master client) - #38

Merged
itxtoledo merged 4 commits into
mainfrom
feat/ngnet
Nov 29, 2026
Merged

itxtoledo merged 4 commits into
mainfrom
feat/ngnet

Conversation

@itxtoledo

Copy link
Copy Markdown
Contributor

What moved to ngnet

The server's WebRTC transport and its master server client are now the ngnet library, added as the submodule common/ngnet (pinned to 235090f, see "Dependencies" below).

  • Deleted (about 1750 lines, duplicated by ngnet): Net/WebRtc.{c,h}, Net/RtcPeer.{cpp,h}, Net/Master.{c,h}, the in-tree netlib/ (with its README) and server/cmake/libdatachannel.cmake.
  • New Net/Online.{c,h} is the game's side: online_start reads config.toml / SP_* and calls ngnet_set, ngnet_server_start with the events, online_tick (ngnet_set_info when the list's fields change, then ngnet_service() on the tick), online_stop (ngnet_server_stop, which sends leave).
  • Game policy stays in the game: bans and "server full" are the offer callback (the reason is shown to the browser); the connect tokens' policy (master_token_needed) is built on ngnet_master_listed() / ngnet_master_token_trusted(120) and master_token_check calls ngnet_master_token_check; join code and listen-server flow (join_code, unlisted) map to ngnet_set; the 0.75 profile still announces 32 players max with protocol 0.75; ping_info() is serialised as the announce's info_json.
  • conn_t is ngnet's. owner replaces player_id (helpers conn_player / conn_set_player in Net/Conn.h); conn_key_of / conn_ipv6_prefix come from the library. EnetConn.c (UDP players), Worker.c (browser-hosted server), the HELLOINFO intercept and NetGuard are unchanged apart from that.
  • Build: server/CMakeLists.txt does add_subdirectory(common/ngnet) and links ngnet::ngnet (libdatachannel, OpenSSL and libcurl come with it; libdatachannel is still pinned and still fetched on the first configure, FETCHCONTENT_SOURCE_DIR_LIBDATACHANNEL works offline as before). The browser's server (SP_WEB_HOST) builds ngnet with NGNET_WEBRTC=OFF NGNET_MASTER=OFF. The static Linux build, the Dockerfile and tools/build_server_static.sh need no change (the submodule check in the Dockerfile now includes common/ngnet); the CI cache key also hashes ngnet's cmake files.

Behaviour kept

  • Identity: key_file = <data>/master.key (or [master] key_file / SP_MASTER_KEY), cert_file = <data>/webrtc.pem. Checked: a key and a certificate made with OpenSSL in those files give the same master row key and dtls_fingerprint as before.
  • Every config key and env var still works: [webrtc] enabled port stun turn turns turn_username turn_credential, [master] enabled url country key_file connect_tokens, SP_WEBRTC_*, SP_MASTER_URL, SP_MASTER=0, SP_MASTER_KEY, SP_CONNECT_TOKENS. turn and turns are merged into ngnet's single TURN list (the scheme says which kind).
  • WebRTC stays off by default on a dedicated server, and the server is still listed: this needed ngnet's new webrtc = 0 switch (below).
  • Both profiles: protocol 1.0 and --profile 075, native UDP and browsers.
  • EVT master action=listed|error|left|join_code and EVT webrtc action=offer|answer|channel|connected|closing|closed|too_big|text_ignored are still logged (through ngnet_set_event). Changes: EVT webrtc action=connected|closed no longer carry player= / ice= (the library does not know players), EVT master action=announce join_code=... is gone (join_code still is logged), and master action=listed|left gain master=<url>. Nothing in tools/ reads these; docs/protocol-1.0.md says so.
  • STATUS: Join code: ABC-DEF (what the host's client looks for) is logged once the master assigns the code, as before.

Dependencies (read before merging)

  • Depends on ngspades/ngnet PR README: compare the server with SpadesX and piqueserver #1 (feat/initial-library, 899cf5c).
  • The submodule points at 235090f on ngspades/ngnet branch fix/server-config, which is 899cf5c plus one commit with two small library changes this port needs: a webrtc config key (ngnet_set("webrtc", "0"): no browsers but the announce and HELLOINFO stay, the default behaviour of a dedicated server here) and the announce's info_json buffer raised from 4 KB to 32 KB (ping_info() lists the players; the master takes 256 KB). Those should be folded into ngnet PR README: compare the server with SpadesX and piqueserver #1 and the submodule moved to the resulting commit before this merges.
  • ngnet must be made public before this merges: this repository is public and the submodule is fetched by every build. Until then submodules: recursive in CI cannot fetch it, so ci.yml is expected to fail on this PR.

How it was tested (macOS arm64, local master from the master repo's PR #7 branch, -probe=false, MASTER_ALLOW_PRIVATE_IPS=1)

  • make server (Release, -Werror), make server-asan: build; make test: proto10 6331 checks pass, ext075 all pass, both configs --check-config OK; make probe-proto10: all scenarios PASS (handshake, ngmap, mismatch, idle, garbage, early, vanilla, unknown).
  • Server against the local master (1.0): listed (signed announce), row key and dtls_fingerprint equal to the pre-made master.key / webrtc.pem; p10probe ngmap (native UDP) PASS against it while listed; rtcprobe (from the client repo, its list URL patched to /serverlist.json) handshake (a full 1.0 join over WebRTC through the master) and refuse PASS, also against the ASAN build (no AddressSanitizer report; one UBSan note in enet's compress.c, not from this change); a ban in Bans.json rejects the browser's offer (EVT webrtc action=offer ... ok=0 why="banned"); SIGTERM sends leave and the row disappears (EVT master action=left).
  • Default config (WebRTC off, master on): listed with webrtc:false, no UDP port opened for browsers.
  • --listen --join-code ABC-DEF: Join code: ABC-DEF logged, GET /v1/join/ABCDEF resolves, the row is not on the public list.
  • --profile 075: listed with game_version 0.75, players_max 32, aos:// identifier; a 0.75 client (ENet, connect data 3) gets the map start packet, the 1.0 magic gets "wrong protocol" (3).
  • Browser's server: the Emscripten build (emcmake, -DSERVER_WEB_HOST, ngnet with WebRTC and master off) compiles and links.

Not tested

  • The static Alpine/musl build and the Docker image (make server-static): Docker's daemon was down and the Apple container VM had no network. The change to the link line is the same libraries through ngnet::ngnet (libcurl's static dependencies still come from the existing pkg-config block); please run it before merging.
  • The macOS/Windows release builds and the Switch host (SP_SWITCH_HOST).
  • A browser joining by join code (the code is resolved by the master, but I only joined WebRTC by server id), an actual browser, TURN, IPv6, "server full" over WebRTC (the check is the old one moved), and a connect token from the master (SP_CONNECT_TOKENS path).
  • GitHub Actions: not run; this push triggers ci.yml once.

The browsers' WebRTC transport and the master server client move to the
ngnet library (https://github.com/ngspades/ngnet), pinned to the commit with
the two config fixes the server needed (webrtc=0, a 32 KB announce info).
Next commit: the server builds and uses it.
Net/WebRtc.c, Net/RtcPeer.cpp and Net/Master.c (about 1750 lines, a copy of
what ngnet now is) are deleted, with the in-tree netlib/ and
cmake/libdatachannel.cmake. Net/Online.c is the game's side:

- config.toml ([webrtc], [master]) and the SP_* variables become ngnet_set
  calls, as before; key_file stays <data>/master.key and cert_file
  <data>/webrtc.pem, so the master row id and the DTLS fingerprint do not
  change. WebRTC off (the default of a dedicated server) is ngnet's
  webrtc=0: still listed, no browsers, no extra UDP port.
- bans and a full server are the offer callback; the join code, a listen
  server's unlisted row, the 0.75 profile's cap of 32 and protocol label
  and ping_info as the announce's info_json go through ngnet_set /
  ngnet_set_info; the connect tokens' policy stays here on ngnet's
  ngnet_master_token_check.
- conn_t is ngnet's: owner holds the player's id (Net/Conn.h helpers);
  conn_key_of and conn_ipv6_prefix come from the library.
- ngnet's log and events go to LOG_* and evt_log, so the EVT master and
  EVT webrtc lines stay (the connected and closed lines no longer carry the
  player's id; EVT master action=announce is gone).
- the browser's server (SP_WEB_HOST) builds ngnet without WebRTC and the
  master; the build is ngnet's add_subdirectory (libdatachannel pinned in
  ngnet's cmake, still FETCHCONTENT_SOURCE_DIR_LIBDATACHANNEL offline).
README, CONTRIBUTING, protocol-1.0 (section 3.4), plan-075-server and the
manual's install chapter point at common/ngnet and Net/Online.c instead of
Net/WebRtc.c, Net/RtcPeer.cpp and Net/Master.c (and the deleted netlib/).
@itxtoledo
itxtoledo merged commit 3994cc8 into main Nov 29, 2026
2 checks passed
@itxtoledo
itxtoledo deleted the feat/ngnet branch November 30, 2026 22:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant