|
|
@ -35,6 +35,7 @@ pub fn block_selected(id: ClientId, |
|
|
|
character: fc,
|
|
|
|
}),
|
|
|
|
SendShipPacket::CharDataRequest(CharDataRequest {}),
|
|
|
|
SendShipPacket::LobbyList(LobbyList::new()),
|
|
|
|
])
|
|
|
|
}
|
|
|
|
|
|
|
@ -47,10 +48,41 @@ pub fn send_player_to_lobby(id: ClientId, |
|
|
|
let lobby = client_location.add_client_to_next_available_lobby(id, LobbyId(0)).map_err(|_| ShipError::TooManyClients)?;
|
|
|
|
let join_lobby = packet::builder::lobby::join_lobby(id, lobby, client_location, clients, level_table)?;
|
|
|
|
let addto = packet::builder::lobby::add_to_lobby(id, lobby, client_location, clients, level_table)?;
|
|
|
|
|
|
|
|
let neighbors = client_location.get_client_neighbors(id).unwrap();
|
|
|
|
Ok(vec![(id, SendShipPacket::JoinLobby(join_lobby))]
|
|
|
|
.into_iter()
|
|
|
|
.chain(neighbors.into_iter()
|
|
|
|
.map(|c| (c.client, SendShipPacket::AddToLobby(addto.clone())))).collect())
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn change_lobby(id: ClientId,
|
|
|
|
requested_lobby: u32,
|
|
|
|
client_location: &mut ClientLocation,
|
|
|
|
clients: &Clients,
|
|
|
|
level_table: &CharacterLevelTable)
|
|
|
|
-> Result<Vec<(ClientId, SendShipPacket)>, ShipError> {
|
|
|
|
let leave_lobby = packet::builder::lobby::remove_from_lobby(id, client_location).unwrap();
|
|
|
|
let old_neighbors = client_location.get_client_neighbors(id).unwrap();
|
|
|
|
let lobby = LobbyId(requested_lobby as usize);
|
|
|
|
match client_location.add_client_to_lobby(id, lobby) {
|
|
|
|
Ok(lobby) => {
|
|
|
|
}
|
|
|
|
Err(err) => {
|
|
|
|
let dialog = SmallDialog {
|
|
|
|
padding: [0, 0],
|
|
|
|
msg: String::from("Lobby is full."),
|
|
|
|
};
|
|
|
|
return Ok(vec![(id, SendShipPacket::SmallDialog(dialog))])
|
|
|
|
}
|
|
|
|
}
|
|
|
|
let join_lobby = packet::builder::lobby::join_lobby(id, lobby, client_location, clients, level_table)?;
|
|
|
|
let addto = packet::builder::lobby::add_to_lobby(id, lobby, client_location, clients, level_table)?;
|
|
|
|
let neighbors = client_location.get_client_neighbors(id).unwrap();
|
|
|
|
Ok(vec![(id, SendShipPacket::JoinLobby(join_lobby))]
|
|
|
|
.into_iter()
|
|
|
|
.chain(neighbors.into_iter()
|
|
|
|
.map(|c| (c.client, SendShipPacket::AddToLobby(addto.clone()))))
|
|
|
|
.chain(old_neighbors.into_iter()
|
|
|
|
.map(|c| (c.client, SendShipPacket::LeaveLobby(leave_lobby.clone()))))
|
|
|
|
.collect())
|
|
|
|
}
|