summaryrefslogtreecommitdiff
path: root/src/main/java/org
diff options
context:
space:
mode:
authorjbion <joffrey.bion@amadeus.com>2016-12-19 22:13:42 +0100
committerjbion <joffrey.bion@amadeus.com>2016-12-19 22:13:42 +0100
commitb8cff38a1cdddad1baad754f6a813bc26cafe0d9 (patch)
tree6b0392862eb4d3d11f57e5f854908fd1b834fdad /src/main/java/org
parentAdjust exceptions visibility (diff)
downloadseven-wonders-b8cff38a1cdddad1baad754f6a813bc26cafe0d9.tar.gz
seven-wonders-b8cff38a1cdddad1baad754f6a813bc26cafe0d9.tar.bz2
seven-wonders-b8cff38a1cdddad1baad754f6a813bc26cafe0d9.zip
Add response with list of games at subscription to /topic/games
Diffstat (limited to 'src/main/java/org')
-rw-r--r--src/main/java/org/luxons/sevenwonders/config/WebSocketConfig.java2
-rw-r--r--src/main/java/org/luxons/sevenwonders/controllers/LobbyController.java24
-rw-r--r--src/main/java/org/luxons/sevenwonders/repositories/LobbyRepository.java5
3 files changed, 17 insertions, 14 deletions
diff --git a/src/main/java/org/luxons/sevenwonders/config/WebSocketConfig.java b/src/main/java/org/luxons/sevenwonders/config/WebSocketConfig.java
index 83629d6a..3b588894 100644
--- a/src/main/java/org/luxons/sevenwonders/config/WebSocketConfig.java
+++ b/src/main/java/org/luxons/sevenwonders/config/WebSocketConfig.java
@@ -19,7 +19,7 @@ public class WebSocketConfig extends AbstractWebSocketMessageBrokerConfigurer {
config.setUserDestinationPrefix("/user");
// prefix for all calls from clients
- config.setApplicationDestinationPrefixes("/app");
+ config.setApplicationDestinationPrefixes("/app", "/topic");
}
@Override
diff --git a/src/main/java/org/luxons/sevenwonders/controllers/LobbyController.java b/src/main/java/org/luxons/sevenwonders/controllers/LobbyController.java
index 04735040..3b98d72f 100644
--- a/src/main/java/org/luxons/sevenwonders/controllers/LobbyController.java
+++ b/src/main/java/org/luxons/sevenwonders/controllers/LobbyController.java
@@ -1,7 +1,7 @@
package org.luxons.sevenwonders.controllers;
import java.security.Principal;
-import java.util.List;
+import java.util.Collection;
import org.luxons.sevenwonders.actions.JoinOrCreateGameAction;
import org.luxons.sevenwonders.actions.StartGameAction;
@@ -9,7 +9,6 @@ import org.luxons.sevenwonders.errors.ApiMisuseException;
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.repositories.GameRepository;
import org.luxons.sevenwonders.repositories.LobbyRepository;
import org.luxons.sevenwonders.session.SessionAttributes;
@@ -21,11 +20,11 @@ import org.springframework.messaging.handler.annotation.SendTo;
import org.springframework.messaging.simp.SimpMessageHeaderAccessor;
import org.springframework.messaging.simp.SimpMessagingTemplate;
import org.springframework.messaging.simp.annotation.SendToUser;
+import org.springframework.messaging.simp.annotation.SubscribeMapping;
import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
@Controller
-@MessageMapping("/lobby")
public class LobbyController {
private static final Logger logger = LoggerFactory.getLogger(LobbyController.class);
@@ -44,7 +43,13 @@ public class LobbyController {
this.gameRepository = gameRepository;
}
- @MessageMapping("/create-game")
+ @SubscribeMapping("/games") // prefix /topic not shown
+ public Collection<Lobby> listGames() {
+ logger.info("Subscribed to /games");
+ return lobbyRepository.list();
+ }
+
+ @MessageMapping("/lobby/create-game")
@SendTo("/topic/games")
public Lobby createGame(SimpMessageHeaderAccessor headerAccessor, @Validated JoinOrCreateGameAction action,
Principal principal) {
@@ -59,7 +64,7 @@ public class LobbyController {
return lobby;
}
- @MessageMapping("/join-game")
+ @MessageMapping("/lobby/join-game")
@SendToUser("/queue/join-game")
public Lobby joinGame(SimpMessageHeaderAccessor headerAccessor, @Validated JoinOrCreateGameAction action,
Principal principal) {
@@ -82,7 +87,7 @@ public class LobbyController {
}
}
- @MessageMapping("/start-game")
+ @MessageMapping("/lobby/start-game")
public void startGame(SimpMessageHeaderAccessor headerAccessor, @Validated StartGameAction action,
Principal principal) {
Lobby lobby = getOwnedLobby(headerAccessor, principal);
@@ -90,13 +95,6 @@ public class LobbyController {
gameRepository.add(game);
logger.info("Game {} successfully started", game.getId());
-
- List<PlayerTurnInfo> playerTurnInfos = game.startTurn();
- for (PlayerTurnInfo playerTurnInfo : playerTurnInfos) {
- Player player = playerTurnInfo.getTable().getPlayers().get(playerTurnInfo.getPlayerIndex());
- String userName = player.getUserName();
- template.convertAndSendToUser(userName, "/queue/game/turn", playerTurnInfo);
- }
}
private Lobby getOwnedLobby(SimpMessageHeaderAccessor headerAccessor, Principal principal) {
diff --git a/src/main/java/org/luxons/sevenwonders/repositories/LobbyRepository.java b/src/main/java/org/luxons/sevenwonders/repositories/LobbyRepository.java
index 2a4db2f3..bede34af 100644
--- a/src/main/java/org/luxons/sevenwonders/repositories/LobbyRepository.java
+++ b/src/main/java/org/luxons/sevenwonders/repositories/LobbyRepository.java
@@ -1,5 +1,6 @@
package org.luxons.sevenwonders.repositories;
+import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
@@ -24,6 +25,10 @@ public class LobbyRepository {
this.gameDefinitionLoader = gameDefinitionLoader;
}
+ public Collection<Lobby> list() {
+ return lobbies.values();
+ }
+
public Lobby create(String gameName, Player owner) {
if (lobbies.containsKey(gameName)) {
throw new GameNameAlreadyUsedException(gameName);
bgstack15