summaryrefslogtreecommitdiff
path: root/src/main/java/org
diff options
context:
space:
mode:
authorjbion <joffrey.bion@amadeus.com>2016-12-08 19:46:17 +0100
committerjbion <joffrey.bion@amadeus.com>2016-12-08 19:46:17 +0100
commit28b77437282eac733a20d5b396de05c06221c65f (patch)
tree8e65fa1c737a834aed8d03e0f45cd994d8db7ccc /src/main/java/org
parentClean gradle build (diff)
downloadseven-wonders-28b77437282eac733a20d5b396de05c06221c65f.tar.gz
seven-wonders-28b77437282eac733a20d5b396de05c06221c65f.tar.bz2
seven-wonders-28b77437282eac733a20d5b396de05c06221c65f.zip
First draft of client recognition through sessions
Diffstat (limited to 'src/main/java/org')
-rw-r--r--src/main/java/org/luxons/sevenwonders/app/LobbyController.java20
1 files changed, 15 insertions, 5 deletions
diff --git a/src/main/java/org/luxons/sevenwonders/app/LobbyController.java b/src/main/java/org/luxons/sevenwonders/app/LobbyController.java
index c4e43a3b..be23ad52 100644
--- a/src/main/java/org/luxons/sevenwonders/app/LobbyController.java
+++ b/src/main/java/org/luxons/sevenwonders/app/LobbyController.java
@@ -10,6 +10,7 @@ import org.luxons.sevenwonders.game.Settings;
import org.luxons.sevenwonders.game.data.GameDataLoader;
import org.springframework.messaging.handler.annotation.MessageMapping;
import org.springframework.messaging.handler.annotation.SendTo;
+import org.springframework.messaging.simp.SimpMessageHeaderAccessor;
import org.springframework.stereotype.Controller;
@Controller
@@ -21,7 +22,8 @@ public class LobbyController {
@MessageMapping("/lobby/create-game")
@SendTo("/broadcast/games")
- public String createGame() throws Exception {
+ public String createGame(SimpMessageHeaderAccessor headerAccessor) throws Exception {
+ System.out.println("Received message: " + headerAccessor.getSessionId());
Thread.sleep(1000); // simulated delay
String id = String.valueOf(lastGameId++);
@@ -34,14 +36,22 @@ public class LobbyController {
@MessageMapping("/lobby/join-game")
@SendTo("/broadcast/players")
- public Player joinGame(JoinGameAction joinAction) throws Exception {
+ public Player joinGame(SimpMessageHeaderAccessor headerAccessor, JoinGameAction joinAction) throws Exception {
Thread.sleep(1000); // simulated delay
+ Player player = (Player)headerAccessor.getSessionAttributes().get("player");
+ if (player != null) {
+ System.out.println("Client has already joined game under the name " + player.getName());
+ return player;
+ }
System.out.println("Player " + joinAction.getPlayerName() + " joined game " + joinAction.getGameId());
Game game = games.get(joinAction.getGameId());
- Player player = new Player(joinAction.getPlayerName());
- game.addPlayer(player);
- return player;
+ Player newPlayer = new Player(joinAction.getPlayerName());
+ game.addPlayer(newPlayer);
+
+ headerAccessor.getSessionAttributes().put("player", newPlayer);
+
+ return newPlayer;
}
}
bgstack15