Merge branch 'fix/143-client-rejoin-flow' into 'main'
fix: add client leave-lobby rejoin flow Closes #143 See merge request cs108-fs26/Gruppe-13!175
This commit was merged in pull request #331.
This commit is contained in:
@@ -127,6 +127,15 @@ public class LobbyClient {
|
|||||||
client.processCommand("JOIN_LOBBY ID=" + lobbyId);
|
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.
|
* Logs in to the server with the given username by sending a "LOGIN" command.
|
||||||
*
|
*
|
||||||
|
|||||||
+5
-1
@@ -405,7 +405,8 @@ public class CasinoGameController {
|
|||||||
// new Card("king", "spades"),
|
// new Card("king", "spades"),
|
||||||
// new Card("10", "diamonds")));
|
// 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) {
|
// } catch (Exception e) {
|
||||||
// e.printStackTrace();
|
// e.printStackTrace();
|
||||||
// }
|
// }
|
||||||
@@ -2156,6 +2157,9 @@ public class CasinoGameController {
|
|||||||
if (controller == null) {
|
if (controller == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (chatClientService != null && chatLobbyId >= 0) {
|
||||||
|
controller.setLobbyContext(new LobbyClient(chatClientService), chatLobbyId);
|
||||||
|
}
|
||||||
controller.setLobbyActionAnnouncer(this::sendLobbyActionMessage);
|
controller.setLobbyActionAnnouncer(this::sendLobbyActionMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+18
@@ -52,6 +52,8 @@ public class TaskbarController {
|
|||||||
@FXML private Label moneyLabel;
|
@FXML private Label moneyLabel;
|
||||||
|
|
||||||
private GameService gameService;
|
private GameService gameService;
|
||||||
|
private LobbyClient lobbyClient;
|
||||||
|
private int lobbyId = -1;
|
||||||
private PlayerId myPlayerId;
|
private PlayerId myPlayerId;
|
||||||
private String myPlayerName;
|
private String myPlayerName;
|
||||||
private GameState lastState;
|
private GameState lastState;
|
||||||
@@ -242,6 +244,12 @@ public class TaskbarController {
|
|||||||
this.myPlayerName = myPlayerId != null ? normalizeIdentifier(myPlayerId.value()) : null;
|
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. */
|
/** Sets the NotebookController reference for showing/hiding tips. */
|
||||||
public void setNotebookController(NotebookController notebookController) {
|
public void setNotebookController(NotebookController notebookController) {
|
||||||
this.notebookController = notebookController;
|
this.notebookController = notebookController;
|
||||||
@@ -1622,6 +1630,16 @@ public class TaskbarController {
|
|||||||
SoundManager.getInstance().playButtonClick();
|
SoundManager.getInstance().playButtonClick();
|
||||||
javafx.application.Platform.runLater(
|
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
|
// Close game stage
|
||||||
javafx.stage.Stage currentStage =
|
javafx.stage.Stage currentStage =
|
||||||
(javafx.stage.Stage) taskbar.getScene().getWindow();
|
(javafx.stage.Stage) taskbar.getScene().getWindow();
|
||||||
|
|||||||
Reference in New Issue
Block a user