|
|
@ -1,8 +1,8 @@ |
|
|
|
use std::collections::HashMap;
|
|
|
|
use std::sync::{Arc, RwLock};
|
|
|
|
use std::convert::Into;
|
|
|
|
|
|
|
|
use std::time::SystemTime;
|
|
|
|
use thiserror::Error;
|
|
|
|
use crate::common::serverstate::ClientId;
|
|
|
|
|
|
|
|
pub const MAX_ROOMS: usize = 128;
|
|
|
@ -25,27 +25,79 @@ impl LobbyId { |
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[derive(Debug, PartialEq)]
|
|
|
|
#[derive(Error, Debug, PartialEq)]
|
|
|
|
#[error("")]
|
|
|
|
pub enum CreateRoomError {
|
|
|
|
NoOpenSlots,
|
|
|
|
ClientInAreaAlready,
|
|
|
|
JoinError,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, PartialEq)]
|
|
|
|
#[derive(Error, Debug, PartialEq)]
|
|
|
|
#[error("")]
|
|
|
|
pub enum JoinRoomError {
|
|
|
|
RoomDoesNotExist,
|
|
|
|
RoomFull,
|
|
|
|
ClientInAreaAlready,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, PartialEq)]
|
|
|
|
#[derive(Error, Debug, PartialEq)]
|
|
|
|
#[error("")]
|
|
|
|
pub enum JoinLobbyError {
|
|
|
|
LobbyDoesNotExist,
|
|
|
|
LobbyFull,
|
|
|
|
ClientInAreaAlready,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Error, Debug, PartialEq)]
|
|
|
|
#[error("")]
|
|
|
|
pub enum GetAreaError {
|
|
|
|
InvalidClient,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Error, Debug, PartialEq)]
|
|
|
|
#[error("")]
|
|
|
|
pub enum ClientRemovalError {
|
|
|
|
ClientNotInArea,
|
|
|
|
InvalidArea,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Error, Debug, PartialEq)]
|
|
|
|
#[error("")]
|
|
|
|
pub enum GetClientsError {
|
|
|
|
InvalidClient,
|
|
|
|
InvalidArea,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Error, Debug, PartialEq)]
|
|
|
|
#[error("")]
|
|
|
|
pub enum GetNeighborError {
|
|
|
|
InvalidClient,
|
|
|
|
InvalidArea,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Error, Debug, PartialEq)]
|
|
|
|
#[error("")]
|
|
|
|
pub enum GetLeaderError {
|
|
|
|
InvalidClient,
|
|
|
|
InvalidArea,
|
|
|
|
NoClientInArea,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Error, Debug, PartialEq)]
|
|
|
|
#[error("")]
|
|
|
|
pub enum ClientLocationError {
|
|
|
|
CreateRoomError(#[from] CreateRoomError),
|
|
|
|
JoinRoomError(#[from] JoinRoomError),
|
|
|
|
JoinLobbyError(#[from] JoinLobbyError),
|
|
|
|
GetAreaError(#[from] GetAreaError),
|
|
|
|
ClientRemovalError(#[from] ClientRemovalError),
|
|
|
|
GetClientsError(#[from] GetClientsError),
|
|
|
|
GetNeighborError(#[from] GetNeighborError),
|
|
|
|
GetLeaderError(#[from] GetLeaderError)
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[derive(Debug, Copy, Clone, PartialEq)]
|
|
|
|
pub struct LocalClientId(usize);
|
|
|
|
|
|
|
@ -73,36 +125,6 @@ pub enum RoomLobby { |
|
|
|
Lobby(LobbyId),
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, PartialEq)]
|
|
|
|
pub enum GetAreaError {
|
|
|
|
InvalidClient,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, PartialEq)]
|
|
|
|
pub enum ClientRemovalError {
|
|
|
|
ClientNotInArea,
|
|
|
|
InvalidArea,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, PartialEq)]
|
|
|
|
pub enum GetClientsError {
|
|
|
|
InvalidClient,
|
|
|
|
InvalidArea,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, PartialEq)]
|
|
|
|
pub enum GetNeighborError {
|
|
|
|
InvalidClient,
|
|
|
|
InvalidArea,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, PartialEq)]
|
|
|
|
pub enum GetLeaderError {
|
|
|
|
InvalidClient,
|
|
|
|
InvalidArea,
|
|
|
|
NoClientInArea,
|
|
|
|
}
|
|
|
|
|
|
|
|
pub struct ClientLocation {
|
|
|
|
lobbies: [Lobby; 15],
|
|
|
|
rooms: [Option<Room>; MAX_ROOMS],
|
|
|
|