use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(tag = "type")]
pub enum ClientMsg {
SetName { name: String },
ListRooms,
CreateRoom { name: String },
JoinRoom { room_id: u32 },
LeaveRoom,
CreateTable, JoinTable { table_id: u32 }, LeaveTable,
MakeMove { uci: String },
Resign,
Rematch,
SetMainBoardMode { mode: BoardMode },
MainBoardMove { uci: String },
SendChat { body: String },
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(tag = "type")]
pub enum ServerMsg {
Welcome { your_id: u32 },
Error { msg: String },
RoomList { rooms: Vec<RoomInfo> },
RoomJoined { room: RoomInfo, players: Vec<PlayerInfo>, tables: Vec<TableInfo> },
PlayerJoined { player: PlayerInfo },
PlayerLeft { player_id: u32 },
TableCreated { table: TableInfo },
TableUpdated { table: TableInfo },
TableRemoved { table_id: u32 },
TableJoined { table: TableInfo, fen: String },
GameStarted { table_id: u32, white: u32, black: u32, fen: String },
MoveMade { table_id: u32, uci: String, fen: String },
GameOver { table_id: u32, reason: String, winner: Option<u32> },
MainBoardUpdate { mode: BoardMode, fen: String },
ChatMessage { sender: String, body: String, kind: ChatKind },
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RoomInfo {
pub id: u32,
pub name: String,
pub player_count: u32,
pub table_count: u32,
pub active_games: u32,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PlayerInfo {
pub id: u32,
pub name: String,
pub status: PlayerStatus,
pub table_id: Option<u32>,
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub enum PlayerStatus {
Idle,
Playing,
Spectating,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct TableInfo {
pub id: u32,
pub white: Option<PlayerRef>,
pub black: Option<PlayerRef>,
pub spectator_count: u32,
pub has_game: bool,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PlayerRef {
pub id: u32,
pub name: String,
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub enum BoardMode {
Tutorial,
Game,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum ChatKind {
Player,
System,
Spectator,
}
pub const DEFAULT_PORT: u16 = 7878;
pub const CENTRAL_SERVER_PORT: u16 = 7880;