author | unc0rr |
Thu, 03 Mar 2011 22:15:13 +0300 | |
changeset 4975 | 31da8979e5b1 |
parent 4974 | 078cd026a7b1 |
child 4982 | 3572eaf14340 |
permissions | -rw-r--r-- |
4921 | 1 |
{-# LANGUAGE CPP, ScopedTypeVariables, OverloadedStrings #-} |
1804 | 2 |
|
3 |
module Main where |
|
4 |
||
4568 | 5 |
import Network.Socket |
6 |
import Network.BSD |
|
1804 | 7 |
import Control.Concurrent.Chan |
4960 | 8 |
import qualified Control.Exception as E |
1804 | 9 |
import System.Log.Logger |
4962 | 10 |
import System.Process |
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
|
11 |
import Data.TConfig |
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 |
import Data.Maybe |
4973
53411a26df7e
Add server version (which is separate from protocol version) and a check in frontend for a new enough server (currently only qWarning)
unc0rr
parents:
4968
diff
changeset
|
13 |
#if defined(OFFICIAL_SERVER) |
4968 | 14 |
import Control.Monad |
4973
53411a26df7e
Add server version (which is separate from protocol version) and a check in frontend for a new enough server (currently only qWarning)
unc0rr
parents:
4968
diff
changeset
|
15 |
#endif |
1804 | 16 |
----------------------------------- |
17 |
import Opts |
|
18 |
import CoreTypes |
|
19 |
import ServerCore |
|
4974
078cd026a7b1
Add stubs for server config reading and writing routines
unc0rr
parents:
4973
diff
changeset
|
20 |
import ConfigFile |
1804 | 21 |
|
22 |
#if !defined(mingw32_HOST_OS) |
|
23 |
import System.Posix |
|
24 |
#endif |
|
25 |
||
26 |
||
4905 | 27 |
setupLoggers :: IO () |
1804 | 28 |
setupLoggers = |
2867
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2349
diff
changeset
|
29 |
updateGlobalLogger "Clients" |
3947
709fdb89f76c
Some screwing around in try to fix space leak. No luck yet.
unc0rr
parents:
3500
diff
changeset
|
30 |
(setLevel INFO) |
1804 | 31 |
|
4960 | 32 |
|
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 |
server :: ServerInfo c -> IO () |
4960 | 34 |
server si = do |
35 |
proto <- getProtocolNumber "tcp" |
|
36 |
E.bracket |
|
37 |
(socket AF_INET Stream proto) |
|
38 |
sClose |
|
39 |
(\sock -> do |
|
40 |
setSocketOption sock ReuseAddr 1 |
|
41 |
bindSocket sock (SockAddrInet (listenPort si) iNADDR_ANY) |
|
42 |
listen sock maxListenQueue |
|
43 |
startServer si sock |
|
44 |
) |
|
45 |
||
46 |
handleRestart :: ShutdownException -> IO () |
|
47 |
handleRestart ShutdownException = return () |
|
48 |
handleRestart RestartException = do |
|
4962 | 49 |
_ <- createProcess (proc "./hedgewars-server" []) |
4960 | 50 |
return () |
51 |
||
4905 | 52 |
main :: IO () |
1804 | 53 |
main = withSocketsDo $ do |
54 |
#if !defined(mingw32_HOST_OS) |
|
4932 | 55 |
_ <- installHandler sigPIPE Ignore Nothing |
56 |
_ <- installHandler sigCHLD Ignore Nothing |
|
1804 | 57 |
#endif |
58 |
||
2867
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2349
diff
changeset
|
59 |
setupLoggers |
1804 | 60 |
|
2867
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2349
diff
changeset
|
61 |
dbQueriesChan <- newChan |
4905 | 62 |
coreChan' <- newChan |
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
|
63 |
serverInfo' <- getOpts $ newServerInfo coreChan' dbQueriesChan Nothing |
4905 | 64 |
|
1964 | 65 |
#if defined(OFFICIAL_SERVER) |
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
|
66 |
si <- readServerConfig serverInfo' |
1964 | 67 |
#else |
4960 | 68 |
let si = serverInfo' |
1964 | 69 |
#endif |
70 |
||
4960 | 71 |
(server si) `E.catch` handleRestart |