gameServer/ConfigFile.hs
changeset 4989 4771fed9272e
parent 4988 bd540ba66599
child 4990 4b5d62ac01f7
equal deleted inserted replaced
4988:bd540ba66599 4989:4771fed9272e
     5 import Data.TConfig
     5 import Data.TConfig
     6 import qualified Data.ByteString.Char8 as B
     6 import qualified Data.ByteString.Char8 as B
     7 -------------------
     7 -------------------
     8 import CoreTypes
     8 import CoreTypes
     9 
     9 
       
    10 cfgFileName = "hedgewars-server.ini"
       
    11 
    10 readServerConfig serverInfo' = do
    12 readServerConfig serverInfo' = do
    11     cfg <- readConfig "hedgewars-server.ini"
    13     cfg <- readConfig cfgFileName
    12     let si = serverInfo'{
    14     let si = serverInfo'{
    13         dbHost = value "dbHost" cfg
    15         dbHost = value "dbHost" cfg
    14         , dbName = value "dbName" cfg
    16         , dbName = value "dbName" cfg
    15         , dbLogin = value "dbLogin" cfg
    17         , dbLogin = value "dbLogin" cfg
    16         , dbPassword = value "dbPassword" cfg
    18         , dbPassword = value "dbPassword" cfg
    23     where
    25     where
    24         value n c = B.pack . fromJust2 n $ getValue n c
    26         value n c = B.pack . fromJust2 n $ getValue n c
    25         fromJust2 n Nothing = error $ "Missing config entry " ++ n
    27         fromJust2 n Nothing = error $ "Missing config entry " ++ n
    26         fromJust2 _ (Just a) = a
    28         fromJust2 _ (Just a) = a
    27 
    29 
    28 writeServerConfig :: ServerInfo c -> IO ()
    30 
    29 writeServerConfig = undefined
    31 writeServerConfig ServerInfo{serverConfig = Nothing} = return ()
       
    32 writeServerConfig ServerInfo{
       
    33     dbHost = dh,
       
    34     dbName = dn,
       
    35     dbLogin = dl,
       
    36     dbPassword = dp,
       
    37     serverMessage = sm,
       
    38     serverMessageForOldVersions = smo,
       
    39     latestReleaseVersion = ver,
       
    40     serverConfig = Just cfg}
       
    41         = do
       
    42     let newCfg = foldl (\c (n, v) -> repConfig n (B.unpack v) c) cfg entries
       
    43     writeConfig cfgFileName newCfg
       
    44     where
       
    45         entries = [
       
    46             ("dbHost", dh)
       
    47             , ("dbName", dn)
       
    48             , ("dbLogin", dl)
       
    49             , ("dbPassword", dp)
       
    50             , ("sv_message", sm)
       
    51             , ("sv_messageOld", smo)
       
    52             ]