load_character for item_manager to not crash when client leaves a room
This commit is contained in:
		
							parent
							
								
									a8892467f6
								
							
						
					
					
						commit
						94a1893a03
					
				| @ -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<EG: EntityGateway>(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<Vec<(ClientId, SendShipPacket)>, 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(); | ||||
|  | ||||
| @ -346,7 +346,7 @@ impl<EG: EntityGateway> ServerState for ShipServerState<EG> { | ||||
|                 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()) | ||||
|             } | ||||
|         }) | ||||
|     } | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user