feat(runtime): Zelda Notes with a server you choose #2543
No reviewers
Labels
No labels
area/accessibility
area/audio
area/input
area/install
area/menu
area/renderer
area/saves
area/tooling
area/upscaling
beanstalk: approved
beanstalk: failed
beanstalk: needs approval
beanstalk: running
beanstalk: tested
ci: approved
good first issue
gpu/amd
gpu/igpu
gpu/intel
gpu/nvidia
help wanted
kind
bug
kind
chore
kind
docs
kind
feature
kind
performance
kind
question
needs measurements
platform/linux
platform/macos
platform/steam-deck
platform/windows
preview
priority
critical
priority
high
priority
low
regression
risk
high
risk
low
risk
medium
status
blocked
status
confirmed
status
duplicate
status
invalid
status
needs-info
status
wontfix
ci: approved
No milestone
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
MagicBeanDev/Longshot!2543
Loading…
Reference in a new issue
No description provided.
Delete branch "igoticecream/Longshot:zelda-notes-server"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
The game's Zelda Notes features (map sync, the ocarina songs and photos it uploads, its play reports) need a server,
and Longshot never talks to Nintendo's, so they never worked. This PR lets the game talk to any Zelda Notes server the
player chooses, named in
longshot_env.txt:Unset (the default), nothing changes: the game stays offline and every new HLE answers as the import stubs did on
main. Set, the game's network layer is the host's sockets, pointed at that one server:host/nn_porter_net.c(new): thennsocket*calls on the host's sockets (Winsock, BSD sockets on Linux) behind atable of guest descriptors, in Horizon's layout (BSD sockaddr, Linux errno numbers written through the guest's
__errno_location); Poll andnn::socket::EventFd*; name lookups, which all resolve to the server, and connect,which refuses any other address and port; nifm, the network clock task and
GenerateCryptographicallyRandomBytes;nnssl*as a pass-through for curl's uploads; play reports posted tohttp://<server>:<report port>/prepoby ahost thread (queue capped at 256, 5 s socket timeouts).
game/oot_npln.c(new): NPLN's gRPC channels take their "use TLS" byte from one global; the game clears it, sothe channel builder takes insecure credentials. The host calls it through a new
game.hhook,game_online_start, fromnn::ssl::Initialize, which Porter's start calls just before it builds the client. Itchecks the pointer that reads the byte first and logs a warning if this build has it elsewhere.
host/nn_applet.c: with a server set, the account calls answer a network service account (a made-up id) and anunsigned, JWT-shaped id token;
StandardNetworkSystemClock::nowis the host clock;nnsocketPollgoes throughsocket_polllikenn::socket::detail::Poll; prepo Save/Send hand the report to the server.-lws2_32on Windows, and__errno_locationamong the entriesgen/image.cexports.player(gpu/vk/switches.def):LONGSHOT_PORTER_HOST,LONGSHOT_PORTER_PORT_SERVICE(6677, gRPC) and
LONGSHOT_PORTER_PORT_REPORT(6678, HTTP). They aren't an A/B or a kill switch: they are whichserver the player picks, which the team can't decide for them, like
HOS_DISCORD_APP_IDorLONGSHOT_NFC_DIR. AnInsert menu row can't hold an address (rows are choices, toggles and sliders).
docs/user/advanced.md(how to point it at a server, and that nothing is encrypted),and a line each in "What Longshot connects to" and the privacy page.
Nothing is encrypted: gRPC is plain HTTP/2 and the uploads are plain HTTP. The docs and the startup log line say so.
A server to try it with:
zelda_notes_demo.py,a small in-memory server (grpcio only) that answers the game's whole conversation and prints it. Run
python zelda_notes_demo.py, setLONGSHOT_PORTER_HOST=127.0.0.1, set the in-game Zelda Notes option to Use andload a save.
Read first:
host/nn_porter_net.c(its header comment),game/oot_npln.c, then thenn_applet.cdiff.Testing
Tested: Windows 10 Pro 22H2, RTX 3080, NVIDIA 621.01; a runtime of main @
be663a08with this PR's pack.LONGSHOT_PORTER_HOST): loaded a save and played about 5 minutes. The log saysporter: network request: offline, no otherporter:line, no crash, a clean exit.zelda_notes_demo.pyon 127.0.0.1: loaded a save with the Zelda Notes option on Use. The log hasporter: on: every connection goes to 127.0.0.1 (127.0.0.1):6677, ...,porter: gRPC without TLS (NPLN's TLS switch cleared), the name lookup sent to the server and three upload connections on 6678. The server logged thelogin, map sync started with 69 position updates, 17 play reports, the two Scarecrow ocarina song documents with
their files, and a daily-report photo (a 262 KB JPEG). No crash, a clean exit.
network request: offline, every set runporter: onand the gRPC connect.
tests/run_all.pyon Windows and on Linux (WSL, Ubuntu 24.04), on this branch and on main. On Linux thesame 59 fail on both (676 passed, 108 skipped each): checks needing packages and tools this WSL lacks. On Windows
the six checks reading the changed files that fail (
test_input_movie,test_linux_pressure,test_dev_ab,test_texture_ahead,test_bc_small_scratch,test_audio_output_devices) fail on main too.cargo fmt --check,cargo clippy -D warningsandcargo testforliftandbuild-compile: one test fails, onmain too on Windows (
toolchain::tests::the_builder_s_llvm_comes_before_emsdk_and_the_path, which writesclangwithout
.exe). The changed C compiles without warnings for Windows (llvm-mingw) and Linux (clang, WSL).pre-commitisn't installed here; checked by hand (git diff --check, end-of-file newlines). gitleaks runsin CI.
Still to test:
porter: network request: offlineand no crash (@Beanstalk start the game offline on Linux, load a save, play a minute)zelda_notes_demo.pyrunning andLONGSHOT_PORTER_HOST=127.0.0.1, load a save, expecting thelog's
porter: gRPC without TLS (NPLN's TLS switch cleared)and map sync positions in the server's output everysecond (by hand: the farm can't run the server)
Measurements
Verdict: no cost, off or on: every number is within the spread, both for main against this PR with no server
set, and for this PR with the server set against unset.
Setup: Windows 10 Pro 22H2, RTX 3080, NVIDIA 621.01;
dev.py ab --scene hyrule-field(Hyrule Field, child), theRender resolution at 67 %, uncapped (
HOS_FPS_MAX=1000), 60 s measured after the warm-up, three interleaved pairs,the median. Server set:
zelda_notes_demo.pyon 127.0.0.1, the game logged in and sent play reports during the runs(map sync did not start: the scene's save doesn't have Zelda Notes on).
No server set:
be663a08The server set against unset:
dev.py abwrote nomeasurements.mdfor either: it stopped with exit 3 on rows that differ between any two runs onthis PC, on main's side as much as this PR's.
HOS_CONTROLis a new socket name each run, and in the first A/B thesim_turf_*rows read "Load an area" in some runs. The tables are its own lines:The build:
-lws2_32and one more line ingen/image.c; the pack over main's base built in 13 s.Measured at b78d55ba on main @
be663a08, then rebased onto main @2e9e41cb. main's two commits since (#2536, #2541)change CI's workflows, the release script, a builder channel test and a doc page, nothing the game runs, so the
numbers hold.
Risks
LONGSHOT_PORTER_HOSTunset the new HLEs answer asmain's stubs did, so a player who setsnothing sees no change. Two offline crashes found while writing this (gRPC's poll engine on a failed EventFd, and
NPLN reading a null pointer after a failed
nnsocketPoll) are why the offline answers are what they are.the map, the songs, the photos and the play reports. The docs say so, and to name only a server they trust.
game_online_startlogs a warning and gRPC fails toconnect, offline as before.
LONGSHOT_PORTER_HOSTline. Nothing changes in saves,longshot_options.inior the caches.Checklist
Ready for review
main; the title is a Conventional Commit.mise run testpasses (any failure that also fails onmainis named). (tests/run_all.pydirectly, mise isn'tinstalled here; the failures, all on main too, are in Testing)
main, or Measurements says why there is nothing to measure.third_party/untouched; nothing GPL-incompatible.When it applies
gpu/vk/switches.def.(unset, off: the network stays as on main)
the changed files compile with clang in WSL, the whole Linux build is CI's)
Assisted-by:/Co-Authored-By:trailers.Ready to merge
main, measured again or a comment says why the numbers still hold.Tested in game: Windows 10, RTX 3080, NVIDIA 621.01: offline, a save played 5 min, 'porter: network request: offline', no crash; online against zelda_notes_demo.py on 127.0.0.1: login, map sync, play reports, ocarina songs and a photo reached the server, no crash
Possibly related, for context:
WIP: feat(runtime): Zelda Notes with a server you chooseto feat(runtime): Zelda Notes with a server you chooseView command line instructions
Checkout
From your project repository, check out a new branch and test the changes.