Limit room name change rate
authorunc0rr
Fri, 26 Apr 2019 23:21:27 +0200
changeset 14841 111c4d750c6d
parent 14840 b02581c5b0c5
child 14842 ef9630519491
Limit room name change rate
gameServer/CoreTypes.hs
gameServer/FloodDetection.hs
gameServer/HWProtoInRoomState.hs
--- a/gameServer/CoreTypes.hs	Thu Apr 25 23:01:30 2019 +0200
+++ b/gameServer/CoreTypes.hs	Fri Apr 26 23:21:27 2019 +0200
@@ -109,6 +109,7 @@
 data Event = LobbyChatMessage
            | EngineMessage
            | RoomJoin
+           | RoomNameUpdate
 
 type EventsInfo = [(Int, UTCTime)]
 
--- a/gameServer/FloodDetection.hs	Thu Apr 25 23:01:30 2019 +0200
+++ b/gameServer/FloodDetection.hs	Fri Apr 26 23:21:27 2019 +0200
@@ -36,15 +36,19 @@
     einfo LobbyChatMessage = eiLobbyChat
     einfo EngineMessage = eiEM
     einfo RoomJoin = eiJoin
+    einfo RoomNameUpdate = eiLobbyChat
 
     transformField LobbyChatMessage f = \c -> c{eiLobbyChat = f $ eiLobbyChat c}
     transformField EngineMessage f = \c -> c{eiEM = f $ eiEM c}
     transformField RoomJoin f = \c -> c{eiJoin = f $ eiJoin c}
+    transformField RoomNameUpdate f = transformField LobbyChatMessage f
+    
 
     boundaries :: Event -> (Int, (NominalDiffTime, Int), (NominalDiffTime, Int), ([Action], [Action]))
     boundaries LobbyChatMessage = (3, (10, 2), (30, 3), (chat1, chat2))
     boundaries EngineMessage = (8, (10, 4), (25, 5), (em1, em2))
     boundaries RoomJoin = (2, (10, 2), (35, 3), (join1, join2))
+    boundaries RoomNameUpdate = (\(a, b, c, _) -> (a, b, c, (roomName1, roomName2))) $ boundaries LobbyChatMessage
 
     chat1 = [Warning $ loc "Warning! Chat flood protection activated"]
     chat2 = [ByeClient $ loc "Excess flood"]
@@ -52,6 +56,8 @@
     em2 = [ByeClient $ loc "Excess flood"]
     join1 = [Warning $ loc "Warning! Joins flood protection activated"]
     join2 = [ByeClient $ loc "Excess flood"]
+    roomName1 = [Warning $ loc "Warning! Room name change flood protection activated"]
+    roomName2 = [ByeClient $ loc "Excess flood"]
 
     doCheck ei = do
         curTime <- io getCurrentTime
--- a/gameServer/HWProtoInRoomState.hs	Thu Apr 25 23:01:30 2019 +0200
+++ b/gameServer/HWProtoInRoomState.hs	Fri Apr 26 23:21:27 2019 +0200
@@ -326,7 +326,8 @@
             [Warning $ loc "A room with the same name already exists."]
         else
             [ModifyRoom roomUpdate,
-            AnswerClients chans ("ROOM" : "UPD" : name rm : roomInfo (clientProto cl) (nick cl) (roomUpdate rm))]
+            AnswerClients chans ("ROOM" : "UPD" : name rm : roomInfo (clientProto cl) (nick cl) (roomUpdate rm)),
+            RegisterEvent RoomNameUpdate]
     where
         roomUpdate r = r{name = newName}