author | sheepluva |
Fri, 31 Dec 2010 23:09:06 +0100 | |
changeset 4799 | 0f408159a33f |
parent 4568 | f85243bf890e |
child 4904 | 0eab727d4717 |
permissions | -rw-r--r-- |
2348 | 1 |
{-# LANGUAGE CPP, ScopedTypeVariables #-} |
1804 | 2 |
|
3 |
module Main where |
|
4 |
||
4568 | 5 |
import Network.Socket |
6 |
import qualified Network |
|
7 |
import Network.BSD |
|
1804 | 8 |
import Control.Concurrent.STM |
9 |
import Control.Concurrent.Chan |
|
4568 | 10 |
#if defined(NEW_EXCEPTIONS) |
11 |
import qualified Control.OldException as Exception |
|
12 |
#else |
|
2296
19f2f76dc346
Patch for compiling with 6.10 (define NEW_EXCEPTIONS to do that)
unc0rr
parents:
2129
diff
changeset
|
13 |
import qualified Control.Exception as Exception |
4568 | 14 |
#endif |
1804 | 15 |
import System.Log.Logger |
16 |
----------------------------------- |
|
17 |
import Opts |
|
18 |
import CoreTypes |
|
4568 | 19 |
import OfficialServer.DBInteraction |
1804 | 20 |
import ServerCore |
4568 | 21 |
import Utils |
1804 | 22 |
|
23 |
||
24 |
#if !defined(mingw32_HOST_OS) |
|
25 |
import System.Posix |
|
26 |
#endif |
|
27 |
||
28 |
||
29 |
setupLoggers = |
|
2867
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2349
diff
changeset
|
30 |
updateGlobalLogger "Clients" |
3947
709fdb89f76c
Some screwing around in try to fix space leak. No luck yet.
unc0rr
parents:
3500
diff
changeset
|
31 |
(setLevel INFO) |
1804 | 32 |
|
33 |
main = withSocketsDo $ do |
|
34 |
#if !defined(mingw32_HOST_OS) |
|
2867
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2349
diff
changeset
|
35 |
installHandler sigPIPE Ignore Nothing; |
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2349
diff
changeset
|
36 |
installHandler sigCHLD Ignore Nothing; |
1804 | 37 |
#endif |
38 |
||
2867
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2349
diff
changeset
|
39 |
setupLoggers |
1804 | 40 |
|
4568 | 41 |
stats <- atomically $ newTMVar (StatisticsInfo 0 0) |
2867
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2349
diff
changeset
|
42 |
dbQueriesChan <- newChan |
4568 | 43 |
coreChan <- newChan |
44 |
serverInfo' <- getOpts $ newServerInfo stats coreChan dbQueriesChan |
|
45 |
||
1964 | 46 |
#if defined(OFFICIAL_SERVER) |
2867
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2349
diff
changeset
|
47 |
dbHost' <- askFromConsole "DB host: " |
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2349
diff
changeset
|
48 |
dbLogin' <- askFromConsole "login: " |
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2349
diff
changeset
|
49 |
dbPassword' <- askFromConsole "password: " |
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2349
diff
changeset
|
50 |
let serverInfo = serverInfo'{dbHost = dbHost', dbLogin = dbLogin', dbPassword = dbPassword'} |
1964 | 51 |
#else |
2867
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2349
diff
changeset
|
52 |
let serverInfo = serverInfo' |
1964 | 53 |
#endif |
54 |
||
4568 | 55 |
|
56 |
proto <- getProtocolNumber "tcp" |
|
2867
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2349
diff
changeset
|
57 |
Exception.bracket |
4568 | 58 |
(socket AF_INET Stream proto) |
2867
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2349
diff
changeset
|
59 |
sClose |
4568 | 60 |
(\sock -> do |
61 |
setSocketOption sock ReuseAddr 1 |
|
62 |
bindSocket sock (SockAddrInet (listenPort serverInfo) iNADDR_ANY) |
|
63 |
listen sock maxListenQueue |
|
64 |
startServer serverInfo sock |
|
65 |
) |