diff options
Diffstat (limited to 'sw-server/src/main')
3 files changed, 27 insertions, 6 deletions
diff --git a/sw-server/src/main/kotlin/org/luxons/sevenwonders/server/api/Converters.kt b/sw-server/src/main/kotlin/org/luxons/sevenwonders/server/api/Converters.kt index 12f346a2..5689247b 100644 --- a/sw-server/src/main/kotlin/org/luxons/sevenwonders/server/api/Converters.kt +++ b/sw-server/src/main/kotlin/org/luxons/sevenwonders/server/api/Converters.kt @@ -13,6 +13,7 @@ fun Lobby.toDTO(): LobbyDTO = LobbyDTO( players = getPlayers().zip(getAssignedWonders()).map { (p, w) -> p.toDTO(w) }, allWonders = allWonders, state = state, + settings = settings, hasEnoughPlayers = hasEnoughPlayers(), maxPlayersReached = maxPlayersReached(), ) 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 51e8ba4f..94ebceab 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 @@ -31,14 +31,20 @@ class GameController( @MessageMapping("/game/sayReady") fun ready(principal: Principal) { val player = principal.player - player.isReady = true + 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 - logger.info("Game {}: player {} is ready for the next turn", game.id, player) + player.isReady = true - synchronized(player.lobby) { - val players = player.lobby.getPlayers() + synchronized(lobby) { + val players = lobby.getPlayers() sendPlayerReady(game.id, player) + logger.info("Game {}: player {} is ready for the next turn", game.id, player) val allReady = players.all { it.isReady } if (allReady) { @@ -58,6 +64,7 @@ class GameController( @MessageMapping("/game/prepareMove") fun prepareMove(action: PrepareMoveAction, principal: Principal) { val player = principal.player + val lobby = player.lobby val game = player.game synchronized(game) { val preparedCardBack = game.prepareMove(player.index, action.move) @@ -68,7 +75,7 @@ class GameController( if (game.allPlayersPreparedTheirMove()) { logger.info("Game {}: all players have prepared their move, executing turn...", game.id) game.playTurn() - sendTurnInfo(player.lobby.getPlayers(), game, true) + sendTurnInfo(player.lobby.getPlayers(), game, hideHands = lobby.settings.askForReadiness) if (game.endOfGameReached()) { player.lobby.setEndOfGame() } 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 6cc404e9..f73d5481 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 @@ -156,12 +156,25 @@ class LobbyController( val game = lobby.startGame() logger.info("Game {} successfully started", game.id) - game.getCurrentTurnInfo().hideHandsAndWaitForReadiness().forEach { + 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() + + currentTurnInfo.forEach { val player = lobby.getPlayers()[it.playerIndex] template.convertAndSendToUser(player.username, "/queue/lobby/" + lobby.id + "/started", it) } } + private fun Lobby.initializePlayersReadyState() { + val players = getPlayers() + val initialReadyState = !settings.askForReadiness + players.forEach { it.isReady = initialReadyState } + } + companion object { private val logger = LoggerFactory.getLogger(LobbyController::class.java) } |