Opened 9 years ago

Closed 7 years ago

#3260 closed enhancement (wontfix)

Spamfilter for gamesetup (and ready button spam)

Reported by: elexis Owned by:
Priority: Nice to Have Milestone:
Component: UI & Simulation Keywords:
Cc: Patch:

Description (last modified by elexis)

Ready-button spam: Many people abuse the ready button by clicking it more than 20 times in order to scroll any chat messages away (mostly with the idea that this would make the game start faster).

Other spam is rarely seen, however it would appear more frequently if that ready-button spam would be fixed. Therefore a more general spam filter is required.

Luckily there already is a spam filter function in lobby.js:

	if (isSpam(msg.text, msg.from))
		return;
/**
 * Update the spam monitor.
 *
 * @param from User to update.
 */
function updateSpamMonitor(from)
{
	// Integer time in seconds.
	var time = Math.floor(Date.now() / 1000);

	// 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 == " ")
		return true;
	// Block users who are still within their spam block period.
	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] == 6)
	{
		g_spamMonitor[from][2] = time;
		if (from == g_Name)
			addChatMessage({ "from": "system", "text": translate("Please do not spam. You have been blocked for thirty seconds.") });
		return true;
	}
	// Return false if everything is clear.
	else
		return false;
}

This function should be moved into a spam.js file.

Change History (3)

comment:1 by elexis, 9 years ago

That "Block blank lines" part must use a trim():

// Block blank lines.
if (text.trim() == "")
      return true;

Chat messages might be trimmed on the right side using

string.replace(/\s+$/g, '');

so that one can still insert 40 spaces on the left side, in order to write on the right side of the screen... Correct me if I'm wrong and if that should be prohibited too...

comment:2 by historic_bruno, 9 years ago

Ideally spam blocking would be implemented by the server, not the client, since clients can send whatever they want.

comment:3 by elexis, 7 years ago

Description: modified (diff)
Keywords: simple removed
Milestone: Backlog
Resolution: wontfix
Status: newclosed

Not needed anymore since the kick feature IMO.

Note: See TracTickets for help on using tickets.