author | mbait |
Thu, 06 May 2010 20:49:26 +0000 | |
changeset 3438 | 670324167e42 |
parent 3435 | 4e4f88a7bdf2 |
child 3500 | af8390d807d6 |
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 |
#if defined(NEW_EXCEPTIONS) |
19f2f76dc346
Patch for compiling with 6.10 (define NEW_EXCEPTIONS to do that)
unc0rr
parents:
2129
diff
changeset
|
9 |
import qualified Control.OldException as Exception |
19f2f76dc346
Patch for compiling with 6.10 (define NEW_EXCEPTIONS to do that)
unc0rr
parents:
2129
diff
changeset
|
10 |
#else |
19f2f76dc346
Patch for compiling with 6.10 (define NEW_EXCEPTIONS to do that)
unc0rr
parents:
2129
diff
changeset
|
11 |
import qualified Control.Exception as Exception |
19f2f76dc346
Patch for compiling with 6.10 (define NEW_EXCEPTIONS to do that)
unc0rr
parents:
2129
diff
changeset
|
12 |
#endif |
1804 | 13 |
import System.Log.Logger |
14 |
----------------------------------- |
|
15 |
import Opts |
|
16 |
import CoreTypes |
|
17 |
import ServerCore |
|
18 |
||
19 |
||
20 |
#if !defined(mingw32_HOST_OS) |
|
21 |
import System.Posix |
|
22 |
#endif |
|
23 |
||
24 |
||
3435 | 25 |
setupLoggers :: IO () |
1804 | 26 |
setupLoggers = |
2867
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2349
diff
changeset
|
27 |
updateGlobalLogger "Clients" |
3425 | 28 |
(setLevel DEBUG) |
1804 | 29 |
|
3435 | 30 |
main :: IO () |
1804 | 31 |
main = withSocketsDo $ do |
32 |
#if !defined(mingw32_HOST_OS) |
|
2867
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2349
diff
changeset
|
33 |
installHandler sigPIPE Ignore Nothing; |
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2349
diff
changeset
|
34 |
installHandler sigCHLD Ignore Nothing; |
1804 | 35 |
#endif |
36 |
||
2867
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2349
diff
changeset
|
37 |
setupLoggers |
1804 | 38 |
|
3425 | 39 |
stats' <- atomically $ newTMVar (StatisticsInfo 0 0) |
2867
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2349
diff
changeset
|
40 |
dbQueriesChan <- newChan |
3425 | 41 |
coreChan' <- newChan |
42 |
serverInfo' <- getOpts $ newServerInfo stats' coreChan' dbQueriesChan |
|
3435 | 43 |
|
1964 | 44 |
#if defined(OFFICIAL_SERVER) |
2867
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2349
diff
changeset
|
45 |
dbHost' <- askFromConsole "DB host: " |
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2349
diff
changeset
|
46 |
dbLogin' <- askFromConsole "login: " |
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2349
diff
changeset
|
47 |
dbPassword' <- askFromConsole "password: " |
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2349
diff
changeset
|
48 |
let serverInfo = serverInfo'{dbHost = dbHost', dbLogin = dbLogin', dbPassword = dbPassword'} |
1964 | 49 |
#else |
2867
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2349
diff
changeset
|
50 |
let serverInfo = serverInfo' |
1964 | 51 |
#endif |
52 |
||
2867
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2349
diff
changeset
|
53 |
Exception.bracket |
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2349
diff
changeset
|
54 |
(Network.listenOn $ Network.PortNumber $ listenPort serverInfo) |
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2349
diff
changeset
|
55 |
sClose |
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2349
diff
changeset
|
56 |
(startServer serverInfo) |