diff --git a/src/ship/ship.rs b/src/ship/ship.rs index 610b1be..d431c96 100644 --- a/src/ship/ship.rs +++ b/src/ship/ship.rs @@ -22,7 +22,7 @@ use crate::entity::gateway::{EntityGateway, GatewayError}; use crate::entity::account::{UserAccountEntity, UserSettingsEntity}; use crate::entity::character::{CharacterEntity, SectionID}; -use crate::ship::location::{ClientLocation, RoomLobby, MAX_ROOMS, ClientLocationError}; +use crate::ship::location::{ClientLocation, RoomLobby, MAX_ROOMS, ClientLocationError, GetNeighborError, GetClientsError, GetAreaError}; use crate::ship::items; use crate::ship::room; @@ -45,6 +45,9 @@ pub enum ShipError { InvalidSlot(ClientId, u32), TooManyClients, ClientLocationError(#[from] ClientLocationError), + GetNeighborError(#[from] GetNeighborError), + GetClientsError(#[from] GetClientsError), + GetAreaError(#[from] GetAreaError), MapsError(#[from] MapsError), MapAreaError(#[from] MapAreaError), InvalidRoom(u32), @@ -582,11 +585,11 @@ impl ServerState for ShipServerState { async fn on_disconnect(&mut self, id: ClientId) -> Result, ShipError> { // TODO: don't unwrap! - let client = self.clients.get(&id).unwrap(); - let area_client = self.client_location.get_local_client(id).unwrap(); - let neighbors = self.client_location.get_client_neighbors(id).unwrap(); + let client = self.clients.get(&id).ok_or(ShipError::ClientNotFound(id))?; + let area_client = self.client_location.get_local_client(id)?; + let neighbors = self.client_location.get_client_neighbors(id)?; - let pkt = match self.client_location.get_area(id).unwrap() { + let pkt = match self.client_location.get_area(id)? { RoomLobby::Room(room) => { if neighbors.len() == 0 { self.rooms[room.0] = None;