From: Christian Heller Date: Fri, 6 Nov 2020 01:25:55 +0000 (+0100) Subject: Automatically log in if login name already provided previously. X-Git-Url: https://plomlompom.com/repos/%7B%7Bprefix%7D%7D/foo.html?a=commitdiff_plain;h=d16b92da8e0d5b85d909732ae22dee60bf480c5e;p=plomrogue2-experiments Automatically log in if login name already provided previously. --- diff --git a/new2/rogue_chat_curses.py b/new2/rogue_chat_curses.py index 8bd45af..6fda713 100755 --- a/new2/rogue_chat_curses.py +++ b/new2/rogue_chat_curses.py @@ -73,9 +73,9 @@ def cmd_GAME_STATE_COMPLETE(game): game.tui.query_info() player = game.get_thing(game.player_id, False) if player.position in game.portals: - host, port = game.portals[player.position].split(':') - game.tui.teleport_target_host = host - game.tui.teleport_target_port = port + #host, port = game.portals[player.position].split(':') + game.tui.teleport_target_host = game.portals[player.position] + game.tui.teleport_target_port = 5000 game.tui.switch_mode('teleport') game.turn_complete = True game.tui.do_refresh = True @@ -171,6 +171,7 @@ class TUI: self.log = [] self.do_refresh = True self.queue = queue.Queue() + self.login_name = None self.switch_mode('waiting_for_server') curses.wrapper(self.loop) @@ -200,7 +201,10 @@ class TUI: if self.mode.name == 'waiting_for_server': self.log_msg('@ waiting for server …') elif self.mode.name == 'login': - self.log_msg('@ enter username') + if self.login_name: + self.send('LOGIN ' + quote(self.login_name)) + else: + self.log_msg('@ enter username') elif self.mode.name == 'teleport': self.log_msg("@ May teleport to %s:%s" % (self.teleport_target_host, self.teleport_target_port)); @@ -445,6 +449,7 @@ class TUI: if len(self.input_) > max_length: self.input_ = self.input_[:max_length] elif self.mode == self.mode_login and key == '\n': + self.login_name = self.input_ self.send('LOGIN ' + quote(self.input_)) self.input_ = "" elif self.mode == self.mode_chat and key == '\n': diff --git a/new2/rogue_chat_nocanvas_monochrome.html b/new2/rogue_chat_nocanvas_monochrome.html index 2d60619..406dd80 100644 --- a/new2/rogue_chat_nocanvas_monochrome.html +++ b/new2/rogue_chat_nocanvas_monochrome.html @@ -151,7 +151,7 @@ let server = { this.websocket.onopen = function(event) { window.setInterval(function() { server.send(['PING']) }, 30000); tui.log_msg("@ server connected! :)"); - tui.init_login(); + tui.switch_mode(mode_login); }; this.websocket.onclose = function(event) { tui.log_msg("@ server disconnected :("); @@ -335,10 +335,6 @@ let tui = { }; }; }, - init_login: function() { - this.log_msg("@ please enter your username:"); - this.switch_mode(mode_login); - }, switch_mode: function(mode, keep_pos=false) { if (mode == mode_study && !keep_pos && game.player_id in game.things) { explorer.position = game.things[game.player_id].position; @@ -352,10 +348,16 @@ let tui = { this.recalc_input_lines(); } } - if (mode == mode_portal && explorer.position in game.portals) { + if (mode == mode_login) { + if (this.login_name) { + server.send(['LOGIN', this.login_name]); + } else { + this.log_msg("? need login name"); + } + } else if (mode == mode_portal && explorer.position in game.portals) { let portal = game.portals[explorer.position] - this.inputEl.value = portal; - this.recalc_input_lines(); + this.inputEl.value = portal; + this.recalc_input_lines(); } else if (mode == mode_teleport) { tui.log_msg("@ May teleport to: " + tui.teleport_target); tui.log_msg("@ Enter 'YES!' to entusiastically affirm."); @@ -685,8 +687,9 @@ tui.inputEl.addEventListener('keydown', (event) => { event.preventDefault(); } if (tui.mode == mode_login && event.key == 'Enter') { + tui.login_name = tui.inputEl.value; server.send(['LOGIN', tui.inputEl.value]); - tui.switch_mode(mode_login); + tui.empty_input(); } else if (tui.mode == mode_portal && event.key == 'Enter') { explorer.set_portal(tui.inputEl.value); tui.switch_mode(mode_study, true);