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-11 16:21:24 +00:00
|
|
|
import qualified Control.Concurrent.STM as STM
|
|
|
|
|
2023-12-12 01:53:05 +00:00
|
|
|
import Control.Monad.Loops (whileM_)
|
|
|
|
|
2023-12-10 11:44:23 +00:00
|
|
|
import Options.Applicative
|
|
|
|
|
|
|
|
-- 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
|
2023-12-10 19:12:53 +00:00
|
|
|
sock <- connectSocket socketLocation
|
2023-12-11 16:21:24 +00:00
|
|
|
queue <- STM.newTQueueIO
|
2023-12-10 19:12:53 +00:00
|
|
|
putStrLn "connected"
|
2023-12-12 01:53:05 +00:00
|
|
|
|
|
|
|
|
2023-12-10 19:12:53 +00:00
|
|
|
sendMessage (IdRequest) sock
|
2023-12-11 16:21:24 +00:00
|
|
|
threadDelay $ 1 * 10 ^ 6
|
|
|
|
receiveMessage sock queue
|
2023-12-12 01:53:05 +00:00
|
|
|
whileM_
|
|
|
|
(STM.atomically $ STM.isEmptyTQueue queue)
|
|
|
|
(threadDelay $ 1 * 10 ^ 6)
|
2023-12-11 16:21:24 +00:00
|
|
|
clientIdMsg <- head <$> STM.atomically (STM.flushTQueue queue)
|
2023-12-11 10:54:17 +00:00
|
|
|
let clientId = acClientUUID clientIdMsg
|
|
|
|
putStrLn $ "received client UUID: " <> show clientId
|
2023-12-12 01:53:05 +00:00
|
|
|
|
|
|
|
|
2023-12-11 16:21:24 +00:00
|
|
|
putStrLn welcomeText
|
2023-12-12 01:53:05 +00:00
|
|
|
-- threadDelay $ 15 * 10 ^ 6
|
|
|
|
|
|
|
|
|
2023-12-11 10:54:17 +00:00
|
|
|
sendMessage (ClientMessage clientId ClientRequestWizard) sock
|
2023-12-11 16:21:24 +00:00
|
|
|
threadDelay $ 1 * 10 ^ 6
|
|
|
|
receiveMessage sock queue
|
2023-12-12 01:53:05 +00:00
|
|
|
whileM_
|
|
|
|
(STM.atomically $ STM.isEmptyTQueue queue)
|
|
|
|
(threadDelay $ 1 * 10 ^ 6)
|
2023-12-11 16:21:24 +00:00
|
|
|
playerWizard <- head <$> STM.atomically (STM.flushTQueue queue)
|
2023-12-12 01:53:05 +00:00
|
|
|
putStrLn $ "received wizard: " <> show (initWizard playerWizard)
|
|
|
|
|
|
|
|
|
2023-12-11 10:54:17 +00:00
|
|
|
let initRead = ReaderContainer sock clientId
|
|
|
|
initState = StateContainer (initWizard playerWizard)
|
2023-12-11 09:48:25 +00:00
|
|
|
putStrLn "sending quit message"
|
2023-12-11 10:54:17 +00:00
|
|
|
sendMessage (ClientMessage clientId ClientQuit) sock
|
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"
|
|
|
|
)
|
2023-12-11 10:54:17 +00:00
|
|
|
|
|
|
|
welcomeText :: String
|
|
|
|
welcomeText = mconcat $ map (<> "\n")
|
|
|
|
[ "Welcome to the arena, wizards."
|
|
|
|
, ""
|
|
|
|
, "Let the toughest and bravest of you survive"
|
|
|
|
, ""
|
|
|
|
, "Some last hints before you enter the fighting grounds:"
|
|
|
|
, ""
|
2023-12-11 16:21:24 +00:00
|
|
|
, "press [SPACE] to fire your wand"
|
2023-12-11 10:54:17 +00:00
|
|
|
, "press [1] through [9] to change wands, if you have collected more wands"
|
|
|
|
, "press [ESC] to leave"
|
|
|
|
, ""
|
|
|
|
, "Good Luck!"
|
|
|
|
]
|