diff options
author | Joffrey Bion <joffrey.bion@booking.com> | 2020-07-01 16:54:49 +0200 |
---|---|---|
committer | Joffrey Bion <joffrey.bion@booking.com> | 2020-07-01 16:54:49 +0200 |
commit | 5f9ce441d2a75040165fb3c6f828558a852b7fd4 (patch) | |
tree | 9ce9f5ac9b8fbafc6d5e45e59a35658238bcd20c /sw-server/src/main | |
parent | Fix race conditions (diff) | |
download | seven-wonders-5f9ce441d2a75040165fb3c6f828558a852b7fd4.tar.gz seven-wonders-5f9ce441d2a75040165fb3c6f828558a852b7fd4.tar.bz2 seven-wonders-5f9ce441d2a75040165fb3c6f828558a852b7fd4.zip |
Better synchronization on lobby join
Diffstat (limited to 'sw-server/src/main')
-rw-r--r-- | sw-server/src/main/kotlin/org/luxons/sevenwonders/server/controllers/GameBrowserController.kt | 11 | ||||
-rw-r--r-- | sw-server/src/main/kotlin/org/luxons/sevenwonders/server/lobby/Lobby.kt | 1 |
2 files changed, 6 insertions, 6 deletions
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() |