equal
deleted
inserted
replaced
15 --------------- |
15 --------------- |
16 import CoreTypes |
16 import CoreTypes |
17 import EngineInteraction |
17 import EngineInteraction |
18 |
18 |
19 |
19 |
20 pickReplayFile :: Int -> IO String |
20 pickReplayFile :: Int -> [String] -> IO String |
21 pickReplayFile p = do |
21 pickReplayFile p blackList = do |
22 files <- liftM (filter (isSuffixOf ('.' : show p))) $ getDirectoryContents "replays" |
22 files <- liftM (filter (\f -> sameProto f && notBlacklisted f)) $ getDirectoryContents "replays" |
23 if (not $ null files) then |
23 if (not $ null files) then |
24 return $ "replays/" ++ head files |
24 return $ "replays/" ++ head files |
25 else |
25 else |
26 return "" |
26 return "" |
|
27 where |
|
28 sameProto = (isSuffixOf ('.' : show p)) |
|
29 notBlacklisted = flip notElem blackList |
27 |
30 |
28 saveReplay :: RoomInfo -> IO () |
31 saveReplay :: RoomInfo -> IO () |
29 saveReplay r = do |
32 saveReplay r = do |
30 let gi = fromJust $ gameInfo r |
33 let gi = fromJust $ gameInfo r |
31 when (allPlayersHaveRegisteredAccounts gi) $ do |
34 when (allPlayersHaveRegisteredAccounts gi) $ do |
36 E.catch |
39 E.catch |
37 (writeFile fileName (show replayInfo)) |
40 (writeFile fileName (show replayInfo)) |
38 (\(e :: IOException) -> warningM "REPLAYS" $ "Couldn't write to " ++ fileName ++ ": " ++ show e) |
41 (\(e :: IOException) -> warningM "REPLAYS" $ "Couldn't write to " ++ fileName ++ ": " ++ show e) |
39 |
42 |
40 |
43 |
41 loadReplay :: Int -> IO (Maybe CheckInfo, [B.ByteString]) |
44 loadReplay :: Int -> [String] -> IO (Maybe CheckInfo, [B.ByteString]) |
42 loadReplay p = E.handle (\(e :: SomeException) -> warningM "REPLAYS" "Problems reading replay" >> return (Nothing, [])) $ do |
45 loadReplay p blackList = E.handle (\(e :: SomeException) -> warningM "REPLAYS" "Problems reading replay" >> return (Nothing, [])) $ do |
43 fileName <- pickReplayFile p |
46 fileName <- pickReplayFile p blackList |
44 if (not $ null fileName) then |
47 if (not $ null fileName) then |
45 loadFile fileName |
48 loadFile fileName |
46 else |
49 else |
47 return (Nothing, []) |
50 return (Nothing, []) |
48 where |
51 where |