summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xQueryServer.py8
-rw-r--r--templates/server_html.jinja2
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">