- elif self.mode.name == 'admin_enter' and key == '\n':
- self.send('BECOME_ADMIN ' + quote(self.input_))
- self.switch_mode('play')
- elif self.mode.name == 'control_pw_type' and key == '\n':
- if len(self.input_) != 1:
- self.log_msg('@ entered non-single-char, therefore aborted')
- self.switch_mode('admin')
- else:
- self.tile_control_char = self.input_
- self.switch_mode('control_pw_pw')
- elif self.mode.name == 'admin_thing_protect' and key == '\n':
- if len(self.input_) != 1:
- self.log_msg('@ entered non-single-char, therefore aborted')
- else:
- self.send('THING_PROTECTION %s %s' % (self.thing_selected.id_,
- quote(self.input_)))
- self.log_msg('@ sent new protection character for thing')
+
+ prev_disconnected = self.socket.disconnected
+ self.socket.keep_connection_alive()
+ if prev_disconnected and not self.socket.disconnected:
+ self.update_on_connect()
+ if self.flash:
+ curses.flash()
+ self.flash = False
+ if self.do_refresh:
+ draw_screen()
+ self.do_refresh = False
+ for msg in self.socket.get_message():
+ handle_input(msg)
+ try:
+ key = self.stdscr.getkey()
+ self.do_refresh = True
+ except curses.error:
+ return
+ keycode = None
+ if len(key) == 1:
+ keycode = ord(key)
+ # workaround for <https://stackoverflow.com/a/56390915>
+ if self.store_widechar:
+ self.store_widechar = False
+ key = bytes([195, keycode]).decode()
+ if keycode == 195:
+ self.store_widechar = True
+ return
+ self.show_help = False
+ self.draw_face = False
+ if key == 'KEY_RESIZE':
+ self.reset_size()
+ elif self.mode.has_input_prompt and key == 'KEY_BACKSPACE':
+ self.input_ = self.input_[:-1]
+ elif (((not self.mode.is_intro) and keycode == 27) # Escape
+ or (self.mode.has_input_prompt and key == '\n'
+ and self.input_ == ''\
+ and self.mode.name in {'chat', 'command_thing',
+ 'take_thing', 'drop_thing',
+ 'admin_enter'})):
+ if self.mode.name not in {'chat', 'play', 'study', 'edit'}:
+ self.log('@ aborted')
+ self.switch_mode('play')
+ elif self.mode.has_input_prompt and key == '\n' and self.input_ == '/help':
+ self.show_help = True
+ self.input_ = ""
+ self.restore_input_values()
+ elif self.mode.has_input_prompt and key != '\n': # Return key
+ self.input_ += key
+ max_length = self.right_window_width * self.size.y - len(self.input_prompt) - 1
+ if len(self.input_) > max_length:
+ self.input_ = self.input_[:max_length]
+ elif key == self.keys['help'] and not self.mode.is_single_char_entry:
+ self.show_help = True
+ elif self.mode.name == 'login' and key == '\n':
+ self.login_name = self.input_
+ self.send('LOGIN ' + quote(self.input_))
+ self.input_ = ""
+ elif self.mode.name == 'enter_face' and key == '\n':
+ enter_ascii_art('PLAYER_FACE', 3, 6)
+ elif self.mode.name == 'enter_design' and key == '\n':
+ if self.game.player.carrying.type_ == 'Hat':
+ enter_ascii_art('THING_DESIGN',
+ self.game.player.carrying.design[0].y,
+ self.game.player.carrying.design[0].x, True)
+ else:
+ enter_ascii_art('THING_DESIGN',
+ self.game.player.carrying.design[0].y,
+ self.game.player.carrying.design[0].x,
+ True, True)
+ elif self.mode.name == 'take_thing' and key == '\n':
+ pick_selectable('PICK_UP')
+ elif self.mode.name == 'drop_thing' and key == '\n':
+ pick_selectable('DROP')
+ elif self.mode.name == 'command_thing' and key == '\n':
+ self.send('TASK:COMMAND ' + quote(self.input_))
+ self.input_ = ""
+ elif self.mode.name == 'control_pw_pw' and key == '\n':
+ if self.input_ == '':
+ self.log('@ aborted')
+ else:
+ self.send('SET_MAP_CONTROL_PASSWORD ' + quote(self.tile_control_char) + ' ' + quote(self.input_))
+ self.log('@ sent new password for protection character "%s"' % self.tile_control_char)
+ self.switch_mode('admin')
+ elif self.mode.name == 'password' and key == '\n':
+ if self.input_ == '':
+ self.input_ = ' '
+ self.password = self.input_
+ self.switch_mode('edit')
+ elif self.mode.name == 'admin_enter' and key == '\n':
+ self.send('BECOME_ADMIN ' + quote(self.input_))
+ self.switch_mode('play')
+ elif self.mode.name == 'control_pw_type' and key == '\n':
+ if len(self.input_) != 1:
+ self.log('@ entered non-single-char, therefore aborted')