Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Aug 2009
    Posts
    131
    Thanks
    28
    Thanked 7 Times in 7 Posts

    "Lag" causes more than 1 database input

    Hello.

    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?

    Thanks

  • #2
    Senior Coder timgolding's Avatar
    Join Date
    Aug 2006
    Location
    Southampton
    Posts
    1,517
    Thanks
    114
    Thanked 110 Times in 109 Posts
    we need to see code! Otherwise your guess is as good as mine...
    You can not say you know how to do something, until you can teach it to someone else.

  • #3
    Regular Coder
    Join Date
    Aug 2009
    Posts
    131
    Thanks
    28
    Thanked 7 Times in 7 Posts
    I cut the script out. This is the anti-spam/flood part of it.

    PHP Code:
    <?php
    if(isset($_POST['shout'])){
        
    $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());
                die();
            }
            
            
    // 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());
            die();
        }
    }
    ?>


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •