netserver/Opts.hs
changeset 1492 2da1fe033f23
parent 1473 60e1fad78d58
child 1757 3aa7d21baca1
--- a/netserver/Opts.hs	Mon Nov 10 15:50:46 2008 +0000
+++ b/netserver/Opts.hs	Mon Nov 10 15:57:59 2008 +0000
@@ -1,7 +1,6 @@
 module Opts
 (
-	GlobalOptions(..),
-	globalOptions
+	getOpts,
 ) where
 
 import System
@@ -11,23 +10,14 @@
 import Miscutils
 import System.IO.Unsafe
 
-data GlobalOptions =
-	GlobalOptions
-	{
-		isDedicated :: Bool,
-		serverMessage :: String,
-		listenPort :: PortNumber
-	}
-defaultMessage = "<h2><p align=center><a href=\"http://www.hedgewars.org/\">http://www.hedgewars.org/</a></p></h2>"
-defaultOptions = (GlobalOptions True defaultMessage 46631)
 
-options :: [OptDescr (GlobalOptions -> GlobalOptions)]
+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 -> GlobalOptions -> GlobalOptions
+readListenPort, readDedicated :: String -> ServerInfo -> ServerInfo
 readListenPort str opts = opts{listenPort = readPort}
 	where
 		readPort = fromInteger $ fromMaybe 46631 (maybeRead str :: Maybe Integer)
@@ -36,13 +26,10 @@
 	where
 		readDedicated = fromMaybe True (maybeRead str :: Maybe Bool)
 
-opts :: IO GlobalOptions
-opts = do
+getOpts :: ServerInfo -> IO ServerInfo
+getOpts opts = do
 	args <- getArgs
 	case getOpt Permute options args of
-		(o, [], []) -> return $ foldr ($) defaultOptions o
+		(o, [], []) -> return $ foldr ($) opts o
 		(_,_,errs) -> ioError (userError (concat errs ++ usageInfo header options))
 	where header = "Usage: newhwserv [OPTION...]"
-
-{-# NOINLINE globalOptions #-}
-globalOptions = unsafePerformIO opts