|
@ -341,9 +341,17 @@ impl<EG: EntityGateway> ShipServerState<EG> { |
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
fn create_room(&mut self, id: ClientId, create_room: &CreateRoom) -> Box<dyn Iterator<Item = (ClientId, SendShipPacket)>> {
|
|
|
fn create_room(&mut self, id: ClientId, create_room: &CreateRoom) -> Box<dyn Iterator<Item = (ClientId, SendShipPacket)>> {
|
|
|
|
|
|
let area = self.client_location.get_area_by_user(id);
|
|
|
|
|
|
let area_client = area.clients().into_iter().filter(|client| {
|
|
|
|
|
|
client.client_id == id
|
|
|
|
|
|
}).next().unwrap();
|
|
|
|
|
|
let other_clients = area.clients().into_iter()
|
|
|
|
|
|
.filter(move |c| {
|
|
|
|
|
|
c.client_id != id
|
|
|
|
|
|
});
|
|
|
let room_id = match self.client_location.new_room(id) {
|
|
|
let room_id = match self.client_location.new_room(id) {
|
|
|
Ok(room_id) => room_id,
|
|
|
Ok(room_id) => room_id,
|
|
|
Err(e) => return Box::new(vec![(id, SendShipPacket::SmallDialog(SmallDialog::new("could not create room".to_owned())))].into_iter())
|
|
|
|
|
|
|
|
|
Err(err) => return Box::new(vec![(id, SendShipPacket::SmallDialog(SmallDialog::new(format!("could not create room: {:?}", err))))].into_iter())
|
|
|
};
|
|
|
};
|
|
|
|
|
|
|
|
|
let room = room::RoomState::from_create_room(create_room).unwrap();
|
|
|
let room = room::RoomState::from_create_room(create_room).unwrap();
|
|
@ -377,8 +385,10 @@ impl<EG: EntityGateway> ShipServerState<EG> { |
|
|
unknown: 0,
|
|
|
unknown: 0,
|
|
|
};
|
|
|
};
|
|
|
|
|
|
|
|
|
Box::new(vec![(id, SendShipPacket::JoinRoom(join_room))].into_iter())
|
|
|
|
|
|
//self.rooms.insert(room_id, room);
|
|
|
|
|
|
|
|
|
let leader = area.leader();
|
|
|
|
|
|
Box::new(vec![(id, SendShipPacket::JoinRoom(join_room))].into_iter().chain(other_clients.map(move |c| {
|
|
|
|
|
|
(c.client_id, SendShipPacket::LeaveLobby(LeaveLobby::new(area_client.index as u8, leader.index as u8)))
|
|
|
|
|
|
})))
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|