Browse Source

remove player from lobby before sending to another ship/block

pbs
jake 4 years ago
parent
commit
ae696888e9
  1. 24
      src/ship/packet/handler/lobby.rs
  2. 14
      src/ship/ship.rs

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

@ -15,7 +15,7 @@ pub fn block_selected(id: ClientId,
clients: &mut Clients, clients: &mut Clients,
item_manager: &ItemManager, item_manager: &ItemManager,
level_table: &CharacterLevelTable) level_table: &CharacterLevelTable)
-> Result<Vec<SendShipPacket>, anyhow::Error> {
-> Result<Vec<(ClientId, SendShipPacket)>, anyhow::Error> {
let client = clients.get_mut(&id).ok_or(ShipError::ClientNotFound(id))?; let client = clients.get_mut(&id).ok_or(ShipError::ClientNotFound(id))?;
client.block = pkt.item as usize - 1; client.block = pkt.item as usize - 1;
@ -38,11 +38,11 @@ pub fn block_selected(id: ClientId,
.build(); .build();
Ok(vec![ Ok(vec![
SendShipPacket::FullCharacter(Box::new(FullCharacter {
(id, SendShipPacket::FullCharacter(Box::new(FullCharacter {
character: fc, character: fc,
})),
SendShipPacket::CharDataRequest(CharDataRequest {}),
SendShipPacket::LobbyList(LobbyList::new()),
}))),
(id, SendShipPacket::CharDataRequest(CharDataRequest {})),
(id, SendShipPacket::LobbyList(LobbyList::new())),
]) ])
} }
@ -113,3 +113,17 @@ pub async fn change_lobby<EG: EntityGateway>(id: ClientId,
.map(|c| (c.client, SendShipPacket::LeaveLobby(leave_lobby.clone())))) .map(|c| (c.client, SendShipPacket::LeaveLobby(leave_lobby.clone()))))
.collect()) .collect())
} }
pub fn remove_from_lobby(id: ClientId,
client_location: &mut ClientLocation)
-> Result<Vec<(ClientId, SendShipPacket)>, anyhow::Error> {
let area_client = client_location.get_local_client(id)?;
let neighbors = client_location.get_client_neighbors(id)?;
let leader = client_location.get_leader_by_client(id)?;
let leave_lobby_pkt = SendShipPacket::LeaveLobby(LeaveLobby::new(area_client.local_client.id(), leader.local_client.id()));
client_location.remove_client_from_area(id)?;
Ok(neighbors.into_iter().map(|n| {
(n.client, leave_lobby_pkt.clone())
}).collect())
}

14
src/ship/ship.rs

@ -571,8 +571,16 @@ impl<EG: EntityGateway> ServerState for ShipServerState<EG> {
RecvShipPacket::MenuSelect(menuselect) => { RecvShipPacket::MenuSelect(menuselect) => {
let block = self.blocks.with_client(id, &self.clients)?; let block = self.blocks.with_client(id, &self.clients)?;
match menuselect.menu { match menuselect.menu {
SHIP_MENU_ID => handler::ship::selected_ship(id, menuselect, &self.ship_list)?,
BLOCK_MENU_ID => Box::new(handler::lobby::block_selected(id, menuselect, &mut self.clients, &self.item_manager, &self.level_table)?.into_iter().map(move |pkt| (id, pkt))),
SHIP_MENU_ID => {
let leave_lobby = handler::lobby::remove_from_lobby(id, &mut block.client_location).into_iter().into_iter().flatten();
let select_ship = handler::ship::selected_ship(id, menuselect, &self.ship_list)?;
Box::new(leave_lobby.chain(select_ship))
}
BLOCK_MENU_ID => {
let leave_lobby = handler::lobby::remove_from_lobby(id, &mut block.client_location).into_iter().into_iter().flatten();
let select_block = handler::lobby::block_selected(id, menuselect, &mut self.clients, &self.item_manager, &self.level_table)?.into_iter();
Box::new(leave_lobby.chain(select_block))
}
ROOM_MENU_ID => handler::room::join_room(id, menuselect, &mut block.client_location, &mut self.clients, &mut self.item_manager, &self.level_table, &mut block.rooms)?, ROOM_MENU_ID => handler::room::join_room(id, menuselect, &mut block.client_location, &mut self.clients, &mut self.item_manager, &self.level_table, &mut block.rooms)?,
QUEST_CATEGORY_MENU_ID => handler::quest::select_quest_category(id, menuselect, &self.quests)?, QUEST_CATEGORY_MENU_ID => handler::quest::select_quest_category(id, menuselect, &self.quests)?,
_ => unreachable!(), _ => unreachable!(),
@ -680,7 +688,7 @@ impl<EG: EntityGateway> ServerState for ShipServerState<EG> {
handler::ship::ship_list(id, &self.ship_list) handler::ship::ship_list(id, &self.ship_list)
}, },
RecvShipPacket::RequestShipBlockList(_) => { RecvShipPacket::RequestShipBlockList(_) => {
handler::ship::block_list(id, &self.name, 1)
handler::ship::block_list(id, &self.name, self.blocks.0.len())
} }
}) })
} }

Loading…
Cancel
Save