79 lines
4.6 KiB
PowerShell
79 lines
4.6 KiB
PowerShell
param(
|
|||
|
|
[string]$ServerDirectory = 'C:/Users/ScarPC/Documents/NeoForge Server 26.2',
|
||
|
|
[string]$Java = 'C:/Program Files/Java/jdk-26.0.2/bin/java.exe',
|
||
|
|
[int]$Port = 26705,
|
||
|
|
[string]$AstraPlusJar = 'C:/Users/ScarPC/Documents/Plugins/AstraPlus/build/libs/AstraPlus-0.5.67.jar'
|
||
|
|
)
|
||
|
|
$ErrorActionPreference = 'Stop'
|
||
|
|
$repo = Split-Path $PSScriptRoot -Parent
|
||
|
|
$version = [regex]::Match((Get-Content "$repo/build.gradle.kts" -Raw), '(?m)^version = "([^"]+)"').Groups[1].Value
|
||
|
|
$run = Join-Path $repo ('build/weapons-capture-' + (Get-Date -Format 'yyyyMMdd-HHmmss') + '-' + [guid]::NewGuid().ToString('N').Substring(0,6))
|
||
|
|
$serverRun = Join-Path $run 'server'
|
||
|
|
$clientRun = Join-Path $run 'client'
|
||
|
|
New-Item -ItemType Directory -Path "$serverRun/mods", "$clientRun/resourcepacks" -Force | Out-Null
|
||
|
|
Copy-Item -LiteralPath $AstraPlusJar, "$repo/build/libs/AstraWeapons-0.1.0.jar", "$repo/build/libs/AstraWeapons-0.1.0-verification.jar" -Destination "$serverRun/mods"
|
||
|
|
New-Item -ItemType Directory -Path "$serverRun/astraplus" -Force | Out-Null
|
||
|
|
$serverRoot = (Resolve-Path -LiteralPath $ServerDirectory).Path.Replace('\','/')
|
||
|
|
$argsText = (@(foreach ($line in (Get-Content "$ServerDirectory/libraries/net/neoforged/neoforge/26.2.0.79/win_args.txt")) {
|
||
|
|
if ($line -eq '-DlibraryDirectory=libraries') { '"-DlibraryDirectory=' + $serverRoot + '/libraries"' }
|
||
|
|
elseif ($line.StartsWith('libraries/')) { '"' + $line.Replace('libraries/', "$serverRoot/libraries/") + '"' }
|
||
|
|
else { $line }
|
||
|
|
}) -join "`n")
|
||
|
|
[IO.File]::WriteAllText("$serverRun/server-args.txt", $argsText, [Text.UTF8Encoding]::new($false))
|
||
|
|
[IO.File]::WriteAllText("$serverRun/eula.txt", 'eula=true')
|
||
|
|
[IO.File]::WriteAllText("$serverRun/server.properties", @"
|
||
|
|
server-ip=127.0.0.1
|
||
|
|
server-port=$Port
|
||
|
|
online-mode=false
|
||
|
|
difficulty=normal
|
||
|
|
level-type=minecraft:flat
|
||
|
|
generator-settings={"layers":[{"block":"minecraft:bedrock","height":1},{"block":"minecraft:dirt","height":2},{"block":"minecraft:grass_block","height":1}],"biome":"minecraft:plains"}
|
||
|
|
generate-structures=false
|
||
|
|
spawn-protection=0
|
||
|
|
view-distance=3
|
||
|
|
simulation-distance=3
|
||
|
|
max-tick-time=120000
|
||
|
|
use-native-transport=false
|
||
|
|
"@)
|
||
|
|
[IO.File]::WriteAllText("$clientRun/options.txt", @'
|
||
|
|
resourcePacks:["vanilla","file/AstraPlus.zip"]
|
||
|
|
incompatibleResourcePacks:[]
|
||
|
|
enableVsync:false
|
||
|
|
renderDistance:4
|
||
|
|
simulationDistance:5
|
||
|
|
maxFps:60
|
||
|
|
pauseOnLostFocus:false
|
||
|
|
skipMultiplayerWarning:true
|
||
|
|
onboardAccessibility:false
|
||
|
|
tutorialStep:none
|
||
|
|
soundCategory_master:0.0
|
||
|
|
fullscreen:false
|
||
|
|
'@)
|
||
|
|
Set-Content -LiteralPath "$repo/build/active-weapons-capture.txt" -Value $run
|
||
|
|
New-Item -ItemType Directory -Path "$serverRun/config" -Force | Out-Null
|
||
|
|
[IO.File]::WriteAllText("$serverRun/config/astraplus.json",'{"build":{"onStartup":false},"astraPacks":{"enabled":false,"rebuildAfterExport":false}}')
|
||
|
|
$serverProcess = Start-Process -FilePath $Java -ArgumentList @('-Xms256M','-Xmx3G','-Dastraweapons.isolatedVerification=true','-Dastraweapons.capture=true','@server-args.txt','nogui') -WorkingDirectory $serverRun -WindowStyle Hidden -PassThru -RedirectStandardOutput "$serverRun/stdout.log" -RedirectStandardError "$serverRun/stderr.log"
|
||
|
|
try {
|
||
|
|
$deadline = [DateTime]::UtcNow.AddMinutes(5)
|
||
|
|
while (!(Test-Path -LiteralPath "$serverRun/capture-ready.txt")) {
|
||
|
|
if ($serverProcess.HasExited) { throw "Capture fixture exited before ready: $serverRun" }
|
||
|
|
if ([DateTime]::UtcNow -gt $deadline) { throw "Capture fixture startup timed out: $serverRun" }
|
||
|
|
Start-Sleep -Seconds 1
|
||
|
|
}
|
||
|
|
Copy-Item -LiteralPath "$serverRun/astraplus/output/AstraPlus.zip" -Destination "$clientRun/resourcepacks/AstraPlus.zip"
|
||
|
|
Write-Output "Isolated server ready; launching client: $run"
|
||
|
|
$env:JAVA_HOME = Split-Path (Split-Path $Java -Parent) -Parent
|
||
|
|
Push-Location $repo
|
||
|
|
try {
|
||
|
|
& .\gradlew.bat runWeaponsCaptureClient "-PcaptureClientDirectory=$clientRun" "-PcaptureServerDirectory=$serverRun" "-PcapturePort=$Port" "-PastraPlusJar=$AstraPlusJar" --offline --console=plain *> "$run/client-launch.log"
|
||
|
|
if ($LASTEXITCODE -ne 0) { throw "Client launch failed: $run/client-launch.log" }
|
||
|
|
} finally { Pop-Location }
|
||
|
|
$result = Get-Content -LiteralPath "$clientRun/weapons-client-result.txt" -Raw
|
||
|
|
if (!$result.StartsWith('PASS:')) { throw "Client verification failed: $result ($run)" }
|
||
|
|
Write-Output $result
|
||
|
|
Write-Output "Screenshots: $clientRun/screenshots"
|
||
|
|
} finally {
|
||
|
|
# Graceful fixture shutdown uses only the unique disposable directory created above.
|
||
|
|
[IO.File]::WriteAllText("$serverRun/capture-finished.txt", 'Harness completed')
|
||
|
|
if (!$serverProcess.HasExited -and !$serverProcess.WaitForExit(15000)) { Stop-Process -Id $serverProcess.Id }
|
||
|
|
}
|