diff options
Diffstat (limited to 'sw-server')
-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 { |