home · contact · privacy
Make curses client PING.
[plomrogue2-experiments] / new2 / rogue_chat_curses.py
index 0ffceeb2d4c5d64c5d60df1fb1e4e38881ffa403..15d0053a8bca770f385aa9e8a70a2f707f415c55 100755 (executable)
@@ -139,8 +139,13 @@ def cmd_ANNOTATION(game, position, msg):
         game.tui.do_refresh = True
 cmd_ANNOTATION.argtypes = 'yx_tuple:nonneg string'
 
+def cmd_PONG(game):
+    pass
+cmd_PONG.argtypes = ''
+
 class Game(GameBase):
     commands = {'LOGIN_OK': cmd_LOGIN_OK,
+                'PONG': cmd_PONG,
                 'CHAT': cmd_CHAT,
                 'PLAYER_ID': cmd_PLAYER_ID,
                 'TURN': cmd_TURN,
@@ -296,6 +301,7 @@ class TUI:
 
     def loop(self, stdscr):
         import time
+        import datetime
 
         def safe_addstr(y, x, line):
             if y < self.size.y - 1 or x + len(line) < self.size.x:
@@ -394,10 +400,15 @@ class TUI:
         def draw_info():
             if not self.game.turn_complete:
                 return
+            pos_i = self.explorer.y * self.game.map_geometry.size.x + self.explorer.x
+            info = 'TERRAIN: %s\n' % self.game.map_content[pos_i]
+            for t in self.game.things:
+                if t.position == self.explorer:
+                    info += 'PLAYER @: %s\n' % t.name
             if self.explorer in self.game.portals:
-                info = 'PORTAL: ' + self.game.portals[self.explorer] + '\n'
+                info += 'PORTAL: ' + self.game.portals[self.explorer] + '\n'
             else:
-                info = 'PORTAL: (none)\n'
+                info += 'PORTAL: (none)\n'
             if self.explorer in self.game.info_db:
                 info += 'ANNOTATION: ' + self.game.info_db[self.explorer]
             else:
@@ -487,7 +498,13 @@ class TUI:
         self.input_ = ''
         input_prompt = '> '
         connect()
+        last_ping = datetime.datetime.now()
+        interval = datetime.timedelta(seconds=30)
         while True:
+            now = datetime.datetime.now()
+            if now - last_ping > interval:
+                self.send('PING')
+                last_ping = now
             if self.do_refresh:
                 draw_screen()
                 self.do_refresh = False
@@ -517,9 +534,9 @@ class TUI:
                 self.input_ = ""
             elif self.mode == self.mode_chat and key == '\n':
                 if self.input_[0] == '/':
-                    if self.input_ in {'/P', '/play'}:
+                    if self.input_ in {'/' + self.keys['switch_to_play'], '/play'}:
                         self.switch_mode('play')
-                    elif self.input_ in {'/?', '/study'}:
+                    elif self.input_ in {'/' + self.keys['switch_to_study'], '/study'}:
                         self.switch_mode('study')
                     elif self.input_ == '/help':
                         self.help()