Add new messages

This commit is contained in:
2023-02-21 11:42:14 +01:00
parent 7c8330465f
commit 7357062f92
5 changed files with 62 additions and 2 deletions

View File

@@ -1,19 +1,40 @@
use crate::types::{Position2dRef, TileRef};
use board_shared::{position::Position2d, tile::Tile};
use serde::{Deserialize, Serialize};
#[derive(Debug, Deserialize, Eq, PartialEq, Serialize)]
pub enum ClientMessage {
/// Creates a new room and join it with the given player name.
///
/// The server answers with a JoinedRoom message.
CreateRoom(String),
JoinRoom(String, String),
Disconnected,
TileUse(#[serde(with = "Position2dRef")] Position2d, usize),
TileTake(usize),
}
#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub enum ServerMessage {
/// Informs that a room has been joined.
JoinedRoom {
room_name: String,
players: Vec<(String, u32, bool)>,
active_player: usize,
},
/// Notify that new player has joined the game.
PlayerConnected(String),
/// Notify that new player has rejoined the game.
PlayerReconnected(usize),
/// Notify that new player has temporary left the game.
PlayerDisconnected(usize),
}
/// Change the current player
PlayerTurn(usize),
/// Informs that a tile has been placed
TilePlaced(
#[serde(with = "Position2dRef")] Position2d,
#[serde(with = "TileRef")] Tile,
),
/// Informs that a tile has been removed
TileRemoved(#[serde(with = "Position2dRef")] Position2d),
}