Example: LSD

Example: LSD

LSD (pyspades derived, POSIX Makefile, Lua config) gets browser players and a signed listing with:

--- a/Makefile
+++ b/Makefile
-PKGCONF_MODULES=luajit libenet libisal
+PKGCONF_MODULES=luajit libenet libisal ngnet
 ...
-CPPFLAGS=`pkg-config --cflags $(PKGCONF_MODULES)` $(OPTS)
+CPPFLAGS=`pkg-config --cflags $(PKGCONF_MODULES)` -include ngnet/enet.h $(OPTS)

(LIBS already takes pkg-config --libs $(PKGCONF_MODULES); without pkg-config: LDLIBS += -lngnet -ldatachannel -ljuice -lusrsctp -lstdc++ -lcurl -lcrypto, and CFLAGS += -include ngnet/enet.h.)

--- a/src/lua.c
+++ b/src/lua.c
 #include <lualib.h>
+#include <ngnet/lua.h>
 ...
  luaL_openlibs(l);
+ ngnet_lua_open(l);

The shim does nothing until the operator opts in, in config.lua:

ngnet_set("webrtc", "1")                                   -- the opt-in: browsers, signed announce
ngnet_set("master", "https://master.shootanddestroy.obex.pw")
ngnet_set("webrtc_port", 32888)

or with no file change at all: NGNET_WEBRTC=1 ./server. Without it the server runs as before (one thread, its own sockets, its classic announce only). Then: its enet_host_create(addr, ...) becomes the attached game host, its masterlist host (created with NULL) is sniffed for the name, mode, map and player count, its peer->data, peer->address, peer->roundTripTime, enet_peer_send, enet_host_broadcast, enet_peer_disconnect(_now) and enet_peer_reset calls work on browser peers as on UDP ones. LSD installs its own host->intercept (it answers HELLO and HELLOLAN), so it keeps it; to answer the master’s HELLOINFO probe as well, end its intercept with return ngnet_intercept(host, event); (the master falls back to probing over ENet when HELLOINFO is not answered). The whole of LSD was built against the shim and run on macOS with a local master: idle without the opt-in, and with NGNET_WEBRTC=1 a real WebRTC client joined with connect data 3 and received the map. LSD’s Linux sandbox (seccomp without clone/pipe, pivot_root without /etc/ssl) kills the process once the library starts threads: an opted-in LSD on Linux has to be built with -DWITHOUT_SECCOMP -DWITHOUT_UNSHARE until its sandbox allows them.