Put in check for maximum character size in input strings that can be set with settings.MAX_CHAR_LIMIT.

This commit is contained in:
Tehom 2016-12-13 06:53:35 -05:00
parent 619a9cee57
commit 760c5b41fc
2 changed files with 18 additions and 1 deletions

View file

@ -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:

View file

@ -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