From dcef56dcace2142ddef7b183331f726cc2613beb Mon Sep 17 00:00:00 2001 From: jake Date: Sun, 26 Apr 2020 20:39:23 -0600 Subject: [PATCH] add get_room/get_lobby to ClientLocation --- src/ship/location.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) 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 {