Don't forkIO main loop
authorunc0rr
Wed, 23 Feb 2011 18:34:07 +0300
changeset 4955 84543ecae8c3
parent 4952 df752b69a142
child 4957 3684faf5b3d1
Don't forkIO main loop
gameServer/Actions.hs
gameServer/CoreTypes.hs
gameServer/ServerCore.hs
--- a/gameServer/Actions.hs	Sat Feb 19 04:04:34 2011 +0100
+++ b/gameServer/Actions.hs	Wed Feb 23 18:34:07 2011 +0300
@@ -53,6 +53,7 @@
     | StatsAction
     | RestartServer Bool
 
+
 type CmdHandler = [B.ByteString] -> Reader (ClientIndex, IRnC) [Action]
 
 instance NFData Action where
@@ -412,5 +413,8 @@
     where
           st irnc = (length $ allRooms irnc, length $ allClients irnc)
 
-processAction (RestartServer _) =
-    return ()
\ No newline at end of file
+processAction (RestartServer force) = do
+    if force then do
+        return ()
+        else
+        processAction $ ModifyServerInfo (\s -> s{restartPending=True})
--- a/gameServer/CoreTypes.hs	Sat Feb 19 04:04:34 2011 +0100
+++ b/gameServer/CoreTypes.hs	Wed Feb 23 18:34:07 2011 +0300
@@ -135,6 +135,7 @@
         dbLogin :: B.ByteString,
         dbPassword :: B.ByteString,
         lastLogins :: [(B.ByteString, (UTCTime, B.ByteString))],
+        restartPending :: Bool,
         stats :: TMVar StatisticsInfo,
         coreChan :: Chan CoreMessage,
         dbQueries :: Chan DBQuery
@@ -156,6 +157,7 @@
         ""
         ""
         []
+        False
 
 data AccountInfo =
     HasAccount B.ByteString Bool
--- a/gameServer/ServerCore.hs	Sat Feb 19 04:04:34 2011 +0100
+++ b/gameServer/ServerCore.hs	Wed Feb 23 18:34:07 2011 +0300
@@ -32,7 +32,7 @@
 
 mainLoop :: StateT ServerState IO ()
 mainLoop = forever $ do
-    get >>= \s -> put $! s
+    -- get >>= \s -> put $! s
 
     si <- gets serverInfo
     r <- liftIO $ readChan $ coreChan si
@@ -53,11 +53,6 @@
             liftIO $ debugM "Clients"  $ "DeleteClient: " ++ show ci
             processAction (DeleteClient ci)
 
-                --else
-                --do
-                --debugM "Clients" "Message from dead client"
-                --return (serverInfo, rnc)
-
         ClientAccountInfo ci uid info -> do
             rnc <- gets roomsClients
             exists <- liftIO $ clientExists rnc ci
@@ -90,6 +85,4 @@
 
     rnc <- newRoomsAndClients newRoom
 
-    _ <- forkIO $ evalStateT mainLoop (ServerState Nothing si Set.empty rnc)
-
-    forever $ threadDelay 3600000000 -- one hour
+    evalStateT mainLoop (ServerState Nothing si Set.empty rnc)