.BANCHO. .FIX. Fix reset spam rate

This commit is contained in:
Nyo 2016-06-10 16:22:14 +02:00
parent 6cde5b2e68
commit f0f90b0c53
3 changed files with 26 additions and 10 deletions

View File

@ -238,14 +238,9 @@ class token:
increaseSpamRate -- pass True if the user has sent a new message. Optional. Default: True increaseSpamRate -- pass True if the user has sent a new message. Optional. Default: True
""" """
# Increase the spam rate if needed
if increaseSpamRate == True: if increaseSpamRate == True:
# Reset spam rate every 10 seconds
if int(time.time())-self.lastMessagetime >= 10:
self.spamRate = 0
else:
self.spamRate += 1 self.spamRate += 1
# Update last message time
self.lastMessagetime = time.time()
# Silence the user if needed # Silence the user if needed
if self.spamRate > 10: if self.spamRate > 10:

View File

@ -3,8 +3,6 @@ import time
import threading import threading
from events import logoutEvent from events import logoutEvent
from helpers import logHelper as log from helpers import logHelper as log
from constants import serverPackets
from helpers import userHelper
class tokenList: class tokenList:
""" """
@ -13,7 +11,11 @@ class tokenList:
tokens -- dictionary. key: token string, value: token object tokens -- dictionary. key: token string, value: token object
""" """
tokens = {} def __init__(self):
"""
Initialize a tokens list
"""
self.tokens = {}
def addToken(self, __userID): def addToken(self, __userID):
""" """
@ -166,3 +168,17 @@ class tokenList:
# Schedule a new check (endless loop) # Schedule a new check (endless loop)
threading.Timer(__checkTime, self.usersTimeoutCheckLoop, [__timeoutTime, __checkTime]).start() threading.Timer(__checkTime, self.usersTimeoutCheckLoop, [__timeoutTime, __checkTime]).start()
def spamProtectionResetLoop(self):
"""
Reset spam rate every 10 seconds.
CALL THIS FUNCTION ONLY ONCE!
"""
log.debug("Resetting spam protection...")
# Reset spamRate for every token
for _, value in self.tokens.items():
value.spamRate = 0
# Schedule a new check (endless loop)
threading.Timer(10, self.spamProtectionResetLoop).start()

5
pep.py
View File

@ -113,6 +113,11 @@ if __name__ == "__main__":
glob.tokens.usersTimeoutCheckLoop() glob.tokens.usersTimeoutCheckLoop()
consoleHelper.printDone() consoleHelper.printDone()
# Initialize spam protection reset loop
consoleHelper.printNoNl("> Initializing spam protection reset loop... ")
glob.tokens.spamProtectionResetLoop()
consoleHelper.printDone()
# Localize warning # Localize warning
glob.localize = generalFunctions.stringToBool(glob.conf.config["server"]["localize"]) glob.localize = generalFunctions.stringToBool(glob.conf.config["server"]["localize"])
if glob.localize == False: if glob.localize == False: