1
{-# LANGUAGE CPP, ScopedTypeVariables #-}
1
{-# LANGUAGE CPP, ScopedTypeVariables, OverloadedStrings #-}
5
5
import Network.Socket
6
import qualified Network
8
import Control.Concurrent.STM
9
7
import Control.Concurrent.Chan
10
#if defined(NEW_EXCEPTIONS)
11
import qualified Control.OldException as Exception
13
import qualified Control.Exception as Exception
8
import qualified Control.Exception as E
15
9
import System.Log.Logger
16
10
-----------------------------------
19
import OfficialServer.DBInteraction
14
#if defined(OFFICIAL_SERVER)
24
18
#if !defined(mingw32_HOST_OS)
25
19
import System.Posix
30
updateGlobalLogger "Clients"
33
main = withSocketsDo $ do
34
#if !defined(mingw32_HOST_OS)
35
installHandler sigPIPE Ignore Nothing;
36
installHandler sigCHLD Ignore Nothing;
41
stats <- atomically $ newTMVar (StatisticsInfo 0 0)
42
dbQueriesChan <- newChan
44
serverInfo' <- getOpts $ newServerInfo stats coreChan dbQueriesChan
46
#if defined(OFFICIAL_SERVER)
47
dbHost' <- askFromConsole "DB host: "
48
dbLogin' <- askFromConsole "login: "
49
dbPassword' <- askFromConsole "password: "
50
let serverInfo = serverInfo'{dbHost = dbHost', dbLogin = dbLogin', dbPassword = dbPassword'}
52
let serverInfo = serverInfo'
25
updateGlobalLogger "Clients" (setLevel NOTICE)
26
updateGlobalLogger "Core" (setLevel NOTICE)
29
server :: ServerInfo -> IO ()
56
31
proto <- getProtocolNumber "tcp"
58
33
(socket AF_INET Stream proto)
61
36
setSocketOption sock ReuseAddr 1
62
bindSocket sock (SockAddrInet (listenPort serverInfo) iNADDR_ANY)
37
bindSocket sock (SockAddrInet (listenPort si) iNADDR_ANY)
63
38
listen sock maxListenQueue
64
startServer serverInfo sock
39
startServer si{serverSocket = Just sock}
42
handleRestart :: ShutdownException -> IO ()
43
handleRestart ShutdownException = do
44
noticeM "Core" "Shutting down"
48
main = withSocketsDo $ do
49
#if !defined(mingw32_HOST_OS)
50
_ <- installHandler sigPIPE Ignore Nothing
51
_ <- installHandler sigCHLD Ignore Nothing
56
dbQueriesChan <- newChan
58
serverInfo' <- getOpts $ newServerInfo coreChan' dbQueriesChan Nothing Nothing
60
#if defined(OFFICIAL_SERVER)
61
si <- readServerConfig serverInfo'
66
(server si) `E.catch` handleRestart