Opened 9 years ago

Last modified 7 years ago

#3260 closed enhancement

Spamfilter for gamesetup (and ready button spam) — at Initial Version

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

Description

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 (0)

Note: See TracTickets for help on using tickets.