team04_server/messages/
connect_game.rs1use client_role::ClientRole;
2
3use crate::server::state::LobbyId;
4
5use super::*;
6
7#[derive(Deserialize, Debug)]
8#[serde(rename_all = "camelCase")]
9pub struct ConnectGame {
10 pub name: String,
11 pub role: ClientRole,
12 #[serde(rename = "lobbyID")]
13 pub lobby_id: LobbyId,
14}
15
16impl ConnectGame {
17 pub fn validate(&self) -> Result<(), ConnectGameError> {
18 if self.name.chars().count() > 20 {
19 return Err(ConnectGameError::InvalidNameLength);
20 }
21 Ok(())
22 }
23}
24
25#[derive(Debug)]
26pub enum ConnectGameError {
27 InvalidNameLength,
28}
29
30impl Error for ConnectGameError {}
31
32impl Display for ConnectGameError {
33 fn fmt(&self, fmt: &mut Formatter<'_>) -> FmtResult {
34 match self {
35 Self::InvalidNameLength => write!(fmt, "Name is longer than 20 characters"),
36 }
37 }
38}