change_lobby added for changing lobbies and leaving a room

This commit is contained in:
mht8355 2020-04-27 21:22:12 -04:00
parent d206814394
commit 062fed231a
2 changed files with 15 additions and 7 deletions

View File

@ -47,7 +47,7 @@ fn setup_logger() {
.chain(std::io::stdout()); .chain(std::io::stdout());
let fileout = fern::Dispatch::new() let fileout = fern::Dispatch::new()
.level(log::LevelFilter::Trace) .level(log::LevelFilter::Trace)
.chain(fern::log_file(format!("elseware-{}.log", chrono::Local::now().format("%Y-%m-%d"))).unwrap()); .chain(fern::log_file(format!("elseware-{}.log", chrono::Local::now().format("%Y-%m-%d_%H:%M:%S"))).unwrap());
fern::Dispatch::new() fern::Dispatch::new()
.chain(stdio) .chain(stdio)
.chain(fileout) .chain(fileout)

View File

@ -61,19 +61,27 @@ pub fn change_lobby(id: ClientId,
clients: &Clients, clients: &Clients,
level_table: &CharacterLevelTable) level_table: &CharacterLevelTable)
-> Result<Vec<(ClientId, SendShipPacket)>, ShipError> { -> Result<Vec<(ClientId, SendShipPacket)>, ShipError> {
let prev_area = client_location.get_area(id).unwrap();
let leave_lobby = packet::builder::lobby::remove_from_lobby(id, client_location).unwrap(); let leave_lobby = packet::builder::lobby::remove_from_lobby(id, client_location).unwrap();
let old_neighbors = client_location.get_client_neighbors(id).unwrap(); let old_neighbors = client_location.get_client_neighbors(id).unwrap();
let lobby = LobbyId(requested_lobby as usize); let mut lobby = LobbyId(requested_lobby as usize);
match client_location.add_client_to_lobby(id, lobby) { match client_location.add_client_to_lobby(id, lobby) {
Ok(lobby) => { Ok(lobby) => {
} }
Err(err) => { Err(err) => {
match prev_area {
RoomLobby::Lobby(lobby) => {
let dialog = SmallDialog { let dialog = SmallDialog {
padding: [0, 0], padding: [0, 0],
msg: String::from("Lobby is full."), msg: String::from("Lobby is full."),
}; };
return Ok(vec![(id, SendShipPacket::SmallDialog(dialog))]) return Ok(vec![(id, SendShipPacket::SmallDialog(dialog))])
} }
RoomLobby::Room(room) => {
lobby = client_location.add_client_to_next_available_lobby(id, lobby).unwrap();
}
}
}
} }
let join_lobby = packet::builder::lobby::join_lobby(id, lobby, client_location, clients, level_table)?; 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 addto = packet::builder::lobby::add_to_lobby(id, lobby, client_location, clients, level_table)?;