author | unc0rr |
Fri, 04 Sep 2009 07:04:27 +0000 | |
changeset 2348 | b39d826e1ccd |
parent 2296 | 19f2f76dc346 |
child 2349 | ba7a0813c532 |
permissions | -rw-r--r-- |
2348 | 1 |
{-# LANGUAGE CPP, ScopedTypeVariables #-} |
1804 | 2 |
|
3 |
module Main where |
|
4 |
||
5 |
import Network.Socket |
|
6 |
import qualified Network |
|
7 |
import Control.Concurrent.STM |
|
8 |
import Control.Concurrent.Chan |
|
2296
19f2f76dc346
Patch for compiling with 6.10 (define NEW_EXCEPTIONS to do that)
unc0rr
parents:
2129
diff
changeset
|
9 |
#if defined(NEW_EXCEPTIONS) |
19f2f76dc346
Patch for compiling with 6.10 (define NEW_EXCEPTIONS to do that)
unc0rr
parents:
2129
diff
changeset
|
10 |
import qualified Control.OldException as Exception |
19f2f76dc346
Patch for compiling with 6.10 (define NEW_EXCEPTIONS to do that)
unc0rr
parents:
2129
diff
changeset
|
11 |
#else |
19f2f76dc346
Patch for compiling with 6.10 (define NEW_EXCEPTIONS to do that)
unc0rr
parents:
2129
diff
changeset
|
12 |
import qualified Control.Exception as Exception |
19f2f76dc346
Patch for compiling with 6.10 (define NEW_EXCEPTIONS to do that)
unc0rr
parents:
2129
diff
changeset
|
13 |
#endif |
1804 | 14 |
import System.Log.Logger |
15 |
----------------------------------- |
|
16 |
import Opts |
|
17 |
import CoreTypes |
|
18 |
import OfficialServer.DBInteraction |
|
19 |
import ServerCore |
|
1964 | 20 |
import Utils |
1804 | 21 |
|
22 |
||
23 |
#if !defined(mingw32_HOST_OS) |
|
24 |
import System.Posix |
|
25 |
#endif |
|
26 |
||
27 |
||
28 |
setupLoggers = |
|
29 |
updateGlobalLogger "Clients" |
|
1985 | 30 |
(setLevel INFO) |
1804 | 31 |
|
32 |
main = withSocketsDo $ do |
|
33 |
#if !defined(mingw32_HOST_OS) |
|
34 |
installHandler sigPIPE Ignore Nothing; |
|
2129
8664554d5547
Another approach to zombies problem (set SIGCHLD handler to SIG_IGN)
unc0rr
parents:
1985
diff
changeset
|
35 |
installHandler sigCHLD Ignore Nothing; |
1804 | 36 |
#endif |
37 |
||
38 |
setupLoggers |
|
39 |
||
40 |
stats <- atomically $ newTMVar (StatisticsInfo 0 0) |
|
1833 | 41 |
dbQueriesChan <- newChan |
1804 | 42 |
coreChan <- newChan |
1964 | 43 |
serverInfo' <- getOpts $ newServerInfo stats coreChan dbQueriesChan |
1804 | 44 |
|
1964 | 45 |
#if defined(OFFICIAL_SERVER) |
46 |
dbHost' <- askFromConsole "DB host: " |
|
47 |
dbLogin' <- askFromConsole "login: " |
|
48 |
dbPassword' <- askFromConsole "password: " |
|
49 |
let serverInfo = serverInfo'{dbHost = dbHost', dbLogin = dbLogin', dbPassword = dbPassword'} |
|
50 |
#else |
|
51 |
let serverInfo = serverInfo' |
|
52 |
#endif |
|
53 |
||
2296
19f2f76dc346
Patch for compiling with 6.10 (define NEW_EXCEPTIONS to do that)
unc0rr
parents:
2129
diff
changeset
|
54 |
Exception.bracket |
1804 | 55 |
(Network.listenOn $ Network.PortNumber $ listenPort serverInfo) |
56 |
(sClose) |
|
1927
e2031906a347
Ping clients every 30 seconds. Disconnection due to ping timeout to be implemented.
unc0rr
parents:
1839
diff
changeset
|
57 |
(startServer serverInfo) |