@echo off
REM ============================================================
REM  HELLHOUSE join helper (called by PLAY HELLHOUSE.bat).
REM  Arg %1 = server address (LAN or Internet).
REM  Always downloads the CURRENT season wad as _current.wad so
REM  it matches the server no matter which season is live, then
REM  connects. One file, one URL, never changes per season.
REM ============================================================
setlocal
set "ROOT=%~dp0"
set "EXE=%ROOT%zandronum.exe"
set "IWAD=%ROOT%DOOM2.WAD"
set "MOD=%ROOT%brutalv21.50.0.pk3"
set "CUR=%ROOT%_current.wad"
set "SERVER=%~1"
set "WADURL=https://rigzhouse.co.uk/doom/wads/_current.wad"

if not exist "%EXE%"  ( echo [ERROR] zandronum.exe missing from this folder.       & pause & exit /b 1 )
if not exist "%IWAD%" ( echo [ERROR] DOOM2.WAD missing from this folder.           & pause & exit /b 1 )
if not exist "%MOD%"  ( echo [ERROR] brutalv21.50.0.pk3 missing from this folder.  & pause & exit /b 1 )

echo Fetching the current season from the house...
powershell -NoProfile -Command "try{Invoke-WebRequest -UseBasicParsing '%WADURL%' -OutFile '%CUR%'; exit 0}catch{exit 1}"
if not exist "%CUR%" ( echo [WARN] Couldn't fetch the season wad - the server may auto-send it on connect. Continuing... )

echo Launching HELLHOUSE  %SERVER%  ...
start "" "%EXE%" -iwad "%IWAD%" -file "%MOD%" -file "%CUR%" -connect %SERVER%
endlocal
