Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down
2 changes: 1 addition & 1 deletion common/ngnet
Submodule ngnet updated 66 files
+1 −0 .gitignore
+3 −0 .gitmodules
+13 −6 CMakeLists.txt
+21 −674 LICENSE
+1 −1 Makefile
+65 −25 README.md
+34 −0 cmake/atyha.cmake
+5 −3 cmake/libdatachannel.cmake
+1 −0 deps/atyha
+43 −16 docs/master.md
+18 −15 docs/porting.md
+26 −15 docs/wire.md
+1 −1 include/ngnet/conn.h
+1 −1 include/ngnet/enet.h
+1 −1 include/ngnet/host.h
+1 −1 include/ngnet/lua.h
+9 −6 include/ngnet/masterlist.h
+38 −15 include/ngnet/ngnet.h
+9 −6 include/ngnet/p2p.h
+36 −23 include/ngnet/transport.h
+2 −0 manual/.gitignore
+32 −0 manual/Makefile
+20 −0 manual/book.typ
+15 −0 manual/chapters.typ
+8 −0 manual/entry.typ
+19 −0 manual/index.typ
+153 −0 manual/template.typ
+37 −0 manual/tools/build_site.py
+206 −0 manual/tools/gen_docs.py
+15 −0 manual/tools/publish.sh
+13 −9 ngnet.cmake
+15 −4 src/cfg.c
+1 −1 src/enet_real.h
+1 −1 src/host.c
+1 −1 src/httpc.c
+40 −8 src/internal.h
+1 −1 src/json.c
+15 −111 src/master.c
+4 −1 src/masterlist.c
+61 −53 src/p2p.c
+311 −0 src/room.c
+134 −9 src/rtcpeer.cpp
+16 −1 src/rtcpeer.h
+192 −38 src/rtcsrv.c
+4 −1 src/server.c
+1 −1 src/shim.c
+1 −1 src/sign.c
+12 −5 src/stubs.c
+5 −3 src/transport.c
+177 −114 src/transport_enet.c
+134 −100 src/transport_rtc.c
+39 −26 src/transport_web.c
+41 −7 tests/CMakeLists.txt
+1 −1 tests/check.h
+1 −1 tests/run_master.sh
+132 −0 tests/test_client_enet.c
+91 −9 tests/test_core.c
+221 −0 tests/test_direct.cpp
+19 −141 tests/test_e2e.c
+12 −8 tests/test_e2e_shim.c
+1 −1 tests/test_hello.c
+1 −1 tests/test_lua.c
+240 −0 tests/test_room.c
+2 −2 tests/test_shim.c
+16 −0 web/atyha.global.js
+226 −150 web/ngnet_web.js
25 changes: 10 additions & 15 deletions server/Source/Main.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include <Util/TOMLHelpers.h>
#include <Util/Log.h>
#include <Util/Types.h>
#include <ngnet/p2p.h>
#include <uthash/utlist.h>
#include <Util/Alloc.h>
#include <signal.h>
Expand Down Expand Up @@ -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);
}
}

Expand Down
44 changes: 24 additions & 20 deletions server/Source/Server/Net/Online.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 ---- */
Expand Down Expand Up @@ -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};
Expand Down Expand Up @@ -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)");
Expand All @@ -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') {
Expand Down Expand Up @@ -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 <code> 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);

Expand Down Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions tools/build_server_static.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
11 changes: 10 additions & 1 deletion tools/server_deps_macos.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#
# tools/server_deps_macos.sh <prefix> (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 <prefix> 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:
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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"
Loading