diff options
| author | salmonik <salmonik@tuta.io> | 2026-11-08 03:29:35 +0100 |
|---|---|---|
| committer | salmonik <salmonik@tuta.io> | 2026-11-08 03:29:35 +0100 |
| commit | 058432130628d00764663ecf819a9adc6793768d (patch) | |
| tree | d3f49f111fbfaa48647cca2600adcf9017af2d30 /src/client/games | |
| parent | web: serve latest.php through PHP and refuse stray PHP files (diff) | |
| download | zagan-bet-058432130628d00764663ecf819a9adc6793768d.tar.gz zagan-bet-058432130628d00764663ecf819a9adc6793768d.zip | |
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.
Diffstat (limited to '')
| -rw-r--r-- | src/client/games/manager.rs | 21 | ||||
| -rw-r--r-- | src/client/games/roulette.rs | 9 |
2 files changed, 21 insertions, 9 deletions
diff --git a/src/client/games/manager.rs b/src/client/games/manager.rs index 24ceeaa..d35308b 100644 --- a/src/client/games/manager.rs +++ b/src/client/games/manager.rs | |||
| @@ -5,7 +5,7 @@ use super::roulette::RouletteGame; | |||
| 5 | use super::slots::SlotsGame; | 5 | use super::slots::SlotsGame; |
| 6 | use super::traits::{Game, GameError, GamePhase, GameState}; | 6 | use super::traits::{Game, GameError, GamePhase, GameState}; |
| 7 | use crate::blackjack::BlackjackState; | 7 | use crate::blackjack::BlackjackState; |
| 8 | use crate::crash::{payout, CrashState}; | 8 | use crate::crash::{CrashState, payout}; |
| 9 | use crate::roulette::Bets; | 9 | use crate::roulette::Bets; |
| 10 | use std::collections::HashMap; | 10 | use std::collections::HashMap; |
| 11 | 11 | ||
| @@ -244,9 +244,7 @@ impl GameManager { | |||
| 244 | 244 | ||
| 245 | pub fn set_roulette_cursor(&mut self, cursor: &crate::client::games::roulette::Cursor) { | 245 | pub fn set_roulette_cursor(&mut self, cursor: &crate::client::games::roulette::Cursor) { |
| 246 | if let Some(session) = self.current_session.as_mut() { | 246 | if let Some(session) = self.current_session.as_mut() { |
| 247 | session | 247 | session.data.insert("cursor".to_string(), cursor.encoded()); |
| 248 | .data | ||
| 249 | .insert("cursor".to_string(), cursor.encoded()); | ||
| 250 | } | 248 | } |
| 251 | } | 249 | } |
| 252 | 250 | ||
| @@ -339,7 +337,7 @@ impl GameManager { | |||
| 339 | }; | 337 | }; |
| 340 | session.bet_amount = state.bet; | 338 | session.bet_amount = state.bet; |
| 341 | session.data.remove("error"); | 339 | session.data.remove("error"); |
| 342 | for key in ["crash_point", "payout"] { | 340 | for key in ["crash_point", "payout", "commit", "seed"] { |
| 343 | session.data.remove(key); | 341 | session.data.remove(key); |
| 344 | } | 342 | } |
| 345 | session | 343 | session |
| @@ -360,10 +358,21 @@ impl GameManager { | |||
| 360 | session | 358 | session |
| 361 | .data | 359 | .data |
| 362 | .insert("payout".to_string(), state.payout.to_string()); | 360 | .insert("payout".to_string(), state.payout.to_string()); |
| 361 | session | ||
| 362 | .data | ||
| 363 | .insert("started_at".to_string(), state.started_at.to_string()); | ||
| 364 | if let Some(commit) = &state.commit { | ||
| 365 | session.data.insert("commit".to_string(), commit.clone()); | ||
| 366 | } | ||
| 367 | if let Some(seed) = &state.seed { | ||
| 368 | session.data.insert("seed".to_string(), seed.clone()); | ||
| 369 | } | ||
| 363 | if let Some(crash_point) = state.crash_point { | 370 | if let Some(crash_point) = state.crash_point { |
| 371 | // Keep full precision: the browser recomputes this from the | ||
| 372 | // revealed seed, and the GUI charts it. | ||
| 364 | session | 373 | session |
| 365 | .data | 374 | .data |
| 366 | .insert("crash_point".to_string(), format!("{crash_point:.2}")); | 375 | .insert("crash_point".to_string(), crash_point.to_string()); |
| 367 | } | 376 | } |
| 368 | } | 377 | } |
| 369 | 378 | ||
diff --git a/src/client/games/roulette.rs b/src/client/games/roulette.rs index f0ed816..15cc6ed 100644 --- a/src/client/games/roulette.rs +++ b/src/client/games/roulette.rs | |||
| @@ -1,6 +1,7 @@ | |||
| 1 | use super::traits::{Game, GameState}; | 1 | use super::traits::{Game, GameState}; |
| 2 | use crate::client::view::{RoulettePhase, RouletteView}; | 2 | use crate::client::view::{RoulettePhase, RouletteView}; |
| 3 | use crate::roulette::{BetTarget, Bets, Outside, is_even, is_odd}; | 3 | use crate::roulette::{BetTarget, Bets, Outside, is_even, is_odd}; |
| 4 | use serde::{Deserialize, Serialize}; | ||
| 4 | 5 | ||
| 5 | pub const ROULETTE_BOARD_LINES: usize = 12; | 6 | pub const ROULETTE_BOARD_LINES: usize = 12; |
| 6 | 7 | ||
| @@ -21,7 +22,7 @@ const OUTSIDE_ORDER: [Outside; 6] = [ | |||
| 21 | 22 | ||
| 22 | pub struct RouletteGame; | 23 | pub struct RouletteGame; |
| 23 | 24 | ||
| 24 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] | 25 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)] |
| 25 | pub enum Direction { | 26 | pub enum Direction { |
| 26 | Up, | 27 | Up, |
| 27 | Down, | 28 | Down, |
| @@ -41,7 +42,7 @@ pub enum Direction { | |||
| 41 | /// odd,even line between rows split of the two numbers | 42 | /// odd,even line between rows split of the two numbers |
| 42 | /// even,even corner of four cells corner | 43 | /// even,even corner of four cells corner |
| 43 | /// ``` | 44 | /// ``` |
| 44 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] | 45 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)] |
| 45 | pub enum Cursor { | 46 | pub enum Cursor { |
| 46 | Zero, | 47 | Zero, |
| 47 | Lattice { x: usize, y: usize }, | 48 | Lattice { x: usize, y: usize }, |
| @@ -67,7 +68,9 @@ impl Cursor { | |||
| 67 | match parts.as_slice() { | 68 | match parts.as_slice() { |
| 68 | ["zero"] => Cursor::Zero, | 69 | ["zero"] => Cursor::Zero, |
| 69 | ["lattice", x, y] => match (x.parse::<usize>(), y.parse::<usize>()) { | 70 | ["lattice", x, y] => match (x.parse::<usize>(), y.parse::<usize>()) { |
| 70 | (Ok(x), Ok(y)) if (1..=FELT_X_MAX).contains(&x) && (1..=FELT_Y_MAX).contains(&y) => { | 71 | (Ok(x), Ok(y)) |
| 72 | if (1..=FELT_X_MAX).contains(&x) && (1..=FELT_Y_MAX).contains(&y) => | ||
| 73 | { | ||
| 71 | Cursor::Lattice { x, y } | 74 | Cursor::Lattice { x, y } |
| 72 | } | 75 | } |
| 73 | _ => Cursor::default(), | 76 | _ => Cursor::default(), |
