From e6e32033adbf95ccddd2f88b7f599ad1fb4057bc Mon Sep 17 00:00:00 2001 From: pfl Date: Fri, 9 Jan 2026 14:00:32 +0100 Subject: [PATCH] Add live match timer countdown - Add match_time_last_sync timestamp to track server updates - Update timestamp in parser when TIME events received - Calculate elapsed time in UI for live countdown - Timer now ticks in real-time between server events --- parser.py | 6 ++++++ state.py | 1 + ui.py | 11 +++++++++-- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/parser.py b/parser.py index 8aaee05..b3abcd7 100644 --- a/parser.py +++ b/parser.py @@ -94,6 +94,7 @@ class EventParser: # Get Match Time if 'TIME' in data: self.game_state.server_info.match_time = int(data['TIME']) + self.game_state.server_info.match_time_last_sync = time.time() if 'KILLER' not in data: return None @@ -138,6 +139,7 @@ class EventParser: # Get Match Time if 'TIME' in data: self.game_state.server_info.match_time = int(data['TIME']) + self.game_state.server_info.match_time_last_sync = time.time() if 'VICTIM' not in data: return None @@ -244,6 +246,7 @@ class EventParser: # Get Match Time if 'TIME' in data: self.game_state.server_info.match_time = int(data['TIME']) + self.game_state.server_info.match_time_last_sync = time.time() team_won = data.get('TEAM_WON') round_num = data.get('ROUND', 0) @@ -265,6 +268,7 @@ class EventParser: # Get Match Time if 'TIME' in data: self.game_state.server_info.match_time = int(data['TIME']) + self.game_state.server_info.match_time_last_sync = time.time() name = data.get('NAME', 'Unknown') medal = data.get('MEDAL', 'UNKNOWN') @@ -299,6 +303,7 @@ class EventParser: # Get Match Time if 'TIME' in data: self.game_state.server_info.match_time = int(data['TIME']) + self.game_state.server_info.match_time_last_sync = time.time() if self.game_state.server_info.is_team_mode(): return f"^8^2[GAME ON]^0 ^7Match has started - ^1^8RED ^0^7vs. ^4^8BLUE\n" @@ -320,6 +325,7 @@ class EventParser: # Get Match Time if 'TIME' in data: self.game_state.server_info.match_time = int(data['TIME']) + self.game_state.server_info.match_time_last_sync = time.time() if not self.game_state.server_info.is_team_mode(): return None diff --git a/state.py b/state.py index 1d35fe6..d6dd7d4 100644 --- a/state.py +++ b/state.py @@ -34,6 +34,7 @@ class ServerInfo: self.dead_players = {} self.round_end_time = None self.match_time = 0 + self.match_time_last_sync = 0 # Timestamp of last TIME update from server def is_team_mode(self): """Check if current gametype is a team mode""" diff --git a/ui.py b/ui.py index 7957f20..d9aa532 100644 --- a/ui.py +++ b/ui.py @@ -9,6 +9,7 @@ import curses.textpad import threading import queue import logging +import time from config import COLOR_PAIRS, INFO_WINDOW_HEIGHT, INFO_WINDOW_Y, OUTPUT_WINDOW_Y, INPUT_WINDOW_HEIGHT, TEAM_MODES, MAX_COMMAND_HISTORY from cvars import autocomplete, COMMAND_SIGNATURES, get_signature_with_highlight, get_argument_suggestions, COMMAND_ARGUMENTS @@ -535,8 +536,14 @@ class UIManager: timer_display = "" if server_info.match_time > 0 and not server_info.warmup: - mins = server_info.match_time // 60 - secs = server_info.match_time % 60 + # Calculate live time: add elapsed seconds since last server update + current_time = server_info.match_time + if server_info.match_time_last_sync > 0: + elapsed = int(time.time() - server_info.match_time_last_sync) + current_time += elapsed + + mins = current_time // 60 + secs = current_time % 60 timer_display = f"^3^0Time:^8^7 {mins}:{secs:02d}^0" else: timer_display = "^3^0Time:^8^7 0:00^0"