From 27e7e39608987f6d354b0c9c52eee10e1fa31ba2 Mon Sep 17 00:00:00 2001 From: Joffrey Bion Date: Tue, 26 May 2020 10:20:02 +0200 Subject: Fix race condition bewteen next turn and prepared move Resolves: https://github.com/joffrey-bion/seven-wonders/issues/24 --- .../org/luxons/sevenwonders/server/controllers/GameController.kt | 6 +++--- sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/redux/Reducers.kt | 3 ++- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/sw-server/src/main/kotlin/org/luxons/sevenwonders/server/controllers/GameController.kt b/sw-server/src/main/kotlin/org/luxons/sevenwonders/server/controllers/GameController.kt index dc5dffdb..e86e7b54 100644 --- a/sw-server/src/main/kotlin/org/luxons/sevenwonders/server/controllers/GameController.kt +++ b/sw-server/src/main/kotlin/org/luxons/sevenwonders/server/controllers/GameController.kt @@ -62,8 +62,7 @@ class GameController( * the connected user's information */ @MessageMapping("/game/prepareMove") - @SendToUser("/queue/game/preparedMove") - fun prepareMove(action: PrepareMoveAction, principal: Principal): PlayerMove { + fun prepareMove(action: PrepareMoveAction, principal: Principal) { val player = principal.player val game = player.game val preparedCardBack = game.prepareMove(player.index, action.move) @@ -78,8 +77,9 @@ class GameController( if (game.endOfGameReached()) { player.lobby.setEndOfGame() } + } else { + template.convertAndSendToUser(player.username, "/queue/game/preparedMove", action.move) } - return action.move } @MessageMapping("/game/unprepareMove") diff --git a/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/redux/Reducers.kt b/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/redux/Reducers.kt index c21f6deb..1ff0d0ec 100644 --- a/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/redux/Reducers.kt +++ b/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/redux/Reducers.kt @@ -78,7 +78,8 @@ private fun gameStateReducer(gameState: GameState?, action: RAction): GameState? }) is TurnInfoEvent -> gameState?.copy( players = gameState.players.map { p -> p.copy(isReady = false) }, - turnInfo = action.turnInfo + turnInfo = action.turnInfo, + currentPreparedMove = null ) else -> gameState } -- cgit