--- a/gameServer/OfficialServer/GameReplayStore.hs Sat Feb 02 22:57:05 2013 +0400
+++ b/gameServer/OfficialServer/GameReplayStore.hs Mon Feb 04 00:13:55 2013 +0400
@@ -9,8 +9,10 @@
import Data.Maybe
import Data.Unique
import Control.Monad
+import Data.List
---------------
import CoreTypes
+import EngineInteraction
saveReplay :: RoomInfo -> IO ()
@@ -19,8 +21,21 @@
when (allPlayersHaveRegisteredAccounts gi) $ do
time <- getCurrentTime
u <- liftM hashUnique newUnique
- let fileName = "replays/" ++ show time ++ "-" ++ show u
+ let fileName = "replays/" ++ show time ++ "-" ++ show u ++ "." ++ show (roomProto r)
let replayInfo = (teamsAtStart gi, Map.toList $ mapParams r, Map.toList $ params r, roundMsgs gi)
E.catch
(writeFile fileName (show replayInfo))
(\(e :: IOException) -> warningM "REPLAYS" $ "Couldn't write to " ++ fileName ++ ": " ++ show e)
+
+
+loadReplay :: Int -> IO [B.ByteString]
+loadReplay p = E.handle (\(e :: SomeException) -> warningM "REPLAYS" $ "Problems reading replay") $ do
+ files <- liftM (isSuffixOf ('.' : show p)) getDirectoryContents
+ if (not $ null files) then
+ loadFile $ head files
+ else
+ return []
+ where
+ loadFile fileName = E.handle (\(e :: SomeException) -> warningM "REPLAYS" $ "Problems reading " ++ fileName) $ do
+ (teams, params1, params2, roundMsgs) <- liftM read $ readFile fileName
+ return $ replayToDemo teams (Map.fromList params1) (Map.fromList params2) roundMsgs