~ubuntu-branches/ubuntu/utopic/hedgewars/utopic

« back to all changes in this revision

Viewing changes to gameServer/OfficialServer/GameReplayStore.hs

  • Committer: Package Import Robot
  • Author(s): Gianfranco Costamagna
  • Date: 2014-01-02 12:37:23 UTC
  • mfrom: (19.1.5 sid)
  • Revision ID: package-import@ubuntu.com-20140102123723-6pdhmyj8tb5y8xbg
Tags: 0.9.20.3-1
New upstream minor release, suitable for unstable

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
import EngineInteraction
18
18
 
19
19
 
20
 
pickReplayFile :: Int -> IO String
21
 
pickReplayFile p = do
22
 
    files <- liftM (filter (isSuffixOf ('.' : show p))) $ getDirectoryContents "replays"
 
20
pickReplayFile :: Int -> [String] -> IO String
 
21
pickReplayFile p blackList = do
 
22
    files <- liftM (filter (\f -> sameProto f && notBlacklisted f)) $ getDirectoryContents "replays"
23
23
    if (not $ null files) then
24
24
        return $ "replays/" ++ head files
25
25
        else
26
26
        return ""
 
27
    where
 
28
        sameProto = (isSuffixOf ('.' : show p))
 
29
        notBlacklisted = flip notElem blackList
27
30
 
28
31
saveReplay :: RoomInfo -> IO ()
29
32
saveReplay r = do
38
41
            (\(e :: IOException) -> warningM "REPLAYS" $ "Couldn't write to " ++ fileName ++ ": " ++ show e)
39
42
 
40
43
 
41
 
loadReplay :: Int -> IO (Maybe CheckInfo, [B.ByteString])
42
 
loadReplay p = E.handle (\(e :: SomeException) -> warningM "REPLAYS" "Problems reading replay" >> return (Nothing, [])) $ do
43
 
    fileName <- pickReplayFile p
 
44
loadReplay :: Int -> [String] -> IO (Maybe CheckInfo, [B.ByteString])
 
45
loadReplay p blackList = E.handle (\(e :: SomeException) -> warningM "REPLAYS" "Problems reading replay" >> return (Nothing, [])) $ do
 
46
    fileName <- pickReplayFile p blackList
44
47
    if (not $ null fileName) then
45
48
        loadFile fileName
46
49
        else