diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8593bd3..ab252b6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -37,7 +37,7 @@ jobs: sudo apt-get update sudo apt-get install -y --no-install-recommends build-essential cmake pkg-config \ libjson-c-dev libssl-dev libcurl4-openssl-dev zlib1g-dev libreadline-dev \ - liblua5.4-dev + liblua5.4-dev libsodium-dev - name: Cache the fetched dependencies (libdatachannel) uses: actions/cache@v4 @@ -85,7 +85,7 @@ jobs: submodules: recursive - name: Dependencies - run: brew install json-c openssl@3 lua pkg-config + run: brew install json-c openssl@3 lua pkg-config libsodium - name: Build (Release, -Werror) run: make server diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 4d5202f..d1f5d0c 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -169,6 +169,7 @@ jobs: mingw-w64-ucrt-x86_64-gcc mingw-w64-ucrt-x86_64-cmake mingw-w64-ucrt-x86_64-pkgconf mingw-w64-ucrt-x86_64-json-c mingw-w64-ucrt-x86_64-readline mingw-w64-ucrt-x86_64-lua54 mingw-w64-ucrt-x86_64-curl mingw-w64-ucrt-x86_64-openssl mingw-w64-ucrt-x86_64-zlib + mingw-w64-ucrt-x86_64-libsodium - name: Build the static server run: | diff --git a/common/ngnet b/common/ngnet index 8307e6a..d5132ff 160000 --- a/common/ngnet +++ b/common/ngnet @@ -1 +1 @@ -Subproject commit 8307e6a87ce7be66b469d7fbdc0894f057aacff2 +Subproject commit d5132ffb81cd34693660b23375351752deae26a9 diff --git a/server/Source/Main.c b/server/Source/Main.c index ca236d8..bfea878 100644 --- a/server/Source/Main.c +++ b/server/Source/Main.c @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include @@ -821,23 +822,17 @@ int main(int argc, char** argv) } } if (join_code_arg != NULL) { - /* the player's paste: separators and the case out */ - char out[sizeof(get_server()->join_code)]; - size_t n = 0; - for (const char* c = join_code_arg; *c && n + 1 < sizeof(out); c++) { - if (*c == '-' || *c == ' ') { - continue; - } - out[n++] = (char) (*c >= 'a' && *c <= 'z' ? *c - 32 : *c); - } - out[n] = '\0'; - if (n == 6) { + /* the player's paste, read by ngnet's rule (Atyha's codes): eight + letters and digits nobody misreads, a ngspades:// link too */ + char out[sizeof(get_server()->join_code)]; + if (p2p_code_norm(join_code_arg, out, sizeof out)) { snprintf(get_server()->join_code, sizeof(get_server()->join_code), "%s", out); - /* the host sees in the log what its friends will type (and a - test reads it without the master) */ - LOG_STATUS("Join code: %c%c%c-%c%c%c", out[0], out[1], out[2], out[3], out[4], out[5]); + /* the host sees in the log what its friends will type */ + char shown[16]; + p2p_code_display(out, shown, sizeof shown); + LOG_STATUS("Join code: %s", shown); } else { - LOG_WARNING("--join-code %s: a code is six letters and digits (like ABC-DEF)", join_code_arg); + LOG_WARNING("--join-code %s: a code is eight letters and digits (like HK4M-7TRW)", join_code_arg); } } diff --git a/server/Source/Server/Net/Online.c b/server/Source/Server/Net/Online.c index 3d980e4..ec0155f 100644 --- a/server/Source/Server/Net/Online.c +++ b/server/Source/Server/Net/Online.c @@ -40,7 +40,6 @@ static struct int tokens; char state[256]; /* what the list shows: a change of it refreshes the info at once */ uint64_t info_at; /* real nanos of the last info */ - char code[16]; /* the join code already announced in the log */ } online; /* ---- ngnet's log and events into the game's ---- */ @@ -201,6 +200,11 @@ static int _on_offer(void* user, const char* ip, const char** reason) *reason = "server full"; return 1; } + /* a room's offer has no address yet (it came through Atyha's relays): + ngnet asks again with the one ICE found, at the friend's "connect" */ + if (*ip == '\0') { + return 0; + } /* the browser's address as the ban check reads a connection's */ conn_t probe; uint8_t ip4[4] = {0, 0, 0, 0}; @@ -352,8 +356,9 @@ void online_start(server_t* server) } /* WebRTC is the players' own matches' (a join code: the friend's - client, or a browser, comes through the master's signalling); a - dedicated server opens it too when its config says so */ + client, or a browser, comes through the match's room on Atyha's public + relays); a dedicated server opens it too when its config says so, and + browsers then join it by WebRTC direct from the master's list */ int webrtc_on = webrtc_enabled || server->join_code[0]; if (!webrtc_on) { LOG_INFO("WebRTC: off (a join code turns it on; [webrtc] enabled for a dedicated server)"); @@ -365,13 +370,13 @@ void online_start(server_t* server) /* a listen server (a player's own match with its bots, started from the menu) stays off the public list unless its host asked for it (--public): every singleplayer match was listed, and anyone could - join it. One with a join code still announces: the code, not the - list, is where its players find it */ + join it. A join code changes nothing here: its friends come through + the match's room, never the master */ int master_on = 1; if (server->join_code[0] && profile_is_075()) { - LOG_WARNING("master: the join code is the 1.0 profile's (a 0.75 profile join needs a forwarded port)"); - master_on = 0; - } else if (server->listen_private && !server->join_code[0]) { + LOG_WARNING("room: the join code is the 1.0 profile's (a 0.75 profile join needs a forwarded port)"); + } + if (server->listen_private) { LOG_INFO("master: not listed (a listen server; --public lists it)"); master_on = 0; } else if (!master_enabled || url[0] == '\0') { @@ -414,12 +419,19 @@ void online_start(server_t* server) ngnet_set("country", country); } /* a listen server whose host ticked "friends join by code" (--join-code): - the master maps the code to this server and every player that asks for - it is relayed here (its row off the public list unless --public asked). - A 0.75 profile server joins the ENet way and never uncovers the code */ + ngnet opens the match's room under it on Atyha's public relays, with the + room's password (SP_JOIN_PASSWORD, from the host's client: never on the + command line), and logs "Room open" once a relay confirmed it + (the host's client reads that line). A 0.75 profile server joins the + ENet way and opens no room */ if (server->join_code[0] && !profile_is_075()) { + const char* password = getenv("SP_JOIN_PASSWORD"); ngnet_set("join_code", server->join_code); - ngnet_set("unlisted", server->listen_private ? "1" : "0"); + ngnet_set("join_password", password != NULL ? password : ""); + ngnet_set("room_app", "ngspades"); + } + if (server->listen_private) { + ngnet_set("unlisted", "1"); } _on_publish(server, 1); @@ -447,14 +459,6 @@ void online_tick(server_t* server) _on_publish(server, 0); } ngnet_service(); - /* the player's code, exactly as a friend reads it (`XXX-XXX`, the - listenserver log line the host's client looks for), once the master - has assigned it */ - const char* code = ngnet_join_code(); - if (strlen(code) == 6 && strcmp(code, online.code) != 0) { - snprintf(online.code, sizeof online.code, "%s", code); - LOG_STATUS("Join code: %c%c%c-%c%c%c", code[0], code[1], code[2], code[3], code[4], code[5]); - } } void online_stop(void) diff --git a/tools/build_server_static.sh b/tools/build_server_static.sh index 7607f86..4de4658 100755 --- a/tools/build_server_static.sh +++ b/tools/build_server_static.sh @@ -21,6 +21,7 @@ apk add --no-cache \ build-base cmake git linux-headers perl pkgconf file ca-certificates \ openssl-dev openssl-libs-static zlib-dev zlib-static \ json-c-dev lua5.4-dev readline-dev readline-static ncurses-dev ncurses-static \ + libsodium-dev libsodium-static \ curl-dev curl-static brotli-static zstd-static libpsl-static libidn2-static \ libunistring-static nghttp2-static c-ares-dev >/dev/null diff --git a/tools/server_deps_macos.sh b/tools/server_deps_macos.sh index c7ca0c8..92230af 100755 --- a/tools/server_deps_macos.sh +++ b/tools/server_deps_macos.sh @@ -6,7 +6,7 @@ # # tools/server_deps_macos.sh (MACOSX_DEPLOYMENT_TARGET, default 12.0) # -# OpenSSL (libdatachannel's DTLS, the master's signatures), json-c and Lua +# OpenSSL (libdatachannel's DTLS, the master's signatures), json-c, Lua and libsodium # 5.4 land in as .a only (no .dylib, so the linker can only take # the archive), with their pkg-config files. libcurl, zlib and readline # (libedit) are the system's, present on every Mac. Then: @@ -38,6 +38,8 @@ fetch json-c https://s3.amazonaws.com/json-c_releases/releases/json-c-0.18.tar.g 876ab046479166b869afc6896d288183bbc0e5843f141200c677b3e8dfb11724 fetch lua https://www.lua.org/ftp/lua-5.4.7.tar.gz \ 9fbf5e28ef86c69858f6d3d34eccc32e911c1a28b4120ff3e84aaa70cfbf1e30 +fetch libsodium https://github.com/jedisct1/libsodium/releases/download/1.0.20-RELEASE/libsodium-1.0.20.tar.gz \ + ebb65ef6ca439333c2bb41a0c1990587288da07f6c7fd07cb3a18cc18d30ce19 # OpenSSL: libcrypto and libssl only, no shared libraries, no docs; its # certificates are never read (libcurl is the system's) @@ -71,5 +73,12 @@ Libs: -L\${prefix}/lib -llua5.4 Libs.private: -lm EOF +# libsodium: Atyha's crypto (common/atyha: the match's room), static +(cd "$work/libsodium" && + ./configure --disable-shared --enable-static --prefix="$prefix" \ + CFLAGS="-O2 -mmacosx-version-min=$MACOSX_DEPLOYMENT_TARGET" >/dev/null && + make -j"$jobs" >/dev/null && + make install >/dev/null) + rm -f "$prefix"/lib/*.dylib ls -l "$prefix/lib"