From 2886f537ba8b5b698fd0d6d91a1d5676bcbd4cb7 Mon Sep 17 00:00:00 2001 From: jake Date: Fri, 24 Apr 2020 22:22:19 -0600 Subject: [PATCH] simplify leaving lobby packet sending --- src/ship/packet/handler/room.rs | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/ship/packet/handler/room.rs b/src/ship/packet/handler/room.rs index 2d4b228..ff82422 100644 --- a/src/ship/packet/handler/room.rs +++ b/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 - .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 + 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,