diff options
author | André Glüpker <git@wgmd.de> | 2018-09-03 19:32:03 +0200 |
---|---|---|
committer | André Glüpker <git@wgmd.de> | 2018-09-03 19:35:33 +0200 |
commit | ac1cdd56aec9b616d583b8b38887213c771b0e4d (patch) | |
tree | 686df0b3e458a9ee6f18279d2404038d15236cfd | |
parent | 4fc0960dd362f2bb5e2719f2a2c0bbca71713e69 (diff) | |
download | steam-ac1cdd56aec9b616d583b8b38887213c771b0e4d.tar.gz steam-ac1cdd56aec9b616d583b8b38887213c771b0e4d.tar.bz2 steam-ac1cdd56aec9b616d583b8b38887213c771b0e4d.zip |
Track ServerQuery latency
-rwxr-xr-x | QueryServer.py | 8 | ||||
-rw-r--r-- | templates/server_html.jinja | 2 |
2 files changed, 8 insertions, 2 deletions
diff --git a/QueryServer.py b/QueryServer.py index 52e4aa0..fb2efd1 100755 --- a/QueryServer.py +++ b/QueryServer.py @@ -1,5 +1,7 @@ #!/usr/bin/env python3 +import time + # Time to live for caching. 0 to disable caching CACHE_TTL = 15 @@ -71,6 +73,7 @@ class QueryServer(): if gameid in sourcequeryinc: port += 1 + starttime = time.time() conn = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) message = None @@ -89,7 +92,10 @@ class QueryServer(): finally: conn.close() - data = dict() + data = {} + + latency = time.time() - starttime + data['latency'] = int(latency * 1000) # [0]-[3] -> 4*\xFF data['header'] = chr(message[4]) diff --git a/templates/server_html.jinja b/templates/server_html.jinja index 9702300..5b530e5 100644 --- a/templates/server_html.jinja +++ b/templates/server_html.jinja @@ -17,7 +17,7 @@ {% for name, info in servers.items() %} <div class="server {% if info['data'] %}ingame{% else %}busy{%endif%}"> <div class="serverheader"> - <a class="servername" href="steam://connect/{{ info['ip'] }}:{{ info['port'] }}">{{ name }}</a> + <a class="servername" href="steam://connect/{{ info['ip'] }}:{{ info['port'] }}">{{ name }} ({{ info['data']['latency'] }} ms)</a> </div> {% if info['data'] %} <div class="serverdata"> |