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
use bincode::{Decode, Encode};
use de_types::player::Player;

/// Message to be sent from a player/client to a main server (outside of a
/// game).
#[derive(Debug, Encode, Decode)]
pub enum ToServer {
    /// Prompts the server to respond [`FromServer::Pong`] with the same ping ID.
    Ping(u32),
    /// This message opens a new game on the server. The server responds with
    /// [`FromServer::GameOpened`].
    OpenGame { max_players: Player },
}

/// Message to be sent from a main server to a player/client (outside of a
/// game).
#[derive(Debug, Encode, Decode)]
pub enum FromServer {
    /// Response to [`ToServer::Ping`].
    Pong(u32),
    /// A new game was opened upon request from the client.
    GameOpened {
        /// Port at which players may connect to join the game.
        port: u16,
    },
    GameOpenError(GameOpenError),
}

#[derive(Debug, Encode, Decode)]
pub enum GameOpenError {
    /// The player opening the game has already joined a different game.
    DifferentGame,
}