Configuration

2. Configuration, without a new file

int ngnet_set(const char* key, const char* value);   /* 0 ok, -1 unknown key */
keydefault
off1: the library does nothing
webrtcshim: off; native API: 1the shim’s opt-in: without webrtc=1 a program built with -include ngnet/enet.h is plain ENet (no thread, no socket, no announce, no intercept). 0: no browsers (no WebRTC port, no offers); the server still announces and answers HELLOINFO
ipv601: browsers that reach the master over IPv6 are taken and the announce goes over IPv6 too. Default IPv4 only: an IPv6 browser’s offer is refused with “this server takes IPv4 players only”. With a classic (IPv4) ENet an IPv6 browser’s peer->address is 0.0.0.0, so leave it off there
webrtc_portgame port + 1UDP port of every browser
masterhttps://master.shootanddestroy.obex.pwa master URL; repeatable (several masters at once); the first call replaces the default; - or empty: none
stunstun:stun.l.google.com:19302comma separated
turn, turn_username, turn_credentialTURN relays for players behind symmetric NATs
name, map, modefrom the classic announce, else ngnet serverclipped to 64, 32, 16 bytes on a UTF-8 boundary (the master refuses longer)
protocol0.75 after a classic announce, else the master’s defaultany [0-9A-Za-z._-]{1,16}
max_playersfrom the classic announce, else 32
countrythe master finds it from the address when absent
key_fileempty: in memorythe Ed25519 identity on the master. Empty: a new key at every start (a new row id; the old row drops off within 90 s). A path: read from it, or made once and written there (kept in memory if it cannot be written)
cert_fileempty: in memorythe DTLS certificate WebRTC needs. Empty: made at every start. A path: read from it, or made once and written there
join_code, unlistedplay with friends, no forwarded port
bindanylocal address for ICE (multi-homed hosts, tests)

The environment variable NGNET_<KEY> (upper case) overrides ngnet_set; NGNET_MASTER is a list separated by spaces or commas. ngnet_set_info() updates name, map, mode, protocol, player counts and the HELLOINFO JSON at runtime.

Lua (5.1 to 5.4, LuaJIT), header only, compiled against the program’s own Lua headers:

#include <ngnet/lua.h>
ngnet_lua_open(L);          /* registers ngnet_set(key, value) and ngnet_get(key) */
ngnet_set("master", "https://master.example.org")
ngnet_set("name", "My server")