Update main.py
This commit is contained in:
@@ -250,6 +250,10 @@ async def socketio_listener():
|
|||||||
new_lost = current_lost - prev_lost
|
new_lost = current_lost - prev_lost
|
||||||
fp_change = current_fp_score - prev_fp_score
|
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
|
# Update current state in database
|
||||||
await conn.execute("""
|
await conn.execute("""
|
||||||
INSERT INTO scoreboard_state (team_id, service_name, stolen_flags, lost_flags, fp_score, last_updated)
|
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()
|
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)
|
""", team_id, service_name, current_stolen, current_lost, current_fp_score)
|
||||||
|
|
||||||
# Create attack record only for NEW stolen flags (FP gained)
|
# Create attack record only for NEW stolen flags (FP gained) - skip first update
|
||||||
if new_stolen > 0:
|
if new_stolen > 0 and not is_first_update:
|
||||||
timestamp = datetime.utcnow()
|
timestamp = datetime.utcnow()
|
||||||
attack_id = f"r{round_num}_stolen_team{team_id}_{service_name}_{int(timestamp.timestamp())}"
|
attack_id = f"r{round_num}_stolen_team{team_id}_{service_name}_{int(timestamp.timestamp())}"
|
||||||
|
|
||||||
@@ -279,8 +283,8 @@ async def socketio_listener():
|
|||||||
else:
|
else:
|
||||||
print(f" 📌 Team {team_id} stole {new_stolen} NEW flags from {service_name} (+{fp_for_attack:.2f} FP)")
|
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)
|
# Create attack record only for NEW lost flags (FP lost) - skip first update
|
||||||
if new_lost > 0:
|
if new_lost > 0 and not is_first_update:
|
||||||
timestamp = datetime.utcnow()
|
timestamp = datetime.utcnow()
|
||||||
attack_id = f"r{round_num}_lost_team{team_id}_{service_name}_{int(timestamp.timestamp())}"
|
attack_id = f"r{round_num}_lost_team{team_id}_{service_name}_{int(timestamp.timestamp())}"
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user