gameServer/OfficialServer/GameReplayStore.hs
changeset 6040 a740069c21e3
parent 5996 2c72fe81dd37
child 8371 0551b5c3de9a
equal deleted inserted replaced
6038:58d9badf3e7f 6040:a740069c21e3
     1 {-# LANGUAGE ScopedTypeVariables #-}
     1 {-# LANGUAGE ScopedTypeVariables #-}
     2 module OfficialServer.GameReplayStore where
     2 module OfficialServer.GameReplayStore where
     3 
     3 
     4 import CoreTypes
       
     5 import Data.Time
     4 import Data.Time
     6 import Control.Exception as E
     5 import Control.Exception as E
     7 import qualified Data.Map as Map
     6 import qualified Data.Map as Map
     8 import Data.Sequence()
     7 import Data.Sequence()
     9 import System.Log.Logger
     8 import System.Log.Logger
    10 import Data.Maybe
     9 import Data.Maybe
       
    10 import Data.Unique
       
    11 import Control.Monad
       
    12 ---------------
       
    13 import CoreTypes
       
    14 
    11 
    15 
    12 saveReplay :: RoomInfo -> IO ()
    16 saveReplay :: RoomInfo -> IO ()
    13 saveReplay r = do
    17 saveReplay r = do
    14     time <- getCurrentTime
    18     time <- getCurrentTime
    15     let fileName = "replays/" ++ show time
    19     u <- liftM hashUnique newUnique
       
    20     let fileName = "replays/" ++ show time ++ "-" ++ show u
    16     let gi = fromJust $ gameInfo r
    21     let gi = fromJust $ gameInfo r
    17     let replayInfo = (teamsAtStart gi, Map.toList $ mapParams r, Map.toList $ params r, roundMsgs gi)
    22     let replayInfo = (teamsAtStart gi, Map.toList $ mapParams r, Map.toList $ params r, roundMsgs gi)
    18     E.catch
    23     E.catch
    19         (writeFile fileName (show replayInfo))
    24         (writeFile fileName (show replayInfo))
    20         (\(e :: IOException) -> warningM "REPLAYS" $ "Couldn't write to " ++ fileName ++ ": " ++ show e)
    25         (\(e :: IOException) -> warningM "REPLAYS" $ "Couldn't write to " ++ fileName ++ ": " ++ show e)