From 1838fa74c0522c94f9c78009f735c803e35cc07b Mon Sep 17 00:00:00 2001 From: Patrick Veilleux Date: Thu, 16 Sep 2021 19:40:49 -0400 Subject: [PATCH 1/9] add Valheim add PID --- functions/Get-PID.psm1 | 14 ++ functions/Register-PID.psm1 | 16 +++ functions/Set-Priority.psm1 | 22 ++++ functions/Unregister-PID.psm1 | 14 ++ main.ps1 | 25 +++- templates/7daystodie.psm1 | 23 ++-- templates/insurgencysandstorm.psm1 | 50 +++----- templates/pixark.psm1 | 41 +++--- templates/projectzomboid.psm1 | 21 +-- templates/valheim.psm1 | 198 +++++++++++++++++++++++++++++ 10 files changed, 337 insertions(+), 87 deletions(-) create mode 100644 functions/Get-PID.psm1 create mode 100644 functions/Register-PID.psm1 create mode 100644 functions/Set-Priority.psm1 create mode 100644 functions/Unregister-PID.psm1 create mode 100644 templates/valheim.psm1 diff --git a/functions/Get-PID.psm1 b/functions/Get-PID.psm1 new file mode 100644 index 0000000..7454bf6 --- /dev/null +++ b/functions/Get-PID.psm1 @@ -0,0 +1,14 @@ +function Get-PID { + [CmdletBinding()] + [OutputType([Int])] + param ( + ) + try { + $ServerPID = Get-Content -Path ".\servers\$($Server.UID).PID" -ErrorAction Continue + } + catch { + return 0 + } + return $ServerPID + } +Export-ModuleMember -Function Get-PID \ No newline at end of file diff --git a/functions/Register-PID.psm1 b/functions/Register-PID.psm1 new file mode 100644 index 0000000..bdc0c22 --- /dev/null +++ b/functions/Register-PID.psm1 @@ -0,0 +1,16 @@ +function Register-PID { + [CmdletBinding()] + [OutputType([Bool])] + param ( + [Parameter(Mandatory)] + $ServerProcess + ) + try { + New-Item -Path ".\servers\" -Name "$($Server.UID).PID" -ItemType "file" -Value "$($ServerProcess.ID)" -ErrorAction Continue + } + catch { + return $false + } + return $true + } +Export-ModuleMember -Function Register-PID \ No newline at end of file diff --git a/functions/Set-Priority.psm1 b/functions/Set-Priority.psm1 new file mode 100644 index 0000000..cab53d9 --- /dev/null +++ b/functions/Set-Priority.psm1 @@ -0,0 +1,22 @@ +function Set-Priority { + [CmdletBinding()] + [OutputType([Bool])] + param ( + [Parameter(Mandatory)] + $ServerProcess + ) + try { + # Set the priority and affinity + if ($Server.UsePriority) { + $ServerProcess.PriorityClass = $Server.AppPriority + } + if ($Server.UseAffinity){ + $ServerProcess.ProcessorAffinity = $Server.AppAffinity + } + } + catch { + return $false + } + return $true + } +Export-ModuleMember -Function Set-Priority \ No newline at end of file diff --git a/functions/Unregister-PID.psm1 b/functions/Unregister-PID.psm1 new file mode 100644 index 0000000..a04c62d --- /dev/null +++ b/functions/Unregister-PID.psm1 @@ -0,0 +1,14 @@ +function Unregister-PID { + [CmdletBinding()] + [OutputType([Bool])] + param ( + ) + try { + Remove-Item -Path ".\servers\$($Server.UID).PID" -Confirm:$false -ErrorAction Continue + } + catch { + return $false + } + return $true +} +Export-ModuleMember -Function Unregister-PID \ No newline at end of file diff --git a/main.ps1 b/main.ps1 index 6104524..049e511 100644 --- a/main.ps1 +++ b/main.ps1 @@ -119,7 +119,12 @@ if (-not(Test-Path -Path $Server.Exec)){ # If Server is running warn players then stop server #--------------------------------------------------------- if (-not ($FreshInstall)) { - $ServerProcess = Get-Process $Server.ProcessName -ErrorAction SilentlyContinue + $ServerPID = Get-PID + if ($ServerPID -eq 0) { + $ServerProcess = Get-Process -Name $Server.ProcessName -ErrorAction Continue + } else { + $ServerProcess = Get-Process -ID $ServerPID -ErrorAction Continue + } Write-ScriptMsg "Verifying Server State..." if (-not ($ServerProcess) -or $ServerProcess.HasExited) { Write-ServerMsg "Server is not running." @@ -149,9 +154,12 @@ if (-not ($FreshInstall)) { if ($Stopped) { Write-ServerMsg "Server stopped." + if (-not $(Unregister-PID)) { + Write-ServerMsg "Failed to remove PID file." + } } else { if ($Server.AllowForceClose) { - Exit-WithError "Server to stop server." + Exit-WithError "Failed to stop server." } else { Write-ServerMsg "Server not stopped." } @@ -184,7 +192,18 @@ if (-not ($FreshInstall)) { try { Write-ScriptMsg "Starting Server..." - Start-Server + $App = Start-Server + #Wait to see if the server is stable. + Start-Sleep -Seconds 10 + if (-not ($App) -or $App.HasExited){ + Exit-WithError "Server Failed to launch." + } else { + Write-ServerMsg "Server Started." + Set-Priority -ServerProcess $App + } + if (-not $(Register-PID -ServerProcess $App)){ + Write-ServerMsg "Failed to Register PID file." + } } catch { Write-Error $_ diff --git a/templates/7daystodie.psm1 b/templates/7daystodie.psm1 index 3d76929..611bbdf 100644 --- a/templates/7daystodie.psm1 +++ b/templates/7daystodie.psm1 @@ -2,13 +2,19 @@ #Change your servers settings in C:\Users\%username%\AppData\Roaming\7DaysToDie\Saves\serverconfig.xml #> +#Server Name, use the same name to share game files. $Name = "7DaysToDie" + #--------------------------------------------------------- # Server Configuration #--------------------------------------------------------- $ServerDetails = @{ + + #Unique Identifier used to track processes. Must be unique to each servers. + $UID = 7 + #Server Configuration ConfigFile = "$Env:userprofile\AppData\Roaming\7DaysToDie\Saves\serverconfig.xml" @@ -159,7 +165,7 @@ $Arguments = @( [System.Collections.ArrayList]$CleanedArguments=@() foreach($Argument in $Arguments){ - if (!($Argument.EndsWith('=""') -or $Argument.EndsWith('='))){ + if (!($Argument.EndsWith('=""') -or $Argument.EndsWith('=') -or $Argument.EndsWith(' '))){ $CleanedArguments.Add($Argument) } } @@ -188,20 +194,7 @@ function Start-Server { #Start Server $App = Start-Process -FilePath $Launcher -WorkingDirectory $Server.Path -ArgumentList $ArgumentList -PassThru - #Wait to see if the server is stable. - Start-Sleep -Seconds 10 - if (-not ($App) -or $App.HasExited){ - Write-Warning "Server Failed to launch." - } else { - Write-ServerMsg "Server Started." - # Set the priority and affinity - if ($Server.UsePriority) { - $App.PriorityClass = $Server.AppPriority - } - if ($Server.UseAffinity){ - $App.ProcessorAffinity = $Server.AppAffinity - } - } + return $App } Export-ModuleMember -Function Start-Server -Variable @("Server","Backups","Warnings") \ No newline at end of file diff --git a/templates/insurgencysandstorm.psm1 b/templates/insurgencysandstorm.psm1 index ec3a973..b915a4a 100644 --- a/templates/insurgencysandstorm.psm1 +++ b/templates/insurgencysandstorm.psm1 @@ -2,14 +2,19 @@ #Change your servers settings in ".\servers\Insurgency\Saved\Config\WindowsServer" #> +#Server Name, use the same name to share game files. $Name = "InsurgencySandstorm" + #--------------------------------------------------------- # Server Configuration #--------------------------------------------------------- $ServerDetails = @{ + #Unique Identifier used to track processes. Must be unique to each servers. + $UID = 2 + #Name of the server in the Server Browser SessionName = "My Insurgency Server" @@ -193,26 +198,26 @@ $Arguments = @( "$($Server.Map)", "?Scenario=$($Server.Scenario)", "?MaxPlayers=$($Server.MaxPlayers)", - "?password=`"$($Server.Password)`"", - " -Port=$($Server.Port)", - " -QueryPort=$($Server.QueryPort)", - " -hostname=`"$($Server.SessionName)`"", - " -GSLTToken=`"$($Server.GSLTToken)`"", - " -GameStatsToken=`"$($Server.GameStatsToken)`"", - " -Gamestats", - " -MapCycle=`"$($Server.MapCycle)`"", - " -AdminList=`"$($Server.Admins)`"", - " -MOTD=`"$($Server.Motd)`"", - " -ruleset=`"$($Server.OfficialRulesSet)`"", - " -CmdModList=`"$($Server.Mods)`"", - " -mutators=`"$($Server.Mutators)`"", - " -log" + "?password=`"$($Server.Password)`" ", + "-Port=$($Server.Port) ", + "-QueryPort=$($Server.QueryPort) ", + "-hostname=`"$($Server.SessionName)`" ", + "-GSLTToken=`"$($Server.GSLTToken)`" ", + "-GameStatsToken=`"$($Server.GameStatsToken)`" ", + "-Gamestats", + "-MapCycle=`"$($Server.MapCycle)`" ", + "-AdminList=`"$($Server.Admins)`" ", + "-MOTD=`"$($Server.Motd)`" ", + "-ruleset=`"$($Server.OfficialRulesSet)`" ", + "-CmdModList=`"$($Server.Mods)`" ", + "-mutators=`"$($Server.Mutators)`" ", + "-log" ) [System.Collections.ArrayList]$CleanedArguments=@() foreach($Argument in $Arguments){ - if (!($Argument.EndsWith('=""') -or $Argument.EndsWith('='))){ + if (!($Argument.EndsWith('=""') -or $Argument.EndsWith('=') -or $Argument.EndsWith(' '))){ $CleanedArguments.Add($Argument) } } @@ -239,20 +244,7 @@ function Start-Server { #Start Server $App = Start-Process -FilePath $Launcher -WorkingDirectory $Server.Path -ArgumentList $ArgumentList -PassThru - #Wait to see if the server is stable. - Start-Sleep -Seconds 10 - if (-not ($App) -or $App.HasExited){ - Write-Warning "Server Failed to launch." - } else { - Write-ServerMsg "Server Started." - # Set the priority and affinity - if ($Server.UsePriority) { - $App.PriorityClass = $Server.AppPriority - } - if ($Server.UseAffinity){ - $App.ProcessorAffinity = $Server.AppAffinity - } - } + return $App } Export-ModuleMember -Function Start-Server -Variable @("Server","Backups","Warnings") \ No newline at end of file diff --git a/templates/pixark.psm1 b/templates/pixark.psm1 index b46fa2c..181e46f 100644 --- a/templates/pixark.psm1 +++ b/templates/pixark.psm1 @@ -23,6 +23,7 @@ ServerPVPCanAttack=True #> +#Server Name, use the same name to share game files. $Name = "PixArk" #--------------------------------------------------------- @@ -31,6 +32,9 @@ $Name = "PixArk" $ServerDetails = @{ + #Unique Identifier used to track processes. Must be unique to each servers. + $UID = 3 + #Name of the server in the Server Browser SessionName = "My Pixark Server" @@ -212,22 +216,22 @@ $Arguments = @( "?SessionName=`"$($Server.SessionName)`"", "?ServerPassword=$($Server.Password)", "?ShowFloatingDamageText=$($Server.ShowFloatingDamageText)", - "?CULTUREFORCOOKING=$($Server.Language)", - " -CubePort=$($Server.CubePort)", - " -CubeWorld=$($Server.WorldName)", - " -Seed=$($Server.Seed)", - " -forcerespawndinos" - " -NoHangDetection", - " -nosteamclient", - " -game", - " -server", - " -log" + "?CULTUREFORCOOKING=$($Server.Language) ", + "-CubePort=$($Server.CubePort) ", + "-CubeWorld=$($Server.WorldName) ", + "-Seed=$($Server.Seed) ", + "-forcerespawndinos " + "-NoHangDetection ", + "-nosteamclient ", + "-game ", + "-server ", + "-log" ) [System.Collections.ArrayList]$CleanedArguments=@() foreach($Argument in $Arguments){ - if (!($Argument.EndsWith('=""') -or $Argument.EndsWith('='))){ + if (!($Argument.EndsWith('=""') -or $Argument.EndsWith('=') -or $Argument.EndsWith(' '))){ $CleanedArguments.Add($Argument) } } @@ -248,20 +252,7 @@ function Start-Server { #Start Server $App = Start-Process -FilePath $Launcher -WorkingDirectory $Server.Path -ArgumentList $ArgumentList -PassThru - #Wait to see if the server is stable. - Start-Sleep -Seconds 10 - if (-not ($App) -or $App.HasExited){ - Write-Warning "Server Failed to launch." - } else { - Write-ServerMsg "Server Started." - # Set the priority and affinity - if ($Server.UsePriority) { - $App.PriorityClass = $Server.AppPriority - } - if ($Server.UseAffinity){ - $App.ProcessorAffinity = $Server.AppAffinity - } - } + return $App } Export-ModuleMember -Function Start-Server -Variable @("Server","Backups","Warnings") \ No newline at end of file diff --git a/templates/projectzomboid.psm1 b/templates/projectzomboid.psm1 index 25a2b8f..5fc63b2 100644 --- a/templates/projectzomboid.psm1 +++ b/templates/projectzomboid.psm1 @@ -30,6 +30,7 @@ SteamPort2=8767 You do not need to forward RCON. #> +#Server Name, use the same name to share game files. $Name = "ProjectZomboid" #--------------------------------------------------------- @@ -38,6 +39,9 @@ $Name = "ProjectZomboid" $ServerDetails = @{ + #Unique Identifier used to track processes. Must be unique to each servers. + $UID = 4 + #Rcon IP, usually localhost ManagementIP = "127.0.0.1" @@ -197,7 +201,7 @@ $Arguments = @( [System.Collections.ArrayList]$CleanedArguments=@() foreach($Argument in $Arguments){ - if (!($Argument.EndsWith('=""') -or $Argument.EndsWith('='))){ + if (!($Argument.EndsWith('=""') -or $Argument.EndsWith('=') -or $Argument.EndsWith(' '))){ $CleanedArguments.Add($Argument) } } @@ -216,20 +220,7 @@ function Start-Server { $App = Start-Process -FilePath $Launcher -WorkingDirectory $Server.Path -ArgumentList $ArgumentList -PassThru - #Wait to see if the server is stable. - Start-Sleep -Seconds 10 - if (-not ($App) -or $App.HasExited){ - Write-Warning "Server Failed to launch." - } else { - Write-ServerMsg "Server Started." - # Set the priority and affinity - if ($Server.UsePriority) { - $App.PriorityClass = $Server.AppPriority - } - if ($Server.UseAffinity){ - $App.ProcessorAffinity = $Server.AppAffinity - } - } + return $App } Export-ModuleMember -Function Start-Server -Variable @("Server","Backups","Warnings") \ No newline at end of file diff --git a/templates/valheim.psm1 b/templates/valheim.psm1 new file mode 100644 index 0000000..b0d408b --- /dev/null +++ b/templates/valheim.psm1 @@ -0,0 +1,198 @@ + +#Server Name, use the same name to share game files. +$Name = "Valheim" + +#--------------------------------------------------------- +# Server Configuration +#--------------------------------------------------------- + +$ServerDetails = @{ + + #Unique Identifier used to track processes. Must be unique to each servers. + $UID = 5 + + #Name of the server in the Server Browser + SessionName = "My Valheim Server" + + #World name (It is also the seed) + World = "World" + + #Password to join the World *NO SPACES* + Password = "CHANGEME" + + #Server Port + Port = 2459 + + #Rcon IP (not supported by valheim yet.) + ManagementIP = "" + + #Rcon Port + ManagementPort = "" + + #Rcon Password + ManagementPassword = "" + +#--------------------------------------------------------- +# Server Installation Details +#--------------------------------------------------------- + + #Name of the Server Instance + Name = $Name + + #Server Installation Path + Path = ".\servers\$Name" + + #Steam Server App Id + AppID = 896660 + + #Use Beta builds $true or $false + Beta = $false + + #Name of the Beta Build + BetaBuild = "" + + #Beta Build Password + BetaBuildPassword = "" + + #Process name in the task manager + ProcessName = "valheim_server" + + #ProjectZomboid64.exe + Exec = ".\servers\$Name\valheim_server.exe" + + #Allow force close, usefull for server without RCON and Multiple instances. + AllowForceClose = $true + + #Process Priority Realtime, High, Above normal, Normal, Below normal, Low + UsePriority = $true + AppPriority = "High" + + <# + Process Affinity (Core Assignation) + Core 1 = > 00000001 = > 1 + Core 2 = > 00000010 = > 2 + Core 3 = > 00000100 = > 4 + Core 4 = > 00001000 = > 8 + Core 5 = > 00010000 = > 16 + Core 6 = > 00100000 = > 32 + Core 7 = > 01000000 = > 64 + Core 8 = > 10000000 = > 128 + ---------------------------- + 8 Cores = > 11111111 = > 255 + 4 Cores = > 00001111 = > 15 + 2 Cores = > 00000011 = > 3 + #> + + UseAffinity = $false + AppAffinity = 15 + + #Should the server validate install after installation or update *(recommended) + Validate = $true +} +#Create the object +$Server = New-Object -TypeName PsObject -Property $ServerDetails + +#--------------------------------------------------------- +# Backups +#--------------------------------------------------------- + +$BackupsDetails = @{ + #Do Backups + Use = $true + + #Backup Folder + Path = ".\backups\$($Server.Name)" + + #Number of days of backups to keep. + Days = 7 + + #Number of weeks of weekly backups to keep. + Weeks = 4 + + #Folder to include in backup + Saves = "$Env:userprofile\AppData\LocalLow\IronGate\Valheim" +} +#Create the object +$Backups = New-Object -TypeName PsObject -Property $BackupsDetails + +#--------------------------------------------------------- +# Restart Warnings (Require RCON, Telnet or WebSocket API) +#--------------------------------------------------------- + +$WarningsDetails = @{ + #Use Rcon to restart server softly. + Use = $false + + #What protocol to use : Rcon, Telnet, Websocket + Protocol = "Rcon" + + #Times at which the servers will warn the players that it is about to restart. (in seconds between each timers) + Timers = [System.Collections.ArrayList]@(240,50,10) #Total wait time is 240+50+10 = 300 seconds or 5 minutes + + #message that will be sent. % is a wildcard for the timer. + MessageMin = "The server will restart in % minutes !" + + #message that will be sent. % is a wildcard for the timer. + MessageSec = "The server will restart in % seconds !" + + #command to send a message. + CmdMessage = "say" + + #command to save the server + CmdSave = "saveworld" + + #How long to wait in seconds after the save command is sent. + SaveDelay = 15 + + #command to stop the server + CmdStop = "shutdown" +} +#Create the object +$Warnings = New-Object -TypeName PsObject -Property $WarningsDetails + +#--------------------------------------------------------- +# Launch Arguments +#--------------------------------------------------------- + +$app = Start-Process -FilePath "$serverExec" -WorkingDirectory "$serverPath" -ArgumentList "-batchmode -nographics -name $serverName -port $serverPort -world $worldName -password $serverPassword -public 1 " -PassThru + + +#Launch Arguments +$Arguments = @( + "-batchmode ", + "-nographics ", + "-name $($Server.SessionName) ", + "-port $($Server.Port) ", + "-world $($Server.World) ", + "-password $($Server.Password) ", + "-public 1" +) + +[System.Collections.ArrayList]$CleanedArguments=@() + +foreach($Argument in $Arguments){ + if (!($Argument.EndsWith('=""') -or $Argument.EndsWith('=') -or $Argument.EndsWith(' '))){ + $CleanedArguments.Add($Argument) + } +} + +$ArgumentList = $CleanedArguments -join "" + +#Server Launcher +$Launcher = $Server.Exec + +#--------------------------------------------------------- +# Launch Function +#--------------------------------------------------------- + +function Start-Server { + + Write-ScriptMsg "Port Forward : $($server.Port) in TCP and UDP to $($Global.InternalIP)" + + #Start Server + $App = Start-Process -FilePath $Launcher -WorkingDirectory $Server.Path -ArgumentList $ArgumentList -PassThru + + return $App +} + +Export-ModuleMember -Function Start-Server -Variable @("Server","Backups","Warnings") \ No newline at end of file From aa0383e8127db77f1bcb42ba9abf82aa43a891c9 Mon Sep 17 00:00:00 2001 From: Patrick Veilleux Date: Thu, 16 Sep 2021 19:44:39 -0400 Subject: [PATCH 2/9] fix typo --- configs/valheim.psm1 | 198 +++++++++++++++++++++++++++++ launchers/run.cmd | 2 +- templates/7daystodie.psm1 | 2 +- templates/insurgencysandstorm.psm1 | 2 +- templates/pixark.psm1 | 2 +- templates/projectzomboid.psm1 | 2 +- templates/valheim.psm1 | 2 +- 7 files changed, 204 insertions(+), 6 deletions(-) create mode 100644 configs/valheim.psm1 diff --git a/configs/valheim.psm1 b/configs/valheim.psm1 new file mode 100644 index 0000000..b0d408b --- /dev/null +++ b/configs/valheim.psm1 @@ -0,0 +1,198 @@ + +#Server Name, use the same name to share game files. +$Name = "Valheim" + +#--------------------------------------------------------- +# Server Configuration +#--------------------------------------------------------- + +$ServerDetails = @{ + + #Unique Identifier used to track processes. Must be unique to each servers. + $UID = 5 + + #Name of the server in the Server Browser + SessionName = "My Valheim Server" + + #World name (It is also the seed) + World = "World" + + #Password to join the World *NO SPACES* + Password = "CHANGEME" + + #Server Port + Port = 2459 + + #Rcon IP (not supported by valheim yet.) + ManagementIP = "" + + #Rcon Port + ManagementPort = "" + + #Rcon Password + ManagementPassword = "" + +#--------------------------------------------------------- +# Server Installation Details +#--------------------------------------------------------- + + #Name of the Server Instance + Name = $Name + + #Server Installation Path + Path = ".\servers\$Name" + + #Steam Server App Id + AppID = 896660 + + #Use Beta builds $true or $false + Beta = $false + + #Name of the Beta Build + BetaBuild = "" + + #Beta Build Password + BetaBuildPassword = "" + + #Process name in the task manager + ProcessName = "valheim_server" + + #ProjectZomboid64.exe + Exec = ".\servers\$Name\valheim_server.exe" + + #Allow force close, usefull for server without RCON and Multiple instances. + AllowForceClose = $true + + #Process Priority Realtime, High, Above normal, Normal, Below normal, Low + UsePriority = $true + AppPriority = "High" + + <# + Process Affinity (Core Assignation) + Core 1 = > 00000001 = > 1 + Core 2 = > 00000010 = > 2 + Core 3 = > 00000100 = > 4 + Core 4 = > 00001000 = > 8 + Core 5 = > 00010000 = > 16 + Core 6 = > 00100000 = > 32 + Core 7 = > 01000000 = > 64 + Core 8 = > 10000000 = > 128 + ---------------------------- + 8 Cores = > 11111111 = > 255 + 4 Cores = > 00001111 = > 15 + 2 Cores = > 00000011 = > 3 + #> + + UseAffinity = $false + AppAffinity = 15 + + #Should the server validate install after installation or update *(recommended) + Validate = $true +} +#Create the object +$Server = New-Object -TypeName PsObject -Property $ServerDetails + +#--------------------------------------------------------- +# Backups +#--------------------------------------------------------- + +$BackupsDetails = @{ + #Do Backups + Use = $true + + #Backup Folder + Path = ".\backups\$($Server.Name)" + + #Number of days of backups to keep. + Days = 7 + + #Number of weeks of weekly backups to keep. + Weeks = 4 + + #Folder to include in backup + Saves = "$Env:userprofile\AppData\LocalLow\IronGate\Valheim" +} +#Create the object +$Backups = New-Object -TypeName PsObject -Property $BackupsDetails + +#--------------------------------------------------------- +# Restart Warnings (Require RCON, Telnet or WebSocket API) +#--------------------------------------------------------- + +$WarningsDetails = @{ + #Use Rcon to restart server softly. + Use = $false + + #What protocol to use : Rcon, Telnet, Websocket + Protocol = "Rcon" + + #Times at which the servers will warn the players that it is about to restart. (in seconds between each timers) + Timers = [System.Collections.ArrayList]@(240,50,10) #Total wait time is 240+50+10 = 300 seconds or 5 minutes + + #message that will be sent. % is a wildcard for the timer. + MessageMin = "The server will restart in % minutes !" + + #message that will be sent. % is a wildcard for the timer. + MessageSec = "The server will restart in % seconds !" + + #command to send a message. + CmdMessage = "say" + + #command to save the server + CmdSave = "saveworld" + + #How long to wait in seconds after the save command is sent. + SaveDelay = 15 + + #command to stop the server + CmdStop = "shutdown" +} +#Create the object +$Warnings = New-Object -TypeName PsObject -Property $WarningsDetails + +#--------------------------------------------------------- +# Launch Arguments +#--------------------------------------------------------- + +$app = Start-Process -FilePath "$serverExec" -WorkingDirectory "$serverPath" -ArgumentList "-batchmode -nographics -name $serverName -port $serverPort -world $worldName -password $serverPassword -public 1 " -PassThru + + +#Launch Arguments +$Arguments = @( + "-batchmode ", + "-nographics ", + "-name $($Server.SessionName) ", + "-port $($Server.Port) ", + "-world $($Server.World) ", + "-password $($Server.Password) ", + "-public 1" +) + +[System.Collections.ArrayList]$CleanedArguments=@() + +foreach($Argument in $Arguments){ + if (!($Argument.EndsWith('=""') -or $Argument.EndsWith('=') -or $Argument.EndsWith(' '))){ + $CleanedArguments.Add($Argument) + } +} + +$ArgumentList = $CleanedArguments -join "" + +#Server Launcher +$Launcher = $Server.Exec + +#--------------------------------------------------------- +# Launch Function +#--------------------------------------------------------- + +function Start-Server { + + Write-ScriptMsg "Port Forward : $($server.Port) in TCP and UDP to $($Global.InternalIP)" + + #Start Server + $App = Start-Process -FilePath $Launcher -WorkingDirectory $Server.Path -ArgumentList $ArgumentList -PassThru + + return $App +} + +Export-ModuleMember -Function Start-Server -Variable @("Server","Backups","Warnings") \ No newline at end of file diff --git a/launchers/run.cmd b/launchers/run.cmd index 706ae16..0904e89 100644 --- a/launchers/run.cmd +++ b/launchers/run.cmd @@ -1,2 +1,2 @@ cd .. -start powershell.exe -noprofile -executionpolicy bypass -file ".\main.ps1" -ServerCfg "projectzomboid" \ No newline at end of file +start powershell.exe -noprofile -executionpolicy bypass -file ".\main.ps1" -ServerCfg "valheim" \ No newline at end of file diff --git a/templates/7daystodie.psm1 b/templates/7daystodie.psm1 index 611bbdf..1e6cc92 100644 --- a/templates/7daystodie.psm1 +++ b/templates/7daystodie.psm1 @@ -13,7 +13,7 @@ $Name = "7DaysToDie" $ServerDetails = @{ #Unique Identifier used to track processes. Must be unique to each servers. - $UID = 7 + UID = 7 #Server Configuration ConfigFile = "$Env:userprofile\AppData\Roaming\7DaysToDie\Saves\serverconfig.xml" diff --git a/templates/insurgencysandstorm.psm1 b/templates/insurgencysandstorm.psm1 index b915a4a..66c099f 100644 --- a/templates/insurgencysandstorm.psm1 +++ b/templates/insurgencysandstorm.psm1 @@ -13,7 +13,7 @@ $Name = "InsurgencySandstorm" $ServerDetails = @{ #Unique Identifier used to track processes. Must be unique to each servers. - $UID = 2 + UID = 2 #Name of the server in the Server Browser SessionName = "My Insurgency Server" diff --git a/templates/pixark.psm1 b/templates/pixark.psm1 index 181e46f..4733a61 100644 --- a/templates/pixark.psm1 +++ b/templates/pixark.psm1 @@ -33,7 +33,7 @@ $Name = "PixArk" $ServerDetails = @{ #Unique Identifier used to track processes. Must be unique to each servers. - $UID = 3 + UID = 3 #Name of the server in the Server Browser SessionName = "My Pixark Server" diff --git a/templates/projectzomboid.psm1 b/templates/projectzomboid.psm1 index 5fc63b2..bedb5de 100644 --- a/templates/projectzomboid.psm1 +++ b/templates/projectzomboid.psm1 @@ -40,7 +40,7 @@ $Name = "ProjectZomboid" $ServerDetails = @{ #Unique Identifier used to track processes. Must be unique to each servers. - $UID = 4 + UID = 4 #Rcon IP, usually localhost ManagementIP = "127.0.0.1" diff --git a/templates/valheim.psm1 b/templates/valheim.psm1 index b0d408b..322a436 100644 --- a/templates/valheim.psm1 +++ b/templates/valheim.psm1 @@ -9,7 +9,7 @@ $Name = "Valheim" $ServerDetails = @{ #Unique Identifier used to track processes. Must be unique to each servers. - $UID = 5 + UID = 5 #Name of the server in the Server Browser SessionName = "My Valheim Server" From 80215255c535d2f3c23639a714d41391b62cbf73 Mon Sep 17 00:00:00 2001 From: Patrick Veilleux Date: Thu, 16 Sep 2021 19:45:20 -0400 Subject: [PATCH 3/9] fix $ --- configs/valheim.psm1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configs/valheim.psm1 b/configs/valheim.psm1 index b0d408b..322a436 100644 --- a/configs/valheim.psm1 +++ b/configs/valheim.psm1 @@ -9,7 +9,7 @@ $Name = "Valheim" $ServerDetails = @{ #Unique Identifier used to track processes. Must be unique to each servers. - $UID = 5 + UID = 5 #Name of the server in the Server Browser SessionName = "My Valheim Server" From c8dd9b15c086f59b98685517eb85b9eb7f3f0c3b Mon Sep 17 00:00:00 2001 From: Patrick Veilleux Date: Thu, 16 Sep 2021 19:46:44 -0400 Subject: [PATCH 4/9] fix typo --- configs/valheim.psm1 | 3 --- templates/valheim.psm1 | 3 --- 2 files changed, 6 deletions(-) diff --git a/configs/valheim.psm1 b/configs/valheim.psm1 index 322a436..dcace6c 100644 --- a/configs/valheim.psm1 +++ b/configs/valheim.psm1 @@ -154,9 +154,6 @@ $Warnings = New-Object -TypeName PsObject -Property $WarningsDetails # Launch Arguments #--------------------------------------------------------- -$app = Start-Process -FilePath "$serverExec" -WorkingDirectory "$serverPath" -ArgumentList "-batchmode -nographics -name $serverName -port $serverPort -world $worldName -password $serverPassword -public 1 " -PassThru - - #Launch Arguments $Arguments = @( "-batchmode ", diff --git a/templates/valheim.psm1 b/templates/valheim.psm1 index 322a436..dcace6c 100644 --- a/templates/valheim.psm1 +++ b/templates/valheim.psm1 @@ -154,9 +154,6 @@ $Warnings = New-Object -TypeName PsObject -Property $WarningsDetails # Launch Arguments #--------------------------------------------------------- -$app = Start-Process -FilePath "$serverExec" -WorkingDirectory "$serverPath" -ArgumentList "-batchmode -nographics -name $serverName -port $serverPort -world $worldName -password $serverPassword -public 1 " -PassThru - - #Launch Arguments $Arguments = @( "-batchmode ", From 63a32f5b24befa83ecda7f2780f818dabd310808 Mon Sep 17 00:00:00 2001 From: Patrick Veilleux Date: Thu, 16 Sep 2021 21:48:17 -0400 Subject: [PATCH 5/9] add comments --- configs/7daystodie.psm1 | 200 ++++++++++++++++++++++ configs/global.psm1 | 7 +- configs/insurgencysandstorm.psm1 | 250 ++++++++++++++++++++++++++++ configs/pixark.psm1 | 258 +++++++++++++++++++++++++++++ configs/projectzomboid.psm1 | 226 +++++++++++++++++++++++++ functions/Backup-Server.psm1 | 4 +- functions/Exit-WithError.psm1 | 1 + functions/Get-PID.psm1 | 1 + functions/Install-Mcrcon.psm1 | 4 + functions/Install-SevenZip.psm1 | 5 + functions/Install-SteamCMD.psm1 | 2 + functions/Register-PID.psm1 | 2 +- functions/Remove-OldLog.psm1 | 6 +- functions/Send-Command.psm1 | 4 + functions/Send-RestartWarning.psm1 | 14 ++ functions/Set-Priority.psm1 | 3 +- functions/Stop-Server.psm1 | 8 + functions/Unregister-PID.psm1 | 1 + functions/Update-Server.psm1 | 5 +- functions/Write-ScriptMsg.psm1 | 3 +- functions/Write-ServerMsg.psm1 | 1 + main.ps1 | 39 ++++- 22 files changed, 1029 insertions(+), 15 deletions(-) create mode 100644 configs/7daystodie.psm1 create mode 100644 configs/insurgencysandstorm.psm1 create mode 100644 configs/pixark.psm1 create mode 100644 configs/projectzomboid.psm1 diff --git a/configs/7daystodie.psm1 b/configs/7daystodie.psm1 new file mode 100644 index 0000000..1e6cc92 --- /dev/null +++ b/configs/7daystodie.psm1 @@ -0,0 +1,200 @@ +<# +#Change your servers settings in C:\Users\%username%\AppData\Roaming\7DaysToDie\Saves\serverconfig.xml +#> + +#Server Name, use the same name to share game files. +$Name = "7DaysToDie" + + +#--------------------------------------------------------- +# Server Configuration +#--------------------------------------------------------- + +$ServerDetails = @{ + + #Unique Identifier used to track processes. Must be unique to each servers. + UID = 7 + + #Server Configuration + ConfigFile = "$Env:userprofile\AppData\Roaming\7DaysToDie\Saves\serverconfig.xml" + + #Rcon IP, usually localhost + ManagementIP = "127.0.0.1" + + #Rcon Port in serverconfig.xml + ManagementPort = 8081 + + #Rcon Password as set in serverconfig.xml nothing is localhost only. + ManagementPassword = "" + + #Server Log File + LogFile = "$Env:userprofile\AppData\Roaming\7DaysToDie\Logs\$(Get-TimeStamp).txt" + +#--------------------------------------------------------- +# Server Installation Details +#--------------------------------------------------------- + + #Name of the Server Instance + Name = $Name + + #Server Installation Path + Path = ".\servers\$Name" + + #Steam Server App Id + AppID = 294420 + + #Use Beta builds $true or $false + Beta = $false + + #Name of the Beta Build + BetaBuild = "" + + #Beta Build Password + BetaBuildPassword = "" + + #Process name in the task manager + ProcessName = "7DaysToDieServer" + + #ProjectZomboid64.exe + Exec = ".\servers\$Name\7DaysToDieServer.exe" + + #Allow force close, usefull for server without RCON and Multiple instances. + AllowForceClose = $true + + #Process Priority Realtime, High, Above normal, Normal, Below normal, Low + UsePriority = $true + AppPriority = "High" + + <# + Process Affinity (Core Assignation) + Core 1 = > 00000001 = > 1 + Core 2 = > 00000010 = > 2 + Core 3 = > 00000100 = > 4 + Core 4 = > 00001000 = > 8 + Core 5 = > 00010000 = > 16 + Core 6 = > 00100000 = > 32 + Core 7 = > 01000000 = > 64 + Core 8 = > 10000000 = > 128 + ---------------------------- + 8 Cores = > 11111111 = > 255 + 4 Cores = > 00001111 = > 15 + 2 Cores = > 00000011 = > 3 + #> + + UseAffinity = $false + AppAffinity = 15 + + #Should the server validate install after installation or update *(recommended) + Validate = $true +} +#Create the object +$Server = New-Object -TypeName PsObject -Property $ServerDetails + +#--------------------------------------------------------- +# Backups +#--------------------------------------------------------- + +$BackupsDetails = @{ + #Do Backups + Use = $true + + #Backup Folder + Path = ".\backups\$($Server.Name)" + + #Number of days of backups to keep. + Days = 7 + + #Number of weeks of weekly backups to keep. + Weeks = 4 + + #Folder to include in backup + Saves = "$Env:userprofile\AppData\Roaming\7DaysToDie" +} +#Create the object +$Backups = New-Object -TypeName PsObject -Property $BackupsDetails + +#--------------------------------------------------------- +# Restart Warnings (Require RCON, Telnet or WebSocket API) +#--------------------------------------------------------- + +$WarningsDetails = @{ + #Use Rcon to restart server softly. + Use = $true + + #What protocol to use : Rcon, Telnet, Websocket + Protocol = "Telnet" + + #Times at which the servers will warn the players that it is about to restart. (in seconds between each timers) + Timers = [System.Collections.ArrayList]@(240,50,10) #Total wait time is 240+50+10 = 300 seconds or 5 minutes + + #message that will be sent. % is a wildcard for the timer. + MessageMin = "The server will restart in % minutes !" + + #message that will be sent. % is a wildcard for the timer. + MessageSec = "The server will restart in % seconds !" + + #command to send a message. + CmdMessage = "say" + + #command to save the server + CmdSave = "saveworld" + + #How long to wait in seconds after the save command is sent. + SaveDelay = 15 + + #command to stop the server + CmdStop = "shutdown" +} +#Create the object +$Warnings = New-Object -TypeName PsObject -Property $WarningsDetails + +#--------------------------------------------------------- +# Launch Arguments +#--------------------------------------------------------- + +#Launch Arguments +$Arguments = @( + "-logfile $($Server.LogFile) ", + "-configfile=$($Server.ConfigFile) ", + "-batchmode ", + "-nographics ", + "-dedicated ", + "-quit" +) + +[System.Collections.ArrayList]$CleanedArguments=@() + +foreach($Argument in $Arguments){ + if (!($Argument.EndsWith('=""') -or $Argument.EndsWith('=') -or $Argument.EndsWith(' '))){ + $CleanedArguments.Add($Argument) + } +} + +$ArgumentList = $CleanedArguments -join "" + +#Server Launcher +$Launcher = $Server.Exec + +#--------------------------------------------------------- +# Launch Function +#--------------------------------------------------------- + +function Start-Server { + + Write-ScriptMsg "Port Forward : 26900 in TCP and 26900 to 26903 in UDP to $($Global.InternalIP)" + + #Copy Config File if not created. Do not modify the one in the server directory, it will be overwriten on updates. + $ConfigFilePath = Split-Path -Path $Server.ConfigFile + if (-not(Test-Path -Path $ConfigFilePath)){ + New-Item -ItemType "directory" -Path $ConfigFilePath -Force -ErrorAction SilentlyContinue + } + If(-not (Test-Path -Path $Server.ConfigFile -PathType "leaf")){ + Copy-Item -Path "$($Server.Path)\serverconfig.xml" -Destination $Server.ConfigFile -Force + } + #Start Server + $App = Start-Process -FilePath $Launcher -WorkingDirectory $Server.Path -ArgumentList $ArgumentList -PassThru + + return $App +} + +Export-ModuleMember -Function Start-Server -Variable @("Server","Backups","Warnings") \ No newline at end of file diff --git a/configs/global.psm1 b/configs/global.psm1 index 627f8dd..0910008 100644 --- a/configs/global.psm1 +++ b/configs/global.psm1 @@ -17,11 +17,14 @@ $GlobalDetails = @{ #Console Output Text Color FgColor = "Green" + #Console Output Background Color + BgColor = "Black" + #Console Output Text Color for sections SectionColor = "Blue" - #Console Output Background Color - BgColor = "Black" + #Console Output Background Color for sections + SectionBgColor = "Black" } #Create the object diff --git a/configs/insurgencysandstorm.psm1 b/configs/insurgencysandstorm.psm1 new file mode 100644 index 0000000..66c099f --- /dev/null +++ b/configs/insurgencysandstorm.psm1 @@ -0,0 +1,250 @@ +<# +#Change your servers settings in ".\servers\Insurgency\Saved\Config\WindowsServer" +#> + +#Server Name, use the same name to share game files. +$Name = "InsurgencySandstorm" + + +#--------------------------------------------------------- +# Server Configuration +#--------------------------------------------------------- + +$ServerDetails = @{ + + #Unique Identifier used to track processes. Must be unique to each servers. + UID = 2 + + #Name of the server in the Server Browser + SessionName = "My Insurgency Server" + + #Maximum Number of Players + MaxPlayers = 8 + + #Password to join the World *NO SPACES* + Password = "CHANGEME" + + #Server Port + Port = 27102 + + #Query Port + QueryPort = 27131 + + #Token -> https://steamcommunity.com/dev/managegameservers + GSLTToken = "CHANGEME" + + #GameStatToken -> https://gamestats.sandstorm.game/ + GameStatsToken = "CHANGEME" + + #Scenario + Scenario = "Scenario_Citadel_Survival" + + #Map + Map = "Citadel" + + #Map Cycle : Create a new text document in Insurgency/Config/Server named MapCycle.txt + MapCycle = "MapCycle" + + #Admins : Create a new text document in Insurgency/Config/Server named Admins.txt steamID64, one per line + Admins = "Admins" + + #Motd : Create a new text document in Insurgency/Config/Server named MOTD.txt + Motd = "MOTD" + + #Mods comma separted -> https://sandstorm-support.newworldinteractive.com/hc/en-us/articles/360049211072-Server-Admin-Guide + Mods = "" + + #Mutators comma separted -> https://sandstorm-support.newworldinteractive.com/hc/en-us/articles/360049211072-Server-Admin-Guide + Mutators = "" + + #Official RuleSet + OfficialRulesSet = "OfficialRules" + + #Enable Rcon $true or $false + EnableRcon = $true + + #Rcon IP, usually localhost + ManagementIP = "127.0.0.1" + + #Rcon Port + ManagementPort = 27015 + + #Rcon Password *NO SPACES* + ManagementPassword = "CHANGEME" + +#--------------------------------------------------------- +# Server Installation Details +#--------------------------------------------------------- + + #Name of the Server Instance + Name = $Name + + #Server Installation Path + Path = ".\servers\$Name" + + #Steam Server App Id + AppID = 581330 + + #Use Beta builds $true or $false + Beta = $false + + #Name of the Beta Build + BetaBuild = "" + + #Beta Build Password + BetaBuildPassword = "" + + #Process name in the task manager + ProcessName = "InsurgencyServer" + + #ProjectZomboid64.exe + Exec = ".\servers\$Name\InsurgencyServer.exe" + + #Allow force close, usefull for server without RCON and Multiple instances. + AllowForceClose = $true + + #Process Priority Realtime, High, Above normal, Normal, Below normal, Low + UsePriority = $true + AppPriority = "High" + + <# + Process Affinity (Core Assignation) + Core 1 = > 00000001 = > 1 + Core 2 = > 00000010 = > 2 + Core 3 = > 00000100 = > 4 + Core 4 = > 00001000 = > 8 + Core 5 = > 00010000 = > 16 + Core 6 = > 00100000 = > 32 + Core 7 = > 01000000 = > 64 + Core 8 = > 10000000 = > 128 + ---------------------------- + 8 Cores = > 11111111 = > 255 + 4 Cores = > 00001111 = > 15 + 2 Cores = > 00000011 = > 3 + #> + + UseAffinity = $false + AppAffinity = 15 + + #Should the server validate install after installation or update *(recommended) + Validate = $true +} +#Create the object +$Server = New-Object -TypeName PsObject -Property $ServerDetails + +#--------------------------------------------------------- +# Backups +#--------------------------------------------------------- + +$BackupsDetails = @{ + #Do Backups + Use = $true + + #Backup Folder + Path = ".\backups\$($Server.Name)" + + #Number of days of backups to keep. + Days = 7 + + #Number of weeks of weekly backups to keep. + Weeks = 4 + + #Folder to include in backup + Saves = ".\servers\$($Server.Name)\Insurgency\Config\Server" +} +#Create the object +$Backups = New-Object -TypeName PsObject -Property $BackupsDetails + +#--------------------------------------------------------- +# Restart Warnings (Require RCON, Telnet or WebSocket API) +#--------------------------------------------------------- + +$WarningsDetails = @{ + #Use Rcon to restart server softly. + Use = $true + + #What protocol to use : Rcon, Telnet, Websocket + Protocol = "Rcon" + + #Times at which the servers will warn the players that it is about to restart. (in seconds between each timers) + Timers = [System.Collections.ArrayList]@(240,50,10) #Total wait time is 240+50+10 = 300 seconds or 5 minutes + + #message that will be sent. % is a wildcard for the timer. + MessageMin = "The server will restart in % minutes !" + + #message that will be sent. % is a wildcard for the timer. + MessageSec = "The server will restart in % seconds !" + + #command to send a message. + CmdMessage = "say" + + #command to save the server + CmdSave = "listplayers" + + #How long to wait in seconds after the save command is sent. + SaveDelay = 15 + + #command to stop the server + CmdStop = "exit" +} +#Create the object +$Warnings = New-Object -TypeName PsObject -Property $WarningsDetails + +#--------------------------------------------------------- +# Launch Arguments +#--------------------------------------------------------- + +$Arguments = @( + "$($Server.Map)", + "?Scenario=$($Server.Scenario)", + "?MaxPlayers=$($Server.MaxPlayers)", + "?password=`"$($Server.Password)`" ", + "-Port=$($Server.Port) ", + "-QueryPort=$($Server.QueryPort) ", + "-hostname=`"$($Server.SessionName)`" ", + "-GSLTToken=`"$($Server.GSLTToken)`" ", + "-GameStatsToken=`"$($Server.GameStatsToken)`" ", + "-Gamestats", + "-MapCycle=`"$($Server.MapCycle)`" ", + "-AdminList=`"$($Server.Admins)`" ", + "-MOTD=`"$($Server.Motd)`" ", + "-ruleset=`"$($Server.OfficialRulesSet)`" ", + "-CmdModList=`"$($Server.Mods)`" ", + "-mutators=`"$($Server.Mutators)`" ", + "-log" +) + +[System.Collections.ArrayList]$CleanedArguments=@() + +foreach($Argument in $Arguments){ + if (!($Argument.EndsWith('=""') -or $Argument.EndsWith('=') -or $Argument.EndsWith(' '))){ + $CleanedArguments.Add($Argument) + } +} + +if ($Server.EnableRcon){ + $CleanedArguments.Add(" -Rcon") + $CleanedArguments.Add(" -RconPassword=`"$($Server.ManagementPassword)`"") + $CleanedArguments.Add(" -RconListenPort=`"$($Server.ManagementPort)`"") +} + +$ArgumentList = $CleanedArguments -join "" + +#Server Launcher +$Launcher = $Server.Exec + +#--------------------------------------------------------- +# Launch Function +#--------------------------------------------------------- + +function Start-Server { + + Write-ScriptMsg "Port Forward : $($server.Port) and $($server.QueryPort) in TCP and UDP to $($Global.InternalIP)" + + #Start Server + $App = Start-Process -FilePath $Launcher -WorkingDirectory $Server.Path -ArgumentList $ArgumentList -PassThru + + return $App +} + +Export-ModuleMember -Function Start-Server -Variable @("Server","Backups","Warnings") \ No newline at end of file diff --git a/configs/pixark.psm1 b/configs/pixark.psm1 new file mode 100644 index 0000000..4733a61 --- /dev/null +++ b/configs/pixark.psm1 @@ -0,0 +1,258 @@ +<# +#Change your servers settings in ".\servers\PixArk\ShooterGame\Saved\Config\WindowsServer\GameUserSettings.ini" + +Under : [ServerSettings] +Add/Set one of those settings : + +Pioneering : + +CanPVPAttack=False +ServerPVPCanAttack=False + +Fury : + +ServerPVE=False +CanPVPAttack=True +ServerPVPCanAttack=False + +Chaos: + +ServerPVE=False +CanPVPAttack=False +ServerPVPCanAttack=True + +#> + +#Server Name, use the same name to share game files. +$Name = "PixArk" + +#--------------------------------------------------------- +# Server Configuration +#--------------------------------------------------------- + +$ServerDetails = @{ + + #Unique Identifier used to track processes. Must be unique to each servers. + UID = 3 + + #Name of the server in the Server Browser + SessionName = "My Pixark Server" + + #Maximum Number of Players + MaxPlayers = 20 + + #Password to join the World *NO SPACES* + Password = "CHANGEME" + + #Server Port + Port = 7797 + + #World Seed + Seed = 32399 + + #Query Port + QueryPort = 27515 + + #Cube Port + CubePort = 27518 + + #World Name *NO SPACES* + WorldName = "World" + + #World Type : "SkyPiea_Light" for Skyward or "CubeWorld_Light" for regular + WorldType = "CubeWorld_Light" + + #Show Floating Damage Text "True" or "False" + ShowFloatingDamageText = "True" + + #Server Language + Language = "en" + + #Enable Rcon "True" or "False" + EnableRcon = "True" + + #Rcon IP, usually localhost + ManagementIP = "127.0.0.1" + + #Rcon Port + ManagementPort = 27520 + + #Rcon Password *NO SPACES* + ManagementPassword = "CHANGEME2" + +#--------------------------------------------------------- +# Server Installation Details +#--------------------------------------------------------- + + #Name of the Server Instance + Name = $Name + + #Server Installation Path + Path = ".\servers\$Name" + + #Steam Server App Id + AppID = 824360 + + #Use Beta builds $true or $false + Beta = $false + + #Name of the Beta Build + BetaBuild = "" + + #Beta Build Password + BetaBuildPassword = "" + + #Process name in the task manager + ProcessName = "PixArkServer" + + #ProjectZomboid64.exe + Exec = ".\servers\$Name\ShooterGame\Binaries\Win64\PixARKServer.exe" + + #Allow force close, usefull for server without RCON and Multiple instances. + AllowForceClose = $true + + #Process Priority Realtime, High, Above normal, Normal, Below normal, Low + UsePriority = $true + AppPriority = "High" + + <# + Process Affinity (Core Assignation) + Core 1 = > 00000001 = > 1 + Core 2 = > 00000010 = > 2 + Core 3 = > 00000100 = > 4 + Core 4 = > 00001000 = > 8 + Core 5 = > 00010000 = > 16 + Core 6 = > 00100000 = > 32 + Core 7 = > 01000000 = > 64 + Core 8 = > 10000000 = > 128 + ---------------------------- + 8 Cores = > 11111111 = > 255 + 4 Cores = > 00001111 = > 15 + 2 Cores = > 00000011 = > 3 + #> + + UseAffinity = $false + AppAffinity = 15 + + #Should the server validate install after installation or update *(recommended) + Validate = $true +} +#Create the object +$Server = New-Object -TypeName PsObject -Property $ServerDetails + +#--------------------------------------------------------- +# Backups +#--------------------------------------------------------- + +$BackupsDetails = @{ + #Do Backups + Use = $true + + #Backup Folder + Path = ".\backups\$($Server.Name)" + + #Number of days of backups to keep. + Days = 7 + + #Number of weeks of weekly backups to keep. + Weeks = 4 + + #Folder to include in backup + Saves = ".\servers\$($Server.Name)\ShooterGame\Saved" +} +#Create the object +$Backups = New-Object -TypeName PsObject -Property $BackupsDetails + +#--------------------------------------------------------- +# Restart Warnings (Require RCON, Telnet or WebSocket API) +#--------------------------------------------------------- + +$WarningsDetails = @{ + #Use Rcon to restart server softly. + Use = $true + + #What protocol to use : Rcon, Telnet, Websocket + Protocol = "Rcon" + + #Times at which the servers will warn the players that it is about to restart. (in seconds between each timers) + Timers = [System.Collections.ArrayList]@(240,50,10) #Total wait time is 240+50+10 = 300 seconds or 5 minutes + + #message that will be sent. % is a wildcard for the timer. + MessageMin = "The server will restart in % minutes !" + + #message that will be sent. % is a wildcard for the timer. + MessageSec = "The server will restart in % seconds !" + + #command to send a message. + CmdMessage = "broadcast" + + #command to save the server + CmdSave = "saveworld" + + #How long to wait in seconds after the save command is sent. + SaveDelay = 15 + + #command to stop the server + CmdStop = "quit" +} +#Create the object +$Warnings = New-Object -TypeName PsObject -Property $WarningsDetails + +#--------------------------------------------------------- +# Launch Arguments +#--------------------------------------------------------- + +#Launch Arguments +$Arguments = @( + "$($Server.WorldType)", + "?listen", + "?Multihome=$($Server.InternalIP)", + "?RCONEnabled=$($Server.EnableRcon)", + "?MaxPlayers=$($Server.MaxPlayers)", + "?Port=$($Server.Port)", + "?RCONPort=$($Server.ManagementPort)", + "?QueryPort=$($Server.QueryPort)", + "?ServerAdminPassword=$($Server.ManagementPassword)", + "?SessionName=`"$($Server.SessionName)`"", + "?ServerPassword=$($Server.Password)", + "?ShowFloatingDamageText=$($Server.ShowFloatingDamageText)", + "?CULTUREFORCOOKING=$($Server.Language) ", + "-CubePort=$($Server.CubePort) ", + "-CubeWorld=$($Server.WorldName) ", + "-Seed=$($Server.Seed) ", + "-forcerespawndinos " + "-NoHangDetection ", + "-nosteamclient ", + "-game ", + "-server ", + "-log" +) + +[System.Collections.ArrayList]$CleanedArguments=@() + +foreach($Argument in $Arguments){ + if (!($Argument.EndsWith('=""') -or $Argument.EndsWith('=') -or $Argument.EndsWith(' '))){ + $CleanedArguments.Add($Argument) + } +} + +$ArgumentList = $CleanedArguments -join "" + +#Server Launcher +$Launcher = $Server.Exec + +#--------------------------------------------------------- +# Launch Function +#--------------------------------------------------------- + +function Start-Server { + + Write-ScriptMsg "Port Forward : $($server.Port), $($server.QueryPort) And $($server.CubePort) in TCP and UDP to $($Global.InternalIP)" + + #Start Server + $App = Start-Process -FilePath $Launcher -WorkingDirectory $Server.Path -ArgumentList $ArgumentList -PassThru + + return $App +} + +Export-ModuleMember -Function Start-Server -Variable @("Server","Backups","Warnings") \ No newline at end of file diff --git a/configs/projectzomboid.psm1 b/configs/projectzomboid.psm1 new file mode 100644 index 0000000..bedb5de --- /dev/null +++ b/configs/projectzomboid.psm1 @@ -0,0 +1,226 @@ +<# +#Change your servers settings in C:\Users\%username%\Zomboid\Server\servertest.ini + +Options to look for when setting your server in servertest.ini (Suggested values) +``` +DefaultPort=16261 +MaxPlayers=64 +Open=true +PVP=true +Password=My server password +PauseEmpty=true +PingFrequency=10 +PingLimit=200 +Public=true +PublicDescription=My server Description +PublicName=My server name +RCONPassword=CHANGEME +RCONPort=27015 +SteamPort1=8766 +SteamPort2=8767 +``` + +You need to port forward the following Ports on your router, both in TCP and UDP + +``` +DefaultPort=16261 +SteamPort1=8766 +SteamPort2=8767 +``` +You do not need to forward RCON. +#> + +#Server Name, use the same name to share game files. +$Name = "ProjectZomboid" + +#--------------------------------------------------------- +# Server Configuration +#--------------------------------------------------------- + +$ServerDetails = @{ + + #Unique Identifier used to track processes. Must be unique to each servers. + UID = 4 + + #Rcon IP, usually localhost + ManagementIP = "127.0.0.1" + + #Rcon Port in servertest.ini + ManagementPort = 27015 + + #Rcon Password as set in servertest.ini (Do not use " " in servertest.ini) + ManagementPassword = "CHANGEME" + +#--------------------------------------------------------- +# Server Installation +#--------------------------------------------------------- + + #Name of the Server Instance + Name = $Name + + #Server Installation Path + Path = ".\servers\$Name" + + #Steam Server App Id + AppID = 380870 + + #Use Beta builds $true or $false + Beta = $false + + #Name of the Beta Build + BetaBuild = "iwillbackupmysave" + + #Beta Build Password + BetaBuildPassword = "iaccepttheconsequences" + + #Process name in the task manager + ProcessName = "java" + + #ProjectZomboid64.exe + Exec = ".\servers\$Name\ProjectZomboid64.exe" + + #Allow force close, usefull for server without RCON and Multiple instances. + AllowForceClose = $true + + #Process Priority Realtime, High, Above normal, Normal, Below normal, Low + UsePriority = $true + AppPriority = "High" + + <# + Process Affinity (Core Assignation) + Core 1 = > 00000001 = > 1 + Core 2 = > 00000010 = > 2 + Core 3 = > 00000100 = > 4 + Core 4 = > 00001000 = > 8 + Core 5 = > 00010000 = > 16 + Core 6 = > 00100000 = > 32 + Core 7 = > 01000000 = > 64 + Core 8 = > 10000000 = > 128 + ---------------------------- + 8 Cores = > 11111111 = > 255 + 4 Cores = > 00001111 = > 15 + 2 Cores = > 00000011 = > 3 + #> + + UseAffinity = $false + AppAffinity = 15 + + #Should the server validate install after installation or update *(recommended) + Validate = $true +} +#Create the object +$Server = New-Object -TypeName PsObject -Property $ServerDetails + +#--------------------------------------------------------- +# Backups +#--------------------------------------------------------- +$BackupsDetails = @{ + #Do Backups + Use = $true + + #Backup Folder + Path = ".\backups\$($Server.Name)" + + #Number of days of backups to keep. + Days = 7 + + #Number of weeks of weekly backups to keep. + Weeks = 4 + + #Folder to include in backup + Saves = "$Env:userprofile\Zomboid" +} +#Create the object +$Backups = New-Object -TypeName PsObject -Property $BackupsDetails + +#--------------------------------------------------------- +# Restart Warnings (Require RCON, Telnet or WebSocket API) +#--------------------------------------------------------- +$WarningsDetails = @{ + #Use Rcon to restart server softly. + Use = $true + + #What protocol to use : Rcon, Telnet, Websocket + Protocol = "Rcon" + + #Times at which the servers will warn the players that it is about to restart. (in seconds between each timers) + Timers = [System.Collections.ArrayList]@(240,50,10) #Total wait time is 240+50+10 = 300 seconds or 5 minutes + + #message that will be sent. % is a wildcard for the timer. + MessageMin = "The server will restart in % minutes !" + + #message that will be sent. % is a wildcard for the timer. + MessageSec = "The server will restart in % seconds !" + + #command to send a message. + CmdMessage = "servermsg" + + #command to save the server + CmdSave = "save" + + #How long to wait in seconds after the save command is sent. + SaveDelay = 15 + + #command to stop the server + CmdStop = "quit" +} +#Create the object +$Warnings = New-Object -TypeName PsObject -Property $WarningsDetails + +#--------------------------------------------------------- +# Launch Arguments +#--------------------------------------------------------- + +#Java Arguments +$PZ_CLASSPATH_LIST = @( + "java/jinput.jar;", + "java/lwjgl.jar;", + "java/lwjgl_util.jar;", + "java/sqlite-jdbc-3.8.10.1.jar;", + "java/trove-3.0.3.jar;", + "java/uncommons-maths-1.2.3.jar;", + "java/javacord-2.0.17-shaded.jar;", + "java/guava-23.0.jar;", + "java/" +) + +$PZ_CLASSPATH = $PZ_CLASSPATH_LIST -join "" +#Launch Arguments +$Arguments = @( + "-Dzomboid.steam=1 ", + "-Dzomboid.znetlog=1 ", + "-XX:+UseConcMarkSweepGC ", + "-XX:-CreateMinidumpOnCrash ", + "-XX:-OmitStackTraceInFastThrow ", + "-Xms2048m ", + "-Xmx2048m ", + "-Djava.library.path=natives/;. ", + "-cp $PZ_CLASSPATH zombie.network.GameServer" +) + +[System.Collections.ArrayList]$CleanedArguments=@() + +foreach($Argument in $Arguments){ + if (!($Argument.EndsWith('=""') -or $Argument.EndsWith('=') -or $Argument.EndsWith(' '))){ + $CleanedArguments.Add($Argument) + } +} + +$ArgumentList = $CleanedArguments -join "" + +$Launcher = "$($Server.Path)\jre64\bin\java.exe" + +#--------------------------------------------------------- +# Launch Function +#--------------------------------------------------------- + +function Start-Server { + + Write-ScriptMsg "Port Forward : 16261, 8766 and 8767 in TCP and UDP to $($Global.InternalIP)" + + $App = Start-Process -FilePath $Launcher -WorkingDirectory $Server.Path -ArgumentList $ArgumentList -PassThru + + return $App +} + +Export-ModuleMember -Function Start-Server -Variable @("Server","Backups","Warnings") \ No newline at end of file diff --git a/functions/Backup-Server.psm1 b/functions/Backup-Server.psm1 index 7a17f27..01d44b2 100644 --- a/functions/Backup-Server.psm1 +++ b/functions/Backup-Server.psm1 @@ -35,7 +35,9 @@ function Backup-Server { #Delete old backups Write-ServerMsg "Deleting old backups." - Get-ChildItem -Path "$($Backups.Path)\$Type" -Recurse -Force | Where-Object { -not ($_.PSIsContainer) -and $_.LastWriteTime -lt $Limit } | Remove-Item -Force + Get-ChildItem -Path "$($Backups.Path)\$Type" -Recurse -Force | + Where-Object { -not ($_.PSIsContainer) -and $_.LastWriteTime -lt $Limit } | + Remove-Item -Force } Export-ModuleMember -Function Backup-Server \ No newline at end of file diff --git a/functions/Exit-WithError.psm1 b/functions/Exit-WithError.psm1 index d3636fa..34b658d 100644 --- a/functions/Exit-WithError.psm1 +++ b/functions/Exit-WithError.psm1 @@ -5,6 +5,7 @@ function Exit-WithError [Parameter(Mandatory)] [string]$ErrorMsg ) + #Write error in red on black, stop logging, pause, exit. Write-Host -ForegroundColor "Red" -BackgroundColor "Black" -Object $ErrorMsg Stop-Transcript Read-Host diff --git a/functions/Get-PID.psm1 b/functions/Get-PID.psm1 index 7454bf6..8118d0e 100644 --- a/functions/Get-PID.psm1 +++ b/functions/Get-PID.psm1 @@ -4,6 +4,7 @@ function Get-PID { param ( ) try { + #Read the process ID from the PID file named by the UID defined in the server cfg file. $ServerPID = Get-Content -Path ".\servers\$($Server.UID).PID" -ErrorAction Continue } catch { diff --git a/functions/Install-Mcrcon.psm1 b/functions/Install-Mcrcon.psm1 index 3190cdf..0054657 100644 --- a/functions/Install-Mcrcon.psm1 +++ b/functions/Install-Mcrcon.psm1 @@ -5,9 +5,13 @@ function Install-Mcrcon { [string]$Application ) Write-ServerMsg "Downloading mcrcon." + #Create Install Directory. New-Item -Path (Split-Path -Path $Application) -ItemType "directory" + #Download zip file. Invoke-WebRequest -Uri "https://github.com/Tiiffi/mcrcon/releases/download/v0.7.1/mcrcon-0.7.1-windows-x86-32.zip" -OutFile ".\downloads\mcrcon.zip" -ErrorAction SilentlyContinue + #Unzip file. Expand-Archive -Path ".\downloads\mcrcon.zip" -DestinationPath ".\downloads\mcrcon\" -Force + #Copy executable to install directory. Copy-Item -Path ".\downloads\mcrcon\mcrcon-0.7.1-windows-x86-32\mcrcon.exe" -Destination $Application -Force Write-ServerMsg "Mcrcon Installed." } diff --git a/functions/Install-SevenZip.psm1 b/functions/Install-SevenZip.psm1 index cfc1a0c..6d0e67d 100644 --- a/functions/Install-SevenZip.psm1 +++ b/functions/Install-SevenZip.psm1 @@ -6,11 +6,16 @@ function Install-SevenZip { ) Write-ServerMsg "Installing 7Zip Portable." Write-ServerMsg "Downloading 7zip 9.20 to extract 7zip 19.00" + #Download 7zip 9.20 Invoke-WebRequest -Uri "https://www.7-zip.org/a/7za920.zip" -OutFile ".\downloads\7za920.zip" + #Unzip 7zip 9.20 Expand-Archive -Path ".\downloads\7za920.zip" -DestinationPath ".\downloads\7z920\" -Force Write-ServerMsg "Downloading 7zip 19.00" + #Download 7zip 19.00 Invoke-WebRequest -Uri "https://www.7-zip.org/a/7z1900-extra.7z" -OutFile ".\downloads\7z1900-extra.7z" -ErrorAction SilentlyContinue + #Use 7zip 9.20 to unzip 7zip 19.00 & ".\downloads\7z920\7za.exe" x ".\downloads\7z1900-extra.7z" -o".\downloads\7z1900\" -y + #Copy the executable and dll to the 7zip directory. Copy-Item -Path ".\downloads\7z1900\x64\" -Destination (Split-Path -Path $Application) -Recurse -Force Write-ServerMsg "7Zip Installed." } diff --git a/functions/Install-SteamCMD.psm1 b/functions/Install-SteamCMD.psm1 index 9f4b099..2a00414 100644 --- a/functions/Install-SteamCMD.psm1 +++ b/functions/Install-SteamCMD.psm1 @@ -5,7 +5,9 @@ function Install-SteamCMD { [string]$Application ) Write-ServerMsg "Downloading SteamCMD." + #Download file Invoke-WebRequest -Uri "https://steamcdn-a.akamaihd.net/client/installer/steamcmd.zip" -OutFile ".\downloads\steamcmd.zip" -ErrorAction SilentlyContinue + #Unzip file in installation directory Expand-Archive -Path ".\downloads\steamcmd.zip" -DestinationPath (Split-Path -Path $Application) -Force Write-ServerMsg "SteamCMD Installed." } diff --git a/functions/Register-PID.psm1 b/functions/Register-PID.psm1 index bdc0c22..94be123 100644 --- a/functions/Register-PID.psm1 +++ b/functions/Register-PID.psm1 @@ -6,7 +6,7 @@ function Register-PID { $ServerProcess ) try { - New-Item -Path ".\servers\" -Name "$($Server.UID).PID" -ItemType "file" -Value "$($ServerProcess.ID)" -ErrorAction Continue + New-Item -Path ".\servers\" -Name "$($Server.UID).PID" -ItemType "file" -Value "$($ServerProcess.ID)" -Force -ErrorAction Continue } catch { return $false diff --git a/functions/Remove-OldLog.psm1 b/functions/Remove-OldLog.psm1 index cd1cd15..e61e476 100644 --- a/functions/Remove-OldLog.psm1 +++ b/functions/Remove-OldLog.psm1 @@ -1,6 +1,10 @@ function Remove-OldLog { + #define the number of days. $Limit = (Get-Date).AddDays(-$Global.Days) - Get-ChildItem -Path $Global.LogFolder -Recurse | Where-Object { -not ($_.PSIsContainer) -and $_.LastWriteTime -lt $Limit } | Remove-Item -Force -ErrorAction SilentlyContinue + #find and delete old files. + Get-ChildItem -Path $Global.LogFolder -Recurse | + Where-Object { -not ($_.PSIsContainer) -and $_.LastWriteTime -lt $Limit } | + Remove-Item -Force -ErrorAction SilentlyContinue } Export-ModuleMember -Function Remove-OldLog \ No newline at end of file diff --git a/functions/Send-Command.psm1 b/functions/Send-Command.psm1 index 5bd17c7..c595cf4 100644 --- a/functions/Send-Command.psm1 +++ b/functions/Send-Command.psm1 @@ -12,6 +12,7 @@ function Send-Command { #Select Protocol switch ($Warnings.Protocol) { "Rcon" { + #send Rcon command. $Result = Start-Process $Global.Mcrcon -ArgumentList "-c -H $($Server.ManagementIP) -P $($Server.ManagementPort) -p $($Server.ManagementPassword) `"$Command $Message`"" -Wait -PassThru -NoNewWindow if ($Result.ExitCode -eq 0) { $Success = $true @@ -19,6 +20,7 @@ function Send-Command { } "Telnet" { + #send Telnet command. $Result = Get-Telnet -Command "$Command `"$Message`"" -RemoteHost $Server.ManagementIP -Port $Server.ManagementPort -Password $Server.ManagementPassword Write-Host $Result if (-not(($Result -like "*Unable to connect to host:*") -or ($Result -like "*incorrect*"))) { @@ -27,7 +29,9 @@ function Send-Command { } "Websocket" { + #send Websocket command. Write-Warning "Protocol Not Implemented Yet" + #TODO } Default { diff --git a/functions/Send-RestartWarning.psm1 b/functions/Send-RestartWarning.psm1 index 08bd6c8..762fd66 100644 --- a/functions/Send-RestartWarning.psm1 +++ b/functions/Send-RestartWarning.psm1 @@ -7,20 +7,31 @@ function Send-RestartWarning { ) $Stopped = $false $Failed = $false + #Loop until the list of timers is empty while ($Warnings.Timers.Count -gt 0) { + #Select first timer in the list $Timer = $Warnings.Timers[0] + #Set variable $TimeLeft = 0 + #Add all timers to find total wait time. $Warnings.Timers | ForEach-Object { $TimeLeft += $_} + #Remove first timer from the list. $Warnings.Timers.RemoveAt(0) + #if the timer is shorter than 60 seconds show minutes if ($TimeLeft -lt 60) { + #select Seconds message. $Message = $Warnings.MessageSec $TimerText = [string]$TimeLeft } else { + #Calculate minutes and select minutes message. $Message = $Warnings.MessageMin $TimerText = [string][Math]::Round($TimeLeft / 60,[MidpointRounding]::AwayFromZero) } + #Insert time in messages. $Message = $Message -replace "%", $TimerText + #Send the message. $Success = Send-Command -Command $Warnings.CmdMessage -Message $Message + #If the command succeed, sleep until next command, else break. if ($Success) { Write-ServerMsg "Waiting $Timer seconds before next warning..." Start-Sleep -Seconds $Timer @@ -30,6 +41,7 @@ function Send-RestartWarning { break } } + #If warning messages commands succeeded, send save cmd and wait safety timer. if (-not ($Failed)) { if (-not ($null -eq $Warnings.CmdSave)){ Write-ServerMsg "Saving server." @@ -40,11 +52,13 @@ function Send-RestartWarning { Write-Warning "Unable to send save command." } } + #Send server stop command and wait for the process to exit for at most 60 seconds. Write-ServerMsg "Closing server." $Stopped = Send-Command -Command $Warnings.CmdStop $ServerProcess.WaitForExit(30000) Start-Sleep -Seconds 5 } + #if the process is still running, if allowed, stop process. if(-not ($ServerProcess.HasExited) -and ($Server.AllowForceClose)){ $Stopped = Stop-Server -ServerProcess $ServerProcess } diff --git a/functions/Set-Priority.psm1 b/functions/Set-Priority.psm1 index cab53d9..ed54910 100644 --- a/functions/Set-Priority.psm1 +++ b/functions/Set-Priority.psm1 @@ -6,10 +6,11 @@ function Set-Priority { $ServerProcess ) try { - # Set the priority and affinity + # Set the process priority if ($Server.UsePriority) { $ServerProcess.PriorityClass = $Server.AppPriority } + # Set the process affinity if ($Server.UseAffinity){ $ServerProcess.ProcessorAffinity = $Server.AppAffinity } diff --git a/functions/Stop-Server.psm1 b/functions/Stop-Server.psm1 index 06a7d25..11119d1 100644 --- a/functions/Stop-Server.psm1 +++ b/functions/Stop-Server.psm1 @@ -5,16 +5,23 @@ function Stop-Server { [Parameter(Mandatory)] $ServerProcess ) + #if the server is still running if(-not $Server.HasExited){ Write-ServerMsg "Closing main window..." + #Close the main windows. $ServerProcess.CloseMainWindow() + #Wait for exit for at most 30 seconds. $ServerProcess.WaitForExit(30000) + #if the process exited send success message if ($ServerProcess.HasExited) { Write-ServerMsg "Server succesfully stopped." }else{ Write-Warning "Trying again to stop the server..." + #else try to stop server with stop-process. Stop-Process $ServerProcess + #Wait for exit for at most 30 seconds. $ServerProcess.WaitForExit(30000) + #If process is still running, force stop-process. if ($ServerProcess.HasExited) { Write-Warning "Server succesfully stopped on second try." }else{ @@ -23,6 +30,7 @@ function Stop-Server { } } } + #Safety timer for allowing the files to unlock before backup. Start-Sleep -Seconds 10 if ($ServerProcess.HasExited) { return $true diff --git a/functions/Unregister-PID.psm1 b/functions/Unregister-PID.psm1 index a04c62d..8b85d6a 100644 --- a/functions/Unregister-PID.psm1 +++ b/functions/Unregister-PID.psm1 @@ -4,6 +4,7 @@ function Unregister-PID { param ( ) try { + #Delete the PID file based on the Server UID. Remove-Item -Path ".\servers\$($Server.UID).PID" -Confirm:$false -ErrorAction Continue } catch { diff --git a/functions/Update-Server.psm1 b/functions/Update-Server.psm1 index 4c82a97..1b138b9 100644 --- a/functions/Update-Server.psm1 +++ b/functions/Update-Server.psm1 @@ -4,11 +4,13 @@ function Update-Server { [Parameter(Mandatory)] [string]$UpdateType ) - + #Create server directory if not found. if (-not(Test-Path -Path $Server.Path)){ New-Item -ItemType "directory" -Path $Server.Path -ErrorAction SilentlyContinue } + #Resolve complete path of the server folder. $Server.Path = Resolve-Path -Path $Server.Path + #Run steam the correct steam command based on context. if($Server.Beta){ Write-ServerMsg "$UpdateType Beta Build." try { @@ -32,6 +34,7 @@ function Update-Server { Exit-WithError -ErrorMsg "SteamCMD failed to complete." } } + #Update Server.Exec value with the full path. $Server.Exec = Resolve-Path -Path $Server.Exec } Export-ModuleMember -Function Update-Server \ No newline at end of file diff --git a/functions/Write-ScriptMsg.psm1 b/functions/Write-ScriptMsg.psm1 index d6eb034..6faf699 100644 --- a/functions/Write-ScriptMsg.psm1 +++ b/functions/Write-ScriptMsg.psm1 @@ -4,7 +4,8 @@ function Write-ScriptMsg { [Parameter(Mandatory)] [string]$Message ) - Write-Host -ForegroundColor $Global.SectionColor -BackgroundColor $Global.BgColor -Object $Message + #Write script message with the colors defined in global.cfg + Write-Host -ForegroundColor $Global.SectionColor -BackgroundColor $Global.SectionBgColor -Object $Message } Export-ModuleMember -Function Write-ScriptMsg \ No newline at end of file diff --git a/functions/Write-ServerMsg.psm1 b/functions/Write-ServerMsg.psm1 index fba0ba7..806266f 100644 --- a/functions/Write-ServerMsg.psm1 +++ b/functions/Write-ServerMsg.psm1 @@ -4,6 +4,7 @@ function Write-ServerMsg { [Parameter(Mandatory)] [string]$Message ) + #Write server message with the colors defined in global.cfg Write-Host -ForegroundColor $Global.FGColor -BackgroundColor $Global.BgColor -Object $Message } diff --git a/main.ps1 b/main.ps1 index 049e511..b62069c 100644 --- a/main.ps1 +++ b/main.ps1 @@ -12,6 +12,7 @@ param ( # Importing functions and variables. #--------------------------------------------------------- +#Check if requested config exist in the config folder, if not, copy it from the templates. Exit if fails. if (-not (Test-Path -Path ".\configs\$ServerCfg.psm1" -PathType "Leaf")) { if (Test-Path -Path ".\templates\$ServerCfg.psm1" -PathType "Leaf"){ Copy-Item -Path ".\templates\$ServerCfg.psm1" -Destination ".\configs\$ServerCfg.psm1" -ErrorAction SilentlyContinue @@ -20,6 +21,7 @@ if (-not (Test-Path -Path ".\configs\$ServerCfg.psm1" -PathType "Leaf")) { } } +# import global config, all functions and the current server config file. Exit if fails. try { Import-Module -Name ".\configs\global.psm1" Get-ChildItem -Path ".\functions" -Include "*.psm1" -Recurse | Import-Module @@ -34,7 +36,8 @@ catch { # Start Logging #--------------------------------------------------------- -$LogFile = "$(Get-TimeStamp).txt" +#Define Logfile by TimeStamp-ServerCfg. +$LogFile = "$(Get-TimeStamp)-$($ServerCfg).txt" # Start Logging Start-Transcript -Path "$($Global.LogFolder)\$LogFile" -IncludeInvocationHeader @@ -42,6 +45,7 @@ Start-Transcript -Path "$($Global.LogFolder)\$LogFile" -IncludeInvocationHeader # Set Script Directory as Working Directory #--------------------------------------------------------- +#Find the location of the current invocation of main.ps1, remove the filename, set the working directory to that path. Write-ScriptMsg "Setting Script Directory as Working Directory..." $scriptpath = $MyInvocation.MyCommand.Path $dir = Split-Path -Path $scriptpath @@ -53,6 +57,7 @@ Write-ScriptMsg "Working Directory : $(Get-Location)" # Get server IPs #--------------------------------------------------------- +#Get current internal ip from active network interface. Write-ScriptMsg "Finding server IPs..." $InternalIP = ( Get-NetIPConfiguration | @@ -62,11 +67,13 @@ $InternalIP = ( } ).IPv4Address.IPAddress +#Get current external ip from ifconfig.me $ExternalIP = (Invoke-WebRequest ifconfig.me/ip).Content.Trim() Write-ScriptMsg "Server local IP : $InternalIP" Write-ScriptMsg "Server external IP : $ExternalIP" +#Add propreties to global. Add-Member -InputObject $Global -Name "InternalIP" -Type NoteProperty -Value $InternalIP Add-Member -InputObject $Global -Name "ExternalIP" -Type NoteProperty -Value $ExternalIP @@ -74,6 +81,7 @@ Add-Member -InputObject $Global -Name "ExternalIP" -Type NoteProperty -Value $Ex # Install Dependencies #--------------------------------------------------------- +#Define variables Write-ScriptMsg "Verifying Dependencies..." $Dependencies = @{ SevenZip = $Global.SevenZip @@ -83,12 +91,14 @@ $Dependencies = @{ [System.Collections.ArrayList]$MissingDependencies = @() +#For each dependency check if the excutable exist, if not, add the key of the dependency to the MissingDependencies list. foreach ($Key in $Dependencies.keys) { if (-not(Test-Path -Path $Dependencies[$Key])) { $null = $MissingDependencies.Add($Key) } } +#If there is missing dependencies, create the download folder and for each missing dependency, run the installation script. if ($MissingDependencies.Count -gt 0){ #Create Temporary Download Folder New-Item -Path ".\downloads" -ItemType "directory" -ErrorAction SilentlyContinue @@ -107,7 +117,9 @@ if ($MissingDependencies.Count -gt 0){ #--------------------------------------------------------- Write-ScriptMsg "Verifying Server installation..." +#Flag of a fresh installation in the current instance. [boolean]$FreshInstall = $false +#If the server executable is missing, run SteamCMD and install the server. if (-not(Test-Path -Path $Server.Exec)){ Write-ServerMsg "Server is not installed : Installing $($Server.Name) Server." Update-Server -UpdateType "Installing" @@ -118,13 +130,20 @@ if (-not(Test-Path -Path $Server.Exec)){ #--------------------------------------------------------- # If Server is running warn players then stop server #--------------------------------------------------------- + +#If the server is not freshly installed. if (-not ($FreshInstall)) { + #Get the PID from the .PID market file. $ServerPID = Get-PID - if ($ServerPID -eq 0) { - $ServerProcess = Get-Process -Name $Server.ProcessName -ErrorAction Continue - } else { + #If it returned 0, it failed to get a PID + if ($ServerPID -ne 0) { $ServerProcess = Get-Process -ID $ServerPID -ErrorAction Continue } + #If the server process is none-existent, Get the process from the server process name. + if (-not $ServerProcess) { + $ServerProcess = Get-Process -Name $Server.ProcessName -ErrorAction Continue + } + #Check if the process was found. Write-ScriptMsg "Verifying Server State..." if (-not ($ServerProcess) -or $ServerProcess.HasExited) { Write-ServerMsg "Server is not running." @@ -152,11 +171,9 @@ if (-not ($FreshInstall)) { } } + #If the server stopped, send messages, if not check if it's normal, then stopped it, if it fails, exit with error. if ($Stopped) { Write-ServerMsg "Server stopped." - if (-not $(Unregister-PID)) { - Write-ServerMsg "Failed to remove PID file." - } } else { if ($Server.AllowForceClose) { Exit-WithError "Failed to stop server." @@ -165,12 +182,17 @@ if (-not ($FreshInstall)) { } } } + #Unregister the PID + if (-not $(Unregister-PID)) { + Write-ServerMsg "Failed to remove PID file." + } } #--------------------------------------------------------- # Backup #--------------------------------------------------------- +#If not a fresh install and Backups are enabled, run backups. if ($Backups.Use -and -not ($FreshInstall)) { Write-ScriptMsg "Verifying Backups..." Backup-Server @@ -180,6 +202,7 @@ if ($Backups.Use -and -not ($FreshInstall)) { # Update #--------------------------------------------------------- +#If not a fresh install, update and/or validate server. if (-not ($FreshInstall)) { Write-ScriptMsg "Updating Server..." Update-Server -UpdateType "Updating / Validating" @@ -190,6 +213,7 @@ if (-not ($FreshInstall)) { # Start Server #--------------------------------------------------------- +#Try to start the server, then if it's stable, set the priority and affinity then register the PID. Exit with Error if it fails. try { Write-ScriptMsg "Starting Server..." $App = Start-Server @@ -214,6 +238,7 @@ catch { # Cleanup #--------------------------------------------------------- +#Remove old log files. try { Write-ScriptMsg "Deleting logs older than $($Global.Days) days." Remove-OldLog From 9e7d05f00bca2c37f56f1c9325c828bf0afd661d Mon Sep 17 00:00:00 2001 From: Patrick Veilleux Date: Thu, 16 Sep 2021 22:50:08 -0400 Subject: [PATCH 6/9] add Killing Floor 2 --- launchers/run.cmd | 2 +- templates/killingfloor2.psm1 | 219 +++++++++++++++++++++++++++++++++++ 2 files changed, 220 insertions(+), 1 deletion(-) create mode 100644 templates/killingfloor2.psm1 diff --git a/launchers/run.cmd b/launchers/run.cmd index 0904e89..6653623 100644 --- a/launchers/run.cmd +++ b/launchers/run.cmd @@ -1,2 +1,2 @@ cd .. -start powershell.exe -noprofile -executionpolicy bypass -file ".\main.ps1" -ServerCfg "valheim" \ No newline at end of file +start powershell.exe -noprofile -executionpolicy bypass -file ".\main.ps1" -ServerCfg "killingfloor2" \ No newline at end of file diff --git a/templates/killingfloor2.psm1 b/templates/killingfloor2.psm1 new file mode 100644 index 0000000..bf4a97c --- /dev/null +++ b/templates/killingfloor2.psm1 @@ -0,0 +1,219 @@ + +<# +Edit configuration in ./Servers/KillingFloor2/KFGame/Config/KF[UID].INI +bEnabled=true to enable webadmin +#> + +#Server Name, use the same name to share game files. +$Name = "KillingFloor2" + +#--------------------------------------------------------- +# Server Configuration +#--------------------------------------------------------- + +$ServerDetails = @{ + + #Unique Identifier used to track processes. Must be unique to each servers. + UID = 6 + + #This is the admin username for WebAdmin if you're configuring WebAdmin via Commandline + AdminName = "admin" + + #This is the master server administrator password + AdminPassword = "CHANGEME" + + #This is how many maximum players the server is set to support + MaxPlayers = 6 + + #This sets the server difficulty. 0 = Normal, 1 = Hard, 2 = Suicidal, 3 = Hell on Earth + Difficulty = 0 + + #This is the game port. + Port = 7777 + + #This is the query port. + QueryPort = 27015 + + #This is the web admin port. Changing this will change the port used to connect to the servers webadmin panel if that functionality is turned on. + WebAdminPort = 8080 + + #Starting map name. + Map = "kf-bioticslab" + + #Game mode EG : KFGameContent.KFGameInfo_WeeklySurvival, KFGameContent.KFGameInfo_VersusSurvival, KFGameContent.KFGameInfo_Endless + GameMode = "KFGameContent.KFGameInfo_WeeklySurvival" + + #Rcon IP (not supported by KF2.) + ManagementIP = "127.0.0.1" + + #Rcon Port + ManagementPort = "" + + #Rcon Password + ManagementPassword = "" + +#--------------------------------------------------------- +# Server Installation Details +#--------------------------------------------------------- + + #Name of the Server Instance + Name = $Name + + #Server Installation Path + Path = ".\servers\$Name" + + #Steam Server App Id + AppID = 232130 + + #Use Beta builds $true or $false + Beta = $false + + #Name of the Beta Build + BetaBuild = "" + + #Beta Build Password + BetaBuildPassword = "" + + #Process name in the task manager + ProcessName = "KFServer" + + #ProjectZomboid64.exe + Exec = ".\servers\$Name\Binaries\Win64\KFServer.exe" + + #Allow force close, usefull for server without RCON and Multiple instances. + AllowForceClose = $true + + #Process Priority Realtime, High, Above normal, Normal, Below normal, Low + UsePriority = $true + AppPriority = "High" + + <# + Process Affinity (Core Assignation) + Core 1 = > 00000001 = > 1 + Core 2 = > 00000010 = > 2 + Core 3 = > 00000100 = > 4 + Core 4 = > 00001000 = > 8 + Core 5 = > 00010000 = > 16 + Core 6 = > 00100000 = > 32 + Core 7 = > 01000000 = > 64 + Core 8 = > 10000000 = > 128 + ---------------------------- + 8 Cores = > 11111111 = > 255 + 4 Cores = > 00001111 = > 15 + 2 Cores = > 00000011 = > 3 + #> + + UseAffinity = $false + AppAffinity = 15 + + #Should the server validate install after installation or update *(recommended) + Validate = $true +} +#Create the object +$Server = New-Object -TypeName PsObject -Property $ServerDetails + +#--------------------------------------------------------- +# Backups +#--------------------------------------------------------- + +$BackupsDetails = @{ + #Do Backups + Use = $true + + #Backup Folder + Path = ".\backups\$($Server.Name)" + + #Number of days of backups to keep. + Days = 7 + + #Number of weeks of weekly backups to keep. + Weeks = 4 + + #Folder to include in backup + Saves = ".\servers\$Name\KFGame\Config\" +} +#Create the object +$Backups = New-Object -TypeName PsObject -Property $BackupsDetails + +#--------------------------------------------------------- +# Restart Warnings (Require RCON, Telnet or WebSocket API) +#--------------------------------------------------------- + +$WarningsDetails = @{ + #Use Rcon to restart server softly. + Use = $false + + #What protocol to use : Rcon, Telnet, Websocket + Protocol = "Rcon" + + #Times at which the servers will warn the players that it is about to restart. (in seconds between each timers) + Timers = [System.Collections.ArrayList]@(240,50,10) #Total wait time is 240+50+10 = 300 seconds or 5 minutes + + #message that will be sent. % is a wildcard for the timer. + MessageMin = "The server will restart in % minutes !" + + #message that will be sent. % is a wildcard for the timer. + MessageSec = "The server will restart in % seconds !" + + #command to send a message. + CmdMessage = "say" + + #command to save the server + CmdSave = "saveworld" + + #How long to wait in seconds after the save command is sent. + SaveDelay = 15 + + #command to stop the server + CmdStop = "shutdown" +} +#Create the object +$Warnings = New-Object -TypeName PsObject -Property $WarningsDetails + +#--------------------------------------------------------- +# Launch Arguments +#--------------------------------------------------------- + +#Launch Arguments +$Arguments = @( + "Server ", + "$($Server.Map)", + "?Game=$($Server.GameMode)", + "?MaxPlayers=$($Server.MaxPlayers)", + "?Difficulty=$($Server.Difficulty) ", + "-Port=$($Server.Port) ", + "-QueryPort=$($Server.QueryPort) ", + "-WebAdminPort=$($Server.WebAdminPort) ", + "-Multihome=$($Global.InternalIP) ", + "-ConfigSubDir=KF$($Server.UID)" +) + +[System.Collections.ArrayList]$CleanedArguments=@() + +foreach($Argument in $Arguments){ + if (!($Argument.EndsWith('=""') -or $Argument.EndsWith('=') -or $Argument.EndsWith(' '))){ + $CleanedArguments.Add($Argument) + } +} + +$ArgumentList = $CleanedArguments -join "" + +#Server Launcher +$Launcher = $Server.Exec + +#--------------------------------------------------------- +# Launch Function +#--------------------------------------------------------- + +function Start-Server { + + Write-ScriptMsg "Port Forward : $($server.Port), $($server.QueryPort), 20560, 123 in UDP and $($server.WebAdminPort) in TCP to $($Global.InternalIP)" + Write-ScriptMsg "Once Webadmin enabled, go to http://$($Global.InternalIP):$($server.WebAdminPort) to administer this server." + + #Start Server + $App = Start-Process -FilePath $Launcher -WorkingDirectory $Server.Path -ArgumentList $ArgumentList -PassThru + + return $App +} + +Export-ModuleMember -Function Start-Server -Variable @("Server","Backups","Warnings") \ No newline at end of file From cfff6381dbdf92b0de62dfebc34e189a52077e10 Mon Sep 17 00:00:00 2001 From: Patrick Veilleux Date: Thu, 16 Sep 2021 23:11:05 -0400 Subject: [PATCH 7/9] change load order --- configs/killingfloor2.psm1 | 218 +++++++++++++++++++++++++++++++++++ main.ps1 | 38 +++--- templates/killingfloor2.psm1 | 5 +- templates/rust.psm1 | 218 +++++++++++++++++++++++++++++++++++ 4 files changed, 463 insertions(+), 16 deletions(-) create mode 100644 configs/killingfloor2.psm1 create mode 100644 templates/rust.psm1 diff --git a/configs/killingfloor2.psm1 b/configs/killingfloor2.psm1 new file mode 100644 index 0000000..6cf71a6 --- /dev/null +++ b/configs/killingfloor2.psm1 @@ -0,0 +1,218 @@ + +<# +Edit configuration in ./Servers/KillingFloor2/KFGame/Config/KF[UID].INI +bEnabled=true to enable webadmin +#> + +#Server Name, use the same name to share game files. +$Name = "KillingFloor2" + +#--------------------------------------------------------- +# Server Configuration +#--------------------------------------------------------- + +$ServerDetails = @{ + + #Unique Identifier used to track processes. Must be unique to each servers. + UID = 6 + + #This is the admin username for WebAdmin if you're configuring WebAdmin via Commandline + AdminName = "admin" + + #This is the master server administrator password + AdminPassword = "CHANGEME" + + #This is how many maximum players the server is set to support + MaxPlayers = 6 + + #This sets the server difficulty. 0 = Normal, 1 = Hard, 2 = Suicidal, 3 = Hell on Earth + Difficulty = 0 + + #This is the game port. + Port = 7777 + + #This is the query port. + QueryPort = 27015 + + #This is the web admin port. Changing this will change the port used to connect to the servers webadmin panel if that functionality is turned on. + WebAdminPort = 8080 + + #Starting map name. + Map = "KF-BIOTICSLAB" + + #Game mode EG : KFGameContent.KFGameInfo_WeeklySurvival, KFGameContent.KFGameInfo_VersusSurvival, KFGameContent.KFGameInfo_Endless + GameMode = "KFGameContent.KFGameInfo_WeeklySurvival" + + #Rcon IP (not supported by KF2.) + ManagementIP = "127.0.0.1" + + #Rcon Port + ManagementPort = "" + + #Rcon Password + ManagementPassword = "" + +#--------------------------------------------------------- +# Server Installation Details +#--------------------------------------------------------- + + #Name of the Server Instance + Name = $Name + + #Server Installation Path + Path = ".\servers\$Name" + + #Steam Server App Id + AppID = 232130 + + #Use Beta builds $true or $false + Beta = $false + + #Name of the Beta Build + BetaBuild = "" + + #Beta Build Password + BetaBuildPassword = "" + + #Process name in the task manager + ProcessName = "KFServer" + + #ProjectZomboid64.exe + Exec = ".\servers\$Name\Binaries\Win64\KFServer.exe" + + #Allow force close, usefull for server without RCON and Multiple instances. + AllowForceClose = $true + + #Process Priority Realtime, High, Above normal, Normal, Below normal, Low + UsePriority = $true + AppPriority = "High" + + <# + Process Affinity (Core Assignation) + Core 1 = > 00000001 = > 1 + Core 2 = > 00000010 = > 2 + Core 3 = > 00000100 = > 4 + Core 4 = > 00001000 = > 8 + Core 5 = > 00010000 = > 16 + Core 6 = > 00100000 = > 32 + Core 7 = > 01000000 = > 64 + Core 8 = > 10000000 = > 128 + ---------------------------- + 8 Cores = > 11111111 = > 255 + 4 Cores = > 00001111 = > 15 + 2 Cores = > 00000011 = > 3 + #> + + UseAffinity = $false + AppAffinity = 15 + + #Should the server validate install after installation or update *(recommended) + Validate = $false +} +#Create the object +$Server = New-Object -TypeName PsObject -Property $ServerDetails + +#--------------------------------------------------------- +# Backups +#--------------------------------------------------------- + +$BackupsDetails = @{ + #Do Backups + Use = $true + + #Backup Folder + Path = ".\backups\$($Server.Name)" + + #Number of days of backups to keep. + Days = 7 + + #Number of weeks of weekly backups to keep. + Weeks = 4 + + #Folder to include in backup + Saves = ".\servers\$Name\KFGame\Config\" +} +#Create the object +$Backups = New-Object -TypeName PsObject -Property $BackupsDetails + +#--------------------------------------------------------- +# Restart Warnings (Require RCON, Telnet or WebSocket API) +#--------------------------------------------------------- + +$WarningsDetails = @{ + #Use Rcon to restart server softly. + Use = $false + + #What protocol to use : Rcon, Telnet, Websocket + Protocol = "Rcon" + + #Times at which the servers will warn the players that it is about to restart. (in seconds between each timers) + Timers = [System.Collections.ArrayList]@(240,50,10) #Total wait time is 240+50+10 = 300 seconds or 5 minutes + + #message that will be sent. % is a wildcard for the timer. + MessageMin = "The server will restart in % minutes !" + + #message that will be sent. % is a wildcard for the timer. + MessageSec = "The server will restart in % seconds !" + + #command to send a message. + CmdMessage = "say" + + #command to save the server + CmdSave = "saveworld" + + #How long to wait in seconds after the save command is sent. + SaveDelay = 15 + + #command to stop the server + CmdStop = "shutdown" +} +#Create the object +$Warnings = New-Object -TypeName PsObject -Property $WarningsDetails + +#--------------------------------------------------------- +# Launch Arguments +#--------------------------------------------------------- + +#Launch Arguments +$Arguments = @( + "$($Server.Map)", + "?Game=$($Server.GameMode)", + "?MaxPlayers=$($Server.MaxPlayers)", + "?Difficulty=$($Server.Difficulty) ", + "-Port=$($Server.Port) ", + "-QueryPort=$($Server.QueryPort) ", + "-WebAdminPort=$($Server.WebAdminPort) ", + "-Multihome=$($Global.InternalIP) ", + "-ConfigSubDir=KF$($Server.UID)" +) + +[System.Collections.ArrayList]$CleanedArguments=@() + +foreach($Argument in $Arguments){ + if (!($Argument.EndsWith('=""') -or $Argument.EndsWith('=') -or $Argument.EndsWith(' '))){ + $CleanedArguments.Add($Argument) + } +} + +$ArgumentList = $CleanedArguments -join "" + +#Server Launcher +$Launcher = $Server.Exec + +#--------------------------------------------------------- +# Launch Function +#--------------------------------------------------------- + +function Start-Server { + + Write-ScriptMsg "Port Forward : $($server.Port), $($server.QueryPort), 20560, 123 in UDP and $($server.WebAdminPort) in TCP to $($Global.InternalIP)" + Write-ScriptMsg "Once Webadmin enabled, go to http://$($Global.InternalIP):$($server.WebAdminPort) to administer this server." + + #Start Server + $App = Start-Process -FilePath $Launcher -WorkingDirectory $Server.Path -ArgumentList $ArgumentList -PassThru + + return $App +} + +Export-ModuleMember -Function Start-Server -Variable @("Server","Backups","Warnings") \ No newline at end of file diff --git a/main.ps1 b/main.ps1 index b62069c..59bedb1 100644 --- a/main.ps1 +++ b/main.ps1 @@ -12,20 +12,10 @@ param ( # Importing functions and variables. #--------------------------------------------------------- -#Check if requested config exist in the config folder, if not, copy it from the templates. Exit if fails. -if (-not (Test-Path -Path ".\configs\$ServerCfg.psm1" -PathType "Leaf")) { - if (Test-Path -Path ".\templates\$ServerCfg.psm1" -PathType "Leaf"){ - Copy-Item -Path ".\templates\$ServerCfg.psm1" -Destination ".\configs\$ServerCfg.psm1" -ErrorAction SilentlyContinue - } else { - Exit-WithError -ErrorMsg "Unable to find configuration file." - } -} - -# import global config, all functions and the current server config file. Exit if fails. +# import global config, all functions. Exit if fails. try { Import-Module -Name ".\configs\global.psm1" Get-ChildItem -Path ".\functions" -Include "*.psm1" -Recurse | Import-Module - Import-Module -Name ".\configs\$ServerCfg.psm1" } catch { Exit-WithError -ErrorMsg "Unable to import modules." @@ -112,6 +102,29 @@ if ($MissingDependencies.Count -gt 0){ Remove-Item -Path ".\downloads" -Recurse -Force -ErrorAction SilentlyContinue } +#--------------------------------------------------------- +# Importing server configuration. +#--------------------------------------------------------- + +Write-ScriptMsg "Importing Server Configuration..." +#Check if requested config exist in the config folder, if not, copy it from the templates. Exit if fails. +if (-not (Test-Path -Path ".\configs\$ServerCfg.psm1" -PathType "Leaf")) { + if (Test-Path -Path ".\templates\$ServerCfg.psm1" -PathType "Leaf"){ + Copy-Item -Path ".\templates\$ServerCfg.psm1" -Destination ".\configs\$ServerCfg.psm1" -ErrorAction SilentlyContinue + } else { + Exit-WithError -ErrorMsg "Unable to find configuration file." + } +} + +# import the current server config file. Exit if fails. +try { + Import-Module -Name ".\configs\$ServerCfg.psm1" +} +catch { + Exit-WithError -ErrorMsg "Unable to server configuration." + exit +} + #--------------------------------------------------------- # Install Server #--------------------------------------------------------- @@ -130,7 +143,7 @@ if (-not(Test-Path -Path $Server.Exec)){ #--------------------------------------------------------- # If Server is running warn players then stop server #--------------------------------------------------------- - +Write-ScriptMsg "Verifying Server State..." #If the server is not freshly installed. if (-not ($FreshInstall)) { #Get the PID from the .PID market file. @@ -144,7 +157,6 @@ if (-not ($FreshInstall)) { $ServerProcess = Get-Process -Name $Server.ProcessName -ErrorAction Continue } #Check if the process was found. - Write-ScriptMsg "Verifying Server State..." if (-not ($ServerProcess) -or $ServerProcess.HasExited) { Write-ServerMsg "Server is not running." } else { diff --git a/templates/killingfloor2.psm1 b/templates/killingfloor2.psm1 index bf4a97c..6cf71a6 100644 --- a/templates/killingfloor2.psm1 +++ b/templates/killingfloor2.psm1 @@ -38,7 +38,7 @@ $ServerDetails = @{ WebAdminPort = 8080 #Starting map name. - Map = "kf-bioticslab" + Map = "KF-BIOTICSLAB" #Game mode EG : KFGameContent.KFGameInfo_WeeklySurvival, KFGameContent.KFGameInfo_VersusSurvival, KFGameContent.KFGameInfo_Endless GameMode = "KFGameContent.KFGameInfo_WeeklySurvival" @@ -107,7 +107,7 @@ $ServerDetails = @{ AppAffinity = 15 #Should the server validate install after installation or update *(recommended) - Validate = $true + Validate = $false } #Create the object $Server = New-Object -TypeName PsObject -Property $ServerDetails @@ -176,7 +176,6 @@ $Warnings = New-Object -TypeName PsObject -Property $WarningsDetails #Launch Arguments $Arguments = @( - "Server ", "$($Server.Map)", "?Game=$($Server.GameMode)", "?MaxPlayers=$($Server.MaxPlayers)", diff --git a/templates/rust.psm1 b/templates/rust.psm1 new file mode 100644 index 0000000..6cf71a6 --- /dev/null +++ b/templates/rust.psm1 @@ -0,0 +1,218 @@ + +<# +Edit configuration in ./Servers/KillingFloor2/KFGame/Config/KF[UID].INI +bEnabled=true to enable webadmin +#> + +#Server Name, use the same name to share game files. +$Name = "KillingFloor2" + +#--------------------------------------------------------- +# Server Configuration +#--------------------------------------------------------- + +$ServerDetails = @{ + + #Unique Identifier used to track processes. Must be unique to each servers. + UID = 6 + + #This is the admin username for WebAdmin if you're configuring WebAdmin via Commandline + AdminName = "admin" + + #This is the master server administrator password + AdminPassword = "CHANGEME" + + #This is how many maximum players the server is set to support + MaxPlayers = 6 + + #This sets the server difficulty. 0 = Normal, 1 = Hard, 2 = Suicidal, 3 = Hell on Earth + Difficulty = 0 + + #This is the game port. + Port = 7777 + + #This is the query port. + QueryPort = 27015 + + #This is the web admin port. Changing this will change the port used to connect to the servers webadmin panel if that functionality is turned on. + WebAdminPort = 8080 + + #Starting map name. + Map = "KF-BIOTICSLAB" + + #Game mode EG : KFGameContent.KFGameInfo_WeeklySurvival, KFGameContent.KFGameInfo_VersusSurvival, KFGameContent.KFGameInfo_Endless + GameMode = "KFGameContent.KFGameInfo_WeeklySurvival" + + #Rcon IP (not supported by KF2.) + ManagementIP = "127.0.0.1" + + #Rcon Port + ManagementPort = "" + + #Rcon Password + ManagementPassword = "" + +#--------------------------------------------------------- +# Server Installation Details +#--------------------------------------------------------- + + #Name of the Server Instance + Name = $Name + + #Server Installation Path + Path = ".\servers\$Name" + + #Steam Server App Id + AppID = 232130 + + #Use Beta builds $true or $false + Beta = $false + + #Name of the Beta Build + BetaBuild = "" + + #Beta Build Password + BetaBuildPassword = "" + + #Process name in the task manager + ProcessName = "KFServer" + + #ProjectZomboid64.exe + Exec = ".\servers\$Name\Binaries\Win64\KFServer.exe" + + #Allow force close, usefull for server without RCON and Multiple instances. + AllowForceClose = $true + + #Process Priority Realtime, High, Above normal, Normal, Below normal, Low + UsePriority = $true + AppPriority = "High" + + <# + Process Affinity (Core Assignation) + Core 1 = > 00000001 = > 1 + Core 2 = > 00000010 = > 2 + Core 3 = > 00000100 = > 4 + Core 4 = > 00001000 = > 8 + Core 5 = > 00010000 = > 16 + Core 6 = > 00100000 = > 32 + Core 7 = > 01000000 = > 64 + Core 8 = > 10000000 = > 128 + ---------------------------- + 8 Cores = > 11111111 = > 255 + 4 Cores = > 00001111 = > 15 + 2 Cores = > 00000011 = > 3 + #> + + UseAffinity = $false + AppAffinity = 15 + + #Should the server validate install after installation or update *(recommended) + Validate = $false +} +#Create the object +$Server = New-Object -TypeName PsObject -Property $ServerDetails + +#--------------------------------------------------------- +# Backups +#--------------------------------------------------------- + +$BackupsDetails = @{ + #Do Backups + Use = $true + + #Backup Folder + Path = ".\backups\$($Server.Name)" + + #Number of days of backups to keep. + Days = 7 + + #Number of weeks of weekly backups to keep. + Weeks = 4 + + #Folder to include in backup + Saves = ".\servers\$Name\KFGame\Config\" +} +#Create the object +$Backups = New-Object -TypeName PsObject -Property $BackupsDetails + +#--------------------------------------------------------- +# Restart Warnings (Require RCON, Telnet or WebSocket API) +#--------------------------------------------------------- + +$WarningsDetails = @{ + #Use Rcon to restart server softly. + Use = $false + + #What protocol to use : Rcon, Telnet, Websocket + Protocol = "Rcon" + + #Times at which the servers will warn the players that it is about to restart. (in seconds between each timers) + Timers = [System.Collections.ArrayList]@(240,50,10) #Total wait time is 240+50+10 = 300 seconds or 5 minutes + + #message that will be sent. % is a wildcard for the timer. + MessageMin = "The server will restart in % minutes !" + + #message that will be sent. % is a wildcard for the timer. + MessageSec = "The server will restart in % seconds !" + + #command to send a message. + CmdMessage = "say" + + #command to save the server + CmdSave = "saveworld" + + #How long to wait in seconds after the save command is sent. + SaveDelay = 15 + + #command to stop the server + CmdStop = "shutdown" +} +#Create the object +$Warnings = New-Object -TypeName PsObject -Property $WarningsDetails + +#--------------------------------------------------------- +# Launch Arguments +#--------------------------------------------------------- + +#Launch Arguments +$Arguments = @( + "$($Server.Map)", + "?Game=$($Server.GameMode)", + "?MaxPlayers=$($Server.MaxPlayers)", + "?Difficulty=$($Server.Difficulty) ", + "-Port=$($Server.Port) ", + "-QueryPort=$($Server.QueryPort) ", + "-WebAdminPort=$($Server.WebAdminPort) ", + "-Multihome=$($Global.InternalIP) ", + "-ConfigSubDir=KF$($Server.UID)" +) + +[System.Collections.ArrayList]$CleanedArguments=@() + +foreach($Argument in $Arguments){ + if (!($Argument.EndsWith('=""') -or $Argument.EndsWith('=') -or $Argument.EndsWith(' '))){ + $CleanedArguments.Add($Argument) + } +} + +$ArgumentList = $CleanedArguments -join "" + +#Server Launcher +$Launcher = $Server.Exec + +#--------------------------------------------------------- +# Launch Function +#--------------------------------------------------------- + +function Start-Server { + + Write-ScriptMsg "Port Forward : $($server.Port), $($server.QueryPort), 20560, 123 in UDP and $($server.WebAdminPort) in TCP to $($Global.InternalIP)" + Write-ScriptMsg "Once Webadmin enabled, go to http://$($Global.InternalIP):$($server.WebAdminPort) to administer this server." + + #Start Server + $App = Start-Process -FilePath $Launcher -WorkingDirectory $Server.Path -ArgumentList $ArgumentList -PassThru + + return $App +} + +Export-ModuleMember -Function Start-Server -Variable @("Server","Backups","Warnings") \ No newline at end of file From 32dac85257045e28cfd47320063e4676b4643a45 Mon Sep 17 00:00:00 2001 From: Patrick Veilleux Date: Fri, 17 Sep 2021 01:18:49 -0400 Subject: [PATCH 8/9] add rust WIP --- configs/7daystodie.psm1 | 200 ------------------------ configs/insurgencysandstorm.psm1 | 250 ------------------------------ configs/killingfloor2.psm1 | 218 -------------------------- configs/pixark.psm1 | 258 ------------------------------- configs/projectzomboid.psm1 | 226 --------------------------- configs/valheim.psm1 | 195 ----------------------- launchers/run.cmd | 2 +- templates/rust.psm1 | 102 ++++++------ 8 files changed, 58 insertions(+), 1393 deletions(-) delete mode 100644 configs/7daystodie.psm1 delete mode 100644 configs/insurgencysandstorm.psm1 delete mode 100644 configs/killingfloor2.psm1 delete mode 100644 configs/pixark.psm1 delete mode 100644 configs/projectzomboid.psm1 delete mode 100644 configs/valheim.psm1 diff --git a/configs/7daystodie.psm1 b/configs/7daystodie.psm1 deleted file mode 100644 index 1e6cc92..0000000 --- a/configs/7daystodie.psm1 +++ /dev/null @@ -1,200 +0,0 @@ -<# -#Change your servers settings in C:\Users\%username%\AppData\Roaming\7DaysToDie\Saves\serverconfig.xml -#> - -#Server Name, use the same name to share game files. -$Name = "7DaysToDie" - - -#--------------------------------------------------------- -# Server Configuration -#--------------------------------------------------------- - -$ServerDetails = @{ - - #Unique Identifier used to track processes. Must be unique to each servers. - UID = 7 - - #Server Configuration - ConfigFile = "$Env:userprofile\AppData\Roaming\7DaysToDie\Saves\serverconfig.xml" - - #Rcon IP, usually localhost - ManagementIP = "127.0.0.1" - - #Rcon Port in serverconfig.xml - ManagementPort = 8081 - - #Rcon Password as set in serverconfig.xml nothing is localhost only. - ManagementPassword = "" - - #Server Log File - LogFile = "$Env:userprofile\AppData\Roaming\7DaysToDie\Logs\$(Get-TimeStamp).txt" - -#--------------------------------------------------------- -# Server Installation Details -#--------------------------------------------------------- - - #Name of the Server Instance - Name = $Name - - #Server Installation Path - Path = ".\servers\$Name" - - #Steam Server App Id - AppID = 294420 - - #Use Beta builds $true or $false - Beta = $false - - #Name of the Beta Build - BetaBuild = "" - - #Beta Build Password - BetaBuildPassword = "" - - #Process name in the task manager - ProcessName = "7DaysToDieServer" - - #ProjectZomboid64.exe - Exec = ".\servers\$Name\7DaysToDieServer.exe" - - #Allow force close, usefull for server without RCON and Multiple instances. - AllowForceClose = $true - - #Process Priority Realtime, High, Above normal, Normal, Below normal, Low - UsePriority = $true - AppPriority = "High" - - <# - Process Affinity (Core Assignation) - Core 1 = > 00000001 = > 1 - Core 2 = > 00000010 = > 2 - Core 3 = > 00000100 = > 4 - Core 4 = > 00001000 = > 8 - Core 5 = > 00010000 = > 16 - Core 6 = > 00100000 = > 32 - Core 7 = > 01000000 = > 64 - Core 8 = > 10000000 = > 128 - ---------------------------- - 8 Cores = > 11111111 = > 255 - 4 Cores = > 00001111 = > 15 - 2 Cores = > 00000011 = > 3 - #> - - UseAffinity = $false - AppAffinity = 15 - - #Should the server validate install after installation or update *(recommended) - Validate = $true -} -#Create the object -$Server = New-Object -TypeName PsObject -Property $ServerDetails - -#--------------------------------------------------------- -# Backups -#--------------------------------------------------------- - -$BackupsDetails = @{ - #Do Backups - Use = $true - - #Backup Folder - Path = ".\backups\$($Server.Name)" - - #Number of days of backups to keep. - Days = 7 - - #Number of weeks of weekly backups to keep. - Weeks = 4 - - #Folder to include in backup - Saves = "$Env:userprofile\AppData\Roaming\7DaysToDie" -} -#Create the object -$Backups = New-Object -TypeName PsObject -Property $BackupsDetails - -#--------------------------------------------------------- -# Restart Warnings (Require RCON, Telnet or WebSocket API) -#--------------------------------------------------------- - -$WarningsDetails = @{ - #Use Rcon to restart server softly. - Use = $true - - #What protocol to use : Rcon, Telnet, Websocket - Protocol = "Telnet" - - #Times at which the servers will warn the players that it is about to restart. (in seconds between each timers) - Timers = [System.Collections.ArrayList]@(240,50,10) #Total wait time is 240+50+10 = 300 seconds or 5 minutes - - #message that will be sent. % is a wildcard for the timer. - MessageMin = "The server will restart in % minutes !" - - #message that will be sent. % is a wildcard for the timer. - MessageSec = "The server will restart in % seconds !" - - #command to send a message. - CmdMessage = "say" - - #command to save the server - CmdSave = "saveworld" - - #How long to wait in seconds after the save command is sent. - SaveDelay = 15 - - #command to stop the server - CmdStop = "shutdown" -} -#Create the object -$Warnings = New-Object -TypeName PsObject -Property $WarningsDetails - -#--------------------------------------------------------- -# Launch Arguments -#--------------------------------------------------------- - -#Launch Arguments -$Arguments = @( - "-logfile $($Server.LogFile) ", - "-configfile=$($Server.ConfigFile) ", - "-batchmode ", - "-nographics ", - "-dedicated ", - "-quit" -) - -[System.Collections.ArrayList]$CleanedArguments=@() - -foreach($Argument in $Arguments){ - if (!($Argument.EndsWith('=""') -or $Argument.EndsWith('=') -or $Argument.EndsWith(' '))){ - $CleanedArguments.Add($Argument) - } -} - -$ArgumentList = $CleanedArguments -join "" - -#Server Launcher -$Launcher = $Server.Exec - -#--------------------------------------------------------- -# Launch Function -#--------------------------------------------------------- - -function Start-Server { - - Write-ScriptMsg "Port Forward : 26900 in TCP and 26900 to 26903 in UDP to $($Global.InternalIP)" - - #Copy Config File if not created. Do not modify the one in the server directory, it will be overwriten on updates. - $ConfigFilePath = Split-Path -Path $Server.ConfigFile - if (-not(Test-Path -Path $ConfigFilePath)){ - New-Item -ItemType "directory" -Path $ConfigFilePath -Force -ErrorAction SilentlyContinue - } - If(-not (Test-Path -Path $Server.ConfigFile -PathType "leaf")){ - Copy-Item -Path "$($Server.Path)\serverconfig.xml" -Destination $Server.ConfigFile -Force - } - #Start Server - $App = Start-Process -FilePath $Launcher -WorkingDirectory $Server.Path -ArgumentList $ArgumentList -PassThru - - return $App -} - -Export-ModuleMember -Function Start-Server -Variable @("Server","Backups","Warnings") \ No newline at end of file diff --git a/configs/insurgencysandstorm.psm1 b/configs/insurgencysandstorm.psm1 deleted file mode 100644 index 66c099f..0000000 --- a/configs/insurgencysandstorm.psm1 +++ /dev/null @@ -1,250 +0,0 @@ -<# -#Change your servers settings in ".\servers\Insurgency\Saved\Config\WindowsServer" -#> - -#Server Name, use the same name to share game files. -$Name = "InsurgencySandstorm" - - -#--------------------------------------------------------- -# Server Configuration -#--------------------------------------------------------- - -$ServerDetails = @{ - - #Unique Identifier used to track processes. Must be unique to each servers. - UID = 2 - - #Name of the server in the Server Browser - SessionName = "My Insurgency Server" - - #Maximum Number of Players - MaxPlayers = 8 - - #Password to join the World *NO SPACES* - Password = "CHANGEME" - - #Server Port - Port = 27102 - - #Query Port - QueryPort = 27131 - - #Token -> https://steamcommunity.com/dev/managegameservers - GSLTToken = "CHANGEME" - - #GameStatToken -> https://gamestats.sandstorm.game/ - GameStatsToken = "CHANGEME" - - #Scenario - Scenario = "Scenario_Citadel_Survival" - - #Map - Map = "Citadel" - - #Map Cycle : Create a new text document in Insurgency/Config/Server named MapCycle.txt - MapCycle = "MapCycle" - - #Admins : Create a new text document in Insurgency/Config/Server named Admins.txt steamID64, one per line - Admins = "Admins" - - #Motd : Create a new text document in Insurgency/Config/Server named MOTD.txt - Motd = "MOTD" - - #Mods comma separted -> https://sandstorm-support.newworldinteractive.com/hc/en-us/articles/360049211072-Server-Admin-Guide - Mods = "" - - #Mutators comma separted -> https://sandstorm-support.newworldinteractive.com/hc/en-us/articles/360049211072-Server-Admin-Guide - Mutators = "" - - #Official RuleSet - OfficialRulesSet = "OfficialRules" - - #Enable Rcon $true or $false - EnableRcon = $true - - #Rcon IP, usually localhost - ManagementIP = "127.0.0.1" - - #Rcon Port - ManagementPort = 27015 - - #Rcon Password *NO SPACES* - ManagementPassword = "CHANGEME" - -#--------------------------------------------------------- -# Server Installation Details -#--------------------------------------------------------- - - #Name of the Server Instance - Name = $Name - - #Server Installation Path - Path = ".\servers\$Name" - - #Steam Server App Id - AppID = 581330 - - #Use Beta builds $true or $false - Beta = $false - - #Name of the Beta Build - BetaBuild = "" - - #Beta Build Password - BetaBuildPassword = "" - - #Process name in the task manager - ProcessName = "InsurgencyServer" - - #ProjectZomboid64.exe - Exec = ".\servers\$Name\InsurgencyServer.exe" - - #Allow force close, usefull for server without RCON and Multiple instances. - AllowForceClose = $true - - #Process Priority Realtime, High, Above normal, Normal, Below normal, Low - UsePriority = $true - AppPriority = "High" - - <# - Process Affinity (Core Assignation) - Core 1 = > 00000001 = > 1 - Core 2 = > 00000010 = > 2 - Core 3 = > 00000100 = > 4 - Core 4 = > 00001000 = > 8 - Core 5 = > 00010000 = > 16 - Core 6 = > 00100000 = > 32 - Core 7 = > 01000000 = > 64 - Core 8 = > 10000000 = > 128 - ---------------------------- - 8 Cores = > 11111111 = > 255 - 4 Cores = > 00001111 = > 15 - 2 Cores = > 00000011 = > 3 - #> - - UseAffinity = $false - AppAffinity = 15 - - #Should the server validate install after installation or update *(recommended) - Validate = $true -} -#Create the object -$Server = New-Object -TypeName PsObject -Property $ServerDetails - -#--------------------------------------------------------- -# Backups -#--------------------------------------------------------- - -$BackupsDetails = @{ - #Do Backups - Use = $true - - #Backup Folder - Path = ".\backups\$($Server.Name)" - - #Number of days of backups to keep. - Days = 7 - - #Number of weeks of weekly backups to keep. - Weeks = 4 - - #Folder to include in backup - Saves = ".\servers\$($Server.Name)\Insurgency\Config\Server" -} -#Create the object -$Backups = New-Object -TypeName PsObject -Property $BackupsDetails - -#--------------------------------------------------------- -# Restart Warnings (Require RCON, Telnet or WebSocket API) -#--------------------------------------------------------- - -$WarningsDetails = @{ - #Use Rcon to restart server softly. - Use = $true - - #What protocol to use : Rcon, Telnet, Websocket - Protocol = "Rcon" - - #Times at which the servers will warn the players that it is about to restart. (in seconds between each timers) - Timers = [System.Collections.ArrayList]@(240,50,10) #Total wait time is 240+50+10 = 300 seconds or 5 minutes - - #message that will be sent. % is a wildcard for the timer. - MessageMin = "The server will restart in % minutes !" - - #message that will be sent. % is a wildcard for the timer. - MessageSec = "The server will restart in % seconds !" - - #command to send a message. - CmdMessage = "say" - - #command to save the server - CmdSave = "listplayers" - - #How long to wait in seconds after the save command is sent. - SaveDelay = 15 - - #command to stop the server - CmdStop = "exit" -} -#Create the object -$Warnings = New-Object -TypeName PsObject -Property $WarningsDetails - -#--------------------------------------------------------- -# Launch Arguments -#--------------------------------------------------------- - -$Arguments = @( - "$($Server.Map)", - "?Scenario=$($Server.Scenario)", - "?MaxPlayers=$($Server.MaxPlayers)", - "?password=`"$($Server.Password)`" ", - "-Port=$($Server.Port) ", - "-QueryPort=$($Server.QueryPort) ", - "-hostname=`"$($Server.SessionName)`" ", - "-GSLTToken=`"$($Server.GSLTToken)`" ", - "-GameStatsToken=`"$($Server.GameStatsToken)`" ", - "-Gamestats", - "-MapCycle=`"$($Server.MapCycle)`" ", - "-AdminList=`"$($Server.Admins)`" ", - "-MOTD=`"$($Server.Motd)`" ", - "-ruleset=`"$($Server.OfficialRulesSet)`" ", - "-CmdModList=`"$($Server.Mods)`" ", - "-mutators=`"$($Server.Mutators)`" ", - "-log" -) - -[System.Collections.ArrayList]$CleanedArguments=@() - -foreach($Argument in $Arguments){ - if (!($Argument.EndsWith('=""') -or $Argument.EndsWith('=') -or $Argument.EndsWith(' '))){ - $CleanedArguments.Add($Argument) - } -} - -if ($Server.EnableRcon){ - $CleanedArguments.Add(" -Rcon") - $CleanedArguments.Add(" -RconPassword=`"$($Server.ManagementPassword)`"") - $CleanedArguments.Add(" -RconListenPort=`"$($Server.ManagementPort)`"") -} - -$ArgumentList = $CleanedArguments -join "" - -#Server Launcher -$Launcher = $Server.Exec - -#--------------------------------------------------------- -# Launch Function -#--------------------------------------------------------- - -function Start-Server { - - Write-ScriptMsg "Port Forward : $($server.Port) and $($server.QueryPort) in TCP and UDP to $($Global.InternalIP)" - - #Start Server - $App = Start-Process -FilePath $Launcher -WorkingDirectory $Server.Path -ArgumentList $ArgumentList -PassThru - - return $App -} - -Export-ModuleMember -Function Start-Server -Variable @("Server","Backups","Warnings") \ No newline at end of file diff --git a/configs/killingfloor2.psm1 b/configs/killingfloor2.psm1 deleted file mode 100644 index 6cf71a6..0000000 --- a/configs/killingfloor2.psm1 +++ /dev/null @@ -1,218 +0,0 @@ - -<# -Edit configuration in ./Servers/KillingFloor2/KFGame/Config/KF[UID].INI -bEnabled=true to enable webadmin -#> - -#Server Name, use the same name to share game files. -$Name = "KillingFloor2" - -#--------------------------------------------------------- -# Server Configuration -#--------------------------------------------------------- - -$ServerDetails = @{ - - #Unique Identifier used to track processes. Must be unique to each servers. - UID = 6 - - #This is the admin username for WebAdmin if you're configuring WebAdmin via Commandline - AdminName = "admin" - - #This is the master server administrator password - AdminPassword = "CHANGEME" - - #This is how many maximum players the server is set to support - MaxPlayers = 6 - - #This sets the server difficulty. 0 = Normal, 1 = Hard, 2 = Suicidal, 3 = Hell on Earth - Difficulty = 0 - - #This is the game port. - Port = 7777 - - #This is the query port. - QueryPort = 27015 - - #This is the web admin port. Changing this will change the port used to connect to the servers webadmin panel if that functionality is turned on. - WebAdminPort = 8080 - - #Starting map name. - Map = "KF-BIOTICSLAB" - - #Game mode EG : KFGameContent.KFGameInfo_WeeklySurvival, KFGameContent.KFGameInfo_VersusSurvival, KFGameContent.KFGameInfo_Endless - GameMode = "KFGameContent.KFGameInfo_WeeklySurvival" - - #Rcon IP (not supported by KF2.) - ManagementIP = "127.0.0.1" - - #Rcon Port - ManagementPort = "" - - #Rcon Password - ManagementPassword = "" - -#--------------------------------------------------------- -# Server Installation Details -#--------------------------------------------------------- - - #Name of the Server Instance - Name = $Name - - #Server Installation Path - Path = ".\servers\$Name" - - #Steam Server App Id - AppID = 232130 - - #Use Beta builds $true or $false - Beta = $false - - #Name of the Beta Build - BetaBuild = "" - - #Beta Build Password - BetaBuildPassword = "" - - #Process name in the task manager - ProcessName = "KFServer" - - #ProjectZomboid64.exe - Exec = ".\servers\$Name\Binaries\Win64\KFServer.exe" - - #Allow force close, usefull for server without RCON and Multiple instances. - AllowForceClose = $true - - #Process Priority Realtime, High, Above normal, Normal, Below normal, Low - UsePriority = $true - AppPriority = "High" - - <# - Process Affinity (Core Assignation) - Core 1 = > 00000001 = > 1 - Core 2 = > 00000010 = > 2 - Core 3 = > 00000100 = > 4 - Core 4 = > 00001000 = > 8 - Core 5 = > 00010000 = > 16 - Core 6 = > 00100000 = > 32 - Core 7 = > 01000000 = > 64 - Core 8 = > 10000000 = > 128 - ---------------------------- - 8 Cores = > 11111111 = > 255 - 4 Cores = > 00001111 = > 15 - 2 Cores = > 00000011 = > 3 - #> - - UseAffinity = $false - AppAffinity = 15 - - #Should the server validate install after installation or update *(recommended) - Validate = $false -} -#Create the object -$Server = New-Object -TypeName PsObject -Property $ServerDetails - -#--------------------------------------------------------- -# Backups -#--------------------------------------------------------- - -$BackupsDetails = @{ - #Do Backups - Use = $true - - #Backup Folder - Path = ".\backups\$($Server.Name)" - - #Number of days of backups to keep. - Days = 7 - - #Number of weeks of weekly backups to keep. - Weeks = 4 - - #Folder to include in backup - Saves = ".\servers\$Name\KFGame\Config\" -} -#Create the object -$Backups = New-Object -TypeName PsObject -Property $BackupsDetails - -#--------------------------------------------------------- -# Restart Warnings (Require RCON, Telnet or WebSocket API) -#--------------------------------------------------------- - -$WarningsDetails = @{ - #Use Rcon to restart server softly. - Use = $false - - #What protocol to use : Rcon, Telnet, Websocket - Protocol = "Rcon" - - #Times at which the servers will warn the players that it is about to restart. (in seconds between each timers) - Timers = [System.Collections.ArrayList]@(240,50,10) #Total wait time is 240+50+10 = 300 seconds or 5 minutes - - #message that will be sent. % is a wildcard for the timer. - MessageMin = "The server will restart in % minutes !" - - #message that will be sent. % is a wildcard for the timer. - MessageSec = "The server will restart in % seconds !" - - #command to send a message. - CmdMessage = "say" - - #command to save the server - CmdSave = "saveworld" - - #How long to wait in seconds after the save command is sent. - SaveDelay = 15 - - #command to stop the server - CmdStop = "shutdown" -} -#Create the object -$Warnings = New-Object -TypeName PsObject -Property $WarningsDetails - -#--------------------------------------------------------- -# Launch Arguments -#--------------------------------------------------------- - -#Launch Arguments -$Arguments = @( - "$($Server.Map)", - "?Game=$($Server.GameMode)", - "?MaxPlayers=$($Server.MaxPlayers)", - "?Difficulty=$($Server.Difficulty) ", - "-Port=$($Server.Port) ", - "-QueryPort=$($Server.QueryPort) ", - "-WebAdminPort=$($Server.WebAdminPort) ", - "-Multihome=$($Global.InternalIP) ", - "-ConfigSubDir=KF$($Server.UID)" -) - -[System.Collections.ArrayList]$CleanedArguments=@() - -foreach($Argument in $Arguments){ - if (!($Argument.EndsWith('=""') -or $Argument.EndsWith('=') -or $Argument.EndsWith(' '))){ - $CleanedArguments.Add($Argument) - } -} - -$ArgumentList = $CleanedArguments -join "" - -#Server Launcher -$Launcher = $Server.Exec - -#--------------------------------------------------------- -# Launch Function -#--------------------------------------------------------- - -function Start-Server { - - Write-ScriptMsg "Port Forward : $($server.Port), $($server.QueryPort), 20560, 123 in UDP and $($server.WebAdminPort) in TCP to $($Global.InternalIP)" - Write-ScriptMsg "Once Webadmin enabled, go to http://$($Global.InternalIP):$($server.WebAdminPort) to administer this server." - - #Start Server - $App = Start-Process -FilePath $Launcher -WorkingDirectory $Server.Path -ArgumentList $ArgumentList -PassThru - - return $App -} - -Export-ModuleMember -Function Start-Server -Variable @("Server","Backups","Warnings") \ No newline at end of file diff --git a/configs/pixark.psm1 b/configs/pixark.psm1 deleted file mode 100644 index 4733a61..0000000 --- a/configs/pixark.psm1 +++ /dev/null @@ -1,258 +0,0 @@ -<# -#Change your servers settings in ".\servers\PixArk\ShooterGame\Saved\Config\WindowsServer\GameUserSettings.ini" - -Under : [ServerSettings] -Add/Set one of those settings : - -Pioneering : - -CanPVPAttack=False -ServerPVPCanAttack=False - -Fury : - -ServerPVE=False -CanPVPAttack=True -ServerPVPCanAttack=False - -Chaos: - -ServerPVE=False -CanPVPAttack=False -ServerPVPCanAttack=True - -#> - -#Server Name, use the same name to share game files. -$Name = "PixArk" - -#--------------------------------------------------------- -# Server Configuration -#--------------------------------------------------------- - -$ServerDetails = @{ - - #Unique Identifier used to track processes. Must be unique to each servers. - UID = 3 - - #Name of the server in the Server Browser - SessionName = "My Pixark Server" - - #Maximum Number of Players - MaxPlayers = 20 - - #Password to join the World *NO SPACES* - Password = "CHANGEME" - - #Server Port - Port = 7797 - - #World Seed - Seed = 32399 - - #Query Port - QueryPort = 27515 - - #Cube Port - CubePort = 27518 - - #World Name *NO SPACES* - WorldName = "World" - - #World Type : "SkyPiea_Light" for Skyward or "CubeWorld_Light" for regular - WorldType = "CubeWorld_Light" - - #Show Floating Damage Text "True" or "False" - ShowFloatingDamageText = "True" - - #Server Language - Language = "en" - - #Enable Rcon "True" or "False" - EnableRcon = "True" - - #Rcon IP, usually localhost - ManagementIP = "127.0.0.1" - - #Rcon Port - ManagementPort = 27520 - - #Rcon Password *NO SPACES* - ManagementPassword = "CHANGEME2" - -#--------------------------------------------------------- -# Server Installation Details -#--------------------------------------------------------- - - #Name of the Server Instance - Name = $Name - - #Server Installation Path - Path = ".\servers\$Name" - - #Steam Server App Id - AppID = 824360 - - #Use Beta builds $true or $false - Beta = $false - - #Name of the Beta Build - BetaBuild = "" - - #Beta Build Password - BetaBuildPassword = "" - - #Process name in the task manager - ProcessName = "PixArkServer" - - #ProjectZomboid64.exe - Exec = ".\servers\$Name\ShooterGame\Binaries\Win64\PixARKServer.exe" - - #Allow force close, usefull for server without RCON and Multiple instances. - AllowForceClose = $true - - #Process Priority Realtime, High, Above normal, Normal, Below normal, Low - UsePriority = $true - AppPriority = "High" - - <# - Process Affinity (Core Assignation) - Core 1 = > 00000001 = > 1 - Core 2 = > 00000010 = > 2 - Core 3 = > 00000100 = > 4 - Core 4 = > 00001000 = > 8 - Core 5 = > 00010000 = > 16 - Core 6 = > 00100000 = > 32 - Core 7 = > 01000000 = > 64 - Core 8 = > 10000000 = > 128 - ---------------------------- - 8 Cores = > 11111111 = > 255 - 4 Cores = > 00001111 = > 15 - 2 Cores = > 00000011 = > 3 - #> - - UseAffinity = $false - AppAffinity = 15 - - #Should the server validate install after installation or update *(recommended) - Validate = $true -} -#Create the object -$Server = New-Object -TypeName PsObject -Property $ServerDetails - -#--------------------------------------------------------- -# Backups -#--------------------------------------------------------- - -$BackupsDetails = @{ - #Do Backups - Use = $true - - #Backup Folder - Path = ".\backups\$($Server.Name)" - - #Number of days of backups to keep. - Days = 7 - - #Number of weeks of weekly backups to keep. - Weeks = 4 - - #Folder to include in backup - Saves = ".\servers\$($Server.Name)\ShooterGame\Saved" -} -#Create the object -$Backups = New-Object -TypeName PsObject -Property $BackupsDetails - -#--------------------------------------------------------- -# Restart Warnings (Require RCON, Telnet or WebSocket API) -#--------------------------------------------------------- - -$WarningsDetails = @{ - #Use Rcon to restart server softly. - Use = $true - - #What protocol to use : Rcon, Telnet, Websocket - Protocol = "Rcon" - - #Times at which the servers will warn the players that it is about to restart. (in seconds between each timers) - Timers = [System.Collections.ArrayList]@(240,50,10) #Total wait time is 240+50+10 = 300 seconds or 5 minutes - - #message that will be sent. % is a wildcard for the timer. - MessageMin = "The server will restart in % minutes !" - - #message that will be sent. % is a wildcard for the timer. - MessageSec = "The server will restart in % seconds !" - - #command to send a message. - CmdMessage = "broadcast" - - #command to save the server - CmdSave = "saveworld" - - #How long to wait in seconds after the save command is sent. - SaveDelay = 15 - - #command to stop the server - CmdStop = "quit" -} -#Create the object -$Warnings = New-Object -TypeName PsObject -Property $WarningsDetails - -#--------------------------------------------------------- -# Launch Arguments -#--------------------------------------------------------- - -#Launch Arguments -$Arguments = @( - "$($Server.WorldType)", - "?listen", - "?Multihome=$($Server.InternalIP)", - "?RCONEnabled=$($Server.EnableRcon)", - "?MaxPlayers=$($Server.MaxPlayers)", - "?Port=$($Server.Port)", - "?RCONPort=$($Server.ManagementPort)", - "?QueryPort=$($Server.QueryPort)", - "?ServerAdminPassword=$($Server.ManagementPassword)", - "?SessionName=`"$($Server.SessionName)`"", - "?ServerPassword=$($Server.Password)", - "?ShowFloatingDamageText=$($Server.ShowFloatingDamageText)", - "?CULTUREFORCOOKING=$($Server.Language) ", - "-CubePort=$($Server.CubePort) ", - "-CubeWorld=$($Server.WorldName) ", - "-Seed=$($Server.Seed) ", - "-forcerespawndinos " - "-NoHangDetection ", - "-nosteamclient ", - "-game ", - "-server ", - "-log" -) - -[System.Collections.ArrayList]$CleanedArguments=@() - -foreach($Argument in $Arguments){ - if (!($Argument.EndsWith('=""') -or $Argument.EndsWith('=') -or $Argument.EndsWith(' '))){ - $CleanedArguments.Add($Argument) - } -} - -$ArgumentList = $CleanedArguments -join "" - -#Server Launcher -$Launcher = $Server.Exec - -#--------------------------------------------------------- -# Launch Function -#--------------------------------------------------------- - -function Start-Server { - - Write-ScriptMsg "Port Forward : $($server.Port), $($server.QueryPort) And $($server.CubePort) in TCP and UDP to $($Global.InternalIP)" - - #Start Server - $App = Start-Process -FilePath $Launcher -WorkingDirectory $Server.Path -ArgumentList $ArgumentList -PassThru - - return $App -} - -Export-ModuleMember -Function Start-Server -Variable @("Server","Backups","Warnings") \ No newline at end of file diff --git a/configs/projectzomboid.psm1 b/configs/projectzomboid.psm1 deleted file mode 100644 index bedb5de..0000000 --- a/configs/projectzomboid.psm1 +++ /dev/null @@ -1,226 +0,0 @@ -<# -#Change your servers settings in C:\Users\%username%\Zomboid\Server\servertest.ini - -Options to look for when setting your server in servertest.ini (Suggested values) -``` -DefaultPort=16261 -MaxPlayers=64 -Open=true -PVP=true -Password=My server password -PauseEmpty=true -PingFrequency=10 -PingLimit=200 -Public=true -PublicDescription=My server Description -PublicName=My server name -RCONPassword=CHANGEME -RCONPort=27015 -SteamPort1=8766 -SteamPort2=8767 -``` - -You need to port forward the following Ports on your router, both in TCP and UDP - -``` -DefaultPort=16261 -SteamPort1=8766 -SteamPort2=8767 -``` -You do not need to forward RCON. -#> - -#Server Name, use the same name to share game files. -$Name = "ProjectZomboid" - -#--------------------------------------------------------- -# Server Configuration -#--------------------------------------------------------- - -$ServerDetails = @{ - - #Unique Identifier used to track processes. Must be unique to each servers. - UID = 4 - - #Rcon IP, usually localhost - ManagementIP = "127.0.0.1" - - #Rcon Port in servertest.ini - ManagementPort = 27015 - - #Rcon Password as set in servertest.ini (Do not use " " in servertest.ini) - ManagementPassword = "CHANGEME" - -#--------------------------------------------------------- -# Server Installation -#--------------------------------------------------------- - - #Name of the Server Instance - Name = $Name - - #Server Installation Path - Path = ".\servers\$Name" - - #Steam Server App Id - AppID = 380870 - - #Use Beta builds $true or $false - Beta = $false - - #Name of the Beta Build - BetaBuild = "iwillbackupmysave" - - #Beta Build Password - BetaBuildPassword = "iaccepttheconsequences" - - #Process name in the task manager - ProcessName = "java" - - #ProjectZomboid64.exe - Exec = ".\servers\$Name\ProjectZomboid64.exe" - - #Allow force close, usefull for server without RCON and Multiple instances. - AllowForceClose = $true - - #Process Priority Realtime, High, Above normal, Normal, Below normal, Low - UsePriority = $true - AppPriority = "High" - - <# - Process Affinity (Core Assignation) - Core 1 = > 00000001 = > 1 - Core 2 = > 00000010 = > 2 - Core 3 = > 00000100 = > 4 - Core 4 = > 00001000 = > 8 - Core 5 = > 00010000 = > 16 - Core 6 = > 00100000 = > 32 - Core 7 = > 01000000 = > 64 - Core 8 = > 10000000 = > 128 - ---------------------------- - 8 Cores = > 11111111 = > 255 - 4 Cores = > 00001111 = > 15 - 2 Cores = > 00000011 = > 3 - #> - - UseAffinity = $false - AppAffinity = 15 - - #Should the server validate install after installation or update *(recommended) - Validate = $true -} -#Create the object -$Server = New-Object -TypeName PsObject -Property $ServerDetails - -#--------------------------------------------------------- -# Backups -#--------------------------------------------------------- -$BackupsDetails = @{ - #Do Backups - Use = $true - - #Backup Folder - Path = ".\backups\$($Server.Name)" - - #Number of days of backups to keep. - Days = 7 - - #Number of weeks of weekly backups to keep. - Weeks = 4 - - #Folder to include in backup - Saves = "$Env:userprofile\Zomboid" -} -#Create the object -$Backups = New-Object -TypeName PsObject -Property $BackupsDetails - -#--------------------------------------------------------- -# Restart Warnings (Require RCON, Telnet or WebSocket API) -#--------------------------------------------------------- -$WarningsDetails = @{ - #Use Rcon to restart server softly. - Use = $true - - #What protocol to use : Rcon, Telnet, Websocket - Protocol = "Rcon" - - #Times at which the servers will warn the players that it is about to restart. (in seconds between each timers) - Timers = [System.Collections.ArrayList]@(240,50,10) #Total wait time is 240+50+10 = 300 seconds or 5 minutes - - #message that will be sent. % is a wildcard for the timer. - MessageMin = "The server will restart in % minutes !" - - #message that will be sent. % is a wildcard for the timer. - MessageSec = "The server will restart in % seconds !" - - #command to send a message. - CmdMessage = "servermsg" - - #command to save the server - CmdSave = "save" - - #How long to wait in seconds after the save command is sent. - SaveDelay = 15 - - #command to stop the server - CmdStop = "quit" -} -#Create the object -$Warnings = New-Object -TypeName PsObject -Property $WarningsDetails - -#--------------------------------------------------------- -# Launch Arguments -#--------------------------------------------------------- - -#Java Arguments -$PZ_CLASSPATH_LIST = @( - "java/jinput.jar;", - "java/lwjgl.jar;", - "java/lwjgl_util.jar;", - "java/sqlite-jdbc-3.8.10.1.jar;", - "java/trove-3.0.3.jar;", - "java/uncommons-maths-1.2.3.jar;", - "java/javacord-2.0.17-shaded.jar;", - "java/guava-23.0.jar;", - "java/" -) - -$PZ_CLASSPATH = $PZ_CLASSPATH_LIST -join "" -#Launch Arguments -$Arguments = @( - "-Dzomboid.steam=1 ", - "-Dzomboid.znetlog=1 ", - "-XX:+UseConcMarkSweepGC ", - "-XX:-CreateMinidumpOnCrash ", - "-XX:-OmitStackTraceInFastThrow ", - "-Xms2048m ", - "-Xmx2048m ", - "-Djava.library.path=natives/;. ", - "-cp $PZ_CLASSPATH zombie.network.GameServer" -) - -[System.Collections.ArrayList]$CleanedArguments=@() - -foreach($Argument in $Arguments){ - if (!($Argument.EndsWith('=""') -or $Argument.EndsWith('=') -or $Argument.EndsWith(' '))){ - $CleanedArguments.Add($Argument) - } -} - -$ArgumentList = $CleanedArguments -join "" - -$Launcher = "$($Server.Path)\jre64\bin\java.exe" - -#--------------------------------------------------------- -# Launch Function -#--------------------------------------------------------- - -function Start-Server { - - Write-ScriptMsg "Port Forward : 16261, 8766 and 8767 in TCP and UDP to $($Global.InternalIP)" - - $App = Start-Process -FilePath $Launcher -WorkingDirectory $Server.Path -ArgumentList $ArgumentList -PassThru - - return $App -} - -Export-ModuleMember -Function Start-Server -Variable @("Server","Backups","Warnings") \ No newline at end of file diff --git a/configs/valheim.psm1 b/configs/valheim.psm1 deleted file mode 100644 index dcace6c..0000000 --- a/configs/valheim.psm1 +++ /dev/null @@ -1,195 +0,0 @@ - -#Server Name, use the same name to share game files. -$Name = "Valheim" - -#--------------------------------------------------------- -# Server Configuration -#--------------------------------------------------------- - -$ServerDetails = @{ - - #Unique Identifier used to track processes. Must be unique to each servers. - UID = 5 - - #Name of the server in the Server Browser - SessionName = "My Valheim Server" - - #World name (It is also the seed) - World = "World" - - #Password to join the World *NO SPACES* - Password = "CHANGEME" - - #Server Port - Port = 2459 - - #Rcon IP (not supported by valheim yet.) - ManagementIP = "" - - #Rcon Port - ManagementPort = "" - - #Rcon Password - ManagementPassword = "" - -#--------------------------------------------------------- -# Server Installation Details -#--------------------------------------------------------- - - #Name of the Server Instance - Name = $Name - - #Server Installation Path - Path = ".\servers\$Name" - - #Steam Server App Id - AppID = 896660 - - #Use Beta builds $true or $false - Beta = $false - - #Name of the Beta Build - BetaBuild = "" - - #Beta Build Password - BetaBuildPassword = "" - - #Process name in the task manager - ProcessName = "valheim_server" - - #ProjectZomboid64.exe - Exec = ".\servers\$Name\valheim_server.exe" - - #Allow force close, usefull for server without RCON and Multiple instances. - AllowForceClose = $true - - #Process Priority Realtime, High, Above normal, Normal, Below normal, Low - UsePriority = $true - AppPriority = "High" - - <# - Process Affinity (Core Assignation) - Core 1 = > 00000001 = > 1 - Core 2 = > 00000010 = > 2 - Core 3 = > 00000100 = > 4 - Core 4 = > 00001000 = > 8 - Core 5 = > 00010000 = > 16 - Core 6 = > 00100000 = > 32 - Core 7 = > 01000000 = > 64 - Core 8 = > 10000000 = > 128 - ---------------------------- - 8 Cores = > 11111111 = > 255 - 4 Cores = > 00001111 = > 15 - 2 Cores = > 00000011 = > 3 - #> - - UseAffinity = $false - AppAffinity = 15 - - #Should the server validate install after installation or update *(recommended) - Validate = $true -} -#Create the object -$Server = New-Object -TypeName PsObject -Property $ServerDetails - -#--------------------------------------------------------- -# Backups -#--------------------------------------------------------- - -$BackupsDetails = @{ - #Do Backups - Use = $true - - #Backup Folder - Path = ".\backups\$($Server.Name)" - - #Number of days of backups to keep. - Days = 7 - - #Number of weeks of weekly backups to keep. - Weeks = 4 - - #Folder to include in backup - Saves = "$Env:userprofile\AppData\LocalLow\IronGate\Valheim" -} -#Create the object -$Backups = New-Object -TypeName PsObject -Property $BackupsDetails - -#--------------------------------------------------------- -# Restart Warnings (Require RCON, Telnet or WebSocket API) -#--------------------------------------------------------- - -$WarningsDetails = @{ - #Use Rcon to restart server softly. - Use = $false - - #What protocol to use : Rcon, Telnet, Websocket - Protocol = "Rcon" - - #Times at which the servers will warn the players that it is about to restart. (in seconds between each timers) - Timers = [System.Collections.ArrayList]@(240,50,10) #Total wait time is 240+50+10 = 300 seconds or 5 minutes - - #message that will be sent. % is a wildcard for the timer. - MessageMin = "The server will restart in % minutes !" - - #message that will be sent. % is a wildcard for the timer. - MessageSec = "The server will restart in % seconds !" - - #command to send a message. - CmdMessage = "say" - - #command to save the server - CmdSave = "saveworld" - - #How long to wait in seconds after the save command is sent. - SaveDelay = 15 - - #command to stop the server - CmdStop = "shutdown" -} -#Create the object -$Warnings = New-Object -TypeName PsObject -Property $WarningsDetails - -#--------------------------------------------------------- -# Launch Arguments -#--------------------------------------------------------- - -#Launch Arguments -$Arguments = @( - "-batchmode ", - "-nographics ", - "-name $($Server.SessionName) ", - "-port $($Server.Port) ", - "-world $($Server.World) ", - "-password $($Server.Password) ", - "-public 1" -) - -[System.Collections.ArrayList]$CleanedArguments=@() - -foreach($Argument in $Arguments){ - if (!($Argument.EndsWith('=""') -or $Argument.EndsWith('=') -or $Argument.EndsWith(' '))){ - $CleanedArguments.Add($Argument) - } -} - -$ArgumentList = $CleanedArguments -join "" - -#Server Launcher -$Launcher = $Server.Exec - -#--------------------------------------------------------- -# Launch Function -#--------------------------------------------------------- - -function Start-Server { - - Write-ScriptMsg "Port Forward : $($server.Port) in TCP and UDP to $($Global.InternalIP)" - - #Start Server - $App = Start-Process -FilePath $Launcher -WorkingDirectory $Server.Path -ArgumentList $ArgumentList -PassThru - - return $App -} - -Export-ModuleMember -Function Start-Server -Variable @("Server","Backups","Warnings") \ No newline at end of file diff --git a/launchers/run.cmd b/launchers/run.cmd index 6653623..0904e89 100644 --- a/launchers/run.cmd +++ b/launchers/run.cmd @@ -1,2 +1,2 @@ cd .. -start powershell.exe -noprofile -executionpolicy bypass -file ".\main.ps1" -ServerCfg "killingfloor2" \ No newline at end of file +start powershell.exe -noprofile -executionpolicy bypass -file ".\main.ps1" -ServerCfg "valheim" \ No newline at end of file diff --git a/templates/rust.psm1 b/templates/rust.psm1 index 6cf71a6..83e61c1 100644 --- a/templates/rust.psm1 +++ b/templates/rust.psm1 @@ -1,11 +1,9 @@ - <# -Edit configuration in ./Servers/KillingFloor2/KFGame/Config/KF[UID].INI -bEnabled=true to enable webadmin +Edit configuration in ".\servers\Rust\server\[Identity]\cfg\serverauto.cfg" #> #Server Name, use the same name to share game files. -$Name = "KillingFloor2" +$Name = "Rust" #--------------------------------------------------------- # Server Configuration @@ -14,43 +12,49 @@ $Name = "KillingFloor2" $ServerDetails = @{ #Unique Identifier used to track processes. Must be unique to each servers. - UID = 6 + UID = 8 + + #Name of the server + Hostname = "My Rust Server" - #This is the admin username for WebAdmin if you're configuring WebAdmin via Commandline - AdminName = "admin" + #Identity of the server + Identity = "RustServer01" - #This is the master server administrator password - AdminPassword = "CHANGEME" + #Max number of Players + MaxPlayers = 50 - #This is how many maximum players the server is set to support - MaxPlayers = 6 + #Server Port + Port = 28015 - #This sets the server difficulty. 0 = Normal, 1 = Hard, 2 = Suicidal, 3 = Hell on Earth - Difficulty = 0 + #Server Seed + Seed = "seed" - #This is the game port. - Port = 7777 + #World Name + worldName = "Procedural Map" - #This is the query port. - QueryPort = 27015 + #World Size + worldSize = 4000 - #This is the web admin port. Changing this will change the port used to connect to the servers webadmin panel if that functionality is turned on. - WebAdminPort = 8080 + #Save Interval + saveInterval = 300 - #Starting map name. - Map = "KF-BIOTICSLAB" + #Save Interval, Max 30, recommended 15 + TickRate = 15 - #Game mode EG : KFGameContent.KFGameInfo_WeeklySurvival, KFGameContent.KFGameInfo_VersusSurvival, KFGameContent.KFGameInfo_Endless - GameMode = "KFGameContent.KFGameInfo_WeeklySurvival" + #Enable Valve Anti-Cheat + VAC = "true" - #Rcon IP (not supported by KF2.) + #rcon version (0 = Source RCON | 1 = websocket) + rconVersion = 0 + + #Rcon IP ManagementIP = "127.0.0.1" #Rcon Port - ManagementPort = "" + ManagementPort = 28016 #Rcon Password - ManagementPassword = "" + ManagementPassword = "CHANGEME" #--------------------------------------------------------- # Server Installation Details @@ -63,7 +67,7 @@ $ServerDetails = @{ Path = ".\servers\$Name" #Steam Server App Id - AppID = 232130 + AppID = 258550 #Use Beta builds $true or $false Beta = $false @@ -75,10 +79,10 @@ $ServerDetails = @{ BetaBuildPassword = "" #Process name in the task manager - ProcessName = "KFServer" + ProcessName = "RustDedicated" #ProjectZomboid64.exe - Exec = ".\servers\$Name\Binaries\Win64\KFServer.exe" + Exec = ".\servers\$Name\RustDedicated.exe" #Allow force close, usefull for server without RCON and Multiple instances. AllowForceClose = $true @@ -130,7 +134,7 @@ $BackupsDetails = @{ Weeks = 4 #Folder to include in backup - Saves = ".\servers\$Name\KFGame\Config\" + Saves = ".\servers\$Name\server\$($Server.Identity)" } #Create the object $Backups = New-Object -TypeName PsObject -Property $BackupsDetails @@ -141,7 +145,7 @@ $Backups = New-Object -TypeName PsObject -Property $BackupsDetails $WarningsDetails = @{ #Use Rcon to restart server softly. - Use = $false + Use = $true #What protocol to use : Rcon, Telnet, Websocket Protocol = "Rcon" @@ -159,13 +163,13 @@ $WarningsDetails = @{ CmdMessage = "say" #command to save the server - CmdSave = "saveworld" + CmdSave = "server.save" #How long to wait in seconds after the save command is sent. SaveDelay = 15 #command to stop the server - CmdStop = "shutdown" + CmdStop = "server.stop" } #Create the object $Warnings = New-Object -TypeName PsObject -Property $WarningsDetails @@ -176,15 +180,24 @@ $Warnings = New-Object -TypeName PsObject -Property $WarningsDetails #Launch Arguments $Arguments = @( - "$($Server.Map)", - "?Game=$($Server.GameMode)", - "?MaxPlayers=$($Server.MaxPlayers)", - "?Difficulty=$($Server.Difficulty) ", - "-Port=$($Server.Port) ", - "-QueryPort=$($Server.QueryPort) ", - "-WebAdminPort=$($Server.WebAdminPort) ", - "-Multihome=$($Global.InternalIP) ", - "-ConfigSubDir=KF$($Server.UID)" + "-batchmode ", + "+server.ip $($Global.InternalIP) ", + "+server.port $($Server.Port) ", + "+server.hostname `"$($Server.Hostname)`" ", + "+server.identity `"$($Server.Identity)`" ", + "+server.maxplayers $($Server.MaxPlayers) ", + "+server.level `"$($Server.worldName)`" ", + "+server.worldsize $($Server.worldSize) ", + "+server.seed $($Server.Seed) ", + "+server.tickrate $($Server.TickRate) ", + "+server.saveinterval $($Server.saveInterval) ", + "+server.secure $($Server.VAC) ", + "+app.port $($Server.Port + 69) ", + "+rcon.ip $($Server.ManagementIP) ", + "+rcon.port $($Server.ManagementPort) ", + "+rcon.password `"$($Server.ManagementPassword)`" ", + "+rcon.web $($Server.rconVersion) ", + "-logfile $($Server.Identity).txt " ) [System.Collections.ArrayList]$CleanedArguments=@() @@ -206,11 +219,10 @@ $Launcher = $Server.Exec function Start-Server { - Write-ScriptMsg "Port Forward : $($server.Port), $($server.QueryPort), 20560, 123 in UDP and $($server.WebAdminPort) in TCP to $($Global.InternalIP)" - Write-ScriptMsg "Once Webadmin enabled, go to http://$($Global.InternalIP):$($server.WebAdminPort) to administer this server." + Write-ScriptMsg "Port Forward : $($server.Port), $($server.ManagementPort), $($Server.Port + 69) in TCP and UDP to $($Global.InternalIP)" #Start Server - $App = Start-Process -FilePath $Launcher -WorkingDirectory $Server.Path -ArgumentList $ArgumentList -PassThru + Start-Process -FilePath $Launcher -WorkingDirectory $Server.Path -ArgumentList $ArgumentList -PassThru return $App } From c5638fbfc3346fecc76acbbc6aca7eabcad6ae62 Mon Sep 17 00:00:00 2001 From: Patrick Veilleux Date: Fri, 17 Sep 2021 12:09:20 -0400 Subject: [PATCH 9/9] add rust --- launchers/run.cmd | 2 +- templates/rust.psm1 | 56 +++++++++++++++++++++++++++++++++++++-------- 2 files changed, 48 insertions(+), 10 deletions(-) diff --git a/launchers/run.cmd b/launchers/run.cmd index 0904e89..2dffa2c 100644 --- a/launchers/run.cmd +++ b/launchers/run.cmd @@ -1,2 +1,2 @@ cd .. -start powershell.exe -noprofile -executionpolicy bypass -file ".\main.ps1" -ServerCfg "valheim" \ No newline at end of file +start powershell.exe -noprofile -executionpolicy bypass -file ".\main.ps1" -ServerCfg "rust" \ No newline at end of file diff --git a/templates/rust.psm1 b/templates/rust.psm1 index 83e61c1..a474fe9 100644 --- a/templates/rust.psm1 +++ b/templates/rust.psm1 @@ -20,29 +20,56 @@ $ServerDetails = @{ #Identity of the server Identity = "RustServer01" + #Description of the server \n for new line + Description = "Welcome to my server" + + #URL of the website of the server + Website = "https://example.com/" + + #URL of the banner of the server (500 x 256 png or jpg) + Banner = "https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png" + + #URL of the logo image shown in the Rust+ App (128 x 128 png or jpg) + Logo = "https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png" + #Max number of Players MaxPlayers = 50 #Server Port Port = 28015 - #Server Seed - Seed = "seed" - #World Name worldName = "Procedural Map" #World Size worldSize = 4000 + #World Seed + Seed = 1234 + + #PVE mode ("True" = PVE | "False" = PVP) + PVE = "False" + #Save Interval saveInterval = 300 - #Save Interval, Max 30, recommended 15 - TickRate = 15 + #Save Interval, Max 30, recommended 10 + TickRate = 10 + + #Decay Scale (1 = normal | 0 = off) + DecayScale = 1 + + #Enable or disable instant crafting ("True" = instant crafting enabled | "False" = instant crafting disabled) + InstantCraft = "False" + + #SteamID64 of the Steam Group associated with the server to whitelist only that group. + SteamGroup = "" + + #Enable Easy Anti-Cheat (1 = enabled | 0 = disabled) + EAC = 1 - #Enable Valve Anti-Cheat - VAC = "true" + #Enable Valve Anti Cheat security ("True" = enabled | "False" = disabled) + VAC = "True" #rcon version (0 = Source RCON | 1 = websocket) rconVersion = 0 @@ -181,16 +208,26 @@ $Warnings = New-Object -TypeName PsObject -Property $WarningsDetails #Launch Arguments $Arguments = @( "-batchmode ", + "-nographics ", "+server.ip $($Global.InternalIP) ", "+server.port $($Server.Port) ", "+server.hostname `"$($Server.Hostname)`" ", "+server.identity `"$($Server.Identity)`" ", + "+server.description `"$($Server.Description)`" ", + "+server.url `"$($Server.Website)`" ", + "+server.headerimage `"$($Server.Banner)`" ", + "+server.logoimage `"$($Server.Logo)`" ", "+server.maxplayers $($Server.MaxPlayers) ", "+server.level `"$($Server.worldName)`" ", "+server.worldsize $($Server.worldSize) ", "+server.seed $($Server.Seed) ", + "+server.pve $($Server.PVE) ", + "+decay.scale $($Server.DecayScale) ", + "+craft.instant $($Server.InstantCraft) ", + "+server.steamgroup $($Server.SteamGroup) ", "+server.tickrate $($Server.TickRate) ", "+server.saveinterval $($Server.saveInterval) ", + "+server.eac $($Server.EAC) ", "+server.secure $($Server.VAC) ", "+app.port $($Server.Port + 69) ", "+rcon.ip $($Server.ManagementIP) ", @@ -211,7 +248,8 @@ foreach($Argument in $Arguments){ $ArgumentList = $CleanedArguments -join "" #Server Launcher -$Launcher = $Server.Exec +$Launcher = $(Resolve-Path -Path $Server.Exec) +$WorkingDirectory = $(Resolve-Path -Path $Server.Path) #--------------------------------------------------------- # Launch Function @@ -222,7 +260,7 @@ function Start-Server { Write-ScriptMsg "Port Forward : $($server.Port), $($server.ManagementPort), $($Server.Port + 69) in TCP and UDP to $($Global.InternalIP)" #Start Server - Start-Process -FilePath $Launcher -WorkingDirectory $Server.Path -ArgumentList $ArgumentList -PassThru + $App = Start-Process -FilePath "$Launcher" -WorkingDirectory "$WorkingDirectory" -ArgumentList "$ArgumentList" -PassThru return $App }