Hack checker to run engine with record file received (uses hardcoded paths)
authorunc0rr
Mon, 11 Feb 2013 00:19:15 +0400
changeset 8497 c5605c6f5bb3
parent 8496 a06b1598c3a2
child 8498 eecadca7db50
Hack checker to run engine with record file received (uses hardcoded paths)
gameServer/OfficialServer/checker.hs
--- 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 ()