gameServer/ServerCore.hs
changeset 3566 772a46ef8288
parent 3500 af8390d807d6
child 3657 fa3bf50d0338
--- a/gameServer/ServerCore.hs	Sat Jun 26 16:58:19 2010 +0400
+++ b/gameServer/ServerCore.hs	Sun Jun 27 21:06:41 2010 +0400
@@ -8,6 +8,7 @@
 import System.Log.Logger
 import Control.Monad.Reader
 import Control.Monad.State
+import Data.Set as Set
 import qualified Data.ByteString.Char8 as B
 --------------------------------------
 import CoreTypes
@@ -35,29 +36,27 @@
     r <- liftIO $ readChan $ coreChan si
 
     case r of
-        Accept ci -> do
-            processAction (AddClient ci)
-            return ()
+        Accept ci -> processAction (AddClient ci)
 
         ClientMessage (ci, cmd) -> do
             liftIO $ debugM "Clients" $ (show ci) ++ ": " ++ (show cmd)
-            modify (\as -> as{clientIndex = Just ci})
-            --if clID `IntMap.member` clients then
-            reactCmd cmd
-            return ()
+
+            removed <- gets removedClients
+            when (not $ ci `Set.member` removed) $ do
+                modify (\as -> as{clientIndex = Just ci})
+                reactCmd cmd
+
+        Remove ci -> processAction (DeleteClient ci)
+
                 --else
                 --do
                 --debugM "Clients" "Message from dead client"
                 --return (serverInfo, rnc)
 
-        ClientAccountInfo (clID, info) -> do
-            --if clID `IntMap.member` clients then
-            processAction (ProcessAccountInfo info)
-            return ()
-                --else
-                --do
-                --debugM "Clients" "Got info for dead client"
-                --return (serverInfo, rnc)
+        ClientAccountInfo (ci, info) -> do
+            removed <- gets removedClients
+            when (not $ ci `Set.member` removed) $
+                processAction (ProcessAccountInfo info)
 
         TimerAction tick ->
             return ()
@@ -65,10 +64,6 @@
             --    foldM processAction (0, serverInfo, rnc) $
             --        PingAll : [StatsAction | even tick]
 
-        FreeClient ci -> do
-            rnc <- gets roomsClients
-            liftIO $ removeClient rnc ci
-
 
 startServer :: ServerInfo -> Socket -> IO ()
 startServer serverInfo serverSocket = do
@@ -87,6 +82,6 @@
 
     rnc <- newRoomsAndClients newRoom
 
-    forkIO $ evalStateT mainLoop (ServerState Nothing serverInfo rnc)
+    forkIO $ evalStateT mainLoop (ServerState Nothing serverInfo Set.empty rnc)
 
     forever $ threadDelay (60 * 60 * 10^6) >> putStrLn "***"