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.
This commit is contained in:
parent
06c60dfdc3
commit
6f7e4398dd
@ -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):
|
||||
|
@ -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"
|
||||
|
@ -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)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user