Skip to content

Commit

Permalink
Merge pull request #43 from 21-23/fix/participant-input-when-round-is…
Browse files Browse the repository at this point in the history
…-not-in-progress

🔧 Do not accept participant input when round is not in progress
  • Loading branch information
DaQuirm authored Dec 5, 2017
2 parents 1fd176c + 242ab51 commit 4bb2a3a
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions app/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
module Main where

import Control.Concurrent
import Control.Monad (forever, unless)
import Control.Monad (forever, unless, when)
import Control.Monad.IO.Class (MonadIO)
import Control.Monad.Trans.Control (MonadBaseControl)
import Network (PortID(PortNumber))
Expand Down Expand Up @@ -33,7 +33,7 @@ import qualified State
import Message
import Identity
import Envelope
import Session (EntityField(..), Session, SessionId)
import Session (EntityField(..), Session(Session, roundPhase), SessionId)
import qualified Session
import Puzzle (EntityField(PuzzleId), options)
import PuzzleOptions (timeLimit)
Expand Down Expand Up @@ -270,14 +270,16 @@ app config stateVar pool connection = do
ParticipantInput sessionId participantId input timestamp -> do
state <- readMVar stateVar
case State.getSession sessionId state of
Just _ ->
unless (State.hasCorrectSolution sessionId participantId state) $ do
Just Session {roundPhase} ->
when (roundPhase == InProgress) $
unless (State.hasCorrectSolution sessionId participantId state) $ do
-- this update is not synced with the database, participant input is considered perishable
updateState stateVar $ State.setParticipantInput sessionId participantId input
transaction <- State.createSandboxTransaction sessionId participantId input timestamp
-- this update is not synced with the database because of possible performance implications
updateState stateVar $ State.addSandboxTransaction transaction
sendMessage connection SandboxService $ EvaluateSolution (taskId transaction) input

Nothing -> putStrLn $ "Session not found: " ++ show sessionId

EvaluatedSolution taskId result correctness -> do
Expand Down

0 comments on commit 4bb2a3a

Please sign in to comment.