def lineReceived(self, line): """A line was received.""" self.idle_since = datetime.utcnow() line = line.decode(encoding, 'replace') with session() as s: if self.intercept is not None: return self.intercept.feed(line) if self.username is None: self.username = line.lower() if line == config.new_character_command: msg = 'Enter a name for your new character:' else: msg = 'Password:'******'That character name is taken. Please choose ' 'another.') elif not line: self.notify( 'Character names cannot be blank. Goodbye.') return self.transport.loseConnection() else: c = Character(name=line.title()) s.add(c) c.location = Room.first() s.commit() self.object = c self.logger.info('Created character %s.', c) self.notify( f'Your new password is {c.randomise_password()}.') else: c = Character.query( func.lower(Character.name) == self.username).first() if c is None or not c.check_password(line): self.notify('Incorrect password.') self.username = None return self.notify('Username:'******'s tell the # user where they are. return self.object.show_location() if not line: return # Just a blank line. if line[0] in config.command_substitutions: line = config.command_substitutions[line[0]] + line[1:] both = line.split(' ', 1) if len(both) == 1: both.append('') if self.object is not None and self.object.log_commands: self.object.log_command(line) command, rest = both if command in commands_table and commands_table[command].allowed( self.object): try: return commands_table[command].run(self.object, rest) except Exception as e: return self.object.notify( 'Something went wrong with your command.') cmd = RoomCommand.query( name=command, location_id=self.object.location_id).first() if cmd is not None: try: with manage_environment(character=self.object, here=self.object.location, text=rest) as lua: lua.execute(cmd.code) except MatchError as e: self.object.notify(str(e)) except Exception as e: self.notify('There was a problem with your command.') logger.warning('Room command %s caused an error:', cmd) logger.exception(e) return direction = self.object.location.match_direction(line) if direction is None: return self.notify("I don't understand that.") commands_table['go'].run(self.object, direction.name)