From: Christian Heller Date: Sun, 25 Oct 2020 03:08:19 +0000 (+0100) Subject: Add PING. X-Git-Url: https://plomlompom.com/repos/%7B%7B%20web_path%20%7D%7D/decks/%7B%7Bdeck_id%7D%7D?a=commitdiff_plain;h=1dc47266dcb1f7f692a7e993d2fb0bfb9f7ceeb1;p=plomrogue2-experiments Add PING. --- diff --git a/new2/plomrogue/commands.py b/new2/plomrogue/commands.py index 79a4678..09f22c0 100644 --- a/new2/plomrogue/commands.py +++ b/new2/plomrogue/commands.py @@ -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 = '' diff --git a/new2/plomrogue/game.py b/new2/plomrogue/game.py index 81bd530..25f4d80 100755 --- a/new2/plomrogue/game.py +++ b/new2/plomrogue/game.py @@ -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 = {} diff --git a/new2/rogue_chat.html b/new2/rogue_chat.html index 7ba548b..dd0036e 100644 --- a/new2/rogue_chat.html +++ b/new2/rogue_chat.html @@ -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);