forked from CubeCoders/AMPTemplates
-
Notifications
You must be signed in to change notification settings - Fork 0
/
arma3runhc.ps1
53 lines (49 loc) · 1.57 KB
/
arma3runhc.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# Arguments: [number_clients] [server_binding] [server_port] "<server_password>" "<mod_list>" "<hc_parameters_file>" [start_limit]
# Check if any headless clients are to be run
# If none, immediately exit
if ($args[0] -eq "0") { exit }
# Check if server starts successfully within <start_limit> seconds
# If not, exit
$serverStarted = $false
if ($args.Length -lt 7) {
$startlimit = 180
} else {
$startlimit = $args[6]
}
for ($i = 1; $i -le [int]$startlimit; $i++) {
if (Get-NetUDPEndpoint -LocalPort $args[2] -ErrorAction SilentlyContinue) {
$serverStarted = $true
break
}
Start-Sleep -Seconds 1
}
if (-not $serverStarted) { exit 1 }
# Start the headless clients
$clients = @()
$basePort = [int]$args[2] + 498
if ($args.Length -lt 6) {
$parfile = ""
} else {
$parfile = $args[5]
}
cd "$PSScriptRoot\arma3\233780"
for ($i = 1; $i -le [int]$args[0]; $i++) {
if ($args[1] -eq "0.0.0.0") {
$connect = "127.0.0.1"
} else {
$connect = $args[1]
}
$hcProcess = Start-Process -FilePath "ArmA3Server_x64.exe" -ArgumentList "-client", "-nosound", "-profiles=A3Master", "-connect=${connect}:$($args[2])", "-port=$basePort", "-password=`"$($args[3])`"", "`"-mod=$($args[4])`"", "`"-par=$parfile`"" -WindowStyle Hidden -PassThru
$clients += $hcProcess.Id
}
# Monitor server process and terminate headless clients
# when server terminates
while ($true) {
if (-not (Get-NetUDPEndpoint -LocalPort $args[2] -ErrorAction SilentlyContinue)) {
foreach ($processId in $clients) {
Stop-Process -Id $processId -Force
}
exit 0
}
Start-Sleep -Seconds 1
}