author | unC0Rr |
Wed, 15 May 2024 10:05:13 +0200 | |
changeset 16042 | 2e529b1a9d5b |
parent 11046 | 47a8c19ecb60 |
permissions | -rw-r--r-- |
10460
8dcea9087d75
Added copyrights to gameServer directory
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
8401
diff
changeset
|
1 |
{- |
8dcea9087d75
Added copyrights to gameServer directory
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
8401
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:
8401
diff
changeset
|
4 |
* |
8dcea9087d75
Added copyrights to gameServer directory
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
8401
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:
8401
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:
8401
diff
changeset
|
7 |
* the Free Software Foundation; version 2 of the License |
8dcea9087d75
Added copyrights to gameServer directory
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
8401
diff
changeset
|
8 |
* |
8dcea9087d75
Added copyrights to gameServer directory
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
8401
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:
8401
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:
8401
diff
changeset
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
8dcea9087d75
Added copyrights to gameServer directory
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
8401
diff
changeset
|
12 |
* GNU General Public License for more details. |
8dcea9087d75
Added copyrights to gameServer directory
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
8401
diff
changeset
|
13 |
* |
8dcea9087d75
Added copyrights to gameServer directory
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
8401
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:
8401
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:
8401
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:
8401
diff
changeset
|
17 |
\-} |
8dcea9087d75
Added copyrights to gameServer directory
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
8401
diff
changeset
|
18 |
|
4975
31da8979e5b1
Use Data.TConfig to read and store server config in hedgewars.ini (a little bit of hate to the author for not exporting Conf type)
unc0rr
parents:
4974
diff
changeset
|
19 |
{-# LANGUAGE RankNTypes #-} |
4974
078cd026a7b1
Add stubs for server config reading and writing routines
unc0rr
parents:
diff
changeset
|
20 |
module ConfigFile where |
078cd026a7b1
Add stubs for server config reading and writing routines
unc0rr
parents:
diff
changeset
|
21 |
|
4975
31da8979e5b1
Use Data.TConfig to read and store server config in hedgewars.ini (a little bit of hate to the author for not exporting Conf type)
unc0rr
parents:
4974
diff
changeset
|
22 |
import Data.Maybe |
4974
078cd026a7b1
Add stubs for server config reading and writing routines
unc0rr
parents:
diff
changeset
|
23 |
import Data.TConfig |
4975
31da8979e5b1
Use Data.TConfig to read and store server config in hedgewars.ini (a little bit of hate to the author for not exporting Conf type)
unc0rr
parents:
4974
diff
changeset
|
24 |
import qualified Data.ByteString.Char8 as B |
4974
078cd026a7b1
Add stubs for server config reading and writing routines
unc0rr
parents:
diff
changeset
|
25 |
------------------- |
078cd026a7b1
Add stubs for server config reading and writing routines
unc0rr
parents:
diff
changeset
|
26 |
import CoreTypes |
078cd026a7b1
Add stubs for server config reading and writing routines
unc0rr
parents:
diff
changeset
|
27 |
|
4992 | 28 |
cfgFileName :: String |
4989 | 29 |
cfgFileName = "hedgewars-server.ini" |
30 |
||
4992 | 31 |
|
32 |
readServerConfig :: ServerInfo -> IO ServerInfo |
|
4975
31da8979e5b1
Use Data.TConfig to read and store server config in hedgewars.ini (a little bit of hate to the author for not exporting Conf type)
unc0rr
parents:
4974
diff
changeset
|
33 |
readServerConfig serverInfo' = do |
4989 | 34 |
cfg <- readConfig cfgFileName |
4975
31da8979e5b1
Use Data.TConfig to read and store server config in hedgewars.ini (a little bit of hate to the author for not exporting Conf type)
unc0rr
parents:
4974
diff
changeset
|
35 |
let si = serverInfo'{ |
31da8979e5b1
Use Data.TConfig to read and store server config in hedgewars.ini (a little bit of hate to the author for not exporting Conf type)
unc0rr
parents:
4974
diff
changeset
|
36 |
dbHost = value "dbHost" cfg |
4982
3572eaf14340
Add dbName parameter to .ini file, fix some warnings
unc0rr
parents:
4975
diff
changeset
|
37 |
, dbName = value "dbName" cfg |
4975
31da8979e5b1
Use Data.TConfig to read and store server config in hedgewars.ini (a little bit of hate to the author for not exporting Conf type)
unc0rr
parents:
4974
diff
changeset
|
38 |
, dbLogin = value "dbLogin" cfg |
31da8979e5b1
Use Data.TConfig to read and store server config in hedgewars.ini (a little bit of hate to the author for not exporting Conf type)
unc0rr
parents:
4974
diff
changeset
|
39 |
, dbPassword = value "dbPassword" cfg |
4988 | 40 |
, serverMessage = value "sv_message" cfg |
41 |
, serverMessageForOldVersions = value "sv_messageOld" cfg |
|
5009 | 42 |
, bans = read . fromJust2 "bans" $ getValue "bans" cfg |
4988 | 43 |
, latestReleaseVersion = read . fromJust $ getValue "sv_latestProto" cfg |
4975
31da8979e5b1
Use Data.TConfig to read and store server config in hedgewars.ini (a little bit of hate to the author for not exporting Conf type)
unc0rr
parents:
4974
diff
changeset
|
44 |
, serverConfig = Just cfg |
31da8979e5b1
Use Data.TConfig to read and store server config in hedgewars.ini (a little bit of hate to the author for not exporting Conf type)
unc0rr
parents:
4974
diff
changeset
|
45 |
} |
31da8979e5b1
Use Data.TConfig to read and store server config in hedgewars.ini (a little bit of hate to the author for not exporting Conf type)
unc0rr
parents:
4974
diff
changeset
|
46 |
return si |
31da8979e5b1
Use Data.TConfig to read and store server config in hedgewars.ini (a little bit of hate to the author for not exporting Conf type)
unc0rr
parents:
4974
diff
changeset
|
47 |
where |
4988 | 48 |
value n c = B.pack . fromJust2 n $ getValue n c |
49 |
fromJust2 n Nothing = error $ "Missing config entry " ++ n |
|
50 |
fromJust2 _ (Just a) = a |
|
4974
078cd026a7b1
Add stubs for server config reading and writing routines
unc0rr
parents:
diff
changeset
|
51 |
|
4989 | 52 |
|
4992 | 53 |
writeServerConfig :: ServerInfo -> IO () |
4989 | 54 |
writeServerConfig ServerInfo{serverConfig = Nothing} = return () |
55 |
writeServerConfig ServerInfo{ |
|
56 |
dbHost = dh, |
|
57 |
dbName = dn, |
|
58 |
dbLogin = dl, |
|
59 |
dbPassword = dp, |
|
60 |
serverMessage = sm, |
|
61 |
serverMessageForOldVersions = smo, |
|
5009 | 62 |
bans = b, |
4989 | 63 |
latestReleaseVersion = ver, |
64 |
serverConfig = Just cfg} |
|
5009 | 65 |
= |
66 |
writeConfig cfgFileName $ foldl1 (.) entries cfg |
|
4989 | 67 |
where |
5009 | 68 |
entries = |
69 |
repConfig "sv_latestProto" (show ver) |
|
70 |
: repConfig "bans" (show b) |
|
71 |
: map (\(n, v) -> repConfig n (B.unpack v)) [ |
|
4989 | 72 |
("dbHost", dh) |
73 |
, ("dbName", dn) |
|
74 |
, ("dbLogin", dl) |
|
75 |
, ("dbPassword", dp) |
|
76 |
, ("sv_message", sm) |
|
77 |
, ("sv_messageOld", smo) |
|
78 |
] |