diff --git a/.github/ISSUE_TEMPLATE/bug.yml b/.github/ISSUE_TEMPLATE/bug.yml index 5200d373..95b65a1f 100644 --- a/.github/ISSUE_TEMPLATE/bug.yml +++ b/.github/ISSUE_TEMPLATE/bug.yml @@ -19,7 +19,7 @@ body: id: version attributes: label: Version - placeholder: "1.3.58" + placeholder: "1.3.59" validations: required: true - type: input diff --git a/AGENTS.md b/AGENTS.md index df9f292c..bde1d27c 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -2,7 +2,7 @@ ## Authority and scope -- This is U-Jagd 1.3.58 (`src/core/version.py`); current saves are v28-only. Treat these as compatibility contracts, not changelog entries. +- This is U-Jagd 1.3.59 (`src/core/version.py`); current saves are v28-only. Treat these as compatibility contracts, not changelog entries. - Resolve conflicts in this order: executable code and focused tests; packaged JSON/runtime resources; `pyproject.toml` and provenance/license notices; `README.md`; design/history documents under `docs/`. A plan or old comment is not an implementation contract. - Preserve explicit compatibility tests and user data unless a task intentionally changes the contract. Add a regression test for behavior changes. - Older phase/milestone labels under `docs/GDD.md`, `docs/implementation-plan.md`, `docs/plan-0.1.6.md`, and `docs/plan-0.1.7.md` are historical. Current resumable work is tracked in `docs/plan-1.3.md` and `docs/resume.md`. diff --git a/CHANGELOG.de.md b/CHANGELOG.de.md index ac35e5a4..71f0eea3 100644 --- a/CHANGELOG.de.md +++ b/CHANGELOG.de.md @@ -4,9 +4,9 @@ Alle Versionen von U-Jagd, die neueste zuerst. Die [README](README.de.md) zeigt nur die neueste. -## 1.3.58 +## 1.3.59 -Version 1.3.58 räumt auf, ohne das Spiel zu ändern. Die beiden größten Module +Version 1.3.59 räumt auf, ohne das Spiel zu ändern. Die beiden größten Module sind entlang ihrer Nähte geteilt: Radar-, Luft-, ECM-, ESM- und Funklage mit Flugkörpern und Angreifern ziehen aus dem Simulationsschritt in ein eigenes Modul, und die Aktionen der Remote-Crew-Stationen ziehen aus der Brücke in ein @@ -15,9 +15,9 @@ Aktualisierungsreihenfolge bleibt eingefroren. Der Changelog-Eintrag zu 1.3.43 beschreibt jetzt, was diese Version tatsächlich behoben hat. Spielstände bleiben v28. -## 1.3.57 +## 1.3.58 -Version 1.3.57 begrüßt den ersten Start mit einer Auswahl. Gibt es noch keine +Version 1.3.58 begrüßt den ersten Start mit einer Auswahl. Gibt es noch keine Einstellungsdatei, folgt auf das Startbild eine Seite mit der Frage, was du spielen möchtest: Fregatte öffnet das Training mit der ersten Fregatten- Lektion, U-Boot öffnet die erste U-Boot-Lektion und stellt die uConsole auf @@ -25,9 +25,9 @@ die U-Boot-Seite, Remote Crew öffnet die F9-Seite für Browser-Crews, und Hauptmenü (oder `Esc`) führt direkt ins Menü. Die Wahl wird gemerkt, die Seite erscheint also nur einmal. Spielstände bleiben v28. -## 1.3.56 +## 1.3.57 -Version 1.3.56 lässt die U-Boot-Besatzung mehr Meldungen sprechen. Neben +Version 1.3.57 lässt die U-Boot-Besatzung mehr Meldungen sprechen. Neben Kontakten, Ortungsimpulsen und Torpedowarnungen meldet das Boot jetzt den eigenen Torpedo los, Detonationen nah oder fern mit Peilung, Sinkgeräusche, die sein Sonar hören kann, einen aufgenommenen Rundspruch der Führung (und ob @@ -38,9 +38,9 @@ auf Deutsch oder Englisch. Jede gesprochene Meldung stammt aus einer Zeile im eigenen Bordbuch, die Besatzung hört also nie mehr, als ihr gemeldet wurde. Spielstände bleiben v28. -## 1.3.55 +## 1.3.56 -Version 1.3.55 gibt der OPZ Zuordnungsvorschläge. Melden zwei eigene Sensoren +Version 1.3.56 gibt der OPZ Zuordnungsvorschläge. Melden zwei eigene Sensoren des Schiffs (Sonar, Radar, ESM, Ausguck) einen Kontakt in derselben Peilung innerhalb ihrer Unsicherheit (und, wo beide eine Position haben, nah beieinander), bietet die OPZ das Paar zur Fusion an: auf der uConsole stehen @@ -50,9 +50,9 @@ mit Knöpfen zum Fusionieren und Verwerfen. Verglichen werden nur veröffentlichte Meldungen, die höchstens 30 s alt sind; ohne den Bediener wird nichts fusioniert. Spielstände bleiben v28. -## 1.3.54 +## 1.3.55 -Version 1.3.54 gibt der Fregatte eine Autopilot-Route. Auf der Brücke setzt +Version 1.3.55 gibt der Fregatte eine Autopilot-Route. Auf der Brücke setzt ein Rechtsklick in die Karte einen Wegpunkt (bis zu 8), `W` startet ein Suchmuster ab Position und Kurs des Schiffs (Zickzack mit 3 sm langen Schlägen, dann wachsendes Quadrat), und `Rücktaste` löscht die Route. Das @@ -64,9 +64,9 @@ Route mit nummerierten Wegpunkten, und die Remote-Crew-Brücke hat eine Karte Wegpunkten. Spielstände sind jetzt v28 (sie behalten die Route); v27-Stände laden nicht mehr. -## 1.3.53 +## 1.3.54 -Version 1.3.53 lässt die KI-Jäger das ESM der Fregatte nutzen. Hat die +Version 1.3.54 lässt die KI-Jäger das ESM der Fregatte nutzen. Hat die Fregatte keinen Standort des U-Boots, gibt jetzt ein ESM-Intercept eines Mastradars die Suchlinie: Die Bibliothek muss unter ihren drei besten Treffern ein U-Boot-Radar führen, und kein Schiff, das die Fregatte per Radar oder AIS @@ -75,9 +75,9 @@ Alter mit den HF/DF-Peilungen und bleibt 5 Minuten ein Datum; ein U-Boot, das auf Sehrohrtiefe sein Radar benutzt, zieht so Fregatte, Hubschrauber und Seefernaufklärer auf diese Peilung. Spielstände bleiben v27. -## 1.3.52 +## 1.3.53 -Version 1.3.52 bringt eine Absicherung gegen eingefrorene Remote-Crew-Browser. +Version 1.3.53 bringt eine Absicherung gegen eingefrorene Remote-Crew-Browser. Ein neuer Test spielt zwei belebte Missionen (die Fregatte mit Autocrew auf allen Stationen gegen das KI-U-Boot und ein besetztes U-Boot mit gefülltem Funkraum, Bedrohungsbild und HQ-Aufträgen), veröffentlicht Zustand und Karte @@ -86,18 +86,18 @@ des Browsers selbst. Ein Feld, das der Browser ablehnen würde, wie in 1.3.44, lässt jetzt die Tests vor einem Release scheitern. Am Spiel ändert sich nichts. Spielstände bleiben v27. -## 1.3.51 +## 1.3.52 -Version 1.3.51 lässt Remote-Crew-Browser einem Update des Hosts selbst folgen. +Version 1.3.52 lässt Remote-Crew-Browser einem Update des Hosts selbst folgen. Der Host nennt seine Version jetzt in jeder Antwort und in der Seite, die er ausliefert; eine Browserseite, die noch von vor dem Update offen ist, lädt sich einmal selbst neu und läuft so immer mit dem Web-Client, der zum Host passt, statt an Daten hängen zu bleiben, die sie nicht lesen kann. Spielstände bleiben v27. -## 1.3.50 +## 1.3.51 -Version 1.3.50 bringt einen Autosave. Eine laufende Mission wird alle 5 +Version 1.3.51 bringt einen Autosave. Eine laufende Mission wird alle 5 Minuten und beim Beenden oder Verlassen ins Hauptmenü nach `~/.u-jagd/autosave.json` gespeichert, neben den fünf Plätzen. Das Hauptmenü beginnt dann mit „Einsatz fortsetzen“, das sie exakt weiterführt; nach einem @@ -105,6 +105,17 @@ Absturz ist es der letzte 5-Minuten-Stand. Die Datei wird im Hintergrund geschrieben, damit die uConsole nicht ruckelt. Eine beendete und jede neue Mission löschen den Autosave. Spielstände bleiben v27. +## 1.3.50 + +Version 1.3.50 repariert die Remote-Crew-Kopplung im LAN. Ein frisch +gekoppelter Browser begrüßt nicht mehr mit „Deine Station wurde widerrufen oder +freigegeben“, als wäre die Kopplung gescheitert, sondern mit der Aufforderung, +eine freie Station zu nehmen. Die Crew-Seite sagt jetzt, wenn sie in einem +Browser läuft, der nicht Chrome oder Chromium (auch Edge) ist: Firefox und +Safari zeigen über dem Kopplungscode einen Hinweis, und eine Seite, die dort +nicht starten kann, sagt das, statt endlos zu laden. Der Navigationsvorschlag +der Brücke nimmt die vollen 31 kn der Fregatte an; Spielstände bleiben v27. + ## 1.3.49 Version 1.3.49 zeigt Flugzeuge im Fernglas des Ausgucks, im Ausguckstreifen, im diff --git a/CHANGELOG.md b/CHANGELOG.md index add92f62..be5f677f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,9 +4,9 @@ Every U-Jagd release, newest first. The [README](README.md) shows only the latest one. -## 1.3.58 +## 1.3.59 -Release 1.3.58 is a clean-up with no change in play. The two largest modules +Release 1.3.59 is a clean-up with no change in play. The two largest modules are split along their seams: the radar, air, ECM, ESM and radio pictures with missiles and raiders move from the simulation step into their own module, and the Remote Crew station action handlers move out of the bridge into their own @@ -14,9 +14,9 @@ module; the code moves verbatim and the update order stays frozen. The changelog entry of 1.3.43 now says what that release actually fixed. Saves stay v28. -## 1.3.57 +## 1.3.58 -Release 1.3.57 greets a first launch with a choice. When no settings file +Release 1.3.58 greets a first launch with a choice. When no settings file exists yet, the splash is followed by one page asking what you want to play: Frigate opens the training with the first frigate lesson selected, Submarine opens the first submarine lesson and sets the uConsole to the submarine side, @@ -24,9 +24,9 @@ Remote Crew opens the F9 page for browser crews, and Main menu (or `Esc`) goes straight to the menu. Any choice is remembered, so the page appears only once. Saves stay v28. -## 1.3.56 +## 1.3.57 -Release 1.3.56 lets the submarine's crew speak more of its reports. Besides +Release 1.3.57 lets the submarine's crew speak more of its reports. Besides contacts, pings and torpedo warnings the boat now calls out its own torpedo leaving the tube, detonations close aboard or at a distance with their bearing, breaking-up noises its sonar can hear, a copied HQ broadcast (and @@ -36,9 +36,9 @@ hit, hull damage and the mission result, in English or German. Every spoken report comes from a line in the boat's own log, so the crew never hears more than it has been told. Saves stay v28. -## 1.3.55 +## 1.3.56 -Release 1.3.55 gives the OPZ correlation suggestions. When two of the ship's +Release 1.3.56 gives the OPZ correlation suggestions. When two of the ship's own sensors (sonar, radar, ESM, lookout) report a contact on the same bearing within their uncertainty (and, where both have positions, close together), the OPZ offers the pair for fusion: on the uConsole up to two suggestions stand in @@ -47,9 +47,9 @@ Remote Crew OPZ lists up to four with Fuse and Dismiss buttons. Suggestions only compare published reports no older than 30 s; nothing is fused without the operator. Saves stay v28. -## 1.3.54 +## 1.3.55 -Release 1.3.54 gives the frigate an autopilot route. On the Bridge a right +Release 1.3.55 gives the frigate an autopilot route. On the Bridge a right click on the chart adds a waypoint (up to 8), `W` starts a search pattern from the ship's position and course (a zigzag of 3 NM legs, then an expanding square) and `Backspace` clears the route. The helm steers for each waypoint in @@ -59,9 +59,9 @@ the route with numbered waypoints, and the Remote Crew bridge has an "Autopilot route" card with the same patterns and a chart mode for setting waypoints. Saves are now v28 (they keep the route); v27 saves no longer load. -## 1.3.53 +## 1.3.54 -Release 1.3.53 lets the AI hunters use the frigate's ESM. When the frigate has +Release 1.3.54 lets the AI hunters use the frigate's ESM. When the frigate has no position on the submarine, an ESM intercept of a mast radar now gives the search line: the library must rank a submarine radar among its three best matches and no ship the frigate tracks by radar or AIS may lie within 10° of @@ -69,9 +69,9 @@ the bearing. It competes with the HF/DF bearings by age and stays a datum for 5 minutes, so a submarine that radiates at periscope depth draws the frigate, its helicopter and the patrol aircraft down that bearing. Saves stay v27. -## 1.3.52 +## 1.3.53 -Release 1.3.52 adds a guard against frozen Remote Crew browsers. A new test +Release 1.3.53 adds a guard against frozen Remote Crew browsers. A new test plays two busy missions (the frigate with the autocrew on every station against the AI submarine, and a crewed submarine with its radio, threat picture and HQ tasks filled), publishes every station's state and chart for @@ -79,23 +79,33 @@ both units and runs the browser's own validators over all of them in Node. A field the browser would refuse, as in 1.3.44, now fails the tests before a release. Nothing changes in play. Saves stay v27. -## 1.3.51 +## 1.3.52 -Release 1.3.51 lets Remote Crew browsers follow a host update by themselves. +Release 1.3.52 lets Remote Crew browsers follow a host update by themselves. The host now names its version on every reply and in the page it serves; a browser page that is still open from before an update reloads itself once and so always runs the web client that matches the host, instead of freezing on data it cannot read. Saves stay v27. -## 1.3.50 +## 1.3.51 -Release 1.3.50 adds an autosave. A running mission is saved every 5 minutes +Release 1.3.51 adds an autosave. A running mission is saved every 5 minutes and when you quit or leave it for the main menu, to `~/.u-jagd/autosave.json` beside the five slots. The main menu then starts with "Continue mission", which resumes it exactly; after a crash it holds the last 5-minute save. The file is written in the background so the uConsole does not stutter. A mission that ends and any new mission delete the autosave. Saves stay v27. +## 1.3.50 + +Release 1.3.50 fixes Remote Crew pairing on the LAN. A freshly paired +browser no longer greets you with "Your station was revoked or released" as if +pairing had failed; it now says "Authenticated. Take a free station." The crew +page now tells you when it runs in a browser that is not Chrome or Chromium (also +Edge): Firefox and Safari show a hint above the pairing code, and a page that +cannot start there says so instead of loading forever. The bridge's navigation +proposal accepts the frigate's full 31 kn; saves stay v27. + ## 1.3.49 Release 1.3.49 puts aircraft at their true height in the lookout's binoculars, diff --git a/README.de.md b/README.de.md index fe826f33..48c71304 100644 --- a/README.de.md +++ b/README.de.md @@ -14,9 +14,9 @@ Sie führen eine fiktive Fregatte und wechseln zwischen neun Arbeitsplätzen, um zu navigieren, zu suchen, Kontakte zu klassifizieren, Ziele zu bekämpfen und das Schiff einsatzfähig zu halten. -Aktuelle Version: **1.3.58** +Aktuelle Version: **1.3.59** -Version 1.3.58 räumt auf, ohne das Spiel zu ändern. Die beiden größten Module +Version 1.3.59 räumt auf, ohne das Spiel zu ändern. Die beiden größten Module sind entlang ihrer Nähte geteilt: Radar-, Luft-, ECM-, ESM- und Funklage mit Flugkörpern und Angreifern ziehen aus dem Simulationsschritt in ein eigenes Modul, und die Aktionen der Remote-Crew-Stationen ziehen aus der Brücke in ein diff --git a/README.md b/README.md index 1657ce3e..a055257f 100644 --- a/README.md +++ b/README.md @@ -12,9 +12,9 @@ around the ClockworkPi uConsole's 1280 x 720 workspace. You command a fictional frigate and move between nine workstations to navigate, search, classify, engage, and keep the ship operational. -Current release: **1.3.58** +Current release: **1.3.59** -Release 1.3.58 is a clean-up with no change in play. The two largest modules +Release 1.3.59 is a clean-up with no change in play. The two largest modules are split along their seams: the radar, air, ECM, ESM and radio pictures with missiles and raiders move from the simulation step into their own module, and the Remote Crew station action handlers move out of the bridge into their own diff --git a/data/commander/css/screens.css b/data/commander/css/screens.css index 632888b0..046230aa 100644 --- a/data/commander/css/screens.css +++ b/data/commander/css/screens.css @@ -108,3 +108,4 @@ body.workstation-mode .role-rail, body.workstation-mode .mobile-role { display: .mobile-role:not([hidden]) { grid-template-columns: minmax(0, 1fr) auto; } .mobile-role label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0, 0, 0, 0); } } +.pair-card > .browser-hint { padding: .6rem .8rem; color: var(--text); background: var(--bg-3); border-left: 3px solid var(--alarm); } diff --git a/data/commander/css/shell.css b/data/commander/css/shell.css index 492e4a36..9807a0fd 100644 --- a/data/commander/css/shell.css +++ b/data/commander/css/shell.css @@ -268,3 +268,4 @@ body.workstation-mode .tablist { display: none; } .dock[data-collapsed="true"] .dock-title { writing-mode: horizontal-tb; transform: none; } .dock[data-collapsed="true"] .dock-toggle { order: 0; } } +.bootstrap-hint { flex-basis: 100%; max-width: 46ch; margin: 0; color: var(--alarm); text-align: center; } diff --git a/data/commander/index.html b/data/commander/index.html index 01e186f9..17202c16 100644 --- a/data/commander/index.html +++ b/data/commander/index.html @@ -14,11 +14,12 @@ + -
U-Jagd Commander
+
U-Jagd Commander
diff --git a/data/commander/js/browser-check.js b/data/commander/js/browser-check.js new file mode 100644 index 00000000..41db0a4b --- /dev/null +++ b/data/commander/js/browser-check.js @@ -0,0 +1,31 @@ +// Browser check of the pairing page. A classic script, independent of the +// ES module client: it still runs when a browser cannot load or evaluate the +// modules, so the page never stays silently on its loading screen. +(() => { + const agent = navigator.userAgent || ""; + // Chrome, Chromium, Edge, Opera and other Blink browsers name "Chrome/"; + // Firefox and Safari (also Chrome on iOS, which is WebKit) do not. + const chromium = /(?:Chrome|Chromium)\/\d/.test(agent) && !/\b(?:CriOS|FxiOS|EdgiOS)\//.test(agent); + const root = document.documentElement; + root.dataset.browser = chromium ? "chromium" : "other"; + const hint = document.getElementById("browser-hint"); + if (hint) hint.hidden = chromium; + // The module client hides #bootstrap once its language catalog is loaded. + setTimeout(async () => { + const bootstrap = document.getElementById("bootstrap"); + const note = document.getElementById("bootstrap-hint"); + if (!bootstrap || bootstrap.hidden || !note) return; + root.dataset.startup = "stalled"; + const language = /^de\b/i.test(navigator.language || "") ? "de" : "en"; + try { + const response = await fetch(`/api/v2/ui?lang=${language}`, {cache: "no-store", credentials: "omit"}); + const catalog = response.ok ? await response.json() : null; + const text = catalog && catalog["commander.web.browser_stalled"]; + if (typeof text !== "string" || bootstrap.hidden) return; + note.textContent = text; + note.hidden = false; + } catch (_) { + // The host is unreachable: the loading screen stays as it is. + } + }, 8000); +})(); diff --git a/data/commander/js/input/wiring.js b/data/commander/js/input/wiring.js index 1618f4c9..e0b9f264 100644 --- a/data/commander/js/input/wiring.js +++ b/data/commander/js/input/wiring.js @@ -677,7 +677,7 @@ export function init() { if (course !== null) params.course = course; if (speed !== null) params.speed_kn = speed; if (!Object.keys(params).length || (course !== null && (!finite(course) || course < 0 || course >= 360)) || - (speed !== null && (!finite(speed) || speed < 0 || speed > 25))) { + (speed !== null && (!finite(speed) || speed < 0 || speed > 31))) { S.commandMessage = {key: "navigation_invalid", status: "rejected"}; renderActionState(); return; diff --git a/data/commander/js/state/display-model.js b/data/commander/js/state/display-model.js index 2cb2665a..0662562d 100644 --- a/data/commander/js/state/display-model.js +++ b/data/commander/js/state/display-model.js @@ -118,7 +118,7 @@ export function validateProposals(value) { if (value.navigation !== null && (!exactKeys(value.navigation, ["course", "speed_kn", "status"]) || value.role !== "bridge" || !validStatus(value.navigation.status) || (value.navigation.course !== null && (!finite(value.navigation.course) || value.navigation.course < 0 || value.navigation.course >= 360)) || - (value.navigation.speed_kn !== null && (!finite(value.navigation.speed_kn) || value.navigation.speed_kn < 0 || value.navigation.speed_kn > 25)) || + (value.navigation.speed_kn !== null && (!finite(value.navigation.speed_kn) || value.navigation.speed_kn < 0 || value.navigation.speed_kn > 31)) || value.navigation.course === null && value.navigation.speed_kn === null)) throw new Error("proposals"); } export function validateEvents(value) { diff --git a/data/commander/js/views/lobby.js b/data/commander/js/views/lobby.js index 2b1b19aa..a6095bc3 100644 --- a/data/commander/js/views/lobby.js +++ b/data/commander/js/views/lobby.js @@ -152,7 +152,7 @@ export function acceptSession(next) { const changed = previous && (previous.station !== next.station || previous.station_generation !== next.station_generation || previous.active_generation !== next.active_generation); - const lostRole = previous?.station !== null && next.station === null; + const lostRole = previous != null && previous.station !== null && next.station === null; // A plain activation moves between leases this client already held under the // same generations; any lease, grant or world change is a full reset. const activation = changed && previous.station !== null && next.station !== null && diff --git a/data/i18n/de.json b/data/i18n/de.json index 7fc9f41a..88b9771f 100644 --- a/data/i18n/de.json +++ b/data/i18n/de.json @@ -419,6 +419,8 @@ "commander.web.pair_intro": "Mission beobachten, Kontakte bewerten und der Besatzung ein Ziel vorschlagen. Das taktische Lagebild im Blick behalten, ohne das Ruder zu übernehmen.", "commander.web.authority_note": "Schiffsführung und Waffeneinsatz bleiben bei der Besatzung. Ein Zielvorschlag ist kein Waffenbefehl.", "commander.web.pair_heading": "Mit der Besatzung verbinden", + "commander.web.browser_hint": "Remote Crew ist für Chrome oder Chromium (auch Edge) auf einem Desktop-PC gebaut und getestet. Dieser Browser basiert nicht auf Chromium, daher können Kopplung, Ton oder Stationsbilder versagen. Öffne diese Adresse in Chrome oder Chromium.", + "commander.web.browser_stalled": "Die Crew-Seite ist in diesem Browser nicht gestartet. Öffne diese Adresse in Chrome oder Chromium (auch Edge) oder lade die Seite neu.", "commander.web.pair_help": "Den Host-Code eingeben: 3 Ziffern, danach 3 Großbuchstaben. Kleinbuchstaben werden automatisch umgewandelt. Der Code läuft nach 5 Minuten ab. Nur ein vertrauenswürdiges Netz verwenden.", "commander.web.pair_name": "Stationsname", "commander.web.pair_name_default": "Wachoffizier", diff --git a/data/i18n/en.json b/data/i18n/en.json index c183b7eb..447edc31 100644 --- a/data/i18n/en.json +++ b/data/i18n/en.json @@ -419,6 +419,8 @@ "commander.web.pair_intro": "Observe the mission, annotate contacts and propose a target to the crew. Keep the tactical picture in view without taking the helm.", "commander.web.authority_note": "The crew retains ship control and weapon authority. A target proposal is not a weapon order.", "commander.web.pair_heading": "Join the crew", + "commander.web.browser_hint": "Remote Crew is built and tested for Chrome or Chromium (also Edge) on a desktop PC. This browser is not Chromium-based, so pairing, sound or station pictures may fail. Open this address in Chrome or Chromium.", + "commander.web.browser_stalled": "The crew page did not start in this browser. Open this address in Chrome or Chromium (also Edge), or reload the page.", "commander.web.pair_help": "Enter the host's code: 3 digits followed by 3 uppercase letters. Lowercase input is converted automatically. The code expires after 5 minutes. Use only a network you trust.", "commander.web.pair_name": "Station name", "commander.web.pair_name_default": "Watch Officer", diff --git a/data/manual/00-quickstart.de.md b/data/manual/00-quickstart.de.md index 2462af33..83e394d9 100644 --- a/data/manual/00-quickstart.de.md +++ b/data/manual/00-quickstart.de.md @@ -88,7 +88,7 @@ Die Statuszeile unten zeigt das neueste Ereignis und die wichtigste Telemetrie; - `S` / `L`: Speichern / Laden (Plätze 1-5). Spielstände sind exakt und deterministisch: ein geladenes Spiel läuft identisch weiter. - **Autosave:** Eine laufende Mission wird alle 5 Minuten und beim Beenden oder Verlassen ins Hauptmenü nach `~/.u-jagd/autosave.json` gespeichert, neben den fünf Plätzen. Das Hauptmenü beginnt dann mit **Einsatz fortsetzen**, das sie exakt weiterführt; nach einem Absturz ist es der letzte 5-Minuten-Stand. Eine beendete Mission (Sieg, Niederlage oder Schiff gesunken) und jede neue Mission löschen den Autosave. Der Web-Host (`--web-host`) speichert nicht automatisch. - `F10`: Optionen - Sprache, Vollbild, Audio, große Schrift, Tooltips, Bildrate (30 oder 60 FPS; 30 spart Rechenleistung auf der uConsole und ist voreingestellt), Ereignislog/Telemetrie als Statuszeile (Standard, mehr Platz für die Station) oder feste Leiste, Bedienerassistenz aus (Standard: Rohdaten und manuelle Analyse) oder Training (automatische Linienbeschriftung, Blattfrequenz- und Katalog-/Senderkandidaten). Seite 2 (`Bild ab`/`Tab`): welche Seite der uConsole spielt, Fregatte (Standard) oder feindliches U-Boot; nur im Hauptmenü, nie gespeichert. Ein neues Spiel fragt ohnehin zuerst danach. Auf Seite 2 liegen auch die **geglätteten Kartenlinien** (standardmäßig aus; glättet Peilstriche, Küste und Plot, kostet auf der uConsole etwas Rechenzeit). Dazu die **gesprochenen Crew-Meldungen** (standardmäßig aus): die Crew meldet Torpedo im Wasser, neuen Kontakt mit Peilung, Sinkgeräusche, Torpedo los, Treffer, Gefechtsstationen, Seefernaufklärer auf Station und das Missionsende laut, Peilungen Ziffer für Ziffer. Die uConsole spricht über ein installiertes `espeak-ng` (`sudo apt install espeak-ng`) und bleibt ohne es stumm; Remote-Crew-Browser haben einen eigenen Schalter unter Einstellungen (Sprachausgabe des Browsers, in dessen Sprache). Spielt die uConsole das U-Boot, meldet stattdessen dessen Crew (siehe Kapitel Referenz). -- `F9`: Commander / Remote Crew - Browser im LAN können Stationen übernehmen. Eine freie Station wird sofort mit allen ihren Rechten übernommen (auch Direktfeuer und Sonar-Liveaudio, wo die Station sie hat); eine Station, die ein Crewmitglied hält, wird angefragt, und der Host kann sie übergeben. Der Host kann jederzeit eine Station oder einzelne Rechte entziehen und bis zu zwei Browser zu reinen Beobachtern machen (Roster-Taste `O`): sie sehen jede Station beider Einheiten, ohne sie zu halten, können nichts befehlen und erhalten das SimLog mit Zeitstrahl zur Nachbesprechung und JSON-Export. Auf einem Windows-PC startet das Programm `U-Jagd-Windows.exe` das Spiel mit bereits eingeschalteter Remote Crew (Besatzungs- oder Solomodus) und zeigt Browser-Adresse, Beitrittscode und QR-Code; `--remote-crew` macht dasselbe über die Kommandozeile (siehe README). Nach einem Update des Hosts lädt sich eine offene Browserseite einmal selbst neu und läuft so immer mit dem passenden Web-Client. +- `F9`: Commander / Remote Crew - Browser im LAN können Stationen übernehmen. Eine freie Station wird sofort mit allen ihren Rechten übernommen (auch Direktfeuer und Sonar-Liveaudio, wo die Station sie hat); eine Station, die ein Crewmitglied hält, wird angefragt, und der Host kann sie übergeben. Der Host kann jederzeit eine Station oder einzelne Rechte entziehen und bis zu zwei Browser zu reinen Beobachtern machen (Roster-Taste `O`): sie sehen jede Station beider Einheiten, ohne sie zu halten, können nichts befehlen und erhalten das SimLog mit Zeitstrahl zur Nachbesprechung und JSON-Export. Auf einem Windows-PC startet das Programm `U-Jagd-Windows.exe` das Spiel mit bereits eingeschalteter Remote Crew (Besatzungs- oder Solomodus) und zeigt Browser-Adresse, Beitrittscode und QR-Code; `--remote-crew` macht dasselbe über die Kommandozeile (siehe README). Die Crew-Seite ist für Chrome oder Chromium (auch Edge) auf einem Desktop-PC gebaut; ein anderer Browser zeigt über dem Kopplungscode einen Hinweis, und eine Seite, die dort nicht starten kann, sagt das, statt endlos zu laden. Nach einem Update des Hosts lädt sich eine offene Browserseite einmal selbst neu und läuft so immer mit dem passenden Web-Client. ## Handy-Ausguck und Sehrohr {#qs-phone} diff --git a/data/manual/00-quickstart.en.md b/data/manual/00-quickstart.en.md index 9487403a..c07902d9 100644 --- a/data/manual/00-quickstart.en.md +++ b/data/manual/00-quickstart.en.md @@ -88,7 +88,7 @@ The bottom status ticker shows the newest event and key telemetry; `F11` opens t - `S` / `L`: save / load (slots 1-5). Saves are exact and deterministic: a loaded game continues identically. - **Autosave:** a running mission is saved every 5 minutes and when you quit or leave it for the main menu, to `~/.u-jagd/autosave.json` beside the five slots. The main menu then starts with **Continue mission**, which resumes it exactly; after a crash it holds the last 5-minute save. A mission that ends (won, lost or ship sunk) and any new mission delete the autosave. The web host (`--web-host`) does not autosave. - `F10`: options - language, fullscreen, audio, large text, tooltips, frame rate (30 or 60 FPS; 30 saves CPU on the uConsole and is the default), event log / telemetry as status ticker (default, more room for the station) or docked band, operator assistance off (default: raw data and manual analysis) or training (automatic line labels, blade-rate and catalogue/emitter candidates). Page 2 (`PgDn`/`Tab`): which side the uConsole plays, frigate (default) or hostile submarine; only in the main menu, never saved. A new game asks for it first anyway. Page 2 also holds **anti-aliased chart lines** (off by default; smooths bearing lines, coast and plot at some CPU cost on the uConsole). And **spoken crew reports** (off by default): the crew says torpedo in the water, new contact with bearing, breaking-up noises, torpedo away, hit, action stations, patrol aircraft on station and the mission result aloud, bearings digit by digit. The uConsole speaks through an installed `espeak-ng` (`sudo apt install espeak-ng`) and stays silent without it; Remote Crew browsers have their own switch under Settings (the browser's speech synthesis, in the browser's language). With the uConsole on the submarine the submarine's crew reports instead (see the reference chapter). -- `F9`: Commander / Remote Crew - lets browser clients on the LAN take stations. A free station is taken at once with all of its rights (including direct fire and live sonar audio where the station has them); a station a crewmate holds is requested, and the host can hand it over. The host can revoke a station or single rights at any time, and can make up to two browsers read-only observers (roster key `O`): they watch any station of either unit without holding it, cannot command, and get the SimLog with a debrief timeline and JSON export. On a Windows PC the program `U-Jagd-Windows.exe` starts the game with Remote Crew already on (crew or solo mode) and shows the browser address, join code and QR code; `--remote-crew` does the same from the command line (see the README). After a host update an open browser page reloads itself once, so it always runs the web client that matches the host. +- `F9`: Commander / Remote Crew - lets browser clients on the LAN take stations. A free station is taken at once with all of its rights (including direct fire and live sonar audio where the station has them); a station a crewmate holds is requested, and the host can hand it over. The host can revoke a station or single rights at any time, and can make up to two browsers read-only observers (roster key `O`): they watch any station of either unit without holding it, cannot command, and get the SimLog with a debrief timeline and JSON export. On a Windows PC the program `U-Jagd-Windows.exe` starts the game with Remote Crew already on (crew or solo mode) and shows the browser address, join code and QR code; `--remote-crew` does the same from the command line (see the README). The crew page is built for Chrome or Chromium (also Edge) on a desktop PC; another browser shows a hint above the pairing code, and a page that cannot start there says so instead of loading forever. After a host update an open browser page reloads itself once, so it always runs the web client that matches the host. ## Phone lookout and periscope {#qs-phone} diff --git a/docs/manual/handbuch.de.pdf b/docs/manual/handbuch.de.pdf index a893e885..88b2281b 100644 Binary files a/docs/manual/handbuch.de.pdf and b/docs/manual/handbuch.de.pdf differ diff --git a/docs/manual/manual.de.md b/docs/manual/manual.de.md index ef705d38..64c5dde1 100644 --- a/docs/manual/manual.de.md +++ b/docs/manual/manual.de.md @@ -134,7 +134,7 @@ Die Statuszeile unten zeigt das neueste Ereignis und die wichtigste Telemetrie; - `S` / `L`: Speichern / Laden (Plätze 1-5). Spielstände sind exakt und deterministisch: ein geladenes Spiel läuft identisch weiter. - **Autosave:** Eine laufende Mission wird alle 5 Minuten und beim Beenden oder Verlassen ins Hauptmenü nach `~/.u-jagd/autosave.json` gespeichert, neben den fünf Plätzen. Das Hauptmenü beginnt dann mit **Einsatz fortsetzen**, das sie exakt weiterführt; nach einem Absturz ist es der letzte 5-Minuten-Stand. Eine beendete Mission (Sieg, Niederlage oder Schiff gesunken) und jede neue Mission löschen den Autosave. Der Web-Host (`--web-host`) speichert nicht automatisch. - `F10`: Optionen - Sprache, Vollbild, Audio, große Schrift, Tooltips, Bildrate (30 oder 60 FPS; 30 spart Rechenleistung auf der uConsole und ist voreingestellt), Ereignislog/Telemetrie als Statuszeile (Standard, mehr Platz für die Station) oder feste Leiste, Bedienerassistenz aus (Standard: Rohdaten und manuelle Analyse) oder Training (automatische Linienbeschriftung, Blattfrequenz- und Katalog-/Senderkandidaten). Seite 2 (`Bild ab`/`Tab`): welche Seite der uConsole spielt, Fregatte (Standard) oder feindliches U-Boot; nur im Hauptmenü, nie gespeichert. Ein neues Spiel fragt ohnehin zuerst danach. Auf Seite 2 liegen auch die **geglätteten Kartenlinien** (standardmäßig aus; glättet Peilstriche, Küste und Plot, kostet auf der uConsole etwas Rechenzeit). Dazu die **gesprochenen Crew-Meldungen** (standardmäßig aus): die Crew meldet Torpedo im Wasser, neuen Kontakt mit Peilung, Sinkgeräusche, Torpedo los, Treffer, Gefechtsstationen, Seefernaufklärer auf Station und das Missionsende laut, Peilungen Ziffer für Ziffer. Die uConsole spricht über ein installiertes `espeak-ng` (`sudo apt install espeak-ng`) und bleibt ohne es stumm; Remote-Crew-Browser haben einen eigenen Schalter unter Einstellungen (Sprachausgabe des Browsers, in dessen Sprache). Spielt die uConsole das U-Boot, meldet stattdessen dessen Crew (siehe Kapitel Referenz). -- `F9`: Commander / Remote Crew - Browser im LAN können Stationen übernehmen. Eine freie Station wird sofort mit allen ihren Rechten übernommen (auch Direktfeuer und Sonar-Liveaudio, wo die Station sie hat); eine Station, die ein Crewmitglied hält, wird angefragt, und der Host kann sie übergeben. Der Host kann jederzeit eine Station oder einzelne Rechte entziehen und bis zu zwei Browser zu reinen Beobachtern machen (Roster-Taste `O`): sie sehen jede Station beider Einheiten, ohne sie zu halten, können nichts befehlen und erhalten das SimLog mit Zeitstrahl zur Nachbesprechung und JSON-Export. Auf einem Windows-PC startet das Programm `U-Jagd-Windows.exe` das Spiel mit bereits eingeschalteter Remote Crew (Besatzungs- oder Solomodus) und zeigt Browser-Adresse, Beitrittscode und QR-Code; `--remote-crew` macht dasselbe über die Kommandozeile (siehe README). Nach einem Update des Hosts lädt sich eine offene Browserseite einmal selbst neu und läuft so immer mit dem passenden Web-Client. +- `F9`: Commander / Remote Crew - Browser im LAN können Stationen übernehmen. Eine freie Station wird sofort mit allen ihren Rechten übernommen (auch Direktfeuer und Sonar-Liveaudio, wo die Station sie hat); eine Station, die ein Crewmitglied hält, wird angefragt, und der Host kann sie übergeben. Der Host kann jederzeit eine Station oder einzelne Rechte entziehen und bis zu zwei Browser zu reinen Beobachtern machen (Roster-Taste `O`): sie sehen jede Station beider Einheiten, ohne sie zu halten, können nichts befehlen und erhalten das SimLog mit Zeitstrahl zur Nachbesprechung und JSON-Export. Auf einem Windows-PC startet das Programm `U-Jagd-Windows.exe` das Spiel mit bereits eingeschalteter Remote Crew (Besatzungs- oder Solomodus) und zeigt Browser-Adresse, Beitrittscode und QR-Code; `--remote-crew` macht dasselbe über die Kommandozeile (siehe README). Die Crew-Seite ist für Chrome oder Chromium (auch Edge) auf einem Desktop-PC gebaut; ein anderer Browser zeigt über dem Kopplungscode einen Hinweis, und eine Seite, die dort nicht starten kann, sagt das, statt endlos zu laden. Nach einem Update des Hosts lädt sich eine offene Browserseite einmal selbst neu und läuft so immer mit dem passenden Web-Client. ### Handy-Ausguck und Sehrohr diff --git a/docs/manual/manual.en.md b/docs/manual/manual.en.md index 52802754..9ea5541b 100644 --- a/docs/manual/manual.en.md +++ b/docs/manual/manual.en.md @@ -134,7 +134,7 @@ The bottom status ticker shows the newest event and key telemetry; `F11` opens t - `S` / `L`: save / load (slots 1-5). Saves are exact and deterministic: a loaded game continues identically. - **Autosave:** a running mission is saved every 5 minutes and when you quit or leave it for the main menu, to `~/.u-jagd/autosave.json` beside the five slots. The main menu then starts with **Continue mission**, which resumes it exactly; after a crash it holds the last 5-minute save. A mission that ends (won, lost or ship sunk) and any new mission delete the autosave. The web host (`--web-host`) does not autosave. - `F10`: options - language, fullscreen, audio, large text, tooltips, frame rate (30 or 60 FPS; 30 saves CPU on the uConsole and is the default), event log / telemetry as status ticker (default, more room for the station) or docked band, operator assistance off (default: raw data and manual analysis) or training (automatic line labels, blade-rate and catalogue/emitter candidates). Page 2 (`PgDn`/`Tab`): which side the uConsole plays, frigate (default) or hostile submarine; only in the main menu, never saved. A new game asks for it first anyway. Page 2 also holds **anti-aliased chart lines** (off by default; smooths bearing lines, coast and plot at some CPU cost on the uConsole). And **spoken crew reports** (off by default): the crew says torpedo in the water, new contact with bearing, breaking-up noises, torpedo away, hit, action stations, patrol aircraft on station and the mission result aloud, bearings digit by digit. The uConsole speaks through an installed `espeak-ng` (`sudo apt install espeak-ng`) and stays silent without it; Remote Crew browsers have their own switch under Settings (the browser's speech synthesis, in the browser's language). With the uConsole on the submarine the submarine's crew reports instead (see the reference chapter). -- `F9`: Commander / Remote Crew - lets browser clients on the LAN take stations. A free station is taken at once with all of its rights (including direct fire and live sonar audio where the station has them); a station a crewmate holds is requested, and the host can hand it over. The host can revoke a station or single rights at any time, and can make up to two browsers read-only observers (roster key `O`): they watch any station of either unit without holding it, cannot command, and get the SimLog with a debrief timeline and JSON export. On a Windows PC the program `U-Jagd-Windows.exe` starts the game with Remote Crew already on (crew or solo mode) and shows the browser address, join code and QR code; `--remote-crew` does the same from the command line (see the README). After a host update an open browser page reloads itself once, so it always runs the web client that matches the host. +- `F9`: Commander / Remote Crew - lets browser clients on the LAN take stations. A free station is taken at once with all of its rights (including direct fire and live sonar audio where the station has them); a station a crewmate holds is requested, and the host can hand it over. The host can revoke a station or single rights at any time, and can make up to two browsers read-only observers (roster key `O`): they watch any station of either unit without holding it, cannot command, and get the SimLog with a debrief timeline and JSON export. On a Windows PC the program `U-Jagd-Windows.exe` starts the game with Remote Crew already on (crew or solo mode) and shows the browser address, join code and QR code; `--remote-crew` does the same from the command line (see the README). The crew page is built for Chrome or Chromium (also Edge) on a desktop PC; another browser shows a hint above the pairing code, and a page that cannot start there says so instead of loading forever. After a host update an open browser page reloads itself once, so it always runs the web client that matches the host. ### Phone lookout and periscope diff --git a/docs/manual/manual.en.pdf b/docs/manual/manual.en.pdf index 0028d65a..67408712 100644 Binary files a/docs/manual/manual.en.pdf and b/docs/manual/manual.en.pdf differ diff --git a/docs/plan-uboot-stations.md b/docs/plan-uboot-stations.md index 25a876fc..516daa3d 100644 --- a/docs/plan-uboot-stations.md +++ b/docs/plan-uboot-stations.md @@ -152,7 +152,7 @@ plan mit auf und setzte das auch um"): zum Datum, befreundete KI-Kriegsschiffe mit ASROC schießen per Datenlink (Dominik: kein eigener Geleitzerstörer). Radarpunkte und Markierungen im Spielstand v25 (`radar_marks`). ESM-Peilungen der Fregatte auf das - Bootsradar nutzen die Jäger seit 1.3.53 als Suchlinie. + Bootsradar nutzen die Jäger seit 1.3.54 als Suchlinie. 7. ~~**KI-U-Boot mit Auftrag**~~ erledigt in 1.3.30 (`src/core/boat_ai.py`): Ein unbesetztes Missionsboot fährt Durchbruch, Aufklärung (Sehrohrtiefe, Meldung) und Geleitzugangriff (Torpedos auf Handelsschiffe) statt zu diff --git a/docs/station-shortcuts.de.md b/docs/station-shortcuts.de.md index 4fb48862..cdfcab80 100644 --- a/docs/station-shortcuts.de.md +++ b/docs/station-shortcuts.de.md @@ -1,4 +1,4 @@ -# U-Jagd 1.3.58 - Stations- und Tastenkürzel +# U-Jagd 1.3.59 - Stations- und Tastenkürzel Druckfassung: [`station-shortcuts.de.pdf`](station-shortcuts.de.pdf). Maßgeblich ist die implementierte lokale Bedienung. Stationsnummern und diff --git a/docs/station-shortcuts.de.pdf b/docs/station-shortcuts.de.pdf index 8f6dfe40..bfffb8a9 100644 Binary files a/docs/station-shortcuts.de.pdf and b/docs/station-shortcuts.de.pdf differ diff --git a/src/commander/actions.py b/src/commander/actions.py index 07873d49..42a9df4f 100644 --- a/src/commander/actions.py +++ b/src/commander/actions.py @@ -3,7 +3,7 @@ v2 action, applied on the main thread through the closed tables ``_V2_ACTION_HANDLERS``, ``_UBOOT_ACTION_HANDLERS`` and ``_HOST_ACTION_HANDLERS`` (never a dynamic method lookup). -Verbatim move from ``bridge.py`` (1.3.58); ``bridge.py`` re-exports every +Verbatim move from ``bridge.py`` (1.3.59); ``bridge.py`` re-exports every name so existing imports keep working.""" import math diff --git a/src/core/game_radar.py b/src/core/game_radar.py index ee650231..f59effdb 100644 --- a/src/core/game_radar.py +++ b/src/core/game_radar.py @@ -2,7 +2,7 @@ tracks, mast echoes, ECM, ESM and radio pictures, anti-ship missiles and raiders (``Game`` mixin). -Verbatim move from ``game_sim.py`` (1.3.58); the stages still run in the +Verbatim move from ``game_sim.py`` (1.3.59); the stages still run in the ``SIM_ORDER`` of ``_update_sim``.""" import math diff --git a/src/core/version.py b/src/core/version.py index 0817bc99..88045015 100644 --- a/src/core/version.py +++ b/src/core/version.py @@ -4,7 +4,7 @@ This module is deliberately dependency-free because setuptools imports the version while building the project. """ -APP_VERSION = "1.3.58" +APP_VERSION = "1.3.59" SAVE_VERSION = 28 SAVE_SCHEMA = "u-jagd-save-v28" SPLASH_TEXT = ( diff --git a/tests/test_commander_assets.py b/tests/test_commander_assets.py index a4d6e492..1cc854d5 100644 --- a/tests/test_commander_assets.py +++ b/tests/test_commander_assets.py @@ -79,7 +79,7 @@ def test_commander_resources_are_self_contained_and_csp_safe(): assert tag not in {"iframe", "img", "object", "embed", "style"} for key in ("src", "href"): if key in attrs: - assert (attrs[key] in {"./js/main.js", "./voice.js"} + assert (attrs[key] in {"./js/main.js", "./js/browser-check.js", "./voice.js"} or key == "href" and re.fullmatch(r"\./css/[a-z]+\.css", attrs[key]) or key == "href" and attrs[key].startswith("#guide-") or key == "href" and attrs[key] == "/manual-en" diff --git a/tests/test_commander_pairing_browser.py b/tests/test_commander_pairing_browser.py new file mode 100644 index 00000000..df327465 --- /dev/null +++ b/tests/test_commander_pairing_browser.py @@ -0,0 +1,193 @@ +"""LAN pairing in a real browser, and the hint for browsers that are not Chromium. + +Pairs the packaged page in Chromium against the real Game and a crew-mode +CommanderServer (the F9 LAN listener). A Firefox user agent must see the +browser hint and still pair; a client whose modules fail to start must not +stay silently on its loading screen. +""" + +import json +import re +import shutil +import subprocess +import time + +import pytest +from commander_web import copy_assets, index_html, inject_probe + +from src.commander import server as commander_transport +from src.commander.assets import static_assets +from src.core import config, manual +from src.core.game import Game +from test_commander_assets import ASSETS, PREFIX, Document, catalogs + +FIREFOX = "Mozilla/5.0 (X11; Linux x86_64; rv:130.0) Gecko/20100101 Firefox/130.0" + +PAIR_SCRIPT = r""" +(() => { +"use strict"; +const $ = (id) => document.getElementById(id); +const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms)); +async function until(check, message, limit = 1500) { + for (let index = 0; index < limit; index++) { + if (check()) return; + await sleep(20); + } + throw new Error(message); +} +async function run() { + await until(() => !$("shell").hidden, "translations missing"); + const root = document.documentElement; + root.dataset.hintVisible = String(!$("browser-hint").hidden); + root.dataset.hintText = $("browser-hint").textContent; + $("name").value = "LAN"; + $("code").value = __CODE__; + $("pair-form").requestSubmit(); + await until(() => $("pairing").hidden && !$("lobby").hidden, "pairing did not reach the lobby: " + $("pair-error").textContent); + // A fresh session never held a station, so nothing was revoked. + root.dataset.lobbyStatus = $("lobby-status").textContent; + // A free station is leased at once and its console opens. + document.querySelector("#station-cards [data-station='bridge'] button").click(); + await until(() => document.body.dataset.remoteRole === "assigned" && !$("operations").hidden, + "bridge console did not open: " + $("lobby-status").textContent); + root.dataset.pairTest = "passed"; +} +addEventListener("load", () => { + run().catch((error) => { document.documentElement.dataset.failure = String(error?.stack || error); }); +}); +})(); +""" + + +def _chromium(): + chromium = (shutil.which("chromium") or shutil.which("chromium-browser") + or shutil.which("google-chrome")) + if not chromium: + pytest.skip("Optional pairing browser contract: no installed Chromium") + return chromium + + +def _pair(tmp_path, monkeypatch, *extra_args): + chromium = _chromium() + monkeypatch.setattr(config, "SAVE_DIR", str(tmp_path / "saves")) + en, de = catalogs() + game = Game(seed=917, start_menu=False, audio_enabled=False, language="en") + console = game.commander + console.solo = False + console.port = 0 + console._translations = { + "en": {key: value for key, value in en.items() if key.startswith(PREFIX)}, + "de": {key: value for key, value in de.items() if key.startswith(PREFIX)}, + } + console._contact_analysis_assets = {} + console._manual_pages = {lang: manual.html_page(lang) for lang in manual.LANGUAGES} + copy_assets(tmp_path, inject_probe(index_html(), "pair-test.js")) + monkeypatch.setattr(commander_transport.resources, "files", lambda _package: tmp_path) + + console.activate(game) + assert console.address is not None and console.server.solo_mode is False + console.server._http.assets["/pair-test.js"] = ( + "text/javascript; charset=utf-8", + PAIR_SCRIPT.replace("__CODE__", json.dumps(console.pairing_code)).encode("utf-8")) + process = subprocess.Popen( + [chromium, "--headless", "--no-sandbox", "--disable-gpu", + "--disable-background-networking", "--no-first-run", + "--no-default-browser-check", "--disable-dev-shm-usage", + f"--user-data-dir={tmp_path / 'pair-browser'}", "--virtual-time-budget=20000", + "--window-size=1600,900", *extra_args, "--dump-dom", + f"http://{console.address[0]}:{console.address[1]}/"], + stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True) + started = time.monotonic() + try: + while process.poll() is None and time.monotonic() - started < 120: + console.pump(game) + game.update(.02) + time.sleep(.02) + stdout, stderr = process.communicate(timeout=5) + finally: + if process.poll() is None: + process.kill() + stdout, stderr = process.communicate(timeout=5) + console.stop() + game.audio.shutdown() + root = next((attrs for tag, attrs in Document(stdout).elements if tag == "html"), {}) + assert root.get("data-pair-test") == "passed", root.get( + "data-failure", stdout[-4000:] + stderr[-2000:]) + return root, en + + +def test_lan_pairing_reaches_the_lobby_in_chromium_without_a_browser_hint( + tmp_path, monkeypatch): + root, _en = _pair(tmp_path, monkeypatch) + assert root.get("data-browser") == "chromium" + assert root.get("data-hint-visible") == "false" + assert root.get("data-lobby-status") == _en[PREFIX + "lobby_waiting"] + + +def test_firefox_sees_the_browser_hint_and_can_still_pair(tmp_path, monkeypatch): + root, en = _pair(tmp_path, monkeypatch, f"--user-agent={FIREFOX}") + assert root.get("data-browser") == "other" + assert root.get("data-hint-visible") == "true" + assert root.get("data-hint-text") == en[PREFIX + "browser_hint"] + + +def test_a_client_that_cannot_start_explains_itself(tmp_path, monkeypatch): + """Modules that fail to load leave the loading screen with a browser note.""" + chromium = _chromium() + en, de = catalogs() + translations = { + "en": {key: value for key, value in en.items() if key.startswith(PREFIX)}, + "de": {key: value for key, value in de.items() if key.startswith(PREFIX)}, + } + copy_assets(tmp_path) + (tmp_path / "js" / "main.js").write_text( + 'throw new Error("module client unsupported");\n', encoding="utf-8") + monkeypatch.setattr(commander_transport.resources, "files", lambda _package: tmp_path) + server = commander_transport.CommanderServer(translations=translations, + contact_analysis_assets={}) + server.start("127.0.0.1", 0) + try: + host, port = server.address + result = subprocess.run( + [chromium, "--headless", "--no-sandbox", "--disable-gpu", + "--disable-background-networking", "--no-first-run", + "--no-default-browser-check", "--disable-dev-shm-usage", + f"--user-data-dir={tmp_path / 'stall-browser'}", "--lang=de-DE", + "--virtual-time-budget=20000", "--dump-dom", f"http://{host}:{port}/"], + capture_output=True, text=True, timeout=90) + finally: + server.stop() + root = next((attrs for tag, attrs in Document(result.stdout).elements if tag == "html"), {}) + assert root.get("data-startup") == "stalled", result.stdout[-3000:] + result.stderr[-1500:] + note = re.search(r'

]*)>(.*?)

', result.stdout, re.S) + assert note is not None and "hidden" not in note.group(1) + # navigator.language decides the catalog; headless Chromium may ignore --lang. + assert note.group(2) in (en[PREFIX + "browser_stalled"], de[PREFIX + "browser_stalled"]) + + +def test_browser_check_ships_with_every_listener_and_runs_before_the_client(): + page = index_html() + check = '' + assert page.index(check) < page.index('