gameServer/Opts.hs
changeset 1832 1fb61a53a2c2
parent 1804 4e78ad846fb6
child 1964 dc9ea05c9d2f
equal deleted inserted replaced
1831:025348f05b9f 1832:1fb61a53a2c2
    12 
    12 
    13 options :: [OptDescr (ServerInfo -> ServerInfo)]
    13 options :: [OptDescr (ServerInfo -> ServerInfo)]
    14 options = [
    14 options = [
    15 	Option ['p'] ["port"] (ReqArg readListenPort "PORT") "listen on PORT",
    15 	Option ['p'] ["port"] (ReqArg readListenPort "PORT") "listen on PORT",
    16 	Option ['d'] ["dedicated"] (ReqArg readDedicated "BOOL") "start as dedicated (True or False)",
    16 	Option ['d'] ["dedicated"] (ReqArg readDedicated "BOOL") "start as dedicated (True or False)",
    17 	Option []    ["password"] (ReqArg readPassword "STRING") "admin password"
    17 	Option []    ["db-login"] (ReqArg readDbLogin "STRING") "database access login",
       
    18 	Option []    ["db-password"] (ReqArg readDbPassword "STRING") "database access password",
       
    19 	Option []    ["db-host"] (ReqArg readDbHost "STRING") "database host"
    18 	]
    20 	]
    19 
    21 
    20 readListenPort, readDedicated, readPassword :: String -> ServerInfo -> ServerInfo
    22 readListenPort,
       
    23 	readDedicated,
       
    24 	readDbLogin,
       
    25 	readDbPassword,
       
    26 	readDbHost :: String -> ServerInfo -> ServerInfo
       
    27 
    21 readListenPort str opts = opts{listenPort = readPort}
    28 readListenPort str opts = opts{listenPort = readPort}
    22 	where
    29 	where
    23 		readPort = fromInteger $ fromMaybe 46631 (maybeRead str :: Maybe Integer)
    30 		readPort = fromInteger $ fromMaybe 46631 (maybeRead str :: Maybe Integer)
    24 
    31 
    25 readDedicated str opts = opts{isDedicated = readDedicated}
    32 readDedicated str opts = opts{isDedicated = readDedicated}
    26 	where
    33 	where
    27 		readDedicated = fromMaybe True (maybeRead str :: Maybe Bool)
    34 		readDedicated = fromMaybe True (maybeRead str :: Maybe Bool)
    28 
    35 
    29 readPassword str opts = opts{adminPassword = str}
    36 readDbLogin str opts = opts{dbLogin = str}
       
    37 readDbPassword str opts = opts{dbPassword = str}
       
    38 readDbHost str opts = opts{dbHost = str}
    30 
    39 
    31 getOpts :: ServerInfo -> IO ServerInfo
    40 getOpts :: ServerInfo -> IO ServerInfo
    32 getOpts opts = do
    41 getOpts opts = do
    33 	args <- getArgs
    42 	args <- getArgs
    34 	case getOpt Permute options args of
    43 	case getOpt Permute options args of