Browse Source

simplify leaving lobby packet sending

pbs
jake 5 years ago
parent
commit
2886f537ba
  1. 17
      src/ship/packet/handler/room.rs

17
src/ship/packet/handler/room.rs

@ -27,16 +27,19 @@ pub fn create_room(id: ClientId,
let join_room = builder::room::join_room(id, clients, client_location, room_id, &room)?;
rooms[room_id.0] = Some(room);
let leader = client_location.get_area_leader(area);
let result = vec![(id, SendShipPacket::JoinRoom(join_room))].into_iter();
match leader {
Ok(leader) => Ok(Box::new(result.chain(lobby_neighbors
let mut result: Box<dyn Iterator<Item=(ClientId, SendShipPacket)> + Send> = Box::new(
vec![(id, SendShipPacket::JoinRoom(join_room))].into_iter()
);
if let Ok(leader) = client_location.get_area_leader(area) {
let leave_lobby = SendShipPacket::LeaveLobby(LeaveLobby::new(area_client.local_client.id(), leader.local_client.id()));
result = Box::new(result.chain(lobby_neighbors
.into_iter()
.map(move |c| {
(c.client, SendShipPacket::LeaveLobby(LeaveLobby::new(area_client.local_client.id(), leader.local_client.id())))
})))),
Err(_) => Ok(Box::new(result))
(c.client, leave_lobby.clone())
})));
}
Ok(result)
}
pub fn room_name_request(id: ClientId,

Loading…
Cancel
Save