add get_room/get_lobby to ClientLocation
This commit is contained in:
parent
c7c9cd0bec
commit
dcef56dcac
@ -52,6 +52,8 @@ pub enum JoinLobbyError {
|
||||
#[derive(Error, Debug, PartialEq)]
|
||||
#[error("")]
|
||||
pub enum GetAreaError {
|
||||
NotInRoom,
|
||||
NotInLobby,
|
||||
InvalidClient,
|
||||
}
|
||||
|
||||
@ -331,6 +333,24 @@ impl ClientLocation {
|
||||
.map(Clone::clone)
|
||||
}
|
||||
|
||||
pub fn get_room(&self, id: ClientId) -> Result<RoomId, GetAreaError> {
|
||||
if let RoomLobby::Room(room) = self.client_location.get(&id).ok_or(GetAreaError::InvalidClient)? {
|
||||
Ok(*room)
|
||||
}
|
||||
else {
|
||||
Err(GetAreaError::NotInRoom)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_lobby(&self, id: ClientId) -> Result<LobbyId, GetAreaError> {
|
||||
if let RoomLobby::Lobby(lobby) = self.client_location.get(&id).ok_or(GetAreaError::InvalidClient)? {
|
||||
Ok(*lobby)
|
||||
}
|
||||
else {
|
||||
Err(GetAreaError::NotInLobby)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn remove_client_from_area(&mut self, id: ClientId) -> Result<(), ClientRemovalError> {
|
||||
let area = self.client_location.get_mut(&id).ok_or(ClientRemovalError::ClientNotInArea)?;
|
||||
let client_list = match area {
|
||||
|
Loading…
x
Reference in New Issue
Block a user