author | unc0rr |
Tue, 22 Jan 2013 00:33:37 +0400 | |
changeset 8423 | 8aa450f6cf2c |
parent 8371 | 0551b5c3de9a |
child 8479 | 8d71109b04d2 |
permissions | -rw-r--r-- |
5143
649d87819682
Start implementation of archivements/ratings on server side: replay saving routine
unc0rr
parents:
diff
changeset
|
1 |
{-# LANGUAGE ScopedTypeVariables #-} |
649d87819682
Start implementation of archivements/ratings on server side: replay saving routine
unc0rr
parents:
diff
changeset
|
2 |
module OfficialServer.GameReplayStore where |
649d87819682
Start implementation of archivements/ratings on server side: replay saving routine
unc0rr
parents:
diff
changeset
|
3 |
|
649d87819682
Start implementation of archivements/ratings on server side: replay saving routine
unc0rr
parents:
diff
changeset
|
4 |
import Data.Time |
649d87819682
Start implementation of archivements/ratings on server side: replay saving routine
unc0rr
parents:
diff
changeset
|
5 |
import Control.Exception as E |
649d87819682
Start implementation of archivements/ratings on server side: replay saving routine
unc0rr
parents:
diff
changeset
|
6 |
import qualified Data.Map as Map |
649d87819682
Start implementation of archivements/ratings on server side: replay saving routine
unc0rr
parents:
diff
changeset
|
7 |
import Data.Sequence() |
649d87819682
Start implementation of archivements/ratings on server side: replay saving routine
unc0rr
parents:
diff
changeset
|
8 |
import System.Log.Logger |
5996
2c72fe81dd37
Convert boolean variable + a bunch of fields which make sense only while game is going on into Maybe + structure
unc0rr
parents:
5143
diff
changeset
|
9 |
import Data.Maybe |
6040 | 10 |
import Data.Unique |
11 |
import Control.Monad |
|
12 |
--------------- |
|
13 |
import CoreTypes |
|
14 |
||
5143
649d87819682
Start implementation of archivements/ratings on server side: replay saving routine
unc0rr
parents:
diff
changeset
|
15 |
|
649d87819682
Start implementation of archivements/ratings on server side: replay saving routine
unc0rr
parents:
diff
changeset
|
16 |
saveReplay :: RoomInfo -> IO () |
8423 | 17 |
saveReplay r = do |
5996
2c72fe81dd37
Convert boolean variable + a bunch of fields which make sense only while game is going on into Maybe + structure
unc0rr
parents:
5143
diff
changeset
|
18 |
let gi = fromJust $ gameInfo r |
8423 | 19 |
when (allPlayersHaveRegisteredAccounts gi) $ do |
20 |
time <- getCurrentTime |
|
21 |
u <- liftM hashUnique newUnique |
|
22 |
let fileName = "replays/" ++ show time ++ "-" ++ show u |
|
23 |
let replayInfo = (teamsAtStart gi, Map.toList $ mapParams r, Map.toList $ params r, roundMsgs gi) |
|
24 |
E.catch |
|
25 |
(writeFile fileName (show replayInfo)) |
|
26 |
(\(e :: IOException) -> warningM "REPLAYS" $ "Couldn't write to " ++ fileName ++ ": " ++ show e) |