author | unc0rr |
Wed, 05 May 2010 08:01:37 +0000 | |
changeset 3425 | ead2ed20dfd4 |
parent 2867 | 9be6693c78cb |
child 3435 | 4e4f88a7bdf2 |
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 |
||
25 |
setupLoggers = |
|
2867
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2349
diff
changeset
|
26 |
updateGlobalLogger "Clients" |
3425 | 27 |
(setLevel DEBUG) |
1804 | 28 |
|
29 |
main = withSocketsDo $ do |
|
30 |
#if !defined(mingw32_HOST_OS) |
|
2867
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2349
diff
changeset
|
31 |
installHandler sigPIPE Ignore Nothing; |
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2349
diff
changeset
|
32 |
installHandler sigCHLD Ignore Nothing; |
1804 | 33 |
#endif |
34 |
||
2867
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2349
diff
changeset
|
35 |
setupLoggers |
1804 | 36 |
|
3425 | 37 |
stats' <- atomically $ newTMVar (StatisticsInfo 0 0) |
2867
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2349
diff
changeset
|
38 |
dbQueriesChan <- newChan |
3425 | 39 |
coreChan' <- newChan |
40 |
serverInfo' <- getOpts $ newServerInfo stats' coreChan' dbQueriesChan |
|
2867
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2349
diff
changeset
|
41 |
|
1964 | 42 |
#if defined(OFFICIAL_SERVER) |
2867
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2349
diff
changeset
|
43 |
dbHost' <- askFromConsole "DB host: " |
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2349
diff
changeset
|
44 |
dbLogin' <- askFromConsole "login: " |
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2349
diff
changeset
|
45 |
dbPassword' <- askFromConsole "password: " |
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2349
diff
changeset
|
46 |
let serverInfo = serverInfo'{dbHost = dbHost', dbLogin = dbLogin', dbPassword = dbPassword'} |
1964 | 47 |
#else |
2867
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2349
diff
changeset
|
48 |
let serverInfo = serverInfo' |
1964 | 49 |
#endif |
50 |
||
2867
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2349
diff
changeset
|
51 |
Exception.bracket |
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2349
diff
changeset
|
52 |
(Network.listenOn $ Network.PortNumber $ listenPort serverInfo) |
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2349
diff
changeset
|
53 |
sClose |
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2349
diff
changeset
|
54 |
(startServer serverInfo) |