gameServer/ConfigFile.hs
author unc0rr
Sat, 05 Mar 2011 22:39:26 +0300
changeset 4988 bd540ba66599
parent 4982 3572eaf14340
child 4989 4771fed9272e
permissions -rw-r--r--
Store more parameters in ini file

{-# LANGUAGE RankNTypes #-}
module ConfigFile where

import Data.Maybe
import Data.TConfig
import qualified Data.ByteString.Char8 as B
-------------------
import CoreTypes

readServerConfig serverInfo' = do
    cfg <- readConfig "hedgewars-server.ini"
    let si = serverInfo'{
        dbHost = value "dbHost" cfg
        , dbName = value "dbName" cfg
        , dbLogin = value "dbLogin" cfg
        , dbPassword = value "dbPassword" cfg
        , serverMessage = value "sv_message" cfg
        , serverMessageForOldVersions = value "sv_messageOld" cfg
        , latestReleaseVersion = read . fromJust $ getValue "sv_latestProto" cfg
        , serverConfig = Just cfg
    }
    return si
    where
        value n c = B.pack . fromJust2 n $ getValue n c
        fromJust2 n Nothing = error $ "Missing config entry " ++ n
        fromJust2 _ (Just a) = a

writeServerConfig :: ServerInfo c -> IO ()
writeServerConfig = undefined