Defer kicking to the time when everything is in consistent state
authorunc0rr
Mon, 28 Dec 2015 21:51:12 +0300
changeset 11471 4b5c7a5c49fd
parent 11470 0ae2e4c13bd1
child 11472 f2c36df8c7b1
Defer kicking to the time when everything is in consistent state
gameServer/CoreTypes.hs
gameServer/FloodDetection.hs
gameServer/HWProtoCore.hs
gameServer/NetRoutines.hs
gameServer/ServerCore.hs
--- a/gameServer/CoreTypes.hs	Mon Dec 28 21:21:02 2015 +0300
+++ b/gameServer/CoreTypes.hs	Mon Dec 28 21:51:12 2015 +0300
@@ -152,7 +152,8 @@
         eiLobbyChat,
         eiEM,
         eiJoin :: !EventsInfo,
-        teamsInGame :: !Word
+        teamsInGame :: !Word,
+        pendingActions :: ![Action]
     }
 
 instance Eq ClientInfo where
--- a/gameServer/FloodDetection.hs	Mon Dec 28 21:21:02 2015 +0300
+++ b/gameServer/FloodDetection.hs	Mon Dec 28 21:51:12 2015 +0300
@@ -49,7 +49,7 @@
     chat1 = [Warning $ loc "Warning! Chat flood protection activated"]
     chat2 = [ByeClient $ loc "Excess flood"]
     em1 = [Warning $ loc "Game messages flood detected - 1"]
-    em2 = [Warning $ loc "Game messages flood detected - 2"]
+    em2 = [ByeClient $ loc "Excess flood"]
     join1 = [Warning $ loc "Warning! Joins flood protection activated"]
     join2 = [ByeClient $ loc "Excess flood"]
 
@@ -69,7 +69,9 @@
                     else
                     []
 
-        return $ (ModifyClient . transformField e . const $ (numPerEntry, curTime) : nei) : actions
+        return $ [ModifyClient . transformField e . const $ (numPerEntry, curTime) : nei
+                , ModifyClient (\c -> c{pendingActions = actions}) -- append? prepend? just replacing for now
+            ]
 
     updateInfo = return [
         ModifyClient $ transformField e
--- a/gameServer/HWProtoCore.hs	Mon Dec 28 21:21:02 2015 +0300
+++ b/gameServer/HWProtoCore.hs	Mon Dec 28 21:51:12 2015 +0300
@@ -94,9 +94,12 @@
         h "RESTART_SERVER" "YES" = handleCmd ["RESTART_SERVER"]
         h "REGISTERED_ONLY" _ = do
             cl <- thisClient
-            return [ModifyServerInfo(\s -> s{isRegisteredUsersOnly = not $ isRegisteredUsersOnly s})
+            return $ if isAdministrator cl then 
+                [ModifyServerInfo(\s -> s{isRegisteredUsersOnly = not $ isRegisteredUsersOnly s})
                 , AnswerClients [sendChan cl] ["CHAT", "[server]", "'Registered only' state toggled"]
                 ]
+                else
+                []
         h c p = return [Warning $ B.concat ["Unknown cmd: /", c, " ", p]]
 
         extractParameters p = let (a, b) = B.break (== ' ') p in (upperCase a, B.dropWhile (== ' ') b)
--- a/gameServer/NetRoutines.hs	Mon Dec 28 21:21:02 2015 +0300
+++ b/gameServer/NetRoutines.hs	Mon Dec 28 21:51:12 2015 +0300
@@ -79,6 +79,7 @@
                     newEventsInfo
                     newEventsInfo
                     0
+                    []
                     )
 
         writeChan chan $ Accept newClient
--- a/gameServer/ServerCore.hs	Mon Dec 28 21:21:02 2015 +0300
+++ b/gameServer/ServerCore.hs	Mon Dec 28 21:51:12 2015 +0300
@@ -23,7 +23,7 @@
 import System.Log.Logger
 import Control.Monad.Reader
 import Control.Monad.State.Strict
-import Data.Set as Set
+import Data.Set as Set hiding (null)
 import Data.Unique
 import Data.Maybe
 --------------------------------------
@@ -55,6 +55,10 @@
             unless (ci `Set.member` removed) $ do
                 modify (\s -> s{clientIndex = Just ci})
                 processAction $ ReactCmd cmd
+                pa <- client's pendingActions
+                when (not $ null pa) $ do
+                    mapM_ processAction pa
+                    processAction $ ModifyClient $ \c -> c{pendingActions = []}
 
         Remove ci ->
             processAction (DeleteClient ci)