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