Added servers updating options

This commit is contained in:
Vladislav Salikov
2024-11-11 19:12:05 +03:00
parent acdcf23a1b
commit a8a061464f
4 changed files with 188 additions and 127 deletions

View File

@@ -1,5 +1,10 @@
@echo off
set scriptPath=%~dp0
set customPath=D:\DayZ\Server\.customs
cd /d %scriptPath%
pushd %scriptPath%
set update=0
if "%1" equ "/U" set update=1
if "%1" equ "/u" set update=1
@@ -7,6 +12,11 @@ if "%1" equ "-U" set update=1
if "%1" equ "-u" set update=1
if "%1" equ "--update" set update=1
cd /d %scriptPath%
@REM powershell -ExecutionPolicy RemoteSigned -File wDayzManager.ps1 %update%
powershell -ExecutionPolicy RemoteSigned -File wDayzManager.ps1 %update% > wDayzManager.log
powershell -ExecutionPolicy RemoteSigned -File wDayzManager.ps1 %update%
@REM powershell -ExecutionPolicy RemoteSigned -File wDayzManager.ps1 %update% > wDayzManager.log
@REM echo Customization...
@REM cd /d %customPath%
@REM copy /Y messages.xml d:\dayz\server\mpmissions\hardcore.namalsk\db
popd

View File

@@ -6,15 +6,24 @@ steamCMD=D:\DayZ\SteamCMD
steamUser=w0lf_2k
appidGame=221100
appidServer=223350
namalskMission=Regular
rotateLogs=1
rotateLogs=0
daysAmount=3
rotatedLogsFolderName=RotatedLogs
; rotatedLogsFolderName=
becFolderName=BEC
; becFolderName=
atFolderName=CommunityOnlineTools
; atFolderName=VPPAdminTools
atFolderName=VPPAdminTools
; atFolderName=CommunityOnlineTools
; Server updating settings:
; D = Daily - Updates are checked daily at the hours specified in parameter 'updateHour' (0 - 23). In this case, parameter 'updateDay' is ignored.
; W = Weekly - Updates are checked weekly at the hours specified in parameter 'updateHour' (0 - 23). Parameter 'updateDay' specifies the day of the week (0 - 6, 0 = Sunday).
; M = Monthly - Updates are checked monthly at the hours specified in parameter 'updateHour' (0 - 23). Parameter 'updateDay' specifies the day of the month (1 - 31. Be careful with February!).
; Any other value disables the updates.
updatePeriod=W
updateDay=1
updateHour=4
[ClientMods]
@GAZ_TIGR=2731398623
@@ -34,13 +43,18 @@ serverPort=35500
serverConfig=serverDZ.cfg
serverExeName=DayZServer_x64.exe
serverCPU=4
startupClientMods=@CF;@COT
; startupClientMods=@CF;@COT
startupClientMods=@CF;@VPPAdminTools;@Namalsk_Island;@Namalsk_Survival
startupServerMods=
additionalParams= -name=Server -filePatching
namalskMission=Hardcore
[Server 6]
serverPort=35600
serverConfig=serverDZ.cfg
serverExeName=DayZServer_x64.exe
serverCPU=2
startupClientMods=@CF;@VPPAdminTools
startupServerMods=
; [Server 6]
; serverPort=35600
; serverConfig=serverDZ.cfg
; serverExeName=DayZServer_x64.exe
; serverCPU=2
; startupClientMods=@CF;@VPPAdminTools
; startupServerMods=
; additionalParams= -name=Server -adminLog -filePatching
; namalskMission=Hardcore

View File

