author | unc0rr |
Sun, 27 Feb 2011 19:32:14 +0300 | |
changeset 4960 | 3b54b1c9b768 |
parent 4957 | 3684faf5b3d1 |
child 4962 | 705c6186ad9d |
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 |
4960 | 8 |
import qualified Control.Exception as E |
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 |
|
4960 | 29 |
|
30 |
server :: ServerInfo -> IO () |
|
31 |
server si = do |
|
32 |
proto <- getProtocolNumber "tcp" |
|
33 |
E.bracket |
|
34 |
(socket AF_INET Stream proto) |
|
35 |
sClose |
|
36 |
(\sock -> do |
|
37 |
setSocketOption sock ReuseAddr 1 |
|
38 |
bindSocket sock (SockAddrInet (listenPort si) iNADDR_ANY) |
|
39 |
listen sock maxListenQueue |
|
40 |
startServer si sock |
|
41 |
) |
|
42 |
||
43 |
handleRestart :: ShutdownException -> IO () |
|
44 |
handleRestart ShutdownException = return () |
|
45 |
handleRestart RestartException = do |
|
46 |
||
47 |
return () |
|
48 |
||
4905 | 49 |
main :: IO () |
1804 | 50 |
main = withSocketsDo $ do |
51 |
#if !defined(mingw32_HOST_OS) |
|
4932 | 52 |
_ <- installHandler sigPIPE Ignore Nothing |
53 |
_ <- installHandler sigCHLD Ignore Nothing |
|
1804 | 54 |
#endif |
55 |
||
2867
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2349
diff
changeset
|
56 |
setupLoggers |
1804 | 57 |
|
2867
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2349
diff
changeset
|
58 |
dbQueriesChan <- newChan |
4905 | 59 |
coreChan' <- newChan |
4957 | 60 |
serverInfo' <- getOpts $ newServerInfo coreChan' dbQueriesChan |
4905 | 61 |
|
1964 | 62 |
#if defined(OFFICIAL_SERVER) |
2867
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2349
diff
changeset
|
63 |
dbHost' <- askFromConsole "DB host: " |
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2349
diff
changeset
|
64 |
dbLogin' <- askFromConsole "login: " |
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2349
diff
changeset
|
65 |
dbPassword' <- askFromConsole "password: " |
4960 | 66 |
let si = serverInfo'{dbHost = dbHost', dbLogin = dbLogin', dbPassword = dbPassword'} |
1964 | 67 |
#else |
4960 | 68 |
let si = serverInfo' |
1964 | 69 |
#endif |
70 |
||
4960 | 71 |
(server si) `E.catch` handleRestart |