From a24381bc66108da197d6b04f30b1319cf96bd7fe Mon Sep 17 00:00:00 2001 From: mht8355 Date: Mon, 27 Apr 2020 22:58:43 -0400 Subject: [PATCH] sends the client a message when selected lobby = current lobby --- src/ship/packet/handler/lobby.rs | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/ship/packet/handler/lobby.rs b/src/ship/packet/handler/lobby.rs index 8d0cba4..cc31ba1 100644 --- a/src/ship/packet/handler/lobby.rs +++ b/src/ship/packet/handler/lobby.rs @@ -4,9 +4,10 @@ use crate::common::serverstate::ClientId; use crate::common::leveltable::CharacterLevelTable; use crate::ship::ship::{SendShipPacket, ShipError, ClientState, Clients}; use crate::ship::character::{CharacterBytesBuilder, FullCharacterBytesBuilder}; -use crate::ship::location::{ClientLocation, LobbyId, RoomId, RoomLobby, MAX_ROOMS}; +use crate::ship::location::{ClientLocation, LobbyId, RoomId, RoomLobby, MAX_ROOMS, ClientLocationError}; use crate::ship::packet; use libpso::character::character; +use crate::ship::location::ClientLocationError::GetAreaError; // this function needs a better home pub fn block_selected(id: ClientId, @@ -61,8 +62,12 @@ pub fn change_lobby(id: ClientId, clients: &Clients, level_table: &CharacterLevelTable) -> Result, ShipError> { - let prev_area = client_location.get_area(id).unwrap(); - let leave_lobby = packet::builder::lobby::remove_from_lobby(id, client_location).unwrap(); + let prev_area = client_location.get_area(id).map_err(|err| -> ClientLocationError {err.into()})?; + if prev_area == RoomLobby::Lobby(LobbyId(requested_lobby as usize)) { // If the client is already in the selected lobby, + let dialog = SmallDialog::new(String::from("You are already in this Lobby!")); // Send a SmallDialog to prevent client softlock / server crash + return Ok(vec![(id, SendShipPacket::SmallDialog(dialog))]) + } + let leave_lobby = packet::builder::lobby::remove_from_lobby(id, client_location)?; let old_neighbors = client_location.get_client_neighbors(id).unwrap(); let mut lobby = LobbyId(requested_lobby as usize); match client_location.add_client_to_lobby(id, lobby) { @@ -71,14 +76,11 @@ pub fn change_lobby(id: ClientId, Err(err) => { match prev_area { RoomLobby::Lobby(lobby) => { - let dialog = SmallDialog { - padding: [0, 0], - msg: String::from("Lobby is full."), - }; + let dialog = SmallDialog::new(String::from("Lobby is full.")); return Ok(vec![(id, SendShipPacket::SmallDialog(dialog))]) } RoomLobby::Room(room) => { - lobby = client_location.add_client_to_next_available_lobby(id, lobby).unwrap(); + lobby = client_location.add_client_to_next_available_lobby(id, lobby).map_err(|_| ShipError::TooManyClients)?; } } }