summaryrefslogtreecommitdiffhomepage
path: root/Replay.hs
blob: b50bc401bc8bb195822e30108530967cd636dabd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
module Replay where

import Types
import Log
import CmdLine
import Session

import qualified Data.ByteString as B
import System.IO
import Control.Concurrent.Thread.Delay

replay :: ReplayOpts -> IO ()
replay opts = go Nothing =<< loadLog (replayLogFile opts)
  where
	go _ [] = sessionDone
	go prevts (l:ls) = do
		case prevts of
			Nothing -> return ()
			Just t ->
				let s = loggedTimestamp l - t
				    ms = s * 1000000
				in delay (ceiling ms)

		case loggedActivity l of
			ActivityEntered {} -> return ()
			ActivitySeen a -> case activity a of
				Rejected {} -> return ()
				Proto s -> do
					B.hPut stdout (val (seenData s))
					hFlush stdout
		go (Just $ loggedTimestamp l) ls