gameServer/OfficialServer/checker.hs
changeset 9399 1767c92eff37
parent 9397 7b7ee65f82ad
child 9403 9f6ca48d8e9c
equal deleted inserted replaced
9397:7b7ee65f82ad 9399:1767c92eff37
    30     deriving Show
    30     deriving Show
    31 
    31 
    32 serverAddress = "netserver.hedgewars.org"
    32 serverAddress = "netserver.hedgewars.org"
    33 protocolNumber = "45"
    33 protocolNumber = "45"
    34 
    34 
    35 getLines :: Handle -> IO [String]
    35 getLines :: Handle -> IO [B.ByteString]
    36 getLines h = g
    36 getLines h = g
    37     where
    37     where
    38         g = do
    38         g = do
    39             l <- liftM Just (hGetLine h) `Exception.catch` (\(_ :: Exception.IOException) -> return Nothing)
    39             l <- liftM Just (B.hGetLine h) `Exception.catch` (\(_ :: Exception.IOException) -> return Nothing)
    40             if isNothing l then
    40             if isNothing l then
    41                 return []
    41                 return []
    42                 else
    42                 else
    43                 do
    43                 do
    44                 lst <- g
    44                 lst <- g
    45                 return $ fromJust l : lst
    45                 return $ fromJust l : lst
    46 
    46 
    47 
    47 
    48 engineListener :: Chan Message -> Handle -> String -> IO ()
    48 engineListener :: Chan Message -> Handle -> String -> IO ()
    49 engineListener coreChan h fileName = do
    49 engineListener coreChan h fileName = do
    50     output <- getLines h
    50     stats <- liftM (L.dropWhile start) $ getLines h
    51     debugM "Engine" $ show output
    51     debugM "Engine" $ show stats
    52     if isNothing $ L.find start output then
    52     if null stats then
    53         writeChan coreChan $ CheckFailed "No stats msg"
    53         writeChan coreChan $ CheckFailed "No stats msg"
    54         else
    54         else
    55         writeChan coreChan $ CheckSuccess []
    55         writeChan coreChan $ CheckSuccess stats
    56 
    56 
    57     removeFile fileName
    57     removeFile fileName
    58     where
    58     where
    59         start = flip L.elem ["WINNERS", "DRAW"]
    59         start = flip L.elem ["WINNERS", "DRAW"]
    60 
    60