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. --- src/client/view.rs | 60 ++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 45 insertions(+), 15 deletions(-) (limited to 'src/client/view.rs') diff --git a/src/client/view.rs b/src/client/view.rs index 4615720..0886d64 100644 --- a/src/client/view.rs +++ b/src/client/view.rs @@ -7,15 +7,17 @@ use crate::blackjack::BlackjackState; use crate::client::games::roulette::{Cursor, Direction}; use crate::client::games::traits::{GamePhase, GameState}; use crate::roulette::{BetTarget, Bets}; +use serde::{Deserialize, Serialize}; -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)] +#[serde(rename_all = "snake_case")] pub enum RoulettePhase { Placing, Spinning, Result, } -#[derive(Debug, Clone, PartialEq, Eq)] +#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] pub struct RouletteView { pub bet_amount: u64, pub balance: Option, @@ -51,7 +53,10 @@ impl RouletteView { Some("result") => RoulettePhase::Result, _ => RoulettePhase::Placing, }; - let number = state.data.get("number").and_then(|value| value.parse().ok()); + let number = state + .data + .get("number") + .and_then(|value| value.parse().ok()); let color = state.data.get("color").cloned(); let winnings = state .data @@ -82,14 +87,15 @@ impl RouletteView { } } -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)] +#[serde(rename_all = "snake_case")] pub enum SlotsPhase { Ready, Spinning, Result, } -#[derive(Debug, Clone, PartialEq, Eq)] +#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] pub struct SlotsView { pub bet: u64, pub balance: Option, @@ -149,7 +155,7 @@ impl SlotsView { } } -#[derive(Debug, Clone, PartialEq, Eq)] +#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] pub struct BlackjackView { pub status: String, pub balance: Option, @@ -186,7 +192,7 @@ impl BlackjackView { } } -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] pub struct CrashView { pub status: String, pub balance: Option, @@ -195,6 +201,11 @@ pub struct CrashView { pub potential: u64, pub crash_point: Option, pub payout: u64, + pub started_at: u64, + /// `sha256(seed)` for this round, before it ends. + pub commit: Option, + /// The revealed seed, after the round ends. + pub seed: Option, pub error: Option, } @@ -232,6 +243,13 @@ impl CrashView { .get("payout") .and_then(|value| value.parse::().ok()) .unwrap_or(0), + started_at: state + .data + .get("started_at") + .and_then(|value| value.parse::().ok()) + .unwrap_or(0), + commit: state.data.get("commit").cloned(), + seed: state.data.get("seed").cloned(), error: state .data .get("error") @@ -242,7 +260,7 @@ impl CrashView { } /// The lobby: who is logged in, the balance, and what can be played. -#[derive(Debug, Clone, PartialEq, Eq)] +#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] pub struct LobbyView { pub connected: bool, pub user: Option, @@ -254,13 +272,14 @@ pub struct LobbyView { } /// The play log, already parsed. -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] pub struct HistoryView { pub records: Vec, } /// Everything a frontend can draw. -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +#[serde(tag = "screen", rename_all = "snake_case")] pub enum View { Lobby(LobbyView), History(HistoryView), @@ -271,17 +290,28 @@ pub enum View { } /// Semantic input. Frontends turn keys and clicks into these. -#[derive(Debug, Clone, PartialEq, Eq)] +#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] pub enum Command { /// The credential is already hashed by the frontend. - Login { user: String, credential: String }, + Login { + user: String, + credential: String, + }, Games, Ping, Echo(String), Info, - Register { user: String, credential: String }, - Play { game: String, bet: Option }, - History { limit: u32 }, + Register { + user: String, + credential: String, + }, + Play { + game: String, + bet: Option, + }, + History { + limit: u32, + }, ShowLobby, Logout, SetBet(u64), -- cgit v1.2.3