gameServer/Opts.hs
changeset 4957 3684faf5b3d1
parent 4932 f11d80bac7ed
child 4975 31da8979e5b1
equal deleted inserted replaced
4955:84543ecae8c3 4957:3684faf5b3d1
     5 ) where
     5 ) where
     6 
     6 
     7 import System.Environment
     7 import System.Environment
     8 import System.Console.GetOpt
     8 import System.Console.GetOpt
     9 import Data.Maybe ( fromMaybe )
     9 import Data.Maybe ( fromMaybe )
    10 #if defined(OFFICIAL_SERVER)
       
    11 import qualified Data.ByteString.Char8 as B
       
    12 import Network
       
    13 #endif
       
    14 -------------------
    10 -------------------
    15 import CoreTypes
    11 import CoreTypes
    16 import Utils
    12 import Utils
    17 
    13 
    18 options :: [OptDescr (ServerInfo -> ServerInfo)]
    14 options :: [OptDescr (ServerInfo -> ServerInfo)]
    21     Option "d" ["dedicated"] (ReqArg readDedicated "BOOL") "start as dedicated (True or False)"
    17     Option "d" ["dedicated"] (ReqArg readDedicated "BOOL") "start as dedicated (True or False)"
    22     ]
    18     ]
    23 
    19 
    24 readListenPort
    20 readListenPort
    25     , readDedicated
    21     , readDedicated
    26 #if defined(OFFICIAL_SERVER)
       
    27     , readDbLogin
       
    28     , readDbPassword
       
    29     readDbHost
       
    30 #endif
       
    31     :: String -> ServerInfo -> ServerInfo
    22     :: String -> ServerInfo -> ServerInfo
    32 
    23 
    33 
    24 
    34 readListenPort str opts = opts{listenPort = readPort}
    25 readListenPort str opts = opts{listenPort = readPort}
    35     where
    26     where
    37 
    28 
    38 readDedicated str opts = opts{isDedicated = readDed}
    29 readDedicated str opts = opts{isDedicated = readDed}
    39     where
    30     where
    40         readDed = fromMaybe True (maybeRead str :: Maybe Bool)
    31         readDed = fromMaybe True (maybeRead str :: Maybe Bool)
    41 
    32 
    42 #if defined(OFFICIAL_SERVER)
       
    43 readDbLogin str opts = opts{dbLogin = B.pack str}
       
    44 readDbPassword str opts = opts{dbPassword = B.pack str}
       
    45 readDbHost str opts = opts{dbHost = B.pack str}
       
    46 #endif
       
    47 
       
    48 getOpts :: ServerInfo -> IO ServerInfo
    33 getOpts :: ServerInfo -> IO ServerInfo
    49 getOpts opts = do
    34 getOpts opts = do
    50     args <- getArgs
    35     args <- getArgs
    51     case getOpt Permute options args of
    36     case getOpt Permute options args of
    52         (o, [], []) -> return $ foldr ($) opts o
    37         (o, [], []) -> return $ foldr ($) opts o