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