fix: add client leave-lobby rejoin flow #331

Merged
jona.walpert merged 1 commits from fix/143-client-rejoin-flow into main 2026-05-13 23:33:12 +02:00
3 changed files with 110 additions and 79 deletions
@@ -127,6 +127,15 @@ public class LobbyClient {
client.processCommand("JOIN_LOBBY ID=" + lobbyId);
}
/**
* Request the server to mark the current user as absent from the given lobby.
*
* @param lobbyId the lobby to leave
*/
public void leaveLobby(int lobbyId) {
client.processCommand("LEAVE_LOBBY ID=" + lobbyId);
}
/**
* Logs in to the server with the given username by sending a "LOGIN" command.
*
@@ -405,7 +405,8 @@ public class CasinoGameController {
// new Card("king", "spades"),
// new Card("10", "diamonds")));
//
// renderPlayerCards(List.of(new Card("10", "spades"), new Card("king", "spades")));
// renderPlayerCards(List.of(new Card("10", "spades"), new Card("king",
// "spades")));
// } catch (Exception e) {
// e.printStackTrace();
// }
@@ -2156,6 +2157,9 @@ public class CasinoGameController {
if (controller == null) {
return;
}
if (chatClientService != null && chatLobbyId >= 0) {
controller.setLobbyContext(new LobbyClient(chatClientService), chatLobbyId);
}
controller.setLobbyActionAnnouncer(this::sendLobbyActionMessage);
}
@@ -52,6 +52,8 @@ public class TaskbarController {
@FXML private Label moneyLabel;
private GameService gameService;
private LobbyClient lobbyClient;
private int lobbyId = -1;
private PlayerId myPlayerId;
private String myPlayerName;
private GameState lastState;
@@ -242,6 +244,12 @@ public class TaskbarController {
this.myPlayerName = myPlayerId != null ? normalizeIdentifier(myPlayerId.value()) : null;
}
/** Sets the lobby context so Exit can notify the server before closing. */
public void setLobbyContext(LobbyClient lobbyClient, int lobbyId) {
this.lobbyClient = lobbyClient;
this.lobbyId = lobbyId;
}
/** Sets the NotebookController reference for showing/hiding tips. */
public void setNotebookController(NotebookController notebookController) {
this.notebookController = notebookController;
@@ -1622,6 +1630,16 @@ public class TaskbarController {
SoundManager.getInstance().playButtonClick();
javafx.application.Platform.runLater(
() -> {
if (lobbyClient != null && lobbyId > 0) {
try {
lobbyClient.leaveLobby(lobbyId);
} catch (RuntimeException e) {
LOGGER.warn(
"Could not notify server about lobby leave: {}",
e.getMessage());
}
}
// Close game stage
javafx.stage.Stage currentStage =
(javafx.stage.Stage) taskbar.getScene().getWindow();