Index: binaries/data/mods/public/gui/lobby/lobby.js =================================================================== --- binaries/data/mods/public/gui/lobby/lobby.js +++ binaries/data/mods/public/gui/lobby/lobby.js @@ -75,9 +75,28 @@ var g_ChatCommandColor = "200 200 255"; /** - * All chat messages received since init (i.e. after lobby join and after returning from a game). + * All chat messages received since init (i.e. after lobby join and after returning from a game), spam count and spam timer. */ -var g_ChatMessages = []; +var g_Chat = { + "messages": [], + "spamCount": 0, + "spamTimer": 0, + "spamHit": () => { + if (g_Chat.spamCount <= 3) + return false; + + g_Chat.spamCount += 3; + + addChatMessage({ + "from": "system", + "text": sprintf(translate("Don't spam. Wait %(seconds)s seconds now."), { + "seconds": g_Chat.spamCount - 3 + }) + }); + + return true; + } +}; /** * Rating of the current user. @@ -1199,6 +1218,21 @@ updatePlayerList(); } +/* + * Spam filter counter reduce function per timeout. + */ +function chatSpamTimer() +{ + if (g_Chat.spamCount == 0) + { + g_Chat.spamTimer = 0; + return; + } + + --g_Chat.spamCount; + return setTimeout(chatSpamTimer, 1000); +} + /** * Executes a lobby command or sends GUI input directly as chat. */ @@ -1207,11 +1241,15 @@ let input = Engine.GetGUIObjectByName("chatInput"); let text = input.caption; - if (!text.length) + if (!text.length || g_Chat.spamHit()) return; if (handleChatCommand(text)) + { Engine.LobbySendMessage(text); + ++g_Chat.spamCount; + g_Chat.spamTimer = g_Chat.spamTimer || chatSpamTimer(); + } input.caption = ""; } @@ -1283,8 +1321,8 @@ if (!formatted) return; - g_ChatMessages.push(formatted); - Engine.GetGUIObjectByName("chatText").caption = g_ChatMessages.join("\n"); + g_Chat.messages.push(formatted); + Engine.GetGUIObjectByName("chatText").caption = g_Chat.messages.join("\n"); } /**