diff --git a/routes/dashboard.py b/routes/dashboard.py index e9e7aa1..a94d28c 100644 --- a/routes/dashboard.py +++ b/routes/dashboard.py @@ -13,8 +13,33 @@ dashboard = Blueprint('dashboard', __name__) @dashboard.route('/') def index(): conn = get_db() - players = conn.execute('SELECT DISTINCT player, player_id FROM town_state WHERE player IS NOT NULL ORDER BY player ASC').fetchall() + rows = conn.execute(''' + SELECT player, player_id, MAX(updated_at) as last_seen + FROM town_state + WHERE player IS NOT NULL + GROUP BY player, player_id + ORDER BY player ASC + ''').fetchall() conn.close() + + players = [] + now = datetime.utcnow() + for r in rows: + is_online = False + if r['last_seen']: + try: + last_seen = datetime.fromisoformat(r['last_seen']) + if (now - last_seen).total_seconds() <= 150: + is_online = True + except Exception: + pass + + players.append({ + 'player': r['player'], + 'player_id': r['player_id'], + 'is_online': is_online + }) + return render_template('index.html', players=players) @dashboard.route('/player/') diff --git a/templates/index.html b/templates/index.html index c5eb7dc..1059e23 100644 --- a/templates/index.html +++ b/templates/index.html @@ -67,7 +67,22 @@ {% for p in players %} - {{ p.player }} (ID: {{ p.player_id }}) +
+
+ {{ p.player }} (ID: {{ p.player_id }}) +
+ {% if p.is_online %} + + + Online + + {% else %} + + + Offline + + {% endif %} +
{% endfor %}