Merge branch 'feat/lobby-join-logging' into 'main'

Feat/lobby join logging

See merge request cs108-fs26/Gruppe-13!119
This commit was merged in pull request #275.
This commit is contained in:
Jona Walpert
2026-04-12 11:33:41 +00:00
5 changed files with 53 additions and 6 deletions
@@ -80,9 +80,11 @@ public class ClientService {
return offlineMode;
}
// Allow primitive values to contain hyphens (UUIDs) in addition to
// digits/words/colons
static Pattern responseRex =
Pattern.compile(
"(?<key>\\w+)=(('(?<string>([^']|\\')+)')|(?<primVal>[+-]?[\\d\\w:]+))");
"(?<key>\\w+)=(('(?<string>([^']|\\')+)')|(?<primVal>[+-]?[-\\d\\w:]+))");
/**
* Removes escape characters from a string, specifically converting escaped single quotes (\')
@@ -387,9 +387,26 @@ public class TaskbarController {
currentStage.close();
// Start lobby UI
try {
new Casinomainui().start(new javafx.stage.Stage());
javafx.stage.Stage newStage = new javafx.stage.Stage();
javafx.fxml.FXMLLoader fxmlLoader =
new javafx.fxml.FXMLLoader(
getClass().getResource("/ui-structure/Casinomainui.fxml"));
javafx.scene.Parent root = fxmlLoader.load();
javafx.scene.Scene scene =
new javafx.scene.Scene(
root, Casinomainui.SCENE_WIDTH, Casinomainui.SCENE_HEIGHT);
newStage.setTitle("Casono");
javafx.scene.image.Image icon =
new javafx.scene.image.Image(
getClass()
.getResource("/images/logoinverted.png")
.toExternalForm());
newStage.getIcons().add(icon);
newStage.setScene(scene);
newStage.setFullScreen(true);
newStage.show();
} catch (Exception e) {
LOGGER.error("Error: starting the lobby UI: {}", e.getMessage());
LOGGER.error("Error: starting the lobby UI: {}", e.getMessage(), e);
}
});
}
@@ -19,8 +19,8 @@ public class Casinomainui extends Application {
// Default constructor
}
private static final int SCENE_WIDTH = 1200;
private static final int SCENE_HEIGHT = 800;
public static final int SCENE_WIDTH = 1200;
public static final int SCENE_HEIGHT = 800;
@Override
/**
@@ -9,6 +9,8 @@ import ch.unibas.dmi.dbis.cs108.casono.server.network.command.execution.CommandH
import ch.unibas.dmi.dbis.cs108.casono.server.network.protocol.response.ErrorResponse;
import ch.unibas.dmi.dbis.cs108.casono.server.network.protocol.response.OkResponse;
import ch.unibas.dmi.dbis.cs108.casono.server.network.protocol.response.dispatcher.ResponseDispatcher;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
/**
* Handler for the `JOIN_LOBBY` command.
@@ -21,6 +23,7 @@ import ch.unibas.dmi.dbis.cs108.casono.server.network.protocol.response.dispatch
public class JoinLobbyHandler extends CommandHandler<JoinLobbyRequest> {
private final LobbyManager lobbyManager;
private final UserRegistry userRegistry;
private static final Logger LOGGER = LogManager.getLogger(JoinLobbyHandler.class);
/**
* Create a new {@link JoinLobbyHandler}.
@@ -46,9 +49,17 @@ public class JoinLobbyHandler extends CommandHandler<JoinLobbyRequest> {
*/
@Override
public void execute(JoinLobbyRequest request) {
LOGGER.info(
"JOIN_LOBBY request: session={}, lobbyId={}",
request.getContext().sessionId(),
request.getId());
LobbyId lid = LobbyId.of(request.getId());
var lobby = lobbyManager.getLobby(lid);
if (lobby == null) {
LOGGER.warn(
"JOIN_LOBBY: Lobby {} not found (session={})",
request.getId(),
request.getContext().sessionId());
responseDispatcher.dispatch(
new ErrorResponse(request.getContext(), "LOBBY_NOT_FOUND", "Lobby not found"));
return;
@@ -56,7 +67,9 @@ public class JoinLobbyHandler extends CommandHandler<JoinLobbyRequest> {
var maybeUser = userRegistry.getBySessionId(request.getContext().sessionId());
if (maybeUser.isEmpty()) {
// UserLoggedInCheck should normally prevent this; keep safe fallback
LOGGER.warn(
"JOIN_LOBBY: No user associated with session {}",
request.getContext().sessionId());
responseDispatcher.dispatch(
new ErrorResponse(
request.getContext(),
@@ -70,6 +83,10 @@ public class JoinLobbyHandler extends CommandHandler<JoinLobbyRequest> {
boolean ok = lobbyManager.addPlayerToLobby(username, lid);
if (!ok) {
LOGGER.warn(
"JOIN_LOBBY: User '{}' failed to join lobby {} (full or already in)",
username,
request.getId());
responseDispatcher.dispatch(
new ErrorResponse(
request.getContext(),
@@ -78,6 +95,8 @@ public class JoinLobbyHandler extends CommandHandler<JoinLobbyRequest> {
return;
}
LOGGER.info("User '{}' joined lobby {}", username, request.getId());
responseDispatcher.dispatch(new OkResponse(request.getContext()));
}
}
@@ -69,6 +69,15 @@ public class LobbyManager {
lobby.addPlayerAndMaybeStart(
username, maxPlayersPerLobby, AUTO_START_PLAYERS, DEFAULT_START_CHIPS);
if (result != AddResult.NOT_ADDED) {
LOGGER.info(
() ->
"User '"
+ username
+ "' joined lobby "
+ lobbyId.value()
+ " (result="
+ result
+ ")");
playerToLobby.put(username, lobbyId);
if (result == AddResult.ADDED_AND_STARTED) {
LOGGER.info(