home · contact · privacy
Add PING.
authorChristian Heller <c.heller@plomlompom.de>
Sun, 25 Oct 2020 03:08:19 +0000 (04:08 +0100)
committerChristian Heller <c.heller@plomlompom.de>
Sun, 25 Oct 2020 03:08:19 +0000 (04:08 +0100)
new2/plomrogue/commands.py
new2/plomrogue/game.py
new2/rogue_chat.html

index 79a4678b1b8133b969e589729d90498e235a2dc8..09f22c081beb346070f5bbc7175110577471378b 100644 (file)
@@ -34,3 +34,7 @@ def cmd_QUERY(game, target_nick, msg, connection_id):
         raise GameError('target user offline')
     raise GameError('can only query with registered nicknames')
 cmd_QUERY.argtypes = 'string string'
+
+def cmd_PING(game, connection_id):
+    game.io.send('PONG')
+cmd_QUERY.argtypes = ''
index 81bd530d8b3cde8c12db964042dabc505468256e..25f4d809b69b04083abb4bcea83996608920ee42 100755 (executable)
@@ -1,6 +1,6 @@
 from plomrogue.tasks import Task_WAIT, Task_MOVE, Task_WRITE
 from plomrogue.errors import GameError
-from plomrogue.commands import cmd_ALL, cmd_LOGIN, cmd_QUERY
+from plomrogue.commands import cmd_ALL, cmd_LOGIN, cmd_QUERY, cmd_PING
 from plomrogue.io import GameIO
 from plomrogue.misc import quote
 from plomrogue.things import Thing, ThingPlayer 
@@ -41,7 +41,8 @@ class Game(GameBase):
         self.map_geometry = MapGeometrySquare(YX(24, 40))
         self.commands = {'QUERY': cmd_QUERY,
                          'ALL': cmd_ALL,
-                         'LOGIN': cmd_LOGIN}
+                         'LOGIN': cmd_LOGIN,
+                         'PING': cmd_PING}
         self.thing_type = Thing
         self.thing_types = {'player': ThingPlayer}
         self.sessions = {}
index 7ba548b119f19cfaf74b373faed4084ea2ba0548..dd0036ec7f8e47ce90c455b7be1a721bf9bc2af5 100644 (file)
@@ -230,10 +230,14 @@ websocket.onmessage = function (event) {
      tui.log_msg('game error: ' + tokens[1]);
   } else if (tokens[0] === 'GAME_ERROR') {
      tui.log_msg('game error: ' + tokens[1]);
+  } else if (tokens[0] === 'PONG') {
+    console.log('PONG');
   } else {
      tui.log_msg('unhandled input: ' + event.data);
   }
 }
+
+window.setInterval(function() { websocket.send('PING') }, 30000);
 </script>
 </body>
 </html>