Fix race condition issue in move handling by first recording new game state before sending it to players

This commit is contained in:
Tissevert 2019-08-22 17:47:45 +02:00
parent bcaa606021
commit 539b74990e

View file

@ -67,12 +67,12 @@ receive (Session.Playing gameKey) played@(Message.Play {}) = do
case result of case result of
Left message -> sendError message Left message -> sendError message
Right newGame -> do Right newGame -> do
Messaging.notifyPlayers newGame logs
case KoiKoi.step newGame of case KoiKoi.step newGame of
KoiKoi.Over -> do KoiKoi.Over -> do
App.debug $ "Game " ++ show gameKey ++ " ended" App.debug $ "Game " ++ show gameKey ++ " ended"
App.update_ $ Server.endGame gameKey App.update_ $ Server.endGame gameKey
_ -> App.update_ $ Server.update gameKey (const newGame) _ -> App.update_ $ Server.update gameKey (const newGame)
Messaging.notifyPlayers newGame logs
receive (Session.Playing gameKey) Message.Quit = do receive (Session.Playing gameKey) Message.Quit = do
games <- (Data.get <$> App.server :: App.T (Map Game.Key Game.T)) games <- (Data.get <$> App.server :: App.T (Map Game.Key Game.T))