1 {-# LANGUAGE CPP, ScopedTypeVariables #-} |
1 {-# LANGUAGE CPP, ScopedTypeVariables #-} |
2 |
2 |
3 module Main where |
3 module Main where |
4 |
4 |
5 import Network |
5 import Network.Socket |
|
6 import qualified Network |
6 import Control.Concurrent.STM |
7 import Control.Concurrent.STM |
7 import Control.Concurrent.Chan |
8 import Control.Concurrent.Chan |
|
9 #if defined(NEW_EXCEPTIONS) |
|
10 import qualified Control.OldException as Exception |
|
11 #else |
8 import qualified Control.Exception as Exception |
12 import qualified Control.Exception as Exception |
|
13 #endif |
9 import System.Log.Logger |
14 import System.Log.Logger |
10 ----------------------------------- |
15 ----------------------------------- |
11 import Opts |
16 import Opts |
12 import CoreTypes |
17 import CoreTypes |
|
18 import OfficialServer.DBInteraction |
13 import ServerCore |
19 import ServerCore |
|
20 import Utils |
14 |
21 |
15 |
22 |
16 #if !defined(mingw32_HOST_OS) |
23 #if !defined(mingw32_HOST_OS) |
17 import System.Posix |
24 import System.Posix |
18 #endif |
25 #endif |
19 |
26 |
20 |
27 |
21 setupLoggers :: IO () |
|
22 setupLoggers = |
28 setupLoggers = |
23 updateGlobalLogger "Clients" |
29 updateGlobalLogger "Clients" |
24 (setLevel INFO) |
30 (setLevel INFO) |
25 |
31 |
26 main :: IO () |
|
27 main = withSocketsDo $ do |
32 main = withSocketsDo $ do |
28 #if !defined(mingw32_HOST_OS) |
33 #if !defined(mingw32_HOST_OS) |
29 installHandler sigPIPE Ignore Nothing; |
34 installHandler sigPIPE Ignore Nothing; |
30 installHandler sigCHLD Ignore Nothing; |
35 installHandler sigCHLD Ignore Nothing; |
31 #endif |
36 #endif |
32 |
37 |
33 setupLoggers |
38 setupLoggers |
34 |
39 |
35 stats' <- atomically $ newTMVar (StatisticsInfo 0 0) |
40 stats <- atomically $ newTMVar (StatisticsInfo 0 0) |
36 dbQueriesChan <- newChan |
41 dbQueriesChan <- newChan |
37 coreChan' <- newChan |
42 coreChan <- newChan |
38 serverInfo' <- getOpts $ newServerInfo stats' coreChan' dbQueriesChan |
43 serverInfo' <- getOpts $ newServerInfo stats coreChan dbQueriesChan |
39 |
44 |
40 #if defined(OFFICIAL_SERVER) |
45 #if defined(OFFICIAL_SERVER) |
41 dbHost' <- askFromConsole "DB host: " |
46 dbHost' <- askFromConsole "DB host: " |
42 dbLogin' <- askFromConsole "login: " |
47 dbLogin' <- askFromConsole "login: " |
43 dbPassword' <- askFromConsole "password: " |
48 dbPassword' <- askFromConsole "password: " |
44 let serverInfo = serverInfo'{dbHost = dbHost', dbLogin = dbLogin', dbPassword = dbPassword'} |
49 let serverInfo = serverInfo'{dbHost = dbHost', dbLogin = dbLogin', dbPassword = dbPassword'} |