Browse Source

add get_room/get_lobby to ClientLocation

pbs
jake 5 years ago
parent
commit
dcef56dcac
  1. 20
      src/ship/location.rs

20
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<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…
Cancel
Save