From 760c5b41fc0a1cd35bc40f4cef4f4bfa946aade4 Mon Sep 17 00:00:00 2001 From: Tehom Date: Tue, 13 Dec 2016 06:53:35 -0500 Subject: [PATCH] Put in check for maximum character size in input strings that can be set with settings.MAX_CHAR_LIMIT. --- evennia/server/portal/portalsessionhandler.py | 11 ++++++++++- evennia/settings_default.py | 8 ++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/evennia/server/portal/portalsessionhandler.py b/evennia/server/portal/portalsessionhandler.py index 5ef4a66e63..efe80a0cc0 100644 --- a/evennia/server/portal/portalsessionhandler.py +++ b/evennia/server/portal/portalsessionhandler.py @@ -18,9 +18,11 @@ _MOD_IMPORT = None # throttles _MAX_CONNECTION_RATE = float(settings.MAX_CONNECTION_RATE) _MAX_COMMAND_RATE = float(settings.MAX_COMMAND_RATE) +_MAX_CHAR_LIMIT = settings.MAX_CHAR_LIMIT _MIN_TIME_BETWEEN_CONNECTS = 1.0 / float(settings.MAX_CONNECTION_RATE) _ERROR_COMMAND_OVERFLOW = settings.COMMAND_RATE_WARNING +_ERROR_MAX_CHAR = settings.MAX_CHAR_LIMIT_WARNING _CONNECTION_QUEUE = deque() @@ -354,7 +356,14 @@ class PortalSessionHandler(SessionHandler): """ #from evennia.server.profiling.timetrace import timetrace #text = timetrace(text, "portalsessionhandler.data_in") - + try: + text = kwargs['text'] + if _MAX_CHAR_LIMIT and len(text) > _MAX_CHAR_LIMIT: + if session: + self.data_out(session, text=[[_ERROR_MAX_CHAR], {}]) + return + except Exception: + pass if session: now = time() if self.command_counter > _MAX_COMMAND_RATE: diff --git a/evennia/settings_default.py b/evennia/settings_default.py index 48e9205615..7b94643ccc 100644 --- a/evennia/settings_default.py +++ b/evennia/settings_default.py @@ -201,6 +201,14 @@ MAX_CONNECTION_RATE = 2 MAX_COMMAND_RATE = 80 # The warning to echo back to users if they send commands too fast COMMAND_RATE_WARNING ="You entered commands too fast. Wait a moment and try again." +# Determine how large of a string can be sent to the server in number +# of characters. If they attempt to enter a string over this character +# limit, we stop them and send a message. Set to None by default. To +# change it, just set it to a number of characters - ie, 6000 to be +# roughly two pages of text. +MAX_CHAR_LIMIT = None +# The warning to echo back to users if they enter a very large string +MAX_CHAR_LIMIT_WARNING="You entered a string that was too large. Please break it up into separate commands." # If this is true, errors and tracebacks from the engine will be # echoed as text in-game as well as to the log. This can speed up # debugging. Showing full tracebacks to regular users could be a