Repository navigation
Port the server onto ngnet (WebRTC transport and master client) - #38
Merged
Merged
Conversation
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/).
This was referenced Nov 30, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 to235090f, see "Dependencies" below).Net/WebRtc.{c,h},Net/RtcPeer.{cpp,h},Net/Master.{c,h}, the in-treenetlib/(with its README) andserver/cmake/libdatachannel.cmake.Net/Online.{c,h}is the game's side:online_startreadsconfig.toml/SP_*and callsngnet_set,ngnet_server_startwith the events,online_tick(ngnet_set_infowhen the list's fields change, thenngnet_service()on the tick),online_stop(ngnet_server_stop, which sendsleave).offercallback (the reason is shown to the browser); the connect tokens' policy (master_token_needed) is built onngnet_master_listed()/ngnet_master_token_trusted(120)andmaster_token_checkcallsngnet_master_token_check; join code and listen-server flow (join_code,unlisted) map tongnet_set; the 0.75 profile still announces 32 players max with protocol0.75;ping_info()is serialised as the announce'sinfo_json.conn_tis ngnet's.ownerreplacesplayer_id(helpersconn_player/conn_set_playerinNet/Conn.h);conn_key_of/conn_ipv6_prefixcome from the library.EnetConn.c(UDP players),Worker.c(browser-hosted server), the HELLOINFO intercept andNetGuardare unchanged apart from that.server/CMakeLists.txtdoesadd_subdirectory(common/ngnet)and linksngnet::ngnet(libdatachannel, OpenSSL and libcurl come with it; libdatachannel is still pinned and still fetched on the first configure,FETCHCONTENT_SOURCE_DIR_LIBDATACHANNELworks offline as before). The browser's server (SP_WEB_HOST) builds ngnet withNGNET_WEBRTC=OFF NGNET_MASTER=OFF. The static Linux build, the Dockerfile andtools/build_server_static.shneed no change (the submodule check in the Dockerfile now includescommon/ngnet); the CI cache key also hashes ngnet's cmake files.Behaviour kept
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 rowkeyanddtls_fingerprintas before.[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.turnandturnsare merged into ngnet's single TURN list (the scheme says which kind).webrtc = 0switch (below).--profile 075, native UDP and browsers.EVT master action=listed|error|left|join_codeandEVT webrtc action=offer|answer|channel|connected|closing|closed|too_big|text_ignoredare still logged (throughngnet_set_event). Changes:EVT webrtc action=connected|closedno longer carryplayer=/ice=(the library does not know players),EVT master action=announce join_code=...is gone (join_codestill is logged), andmaster action=listed|leftgainmaster=<url>. Nothing intools/reads these;docs/protocol-1.0.mdsays 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)
feat/initial-library,899cf5c).235090fonngspades/ngnetbranchfix/server-config, which is899cf5cplus one commit with two small library changes this port needs: awebrtcconfig key (ngnet_set("webrtc", "0"): no browsers but the announce and HELLOINFO stay, the default behaviour of a dedicated server here) and the announce'sinfo_jsonbuffer 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.submodules: recursivein CI cannot fetch it, soci.ymlis 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-configOK;make probe-proto10: all scenarios PASS (handshake, ngmap, mismatch, idle, garbage, early, vanilla, unknown).keyanddtls_fingerprintequal to the pre-mademaster.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) andrefusePASS, also against the ASAN build (no AddressSanitizer report; one UBSan note in enet'scompress.c, not from this change); a ban inBans.jsonrejects the browser's offer (EVT webrtc action=offer ... ok=0 why="banned"); SIGTERM sendsleaveand the row disappears (EVT master action=left).webrtc:false, no UDP port opened for browsers.--listen --join-code ABC-DEF:Join code: ABC-DEFlogged,GET /v1/join/ABCDEFresolves, the row is not on the public list.--profile 075: listed withgame_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).emcmake,-DSERVER_WEB_HOST, ngnet with WebRTC and master off) compiles and links.Not tested
make server-static): Docker's daemon was down and the ApplecontainerVM had no network. The change to the link line is the same libraries throughngnet::ngnet(libcurl's static dependencies still come from the existing pkg-config block); please run it before merging.SP_SWITCH_HOST).SP_CONNECT_TOKENSpath).ci.ymlonce.