diff --git a/Start.bat b/Start.bat index e307f73..99cd43d 100644 --- a/Start.bat +++ b/Start.bat @@ -25,6 +25,7 @@ if "%1" equ "-U" set update=1 if "%1" equ "-u" set update=1 if "%1" equ "--update" set update=1 -powershell -ExecutionPolicy RemoteSigned -File wDayzManager.ps1 %update% > %filename% +powershell -ExecutionPolicy RemoteSigned -File wDayzManager.ps1 %update% +@REM powershell -ExecutionPolicy RemoteSigned -File wDayzManager.ps1 %update% > %filename% popd diff --git a/wDayzManager.ini b/wDayzManager.ini index d9fe0af..4c6c1a9 100644 --- a/wDayzManager.ini +++ b/wDayzManager.ini @@ -1,19 +1,22 @@ ; wDayzManager.ini [Config] -serverLocation=Z:\Servers\dayzserver -steamCMD=Z:\SteamCMD +;serverLocation=Z:\Servers\dayzserver +serverLocation=D:\dayz\server +profilesLocation=profiles +; steamCMD=Z:\SteamCMD +steamCMD=V:\SteamCMD steamUser=w0lf_2k appidGame=221100 appidServer=223350 - -rotateLogs=1 +rotateLogs=0 daysAmount=7 -rotatedLogsFolderName=RotatedLogs -; rotatedLogsFolderName= -becFolderName=BEC -; becFolderName= -atFolderName=VPPAdminTools +; rotatedLogsFolderName=RotatedLogs +rotatedLogsFolderName= +; becFolderName=BEC +becFolderName= +; atFolderName=VPPAdminTools ; atFolderName=CommunityOnlineTools +atFolderName= ; 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. @@ -25,68 +28,75 @@ updateDay=1 updateHour=4 [ClientMods] -@GAZ_TIGR=2731398623 @CF=1559212036 @COT=1564026768 @VPPAdminTools=1828439124 @VanillaPlusPlusMap=1623711988 @Namalsk_Island=2288339650 @Namalsk_Survival=2288336145 -@KAMAZ=2561482171 +@CodeLock=1646187754 +@KAMAZ_NeonMurder=2561482171 +@Kamaz_Truck_LaGTeK=1895398348 +@UralRust=3101355011 +@VPK3927Volk=3354895140 +@GAZ_TIGR_by_Savage=2731398623 +@GAZ_TIGR_by_Fenyx=3323914085 +@TF_UAZ3151=2618764716 +@CnG_UAZ_31514=3160244059 [ServerMods] @SurvivorMissions=1988925918 -[Server-1] -serverPort=35100 -serverConfig=serverDZ.cfg -serverExeName=DayZServer_x64.exe -serverCPU=2 -startupClientMods=@CF;@VPPadminTools -startupServerMods= -additionalParams= -name=Server -adminLog -namalskMission= - -[Server-2] -serverPort=35200 -serverConfig=serverDZ.cfg -serverExeName=DayZServer_x64.exe -serverCPU=2 -startupClientMods=@CF;@VPPadminTools -startupServerMods= -additionalParams= -name=Server -adminLog -namalskMission= - -[Server-3] -serverPort=35300 -serverConfig=serverDZ.cfg -serverExeName=DayZServer_x64.exe -serverCPU=2 -startupClientMods=@CF;@VPPadminTools;@Namalsk_Island;@Namalsk_Survival -startupServerMods= -additionalParams= -name=Server -adminLog -namalskMission=Regular - -[Server-4] -serverPort=35400 -serverConfig=serverDZ.cfg -serverExeName=DayZServer_x64.exe -serverCPU=2 -startupClientMods=@CF;@VPPadminTools -startupServerMods= -additionalParams= -name=Server -adminLog -namalskMission= - -; [Server-5] -; serverPort=35500 +; [Server-1] +; serverPort=35100 ; serverConfig=serverDZ.cfg ; serverExeName=DayZServer_x64.exe -; serverCPU=4 -; ; startupClientMods=@CF;@COT -; startupClientMods=@CF;@VPPAdminTools;@Namalsk_Island;@Namalsk_Survival +; serverCPU=2 +; startupClientMods=@CF;@VPPadminTools ; startupServerMods= -; additionalParams= -name=Server -filePatching -; namalskMission=Hardcore +; additionalParams= -name=Server -adminLog +; namalskMission= + +; [Server-2] +; serverPort=35200 +; serverConfig=serverDZ.cfg +; serverExeName=DayZServer_x64.exe +; serverCPU=2 +; startupClientMods=@CF;@VPPadminTools +; startupServerMods= +; additionalParams= -name=Server -adminLog +; namalskMission= + +; [Server-3] +; serverPort=35300 +; serverConfig=serverDZ.cfg +; serverExeName=DayZServer_x64.exe +; serverCPU=2 +; startupClientMods=@CF;@VPPadminTools;@Namalsk_Island;@Namalsk_Survival +; startupServerMods= +; additionalParams= -name=Server -adminLog +; namalskMission=Regular + +; [Server-4] +; serverPort=35400 +; serverConfig=serverDZ.cfg +; serverExeName=DayZServer_x64.exe +; serverCPU=2 +; startupClientMods=@CF;@VPPadminTools +; startupServerMods= +; additionalParams= -name=Server -adminLog +; namalskMission= + +[Server-5] +serverPort=35500 +serverConfig=serverDZ.cfg +serverExeName=DayZServer_x64.exe +serverCPU=2 +startupClientMods= +; startupClientMods=@CF;@VPPAdminTools;@Namalsk_Island;@Namalsk_Survival +startupServerMods= +additionalParams= -name=Server +namalskMission=Hardcore ; [Server-6] ; serverPort=35600 diff --git a/wDayzManager.ps1 b/wDayzManager.ps1 index 462b21a..5705cf9 100644 --- a/wDayzManager.ps1 +++ b/wDayzManager.ps1 @@ -7,16 +7,79 @@ [CmdletBinding()] param ( [Parameter()] - [int] - $param = 0 + [int]$param = 0 ) [bool]$update = $param + [bool]$noDelete = $false # 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'" + +############################################################################################################################################################### +[string]$myName = "wDayzManager" +[string]$steamScript = $myName + ".txt" +[string]$iniFile = $myName + ".ini" +if (-not (Test-Path -Path $iniFile)) { + Write-Warning "Can't find file '$iniFile', creating new..." + New-Item -ItemType File -Path $iniFile -Value "; $($iniFile)" | Out-Null + $content = " +[Config] +serverLocation=Z:\Servers\DayzServer +profilesLocation=profiles +steamCMD=Z:\SteamCMD +steamUser=SupaMegaGamer +appidGame=221100 +appidServer=223350 +rotateLogs=1 +daysAmount=7 +rotatedLogsFolderName=RotatedLogs +becFolderName=BEC +atFolderName=VPPAdminTools + +; 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] +@CF=1559212036 +@Namalsk_Island=2288339650 +@Namalsk_Survival=2288336145 + +[ServerMods] + +[Server-1] +serverPort=2302 +serverConfig=serverDZ.cfg +serverExeName=DayZServer_x64.exe +serverCPU=2 +startupClientMods=@CF +startupServerMods= +additionalParams= -name=Server + +; Mission name for Namalsk Mod +; This is the name of the Namalsk mod mission. It can be 'Hardcore' or 'Regular', i.e. the names of folders in the '@Namalsk_Survival\Extras\' directory. +; If you are not using Namalsk mod, this parameter is ignored. +namalskMission= + +[Server-2] +serverPort=2402 +serverConfig=serverDZ.cfg +serverExeName=DayZServer_x64.exe +serverCPU=2 +startupClientMods=@CF;@Namalsk_Island;@Namalsk_Survival +startupServerMods= +additionalParams= -name=Server -AdminLog -FilePatching + +; Mission name for Namalsk Mod +; This is the name of the Namalsk mod mission. It can be 'Hardcore' or 'Regular', i.e. the names of folders in the '@Namalsk_Survival\Extras\' directory. +; If you are not using Namalsk mod, this parameter is ignored. +namalskMission=Hardcore +" + Add-Content -Path $iniFile -Value $content -Encoding UTF8 + $content = $null Exit } @@ -31,17 +94,19 @@ Write-Host "update = $($update), noDelete = $($noDelete)" $ini = $config = $servers = $clientMods = $serverMods = $steamProcess = $null $modNI = $modNS = $namalskMission = $pathNamalskMission = $null -$dayzProcess = $becProcess = $instance = $null +$dayzProcess = $becProcess = $instance = $profilesLocation = $null $becLocation = $rotatedLogsFolderName = $atFolderName = $serverLocation = $null $steamCMD = $steamUser = $appidServer = $appidGame = $rotateLogs = $daysAmount = $null $serverPort = $serverConfig = $serverExeName = $serverCPU = $null $startupClientMods = $startupServerMods = $startupMods = $startupParams = $null $serverProfile = $additionalParams = $dayzArguments = $dayz = $bec = $becArguments = $null $logsName = $atLogsLocation = $becLogsLocation = $rotatedLogsLocation = $null +$currentPath = Get-Location $ini = (Get-IniContent -FilePath $iniFile) $config = $ini.Config [string]$serverLocation = $config.serverLocation +[string]$profilesLocation = $config.profilesLocation [string]$steamCMD = $config.steamCMD [string]$steamUser = $config.steamUser [int]$appidGame = $config.appidGame @@ -81,12 +146,10 @@ if ($update) { Write-Host "Start updating server..." if (-not (Test-Path $steamCMD)) { - Write-Error "Can't find folder '$steamCMD'" + Write-Error "Can't find folder '$steamCMD'!" Exit } - $currentPath = Get-Location - # Making Steam script $arr = @() $arr += "@NoPromptForPassword 1" @@ -99,8 +162,8 @@ if ($update) { $arr += "quit" # Saving Steam script - "// wDayzManager.txt - Steam script" | Out-File -FilePath "$($currentPath)\$($steamScript)" -Encoding ascii - $arr | Out-File -FilePath "$($currentPath)\$($steamScript)" -Encoding ascii -Append + "// $($steamScript) - Steam script" | Out-File -FilePath "$($currentPath)\$($steamScript)" -Encoding Ascii + $arr | Out-File -FilePath "$($currentPath)\$($steamScript)" -Encoding Ascii -Append # Run Steam script Write-Host "Run Steam script from `"$($currentPath)\$($steamScript)`"" @@ -167,6 +230,10 @@ if ($rotateLogs) { if (-not ([string]::IsNullOrEmpty($config.rotatedLogsFolderName))) { $rotatedLogsFolderName = $config.rotatedLogsFolderName } + else { + Write-Error "The 'rotatedLogsFolderName' parameter not set!" + Exit + } } if (-not ([string]::IsNullOrEmpty($config.becFolderName))) { @@ -181,8 +248,12 @@ $servers += $ini.Keys.Where({ $_ -Match "^[Ss]erver[\s_-]?[0-9]+$" }) $processID = 0 $dayzProcess = [Object[]]::new($servers.Count) -$becProcess = [Object[]]::new($servers.Count) $dayzArguments = @() +if ($becLocation) { + $becProcess = [Object[]]::new($servers.Count) +} + +EXIT foreach ($srv in $servers) { $instance = ${srv} @@ -222,19 +293,18 @@ foreach ($srv in $servers) { # Rotate logs if ($rotateLogs) { - if ($atFolderName) { - $atLogsLocation = "$($serverProfile)\$($atFolderName)" - - $logsName = Get-ChildItem -Path $atLogsLocation -Directory -Filter "Log*" - $atLogsLocation += '\' + $logsName + if ($rotatedLogsFolderName) { + $rotatedLogsLocation = "$($serverProfile)\$($rotatedLogsFolderName)" } if ($becLocation) { $becLogsLocation = "$($becLocation)\Log\$($instance)" } - if ($rotatedLogsFolderName) { - $rotatedLogsLocation = "$($serverProfile)\$($rotatedLogsFolderName)" + if ($atFolderName) { + $atLogsLocation = "$($serverProfile)\$($atFolderName)" + $logsName = Get-ChildItem -Path $atLogsLocation -Directory -Filter "Log*" + $atLogsLocation += '\' + $logsName } If (!(Test-Path -PathType Container $rotatedLogsLocation)) { @@ -242,13 +312,17 @@ foreach ($srv in $servers) { Write-Host "Created new folder: $($rotatedLogsLocation)" } - $fileList = $null - $destDelDir = "$($rotatedLogsLocation)\DeletedLogs" - $becDestDir = "$($rotatedLogsLocation)\BEC" - $atDestDir = "$($rotatedLogsLocation)\$($atFolderName)" + if ($noDelete) { + $destDelDir = "$($rotatedLogsLocation)\DeletedLogs" + If (!(Test-Path -PathType Container $destDelDir)) { + New-Item -ItemType Directory -Path $destDelDir | Out-Null + Write-Host "Created new folder: $($destDelDir)" + } + } #region ### DayZ Game ### Write-Host "Rotating DAYZ logs..." + $fileList = $null $fileList = Get-Item -Path $serverProfile\*.rpt, $serverProfile\*.log, $serverProfile\*.adm, $serverProfile\*.mdmp | Where-Object { $_.LastWriteTime.Date -lt $date.Date } # Write-Host $fileList -Separator "`n" @@ -262,42 +336,36 @@ foreach ($srv in $servers) { $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:" - 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) { + Write-Host "Removing DayZ logs:" + foreach ($file in $fileList) { + if ($noDelete) { Move-Item -Path $file -Destination $destDelDir -Force Write-Host "Moved $($file) to $($destDelDir)" } - } - else { - foreach ($file in $fileList) { + else { Remove-Item -Path $file Write-Host "Removed $($file)!" } } Write-Host "Total: $($fileList.Count)" - Write-Host "" + Write-Host #endregion #region ### BEC ### - if ($becDestDir) { - Write-Host "Rotating BEC logs..." - $fileList = $null + if ($becLocation) { + $becDestDir = "$($rotatedLogsLocation)\$($becFolderName)" If (!(Test-Path -PathType Container $becDestDir)) { New-Item -ItemType Directory -Path $becDestDir | Out-Null Write-Host "Created new folder: $($becDestDir)" } + Write-Host "Rotating BEC logs..." + $fileList = $null $fileList = Get-ChildItem -Path $becLogsLocation\*.log -Recurse | Where-Object { $_.LastWriteTime.Date -lt $date.Date } # Write-Host $fileList -Separator "`n" - Write-Host "Moving BEC's LOGs to $($becDestDir):" + Write-Host "Moving BEC logs to $($becDestDir):" foreach ($file in $fileList) { Move-Item -Path $file -Destination $becDestDir -Force Write-Host "Moved $($file) to $($becDestDir)" @@ -307,43 +375,37 @@ foreach ($srv in $servers) { $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 "Removing BEC logs:" + foreach ($file in $fileList) { + if ($noDelete) { + Move-Item -Path $file -Destination $destDelDir -Force Write-Host "Moved $($file) to $($destDelDir)" } - } - else { - foreach ($file in $fileList) { + else { Remove-Item -Path $file Write-Host "Removed $($file)!" } } Write-Host "Total: $($fileList.Count)" - Write-Host "" + Write-Host } #endregion #region ### Admin Tool ### - if ($atDestDir) { - Write-Host "Rotating AdminTool logs..." - $fileList = $null + if ($atLogsLocation) { + $atDestDir = "$($rotatedLogsLocation)\$($atFolderName)" If (!(Test-Path -PathType Container $atDestDir)) { New-Item -ItemType Directory -Path $atDestDir | Out-Null Write-Host "Created new folder: $($atDestDir)" } + Write-Host "Rotating AdminTool logs..." + $fileList = $null $fileList = Get-ChildItem -Path $atLogsLocation\*.txt, $atLogsLocation\*.log -Recurse | Where-Object { $_.LastWriteTime.Date -lt $date.Date } # Write-Host $fileList -Separator "`n" - Write-Host "Moving AdminTool's LOGs to $($atDestDir):" + Write-Host "Moving AdminTool logs to $($atDestDir):" foreach ($file in $fileList) { Move-Item -Path $file -Destination $atDestDir -Force Write-Host "Moved $($file) to $($atDestDir)" @@ -353,26 +415,20 @@ foreach ($srv in $servers) { $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)) { - New-Item -ItemType Directory -Path $destDelDir | Out-Null - Write-Host "Created new folder: $($destDelDir)" - } + Write-Host "Removing AdminTool logs:" - foreach ($file in $fileList) { + foreach ($file in $fileList) { + if ($noDelete) { Move-Item -Path $file -Destination $destDelDir -Force Write-Host "Moved $($file) to $($destDelDir)" } - } - else { - foreach ($file in $fileList) { + else { Remove-Item -Path $file Write-Host "Removed $($file)!" } } Write-Host "Total: $($fileList.Count)" - Write-Host "" + Write-Host } #endregion }