View Full Version : "Lag" causes more than 1 database input

09-08-2009, 07:14 PM

I have a shoutbox which logs automatically in the database, if a user floods the shoutbox.

However, it logs it in the database more than once if a user floods the shoutbox way too fast.

1st time punishment > Kick
2nd time punishment > Kick
3rd time punishment > Mute

So if the user sends messages too fast, the bot will auto-message something like "X has been kicked for flooding", "X has been kicked for flooding" and "X has been muted for flooding" - at the same time.

Although, I only want the user to be punished once, and then another punishment if the user does it again.
Does anyone have any suggestions about doing this? I thought of something like:

Check if there's any database inputs with the same $user['id'] and if the `date` column (timestamp) is the exact same, then delete it/prevent the script from adding another input to the database?


09-08-2009, 11:53 PM
we need to see code! Otherwise your guess is as good as mine...

09-09-2009, 12:18 AM
I cut the script out. This is the anti-spam/flood part of it.

$kickTime = time() - 5;
$kickAmount = 4; // 4 shouts within 5 seconds = punish

$checkFlood = mysql_query("SELECT `id` FROM `shoutbox` WHERE `userid` = '".$user['id']."' AND `date` <= '".time()."' AND `date` > '".$kickTime."'") or die(mysql_error());
if(mysql_num_rows($checkFlood) >= $kickAmount){
$previousTime = time() - 300; // Checks for number of punishments within the last 5 minutes.
$getPrevious = mysql_query("SELECT `id` FROM `shoutbox_antispam` WHERE `userid` = '".$user['id']."' AND `date` >= '".$previousTime."'") or die(mysql_error());
if(mysql_num_rows($getPrevious) >= 2){
$muteUser = mysql_query("UPDATE `users` SET `mute` = '1', `muteend` = '".(time() + 600)."' WHERE `id` = '".$user['id']."'") or die(mysql_error());
$setDBMute = mysql_query("INSERT INTO `shoutbox_antispam` (`userid`,`date`,`action`) VALUES ('".$user['id']."','".time()."','Mute')") or die(mysql_error());

// Kick user
$setDBKick = mysql_query("INSERT INTO `shoutbox_antispam` (`userid`,`date`,`action`) VALUES ('".$user['id']."','".time()."','Kick')") or die(mysql_error());
$setKick = mysql_query("UPDATE `users` SET `kicked` = '1' WHERE `id` = '".$user['id']."'") or die(mysql_error());