Browse Source

remove unwraps in ship on_disconnect

pbs
jake 4 years ago
parent
commit
ce3e58d459
  1. 13
      src/ship/ship.rs

13
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<EG: EntityGateway> ServerState for ShipServerState<EG> {
async fn on_disconnect(&mut self, id: ClientId) -> Result<Vec<(ClientId, SendShipPacket)>, 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;

Loading…
Cancel
Save