author | unc0rr |
Wed, 23 Feb 2011 18:38:11 +0300 | |
changeset 4957 | 3684faf5b3d1 |
parent 4932 | f11d80bac7ed |
child 4960 | 3b54b1c9b768 |
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.Chan |
2296
19f2f76dc346
Patch for compiling with 6.10 (define NEW_EXCEPTIONS to do that)
unc0rr
parents:
2129
diff
changeset
|
8 |
import qualified Control.Exception as Exception |
1804 | 9 |
import System.Log.Logger |
10 |
----------------------------------- |
|
11 |
import Opts |
|
12 |
import CoreTypes |
|
13 |
import ServerCore |
|
4921 | 14 |
#if defined(OFFICIAL_SERVER) |
15 |
import Utils |
|
16 |
#endif |
|
1804 | 17 |
|
18 |
||
19 |
#if !defined(mingw32_HOST_OS) |
|
20 |
import System.Posix |
|
21 |
#endif |
|
22 |
||
23 |
||
4905 | 24 |
setupLoggers :: IO () |
1804 | 25 |
setupLoggers = |
2867
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2349
diff
changeset
|
26 |
updateGlobalLogger "Clients" |
3947
709fdb89f76c
Some screwing around in try to fix space leak. No luck yet.
unc0rr
parents:
3500
diff
changeset
|
27 |
(setLevel INFO) |
1804 | 28 |
|
4905 | 29 |
main :: IO () |
1804 | 30 |
main = withSocketsDo $ do |
31 |
#if !defined(mingw32_HOST_OS) |
|
4932 | 32 |
_ <- installHandler sigPIPE Ignore Nothing |
33 |
_ <- installHandler sigCHLD Ignore Nothing |
|
1804 | 34 |
#endif |
35 |
||
2867
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2349
diff
changeset
|
36 |
setupLoggers |
1804 | 37 |
|
2867
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2349
diff
changeset
|
38 |
dbQueriesChan <- newChan |
4905 | 39 |
coreChan' <- newChan |
4957 | 40 |
serverInfo' <- getOpts $ newServerInfo coreChan' dbQueriesChan |
4905 | 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 |
||
4568 | 51 |
|
52 |
proto <- getProtocolNumber "tcp" |
|
2867
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2349
diff
changeset
|
53 |
Exception.bracket |
4568 | 54 |
(socket AF_INET Stream proto) |
2867
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2349
diff
changeset
|
55 |
sClose |
4568 | 56 |
(\sock -> do |
57 |
setSocketOption sock ReuseAddr 1 |
|
58 |
bindSocket sock (SockAddrInet (listenPort serverInfo) iNADDR_ANY) |
|
59 |
listen sock maxListenQueue |
|
60 |
startServer serverInfo sock |
|
61 |
) |