- self.switch_mode('play')
- elif self.mode == self.mode_chat and key == '\n':
- if self.input_ == '':
- continue
- if self.input_[0] == '/': # FIXME fails on empty input
- if self.input_ in {'/' + self.keys['switch_to_play'], '/play'}:
- self.switch_mode('play')
- elif self.input_ in {'/' + self.keys['switch_to_study'], '/study'}:
- self.switch_mode('study')
- elif self.input_.startswith('/nick'):
- tokens = self.input_.split(maxsplit=1)
- if len(tokens) == 2:
- self.send('NICK ' + quote(tokens[1]))
- else:
- self.log_msg('? need login name')
- elif self.input_.startswith('/msg'):
- tokens = self.input_.split(maxsplit=2)
- if len(tokens) == 3:
- self.send('QUERY %s %s' % (quote(tokens[1]),
- quote(tokens[2])))
- else:
- self.log_msg('? need message target and message')
+ self.switch_mode('edit')
+
+ 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')
+ 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('@ entered non-single-char, therefore aborted')
+ else:
+ self.send('THING_PROTECTION %s' % (quote(self.input_)))
+ self.log('@ sent new protection character for thing')
+ self.switch_mode('admin')
+ elif self.mode.name == 'control_tile_type' and key == '\n':
+ if len(self.input_) != 1:
+ self.log('@ entered non-single-char, therefore aborted')
+ self.switch_mode('admin')
+ else:
+ self.tile_control_char = self.input_
+ self.switch_mode('control_tile_draw')
+ elif self.mode.name == 'chat' and key == '\n':
+ if self.input_ == '':
+ return
+ if self.input_[0] == '/':
+ if self.input_.startswith('/nick'):
+ tokens = self.input_.split(maxsplit=1)
+ if len(tokens) == 2:
+ self.send('NICK ' + quote(tokens[1]))