author sheepluva
Wed, 27 Apr 2016 16:20:59 +0200
changeset 11744 ac58a063d26a
parent 11046 47a8c19ecb60
child 15699 27eb5abd5058
permissions -rw-r--r--
Added "Forts" to map type selection. This makes the mode easier selectable/discoverable. Also the slider can be used to adjust the distance between forts.

 * Hedgewars, a free turn based strategy game
 * Copyright (c) 2004-2015 Andrey Korotaev <>
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; version 2 of the License
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * GNU General Public License for more details.
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

{-# LANGUAGE CPP, ScopedTypeVariables, OverloadedStrings #-}

module Main where

import Network.Socket
import Network.BSD
import Control.Concurrent.Chan
import qualified Control.Exception as E
import System.Log.Logger
import Opts
import CoreTypes
import ServerCore
#if defined(OFFICIAL_SERVER)
import ConfigFile

#if !defined(mingw32_HOST_OS)
import System.Posix

setupLoggers :: IO ()
setupLoggers = do
    updateGlobalLogger "Clients" (setLevel NOTICE)
    updateGlobalLogger "Core" (setLevel NOTICE)
    updateGlobalLogger "REPLAYS" (setLevel NOTICE)

server :: ServerInfo -> IO ()
server si = do
    proto <- getProtocolNumber "tcp"
        (socket AF_INET Stream proto)
        (\sock -> do
            setSocketOption sock ReuseAddr 1
            bindSocket sock (SockAddrInet (listenPort si) iNADDR_ANY)
            listen sock maxListenQueue
            startServer si{serverSocket = Just sock}

handleRestart :: ShutdownException -> IO ()
handleRestart ShutdownException = do
    noticeM "Core" "Shutting down"
    return ()

main :: IO ()
main = withSocketsDo $ do
#if !defined(mingw32_HOST_OS)
    _ <- installHandler sigPIPE Ignore Nothing
    _ <- installHandler sigCHLD Ignore Nothing


    dbQueriesChan <- newChan
    coreChan' <- newChan
    serverInfo' <- getOpts $ newServerInfo coreChan' dbQueriesChan Nothing Nothing

#if defined(OFFICIAL_SERVER)
    si <- readServerConfig serverInfo'
    let si = serverInfo'

    (server si) `E.catch` handleRestart