diff options
author | joffrey-bion <joffrey.bion@gmail.com> | 2021-02-17 02:34:18 +0100 |
---|---|---|
committer | joffrey-bion <joffrey.bion@gmail.com> | 2021-02-17 02:34:18 +0100 |
commit | e48dc809a95a3ac813c4da8798c9e57cbb6a32b6 (patch) | |
tree | aa5219552150be13cb0d2fcbc340313260ba928d /sw-server/src | |
parent | Add prepared card indicator (diff) | |
download | seven-wonders-e48dc809a95a3ac813c4da8798c9e57cbb6a32b6.tar.gz seven-wonders-e48dc809a95a3ac813c4da8798c9e57cbb6a32b6.tar.bz2 seven-wonders-e48dc809a95a3ac813c4da8798c9e57cbb6a32b6.zip |
Use automatic sayReady call to synchronize STOMP subscriptions before first turn
We currently miss the preparedCard event from bots if they are too fast, because
the server sends the first turn to everyone without knowing if all clients have
properly subscribed to events.
We now use sayReady to indicate to the server that all subscriptions have been made.
Diffstat (limited to 'sw-server/src')
-rw-r--r-- | sw-server/src/main/kotlin/org/luxons/sevenwonders/server/controllers/GameController.kt | 9 | ||||
-rw-r--r-- | sw-server/src/main/kotlin/org/luxons/sevenwonders/server/controllers/LobbyController.kt | 14 |
2 files changed, 8 insertions, 15 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 cff3aea0..e4c1b39a 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 @@ -40,18 +40,15 @@ class GameController( fun ready(principal: Principal) { val player = principal.player val lobby = player.lobby - if (!lobby.settings.askForReadiness) { - logger.warn("Game {}: player {} is saying ready but readiness concept is disabled", lobby.id, player) - return - } - val game = player.game // This lock doesn't have a clear rationale, but it's cleaner to check the readiness state of everyone within a // lock together with the code that updates the readiness status, to avoid interleaving surprises. synchronized(game) { player.isReady = true - sendPlayerReady(game.id, player) + if (lobby.settings.askForReadiness) { + sendPlayerReady(game.id, player) + } logger.info("Game {}: player {} is ready for the next turn", game.id, player) val players = lobby.getPlayers() diff --git a/sw-server/src/main/kotlin/org/luxons/sevenwonders/server/controllers/LobbyController.kt b/sw-server/src/main/kotlin/org/luxons/sevenwonders/server/controllers/LobbyController.kt index 70ac50e7..6a696d25 100644 --- a/sw-server/src/main/kotlin/org/luxons/sevenwonders/server/controllers/LobbyController.kt +++ b/sw-server/src/main/kotlin/org/luxons/sevenwonders/server/controllers/LobbyController.kt @@ -184,12 +184,10 @@ class LobbyController( meterRegistry.counter("games.started").increment() logger.info("Game {} ('{}') successfully started", game.id, lobby.name) - val currentTurnInfo = game.getCurrentTurnInfo().let { - if (lobby.settings.askForReadiness) it.hideHandsAndWaitForReadiness() else it - } - // even if we don't care about ready state for business logic, the UI may use it nonetheless - lobby.initializePlayersReadyState() + // we wait for readiness here to ensure all subscriptions are correctly setup on client side + val currentTurnInfo = game.getCurrentTurnInfo().hideHandsAndWaitForReadiness() + lobby.resetPlayersReadyState() currentTurnInfo.forEach { val player = lobby.getPlayers()[it.playerIndex] @@ -198,10 +196,8 @@ class LobbyController( template.convertAndSend("/topic/games", GameListEvent.CreateOrUpdate(lobby.toDTO()).wrap()) } - private fun Lobby.initializePlayersReadyState() { - val players = getPlayers() - val initialReadyState = !settings.askForReadiness - players.forEach { it.isReady = initialReadyState } + private fun Lobby.resetPlayersReadyState() { + getPlayers().forEach { it.isReady = false } } companion object { |