netserver/Opts.hs
author unc0rr
Tue, 13 Jan 2009 18:56:14 +0000
changeset 1659 fd593a5e71fb
parent 1492 2da1fe033f23
child 1757 3aa7d21baca1
permissions -rw-r--r--
Team class now supports voicepacks

module Opts
(
	getOpts,
) where

import System
import System.Console.GetOpt
import Network
import Data.Maybe ( fromMaybe )
import Miscutils
import System.IO.Unsafe


options :: [OptDescr (ServerInfo -> ServerInfo)]
options = [
	Option ['p'] ["port"] (ReqArg readListenPort "PORT") "listen on PORT",
	Option ['d'] ["dedicated"] (ReqArg readDedicated "BOOL") "start as dedicated (True or False)"
	]

readListenPort, readDedicated :: String -> ServerInfo -> ServerInfo
readListenPort str opts = opts{listenPort = readPort}
	where
		readPort = fromInteger $ fromMaybe 46631 (maybeRead str :: Maybe Integer)

readDedicated str opts = opts{isDedicated = readDedicated}
	where
		readDedicated = fromMaybe True (maybeRead str :: Maybe Bool)

getOpts :: ServerInfo -> IO ServerInfo
getOpts opts = do
	args <- getArgs
	case getOpt Permute options args of
		(o, [], []) -> return $ foldr ($) opts o
		(_,_,errs) -> ioError (userError (concat errs ++ usageInfo header options))
	where header = "Usage: newhwserv [OPTION...]"