Server Stability of kf2 server in Windows vs Linux
- By anotherDSH
- Support
- 6 Replies
Thank you baz. I had already made a jump to linux so I haven't had a chance to try this out but expect to later on.You will quickly discover it is irrelevant what platform you use. KF2 dedicated servers are not stable. Especially if you add mutators.
Here is a generic Windows Powershell script to monitor and restart KF2 instances. The $Processlist variable needs to be updated to have all of your server details. The hardcoded wait time and number of players can also be adjusted as required.
Code:Function New-TitleObject(){ #Create a object for holding server titles and player count $LDefaultObject = New-Object -TypeName psobject $LDefaultObject | Add-Member -type NoteProperty -name Title -value "NOTSET" $LDefaultObject | Add-Member -type NoteProperty -name PlayerCount -value "NOTSET" return $LDefaultObject } Function Write-LogHost(){ [CmdletBinding()] param ( $LMessage ) write-host "$(get-date -UFormat "%d%m%y %H%M") $($LMessage)" "$(get-date -UFormat "%d%m%y %H%M") $LMessage" | Out-File -Append -FilePath c:\bin\log.txt } #windows only #Gets the currently running KF2 windows titles which has the count of players in the game. Returns array of users and titles Function Get-WindowTitalsAndPlayers(){ $WindowTitles = Get-Process |where {$_.mainWindowTItle} | where { $_.name -eq "KFServer" } | select mainwindowtitle $WindowTitalsAndPlayers=@() foreach ($WindowTitle in $WindowTitles){ $TempTitle=New-TitleObject $TempTitle.Title=$WindowTitle.MainWindowTitle -replace ":.*",'' $TempTitle.PlayerCount=$WindowTitle.MainWindowTitle -replace ".*?\(",'' -replace " players.*",'' $WindowTitalsAndPlayers+=$TempTitle } $WindowTitalsAndPlayers=$WindowTitalsAndPlayers | sort title return $WindowTitalsAndPlayers } #Server name,Binary location,commandline parameters #Server name is the name of the server in the config file. This will appear in the title of the window. #Binary location is the location of the kf2 Binary #commandline parameters are the parameters you wish to pass to the kf2 binary. $Processlist=@( @("BAz | HOE | RANKED | Endless | Server1","C:\KF2Server\Binaries\Win64\KFServer.exe"," KF-HorzineArena-B1-v5?Mutator=xxxx?Game=KFGameContent.KFGameInfo_VersusSurvival?Difficulty=3?AllowSeasonalSkins=0?ConfigSubDir=yyyyyy -QueryPort=xxxxx -Port=xxxx -WebAdminPort=xxxx"), @("BAz | HOE | RANKED | Endless | Server2","C:\KF2Server\Binaries\Win64\KFServer.exe"," KF-HorzineArena-B1-v5?Mutator=xxxx?Game=KFGameContent.KFGameInfo_VersusSurvival?Difficulty=3?AllowSeasonalSkins=0?ConfigSubDir=yyyyyy -QueryPort=xxxxx -Port=xxxx -WebAdminPort=xxxx"), @("BAz | HOE | RANKED | Endless | Server3","C:\KF2Server\Binaries\Win64\KFServer.exe"," KF-HorzineArena-B1-v5?Mutator=xxxx?Game=KFGameContent.KFGameInfo_VersusSurvival?Difficulty=3?AllowSeasonalSkins=0?ConfigSubDir=yyyyyy -QueryPort=xxxxx -Port=xxxx -WebAdminPort=xxxx") ) while(1){ $GWindowTitalsAndPlayers=Get-WindowTitalsAndPlayers #Check all servers are running and restart them. Only restart if there are less than 5 people in game as this causes lagg. $PlayerCount=0 Get-WindowTitalsAndPlayers | % { $PlayerCount+=$_.playercount } if($GWindowTitalsAndPlayers.count -lt $Processlist.count ){ if($PlayerCount -lt 50){ foreach ($KnownProcess in $Processlist){ if(!($GWindowTitalsAndPlayers.title -contains $KnownProcess[0])){ Write-LogHost "Restarting process:$($KnownProcess[1]) $($knownProcess[2])" & "$($KnownProcess[1])" "$($KnownProcess[2])" sleep 30 } } }else{ Write-LogHost "--" Write-LogHost "$(get-date) Server count is $($GWindowTitalsAndPlayers.count) should be $($Processlist.count). Too many users to restart server instance." foreach ($KnownProcess in $Processlist){ if(!($GWindowTitalsAndPlayers.title -contains $KnownProcess[0])){ Write-LogHost "Need to restart process:$($KnownProcess[1]) $($knownProcess[2])" } } Write-LogHost "--" } }else{ Write-LogHost "PlayerCount:$($PlayerCount)" } sleep 60 }
Upvote
0