diff --git a/src/ship/location.rs b/src/ship/location.rs index e3b1c78..bc15201 100644 --- a/src/ship/location.rs +++ b/src/ship/location.rs @@ -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 { + 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 { + 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 {