# HG changeset patch
# User unc0rr
# Date 1383247666 -14400
# Node ID 47dbd960134284657b9f251284af3a0fd50c3f0f
# Parent  788fd9eedfb077e73f027f82dc3184c31c58818e
Ensure checkers don't check same replay simultaneously

diff -r 788fd9eedfb0 -r 47dbd9601342 gameServer/Actions.hs
--- a/gameServer/Actions.hs	Thu Oct 31 23:27:06 2013 +0400
+++ b/gameServer/Actions.hs	Thu Oct 31 23:27:46 2013 +0400
@@ -684,7 +684,16 @@
 processAction CheckRecord = do
     p <- client's clientProto
     c <- client's sendChan
-    (cinfo, l) <- io $ loadReplay (fromIntegral p)
+    ri <- clientRoomA
+    rnc <- gets roomsClients
+
+    blackList <- liftM (map (recordFileName . fromJust . checkInfo) . filter (isJust . checkInfo)) allClientsS
+
+    readyCheckersIds <- io $ do
+        allci <- allClientsM rnc
+        filterM (client'sM rnc (isJust . checkInfo)) allci
+
+    (cinfo, l) <- io $ loadReplay (fromIntegral p) blackList
     when (not . null $ l) $
         mapM_ processAction [
             AnswerClients [c] ("REPLAY" : l)
diff -r 788fd9eedfb0 -r 47dbd9601342 gameServer/OfficialServer/GameReplayStore.hs
--- a/gameServer/OfficialServer/GameReplayStore.hs	Thu Oct 31 23:27:06 2013 +0400
+++ b/gameServer/OfficialServer/GameReplayStore.hs	Thu Oct 31 23:27:46 2013 +0400
@@ -17,13 +17,16 @@
 import EngineInteraction
 
 
-pickReplayFile :: Int -> IO String
-pickReplayFile p = do
-    files <- liftM (filter (isSuffixOf ('.' : show p))) $ getDirectoryContents "replays"
+pickReplayFile :: Int -> [String] -> IO String
+pickReplayFile p blackList = do
+    files <- liftM (filter (\f -> sameProto f && notBlacklisted f)) $ getDirectoryContents "replays"
     if (not $ null files) then
         return $ "replays/" ++ head files
         else
         return ""
+    where
+        sameProto = (isSuffixOf ('.' : show p))
+        notBlacklisted = flip notElem blackList
 
 saveReplay :: RoomInfo -> IO ()
 saveReplay r = do
@@ -38,9 +41,9 @@
             (\(e :: IOException) -> warningM "REPLAYS" $ "Couldn't write to " ++ fileName ++ ": " ++ show e)
 
 
-loadReplay :: Int -> IO (Maybe CheckInfo, [B.ByteString])
-loadReplay p = E.handle (\(e :: SomeException) -> warningM "REPLAYS" "Problems reading replay" >> return (Nothing, [])) $ do
-    fileName <- pickReplayFile p
+loadReplay :: Int -> [String] -> IO (Maybe CheckInfo, [B.ByteString])
+loadReplay p blackList = E.handle (\(e :: SomeException) -> warningM "REPLAYS" "Problems reading replay" >> return (Nothing, [])) $ do
+    fileName <- pickReplayFile p blackList
     if (not $ null fileName) then
         loadFile fileName
         else