Update main.py
This commit is contained in:
@@ -106,6 +106,9 @@ async def socketio_listener():
|
||||
is_our_attack = attacker_id == OUR_TEAM_ID
|
||||
is_attack_to_us = victim_id == OUR_TEAM_ID
|
||||
|
||||
print(f"Flag event: attacker={attacker_id}, victim={victim_id}, service={service_name}, points={attacker_delta:.2f}")
|
||||
print(f" Our team: {OUR_TEAM_ID}, is_our_attack={is_our_attack}, is_attack_to_us={is_attack_to_us}")
|
||||
|
||||
if is_our_attack or is_attack_to_us:
|
||||
conn = await db_pool.acquire()
|
||||
try:
|
||||
@@ -117,6 +120,7 @@ async def socketio_listener():
|
||||
""", attack_id, attacker_id, victim_id, service_name, timestamp, float(attacker_delta), is_our_attack, is_attack_to_us)
|
||||
|
||||
if is_attack_to_us and attacker_delta >= ALERT_THRESHOLD_POINTS:
|
||||
print(f" Sending alert: points {attacker_delta:.2f} >= threshold {ALERT_THRESHOLD_POINTS}")
|
||||
alert_message = f"🚨 ATTACK DETECTED!\nTeam {attacker_id} stole flag from {service_name}\nPoints lost: {attacker_delta:.2f} FP"
|
||||
|
||||
# Get service_id from controller if available
|
||||
@@ -143,6 +147,12 @@ async def socketio_listener():
|
||||
""", attack_id, alert_message)
|
||||
await send_telegram_alert(alert_message, service_id=service_id, service_name=service_name)
|
||||
await conn.execute("UPDATE attack_alerts SET notified = true WHERE id = $1", alert_id)
|
||||
print(f" Alert sent successfully")
|
||||
else:
|
||||
if is_our_attack:
|
||||
print(f" Our successful attack - no alert needed")
|
||||
else:
|
||||
print(f" Attack to us but below threshold: {attacker_delta:.2f} < {ALERT_THRESHOLD_POINTS}")
|
||||
finally:
|
||||
await db_pool.release(conn)
|
||||
except Exception as e:
|
||||
@@ -288,14 +298,15 @@ async def socketio_listener():
|
||||
|
||||
@sio.event
|
||||
async def connect():
|
||||
pass
|
||||
print(f"✅ Connected to scoreboard at {SCOREBOARD_URL}")
|
||||
|
||||
@sio.event
|
||||
async def disconnect():
|
||||
pass
|
||||
print(f"❌ Disconnected from scoreboard")
|
||||
|
||||
while True:
|
||||
try:
|
||||
print(f"Connecting to {SCOREBOARD_URL}...")
|
||||
await sio.connect(
|
||||
SCOREBOARD_URL,
|
||||
namespaces=['/live_events'],
|
||||
@@ -303,6 +314,7 @@ async def socketio_listener():
|
||||
)
|
||||
await sio.wait()
|
||||
except Exception as e:
|
||||
print(f"Connection error: {e}")
|
||||
await asyncio.sleep(5)
|
||||
|
||||
# Lifespan context
|
||||
|
||||
Reference in New Issue
Block a user