zero_trust_rps/common/client/
state.rs1use std::collections::HashMap;
2use tokio::time::Instant;
3use uuid::Uuid;
4
5use crate::common::{
6 blake3::B3Key,
7 immutable::Immutable,
8 message::{HashWithData, RoomState, RpsData, UserState},
9 rps::state::RpsState,
10 utils::get_random_bytes,
11};
12
13pub type ClientStateView = Box<Immutable<ClientState>>;
14
15#[derive(Debug, Clone)]
16pub struct ClientState {
17 pub user: Uuid,
18 pub state: RpsState,
19
20 pub secret: B3Key,
21 pub room: Option<RoomState>,
22 pub cache: HashMap<Uuid, UserState>, pub timed_out: bool,
25
26 pub current_plays: Option<Box<[(Uuid, HashWithData)]>>,
27 pub last_server_message: Instant,
28
29 pub last_play: Option<RpsData>,
30 pub last_error: Option<String>,
31}
32
33impl Default for ClientState {
34 fn default() -> Self {
35 ClientState {
36 state: RpsState::BeforeRoom,
37 secret: get_random_bytes(),
38 room: None,
39 cache: HashMap::new(),
40 current_plays: None,
41 user: Uuid::from_bytes(get_random_bytes()),
42 last_server_message: Instant::now(),
43 last_play: None,
44 timed_out: false,
45 last_error: None,
46 }
47 }
48}