|
|
|
@@ -1,4 +1,4 @@
|
|
|
|
# wDayzManager v0.7
|
|
|
|
# wDayzManager v0.9
|
|
|
|
# Copyright (c) 2024 Vladislav Salikov aka W0LF aka 'dreamforce'
|
|
|
|
# Copyright (c) 2024 Vladislav Salikov aka W0LF aka 'dreamforce'
|
|
|
|
# https://github.com/dreamforceinc
|
|
|
|
# https://github.com/dreamforceinc
|
|
|
|
# Required module: PSIni
|
|
|
|
# Required module: PSIni
|
|
|
|
@@ -22,12 +22,19 @@ Param (
|
|
|
|
################################################################ [ !!! DON'T EDIT BELOW !!! ] #################################################################
|
|
|
|
################################################################ [ !!! DON'T EDIT BELOW !!! ] #################################################################
|
|
|
|
|
|
|
|
|
|
|
|
[string]$myName = "wDayzManager"
|
|
|
|
[string]$myName = "wDayzManager"
|
|
|
|
[string]$myVersion = "v0.7"
|
|
|
|
[string]$myVersion = "v0.9"
|
|
|
|
[string]$steamScript = $myName + ".txt"
|
|
|
|
|
|
|
|
[string]$iniFile = $myName + ".ini"
|
|
|
|
[string]$iniFile = $myName + ".ini"
|
|
|
|
if (-not (Test-Path -Path $iniFile)) {
|
|
|
|
[string]$steamScript = $myName + ".txt"
|
|
|
|
Write-Warning "Can't find file '$iniFile', creating new..."
|
|
|
|
$Error.Clear()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (($init -eq $true) -and ($update -eq $true)) {
|
|
|
|
|
|
|
|
Write-Error "Only one parameter is accepted - either 'Init' or 'Update'."
|
|
|
|
|
|
|
|
Exit
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function Init {
|
|
|
|
New-Item -ItemType File -Path $iniFile -Value "; $($iniFile)" | Out-Null
|
|
|
|
New-Item -ItemType File -Path $iniFile -Value "; $($iniFile)" | Out-Null
|
|
|
|
|
|
|
|
if (!$?) { Exit }
|
|
|
|
$content = "
|
|
|
|
$content = "
|
|
|
|
[Config]
|
|
|
|
[Config]
|
|
|
|
serverLocation=Z:\Servers\DayzServer
|
|
|
|
serverLocation=Z:\Servers\DayzServer
|
|
|
|
@@ -82,11 +89,17 @@ startupServerMods=
|
|
|
|
additionalParams= -name=Server -AdminLog -FilePatching
|
|
|
|
additionalParams= -name=Server -AdminLog -FilePatching
|
|
|
|
namalskMission=
|
|
|
|
namalskMission=
|
|
|
|
"
|
|
|
|
"
|
|
|
|
Add-Content -Path $iniFile -Value $content -Encoding UTF8
|
|
|
|
Add-Content -Path $iniFile -Value $content -Encoding ASCII
|
|
|
|
$content = $null
|
|
|
|
$content = $null
|
|
|
|
Exit
|
|
|
|
Exit
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ($init) { Init ; Exit }
|
|
|
|
|
|
|
|
if (-not (Test-Path -Path $iniFile)) {
|
|
|
|
|
|
|
|
Write-Warning "Can't find file '$iniFile'. You probably need to run the bat-script with the '/I' parameter."
|
|
|
|
|
|
|
|
Exit
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$date = Get-Date
|
|
|
|
$date = Get-Date
|
|
|
|
[int]$currentDayOfWeek = ([datetime]$date).DayOfWeek
|
|
|
|
[int]$currentDayOfWeek = ([datetime]$date).DayOfWeek
|
|
|
|
[int]$currentDay = ([datetime]$date).Day
|
|
|
|
[int]$currentDay = ([datetime]$date).Day
|
|
|
|
@@ -94,7 +107,6 @@ $date = Get-Date
|
|
|
|
|
|
|
|
|
|
|
|
$date2 = Get-Date -Format 's' | ForEach-Object { $_ -replace 'T', ' ' }
|
|
|
|
$date2 = Get-Date -Format 's' | ForEach-Object { $_ -replace 'T', ' ' }
|
|
|
|
Write-Host "$($date2) Starting $($myName) $($myVersion) script"
|
|
|
|
Write-Host "$($date2) Starting $($myName) $($myVersion) script"
|
|
|
|
Write-Host "init = $($init), update = $($update), noDelete = $($noDelete)"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$ini = $config = $servers = $clientMods = $serverMods = $steamProcess = $null
|
|
|
|
$ini = $config = $servers = $clientMods = $serverMods = $steamProcess = $null
|
|
|
|
$modNI = $modNS = $namalskMission = $pathNamalskMission = $null
|
|
|
|
$modNI = $modNS = $namalskMission = $pathNamalskMission = $null
|
|
|
|
@@ -121,14 +133,6 @@ $config = $ini.Config
|
|
|
|
[string]$updatePeriod = $config.updatePeriod
|
|
|
|
[string]$updatePeriod = $config.updatePeriod
|
|
|
|
[bool]$rotateLogs = [int]$config.rotateLogs
|
|
|
|
[bool]$rotateLogs = [int]$config.rotateLogs
|
|
|
|
|
|
|
|
|
|
|
|
function Init {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function Update {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$clientMods = New-Object 'Collections.Generic.List[Tuple[string,string]]'
|
|
|
|
$clientMods = New-Object 'Collections.Generic.List[Tuple[string,string]]'
|
|
|
|
foreach ($mod in $ini.ClientMods.GetEnumerator()) {
|
|
|
|
foreach ($mod in $ini.ClientMods.GetEnumerator()) {
|
|
|
|
if ($mod.Key -notlike "Comment*" ) {
|
|
|
|
if ($mod.Key -notlike "Comment*" ) {
|
|
|
|
@@ -147,11 +151,13 @@ switch ($updatePeriod) {
|
|
|
|
D { if ($currentHour -eq $updateHour) { $update = $true } }
|
|
|
|
D { if ($currentHour -eq $updateHour) { $update = $true } }
|
|
|
|
W { if (($currentDayOfWeek -eq $updateDay) -and ($currentHour -eq $updateHour)) { $update = $true } }
|
|
|
|
W { if (($currentDayOfWeek -eq $updateDay) -and ($currentHour -eq $updateHour)) { $update = $true } }
|
|
|
|
M { if (($currentDay -eq $updateDay) -and ($currentHour -eq $updateHour)) { $update = $true } }
|
|
|
|
M { if (($currentDay -eq $updateDay) -and ($currentHour -eq $updateHour)) { $update = $true } }
|
|
|
|
Default { $update = $param }
|
|
|
|
default { $update = $false }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Write-Host "Init = $($init), Update = $($update), noDelete = $($noDelete)"
|
|
|
|
|
|
|
|
|
|
|
|
if ($update) {
|
|
|
|
if ($update) {
|
|
|
|
If (-NOT ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) {
|
|
|
|
if (-not ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) {
|
|
|
|
Write-Warning "You do not have Administrator rights to run this script!`nPlease re-run this script as an Administrator!"
|
|
|
|
Write-Warning "You do not have Administrator rights to run this script!`nPlease re-run this script as an Administrator!"
|
|
|
|
Exit
|
|
|
|
Exit
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@@ -175,8 +181,8 @@ if ($update) {
|
|
|
|
$arr += "quit"
|
|
|
|
$arr += "quit"
|
|
|
|
|
|
|
|
|
|
|
|
# Saving Steam script
|
|
|
|
# Saving Steam script
|
|
|
|
"// $($steamScript) - Steam script" | Out-File -FilePath "$($currentPath)\$($steamScript)" -Encoding Ascii
|
|
|
|
"// $($steamScript) - Steam script" | Out-File -FilePath "$($currentPath)\$($steamScript)" -Encoding ASCII
|
|
|
|
$arr | Out-File -FilePath "$($currentPath)\$($steamScript)" -Encoding Ascii -Append
|
|
|
|
$arr | Out-File -FilePath "$($currentPath)\$($steamScript)" -Encoding ASCII -Append
|
|
|
|
|
|
|
|
|
|
|
|
# Run Steam script
|
|
|
|
# Run Steam script
|
|
|
|
Write-Host "Run Steam script from `"$($currentPath)\$($steamScript)`""
|
|
|
|
Write-Host "Run Steam script from `"$($currentPath)\$($steamScript)`""
|
|
|
|
@@ -244,7 +250,7 @@ if ($rotateLogs) {
|
|
|
|
|
|
|
|
|
|
|
|
Write-Host "Removing old wDayzManager logs..."
|
|
|
|
Write-Host "Removing old wDayzManager logs..."
|
|
|
|
$fileList = $null
|
|
|
|
$fileList = $null
|
|
|
|
$fileList = Get-ChildItem -Path $currentPath\Logs\*.log -Recurse | Where-Object { $_.LastWriteTime.Date -lt $date.AddDays( -3) }
|
|
|
|
$fileList = Get-ChildItem -Path $currentPath\Logs\*.log -Recurse | Where-Object { $_.LastWriteTime.Date -lt $date.AddDays( -2) }
|
|
|
|
# Write-Host $fileList -Separator "`n"
|
|
|
|
# Write-Host $fileList -Separator "`n"
|
|
|
|
foreach ($file in $fileList) {
|
|
|
|
foreach ($file in $fileList) {
|
|
|
|
Remove-Item -Path $file
|
|
|
|
Remove-Item -Path $file
|
|
|
|
@@ -270,6 +276,7 @@ if (-not ([string]::IsNullOrEmpty($becLocation))) {
|
|
|
|
if (-not (Test-Path -Path "$($becLocation)\")) {
|
|
|
|
if (-not (Test-Path -Path "$($becLocation)\")) {
|
|
|
|
New-Item -ItemType Directory -Path "$($becLocation)\" | Out-Null
|
|
|
|
New-Item -ItemType Directory -Path "$($becLocation)\" | Out-Null
|
|
|
|
New-Item -ItemType Directory -Path "$($becLocation)\Config\" | Out-Null
|
|
|
|
New-Item -ItemType Directory -Path "$($becLocation)\Config\" | Out-Null
|
|
|
|
|
|
|
|
New-Item -ItemType Directory -Path "$($becLocation)\Log\" | Out-Null
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@@ -346,10 +353,26 @@ foreach ($srv in $servers) {
|
|
|
|
Exit
|
|
|
|
Exit
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (-not (Test-Path -Path "$($serverProfile)\BattlEye\")) {
|
|
|
|
|
|
|
|
Write-Host "Creating new folder: `"$($serverProfile)\BattlEye\`""
|
|
|
|
|
|
|
|
New-Item -ItemType Directory -Path "$($serverProfile)\BattlEye\" | Out-Null
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (-not (Test-Path -Path "$($serverProfile)\BattlEye\bans.txt")) {
|
|
|
|
if (-not (Test-Path -Path "$($serverProfile)\BattlEye\bans.txt")) {
|
|
|
|
|
|
|
|
Write-Host "Copying file from `"$($serverLocation)\ban.txt`" to `"$($serverProfile)\BattlEye\bans.txt`""
|
|
|
|
Copy-Item -Path "$($serverLocation)\ban.txt" -Destination "$($serverProfile)\BattlEye\bans.txt" -ErrorAction Stop
|
|
|
|
Copy-Item -Path "$($serverLocation)\ban.txt" -Destination "$($serverProfile)\BattlEye\bans.txt" -ErrorAction Stop
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (-not (Test-Path -Path "$($serverProfile)\BattlEye\BEServer_x64*.cfg")) {
|
|
|
|
|
|
|
|
Write-Host "Creating new file: `"$($serverProfile)\BattlEye\BEServer_x64.cfg`""
|
|
|
|
|
|
|
|
New-Item -ItemType File -Path "$($serverProfile)\BattlEye\BEServer_x64.cfg" | Out-Null
|
|
|
|
|
|
|
|
if (!$?) { Exit }
|
|
|
|
|
|
|
|
[int]$rconPort = [int]$serverPort + 5
|
|
|
|
|
|
|
|
$content = "RConPassword ChangeMe123`r`nRConPort $($rconPort)`r`nRestrictRCon 0"
|
|
|
|
|
|
|
|
Add-Content -Path "$($serverProfile)\BattlEye\BEServer_x64.cfg" -Value $content -Encoding ASCII
|
|
|
|
|
|
|
|
$content = $null
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$bec = "`"$($becLocation)\bec.exe`""
|
|
|
|
$bec = "`"$($becLocation)\bec.exe`""
|
|
|
|
$becArguments = "-f `"$($instance).cfg`" --dsc"
|
|
|
|
$becArguments = "-f `"$($instance).cfg`" --dsc"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@@ -370,14 +393,14 @@ foreach ($srv in $servers) {
|
|
|
|
$atLogsLocation += '\' + $logsName
|
|
|
|
$atLogsLocation += '\' + $logsName
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
If (!(Test-Path -PathType Container $rotatedLogsLocation)) {
|
|
|
|
If (-not (Test-Path -PathType Container $rotatedLogsLocation)) {
|
|
|
|
New-Item -ItemType Directory -Path $rotatedLogsLocation | Out-Null
|
|
|
|
New-Item -ItemType Directory -Path $rotatedLogsLocation | Out-Null
|
|
|
|
Write-Host "Created new folder: $($rotatedLogsLocation)"
|
|
|
|
Write-Host "Created new folder: $($rotatedLogsLocation)"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if ($noDelete) {
|
|
|
|
if ($noDelete) {
|
|
|
|
$destDelDir = "$($rotatedLogsLocation)\DeletedLogs"
|
|
|
|
$destDelDir = "$($rotatedLogsLocation)\DeletedLogs"
|
|
|
|
If (!(Test-Path -PathType Container $destDelDir)) {
|
|
|
|
If (-not (Test-Path -PathType Container $destDelDir)) {
|
|
|
|
New-Item -ItemType Directory -Path $destDelDir | Out-Null
|
|
|
|
New-Item -ItemType Directory -Path $destDelDir | Out-Null
|
|
|
|
Write-Host "Created new folder: $($destDelDir)"
|
|
|
|
Write-Host "Created new folder: $($destDelDir)"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@@ -418,7 +441,7 @@ foreach ($srv in $servers) {
|
|
|
|
if ($becLocation) {
|
|
|
|
if ($becLocation) {
|
|
|
|
$becDestDir = "$($rotatedLogsLocation)\$($becFolderName)"
|
|
|
|
$becDestDir = "$($rotatedLogsLocation)\$($becFolderName)"
|
|
|
|
|
|
|
|
|
|
|
|
If (!(Test-Path -PathType Container $becDestDir)) {
|
|
|
|
If (-not (Test-Path -PathType Container $becDestDir)) {
|
|
|
|
New-Item -ItemType Directory -Path $becDestDir | Out-Null
|
|
|
|
New-Item -ItemType Directory -Path $becDestDir | Out-Null
|
|
|
|
Write-Host "Created new folder: $($becDestDir)"
|
|
|
|
Write-Host "Created new folder: $($becDestDir)"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@@ -458,7 +481,7 @@ foreach ($srv in $servers) {
|
|
|
|
if ($atLogsLocation) {
|
|
|
|
if ($atLogsLocation) {
|
|
|
|
$atDestDir = "$($rotatedLogsLocation)\$($atFolderName)"
|
|
|
|
$atDestDir = "$($rotatedLogsLocation)\$($atFolderName)"
|
|
|
|
|
|
|
|
|
|
|
|
If (!(Test-Path -PathType Container $atDestDir)) {
|
|
|
|
If (-not (Test-Path -PathType Container $atDestDir)) {
|
|
|
|
New-Item -ItemType Directory -Path $atDestDir | Out-Null
|
|
|
|
New-Item -ItemType Directory -Path $atDestDir | Out-Null
|
|
|
|
Write-Host "Created new folder: $($atDestDir)"
|
|
|
|
Write-Host "Created new folder: $($atDestDir)"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|