Update main.py

This commit is contained in:
ilyastar9999
2025-12-03 14:33:47 +03:00
parent 1a59806940
commit 3a1d4141af

View File

@@ -250,6 +250,10 @@ async def socketio_listener():
new_lost = current_lost - prev_lost
fp_change = current_fp_score - prev_fp_score
# Skip creating attack records if this is the first time we see this team+service
# (prev_state is None means first update - just initialize state)
is_first_update = prev_state is None
# Update current state in database
await conn.execute("""
INSERT INTO scoreboard_state (team_id, service_name, stolen_flags, lost_flags, fp_score, last_updated)
@@ -258,8 +262,8 @@ async def socketio_listener():
DO UPDATE SET stolen_flags = $3, lost_flags = $4, fp_score = $5, last_updated = NOW()
""", team_id, service_name, current_stolen, current_lost, current_fp_score)
# Create attack record only for NEW stolen flags (FP gained)
if new_stolen > 0:
# Create attack record only for NEW stolen flags (FP gained) - skip first update
if new_stolen > 0 and not is_first_update:
timestamp = datetime.utcnow()
attack_id = f"r{round_num}_stolen_team{team_id}_{service_name}_{int(timestamp.timestamp())}"
@@ -279,8 +283,8 @@ async def socketio_listener():
else:
print(f" 📌 Team {team_id} stole {new_stolen} NEW flags from {service_name} (+{fp_for_attack:.2f} FP)")
# Create attack record only for NEW lost flags (FP lost)
if new_lost > 0:
# Create attack record only for NEW lost flags (FP lost) - skip first update
if new_lost > 0 and not is_first_update:
timestamp = datetime.utcnow()
attack_id = f"r{round_num}_lost_team{team_id}_{service_name}_{int(timestamp.timestamp())}"