author | unc0rr |
Sat, 05 Feb 2011 11:32:15 +0300 | |
changeset 4918 | c6d3aec73f93 |
parent 4905 | 7842d085acf4 |
child 4921 | 2efad3acbb74 |
permissions | -rw-r--r-- |
2348 | 1 |
{-# LANGUAGE CPP, ScopedTypeVariables #-} |
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 |
|
15 |
||
16 |
||
17 |
#if !defined(mingw32_HOST_OS) |
|
18 |
import System.Posix |
|
19 |
#endif |
|
20 |
||
21 |
||
4905 | 22 |
setupLoggers :: IO () |
1804 | 23 |
setupLoggers = |
2867
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2349
diff
changeset
|
24 |
updateGlobalLogger "Clients" |
3947
709fdb89f76c
Some screwing around in try to fix space leak. No luck yet.
unc0rr
parents:
3500
diff
changeset
|
25 |
(setLevel INFO) |
1804 | 26 |
|
4905 | 27 |
main :: IO () |
1804 | 28 |
main = withSocketsDo $ do |
29 |
#if !defined(mingw32_HOST_OS) |
|
2867
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2349
diff
changeset
|
30 |
installHandler sigPIPE Ignore Nothing; |
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2349
diff
changeset
|
31 |
installHandler sigCHLD Ignore Nothing; |
1804 | 32 |
#endif |
33 |
||
2867
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2349
diff
changeset
|
34 |
setupLoggers |
1804 | 35 |
|
4905 | 36 |
stats' <- atomically $ newTMVar (StatisticsInfo 0 0) |
2867
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2349
diff
changeset
|
37 |
dbQueriesChan <- newChan |
4905 | 38 |
coreChan' <- newChan |
39 |
serverInfo' <- getOpts $ newServerInfo stats' coreChan' dbQueriesChan |
|
40 |
||
1964 | 41 |
#if defined(OFFICIAL_SERVER) |
2867
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2349
diff
changeset
|
42 |
dbHost' <- askFromConsole "DB host: " |
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2349
diff
changeset
|
43 |
dbLogin' <- askFromConsole "login: " |
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2349
diff
changeset
|
44 |
dbPassword' <- askFromConsole "password: " |
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2349
diff
changeset
|
45 |
let serverInfo = serverInfo'{dbHost = dbHost', dbLogin = dbLogin', dbPassword = dbPassword'} |
1964 | 46 |
#else |
2867
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2349
diff
changeset
|
47 |
let serverInfo = serverInfo' |
1964 | 48 |
#endif |
49 |
||
4568 | 50 |
|
51 |
proto <- getProtocolNumber "tcp" |
|
2867
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2349
diff
changeset
|
52 |
Exception.bracket |
4568 | 53 |
(socket AF_INET Stream proto) |
2867
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2349
diff
changeset
|
54 |
sClose |
4568 | 55 |
(\sock -> do |
56 |
setSocketOption sock ReuseAddr 1 |
|
57 |
bindSocket sock (SockAddrInet (listenPort serverInfo) iNADDR_ANY) |
|
58 |
listen sock maxListenQueue |
|
59 |
startServer serverInfo sock |
|
60 |
) |