From 1dc47266dcb1f7f692a7e993d2fb0bfb9f7ceeb1 Mon Sep 17 00:00:00 2001 From: Christian Heller Date: Sun, 25 Oct 2020 04:08:19 +0100 Subject: [PATCH] Add PING. --- new2/plomrogue/commands.py | 4 ++++ new2/plomrogue/game.py | 5 +++-- new2/rogue_chat.html | 4 ++++ 3 files changed, 11 insertions(+), 2 deletions(-) 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); -- 2.30.2