2023-12-08 04:19:32 +00:00
|
|
|
{-# LANGUAGE RecordWildCards #-}
|
|
|
|
{-# LANGUAGE OverloadedStrings #-}
|
2023-12-04 16:20:06 +00:00
|
|
|
module Main where
|
|
|
|
|
2024-03-29 09:34:15 +00:00
|
|
|
import Control.Concurrent (threadDelay)
|
|
|
|
|
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
|
|
|
|
|
2024-05-01 16:04:47 +00:00
|
|
|
import Library.Map
|
2023-12-08 04:19:32 +00:00
|
|
|
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
|
2024-11-04 05:53:58 +00:00
|
|
|
import Server.Log
|
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-12 10:21:25 +00:00
|
|
|
import Server.Util
|
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
|
2024-11-04 05:53:58 +00:00
|
|
|
let logLevel = setLogLevel
|
|
|
|
logPrintIO logLevel Info "Bound and listening to socket:"
|
|
|
|
logPrintIO logLevel Info . show =<< getSocketName sock
|
|
|
|
logPrintIO logLevel Info "-----------------------------------------------------------------------------------"
|
2023-12-08 04:19:32 +00:00
|
|
|
arena <- generateArena setMapRows setMapColumns setSpawnerProbability
|
2024-11-04 05:53:58 +00:00
|
|
|
logPrintIO logLevel Info "generated arena:"
|
2024-05-01 16:04:47 +00:00
|
|
|
prettyPrintMap (arenaMap arena)
|
2024-11-04 05:53:58 +00:00
|
|
|
logPrintIO logLevel Info "-----------------------------------------------------------------------------------"
|
|
|
|
logPrintIO logLevel Info "starting game…"
|
2023-12-08 04:19:32 +00:00
|
|
|
now <- getCurrentTime
|
2023-12-10 05:57:48 +00:00
|
|
|
sockList <- STM.newTMVarIO []
|
2024-11-03 03:40:46 +00:00
|
|
|
queueList <- STM.newTMVarIO []
|
2023-12-11 08:49:24 +00:00
|
|
|
messageQueue <- STM.newTQueueIO
|
2023-12-10 05:57:48 +00:00
|
|
|
serverState <- STM.newTMVarIO (ServerState False False)
|
2023-12-13 10:06:45 +00:00
|
|
|
emptyPLayers <- STM.newTMVarIO []
|
2024-02-02 08:07:11 +00:00
|
|
|
let initRead = ReaderContainer
|
|
|
|
(arenaMap arena)
|
|
|
|
setFPS
|
|
|
|
setFramesPerPing
|
|
|
|
setClientMaxTimeout
|
|
|
|
sock
|
2024-11-04 05:53:58 +00:00
|
|
|
logLevel
|
2024-11-03 03:40:46 +00:00
|
|
|
initState = StateContainer (arenaSpawners arena) emptyPLayers serverState now sockList queueList messageQueue
|
2024-11-29 10:24:07 +00:00
|
|
|
(_finalState, _finalWrite) <- execRWST
|
2023-12-10 05:57:48 +00:00
|
|
|
(do
|
2024-04-06 00:18:08 +00:00
|
|
|
terminateGameOnSigint
|
2023-12-10 05:57:48 +00:00
|
|
|
runGame
|
|
|
|
)
|
|
|
|
initRead
|
|
|
|
initState
|
2024-03-29 22:01:41 +00:00
|
|
|
removeIfExists setSocketPath
|
2024-03-29 09:34:15 +00:00
|
|
|
threadDelay 1000
|
2023-12-12 10:21:25 +00:00
|
|
|
putStrLn "bye bye"
|
2023-12-08 04:19:32 +00:00
|
|
|
where
|
|
|
|
opts = info (options <**> helper)
|
|
|
|
( fullDesc
|
|
|
|
<> progDesc "Run the \"wizard-wipeout\" Server."
|
|
|
|
<> header "wizard-wipeout - Last Mage standing"
|
|
|
|
)
|