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:
@@ -80,9 +80,11 @@ public class ClientService {
|
|||||||
return offlineMode;
|
return offlineMode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Allow primitive values to contain hyphens (UUIDs) in addition to
|
||||||
|
// digits/words/colons
|
||||||
static Pattern responseRex =
|
static Pattern responseRex =
|
||||||
Pattern.compile(
|
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 (\')
|
* Removes escape characters from a string, specifically converting escaped single quotes (\')
|
||||||
|
|||||||
+19
-2
@@ -387,9 +387,26 @@ public class TaskbarController {
|
|||||||
currentStage.close();
|
currentStage.close();
|
||||||
// Start lobby UI
|
// Start lobby UI
|
||||||
try {
|
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) {
|
} 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
|
// Default constructor
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final int SCENE_WIDTH = 1200;
|
public static final int SCENE_WIDTH = 1200;
|
||||||
private static final int SCENE_HEIGHT = 800;
|
public static final int SCENE_HEIGHT = 800;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
/**
|
/**
|
||||||
|
|||||||
+20
-1
@@ -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.ErrorResponse;
|
||||||
import ch.unibas.dmi.dbis.cs108.casono.server.network.protocol.response.OkResponse;
|
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 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.
|
* 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> {
|
public class JoinLobbyHandler extends CommandHandler<JoinLobbyRequest> {
|
||||||
private final LobbyManager lobbyManager;
|
private final LobbyManager lobbyManager;
|
||||||
private final UserRegistry userRegistry;
|
private final UserRegistry userRegistry;
|
||||||
|
private static final Logger LOGGER = LogManager.getLogger(JoinLobbyHandler.class);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new {@link JoinLobbyHandler}.
|
* Create a new {@link JoinLobbyHandler}.
|
||||||
@@ -46,9 +49,17 @@ public class JoinLobbyHandler extends CommandHandler<JoinLobbyRequest> {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void execute(JoinLobbyRequest request) {
|
public void execute(JoinLobbyRequest request) {
|
||||||
|
LOGGER.info(
|
||||||
|
"JOIN_LOBBY request: session={}, lobbyId={}",
|
||||||
|
request.getContext().sessionId(),
|
||||||
|
request.getId());
|
||||||
LobbyId lid = LobbyId.of(request.getId());
|
LobbyId lid = LobbyId.of(request.getId());
|
||||||
var lobby = lobbyManager.getLobby(lid);
|
var lobby = lobbyManager.getLobby(lid);
|
||||||
if (lobby == null) {
|
if (lobby == null) {
|
||||||
|
LOGGER.warn(
|
||||||
|
"JOIN_LOBBY: Lobby {} not found (session={})",
|
||||||
|
request.getId(),
|
||||||
|
request.getContext().sessionId());
|
||||||
responseDispatcher.dispatch(
|
responseDispatcher.dispatch(
|
||||||
new ErrorResponse(request.getContext(), "LOBBY_NOT_FOUND", "Lobby not found"));
|
new ErrorResponse(request.getContext(), "LOBBY_NOT_FOUND", "Lobby not found"));
|
||||||
return;
|
return;
|
||||||
@@ -56,7 +67,9 @@ public class JoinLobbyHandler extends CommandHandler<JoinLobbyRequest> {
|
|||||||
|
|
||||||
var maybeUser = userRegistry.getBySessionId(request.getContext().sessionId());
|
var maybeUser = userRegistry.getBySessionId(request.getContext().sessionId());
|
||||||
if (maybeUser.isEmpty()) {
|
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(
|
responseDispatcher.dispatch(
|
||||||
new ErrorResponse(
|
new ErrorResponse(
|
||||||
request.getContext(),
|
request.getContext(),
|
||||||
@@ -70,6 +83,10 @@ public class JoinLobbyHandler extends CommandHandler<JoinLobbyRequest> {
|
|||||||
|
|
||||||
boolean ok = lobbyManager.addPlayerToLobby(username, lid);
|
boolean ok = lobbyManager.addPlayerToLobby(username, lid);
|
||||||
if (!ok) {
|
if (!ok) {
|
||||||
|
LOGGER.warn(
|
||||||
|
"JOIN_LOBBY: User '{}' failed to join lobby {} (full or already in)",
|
||||||
|
username,
|
||||||
|
request.getId());
|
||||||
responseDispatcher.dispatch(
|
responseDispatcher.dispatch(
|
||||||
new ErrorResponse(
|
new ErrorResponse(
|
||||||
request.getContext(),
|
request.getContext(),
|
||||||
@@ -78,6 +95,8 @@ public class JoinLobbyHandler extends CommandHandler<JoinLobbyRequest> {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LOGGER.info("User '{}' joined lobby {}", username, request.getId());
|
||||||
|
|
||||||
responseDispatcher.dispatch(new OkResponse(request.getContext()));
|
responseDispatcher.dispatch(new OkResponse(request.getContext()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -69,6 +69,15 @@ public class LobbyManager {
|
|||||||
lobby.addPlayerAndMaybeStart(
|
lobby.addPlayerAndMaybeStart(
|
||||||
username, maxPlayersPerLobby, AUTO_START_PLAYERS, DEFAULT_START_CHIPS);
|
username, maxPlayersPerLobby, AUTO_START_PLAYERS, DEFAULT_START_CHIPS);
|
||||||
if (result != AddResult.NOT_ADDED) {
|
if (result != AddResult.NOT_ADDED) {
|
||||||
|
LOGGER.info(
|
||||||
|
() ->
|
||||||
|
"User '"
|
||||||
|
+ username
|
||||||
|
+ "' joined lobby "
|
||||||
|
+ lobbyId.value()
|
||||||
|
+ " (result="
|
||||||
|
+ result
|
||||||
|
+ ")");
|
||||||
playerToLobby.put(username, lobbyId);
|
playerToLobby.put(username, lobbyId);
|
||||||
if (result == AddResult.ADDED_AND_STARTED) {
|
if (result == AddResult.ADDED_AND_STARTED) {
|
||||||
LOGGER.info(
|
LOGGER.info(
|
||||||
|
|||||||
Reference in New Issue
Block a user