gameServer/ClientIO.hs
changeset 3673 45778b16b224
parent 3671 a94d1dc4a8d9
child 3947 709fdb89f76c
equal deleted inserted replaced
3671:a94d1dc4a8d9 3673:45778b16b224
    58 
    58 
    59 
    59 
    60 clientSendLoop :: Socket -> Chan CoreMessage -> Chan [B.ByteString] -> ClientIndex -> IO()
    60 clientSendLoop :: Socket -> Chan CoreMessage -> Chan [B.ByteString] -> ClientIndex -> IO()
    61 clientSendLoop s coreChan chan ci = do
    61 clientSendLoop s coreChan chan ci = do
    62     answer <- readChan chan
    62     answer <- readChan chan
    63     doClose <- Exception.handle
    63     Exception.handle
    64         (\(e :: Exception.IOException) -> if isQuit answer then return True else sendQuit e >> return True) $ do
    64         (\(e :: Exception.IOException) -> when (not $ isQuit answer) $ sendQuit e) $ do
    65             sendAll s $ (B.unlines answer) `B.append` (B.singleton '\n')
    65             sendAll s $ (B.unlines answer) `B.append` (B.singleton '\n')
    66             return $ isQuit answer
       
    67 
    66 
    68     if doClose then
    67     if (isQuit answer) then
    69         Exception.handle (\(_ :: Exception.IOException) -> putStrLn "error on sClose") $ sClose s
    68         Exception.handle (\(_ :: Exception.IOException) -> putStrLn "error on sClose") $ sClose s
    70         else
    69         else
    71         clientSendLoop s coreChan chan ci
    70         clientSendLoop s coreChan chan ci
    72 
    71 
    73     where
    72     where
    74         sendQuit e = writeChan coreChan $ ClientMessage (ci, ["QUIT", B.pack $ show e])
    73         --sendQuit e = writeChan coreChan $ ClientMessage (ci, ["QUIT", B.pack $ show e])
       
    74         sendQuit e = putStrLn $ show e
    75         isQuit ("BYE":xs) = True
    75         isQuit ("BYE":xs) = True
    76         isQuit _ = False
    76         isQuit _ = False