mirror of
https://github.com/tangerineturtle1/NX2navi.git
synced 2026-11-20 08:19:56 -04:00
Add co-op, off by default: rooms through a relay, progress sync between the players' own saves, and a Co-op tab.
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>
This commit is contained in:
@@ -52,6 +52,8 @@ int gfx_window_vk_presentable(VkInstance inst, VkPhysicalDevice pd, uint32_t fam
|
||||
#define WND_STYLE WS_OVERLAPPEDWINDOW
|
||||
#define WM_APP_SETTINGS (WM_APP + 1)
|
||||
#define WM_APP_FULLSCREEN (WM_APP + 2) // the fullscreen setting, retried at the first activation
|
||||
#define WM_APP_TEXT_INPUT (WM_APP + 3) // the menu's text field takes text (wParam 1) or no longer (0)
|
||||
#define WM_APP_PASTE (WM_APP + 4) // the menu's Paste: the clipboard's text, read on the window thread
|
||||
|
||||
static WINDOWPLACEMENT g_saved_place = {sizeof g_saved_place}; // the window behind fullscreen (window thread)
|
||||
|
||||
@@ -189,6 +191,18 @@ void gfx_window_request_close(void) {
|
||||
if (g_hwnd) PostMessageW(g_hwnd, WM_CLOSE, 0, 0);
|
||||
}
|
||||
|
||||
// The menu's text field lives in this window, which has no IME (detached at creation, below): while the field takes
|
||||
// text the window gets the default one, so a player can type a name in Chinese, Japanese or Korean (Windows hands the
|
||||
// composed characters over as WM_CHAR, which menu_window_msg passes on), and it is detached again after. Posted to
|
||||
// the window thread, which owns the window's input context.
|
||||
void gfx_window_text_input(int on) {
|
||||
if (g_hwnd) PostMessageW(g_hwnd, WM_APP_TEXT_INPUT, (WPARAM)(on != 0), 0);
|
||||
}
|
||||
|
||||
void gfx_window_paste(void) {
|
||||
if (g_hwnd) PostMessageW(g_hwnd, WM_APP_PASTE, 0, 0);
|
||||
}
|
||||
|
||||
// ---- refresh rate of the window's monitor (NX2NAVI_FPS_LIMIT=display), measured when the window opens, lands on another
|
||||
// monitor or the display mode changes (gfx_window_set_refresh keeps it). QueryDisplayConfig gives the exact rational
|
||||
// rate (59.94, 143.998); EnumDisplaySettings' whole hertz is the fallback.
|
||||
@@ -496,6 +510,16 @@ static LRESULT CALLBACK wnd_proc(HWND h, UINT m, WPARAM w, LPARAM l) {
|
||||
input_cursor_suspend(0);
|
||||
}
|
||||
return 0;
|
||||
case WM_APP_TEXT_INPUT:
|
||||
if (w) ImmAssociateContextEx(h, NULL, IACE_DEFAULT);
|
||||
else ImmAssociateContext(h, NULL);
|
||||
return 0;
|
||||
case WM_APP_PASTE: {
|
||||
char text[256];
|
||||
plat_clipboard_get(text, sizeof text);
|
||||
menu_event_paste(text);
|
||||
return 0;
|
||||
}
|
||||
case WM_SIZE:
|
||||
keep_awake(w != SIZE_MINIMIZED);
|
||||
if (w != SIZE_MINIMIZED) gfx_window_mark_dirty();
|
||||
@@ -681,7 +705,8 @@ static void window_main(void *arg) {
|
||||
// An IME switched on over the game attaches to this window and then shows its candidate window and eats the keys
|
||||
// it composes, although there is nothing here to type into (a Chinese IME takes Shift, the B button by default).
|
||||
// Detaching the game's window leaves the software keyboard alone: its edit box sits in a window of its own
|
||||
// (swkbd_win.c) and gets the IME it needs.
|
||||
// (swkbd_win.c) and gets the IME it needs. The menu's text field attaches one while it takes text
|
||||
// (gfx_window_text_input).
|
||||
ImmAssociateContext(g_hwnd, NULL);
|
||||
// The frame was measured at the system DPI (or the chosen monitor's); the window may have opened on a monitor at
|
||||
// another scale. When the size changes on a chosen monitor, the window is centred again in its work area;
|
||||
|
||||
Reference in New Issue
Block a user