mirror of
https://github.com/tangerineturtle1/NX2navi.git
synced 2026-11-15 23:39:57 -04:00
Each player keeps their own game and save. One player makes a room, the others join it with its secret, and story flags and, by the room's rules, items, songs, quest items, small keys (a shared pool), rupees and ammunition reach every save. The layer is a host thread with one UDP socket to a relay the players run themselves (tools/coop_relay.py, Python's standard library only); the messages between the players are sealed with a key from the room's secret (XChaCha20-Poly1305, Monocypher 4.0.2 vendored with its licence and a row in THIRD_PARTY_NOTICES.md), every change is signed by the player who made it, a player accepts a room by its members' keys and the key of its rules, the save is copied to coop-backup before anything is applied, and values are set through the game's own routines between frames. The Co-op tab makes, joins, accepts, removes and leaves, and the menu takes typed text for the name, the relay and the secret. This is the contributor's pull request #518 on this line. Nothing reaches the network while co-op is off: the socket is opened, and the relay's name looked up, only after co-op is on, a relay is set and a room is made or joined. There is no default relay. Left out of the pull request: the other players drawn in the world (the "puppets") with the copied engine they need. They were unfinished, added two patch sites to the game's per-frame update that could not be put through the differential tests here, and their file helpers clashed with the ones this line already has. So no position is sent: the POS message's codec stays, nothing sends it. Changed against the pull request: - The menu's test hook drives the Co-op tab only when it comes from the environment. From nx2navi.ini it could turn co-op on, join a room and accept its offer. - The log's label for a room is hashed from the secret instead of being its first three characters. - A game that has not saved yet has no save to copy, and takes nothing from the room until it has saved once; that used to count as a copy made. - A PING's token no longer carries the PC's uptime. - On Windows the maker's key file and its folder get an access list with the player's account alone. - The tests that link the platform layer get the socket library, and the save test a stand-in for the title screen's hook. Checked on Windows, where the pull request had never been compiled: the runtime builds and links; --probe-coop passes (sockets on 127.0.0.1, the codec against its byte vectors, a fuzz of every parser, two sessions through a hostile mock relay, a relay restart, the sync engine); tests/coop_relay_test.py passes its 61 tests, with the probe through the real relay on 127.0.0.1 at 0 and 30 % loss; tests/coop_page_check.py passes and its deliberate fault fails 48 checks. Not checked: two games in one room (one game runs at a time here), any real network, the tab in the game. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
61 lines
3.2 KiB
Python
61 lines
3.2 KiB
Python
"""Build and run tests/coop_page_check.cpp: the menu's Co-op tab (runtime/ui/coop_page.cpp) without the game, driven with
|
|
the key and pad events the menu hands Dear ImGui, the co-op layer answered by the test. Typing a name, a relay and a
|
|
secret (with the letters that switch tabs elsewhere), Make, Join with a wrong secret and a pasted one, the room's offer
|
|
accepted and declined, the maker's key, a player not identified, a key accepted under another name, Remove by key, the
|
|
pools' contributors and their reset, Leave; no confirmation acts on a repeated or held press, the maker changes a rule
|
|
and the others cannot.
|
|
|
|
Then the same checks again with a deliberate fault (COOP_PAGE_FAULT=1: each window that acts on the room opens with the
|
|
cursor moved onto its acting button), which they must catch: the test passes only when the first run has no failed
|
|
check and the second has some.
|
|
|
|
Usage: coop_page_check.py (needs clang++ or g++; no game files)
|
|
"""
|
|
import os
|
|
import shutil
|
|
import subprocess
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
RT = ROOT / 'runtime'
|
|
SOURCES = [ROOT / 'tests' / 'coop_page_check.cpp', RT / 'ui' / 'option_rows.cpp', RT / 'ui' / 'menu_skin.cpp',
|
|
RT / 'ui_text.c', RT / 'coop_proto.c', RT / 'coop_state.c', RT / 'sha256.c',
|
|
RT / 'third_party' / 'monocypher' / 'monocypher.c'] + sorted((RT / 'third_party' / 'imgui').glob('imgui*.cpp'))
|
|
|
|
|
|
def main():
|
|
cxx = os.environ.get('CXX') or shutil.which('clang++') or shutil.which('g++')
|
|
if not cxx:
|
|
sys.exit('needs clang++ or g++ on PATH')
|
|
work = ROOT / 'build' / 'test' / 'coop_page'
|
|
work.mkdir(parents=True, exist_ok=True)
|
|
objs = []
|
|
for src in SOURCES:
|
|
obj = work / (src.stem + '.o')
|
|
lang = ['-x', 'c', '-std=gnu11'] if src.suffix == '.c' else ['-x', 'c++', '-std=gnu++17']
|
|
# the page's own file builds with the game's warnings; the rest as the game builds them, unchecked here
|
|
warn = ['-Wall', '-Wextra', '-Werror'] if src.name == 'coop_page_check.cpp' else ['-w']
|
|
if subprocess.run([cxx, *lang, '-c', '-O1', '-g', *warn, '-march=x86-64-v2', '-I', str(RT),
|
|
'-I', str(RT / 'third_party' / 'imgui'), str(src), '-o', str(obj)]).returncode:
|
|
sys.exit(f'{src.name} did not compile')
|
|
objs.append(str(obj))
|
|
exe = work / ('coop_page_check.exe' if os.name == 'nt' else 'coop_page_check')
|
|
if subprocess.run([cxx, *objs, '-o', str(exe), '-lm']).returncode:
|
|
sys.exit('the link failed')
|
|
env = {**os.environ, 'COOP_PAGE_FONT': str(RT / 'ui' / 'fonts' / 'Roboto-Medium.ttf')} # measures the rows' notes
|
|
r = subprocess.run([str(exe)], env=env)
|
|
if r.returncode:
|
|
sys.exit(r.returncode)
|
|
fault = subprocess.run([str(exe)], env={**env, 'COOP_PAGE_FAULT': '1'}, capture_output=True, text=True)
|
|
fails = [line for line in fault.stdout.splitlines() if line.startswith('FAIL ')]
|
|
print(f'deliberate fault (the cursor moved onto the acting button as a window opens): {len(fails)} checks fail')
|
|
for line in fails[:3]:
|
|
print(' ' + line)
|
|
if not fails:
|
|
sys.exit('the deliberate fault went unnoticed')
|
|
|
|
|
|
if __name__ == '__main__':
|
|
main()
|