From 5f9ce441d2a75040165fb3c6f828558a852b7fd4 Mon Sep 17 00:00:00 2001 From: Joffrey Bion Date: Wed, 1 Jul 2020 16:54:49 +0200 Subject: Better synchronization on lobby join --- .../sevenwonders/server/controllers/GameBrowserController.kt | 11 ++++++----- .../main/kotlin/org/luxons/sevenwonders/server/lobby/Lobby.kt | 1 - 2 files changed, 6 insertions(+), 6 deletions(-) (limited to 'sw-server/src/main/kotlin/org/luxons') diff --git a/sw-server/src/main/kotlin/org/luxons/sevenwonders/server/controllers/GameBrowserController.kt b/sw-server/src/main/kotlin/org/luxons/sevenwonders/server/controllers/GameBrowserController.kt index a0928b45..c3dcf87c 100644 --- a/sw-server/src/main/kotlin/org/luxons/sevenwonders/server/controllers/GameBrowserController.kt +++ b/sw-server/src/main/kotlin/org/luxons/sevenwonders/server/controllers/GameBrowserController.kt @@ -82,12 +82,13 @@ class GameBrowserController( val lobby = lobbyRepository.find(action.gameId) val player = playerRepository.find(principal.name) - lobby.addPlayer(player) + synchronized(lobby) { + lobby.addPlayer(player) - logger.info("Player '{}' ({}) joined game {}", player.displayName, player.username, lobby.name) - val lobbyDTO = lobby.toDTO() - lobbyController.sendLobbyUpdateToPlayers(lobby) - return lobbyDTO + logger.info("Player '{}' ({}) joined game {}", player.displayName, player.username, lobby.name) + lobbyController.sendLobbyUpdateToPlayers(lobby) + } + return lobby.toDTO() } private fun checkThatUserIsNotInAGame(principal: Principal, impossibleActionDescription: String) { 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 dd2b6561..2962e5df 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 @@ -49,7 +49,6 @@ class Lobby( assignedWonders.add(pickRandomWonder()) } - @Synchronized private fun pickRandomWonder(): AssignedWonder = allWonders.filter { !it.isAssigned() }.random().withRandomSide() -- cgit