Created
May 20, 2014 13:12
-
-
Save mlshvdv/551ac4ed944e850d703f to your computer and use it in GitHub Desktop.
Javascript anti-flood system
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var score = 0; | |
var penalty = 100; // Penalty can be fine-tuned. | |
var lastact = new Date(); | |
function talk() { | |
/* The smaller the distance, more time has to pass in order | |
* to negate the score penalty cause{d,s}. | |
*/ | |
score -= (new Date() - lastact) * 0.55; | |
// Score shouldn't be less than zero. | |
score = (score < 0) ? 0 : score; | |
console.log("--------------"); | |
console.log((score += penalty)); | |
if ( parseInt( (score += penalty) ) <= 1000 ) { | |
// Do things. | |
console.log("Work"); | |
} else { | |
console.log("Error"); | |
} | |
lastact = new Date(); | |
} | |
$(document).ready(function(){ | |
$("form").submit(function(){ | |
talk(); | |
return false; | |
}); | |
}); |
Дмитрий, добрый вечер, а не подскажите как переделать его, чтобы считал не по очкам, а по времени. К примеру (одно сообщение = 1000, если больше одного сообщения в секунду - do nothing) . Спасибо)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
PERFECT!!! THANKYOU!!!