diff --git a/events/sendPrivateMessageEvent.py b/events/sendPrivateMessageEvent.py index 5914590..88eb6e1 100644 --- a/events/sendPrivateMessageEvent.py +++ b/events/sendPrivateMessageEvent.py @@ -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") diff --git a/events/sendPublicMessageEvent.py b/events/sendPublicMessageEvent.py index 3f98a8a..76d2ebc 100644 --- a/events/sendPublicMessageEvent.py +++ b/events/sendPublicMessageEvent.py @@ -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") diff --git a/helpers/configHelper.py b/helpers/configHelper.py index 68cb198..1fc8a5f 100644 --- a/helpers/configHelper.py +++ b/helpers/configHelper.py @@ -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") diff --git a/helpers/requestHelper.py b/helpers/requestHelper.py index 49feda7..0599180 100644 --- a/helpers/requestHelper.py +++ b/helpers/requestHelper.py @@ -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 diff --git a/objects/glob.py b/objects/glob.py index 02f3129..03faa37 100644 --- a/objects/glob.py +++ b/objects/glob.py @@ -21,6 +21,7 @@ matches = matchList.matchList() restarting = False pool = None fLocks = fileLocks.fileLocks() +cloudflare = False debug = False outputRequestTime = False diff --git a/objects/osuToken.py b/objects/osuToken.py index defc454..672623d 100644 --- a/objects/osuToken.py +++ b/objects/osuToken.py @@ -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 diff --git a/pep.py b/pep.py index 46b1cdd..f7ecffc 100644 --- a/pep.py +++ b/pep.py @@ -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)