home · contact · privacy
Automatically log in if login name already provided previously.
authorChristian Heller <c.heller@plomlompom.de>
Fri, 6 Nov 2020 01:25:55 +0000 (02:25 +0100)
committerChristian Heller <c.heller@plomlompom.de>
Fri, 6 Nov 2020 01:25:55 +0000 (02:25 +0100)
new2/rogue_chat_curses.py
new2/rogue_chat_nocanvas_monochrome.html

index 8bd45afb3e3742a5bc796632cd8e5d07380ad250..6fda713d2206ac3ed7d186586f0c0aaac542801f 100755 (executable)
@@ -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:
         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
         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.log = []
         self.do_refresh = True
         self.queue = queue.Queue()
+        self.login_name = None
         self.switch_mode('waiting_for_server')
         curses.wrapper(self.loop)
 
         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':
         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));
         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':
                 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':
                 self.send('LOGIN ' + quote(self.input_))
                 self.input_ = ""
             elif self.mode == self.mode_chat and key == '\n':
index 2d60619ee7282d2590a1818f73a3156161b65168..406dd805cf8410d9949c399b288bc9f98735d04b 100644 (file)
@@ -151,7 +151,7 @@ let server = {
         this.websocket.onopen = function(event) {
             window.setInterval(function() { server.send(['PING']) }, 30000);
             tui.log_msg("@ server connected! :)");
         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 :(");
         };
         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;
   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();
         }
     }
            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]
         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.");
     } 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') {
         event.preventDefault();
     }
     if (tui.mode == mode_login && event.key == 'Enter') {
+        tui.login_name = tui.inputEl.value;
         server.send(['LOGIN', 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);
     } else if (tui.mode == mode_portal && event.key == 'Enter') {
         explorer.set_portal(tui.inputEl.value);
         tui.switch_mode(mode_study, true);