author | alfadur |
Thu, 19 Jul 2018 22:50:46 +0300 | |
changeset 13531 | 3f69acc7e268 |
parent 11046 | 47a8c19ecb60 |
permissions | -rw-r--r-- |
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 |
11046 | 3 |
* Copyright (c) 2004-2015 Andrey Korotaev <unC0Rr@gmail.com> |
10460
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 | 19 |
{-# LANGUAGE CPP #-} |
1804 | 20 |
module Opts |
21 |
( |
|
2867
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
1964
diff
changeset
|
22 |
getOpts, |
1804 | 23 |
) where |
24 |
||
4905 | 25 |
import System.Environment |
1804 | 26 |
import System.Console.GetOpt |
4932 | 27 |
import Data.Maybe ( fromMaybe ) |
28 |
------------------- |
|
1804 | 29 |
import CoreTypes |
30 |
import Utils |
|
31 |
||
4989 | 32 |
options :: [OptDescr (ServerInfo -> ServerInfo)] |
1804 | 33 |
options = [ |
4932 | 34 |
Option "p" ["port"] (ReqArg readListenPort "PORT") "listen on PORT", |
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 | 37 |
|
4932 | 38 |
readListenPort |
39 |
, readDedicated |
|
4989 | 40 |
:: String -> ServerInfo -> ServerInfo |
4932 | 41 |
|
1832 | 42 |
|
1804 | 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 | 46 |
|
4932 | 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 | 49 |
readDed = fromMaybe True (maybeRead str :: Maybe Bool) |
1804 | 50 |
|
4989 | 51 |
getOpts :: ServerInfo -> IO ServerInfo |
1804 | 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 | 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 | 57 |
where header = "Usage: hedgewars-server [OPTION...]" |