simplify leaving lobby packet sending
This commit is contained in:
parent
628ad056b4
commit
2886f537ba
@ -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
|
||||
.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))
|
||||
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, leave_lobby.clone())
|
||||
})));
|
||||
}
|
||||
|
||||
Ok(result)
|
||||
}
|
||||
|
||||
pub fn room_name_request(id: ClientId,
|
||||
|
Loading…
x
Reference in New Issue
Block a user