~ubuntu-branches/ubuntu/wily/hedgewars/wily

« back to all changes in this revision

Viewing changes to gameServer/hedgewars-server.hs

  • Committer: Package Import Robot
  • Author(s): Dmitry E. Oboukhov
  • Date: 2011-09-23 10:16:55 UTC
  • mfrom: (1.2.11 upstream)
  • Revision ID: package-import@ubuntu.com-20110923101655-3977th2gc5n0a3pv
Tags: 0.9.16-1
* New upstream version.
 + Downloadable content! Simply click to install any content.
   New voices, hats, maps, themes, translations, music, scripts...
   Hedgewars is now more customisable than ever before! As time goes
   by we will be soliciting community content to feature on this page,
   so remember to check it from time to time. If you decide you want
   to go back to standard Hedgewars, just remove the Data directory
   from your Hedgewars config directory.
 + 3-D rendering! Diorama-like rendering of the game in a variety
   of 3D modes. Let us know which ones work best for you, we didn't
   really have the equipment to test them all.
 + Resizable game window.
 + New utilities! The Time Box will remove one of your hedgehogs
   from the game for a while, protecting from attack until it returns,
   somewhere else on the map. Land spray will allow you to build bridges,
   seal up holes, or just make life unpleasant for your enemies.
 + New single player: Bamboo Thicket, That Sinking Feeling, Newton and
   the Tree and multi-player: The Specialists, Space Invaders,
   Racer - scripts! And a ton more script hooks for scripters
 + New twists on old weapons. Drill strike, seduction and fire have
   been adjusted. Defective mines have been added, rope can attach to
   hogs/crates/barrels again, grenades now have variable bounce (use
   precise key + 1-5). Portal gun is now more usable in flight and
   all game actions are a lot faster.
 + New theme - Golf, dozens of new community hats and a new
   localised Default voice, Ukranian.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
{-# LANGUAGE CPP, ScopedTypeVariables #-}
 
1
{-# LANGUAGE CPP, ScopedTypeVariables, OverloadedStrings #-}
2
2
 
3
3
module Main where
4
4
 
5
5
import Network.Socket
6
 
import qualified Network
7
6
import Network.BSD
8
 
import Control.Concurrent.STM
9
7
import Control.Concurrent.Chan
10
 
#if defined(NEW_EXCEPTIONS)
11
 
import qualified Control.OldException as Exception
12
 
#else
13
 
import qualified Control.Exception as Exception
14
 
#endif
 
8
import qualified Control.Exception as E
15
9
import System.Log.Logger
16
10
-----------------------------------
17
11
import Opts
18
12
import CoreTypes
19
 
import OfficialServer.DBInteraction
20
13
import ServerCore
21
 
import Utils
22
 
 
 
14
#if defined(OFFICIAL_SERVER)
 
15
import ConfigFile
 
16
#endif
23
17
 
24
18
#if !defined(mingw32_HOST_OS)
25
19
import System.Posix
26
20
#endif
27
21
 
28
22
 
29
 
setupLoggers =
30
 
    updateGlobalLogger "Clients"
31
 
        (setLevel INFO)
32
 
 
33
 
main = withSocketsDo $ do
34
 
#if !defined(mingw32_HOST_OS)
35
 
    installHandler sigPIPE Ignore Nothing;
36
 
    installHandler sigCHLD Ignore Nothing;
37
 
#endif
38
 
 
39
 
    setupLoggers
40
 
 
41
 
    stats <- atomically $ newTMVar (StatisticsInfo 0 0)
42
 
    dbQueriesChan <- newChan
43
 
    coreChan <- newChan
44
 
    serverInfo' <- getOpts $ newServerInfo stats coreChan dbQueriesChan
45
 
    
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'}
51
 
#else
52
 
    let serverInfo = serverInfo'
53
 
#endif
54
 
 
55
 
 
 
23
setupLoggers :: IO ()
 
24
setupLoggers = do
 
25
    updateGlobalLogger "Clients" (setLevel NOTICE)
 
26
    updateGlobalLogger "Core" (setLevel NOTICE)
 
27
 
 
28
 
 
29
server :: ServerInfo -> IO ()
 
30
server si = do
56
31
    proto <- getProtocolNumber "tcp"
57
 
    Exception.bracket
 
32
    E.bracket
58
33
        (socket AF_INET Stream proto)
59
34
        sClose
60
35
        (\sock -> do
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}
65
40
        )
 
41
 
 
42
handleRestart :: ShutdownException -> IO ()
 
43
handleRestart ShutdownException = do
 
44
    noticeM "Core" "Shutting down"
 
45
    return ()
 
46
 
 
47
main :: IO ()
 
48
main = withSocketsDo $ do
 
49
#if !defined(mingw32_HOST_OS)
 
50
    _ <- installHandler sigPIPE Ignore Nothing
 
51
    _ <- installHandler sigCHLD Ignore Nothing
 
52
#endif
 
53
 
 
54
    setupLoggers
 
55
 
 
56
    dbQueriesChan <- newChan
 
57
    coreChan' <- newChan
 
58
    serverInfo' <- getOpts $ newServerInfo coreChan' dbQueriesChan Nothing Nothing
 
59
 
 
60
#if defined(OFFICIAL_SERVER)
 
61
    si <- readServerConfig serverInfo'
 
62
#else
 
63
    let si = serverInfo'
 
64
#endif
 
65
 
 
66
    (server si) `E.catch` handleRestart