zero_trust_rps/common/client/
state.rsuse std::collections::HashMap;
use tokio::time::Instant;
use uuid::Uuid;
use crate::common::{
blake3::B3Key,
immutable::Immutable,
message::{HashWithData, RoomState, RpsData, UserState},
rps::state::RpsState,
utils::get_random_bytes,
};
pub type ClientStateView = Box<Immutable<ClientState>>;
#[derive(Debug, Clone)]
pub struct ClientState {
pub user: Uuid,
pub state: RpsState,
pub secret: B3Key,
pub room: Option<RoomState>,
pub cache: HashMap<Uuid, UserState>, pub timed_out: bool,
pub current_plays: Option<Box<[(Uuid, HashWithData)]>>,
pub last_server_message: Instant,
pub last_play: Option<RpsData>,
pub last_error: Option<String>,
}
impl Default for ClientState {
fn default() -> Self {
ClientState {
state: RpsState::BeforeRoom,
secret: get_random_bytes(),
room: None,
cache: HashMap::new(),
current_plays: None,
user: Uuid::from_bytes(get_random_bytes()),
last_server_message: Instant::now(),
last_play: None,
timed_out: false,
last_error: None,
}
}
}