.BANCHO. Remove silence for messages > 256 chars, cloudflare memes

This commit is contained in:
Nyo 2016-06-23 17:51:19 +02:00
parent 3686fa4d9c
commit 99276d83b3
7 changed files with 9 additions and 20 deletions

View File

@ -32,11 +32,7 @@ def handle(userToken, packetData):
raise exceptions.userSilencedException
# Check message length
if len(packetData["message"]) > 256:
if userToken.longMessageWarning == True:
raise exceptions.messageTooLongException
else:
raise exceptions.messageTooLongWarnException
packetData["message"] = packetData["message"][:2048]+"..." if len(packetData["message"]) > 2048 else packetData["message"]
if packetData["to"] == "FokaBot":
# FokaBot command check
@ -72,10 +68,6 @@ def handle(userToken, packetData):
except exceptions.tokenNotFoundException:
# Token not found, user disconnected
log.warning("{} tried to send a message to {}, but their token couldn't be found".format(username, packetData["to"]))
except exceptions.messageTooLongWarnException:
# Message > 256 warn
userToken.longMessageWarning = True
userToken.enqueue(serverPackets.sendMessage("FokaBot", username, "Your message was too long and has not been sent. Please keep your messages under 256 characters. This is your last warning."))
except exceptions.messageTooLongException:
# Message > 256 silence
userToken.silence(2*3600, "Sending messages longer than 256 characters")

View File

@ -33,11 +33,7 @@ def handle(userToken, packetData):
raise exceptions.userSilencedException
# Check message length
if len(packetData["message"]) > 256:
if userToken.longMessageWarning == True:
raise exceptions.messageTooLongException
else:
raise exceptions.messageTooLongWarnException
packetData["message"] = packetData["message"][:2048]+"..." if len(packetData["message"]) > 2048 else packetData["message"]
# Get receivers list
# Check #spectator
@ -129,10 +125,6 @@ def handle(userToken, packetData):
log.warning("{} tried to send a message to an unknown channel ({})".format(username, packetData["to"]))
except exceptions.channelNoPermissionsException:
log.warning("{} tried to send a message to channel {}, but they have no write permissions".format(username, packetData["to"]))
except exceptions.messageTooLongWarnException:
# Message > 256 warn
userToken.longMessageWarning = True
userToken.enqueue(serverPackets.sendMessage("FokaBot", username, "Your message was too long and has not been sent. Please keep your messages under 256 characters. This is your last warning."))
except exceptions.messageTooLongException:
# Message > 256 silence
userToken.silence(2*3600, "Sending messages longer than 256 characters")

View File

@ -54,6 +54,7 @@ class config:
self.config.get("server","gziplevel")
self.config.get("server","localize")
self.config.get("server","cikey")
self.config.get("server","cloudflare")
self.config.get("debug","enable")
self.config.get("debug","packets")
@ -92,6 +93,7 @@ class config:
self.config.set("server", "gziplevel", "6")
self.config.set("server", "localize", "1")
self.config.set("server", "cikey", "changeme")
self.config.set("server", "cloudflare", "0")
self.config.add_section("debug")
self.config.set("debug", "enable", "0")

View File

@ -44,7 +44,7 @@ class asyncRequestHandler(tornado.web.RequestHandler):
self.finish()
def getRequestIP(self):
realIP = self.request.headers.get("X-Real-IP")
realIP = self.request.headers.get("X-Forwarded-For") if glob.cloudflare == True else self.request.headers.get("X-Real-IP")
if realIP != None:
return realIP
return self.request.remote_ip

View File

@ -21,6 +21,7 @@ matches = matchList.matchList()
restarting = False
pool = None
fLocks = fileLocks.fileLocks()
cloudflare = False
debug = False
outputRequestTime = False

View File

@ -68,7 +68,6 @@ class token:
self.osuDirectAlert = False # NOTE: Remove this when osu!direct will be fixed
# Spam protection
self.longMessageWarning = False
self.spamRate = 0
#self.lastMessagetime = 0

3
pep.py
View File

@ -171,6 +171,9 @@ if __name__ == "__main__":
except:
consoleHelper.printColored("[!] Error while starting sentry client! Please check your config.ini and run the server again", bcolors.RED)
# Cloudflare memes
glob.cloudflare = generalFunctions.stringToBool(glob.conf.config["server"]["cloudflare"])
# Server start message and console output
log.logMessage("Server started!", discord=True, of="info.txt", stdout=False)
consoleHelper.printColored("> Tornado listening for clients on 127.0.0.1:{}...".format(serverPort), bcolors.GREEN)