From 0db9a18d39cfaad2e4e6c150af84c4ad3684c8d3 Mon Sep 17 00:00:00 2001 From: JoshuaJB Date: Sat, 25 Jan 2014 21:58:22 +0000 Subject: [PATCH] Fix issue where lobby spam was being sent to external clients. This was SVN commit r14672. --- binaries/data/mods/public/gui/lobby/lobby.js | 34 ++++++++++++++------ 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/binaries/data/mods/public/gui/lobby/lobby.js b/binaries/data/mods/public/gui/lobby/lobby.js index ee64ba6991..3f74a1cee0 100644 --- a/binaries/data/mods/public/gui/lobby/lobby.js +++ b/binaries/data/mods/public/gui/lobby/lobby.js @@ -572,7 +572,7 @@ function submitChatInput() var text = escapeText(input.caption); if (text.length) { - if (!handleSpecialCommand(text)) + if (!handleSpecialCommand(text) && !isSpam(text, g_Name)) Engine.LobbySendMessage(text); input.caption = ""; } @@ -666,7 +666,8 @@ function addChatMessage(msg) msg.text = msg.text.replace(new RegExp('\\b' + '\\' + g_Name + '\\b', "g"), colorPlayerName(g_Name)); // Run spam test - if (updateSpamandDetect(msg.text, msg.from)) + updateSpamMonitor(msg.from); + if (isSpam(msg.text, msg.from)) return; // Format Text @@ -737,22 +738,37 @@ function ircFormat(text, from, color, key) } /** - * Track potential spammers and block if nessasary. + * Update the spam monitor. * - * @param text Body of message. - * @param from Sender of message. - * @return True is message should be blocked. + * @param from User to update. */ -function updateSpamandDetect(text, from) +function updateSpamMonitor(from) { // Integer time in seconds. var time = Math.floor(Date.now() / 1000); - // Update or initialize the player in the spam monitor. + // Update or initialize the user in the spam monitor. if (g_spamMonitor[from]) g_spamMonitor[from][0]++; else g_spamMonitor[from] = [1, time, 0]; +} + +/** + * Check if a message is spam. + * + * @param text Body of message. + * @param from Sender of message. + * @return True if message should be blocked. + */ +function isSpam(text, from) +{ + // Integer time in seconds. + var time = Math.floor(Date.now() / 1000); + + // Initialize if not already in the database. + if (!g_spamMonitor[from]) + g_spamMonitor[from] = [1, time, 0]; // Block blank lines. if (text == " ") @@ -761,7 +777,7 @@ function updateSpamandDetect(text, from) else if (g_spamMonitor[from][2] + SPAM_BLOCK_LENGTH >= time) return true; // Block users who exceed the rate of 1 message per second for five seconds and are not already blocked. TODO: Make this smarter and block profanity. - else if (g_spamMonitor[from][0] == 5) + else if (g_spamMonitor[from][0] == 6) { g_spamMonitor[from][2] = time; if (from == g_Name)