From 058432130628d00764663ecf819a9adc6793768d Mon Sep 17 00:00:00 2001 From: salmonik Date: Sun, 8 Nov 2026 03:29:35 +0100 Subject: v5.0.0: protocol v5 and the browser frontend Protocol v5 replaces newline lines with bounded [u32 len][text] frames and REQ/RES/EVT envelopes. Requests carry correlation ids and the server replays the last 256 replies per connection, so a gateway retry cannot double-debit and a late reply cannot clobber a newer request. HELLO/PONG carry server time; crash rounds announce started_at and push coalesced 10 Hz ticks. Crash now commits sha256(seed) before a round and reveals the seed when it ends, so clients recompute the crash point. Adds the webd/ gateway: one blocking thread, one ClientCore and one pinned upstream TLS connection per session, an HttpOnly session cookie, takeover, and a 60-second grace window. The browser sends Command JSON and renders View JSON; it never speaks the game protocol or stores credentials. Adds the vanilla TypeScript browser app at /play/ (login, lobby, all four games, history, notices, crash verification), the nginx /play and /ws routes, and the headless DOM smoke test. webd and the app stay out of the TUI/GUI/server build graph. The client/server version moves to 5.0.0 in lockstep; v4 peers are refused at HELLO. --- gui/Cargo.toml | 2 +- gui/src/app.rs | 19 +++++++++++-------- gui/src/net.rs | 17 ++++++++++------- 3 files changed, 22 insertions(+), 16 deletions(-) (limited to 'gui') diff --git a/gui/Cargo.toml b/gui/Cargo.toml index e216309..8dc09df 100644 --- a/gui/Cargo.toml +++ b/gui/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "zagan-bet-gui" -version = "4.4.0" +version = "5.0.0" edition = "2024" license = "GPL-3.0-or-later" description = "Desktop frontend for zagan-bet" diff --git a/gui/src/app.rs b/gui/src/app.rs index af64e5e..df8fec3 100644 --- a/gui/src/app.rs +++ b/gui/src/app.rs @@ -16,6 +16,7 @@ use zagan_bet::client::database; use zagan_bet::client::paths; use zagan_bet::client::view::{Command, LobbyView, View}; use zagan_bet::history::PlayRecord; +use zagan_bet::protocol::Packet; use zagan_bet::version::{VERSION, is_newer}; use crate::net::{Command as NetCommand, Connected, Event, Failure, Network}; @@ -280,8 +281,8 @@ impl ZaganApp { } } } - Effect::SendLine(line) => { - self.net.send(NetCommand::Send(line)); + Effect::SendRequest { id, payload } => { + self.net.send(NetCommand::Send { id, payload }); self.awaiting = Some(Instant::now()); } Effect::Disconnect => { @@ -355,17 +356,18 @@ impl ZaganApp { failure, message, } => self.failed(addr, failure, message), - Event::Line(line) => { - if self.core.is_async(&line) { - if let Some(effects) = self.core.handle_async_line(&line) { + Event::Packet(packet) => match packet { + Packet::Event { body, .. } => { + if let Some(effects) = self.core.handle_async_line(&body) { self.apply(ctx, effects); } - } else { + } + Packet::Reply { id, body } => { self.awaiting = None; - let effects = self.core.handle_reply(&line); + let effects = self.core.handle_reply_id(id, &body); self.apply(ctx, effects); } - } + }, Event::Closed => { self.session = None; self.awaiting = None; @@ -384,6 +386,7 @@ impl ZaganApp { self.core .set_host_info(Some(connected.addr.clone()), connected.fingerprint.clone()); self.core.set_logged_in(connected.user.clone()); + self.core.set_server_time(connected.server_time); self.login.error = connected.auth_error.clone(); self.login.user = connected.user.clone().unwrap_or_default(); diff --git a/gui/src/net.rs b/gui/src/net.rs index 7cba604..7882cd3 100644 --- a/gui/src/net.rs +++ b/gui/src/net.rs @@ -14,6 +14,7 @@ use eframe::egui; use rusqlite::Connection; use zagan_bet::client::transport::{self, TlsStream, TransportError, TrustPrompt}; use zagan_bet::client::{database, paths}; +use zagan_bet::protocol::Packet; /// How often the worker checks the socket for pushes when idle. const POLL: Duration = Duration::from_millis(8); @@ -24,7 +25,7 @@ const TRUST_TIMEOUT: Duration = Duration::from_secs(120); #[derive(Debug, Clone, PartialEq, Eq)] pub enum Command { Connect { addr: String }, - Send(String), + Send { id: u64, payload: String }, Disconnect, Stop, } @@ -49,6 +50,7 @@ pub struct Connected { pub latest: String, pub url: String, pub elapsed_ms: f32, + pub server_time: u64, } /// What the worker tells the UI. @@ -65,7 +67,7 @@ pub enum Event { failure: Failure, message: String, }, - Line(String), + Packet(Packet), Closed, } @@ -164,6 +166,7 @@ fn worker( latest: connected.latest, url: connected.url, elapsed_ms: connected.elapsed.as_secs_f64() as f32 * 1000.0, + server_time: connected.server_time, })); stream = Some(connected.stream); } @@ -177,9 +180,9 @@ fn worker( } ctx.request_repaint(); } - Ok(Command::Send(line)) => { + Ok(Command::Send { id, payload }) => { if let Some(open) = &mut stream { - if open.write_line(&line).is_err() { + if open.write_request(id, None, &payload).is_err() { stream = None; let _ = events.send(Event::Closed); } @@ -198,9 +201,9 @@ fn worker( // Drain pushes and replies without blocking the command channel. if let Some(open) = &mut stream { loop { - match open.read_available_line() { - Ok(Some(line)) => { - if events.send(Event::Line(line)).is_err() { + match open.read_available_packet() { + Ok(Some(packet)) => { + if events.send(Event::Packet(packet)).is_err() { return; } } -- cgit v1.2.3