pub type PlayerId = u64;
pub type RoomId = u32;
#[repr(u8)]
pub enum PlayerStatus {
Offline = 0,
Online = 1,
InGame = 2,
Away = 3,
}
pub enum GameEvent {
PlayerJoined {
player_id: PlayerId,
name: String,
position: Position,
},
PlayerLeft { player_id: PlayerId, reason: String },
PlayerMoved(PlayerId, Position),
ChatMessage {
from: PlayerId,
message: String,
timestamp: u64,
},
StateUpdate(GameState),
Ping,
Pong,
}
pub struct Position {
pub x: f32,
pub y: f32,
}
pub struct Velocity {
pub dx: f32,
pub dy: f32,
}
pub struct Player {
pub id: PlayerId,
pub name: String,
pub position: Position,
pub velocity: Velocity,
pub health: u8,
pub score: u32,
pub status: PlayerStatus,
pub avatar_url: Option<String>,
}
pub struct RoomConfig {
pub id: RoomId,
pub name: String,
pub max_players: u8,
pub is_public: bool,
pub game_mode: String,
pub settings: Option<String>,
}
pub struct GameState {
pub tick: u64,
pub timestamp: u64,
pub players: Vec<Player>,
pub room: RoomConfig,
pub paused: bool,
}
pub enum ClientMessage {
JoinRoom {
room_id: RoomId,
password: Option<String>,
},
LeaveRoom,
Move { direction: Velocity },
Chat { message: String },
RequestSync,
Ping { client_time: u64 },
}
pub enum ServerMessage {
Welcome {
server_version: String,
player_id: PlayerId,
},
RoomJoined { room: RoomConfig },
JoinError { reason: String },
Event { event: GameEvent },
Sync { state: GameState },
DeltaSync {
tick: u64,
updates: Vec<PlayerUpdate>,
},
Pong { client_time: u64, server_time: u64 },
Error { code: u16, message: String },
}
pub struct PlayerUpdate {
pub id: PlayerId,
pub position: Option<Position>,
pub velocity: Option<Velocity>,
pub health: Option<u8>,
pub score: Option<u32>,
}
pub struct Paginated<T> {
pub items: Vec<T>,
pub total: u32,
pub page: u32,
pub per_page: u32,
}
pub struct ApiResult<T> {
pub success: bool,
pub data: Option<T>,
pub error: Option<String>,
pub request_id: String,
}