Browse Source

load_character for item_manager to not crash when client leaves a room

pbs
Andy Newjack 5 years ago
parent
commit
94a1893a03
  1. 7
      src/ship/packet/handler/lobby.rs
  2. 2
      src/ship/ship.rs

7
src/ship/packet/handler/lobby.rs

@ -7,6 +7,7 @@ use crate::ship::location::{ClientLocation, LobbyId, RoomLobby, ClientLocationEr
//use crate::ship::items::; //use crate::ship::items::;
use crate::ship::packet; use crate::ship::packet;
use crate::ship::items::ItemManager; use crate::ship::items::ItemManager;
use crate::entity::gateway::EntityGateway;
// this function needs a better home // this function needs a better home
pub fn block_selected(id: ClientId, pub fn block_selected(id: ClientId,
@ -59,13 +60,14 @@ pub fn send_player_to_lobby(id: ClientId,
.map(|c| (c.client, SendShipPacket::AddToLobby(addto.clone())))).collect()) .map(|c| (c.client, SendShipPacket::AddToLobby(addto.clone())))).collect())
} }
pub fn change_lobby(id: ClientId,
pub fn change_lobby<EG: EntityGateway>(id: ClientId,
requested_lobby: u32, requested_lobby: u32,
client_location: &mut ClientLocation, client_location: &mut ClientLocation,
clients: &Clients, clients: &Clients,
item_manager: &mut ItemManager, item_manager: &mut ItemManager,
level_table: &CharacterLevelTable, level_table: &CharacterLevelTable,
ship_rooms: &mut Rooms)
ship_rooms: &mut Rooms,
entity_gateway: &mut EG)
-> Result<Vec<(ClientId, SendShipPacket)>, ShipError> { -> Result<Vec<(ClientId, SendShipPacket)>, ShipError> {
let client = clients.get(&id).ok_or(ShipError::ClientNotFound(id))?; let client = clients.get(&id).ok_or(ShipError::ClientNotFound(id))?;
let prev_area = client_location.get_area(id).map_err(|err| -> ClientLocationError {err.into()})?; let prev_area = client_location.get_area(id).map_err(|err| -> ClientLocationError {err.into()})?;
@ -96,6 +98,7 @@ pub fn change_lobby(id: ClientId,
} }
} }
} }
item_manager.load_character(entity_gateway, &client.character);
let join_lobby = packet::builder::lobby::join_lobby(id, lobby, client_location, clients, item_manager, level_table)?; let join_lobby = packet::builder::lobby::join_lobby(id, lobby, client_location, clients, item_manager, level_table)?;
let addto = packet::builder::lobby::add_to_lobby(id, lobby, client_location, clients, item_manager, level_table)?; let addto = packet::builder::lobby::add_to_lobby(id, lobby, client_location, clients, item_manager, level_table)?;
let neighbors = client_location.get_client_neighbors(id).unwrap(); let neighbors = client_location.get_client_neighbors(id).unwrap();

2
src/ship/ship.rs

@ -346,7 +346,7 @@ impl<EG: EntityGateway> ServerState for ShipServerState<EG> {
handler::room::done_bursting(id, &self.client_location, &mut self.rooms) handler::room::done_bursting(id, &self.client_location, &mut self.rooms)
}, },
RecvShipPacket::LobbySelect(pkt) => { RecvShipPacket::LobbySelect(pkt) => {
Box::new(handler::lobby::change_lobby(id, pkt.lobby, &mut self.client_location, &self.clients, &mut self.item_manager, &self.level_table, &mut self.rooms)?.into_iter())
Box::new(handler::lobby::change_lobby(id, pkt.lobby, &mut self.client_location, &self.clients, &mut self.item_manager, &self.level_table, &mut self.rooms, &mut self.entity_gateway)?.into_iter())
} }
}) })
} }

Loading…
Cancel
Save