gameServer/Opts.hs
author Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
Fri, 28 Nov 2014 16:03:35 +0100
changeset 10561 8b65886906f3
parent 10460 8dcea9087d75
child 11046 47a8c19ecb60
permissions -rw-r--r--
Disable testing if BUILD_ENGINE_C=ON (they fail)
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10460
8dcea9087d75 Added copyrights to gameServer directory
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents: 5210
diff changeset
     1
{-
8dcea9087d75 Added copyrights to gameServer directory
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents: 5210
diff changeset
     2
 * Hedgewars, a free turn based strategy game
8dcea9087d75 Added copyrights to gameServer directory
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents: 5210
diff changeset
     3
 * Copyright (c) 2004-2014 Andrey Korotaev <unC0Rr@gmail.com>
8dcea9087d75 Added copyrights to gameServer directory
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents: 5210
diff changeset
     4
 *
8dcea9087d75 Added copyrights to gameServer directory
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents: 5210
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
8dcea9087d75 Added copyrights to gameServer directory
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents: 5210
diff changeset
     6
 * it under the terms of the GNU General Public License as published by
8dcea9087d75 Added copyrights to gameServer directory
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents: 5210
diff changeset
     7
 * the Free Software Foundation; version 2 of the License
8dcea9087d75 Added copyrights to gameServer directory
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents: 5210
diff changeset
     8
 *
8dcea9087d75 Added copyrights to gameServer directory
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents: 5210
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
8dcea9087d75 Added copyrights to gameServer directory
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents: 5210
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
8dcea9087d75 Added copyrights to gameServer directory
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents: 5210
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
8dcea9087d75 Added copyrights to gameServer directory
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents: 5210
diff changeset
    12
 * GNU General Public License for more details.
8dcea9087d75 Added copyrights to gameServer directory
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents: 5210
diff changeset
    13
 *
8dcea9087d75 Added copyrights to gameServer directory
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents: 5210
diff changeset
    14
 * You should have received a copy of the GNU General Public License
8dcea9087d75 Added copyrights to gameServer directory
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents: 5210
diff changeset
    15
 * along with this program; if not, write to the Free Software
8dcea9087d75 Added copyrights to gameServer directory
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents: 5210
diff changeset
    16
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
8dcea9087d75 Added copyrights to gameServer directory
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents: 5210
diff changeset
    17
 \-}
8dcea9087d75 Added copyrights to gameServer directory
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents: 5210
diff changeset
    18
4932
f11d80bac7ed - Take into account hlint suggestions
unc0rr
parents: 4905
diff changeset
    19
{-# LANGUAGE CPP #-}
1804
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    20
module Opts
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    21
(
2867
9be6693c78cb - Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents: 1964
diff changeset
    22
    getOpts,
1804
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    23
) where
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    24
4905
7842d085acf4 Fix merge :D
unc0rr
parents: 4568
diff changeset
    25
import System.Environment
1804
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    26
import System.Console.GetOpt
4932
f11d80bac7ed - Take into account hlint suggestions
unc0rr
parents: 4905
diff changeset
    27
import Data.Maybe ( fromMaybe )
f11d80bac7ed - Take into account hlint suggestions
unc0rr
parents: 4905
diff changeset
    28
-------------------
1804
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    29
import CoreTypes
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    30
import Utils
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    31
4989
4771fed9272e - Write server config into .ini file on change
unc0rr
parents: 4975
diff changeset
    32
options :: [OptDescr (ServerInfo -> ServerInfo)]
1804
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    33
options = [
4932
f11d80bac7ed - Take into account hlint suggestions
unc0rr
parents: 4905
diff changeset
    34
    Option "p" ["port"] (ReqArg readListenPort "PORT") "listen on PORT",
f11d80bac7ed - Take into account hlint suggestions
unc0rr
parents: 4905
diff changeset
    35
    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
    36
    ]
1804
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    37
4932
f11d80bac7ed - Take into account hlint suggestions
unc0rr
parents: 4905
diff changeset
    38
readListenPort
f11d80bac7ed - Take into account hlint suggestions
unc0rr
parents: 4905
diff changeset
    39
    , readDedicated
4989
4771fed9272e - Write server config into .ini file on change
unc0rr
parents: 4975
diff changeset
    40
    :: String -> ServerInfo -> ServerInfo
4932
f11d80bac7ed - Take into account hlint suggestions
unc0rr
parents: 4905
diff changeset
    41
1832
1fb61a53a2c2 Add options for database access
unc0rr
parents: 1804
diff changeset
    42
1804
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    43
readListenPort str opts = opts{listenPort = readPort}
2867
9be6693c78cb - Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents: 1964
diff changeset
    44
    where
9be6693c78cb - Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents: 1964
diff changeset
    45
        readPort = fromInteger $ fromMaybe 46631 (maybeRead str :: Maybe Integer)
1804
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    46
4932
f11d80bac7ed - Take into account hlint suggestions
unc0rr
parents: 4905
diff changeset
    47
readDedicated str opts = opts{isDedicated = readDed}
2867
9be6693c78cb - Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents: 1964
diff changeset
    48
    where
4932
f11d80bac7ed - Take into account hlint suggestions
unc0rr
parents: 4905
diff changeset
    49
        readDed = fromMaybe True (maybeRead str :: Maybe Bool)
1804
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    50
4989
4771fed9272e - Write server config into .ini file on change
unc0rr
parents: 4975
diff changeset
    51
getOpts :: ServerInfo -> IO ServerInfo
1804
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    52
getOpts opts = do
2867
9be6693c78cb - Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents: 1964
diff changeset
    53
    args <- getArgs
9be6693c78cb - Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents: 1964
diff changeset
    54
    case getOpt Permute options args of
5210
a5329e52a71b Pass correct arguments on restart
unc0rr
parents: 4989
diff changeset
    55
        (o, [], []) -> return $ foldr ($) opts{runArgs = args} o
2867
9be6693c78cb - Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents: 1964
diff changeset
    56
        (_,_,errs) -> ioError (userError (concat errs ++ usageInfo header options))
2966
fab0d8b04bb9 Server:
smxx
parents: 2867
diff changeset
    57
    where header = "Usage: hedgewars-server [OPTION...]"