wizard-wipeout/src-client/Main.hs

52 lines
1.2 KiB
Haskell

{-# LANGUAGE LambdaCase #-}
module Main where
import Control.Concurrent (threadDelay)
import Data.Aeson as A
import qualified Data.ByteString.Lazy.Char8 as B8
import Options.Applicative
import System.IO
-- internal imports
import Client.Communication
import Client.Types
import Library.Types
main :: IO ()
main = do
putStrLn "Hello, Arena!"
(Options socketLocation) <- execParser opts
putStrLn $ "connecting to Socket " <> socketLocation
handle <- connectSocket socketLocation
message <- hGetContents handle
let mJsonMessage = decode' $ B8.pack message :: Maybe ServerMessage
errMsg = (error $ "unexpected message from Server: " <> message)
uuid = maybe
errMsg
(\case
(AcceptClient uuid) -> uuid
_ -> errMsg
)
mJsonMessage
-- reader = ReaderContainer handle uuid
putStrLn $ "received uuid " <> show uuid
-- mock communication code
hPutStrLn handle "meow!"
hFlush handle
threadDelay $ 5 * 10 ^ 6
hPutStrLn handle "Goodbye!"
hFlush handle
threadDelay $ 5 * 10 ^ 6
-- end mock
where
opts = info (options <**> helper)
( fullDesc
<> progDesc "Run the \"wizard-wipeout\" Server."
<> header "wizard-wipeout - Last Mage standing"
)