diff options
author | Joffrey Bion <joffrey.bion@booking.com> | 2020-05-23 02:03:55 +0200 |
---|---|---|
committer | Joffrey Bion <joffrey.bion@booking.com> | 2020-05-23 02:03:55 +0200 |
commit | 8c15e4c7e3a41caef24e93885f1600903f358078 (patch) | |
tree | 0977b65a606097482ae917466d184d288d24cf11 /sw-server | |
parent | Add score board UI at end of game (diff) | |
download | seven-wonders-8c15e4c7e3a41caef24e93885f1600903f358078.tar.gz seven-wonders-8c15e4c7e3a41caef24e93885f1600903f358078.tar.bz2 seven-wonders-8c15e4c7e3a41caef24e93885f1600903f358078.zip |
Add "leave game" feature for end of game
Diffstat (limited to 'sw-server')
-rw-r--r-- | sw-server/src/main/kotlin/org/luxons/sevenwonders/server/controllers/GameController.kt | 11 | ||||
-rw-r--r-- | sw-server/src/main/kotlin/org/luxons/sevenwonders/server/lobby/Lobby.kt | 4 |
2 files changed, 15 insertions, 0 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 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") |