From 6f7e4398ddf6191d6372a3464f89b013a6fb61cd Mon Sep 17 00:00:00 2001 From: nyuszika7h Date: Fri, 6 Jan 2017 16:20:40 +0100 Subject: [PATCH] Simplify latency checking code Since we send the timestamp of the request with the ping and the server will send it back, there is no need to store it. --- src/handler.py | 4 +--- src/settings.py | 1 - src/wolfgame.py | 2 +- 3 files changed, 2 insertions(+), 5 deletions(-) diff --git a/src/handler.py b/src/handler.py index 8bb7a7c..dd9a580 100644 --- a/src/handler.py +++ b/src/handler.py @@ -48,9 +48,7 @@ def unhandled(cli, prefix, cmd, *args): def ping_server(cli): if var.SERVER_PING_INTERVAL > 0: - ts = time.time() - var.LAST_SERVER_PING = ts - cli.send("PING :{0}".format(ts)) + cli.send("PING :{0}".format(time.time())) threading.Timer(var.SERVER_PING_INTERVAL, ping_server, args=(cli,)).start() def connect_callback(cli): diff --git a/src/settings.py b/src/settings.py index 8dc692b..6bc2be2 100644 --- a/src/settings.py +++ b/src/settings.py @@ -206,7 +206,6 @@ PASTEBIN_ERRORS = False # How often to ping the server (in seconds) to detect unclean disconnection SERVER_PING_INTERVAL = 120 -LAST_SERVER_PING = None # TODO: move this to a game mode called "fixed" once we implement a way to randomize roles (and have that game mode be called "random") DEFAULT_ROLE = "villager" diff --git a/src/wolfgame.py b/src/wolfgame.py index 10542ca..28c56a6 100644 --- a/src/wolfgame.py +++ b/src/wolfgame.py @@ -498,7 +498,7 @@ def latency(cli, nick, chan, rest): @hook("pong", hookid=300) def latency_pong(cli, server, target, ts): - lat = round(time.time() - var.LAST_SERVER_PING, 3) + lat = round(time.time() - float(ts), 3) reply(cli, nick, chan, messages["latency"].format(lat, "" if lat == 1 else "s")) hook.unhook(300)