@@ -10,23 +10,24 @@ param (
[int]
$param = 0
)
# $date = (Get-Date).ToString()
$date = Get-Date
[string]$logFile = ".\wDayzManager.log"
# $date | Out-File -FilePath $logFile
[bool]$update = $param
if ($update) {
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!"
Break
}
[bool]$noDelete = $true # For tests - don't delete logs
[string]$logFile = ".\wDayzManager.log"
[string]$steamScript = "wDayzManager.txt"
[string]$iniFile = "wDayzManager.ini"
if (-not (Test-Path $iniFile)) {
Write-Error "Can't find file '$iniFile'"
Exit
}
$date = Get-Date
[int]$currentDayOfWeek = ([datetime]$date).DayOfWeek
[int]$currentDay = ([datetime]$date).Day
[int]$currentHour = ([datetime]$date).Hour
$ini = $config = $servers = $clientMods = $serverMods = $steamProcess = $null
$namalskMission = $nPath = $nPath2 = $dayzProcess = $becProcess = $instance = $null
$modNI = $modNS = $namalskMission = $pathNamalskMission = $null
$dayzProcess = $becProcess = $instance = $null
$becLocation = $rotatedLogsFolderName = $atFolderName = $serverLocation = $null
$steamCMD = $steamUser = $appidServer = $appidGame = $rotateLogs = $daysAmount = $null
$serverPort = $serverConfig = $serverExeName = $serverCPU = $null
@@ -34,22 +35,18 @@ $startupClientMods = $startupServerMods = $startupMods = $startupParams = $null
$serverProfile = $additionalParams = $dayzArguments = $dayz = $bec = $becArguments = $null
$logsName = $atLogsLocation = $becLogsLocation = $rotatedLogsLocation = $null
[bool]$noDelete = $true # For tests - don't delete logs
[string]$steamScript = "wDayzManager.txt"
[string]$iniFile = "wDayzManager.ini"
if (-not (Test-Path $iniFile)) {
Write-Error "Can't find file '$iniFile'"
Exit 1
}
Write-Host "=========="
$ini = (Get-IniContent -FilePath $iniFile)
$config = $ini.Config
$serverLocation = $config.serverLocation
$steamCMD = $config.steamCMD
$steamUser = $config.steamUser
$appidServer = $config.appidServer
$appidGame = $config.appidGame
[string]$serverLocation = $config.serverLocation
[string]$steamCMD = $config.steamCMD
[string]$steamUser = $config.steamUser
[int]$appidGame = $config.appidGame
[int]$appidServer = $config.appidServer
[int]$updateDay = $config.updateDay
[int]$updateHour = $config.updateHour
[string]$updatePeriod = $config.updatePeriod
[bool]$rotateLogs = [int]$config.rotateLogs
$clientMods = New-Object 'Collections.Generic.List[Tuple[string,string]]'
@@ -66,22 +63,24 @@ foreach ($mod in $ini.ServerMods.GetEnumerator()) {
}
}
# $clientMods.Item1 | ForEach-Object {
# if ($_ -like "*namalsk*" -and $_ -like "*survival*") {
# $namalskMission = $config.namalskMission
# if (($namalskMission -eq "regular") -or ($namalskMission -eq "hardcore")) {
# $nPath = "$($namalskMission)\$($namalskMission).namalsk"
# $nPath2 = Split-Path -Path $nPath -Leaf
# }
# }
# }
switch ($updatePeriod) {
D { if ($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 } }
Default { $update = $param }
}
if ($update) {
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!"
Exit
}
Write-Host "Start updating server..."
if (-not (Test-Path $steamCMD)) {
Write-Error "Can't find folder '$steamCMD'"
Exit 2
Exit
}
$currentPath = Get-Location
@@ -106,11 +105,12 @@ if ($update) {
$steamProcess = Start-Process -FilePath "$($steamCMD)\steamcmd.exe" -ArgumentList "+runscript $($currentPath)\$($steamScript) +quit" -PassThru -Wait -NoNewWindow
if ($steamProcess.ExitCode -ne 0) {
Write-Error "$_ failed with error code $($steamProcess.ExitCode)"
Exit $steamProcess.ExitCode
Exit
}
Write-Host
# Making symbolic links to mods
Write-Host "`r`nMaking symbolic links to mods:"
Write-Host "Making symbolic links to mods:"
$clientMods | ForEach-Object {
New-Item -ItemType SymbolicLink -Path "$($serverLocation)\$($_.Item1)" -Target "$($serverLocation)\steamapps\workshop\content\$($appidGame)\$($_.Item2)" -Force
Copy-Item -Path "$($serverLocation)\$($_.Item1)\Keys\*.bikey" -Destination "$($serverLocation)\keys\" -Force
@@ -121,54 +121,44 @@ if ($update) {
}
Start-Sleep -Seconds 1
# Patching Namalsk
$clientMods.Item1 | ForEach-Object {
if ($_ -like "*namalsk*" -and $_ -like "*survival*") {
$namalskMission = $config.namalskMission
if (($namalskMission -eq "regular") -or ($namalskMission -eq "hardcore")) {
Write-Host "`r`nCopying $($namalskMission).namalsk ..."
$nPath = "$($namalskMission)\$($namalskMission).namalsk"
$nPath2 = Split-Path -Path $nPath -Leaf
# # Customizing servers
# # Overwriting default messages.xml from Namalsk by custom file
# if (Test-Path -Path "$($serverLocation)\.customs") {
# Copy-Item -Path "$($serverLocation)\.customs\messages.xml" -Destination "$($serverLocation)\mpmissions\$($nPath2)\db\"
# }
$whatFind_NI = "2288339650"
$replaceWith_NI = "2289456201"
$whatFind_NS = "2288336145"
$replaceWith_NS = "2289461232"
Copy-Item -Path "${serverLocation}\@Namalsk_Survival\Extras\${nPath}\" -Destination "${serverLocation}\mpmissions\" -Recurse -Force
Start-Sleep -Seconds 1
# Patching meta.cpp files
Write-Host "`r`nPatching Namalsk ..."
$content = Get-Content -Path "${serverLocation}\@Namalsk_Island\meta.cpp"
$content = $content -replace $whatFind_NI, $replaceWith_NI
Set-Content -Path "${serverLocation}\@Namalsk_Island\meta.cpp" -Value $content
$content = Get-Content -Path "${serverLocation}\@Namalsk_Survival\meta.cpp"
$content = $content -replace $whatFind_NS, $replaceWith_NS
Set-Content -Path "${serverLocation}\@Namalsk_Survival\meta.cpp" -Value $content
}
}
}
# Customizing servers
# Overwriting default messages.xml from Namalsk by custom file
if (Test-Path -Path "$($serverLocation)\.customs") {
Copy-Item -Path "$($serverLocation)\.customs\messages.xml" -Destination "$($serverLocation)\mpmissions\$($nPath2)\db\"
}
Write-Host "`r`nEnd of update region.`r`n"
Write-Host "End of updating server."
Start-Sleep -Seconds 1
}
Write-Host
if (-not ([string]::IsNullOrEmpty($config.becFolderName))) {
$becLocation = "$($serverLocation)\$($config.becFolderName)"
# Write-Host "becLocation: $($becLocation)"
}
# Patching Namalsk
[bool]$isNamalskIslandPresent = $false
[bool]$isNamalskSurvivalPresent = $false
if (-not ([string]::IsNullOrEmpty($config.atFolderName))) {
$atFolderName = $config.atFolderName
# Write-Host "atFolderName: $($atFolderName)"
$clientMods.Item1 | ForEach-Object {
if ($_ -like "*namalsk*" -and $_ -like "*island*") {
$isNamalskIslandPresent = $true
$modNI = $_
Write-Host "Patching Namalsk Island server meta.cpp file ..."
$whatFind_NI = "2288339650"
$replaceWith_NI = "2289456201"
$content = Get-Content -Path "$($serverLocation)\$($modNI)\meta.cpp"
$content = $content -replace $whatFind_NI, $replaceWith_NI
Set-Content -Path "$($serverLocation)\$($modNI)\meta.cpp" -Value $content
}
if ($_ -like "*namalsk*" -and $_ -like "*survival*") {
$isNamalskSurvivalPresent = $true
$modNS = $_
Write-Host "Patching Namalsk Survival server meta.cpp file ..."
$whatFind_NS = "2288336145"
$replaceWith_NS = "2289461232"
$content = Get-Content -Path "$($serverLocation)\$($modNS)\meta.cpp"
$content = $content -replace $whatFind_NS, $replaceWith_NS
Set-Content -Path "$($serverLocation)\$($modNS)\meta.cpp" -Value $content
}
}
Write-Host
if ($rotateLogs) {
$daysAmount = [Math]::Abs($config.daysAmount)
@@ -177,6 +167,14 @@ if ($rotateLogs) {
}
}
if (-not ([string]::IsNullOrEmpty($config.becFolderName))) {
$becLocation = "$($serverLocation)\$($config.becFolderName)"
}
if (-not ([string]::IsNullOrEmpty($config.atFolderName))) {
$atFolderName = $config.atFolderName
}
$servers += $ini.Keys.Where({ $_ -Match "^[Ss]erver[\s_-]?[0-9]+$" })
$processID = 0
@@ -185,7 +183,6 @@ $becProcess = [Object[]]::new($servers.Count)
$dayzArguments = @()
foreach ($srv in $servers) {
# Write-Host ":$($srv):"
$instance = ${srv}
$serverPort = $ini.${srv}.serverPort
$serverConfig = $ini.${srv}.serverConfig
@@ -193,11 +190,29 @@ foreach ($srv in $servers) {
$serverCPU = $ini.${srv}.serverCPU
$startupClientMods = $ini.${srv}.startupClientMods
$startupServerMods = $ini.${srv}.startupServerMods
$additionalParams = $ini.${srv}.additionalParams
$cm = $startupClientMods -Split ';'
if ($cm -contains $modNS) {
$namalskMission = $ini.${srv}.namalskMission
if (($namalskMission -eq "regular") -or ($namalskMission -eq "hardcore")) {
$pathNamalskMission = "$($namalskMission)\$($namalskMission).namalsk"
$namalskMission += ".namalsk"
if (-not (Test-Path -Path "$($serverLocation)\mpmissions\$($namalskMission)\")) {
Write-Host "Copying $($namalskMission)..."
Copy-Item -Path "$($serverLocation)\$($modNS)\Extras\$($pathNamalskMission)\" -Destination "$($serverLocation)\mpmissions\" -Recurse -Force
Start-Sleep -Seconds 1
}
}
else {
Write-Error "Error in Namalsk mission definition: '$($namalskMission)'"
Exit
}
}
$serverProfile = "$($serverLocation)\profiles\$($instance)"
$startupMods = @("`"-mod=$($startupClientMods)`"", "`"-serverMod=$($startupServerMods)`"")
$startupParams = @("`"-profiles=$($serverProfile)`"", "`"-config=$($serverProfile)\$($serverConfig)`"", "-port=$($serverPort)", "-name=Server")
$additionalParams = @("-cpuCount=$($serverCPU)", "-adminLog -filePatching")
$startupParams = @("`"-profiles=$($serverProfile)`"", "`"-config=$($serverProfile)\$($serverConfig)`"", "-port=$($serverPort)", "-cpuCount=$($serverCPU)")
$dayzArguments = $startupParams + $startupMods + $additionalParams
$dayz = "`"$($serverLocation)\$($serverExeName)`""
$bec = "`"$($becLocation)\bec.exe`""
@@ -211,7 +226,7 @@ foreach ($srv in $servers) {
$logsName = Get-ChildItem -Path $atLogsLocation -Directory -Filter "Log*"
$atLogsLocation += '\' + $logsName
}
if ($becLocation) {
$becLogsLocation = "$($becLocation)\Log\$($instance)"
}
@@ -224,17 +239,12 @@ foreach ($srv in $servers) {
New-Item -ItemType Directory -Path $rotatedLogsLocation | Out-Null
Write-Host "Created new folder: $($rotatedLogsLocation)"
}
$fileList = $null
$destDelDir = "$($rotatedLogsLocation)\DeletedLogs"
$becDestDir = "$($rotatedLogsLocation)\BEC"
$atDestDir = "$($rotatedLogsLocation)\$($atFolderName)"
# Write-Host "destDelDir: $($destDelDir)"
# Write-Host "becDestDir: $($becDestDir)"
# Write-Host " atDestDir: $($atDestDir)"
# Write-Host "----------"
#region ### DayZ Game ###
Write-Host "Rotating DAYZ logs..."
$fileList = Get-Item -Path $serverProfile\*.rpt, $serverProfile\*.log, $serverProfile\*.adm, $serverProfile\*.mdmp | Where-Object { $_.LastWriteTime.Date -lt $date.Date }
@@ -247,7 +257,7 @@ foreach ($srv in $servers) {
}
Write-Host "Total: $($fileList.Count)"
$fileList = Get-Item -Path $rotatedLogsLocation\*.rpt, $rotatedLogsLocation\*.log, $rotatedLogsLocation\*.adm, $rotatedLogsLocation\*.mdmp | Where-Object { $_.LastWriteTime -lt $date.AddDays(-($daysAmount)) }
$fileList = Get-Item -Path $rotatedLogsLocation\*.rpt, $rotatedLogsLocation\*.log, $rotatedLogsLocation\*.adm, $rotatedLogsLocation\*.mdmp | Where-Object { $_.LastWriteTime -lt $date.AddDays( - ($daysAmount)) }
# Write-Host $fileList -Separator "`n"
Write-Host "Removing logs:"
@@ -256,12 +266,13 @@ foreach ($srv in $servers) {
New-Item -ItemType Directory -Path $destDelDir | Out-Null
Write-Host "Created new folder: $($destDelDir)"
}
foreach ($file in $fileList) {
Move-Item -Path $file -Destination $destDelDir -Force
Write-Host "Moved $($file) to $($destDelDir)"
}
} else {
}
else {
foreach ($file in $fileList) {
Remove-Item -Path $file
Write-Host "Removed $($file)!"
@@ -291,21 +302,22 @@ foreach ($srv in $servers) {
}
Write-Host "Total: $($fileList.Count)"
$fileList = Get-Item -Path $becDestDir\*.log | Where-Object { $_.LastWriteTime -lt $date.AddDays(-($daysAmount)) }
$fileList = Get-Item -Path $becDestDir\*.log | Where-Object { $_.LastWriteTime -lt $date.AddDays( - ($daysAmount)) }
# Write-Host $fileList -Separator "`n"
Write-Host "Removing BEC's LOGs:"
if ($noDelete) {
If (!(Test-Path -PathType Container $destDelDir)) {
New-Item -ItemType Directory -Path $destDelDir | Out-Null
Write-Host "Created new folder: $($destDelDir)"
}
foreach ($file in $fileList) {
Move-Item -Path $file -Destination $destDelDir
Write-Host "Moved $($file) to $($destDelDir)"
}
} else {
}
else {
foreach ($file in $fileList) {
Remove-Item -Path $file
Write-Host "Removed $($file)!"
@@ -325,7 +337,7 @@ foreach ($srv in $servers) {
New-Item -ItemType Directory -Path $atDestDir | Out-Null
Write-Host "Created new folder: $($atDestDir)"
}
$fileList = Get-ChildItem -Path $atLogsLocation\*.txt, $atLogsLocation\*.log -Recurse | Where-Object { $_.LastWriteTime.Date -lt $date.Date }
# Write-Host $fileList -Separator "`n"
@@ -336,9 +348,9 @@ foreach ($srv in $servers) {
}
Write-Host "Total: $($fileList.Count)"
$fileList = Get-Item -Path $atDestDir\*.txt, $atDestDir\*.log | Where-Object { $_.LastWriteTime -lt $date.AddDays(-($daysAmount)) }
$fileList = Get-Item -Path $atDestDir\*.txt, $atDestDir\*.log | Where-Object { $_.LastWriteTime -lt $date.AddDays( - ($daysAmount)) }
# Write-Host $fileList -Separator "`n"
Write-Host "Removing AdminTool's LOGs:"
if ($noDelete) {
If (!(Test-Path -PathType Container $destDelDir)) {
@@ -347,10 +359,11 @@ foreach ($srv in $servers) {
}
foreach ($file in $fileList) {
Move-Item -Path $file -Destination $destDelDir -Force
Write-Host "Moved $($file) to $($destDelDir)"
Move-Item -Path $file -Destination $destDelDir -Force
Write-Host "Moved $($file) to $($destDelDir)"
}
} else {
}
else {
foreach ($file in $fileList) {
Remove-Item -Path $file
Write-Host "Removed $($file)!"
@@ -373,6 +386,8 @@ foreach ($srv in $servers) {
# Write-Host " startupMods: $($startupMods)"
# Write-Host " startupParams: $($startupParams)"
# Write-Host " additionalParams: $($additionalParams)"
# Write-Host " pathNamalskMission: $($pathNamalskMission)"
# Write-Host " namalskMission: $($namalskMission)"
# Write-Host
# Write-Host " dayz: $($dayz)"
# Write-Host " dayzArguments: $($dayzArguments)"
@@ -381,27 +396,33 @@ foreach ($srv in $servers) {
# Write-Host " bec: $($bec)"
# Write-Host " becArguments: $($becArguments)"
# Write-Host
# Write-Host " atFolderName: $($atFolderName)"
# Write-Host
# Write-Host " atLogsLocation: $($atLogsLocation)"
# Write-Host " becLogsLocation: $($becLogsLocation)"
# Write-Host
# Write-Host " rotateLogs: $($rotateLogs)"
# Write-Host " destDelDir: $($destDelDir)"
# Write-Host " becDestDir: $($becDestDir)"
# Write-Host " atDestDir: $($atDestDir)"
# Write-Host
# Write-Host "rotatedLogsFolderName: $($rotatedLogsFolderName)"
# Write-Host " rotatedLogsLocation: $($rotatedLogsLocation)"
# Write-Host " daysAmount: $($daysAmount)"
# Write-Host " noDelete: $($noDelete)"
# Starting servers
Set-Location -Path "$($serverLocation)"
$dayzProcess[$processID] = Start-Process -FilePath $dayz -ArgumentList $dayzArguments -PassThru
$dayzProcess[$processID]
# # Starting servers
# Set-Location -Path "$($serverLocation)"
# $dayzProcess[$processID] = Start-Process -FilePath $dayz -ArgumentList $dayzArguments -PassThru
# $dayzProcess[$processID]
if ($becLocation) {
Set-Location -Path "$($becLocation)"
$becProcess[$processID] = Start-Process -FilePath $bec -ArgumentList $becArguments -PassThru
$becProcess[$processID]
}
# if ($becLocation) {
# Set-Location -Path "$($becLocation)"
# $becProcess[$processID] = Start-Process -FilePath $bec -ArgumentList $becArguments -PassThru
# $becProcess[$processID]
# }
$processID++
}
# Start-Sleep -Seconds 5
Write-Host "=========="

16
wDayzManager.txt Normal file
View File

@@ -0,0 +1,16 @@
// wDayzManager.txt - Steam script
@NoPromptForPassword 1
@ShutdownOnFailedCommand 1
force_install_dir "D:\DayZ\Server"
login w0lf_2k
app_update 223350 validate
workshop_download_item 221100 2731398623 validate
workshop_download_item 221100 1559212036 validate
workshop_download_item 221100 1564026768 validate
workshop_download_item 221100 1828439124 validate
workshop_download_item 221100 1623711988 validate
workshop_download_item 221100 2288339650 validate
workshop_download_item 221100 2288336145 validate
workshop_download_item 221100 2561482171 validate
workshop_download_item 221100 1988925918 validate
quit