gameServer/OfficialServer/checker.hs
changeset 8497 c5605c6f5bb3
parent 8479 8d71109b04d2
child 8506 3889dab021b8
--- a/gameServer/OfficialServer/checker.hs	Mon Feb 11 00:14:05 2013 +0400
+++ b/gameServer/OfficialServer/checker.hs	Mon Feb 11 00:19:15 2013 +0400
@@ -15,6 +15,10 @@
 import Network.Socket hiding (recv)
 import Network.Socket.ByteString
 import qualified Data.ByteString.Char8 as B
+import qualified Data.ByteString as BW
+import qualified Codec.Binary.Base64 as Base64
+import System.Process
+import Data.Maybe
 #if !defined(mingw32_HOST_OS)
 import System.Posix
 #endif
@@ -24,6 +28,22 @@
 
 protocolNumber = "43"
 
+checkReplay :: [B.ByteString] -> IO ()
+checkReplay msgs = do
+    tempDir <- getTemporaryDirectory
+    (fileName, h) <- openBinaryTempFile tempDir "checker-demo"
+    B.hPut h . BW.pack . concat . map (fromJust . Base64.decode . B.unpack) $ msgs
+    hFlush h
+    hClose h
+
+    (_, _, Just hErr, _) <- createProcess (proc "/usr/home/unC0Rr/Sources/Hedgewars/Releases/0.9.18/bin/hwengine"
+                ["/usr/home/unC0Rr/.hedgewars"
+                , "/usr/home/unC0Rr/Sources/Hedgewars/Releases/0.9.18/share/hedgewars/Data"
+                , fileName])
+            {std_err = CreatePipe}
+    hSetBuffering hErr LineBuffering
+
+
 takePacks :: State B.ByteString [[B.ByteString]]
 takePacks = do
     modify (until (not . B.isPrefixOf pDelim) (B.drop 2))
@@ -76,6 +96,7 @@
         answer ["CHECKER", protocolNumber, l, p]
         answer ["READY"]
     onPacket ["PING"] = answer ["PONG"]
+    onPacket ("REPLAY":msgs) = checkReplay msgs
     onPacket ("BYE" : xs) = error $ show xs
     onPacket _ = return ()