author | unc0rr |
Sun, 06 Feb 2011 21:50:29 +0300 | |
changeset 4932 | f11d80bac7ed |
parent 4921 | 2efad3acbb74 |
child 4957 | 3684faf5b3d1 |
permissions | -rw-r--r-- |
4921 | 1 |
{-# LANGUAGE CPP, ScopedTypeVariables, OverloadedStrings #-} |
1804 | 2 |
|
3 |
module Main where |
|
4 |
||
4568 | 5 |
import Network.Socket |
6 |
import Network.BSD |
|
1804 | 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 |
import qualified Control.Exception as Exception |
1804 | 10 |
import System.Log.Logger |
11 |
----------------------------------- |
|
12 |
import Opts |
|
13 |
import CoreTypes |
|
14 |
import ServerCore |
|
4921 | 15 |
#if defined(OFFICIAL_SERVER) |
16 |
import Utils |
|
17 |
#endif |
|
1804 | 18 |
|
19 |
||
20 |
#if !defined(mingw32_HOST_OS) |
|
21 |
import System.Posix |
|
22 |
#endif |
|
23 |
||
24 |
||
4905 | 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" |
3947
709fdb89f76c
Some screwing around in try to fix space leak. No luck yet.
unc0rr
parents:
3500
diff
changeset
|
28 |
(setLevel INFO) |
1804 | 29 |
|
4905 | 30 |
main :: IO () |
1804 | 31 |
main = withSocketsDo $ do |
32 |
#if !defined(mingw32_HOST_OS) |
|
4932 | 33 |
_ <- installHandler sigPIPE Ignore Nothing |
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 |
|
4905 | 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 |
4905 | 41 |
coreChan' <- newChan |
42 |
serverInfo' <- getOpts $ newServerInfo stats' coreChan' dbQueriesChan |
|
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 |
||
4568 | 53 |
|
54 |
proto <- getProtocolNumber "tcp" |
|
2867
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2349
diff
changeset
|
55 |
Exception.bracket |
4568 | 56 |
(socket AF_INET Stream proto) |
2867
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2349
diff
changeset
|
57 |
sClose |
4568 | 58 |
(\sock -> do |
59 |
setSocketOption sock ReuseAddr 1 |
|
60 |
bindSocket sock (SockAddrInet (listenPort serverInfo) iNADDR_ANY) |
|
61 |
listen sock maxListenQueue |
|
62 |
startServer serverInfo sock |
|
63 |
) |