Detect team modes by GAME_TYPE code and sync gametype at match start

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <[email protected]>
This commit is contained in:
Debian
2026-09-18 14:19:37 +02:00
co-authored by Sisyphus
parent 016384ef12
commit cbeab1ae45
3 changed files with 20 additions and 5 deletions
+6
View File
@@ -57,6 +57,12 @@ TEAM_MAP = {
3: 'SPECTATOR' 3: 'SPECTATOR'
} }
# GAME_TYPE codes from MATCH_STARTED that are team-based; matching on the code
# is immune to customized factory titles (g_factoryTitle)
TEAM_GAME_TYPE_CODES = {
'TDM', 'CA', 'CTF', '1FLAG', 'HARVESTER', 'FT', 'DOM', 'RR'
}
TEAM_COLORS = { TEAM_COLORS = {
'RED': '^1(RED)^7', 'RED': '^1(RED)^7',
'BLUE': '^4(BLUE)^7', 'BLUE': '^4(BLUE)^7',
+9 -2
View File
@@ -103,14 +103,15 @@ class EventParser:
def _handle_player_connect(self, data): def _handle_player_connect(self, data):
"""Track a connecting player so the roster is complete; connects to the """Track a connecting player so the roster is complete; connects to the
server land as spectators until they join a team. No feed line: the server land as spectators until they join a team — except reconnects of
already-tracked players, whose known team is kept. No feed line: the
RCON connect broadcast already displays one.""" RCON connect broadcast already displays one."""
name = data.get('NAME') name = data.get('NAME')
if not name: if not name:
return None return None
team = data.get('TEAM') team = data.get('TEAM')
if team is None: if team is None:
team = 'SPECTATOR' team = self.game_state.player_tracker.get_team(name) or 'SPECTATOR'
self.game_state.player_tracker.update_team(name, team) self.game_state.player_tracker.update_team(name, team)
self.game_state.player_tracker.add_player(name) self.game_state.player_tracker.add_player(name)
return None return None
@@ -343,6 +344,12 @@ class EventParser:
# Get Match Time # Get Match Time
self._sync_match_time(data) self._sync_match_time(data)
# GAME_TYPE/FACTORY_TITLE are the authoritative gametype for this match;
# the title alone can be customized and defeat exact team-mode matching
self.game_state.server_info.game_type_code = data.get('GAME_TYPE', '')
if data.get('FACTORY_TITLE'):
self.game_state.server_info.gametype = data['FACTORY_TITLE']
# The PLAYERS array is the authoritative roster at match start: sync # The PLAYERS array is the authoritative roster at match start: sync
# teams (numeric codes via TEAM_MAP) and reset scores, clear dead # teams (numeric codes via TEAM_MAP) and reset scores, clear dead
# markers, and drop stale dedup signatures (TIME restarts at 0) # markers, and drop stale dedup signatures (TIME restarts at 0)
+5 -3
View File
@@ -5,7 +5,7 @@ Tracks server info, players, and teams
""" """
import logging import logging
from .constants import TEAM_MODES, TEAM_MAP, MAX_RECENT_EVENTS from .constants import TEAM_MODES, TEAM_MAP, MAX_RECENT_EVENTS, TEAM_GAME_TYPE_CODES
from .formatter import strip_color_codes from .formatter import strip_color_codes
logger = logging.getLogger('state') logger = logging.getLogger('state')
@@ -18,6 +18,7 @@ class ServerInfo:
self.hostname = 'Unknown' self.hostname = 'Unknown'
self.map = 'Unknown' self.map = 'Unknown'
self.gametype = 'Unknown' self.gametype = 'Unknown'
self.game_type_code = ''
self.timelimit = '0' self.timelimit = '0'
self.fraglimit = '0' self.fraglimit = '0'
self.roundlimit = '0' self.roundlimit = '0'
@@ -36,8 +37,9 @@ class ServerInfo:
self.match_time_last_sync = 0 # Timestamp of last TIME update from server self.match_time_last_sync = 0 # Timestamp of last TIME update from server
def is_team_mode(self): def is_team_mode(self):
"""Check if current gametype is a team mode""" """Check if current gametype is a team mode, by GAME_TYPE code from
return self.gametype in TEAM_MODES MATCH_STARTED or by factory title"""
return self.gametype in TEAM_MODES or self.game_type_code in TEAM_GAME_TYPE_CODES
def reset_round_scores(self): def reset_round_scores(self):
"""Reset round scores (for new matches)""" """Reset round scores (for new matches)"""