From f0f90b0c53e242411f7bb7f8e1af9d46c1190e21 Mon Sep 17 00:00:00 2001 From: Nyo Date: Fri, 10 Jun 2016 16:22:14 +0200 Subject: [PATCH] .BANCHO. .FIX. Fix reset spam rate --- objects/osuToken.py | 9 ++------- objects/tokenList.py | 22 +++++++++++++++++++--- pep.py | 5 +++++ 3 files changed, 26 insertions(+), 10 deletions(-) diff --git a/objects/osuToken.py b/objects/osuToken.py index 0fd17cb..93401ff 100644 --- a/objects/osuToken.py +++ b/objects/osuToken.py @@ -238,14 +238,9 @@ class token: increaseSpamRate -- pass True if the user has sent a new message. Optional. Default: True """ + # Increase the spam rate if needed if increaseSpamRate == True: - # Reset spam rate every 10 seconds - if int(time.time())-self.lastMessagetime >= 10: - self.spamRate = 0 - else: - self.spamRate += 1 - # Update last message time - self.lastMessagetime = time.time() + self.spamRate += 1 # Silence the user if needed if self.spamRate > 10: diff --git a/objects/tokenList.py b/objects/tokenList.py index 506f5a5..ee154bc 100644 --- a/objects/tokenList.py +++ b/objects/tokenList.py @@ -3,8 +3,6 @@ import time import threading from events import logoutEvent from helpers import logHelper as log -from constants import serverPackets -from helpers import userHelper class tokenList: """ @@ -13,7 +11,11 @@ class tokenList: tokens -- dictionary. key: token string, value: token object """ - tokens = {} + def __init__(self): + """ + Initialize a tokens list + """ + self.tokens = {} def addToken(self, __userID): """ @@ -166,3 +168,17 @@ class tokenList: # Schedule a new check (endless loop) 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() diff --git a/pep.py b/pep.py index a05a5ed..e0c0c78 100644 --- a/pep.py +++ b/pep.py @@ -113,6 +113,11 @@ if __name__ == "__main__": glob.tokens.usersTimeoutCheckLoop() consoleHelper.printDone() + # Initialize spam protection reset loop + consoleHelper.printNoNl("> Initializing spam protection reset loop... ") + glob.tokens.spamProtectionResetLoop() + consoleHelper.printDone() + # Localize warning glob.localize = generalFunctions.stringToBool(glob.conf.config["server"]["localize"]) if glob.localize == False: