@echo off
:: civpb.com — lets two players be in the Pitboss game at the same time.
:: Points the dead GameSpy "NAT negotiation" hostnames at civpb.com, which
:: brokers (and relays) the direct connection between two players.
:: Run as administrator. Safe to run twice. Remove: delete the civpb lines
:: from C:\Windows\System32\drivers\etc\hosts
set HOSTS=%SystemRoot%\System32\drivers\etc\hosts
net session >nul 2>&1
if %errorlevel% neq 0 (
  echo Please right-click this file and choose "Run as administrator".
  pause
  exit /b 1
)
copy /y "%HOSTS%" "%HOSTS%.civpb-backup" >nul
:: Windows uses the FIRST matching hosts line, so any older natneg entries
:: (e.g. from a lobby hosts file) must go, or ours would never be used.
findstr /v /i /c:"natneg" "%HOSTS%" > "%TEMP%\hosts.civpb"
copy /y "%TEMP%\hosts.civpb" "%HOSTS%" >nul
(
  echo.
  echo # civpb natneg - Civ4 connection broker, see https://civpb.com/connect
  echo 46.224.21.154 natneg1.gamespy.com
  echo 46.224.21.154 natneg2.gamespy.com
  echo 46.224.21.154 natneg3.gamespy.com
  echo 46.224.21.154 civ4bts.natneg1.gamespy.com
  echo 46.224.21.154 civ4bts.natneg2.gamespy.com
  echo 46.224.21.154 civ4bts.natneg3.gamespy.com
  echo 46.224.21.154 civ4.natneg1.gamespy.com
  echo 46.224.21.154 civ4.natneg2.gamespy.com
  echo 46.224.21.154 civ4.natneg3.gamespy.com
  echo 46.224.21.154 natneg1.g.zulan.net
  echo 46.224.21.154 natneg2.g.zulan.net
  echo 46.224.21.154 natneg3.g.zulan.net
  echo 46.224.21.154 civ4bts.natneg1.g.zulan.net
  echo 46.224.21.154 civ4bts.natneg2.g.zulan.net
  echo 46.224.21.154 civ4bts.natneg3.g.zulan.net
) >> "%HOSTS%"
ipconfig /flushdns >nul
echo Done. civpb.com now brokers your connections to other players.
echo (Previous hosts file saved as hosts.civpb-backup; other lobby entries were kept.)
pause
