From 94a1893a032bb6e4049c915c5f7c76306295003b Mon Sep 17 00:00:00 2001 From: Andy Newjack Date: Sat, 23 May 2020 12:33:28 -0300 Subject: [PATCH] load_character for item_manager to not crash when client leaves a room --- src/ship/packet/handler/lobby.rs | 7 +++++-- src/ship/ship.rs | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/ship/packet/handler/lobby.rs b/src/ship/packet/handler/lobby.rs index eace260..c43dcfc 100644 --- a/src/ship/packet/handler/lobby.rs +++ b/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::packet; use crate::ship::items::ItemManager; +use crate::entity::gateway::EntityGateway; // this function needs a better home 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()) } -pub fn change_lobby(id: ClientId, +pub fn change_lobby(id: ClientId, requested_lobby: u32, client_location: &mut ClientLocation, clients: &Clients, item_manager: &mut ItemManager, level_table: &CharacterLevelTable, - ship_rooms: &mut Rooms) + ship_rooms: &mut Rooms, + entity_gateway: &mut EG) -> Result, ShipError> { let client = clients.get(&id).ok_or(ShipError::ClientNotFound(id))?; 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 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(); diff --git a/src/ship/ship.rs b/src/ship/ship.rs index 05a2c28..68f9da2 100644 --- a/src/ship/ship.rs +++ b/src/ship/ship.rs @@ -346,7 +346,7 @@ impl ServerState for ShipServerState { handler::room::done_bursting(id, &self.client_location, &mut self.rooms) }, 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()) } }) }