author | unc0rr |
Sun, 06 Mar 2011 21:54:37 +0300 | |
changeset 4989 | 4771fed9272e |
parent 4988 | bd540ba66599 |
child 4990 | 4b5d62ac01f7 |
permissions | -rw-r--r-- |
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
|
1 |
{-# LANGUAGE RankNTypes #-} |
4974
078cd026a7b1
Add stubs for server config reading and writing routines
unc0rr
parents:
diff
changeset
|
2 |
module ConfigFile where |
078cd026a7b1
Add stubs for server config reading and writing routines
unc0rr
parents:
diff
changeset
|
3 |
|
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
|
4 |
import Data.Maybe |
4974
078cd026a7b1
Add stubs for server config reading and writing routines
unc0rr
parents:
diff
changeset
|
5 |
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
|
6 |
import qualified Data.ByteString.Char8 as B |
4974
078cd026a7b1
Add stubs for server config reading and writing routines
unc0rr
parents:
diff
changeset
|
7 |
------------------- |
078cd026a7b1
Add stubs for server config reading and writing routines
unc0rr
parents:
diff
changeset
|
8 |
import CoreTypes |
078cd026a7b1
Add stubs for server config reading and writing routines
unc0rr
parents:
diff
changeset
|
9 |
|
4989 | 10 |
cfgFileName = "hedgewars-server.ini" |
11 |
||
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
|
12 |
readServerConfig serverInfo' = do |
4989 | 13 |
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
|
14 |
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
|
15 |
dbHost = value "dbHost" cfg |
4982
3572eaf14340
Add dbName parameter to .ini file, fix some warnings
unc0rr
parents:
4975
diff
changeset
|
16 |
, 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
|
17 |
, 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
|
18 |
, dbPassword = value "dbPassword" cfg |
4988 | 19 |
, serverMessage = value "sv_message" cfg |
20 |
, serverMessageForOldVersions = value "sv_messageOld" cfg |
|
21 |
, 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
|
22 |
, 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
|
23 |
} |
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 |
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
|
25 |
where |
4988 | 26 |
value n c = B.pack . fromJust2 n $ getValue n c |
27 |
fromJust2 n Nothing = error $ "Missing config entry " ++ n |
|
28 |
fromJust2 _ (Just a) = a |
|
4974
078cd026a7b1
Add stubs for server config reading and writing routines
unc0rr
parents:
diff
changeset
|
29 |
|
4989 | 30 |
|
31 |
writeServerConfig ServerInfo{serverConfig = Nothing} = return () |
|
32 |
writeServerConfig ServerInfo{ |
|
33 |
dbHost = dh, |
|
34 |
dbName = dn, |
|
35 |
dbLogin = dl, |
|
36 |
dbPassword = dp, |
|
37 |
serverMessage = sm, |
|
38 |
serverMessageForOldVersions = smo, |
|
39 |
latestReleaseVersion = ver, |
|
40 |
serverConfig = Just cfg} |
|
41 |
= do |
|
42 |
let newCfg = foldl (\c (n, v) -> repConfig n (B.unpack v) c) cfg entries |
|
43 |
writeConfig cfgFileName newCfg |
|
44 |
where |
|
45 |
entries = [ |
|
46 |
("dbHost", dh) |
|
47 |
, ("dbName", dn) |
|
48 |
, ("dbLogin", dl) |
|
49 |
, ("dbPassword", dp) |
|
50 |
, ("sv_message", sm) |
|
51 |
, ("sv_messageOld", smo) |
|
52 |
] |