Make sure player input is valid unicode. If an un-decodable character is encountered, replace it with question marks. We'll need to test this with a more unicode capable client than I have.

This commit is contained in:
Greg Taylor 2009-10-27 20:18:01 +00:00
parent b57608cf55
commit af19724bb2
2 changed files with 14 additions and 4 deletions

View file

@ -133,7 +133,9 @@ class Command(object):
""" """
Instantiates the Command object and does some preliminary parsing. Instantiates the Command object and does some preliminary parsing.
""" """
self.raw_input = raw_input # If we get a unicode string with un-recognizable characters, replace
# them instead of throwing errors.
self.raw_input = unicode(raw_input, errors='replace')
self.source_object = source_object self.source_object = source_object
self.session = session self.session = session
# The work starts here. # The work starts here.
@ -441,7 +443,8 @@ def handle(command, ignore_state=False):
# Nothing sent in of value, ignore it. # Nothing sent in of value, ignore it.
raise ExitCommandHandler raise ExitCommandHandler
state = None #no state by default # No state by default.
state = None
if command.session and not command.session.logged_in: if command.session and not command.session.logged_in:
# Not logged in, look through the unlogged-in command table. # Not logged in, look through the unlogged-in command table.

View file

@ -47,6 +47,10 @@ class SessionProtocol(StatefulTelnetProtocol):
self.address = self.getClientAddress() self.address = self.getClientAddress()
self.name = None self.name = None
self.uid = None self.uid = None
# This is merely here to serve as a convenient reference. It is not
# necessarily the most up to date version of the object, so it is NOT
# safe to look at pobject's location or any other attributes from
# the Object model.
self.pobject = None self.pobject = None
self.logged_in = False self.logged_in = False
# The time the user last issued a command. # The time the user last issued a command.
@ -78,9 +82,12 @@ class SessionProtocol(StatefulTelnetProtocol):
Any line return indicates a command for the purpose of a MUD. So we take Any line return indicates a command for the purpose of a MUD. So we take
the user input and pass it to this session's pobject. the user input and pass it to this session's pobject.
""" """
if self.pobject: if self.is_loggedin():
# Session is logged in, run through the normal object execution. # Session is logged in, run through the normal object execution.
self.pobject.execute_cmd(data, session=self) # Get the most up to date copy of the Object.
pobject = self.get_pobject()
if pobject:
pobject.execute_cmd(data, session=self)
else: else:
# Not logged in, manually execute the command. # Not logged in, manually execute the command.
cmdhandler.handle(cmdhandler.Command(None, data, session=self)) cmdhandler.handle(cmdhandler.Command(None, data, session=self))