From 8c15e4c7e3a41caef24e93885f1600903f358078 Mon Sep 17 00:00:00 2001 From: Joffrey Bion Date: Sat, 23 May 2020 02:03:55 +0200 Subject: Add "leave game" feature for end of game --- .../luxons/sevenwonders/server/controllers/GameController.kt | 11 +++++++++++ .../main/kotlin/org/luxons/sevenwonders/server/lobby/Lobby.kt | 4 ++++ 2 files changed, 15 insertions(+) (limited to 'sw-server/src') 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 32359d58..be5d916b 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 @@ -76,6 +76,9 @@ class GameController @Autowired constructor( logger.info("Game {}: all players have prepared their move, executing turn...", game.id) game.playTurn() sendTurnInfo(player.lobby.getPlayers(), game, true) + if (game.endOfGameReached()) { + player.lobby.setEndOfGame() + } } return action.move } @@ -105,6 +108,14 @@ class GameController @Autowired constructor( } } + @MessageMapping("/game/leave") + fun leave(principal: Principal) { + val player = principal.player + val game = player.game + player.leave() + logger.info("Game {}: player {} left the game", game.id, principal.name) + } + companion object { private val logger = LoggerFactory.getLogger(GameController::class.java) } diff --git a/sw-server/src/main/kotlin/org/luxons/sevenwonders/server/lobby/Lobby.kt b/sw-server/src/main/kotlin/org/luxons/sevenwonders/server/lobby/Lobby.kt index eadc1742..24bf5066 100644 --- a/sw-server/src/main/kotlin/org/luxons/sevenwonders/server/lobby/Lobby.kt +++ b/sw-server/src/main/kotlin/org/luxons/sevenwonders/server/lobby/Lobby.kt @@ -88,6 +88,10 @@ class Lobby( return player } + fun setEndOfGame() { + state = State.FINISHED + } + internal class GameAlreadyStartedException(name: String) : IllegalStateException("Game '$name' has already started") -- cgit