2023-12-10 16:00:50 +00:00
|
|
|
{-# LANGUAGE LambdaCase #-}
|
2023-12-04 16:20:06 +00:00
|
|
|
module Main where
|
|
|
|
|
2023-12-10 11:44:23 +00:00
|
|
|
import Control.Concurrent (threadDelay)
|
|
|
|
|
2023-12-10 16:00:50 +00:00
|
|
|
import Data.Aeson as A
|
|
|
|
|
|
|
|
import qualified Data.ByteString.Lazy.Char8 as B8
|
|
|
|
|
2023-12-10 11:44:23 +00:00
|
|
|
import Options.Applicative
|
|
|
|
|
|
|
|
import System.IO
|
|
|
|
|
|
|
|
-- internal imports
|
|
|
|
|
|
|
|
import Client.Communication
|
|
|
|
import Client.Types
|
|
|
|
|
2023-12-10 16:00:50 +00:00
|
|
|
import Library.Types
|
|
|
|
|
2023-12-04 16:20:06 +00:00
|
|
|
main :: IO ()
|
2023-12-10 11:44:23 +00:00
|
|
|
main = do
|
|
|
|
putStrLn "Hello, Arena!"
|
|
|
|
(Options socketLocation) <- execParser opts
|
|
|
|
putStrLn $ "connecting to Socket " <> socketLocation
|
|
|
|
handle <- connectSocket socketLocation
|
2023-12-10 16:00:50 +00:00
|
|
|
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
|
2023-12-10 11:57:36 +00:00
|
|
|
-- mock communication code
|
2023-12-10 11:44:23 +00:00
|
|
|
hPutStrLn handle "meow!"
|
|
|
|
hFlush handle
|
|
|
|
threadDelay $ 5 * 10 ^ 6
|
|
|
|
hPutStrLn handle "Goodbye!"
|
|
|
|
hFlush handle
|
2023-12-10 16:00:50 +00:00
|
|
|
threadDelay $ 5 * 10 ^ 6
|
2023-12-10 11:57:36 +00:00
|
|
|
-- end mock
|
2023-12-10 11:44:23 +00:00
|
|
|
where
|
|
|
|
opts = info (options <**> helper)
|
|
|
|
( fullDesc
|
|
|
|
<> progDesc "Run the \"wizard-wipeout\" Server."
|
|
|
|
<> header "wizard-wipeout - Last Mage standing"
|
|
|
|
)
|