#!/usr/bin/env bash
# Task #52: catch B's crash during the respawn CreatePlayerVehicle.
# B (the victim, port 1601) runs under cdb; A force-kills it cross-pod.
set -x
cd /c/git/bt411/content || exit 1
rm -f mp_a.log mp_b.log

BT_LOG=mp_b.log BT_AFFINITY=0x2 BT_MP_LOG=1 BT_MP_NET=1 BT_DEATH_LOG=1 BT_SCORE_LOG=1 \
  "/c/Program Files (x86)/Windows Kits/10/Debuggers/x86/cdb.exe" -lines \
  -cf /c/git/bt411/scratchpad/respawn_bp.txt \
  ../build/Debug/btl4.exe -egg MP.EGG -net 1601 \
  > /c/git/bt411/scratchpad/respawn_cdb_out.txt 2>&1 &
sleep 4
BT_LOG=mp_a.log BT_AFFINITY=0x1 BT_MP_FORCE_DMG=1 BT_MP_LOG=1 \
  ../build/Debug/btl4.exe -egg MP.EGG -net 1501 &
sleep 6
python ../tools/btconsole.py MP.EGG 127.0.0.1:1501 127.0.0.1:1601 &
PC=$!
# kill takes ~35s of force-damage + 5s respawn + create
sleep 90
kill $PC 2>/dev/null
echo "=== cdb tail ==="
tail -n 40 /c/git/bt411/scratchpad/respawn_cdb_out.txt
taskkill //F //IM btl4.exe 2>/dev/null
taskkill //F //IM cdb.exe 2>/dev/null
taskkill //F //IM python.exe 2>/dev/null
echo "=== DONE ==="
