gameServer/OfficialServer/GameReplayStore.hs
changeset 8482 5656a73fe3c3
parent 8479 8d71109b04d2
child 8495 f1223400b473
--- a/gameServer/OfficialServer/GameReplayStore.hs	Fri Feb 08 00:27:07 2013 +0400
+++ b/gameServer/OfficialServer/GameReplayStore.hs	Fri Feb 08 23:38:14 2013 +0400
@@ -10,6 +10,8 @@
 import Data.Unique
 import Control.Monad
 import Data.List
+import qualified Data.ByteString as B
+import System.Directory
 ---------------
 import CoreTypes
 import EngineInteraction
@@ -29,13 +31,14 @@
 
 
 loadReplay :: Int -> IO [B.ByteString]
-loadReplay p = E.handle (\(e :: SomeException) -> warningM "REPLAYS" $ "Problems reading replay") $ do
-    files <- liftM (isSuffixOf ('.' : show p)) getDirectoryContents
+loadReplay p = E.handle (\(e :: SomeException) -> warningM "REPLAYS" "Problems reading replay" >> return []) $ do
+    files <- liftM (filter (isSuffixOf ('.' : show p))) $ getDirectoryContents "replays"
     if (not $ null files) then
         loadFile $ head files
         else
         return []
     where
-        loadFile fileName = E.handle (\(e :: SomeException) -> warningM "REPLAYS" $ "Problems reading " ++ fileName) $ do
+        loadFile :: String -> IO [B.ByteString]
+        loadFile fileName = E.handle (\(e :: SomeException) -> warningM "REPLAYS" ("Problems reading " ++ fileName) >> return []) $ do
             (teams, params1, params2, roundMsgs) <- liftM read $ readFile fileName
             return $ replayToDemo teams (Map.fromList params1) (Map.fromList params2) roundMsgs