Merge pull request 'load_character for item_manager to not crash when client leaves a room' (#156) from leave_room_crash into master
This commit is contained in:
commit
2e4f54d41c
@ -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();
|
||||||
|
@ -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…
x
Reference in New Issue
Block a user