1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
//! Network formats and container messages
mod action;
pub use action::*;
mod req;
pub use req::*;
mod resp;
pub use resp::*;
mod update;
pub use 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)]
pub 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
pub id: LobbyId,
/// A set of user IDs
pub players: Vec<LobbyUser>,
/// The name of the map
pub map: String,
/// Settings
pub 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 {
pub user: User,
pub player: Player,
}
#[derive(Serialize, Deserialize)]
pub struct Match {
/// The match id
pub id: MatchId,
/// The list of active players
pub players: Vec<MatchUser>,
/// The active game map
pub map: Map,
}
|