|
@ -146,6 +146,12 @@ impl Default for ClientLocation { |
|
|
|
|
|
|
|
|
impl ClientLocation {
|
|
|
impl ClientLocation {
|
|
|
pub fn add_client_to_lobby(&mut self, id: ClientId, lobby: LobbyId) -> Result<(), JoinLobbyError> {
|
|
|
pub fn add_client_to_lobby(&mut self, id: ClientId, lobby: LobbyId) -> Result<(), JoinLobbyError> {
|
|
|
|
|
|
let l = self.lobbies.get_mut(lobby.0).ok_or(JoinLobbyError::LobbyDoesNotExist)?;
|
|
|
|
|
|
if l.0.iter().filter(|c| c.is_none()).count() == 0 {
|
|
|
|
|
|
return Err(JoinLobbyError::LobbyFull);
|
|
|
|
|
|
}
|
|
|
|
|
|
self.remove_client_from_area(id);
|
|
|
|
|
|
|
|
|
let l = self.lobbies.get_mut(lobby.0).ok_or(JoinLobbyError::LobbyDoesNotExist)?;
|
|
|
let l = self.lobbies.get_mut(lobby.0).ok_or(JoinLobbyError::LobbyDoesNotExist)?;
|
|
|
let (index, empty_slot) = l.0.iter_mut()
|
|
|
let (index, empty_slot) = l.0.iter_mut()
|
|
|
.enumerate()
|
|
|
.enumerate()
|
|
@ -157,7 +163,6 @@ impl ClientLocation { |
|
|
local_client: LocalClientId(index),
|
|
|
local_client: LocalClientId(index),
|
|
|
time_join: SystemTime::now(),
|
|
|
time_join: SystemTime::now(),
|
|
|
});
|
|
|
});
|
|
|
self.remove_client_from_area(id);
|
|
|
|
|
|
self.client_location.insert(id, RoomLobby::Lobby(lobby));
|
|
|
self.client_location.insert(id, RoomLobby::Lobby(lobby));
|
|
|
Ok(())
|
|
|
Ok(())
|
|
|
}
|
|
|
}
|
|
|