diff options
Diffstat (limited to 'src/wire/mod.rs')
-rw-r--r-- | src/wire/mod.rs | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/src/wire/mod.rs b/src/wire/mod.rs new file mode 100644 index 000000000000..257333ee118c --- /dev/null +++ b/src/wire/mod.rs @@ -0,0 +1,75 @@ +//! Network formats and container messages + +mod action; +mod req; +mod resp; +mod update; + +use crate::{ + data::{Color, Player}, + map::Map, +}; +use serde::{Deserialize, Serialize}; + +/// An alias for a User's ID +pub type UserId = usize; + +/// Represents a user payload +#[derive(Serialize, Deserialize)] +pub struct User { + /// The internal user ID + id: UserId, + /// The auth token provided by the client + token: String, + /// Whether the scores will be tracked + registered: bool, +} + +/// A more lobby specific abstraction for a user +#[derive(Serialize, Deserialize)] +struct LobbyUser { + /// The user ID + id: UserId, + /// Their nick name + name: String, + /// Are they ready? + ready: bool, + /// The colour they will be in the match + color: Color, +} + +/// An alias for a Room ID +pub type LobbyId = usize; + +/// Represent a lobby +#[derive(Serialize, Deserialize)] +pub struct Lobby { + /// The ID of the lobby + id: LobbyId, + /// A set of user IDs + players: Vec<LobbyUser>, + /// The name of the map + map: String, + /// Settings + settings: Vec<String>, +} + +/// An alias for a match ID +pub type MatchId = usize; + +/// Mapping users to a player in game +#[derive(Serialize, Deserialize)] +pub struct MatchUser { + user: User, + player: Player, +} + +#[derive(Serialize, Deserialize)] +pub struct Match { + /// The match id + id: MatchId, + /// The list of active players + players: Vec<MatchUser>, + /// The active game map + map: Map, +} |