Added a validation-check when changing encodings using the default commands (unloggedin/general). Also put in a safety catch in the sessionhandler to reset faulty encodings that slips by for some reason. This can otherwise lead to errors for shutting down the server since the server fails trying to inform the faulty session about the shutdown.

This commit is contained in:
Griatch 2016-01-12 21:35:27 +01:00
parent 33c479fe04
commit 5d6d13bb12
3 changed files with 22 additions and 5 deletions

View file

@ -416,8 +416,14 @@ class CmdOption(MuxPlayerCommand):
# change encoding # change encoding
old_encoding = self.session.encoding old_encoding = self.session.encoding
new_encoding = self.rhs.strip() or "utf-8" new_encoding = self.rhs.strip() or "utf-8"
try:
utils.to_str(utils.to_unicode("test-string"), encoding=new_encoding)
except LookupError:
string = "|rThe encoding '|w%s|r' is invalid. Keeping the previous encoding '|w%s|r'.|n" % (new_encoding, old_encoding)
else:
self.session.encoding = new_encoding self.session.encoding = new_encoding
self.caller.msg("Encoding was changed from %s to %s." % (old_encoding, new_encoding)) string = "Encoding was changed from '|w%s|n' to '|w%s|n'." % (old_encoding, new_encoding)
self.caller.msg(string)
return return
if self.lhs == "screenreader": if self.lhs == "screenreader":

View file

@ -482,8 +482,13 @@ class CmdUnconnectedEncoding(MuxCommand):
# change encoding # change encoding
old_encoding = self.session.encoding old_encoding = self.session.encoding
encoding = self.args encoding = self.args
try:
utils.to_str(utils.to_unicode("test-string"), encoding=encoding)
except LookupError:
string = "|rThe encoding '|w%s|r' is invalid. Keeping the previous encoding '|w%s|r'.|n" % (encoding, old_encoding)
else:
self.session.encoding = encoding self.session.encoding = encoding
string = "Your custom text encoding was changed from '%s' to '%s'." % (old_encoding, encoding) string = "Your custom text encoding was changed from '|w%s|n' to '|w%s|n'." % (old_encoding, encoding)
self.caller.msg(string.strip()) self.caller.msg(string.strip())
class CmdUnconnectedScreenreader(MuxCommand): class CmdUnconnectedScreenreader(MuxCommand):

View file

@ -524,7 +524,13 @@ class ServerSessionHandler(SessionHandler):
#from evennia.server.profiling.timetrace import timetrace #from evennia.server.profiling.timetrace import timetrace
#text = timetrace(text, "ServerSessionHandler.data_out") #text = timetrace(text, "ServerSessionHandler.data_out")
try:
text = text and to_str(to_unicode(text), encoding=session.encoding) text = text and to_str(to_unicode(text), encoding=session.encoding)
except LookupError:
# wrong encoding set on the session. Set it to a safe one
session.encoding = "utf-8"
text = to_str(to_unicode(text), encoding=session.encoding)
# send across AMP # send across AMP
self.server.amp_protocol.send_MsgServer2Portal(session, self.server.amp_protocol.send_MsgServer2Portal(session,