author | koda |
Fri, 23 Jul 2010 15:08:44 +0200 | |
changeset 3664 | f5bdf26c843e |
parent 3500 | af8390d807d6 |
child 3947 | 709fdb89f76c |
permissions | -rw-r--r-- |
2348 | 1 |
{-# LANGUAGE CPP, ScopedTypeVariables #-} |
1804 | 2 |
|
3 |
module Main where |
|
4 |
||
3425 | 5 |
import Network |
1804 | 6 |
import Control.Concurrent.STM |
7 |
import Control.Concurrent.Chan |
|
2296
19f2f76dc346
Patch for compiling with 6.10 (define NEW_EXCEPTIONS to do that)
unc0rr
parents:
2129
diff
changeset
|
8 |
import qualified Control.Exception as Exception |
1804 | 9 |
import System.Log.Logger |
10 |
----------------------------------- |
|
11 |
import Opts |
|
12 |
import CoreTypes |
|
13 |
import ServerCore |
|
14 |
||
15 |
||
16 |
#if !defined(mingw32_HOST_OS) |
|
17 |
import System.Posix |
|
18 |
#endif |
|
19 |
||
20 |
||
3435 | 21 |
setupLoggers :: IO () |
1804 | 22 |
setupLoggers = |
2867
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2349
diff
changeset
|
23 |
updateGlobalLogger "Clients" |
3425 | 24 |
(setLevel DEBUG) |
1804 | 25 |
|
3435 | 26 |
main :: IO () |
1804 | 27 |
main = withSocketsDo $ do |
28 |
#if !defined(mingw32_HOST_OS) |
|
2867
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2349
diff
changeset
|
29 |
installHandler sigPIPE Ignore Nothing; |
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2349
diff
changeset
|
30 |
installHandler sigCHLD Ignore Nothing; |
1804 | 31 |
#endif |
32 |
||
2867
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2349
diff
changeset
|
33 |
setupLoggers |
1804 | 34 |
|
3425 | 35 |
stats' <- atomically $ newTMVar (StatisticsInfo 0 0) |
2867
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2349
diff
changeset
|
36 |
dbQueriesChan <- newChan |
3425 | 37 |
coreChan' <- newChan |
38 |
serverInfo' <- getOpts $ newServerInfo stats' coreChan' dbQueriesChan |
|
3435 | 39 |
|
1964 | 40 |
#if defined(OFFICIAL_SERVER) |
2867
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2349
diff
changeset
|
41 |
dbHost' <- askFromConsole "DB host: " |
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2349
diff
changeset
|
42 |
dbLogin' <- askFromConsole "login: " |
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2349
diff
changeset
|
43 |
dbPassword' <- askFromConsole "password: " |
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2349
diff
changeset
|
44 |
let serverInfo = serverInfo'{dbHost = dbHost', dbLogin = dbLogin', dbPassword = dbPassword'} |
1964 | 45 |
#else |
2867
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2349
diff
changeset
|
46 |
let serverInfo = serverInfo' |
1964 | 47 |
#endif |
48 |
||
2867
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2349
diff
changeset
|
49 |
Exception.bracket |
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2349
diff
changeset
|
50 |
(Network.listenOn $ Network.PortNumber $ listenPort serverInfo) |
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2349
diff
changeset
|
51 |
sClose |
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2349
diff
changeset
|
52 |
(startServer serverInfo) |