#!/usr/bin/env bash
# Headless TF2 dedicated server: bots on 2fort + GOTV relay. No rendering.
set -u
BASE=/home/ubuntu/tf2stream
mkdir -p "$BASE/srcds/tf/cfg"
cp -f "$BASE/cfg/srcds_server.cfg" "$BASE/srcds/tf/cfg/server.cfg"
# blank MOTD so GOTV viewers get no "Welcome" panel to dismiss
for f in "$BASE/srcds/tf/motd.txt" "$BASE/srcds/tf/motd_text.txt" \
         "$BASE/srcds/tf/cfg/motd_default.txt" "$BASE/srcds/tf/cfg/motd_text_default.txt"; do
  mkdir -p "$(dirname "$f")"; : > "$f"
done
cd "$BASE/srcds"
# srcds_run hardcodes the 32-bit binary (whose replay_srv.so is broken here);
# run the 64-bit server binary directly with its lib path.
export LD_LIBRARY_PATH="$BASE/srcds/bin/linux64:$BASE/srcds/bin:${LD_LIBRARY_PATH:-}"
export SteamAppId=232250
# force everything on the command line (don't rely on server.cfg auto-exec)
exec ./srcds_linux64 -game tf -console -insecure \
  +sv_lan 1 +maxplayers 24 \
  +exec server.cfg \
  +sv_cheats 1 \
  +tv_enable 1 +tv_port 27020 +tv_delay 0 +tv_name EternalBotCam +tv_transmitall 1 \
  +tf_bot_quota 12 +tf_bot_quota_mode fill +tf_bot_difficulty 1 \
  +mp_timelimit 0 +mp_winlimit 0 +mp_maxrounds 0 \
  +map ctf_2fort \
  >"$BASE/logs/srcds.log" 2>&1
