gameServer/Opts.hs
author unc0rr
Thu, 05 May 2011 17:08:29 +0400
changeset 5202 45a16280d68d
parent 4989 4771fed9272e
child 5210 a5329e52a71b
permissions -rw-r--r--
Some improvements on stats subsystem
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4932
f11d80bac7ed - Take into account hlint suggestions
unc0rr
parents: 4905
diff changeset
     1
{-# LANGUAGE CPP #-}
1804
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
     2
module Opts
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
     3
(
2867
9be6693c78cb - Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents: 1964
diff changeset
     4
    getOpts,
1804
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
     5
) where
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
     6
4905
7842d085acf4 Fix merge :D
unc0rr
parents: 4568
diff changeset
     7
import System.Environment
1804
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
     8
import System.Console.GetOpt
4932
f11d80bac7ed - Take into account hlint suggestions
unc0rr
parents: 4905
diff changeset
     9
import Data.Maybe ( fromMaybe )
f11d80bac7ed - Take into account hlint suggestions
unc0rr
parents: 4905
diff changeset
    10
-------------------
1804
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    11
import CoreTypes
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    12
import Utils
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    13
4989
4771fed9272e - Write server config into .ini file on change
unc0rr
parents: 4975
diff changeset
    14
options :: [OptDescr (ServerInfo -> ServerInfo)]
1804
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    15
options = [
4932
f11d80bac7ed - Take into account hlint suggestions
unc0rr
parents: 4905
diff changeset
    16
    Option "p" ["port"] (ReqArg readListenPort "PORT") "listen on PORT",
f11d80bac7ed - Take into account hlint suggestions
unc0rr
parents: 4905
diff changeset
    17
    Option "d" ["dedicated"] (ReqArg readDedicated "BOOL") "start as dedicated (True or False)"
2867
9be6693c78cb - Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents: 1964
diff changeset
    18
    ]
1804
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    19
4932
f11d80bac7ed - Take into account hlint suggestions
unc0rr
parents: 4905
diff changeset
    20
readListenPort
f11d80bac7ed - Take into account hlint suggestions
unc0rr
parents: 4905
diff changeset
    21
    , readDedicated
4989
4771fed9272e - Write server config into .ini file on change
unc0rr
parents: 4975
diff changeset
    22
    :: String -> ServerInfo -> ServerInfo
4932
f11d80bac7ed - Take into account hlint suggestions
unc0rr
parents: 4905
diff changeset
    23
1832
1fb61a53a2c2 Add options for database access
unc0rr
parents: 1804
diff changeset
    24
1804
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    25
readListenPort str opts = opts{listenPort = readPort}
2867
9be6693c78cb - Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents: 1964
diff changeset
    26
    where
9be6693c78cb - Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents: 1964
diff changeset
    27
        readPort = fromInteger $ fromMaybe 46631 (maybeRead str :: Maybe Integer)
1804
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    28
4932
f11d80bac7ed - Take into account hlint suggestions
unc0rr
parents: 4905
diff changeset
    29
readDedicated str opts = opts{isDedicated = readDed}
2867
9be6693c78cb - Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents: 1964
diff changeset
    30
    where
4932
f11d80bac7ed - Take into account hlint suggestions
unc0rr
parents: 4905
diff changeset
    31
        readDed = fromMaybe True (maybeRead str :: Maybe Bool)
1804
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    32
4989
4771fed9272e - Write server config into .ini file on change
unc0rr
parents: 4975
diff changeset
    33
getOpts :: ServerInfo -> IO ServerInfo
1804
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    34
getOpts opts = do
2867
9be6693c78cb - Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents: 1964
diff changeset
    35
    args <- getArgs
9be6693c78cb - Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents: 1964
diff changeset
    36
    case getOpt Permute options args of
9be6693c78cb - Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents: 1964
diff changeset
    37
        (o, [], []) -> return $ foldr ($) opts o
9be6693c78cb - Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents: 1964
diff changeset
    38
        (_,_,errs) -> ioError (userError (concat errs ++ usageInfo header options))
2966
fab0d8b04bb9 Server:
smxx
parents: 2867
diff changeset
    39
    where header = "Usage: hedgewars-server [OPTION...]"