summaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
authorjbion <joffrey.bion@amadeus.com>2016-12-18 23:21:50 +0100
committerjbion <joffrey.bion@amadeus.com>2016-12-19 02:42:08 +0100
commit04a1f919c227371426a11ed74e57613ec891dce6 (patch)
treee63df2124478e8ea2e221a349e5072a13a2410d6 /src/main/java
parentAdd start game action (diff)
downloadseven-wonders-04a1f919c227371426a11ed74e57613ec891dce6.tar.gz
seven-wonders-04a1f919c227371426a11ed74e57613ec891dce6.tar.bz2
seven-wonders-04a1f919c227371426a11ed74e57613ec891dce6.zip
Move session attribute keys to a single file to ensure unicity more easily
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/org/luxons/sevenwonders/controllers/LobbyController.java16
-rw-r--r--src/main/java/org/luxons/sevenwonders/session/SessionAttributes.java8
2 files changed, 16 insertions, 8 deletions
diff --git a/src/main/java/org/luxons/sevenwonders/controllers/LobbyController.java b/src/main/java/org/luxons/sevenwonders/controllers/LobbyController.java
index 37041f32..7567c330 100644
--- a/src/main/java/org/luxons/sevenwonders/controllers/LobbyController.java
+++ b/src/main/java/org/luxons/sevenwonders/controllers/LobbyController.java
@@ -7,11 +7,13 @@ import java.util.Map;
import org.luxons.sevenwonders.actions.JoinOrCreateGameAction;
import org.luxons.sevenwonders.actions.StartGameAction;
+import org.luxons.sevenwonders.errors.UniqueIdAlreadyUsedException;
import org.luxons.sevenwonders.game.Game;
import org.luxons.sevenwonders.game.Lobby;
import org.luxons.sevenwonders.game.Player;
import org.luxons.sevenwonders.game.api.PlayerTurnInfo;
import org.luxons.sevenwonders.game.data.GameDefinitionLoader;
+import org.luxons.sevenwonders.session.SessionAttributes;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
@@ -30,8 +32,6 @@ public class LobbyController {
private static final Logger logger = LoggerFactory.getLogger(LobbyController.class);
- public static final String ATTR_LOBBY = "lobby";
-
private final GameDefinitionLoader gameDefinitionLoader;
private final SimpMessagingTemplate template;
@@ -59,7 +59,7 @@ public class LobbyController {
@SendTo("/topic/games")
public Lobby createGame(SimpMessageHeaderAccessor headerAccessor, @Validated JoinOrCreateGameAction action,
Principal principal) {
- Lobby lobby = (Lobby)headerAccessor.getSessionAttributes().get(ATTR_LOBBY);
+ Lobby lobby = (Lobby)headerAccessor.getSessionAttributes().get(SessionAttributes.ATTR_LOBBY);
if (lobby != null) {
logger.warn("Client already in game '{}', cannot create a new game", lobby.getName());
return lobby;
@@ -68,7 +68,7 @@ public class LobbyController {
Player player = createPlayer(action.getPlayerName(), principal);
lobby = createGame(action.getGameName(), player);
- headerAccessor.getSessionAttributes().put(ATTR_LOBBY, lobby);
+ headerAccessor.getSessionAttributes().put(SessionAttributes.ATTR_LOBBY, lobby);
logger.info("Game '{}' (id={}) created by {} ({})", lobby.getName(), lobby.getId(), player.getDisplayName(),
player.getUserName());
@@ -79,7 +79,7 @@ public class LobbyController {
@SendToUser("/queue/join-game")
public Lobby joinGame(SimpMessageHeaderAccessor headerAccessor, @Validated JoinOrCreateGameAction action,
Principal principal) {
- Lobby lobby = (Lobby)headerAccessor.getSessionAttributes().get(ATTR_LOBBY);
+ Lobby lobby = (Lobby)headerAccessor.getSessionAttributes().get(SessionAttributes.ATTR_LOBBY);
if (lobby != null) {
logger.warn("Client already in game '{}', cannot join a different game", lobby.getName());
return lobby;
@@ -93,7 +93,7 @@ public class LobbyController {
Player newPlayer = createPlayer(action.getPlayerName(), principal);
lobby.addPlayer(newPlayer);
- headerAccessor.getSessionAttributes().put(ATTR_LOBBY, lobby);
+ headerAccessor.getSessionAttributes().put(SessionAttributes.ATTR_LOBBY, lobby);
logger.warn("Player {} joined game {}", action.getPlayerName(), action.getGameName());
@@ -103,9 +103,9 @@ public class LobbyController {
@MessageMapping("/start-game")
public void startGame(SimpMessageHeaderAccessor headerAccessor, @Validated StartGameAction action,
Principal principal) {
- Lobby lobby = (Lobby)headerAccessor.getSessionAttributes().get(ATTR_LOBBY);
+ Lobby lobby = (Lobby)headerAccessor.getSessionAttributes().get(SessionAttributes.ATTR_LOBBY);
if (lobby == null) {
- logger.error("User {} is not in a game", principal.getName());
+ logger.error("User {} is not in a lobby", principal.getName());
template.convertAndSendToUser(principal.getName(), "/queue/errors", "No game to start");
return;
}
diff --git a/src/main/java/org/luxons/sevenwonders/session/SessionAttributes.java b/src/main/java/org/luxons/sevenwonders/session/SessionAttributes.java
new file mode 100644
index 00000000..8c69d8c3
--- /dev/null
+++ b/src/main/java/org/luxons/sevenwonders/session/SessionAttributes.java
@@ -0,0 +1,8 @@
+package org.luxons.sevenwonders.session;
+
+public class SessionAttributes {
+
+ public static final String ATTR_LOBBY = "lobby";
+
+ public static final String ATTR_GAME = "game";
+}
bgstack15