2023-12-08 04:19:32 +00:00
|
|
|
{-# LANGUAGE RecordWildCards #-}
|
|
|
|
{-# LANGUAGE OverloadedStrings #-}
|
2023-12-04 16:20:06 +00:00
|
|
|
module Main where
|
|
|
|
|
2023-12-10 05:57:48 +00:00
|
|
|
import qualified Control.Concurrent.STM as STM
|
|
|
|
|
2023-12-08 04:19:32 +00:00
|
|
|
import Control.Monad.RWS.Strict
|
|
|
|
|
|
|
|
import qualified Data.ByteString.Char8 as B8
|
|
|
|
|
|
|
|
import Data.String (fromString)
|
|
|
|
|
|
|
|
import Data.Time
|
|
|
|
|
|
|
|
import Data.Yaml
|
|
|
|
|
2023-12-09 12:24:33 +00:00
|
|
|
import Network.Socket as Net
|
2023-12-09 07:55:56 +00:00
|
|
|
|
2023-12-08 04:19:32 +00:00
|
|
|
import Options.Applicative
|
|
|
|
|
|
|
|
-- internal imports
|
|
|
|
|
|
|
|
import Library.Types
|
|
|
|
|
2023-12-09 12:58:59 +00:00
|
|
|
import Server.Communication
|
2023-12-09 01:49:19 +00:00
|
|
|
import Server.Game
|
2023-12-08 04:19:32 +00:00
|
|
|
import Server.Map (generateArena)
|
2023-12-09 01:49:19 +00:00
|
|
|
import Server.Types
|
2023-12-08 04:19:32 +00:00
|
|
|
|
2023-12-04 16:20:06 +00:00
|
|
|
main :: IO ()
|
2023-12-08 04:19:32 +00:00
|
|
|
main = do
|
|
|
|
putStrLn "Hello, Wizards!"
|
|
|
|
(Options optSettingLoc) <- execParser opts
|
|
|
|
raw <- B8.readFile optSettingLoc
|
|
|
|
case decodeEither' raw of
|
|
|
|
Left msg ->
|
|
|
|
error (optSettingLoc <> ":" <>
|
|
|
|
" error: " <>
|
|
|
|
fromString (prettyPrintParseException msg)
|
|
|
|
)
|
|
|
|
Right (Settings {..}) -> do
|
2023-12-09 12:58:59 +00:00
|
|
|
sock <- bindSocket setSocketPath
|
2023-12-09 12:24:33 +00:00
|
|
|
putStrLn "Bound and listening to socket:"
|
2023-12-09 07:55:56 +00:00
|
|
|
print =<< getSocketName sock
|
|
|
|
putStrLn "-----------------------------------------------------------------------------------"
|
2023-12-08 04:19:32 +00:00
|
|
|
arena <- generateArena setMapRows setMapColumns setSpawnerProbability
|
|
|
|
putStrLn "generated arena:"
|
|
|
|
print (arenaMap arena)
|
|
|
|
putStrLn "-----------------------------------------------------------------------------------"
|
|
|
|
putStrLn "starting game…"
|
|
|
|
now <- getCurrentTime
|
2023-12-10 05:57:48 +00:00
|
|
|
sockList <- STM.newTMVarIO []
|
|
|
|
serverState <- STM.newTMVarIO (ServerState False False)
|
2023-12-09 12:58:59 +00:00
|
|
|
let initRead = ReaderContainer (arenaMap arena) setFPS sock
|
2023-12-10 05:57:48 +00:00
|
|
|
initState = StateContainer (arenaSpawners arena) [] serverState now sockList
|
|
|
|
(finalState, finalWrite) <- execRWST
|
|
|
|
(do
|
|
|
|
terminateGameOnSigint
|
|
|
|
runGame
|
|
|
|
)
|
|
|
|
initRead
|
|
|
|
initState
|
2023-12-08 04:19:32 +00:00
|
|
|
print finalWrite
|
|
|
|
where
|
|
|
|
opts = info (options <**> helper)
|
|
|
|
( fullDesc
|
|
|
|
<> progDesc "Run the \"wizard-wipeout\" Server."
|
|
|
|
<> header "wizard-wipeout - Last Mage standing"
|
|
|
|
)
|