--- a/gameServer/Actions.hs Thu Feb 24 22:01:36 2011 +0300
+++ b/gameServer/Actions.hs Sun Feb 27 19:32:14 2011 +0300
@@ -416,6 +416,6 @@
processAction (RestartServer force) = do
if force then do
- io $ throwIO ShutdownException
+ throw ShutdownException
else
processAction $ ModifyServerInfo (\s -> s{restartPending=True})
--- a/gameServer/CoreTypes.hs Thu Feb 24 22:01:36 2011 +0300
+++ b/gameServer/CoreTypes.hs Sun Feb 27 19:32:14 2011 +0300
@@ -193,7 +193,9 @@
| AdminLeft
deriving Enum
-data ShutdownException = ShutdownException
+data ShutdownException =
+ ShutdownException
+ | RestartException
deriving (Show, Typeable)
instance Exception ShutdownException
--- a/gameServer/hedgewars-server.hs Thu Feb 24 22:01:36 2011 +0300
+++ b/gameServer/hedgewars-server.hs Sun Feb 27 19:32:14 2011 +0300
@@ -5,7 +5,7 @@
import Network.Socket
import Network.BSD
import Control.Concurrent.Chan
-import qualified Control.Exception as Exception
+import qualified Control.Exception as E
import System.Log.Logger
-----------------------------------
import Opts
@@ -26,6 +26,26 @@
updateGlobalLogger "Clients"
(setLevel INFO)
+
+server :: ServerInfo -> IO ()
+server si = do
+ proto <- getProtocolNumber "tcp"
+ E.bracket
+ (socket AF_INET Stream proto)
+ sClose
+ (\sock -> do
+ setSocketOption sock ReuseAddr 1
+ bindSocket sock (SockAddrInet (listenPort si) iNADDR_ANY)
+ listen sock maxListenQueue
+ startServer si sock
+ )
+
+handleRestart :: ShutdownException -> IO ()
+handleRestart ShutdownException = return ()
+handleRestart RestartException = do
+
+ return ()
+
main :: IO ()
main = withSocketsDo $ do
#if !defined(mingw32_HOST_OS)
@@ -43,19 +63,9 @@
dbHost' <- askFromConsole "DB host: "
dbLogin' <- askFromConsole "login: "
dbPassword' <- askFromConsole "password: "
- let serverInfo = serverInfo'{dbHost = dbHost', dbLogin = dbLogin', dbPassword = dbPassword'}
+ let si = serverInfo'{dbHost = dbHost', dbLogin = dbLogin', dbPassword = dbPassword'}
#else
- let serverInfo = serverInfo'
+ let si = serverInfo'
#endif
-
- proto <- getProtocolNumber "tcp"
- Exception.bracket
- (socket AF_INET Stream proto)
- sClose
- (\sock -> do
- setSocketOption sock ReuseAddr 1
- bindSocket sock (SockAddrInet (listenPort serverInfo) iNADDR_ANY)
- listen sock maxListenQueue
- startServer serverInfo sock
- )
+ (server si) `E.catch` handleRestart