Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🔧 Do not accept participant input when round is not in progress #43

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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