15 import Control.Monad.State.Strict |
15 import Control.Monad.State.Strict |
16 import qualified Data.ByteString.Char8 as B |
16 import qualified Data.ByteString.Char8 as B |
17 import Control.DeepSeq |
17 import Control.DeepSeq |
18 import Data.Unique |
18 import Data.Unique |
19 import Control.Arrow |
19 import Control.Arrow |
20 import Control.Exception |
20 import Control.Exception as E |
21 import System.Process |
21 import System.Process |
22 import Network.Socket |
22 import Network.Socket |
23 import System.Random |
23 import System.Random |
24 ----------------------------- |
24 ----------------------------- |
25 #if defined(OFFICIAL_SERVER) |
25 #if defined(OFFICIAL_SERVER) |
712 processAction (CheckSuccess _) = return () |
712 processAction (CheckSuccess _) = return () |
713 processAction (QueryReplay _) = return () |
713 processAction (QueryReplay _) = return () |
714 #endif |
714 #endif |
715 |
715 |
716 processAction (ShowReplay name) = do |
716 processAction (ShowReplay name) = do |
717 return () |
717 c <- client's sendChan |
718 |
718 cl <- client's id |
|
719 |
|
720 let fileName = B.concat ["checked/", if B.isPrefixOf "replays/" name then B.drop 8 name else name] |
|
721 |
|
722 checkInfo <- liftIO $ E.handle (\(e :: SomeException) -> |
|
723 warningM "REPLAYS" (B.unpack $ B.concat ["Problems reading ", fileName, ": ", B.pack $ show e]) >> return Nothing) $ do |
|
724 (t, p1, p2, msgs) <- liftM read $ readFile (B.unpack fileName) |
|
725 return $ Just (t, Map.fromList p1, Map.fromList p2, reverse msgs) |
|
726 |
|
727 let (teams, params1, params2, roundMsgs) = fromJust checkInfo |
|
728 |
|
729 when (isJust checkInfo) $ do |
|
730 mapM_ processAction $ concat [ |
|
731 [AnswerClients [c] ["JOINED", nick cl]] |
|
732 , answerFullConfigParams cl params1 params2 |
|
733 , answerAllTeams cl teams |
|
734 , [AnswerClients [c] ["RUN_GAME"]] |
|
735 , [AnswerClients [c] $ "EM" : roundMsgs] |
|
736 , [AnswerClients [c] ["KICKED"]] |
|
737 ] |