From ea6eea911e4cd9e2bac065dbe6b89d1f1ea5e296 Mon Sep 17 00:00:00 2001 From: Patrick Veilleux Date: Sat, 18 Sep 2021 16:54:55 -0400 Subject: [PATCH 01/12] restructure some function and add a few games --- functions/Backup-Server.psm1 | 8 +- functions/Install-Dependency.psm1 | 34 ++++++ functions/Read-Config.psm1 | 55 +++++++++ functions/Set-IP.psm1 | 18 +++ functions/Test-ServerState.psm1 | 55 +++++++++ functions/Update-Server.psm1 | 70 +++++++----- launchers/run.cmd | 2 +- main.ps1 | 141 +++++------------------ templates/7daystodie.psm1 | 37 ++---- templates/astroneer.psm1 | 178 +++++++++++++++++++++++++++++ templates/insurgencysandstorm.psm1 | 39 ++----- templates/killingfloor2.psm1 | 29 ++--- templates/l4d2.psm1 | 178 +++++++++++++++++++++++++++++ templates/mordhau.psm1 | 178 +++++++++++++++++++++++++++++ templates/pixark.psm1 | 29 ++--- templates/projectzomboid.psm1 | 29 ++--- templates/rust.psm1 | 34 ++---- templates/squad.psm1 | 31 ++--- templates/starbound.psm1 | 178 +++++++++++++++++++++++++++++ templates/stationeers.psm1 | 178 +++++++++++++++++++++++++++++ templates/terraria.psm1 | 178 +++++++++++++++++++++++++++++ templates/theforest.psm1 | 178 +++++++++++++++++++++++++++++ templates/valheim.psm1 | 32 ++---- 23 files changed, 1554 insertions(+), 335 deletions(-) create mode 100644 functions/Install-Dependency.psm1 create mode 100644 functions/Read-Config.psm1 create mode 100644 functions/Set-IP.psm1 create mode 100644 functions/Test-ServerState.psm1 create mode 100644 templates/astroneer.psm1 create mode 100644 templates/l4d2.psm1 create mode 100644 templates/mordhau.psm1 create mode 100644 templates/starbound.psm1 create mode 100644 templates/stationeers.psm1 create mode 100644 templates/terraria.psm1 create mode 100644 templates/theforest.psm1 diff --git a/functions/Backup-Server.psm1 b/functions/Backup-Server.psm1 index 9315dbb..3557aa8 100644 --- a/functions/Backup-Server.psm1 +++ b/functions/Backup-Server.psm1 @@ -3,17 +3,13 @@ function Backup-Server { #Create backup name from date and time $BackupName = Get-TimeStamp #Check if Backups Destination directory exist and create it. - if (-not (Test-Path -Path "$($Backups.Path)\$Type" -PathType "Container")){ + if (-not (Test-Path -Path "$($Backups.Path)\$Type" -PathType "Container" -ErrorAction SilentlyContinue)){ New-Item -Path "$($Backups.Path)\$Type" -ItemType "directory" -ErrorAction SilentlyContinue } #Check if Backups Source directory exist and create it. - if (-not (Test-Path -Path $Backups.Saves -PathType "Container")){ + if (-not (Test-Path -Path $Backups.Saves -PathType "Container" -ErrorAction SilentlyContinue)){ New-Item -Path $Backups.Saves -ItemType "directory" -ErrorAction SilentlyContinue } - #Resolve Server Saves Path - $Backups.Saves = Resolve-Path -Path $Backups.Saves -ErrorAction SilentlyContinue - #Resolve Backup Path - $Backups.Path = Resolve-Path -Path $Backups.Path -ErrorAction SilentlyContinue #Check if it's friday (Sunday is 0) if ((Get-Date -UFormat %u) -eq 5){ $Type = "Weekly" diff --git a/functions/Install-Dependency.psm1 b/functions/Install-Dependency.psm1 new file mode 100644 index 0000000..ecc1581 --- /dev/null +++ b/functions/Install-Dependency.psm1 @@ -0,0 +1,34 @@ +function Install-Dependency { + #Define variables + Write-ScriptMsg "Verifying Dependencies..." + $Dependencies = @{ + SevenZip = $Global.SevenZip + Mcrcon = $Global.Mcrcon + SteamCMD = $Global.SteamCMD + } + + [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] -ErrorAction SilentlyContinue)) { + $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 + + foreach ($Item in $MissingDependencies) { + $Cmd = "Install-$Item" + &$Cmd -Application $Dependencies[$Item] + } + + #Cleanup + Remove-Item -Path ".\downloads" -Recurse -Force -ErrorAction SilentlyContinue + } +} + +Export-ModuleMember -Function Install-Dependency \ No newline at end of file diff --git a/functions/Read-Config.psm1 b/functions/Read-Config.psm1 new file mode 100644 index 0000000..f151484 --- /dev/null +++ b/functions/Read-Config.psm1 @@ -0,0 +1,55 @@ +function Optimize-ArgumentList { + [CmdletBinding()] + [OutputType([System.Collections.ArrayList])] + param ( + [Parameter(Mandatory)] + [array] $ArgumentList + ) + #Create Server.Arguments from cleaned ArgumentList. + [System.Collections.ArrayList]$CleanedArguments=@() + + foreach($Argument in $ArgumentList){ + if (-not ($Argument.EndsWith('=""') -or $Argument.EndsWith('=') -or $Argument.EndsWith(' '))){ + $CleanedArguments.Add($Argument) + } + } + return ($CleanedArguments -join "") +} + +function Resolve-CompletePath { + [CmdletBinding()] + [OutputType([string])] + param ( + [Parameter(Mandatory)] + [string] $Path, + [string] $ParentPath + ) + #Add the full path to the path from the config file. + if ($Path.StartsWith($ParentPath)){ + return "$(Get-Location)$($Path.substring(1))" + } + $ReturnPath = Resolve-Path -LiteralPath $Path -ErrorAction SilentlyContinue + if ($null -eq $ReturnPath) { + $ReturnPath = $Path + } + return $ReturnPath +} + +function Read-Config { + #Read configuration data and improve it by parsing full paths and cleaning arguments + + #Create Long Paths + $Server.Exec = (Resolve-CompletePath -Path $Server.Exec -ParentPath ".\servers\") + $Server.Path = (Resolve-CompletePath -Path $Server.Path -ParentPath ".\servers\") + $Server.ConfigFolder = (Resolve-CompletePath -Path $Server.ConfigFolder -ParentPath ".\servers\") + $Backups.Path = (Resolve-CompletePath -Path $Backups.Path -ParentPath ".\backups\") + $Backups.Saves = (Resolve-CompletePath -Path $Backups.Saves -ParentPath ".\servers\") + $Global.SevenZip = (Resolve-CompletePath -Path $Global.SevenZip -ParentPath ".\tools\") + $Global.Mcrcon = (Resolve-CompletePath -Path $Global.Mcrcon -ParentPath ".\tools\") + $Global.SteamCMD = (Resolve-CompletePath -Path $Global.SteamCMD -ParentPath ".\tools\") + $Global.LogFolder = (Resolve-CompletePath -Path $Global.LogFolder -ParentPath ".\") + + #Create Arguments + Add-Member -InputObject $Server -Name "Arguments" -Type NoteProperty -Value (Optimize-ArgumentList -ArgumentList $Server.ArgumentList) +} +Export-ModuleMember -Function Read-Config, Resolve-CompletePath \ No newline at end of file diff --git a/functions/Set-IP.psm1 b/functions/Set-IP.psm1 new file mode 100644 index 0000000..2137a9f --- /dev/null +++ b/functions/Set-IP.psm1 @@ -0,0 +1,18 @@ +function Set-IP { + #Get current internal ip from active network interface. + Write-ScriptMsg "Finding server IPs..." + $InternalIP = ( + Get-NetIPConfiguration | Where-Object {(($null -ne $_.IPv4DefaultGateway) -and ($_.NetAdapter.Status -ne "Disconnected"))} + ).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 +} +Export-ModuleMember -Function Set-IP \ No newline at end of file diff --git a/functions/Test-ServerState.psm1 b/functions/Test-ServerState.psm1 new file mode 100644 index 0000000..1c41566 --- /dev/null +++ b/functions/Test-ServerState.psm1 @@ -0,0 +1,55 @@ +function Test-ServerState { + #Get the PID from the .PID market file. + $ServerPID = Get-PID + #If it returned 0, it failed to get a PID + if ($null -ne $ServerPID) { + $ServerProcess = Get-Process -ID $ServerPID -ErrorAction SilentlyContinue + } + #If the server process is none-existent, Get the process from the server process name. + if ($null -eq $ServerProcess) { + $ServerProcess = Get-Process -Name $Server.ProcessName -ErrorAction SilentlyContinue + } + #Check if the process was found. + if ($null -eq $ServerProcess) { + Write-ServerMsg "Server is not running." + } else { + #Check if it's the right server via RCON if possible. + $Success = $false + if ($Warnings.Use){ + $Success = Send-Command("help") + if ($Success) { + Write-ServerMsg "Server is responding to remote messages." + } else { + Write-ServerMsg "Server is not responding to remote messages." + } + } + + #If Rcon worked, send stop warning. + if ($Success) { + Write-ServerMsg "Server is running, warning users about upcomming restart." + $Stopped = Send-RestartWarning -ServerProcess $ServerProcess + } else { + #If Server is allow to be closed, close it. + if ($Server.AllowForceClose){ + Write-ServerMsg "Server is running, stopping server." + $Stopped = Stop-Server -ServerProcess $ServerProcess + } + } + + #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." + } else { + if ($Server.AllowForceClose) { + Exit-WithError "Failed to stop server." + } else { + Write-ServerMsg "Server not stopped." + } + } + } + #Unregister the PID + if (-not $(Unregister-PID)) { + Write-ServerMsg "Failed to remove PID file." + } +} +Export-ModuleMember -Function Test-ServerState \ No newline at end of file diff --git a/functions/Update-Server.psm1 b/functions/Update-Server.psm1 index 5858837..96c1660 100644 --- a/functions/Update-Server.psm1 +++ b/functions/Update-Server.psm1 @@ -5,36 +5,48 @@ function Update-Server { [string]$UpdateType ) #Create server directory if not found. - if (-not (Test-Path -Path $Server.Path)){ + if (-not (Test-Path -Path $Server.Path -ErrorAction SilentlyContinue)){ 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 { - if ($Server.Validate) { - $Task = Start-Process $Global.SteamCMD -ArgumentList "+@ShutdownOnFailedCommand 1 +@NoPromptForPassword 1 +login anonymous +force_install_dir $($Server.Path) `"+app_update $($Server.AppID) -beta $($Server.BetaBuild) -betapassword $($Server.BetaBuildPassword)`" -validate +quit" -Wait -PassThru -NoNewWindow - } else { - $Task = Start-Process $Global.SteamCMD -ArgumentList "+@ShutdownOnFailedCommand 1 +@NoPromptForPassword 1 +login anonymous +force_install_dir $($Server.Path) `"+app_update $($Server.AppID) -beta $($Server.BetaBuild) -betapassword $($Server.BetaBuildPassword)`" +quit" -Wait -PassThru -NoNewWindow - } - } catch { - Exit-WithError -ErrorMsg "SteamCMD failed to complete." - } - } else { - Write-ServerMsg "$UpdateType Regular Build." - try { - if ($Server.Validate){ - $Task = Start-Process $Global.SteamCMD -ArgumentList "+@ShutdownOnFailedCommand 1 +@NoPromptForPassword 1 +login anonymous +force_install_dir $($Server.Path) +app_update $($Server.AppID) -validate +quit" -Wait -PassThru -NoNewWindow - } else { - $Task = Start-Process $Global.SteamCMD -ArgumentList "+@ShutdownOnFailedCommand 1 +@NoPromptForPassword 1 +login anonymous +force_install_dir $($Server.Path) +app_update $($Server.AppID) +quit" -Wait -PassThru -NoNewWindow - } - } catch { - Exit-WithError -ErrorMsg "SteamCMD failed to complete." - } - } - #Update Server.Exec value with the full path. - $Server.Exec = Resolve-Path -Path $Server.Exec + <# + String Part if value is null or false or empty string + if () { + String Part if value is defined + } + #> + #Login String + $LoginString = "+@ShutdownOnFailedCommand 1 +@NoPromptForPassword 1 +login anonymous" + if ($Server.Login -ne "anonymous") { + $LoginString = "+login $($Server.Login)" + } + #Validation String + $ValidateString = "" + $ValidatingString = "" + if ($Server.Validate -ne $false){ + $ValidateString = "-validate" + $ValidatingString = "and validating" + } + #Beta Build String + $BetaBuildString = "" + $VersionString = "Regular" + if ($Server.BetaBuild -ne ""){ + $BetaBuildString = "-beta $($Server.BetaBuild)" + $VersionString = "Beta" + } + #Beta Password String + $BetaPasswordString = "" + if ($Server.BetaBuildPassword -ne ""){ + $BetaPasswordString = "-betapassword $($Server.BetaBuildPassword)" + } + + $Arguments = "$LoginString +force_install_dir `"$($Server.Path)`" `"+app_update $($Server.AppID) $BetaBuildString $BetaPasswordString`" $ValidateString +quit" + #Run the update String + Write-ServerMsg "$UpdateType $ValidatingString $VersionString Build." + try { + Start-Process $Global.SteamCMD -ArgumentList $Arguments -Wait -PassThru -NoNewWindow + } + catch { + Exit-WithError -ErrorMsg "SteamCMD failed to complete." + } } Export-ModuleMember -Function Update-Server \ No newline at end of file diff --git a/launchers/run.cmd b/launchers/run.cmd index 1465e1f..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 "squad" \ 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/main.ps1 b/main.ps1 index 4e357a5..ab51dcc 100644 --- a/main.ps1 +++ b/main.ps1 @@ -47,60 +47,13 @@ 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 | - Where-Object { - $_.IPv4DefaultGateway -ne $null -and - $_.NetAdapter.Status -ne "Disconnected" - } -).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 +Set-IP #--------------------------------------------------------- # Install Dependencies #--------------------------------------------------------- -#Define variables -Write-ScriptMsg "Verifying Dependencies..." -$Dependencies = @{ - SevenZip = $Global.SevenZip - Mcrcon = $Global.Mcrcon - SteamCMD = $Global.SteamCMD -} - -[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 - - foreach ($Item in $MissingDependencies) { - $Cmd = "Install-$Item" - &$Cmd -Application $Dependencies[$Item] - } - - #Cleanup - Remove-Item -Path ".\downloads" -Recurse -Force -ErrorAction SilentlyContinue -} +Install-Dependency #--------------------------------------------------------- # Importing server configuration. @@ -108,8 +61,8 @@ if ($MissingDependencies.Count -gt 0){ 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"){ +if (-not (Test-Path -Path ".\configs\$ServerCfg.psm1" -PathType "Leaf" -ErrorAction SilentlyContinue)) { + if (Test-Path -Path ".\templates\$ServerCfg.psm1" -PathType "Leaf" -ErrorAction SilentlyContinue){ Copy-Item -Path ".\templates\$ServerCfg.psm1" -Destination ".\configs\$ServerCfg.psm1" -ErrorAction SilentlyContinue } else { Exit-WithError -ErrorMsg "Unable to find configuration file." @@ -121,19 +74,22 @@ try { Import-Module -Name ".\configs\$ServerCfg.psm1" } catch { - Exit-WithError -ErrorMsg "Unable to server configuration." - exit + Exit-WithError -ErrorMsg "Unable to import server configuration." } +#Parse configuration +Read-Config +Write-Host $global + #--------------------------------------------------------- # Install Server #--------------------------------------------------------- Write-ScriptMsg "Verifying Server installation..." #Flag of a fresh installation in the current instance. -[boolean]$FreshInstall = $false +$FreshInstall = $false #If the server executable is missing, run SteamCMD and install the server. -if (-not(Test-Path -Path $Server.Exec)){ +if (-not (Test-Path -Path $Server.Exec -ErrorAction SilentlyContinue)){ Write-ServerMsg "Server is not installed : Installing $($Server.Name) Server." Update-Server -UpdateType "Installing" Write-ServerMsg "Server successfully installed." @@ -145,59 +101,8 @@ if (-not(Test-Path -Path $Server.Exec)){ #--------------------------------------------------------- Write-ScriptMsg "Verifying Server State..." #If the server is not freshly installed. -if (-not ($FreshInstall)) { - #Get the PID from the .PID market file. - $ServerPID = Get-PID - #If it returned 0, it failed to get a PID - if ($null -ne $ServerPID) { - $ServerProcess = Get-Process -ID $ServerPID -ErrorAction SilentlyContinue - } - #If the server process is none-existent, Get the process from the server process name. - if ($null -ne $ServerProcess) { - $ServerProcess = Get-Process -Name $Server.ProcessName -ErrorAction SilentlyContinue - } - #Check if the process was found. - if ($null -eq $ServerProcess) { - Write-ServerMsg "Server is not running." - } else { - #Check if it's the right server via RCON if possible. - $Success = $false - if ($Warnings.Use){ - $Success = Send-Command("help") - if ($Success) { - Write-ServerMsg "Server is responding to remote messages." - } else { - Write-ServerMsg "Server is not responding to remote messages." - } - } - - #If Rcon worked, send stop warning. - if ($Success) { - Write-ServerMsg "Server is running, warning users about upcomming restart." - $Stopped = Send-RestartWarning -ServerProcess $ServerProcess - } else { - #If Server is allow to be closed, close it. - if ($Server.AllowForceClose){ - Write-ServerMsg "Server is running, stopping server." - $Stopped = Stop-Server -ServerProcess $ServerProcess - } - } - - #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." - } else { - if ($Server.AllowForceClose) { - Exit-WithError "Failed to stop server." - } else { - Write-ServerMsg "Server not stopped." - } - } - } - #Unregister the PID - if (-not $(Unregister-PID)) { - Write-ServerMsg "Failed to remove PID file." - } +if (-not $FreshInstall) { + Test-ServerState } #--------------------------------------------------------- @@ -205,7 +110,7 @@ if (-not ($FreshInstall)) { #--------------------------------------------------------- #If not a fresh install and Backups are enabled, run backups. -if ($Backups.Use -and -not ($FreshInstall)) { +if ($Backups.Use -and -not $FreshInstall) { Write-ScriptMsg "Verifying Backups..." Backup-Server } @@ -215,9 +120,9 @@ if ($Backups.Use -and -not ($FreshInstall)) { #--------------------------------------------------------- #If not a fresh install, update and/or validate server. -if (-not ($FreshInstall)) { +if (-not $FreshInstall) { Write-ScriptMsg "Updating Server..." - Update-Server -UpdateType "Updating / Validating" + Update-Server -UpdateType "Updating" Write-ServerMsg "Server successfully updated and/or validated." } @@ -229,16 +134,16 @@ if (-not ($FreshInstall)) { try { Write-ScriptMsg "Starting Server..." Start-ServerPrep - $App = Start-Process -FilePath $Server.Launcher -WorkingDirectory $Server.WorkingDirectory -ArgumentList $Server.ArgumentList -PassThru + $App = Start-Process -FilePath $Server.Launcher -WorkingDirectory $Server.Path -ArgumentList $Server.Arguments -PassThru #Wait to see if the server is stable. Start-Sleep -Seconds $Server.StartupWaitTime - if (-not ($App) -or $App.HasExited){ + if (($null -eq $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)){ + if (-not (Register-PID -ServerProcess $App)){ Write-ServerMsg "Failed to Register PID file." } } @@ -247,6 +152,14 @@ catch { Exit-WithError -ErrorMsg "Unable to start server." } +#--------------------------------------------------------- +# Open FreshInstall Configuration folder +#--------------------------------------------------------- + +if ($FreshInstall -and (Test-Path -Path $Server.ConfigFolder -PathType "Container" -ErrorAction SilentlyContinue)) { + & explorer.exe $Server.ConfigFolder +} + #--------------------------------------------------------- # Cleanup #--------------------------------------------------------- diff --git a/templates/7daystodie.psm1 b/templates/7daystodie.psm1 index 04c280e..99481e4 100644 --- a/templates/7daystodie.psm1 +++ b/templates/7daystodie.psm1 @@ -5,7 +5,6 @@ #Server Name, use the same name to share game files. $Name = "7DaysToDie" - #--------------------------------------------------------- # Server Configuration #--------------------------------------------------------- @@ -15,6 +14,9 @@ $ServerDetails = @{ #Unique Identifier used to track processes. Must be unique to each servers. UID = 7 + #Login username used by SteamCMD + Login = "anonymous" + #Server Configuration ConfigFile = "$Env:userprofile\AppData\Roaming\7DaysToDie\Saves\serverconfig.xml" @@ -40,12 +42,12 @@ $ServerDetails = @{ #Server Installation Path Path = ".\servers\$Name" + #Server configuration folder + ConfigFolder = "$Env:userprofile\AppData\Roaming\7DaysToDie\Saves\" + #Steam Server App Id AppID = 294420 - - #Use Beta builds $true or $false - Beta = $false - + #Name of the Beta Build BetaBuild = "" @@ -156,7 +158,7 @@ $Warnings = New-Object -TypeName PsObject -Property $WarningsDetails #--------------------------------------------------------- #Launch Arguments -$Arguments = @( +$ArgumentList = @( "-logfile $($Server.LogFile) ", "-configfile=$($Server.ConfigFile) ", "-batchmode ", @@ -165,23 +167,8 @@ $Arguments = @( "-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 = "$(Get-Location)$($Server.Exec.substring(1))" -$WorkingDirectory = "$(Get-Location)$($Server.Path.substring(1))" - Add-Member -InputObject $Server -Name "ArgumentList" -Type NoteProperty -Value $ArgumentList -Add-Member -InputObject $Server -Name "Launcher" -Type NoteProperty -Value $Launcher -Add-Member -InputObject $Server -Name "WorkingDirectory" -Type NoteProperty -Value $WorkingDirectory +Add-Member -InputObject $Server -Name "Launcher" -Type NoteProperty -Value $Server.Exec #--------------------------------------------------------- # Function that runs just before the server starts. @@ -193,11 +180,11 @@ function Start-ServerPrep { #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)){ + if (-not (Test-Path -Path $ConfigFilePath -ErrorAction SilentlyContinue)){ 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 + If(-not (Test-Path -Path $Server.ConfigFile -PathType "leaf" -ErrorAction SilentlyContinue)){ + Copy-Item -Path "$($Server.Path)\serverconfig.xml" -Destination $Server.ConfigFile -Force -ErrorAction SilentlyContinue } } diff --git a/templates/astroneer.psm1 b/templates/astroneer.psm1 new file mode 100644 index 0000000..4003e7e --- /dev/null +++ b/templates/astroneer.psm1 @@ -0,0 +1,178 @@ +<# + ".\servers\$Name\Multiplayer\config.cfg" +#> + +#Server Name, use the same name to share game files. +$Name = "Terraria" + +#--------------------------------------------------------- +# Server Configuration +#--------------------------------------------------------- + +$ServerDetails = @{ + + #Unique Identifier used to track processes. Must be unique to each servers. + UID = 9 + + #Login username used by SteamCMD + Login = "anonymous" + + #Name of the server in the Server Browser + ConfigFile = ".\servers\$Name\Multiplayer\config.cfg" + + #Rcon IP (not supported by valheim yet.) + 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" + + #Server configuration folder + ConfigFolder = "." + + #Steam Server App Id + AppID = + + #Name of the Beta Build + BetaBuild = "" + + #Beta Build Password + BetaBuildPassword = "" + + #Process name in the task manager + ProcessName = "TerrariaServer" + + #ProjectZomboid64.exe + Exec = ".\servers\$Name\TerrariaServer.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 + + #How long should it wait to check if the server is stable + StartupWaitTime = 10 +} +#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" +} +#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 +$ArgumentList = @( + "-batchmode ", + "-dedicated ", + "-nographics ", + "-nosteamclient ", + "-configfilepath `"$($Server.ConfigFile)`"" +) +Add-Member -InputObject $Server -Name "ArgumentList" -Type NoteProperty -Value $ArgumentList +Add-Member -InputObject $Server -Name "Launcher" -Type NoteProperty -Value $Server.Exec + +#--------------------------------------------------------- +# Function that runs just before the server starts. +#--------------------------------------------------------- + +function Start-ServerPrep { + + Write-ScriptMsg "Port Forward : $($server.Port) in TCP and UDP to $($Global.InternalIP)" + +} + +Export-ModuleMember -Function Start-ServerPrep -Variable @("Server","Backups","Warnings") \ No newline at end of file diff --git a/templates/insurgencysandstorm.psm1 b/templates/insurgencysandstorm.psm1 index 49bb171..68c54e1 100644 --- a/templates/insurgencysandstorm.psm1 +++ b/templates/insurgencysandstorm.psm1 @@ -15,6 +15,9 @@ $ServerDetails = @{ #Unique Identifier used to track processes. Must be unique to each servers. UID = 2 + #Login username used by SteamCMD + Login = "anonymous" + #Name of the server in the Server Browser SessionName = "My Insurgency Server" @@ -60,9 +63,6 @@ $ServerDetails = @{ #Official RuleSet OfficialRulesSet = "OfficialRules" - #Enable Rcon $true or $false - EnableRcon = $true - #Rcon IP, usually localhost ManagementIP = "127.0.0.1" @@ -82,12 +82,12 @@ $ServerDetails = @{ #Server Installation Path Path = ".\servers\$Name" + #Server configuration folder + ConfigFolder = ".\servers\$Name\Saved\Config\WindowsServer" + #Steam Server App Id AppID = 581330 - #Use Beta builds $true or $false - Beta = $false - #Name of the Beta Build BetaBuild = "" @@ -197,7 +197,7 @@ $Warnings = New-Object -TypeName PsObject -Property $WarningsDetails # Launch Arguments #--------------------------------------------------------- -$Arguments = @( +$ArgumentList = @( "$($Server.Map)", "?Scenario=$($Server.Scenario)", "?MaxPlayers=$($Server.MaxPlayers)", @@ -214,32 +214,11 @@ $Arguments = @( "-ruleset=`"$($Server.OfficialRulesSet)`" ", "-CmdModList=`"$($Server.Mods)`" ", "-mutators=`"$($Server.Mutators)`" ", + "-Rcon -RconListenPort=`"$($Server.ManagementPort)`" -RconPassword=`"$($Server.ManagementPassword)`" ", "-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 = "$(Get-Location)$($Server.Exec.substring(1))" -$WorkingDirectory = "$(Get-Location)$($Server.Path.substring(1))" - Add-Member -InputObject $Server -Name "ArgumentList" -Type NoteProperty -Value $ArgumentList -Add-Member -InputObject $Server -Name "Launcher" -Type NoteProperty -Value $Launcher -Add-Member -InputObject $Server -Name "WorkingDirectory" -Type NoteProperty -Value $WorkingDirectory +Add-Member -InputObject $Server -Name "Launcher" -Type NoteProperty -Value $Server.Exec #--------------------------------------------------------- # Function that runs just before the server starts. diff --git a/templates/killingfloor2.psm1 b/templates/killingfloor2.psm1 index e12fd2a..c4e6a3a 100644 --- a/templates/killingfloor2.psm1 +++ b/templates/killingfloor2.psm1 @@ -16,6 +16,9 @@ $ServerDetails = @{ #Unique Identifier used to track processes. Must be unique to each servers. UID = 6 + #Login username used by SteamCMD + Login = "anonymous" + #This is the admin username for WebAdmin if you're configuring WebAdmin via Commandline AdminName = "admin" @@ -62,12 +65,12 @@ $ServerDetails = @{ #Server Installation Path Path = ".\servers\$Name" + #Server Configuration + ConfigFolder = ".\servers\$Name\KFGame\Config\" + #Steam Server App Id AppID = 232130 - #Use Beta builds $true or $false - Beta = $false - #Name of the Beta Build BetaBuild = "" @@ -178,7 +181,7 @@ $Warnings = New-Object -TypeName PsObject -Property $WarningsDetails #--------------------------------------------------------- #Launch Arguments -$Arguments = @( +$ArgumentList = @( "$($Server.Map)", "?Game=$($Server.GameMode)", "?MaxPlayers=$($Server.MaxPlayers)", @@ -189,24 +192,8 @@ $Arguments = @( "-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 = "$(Get-Location)$($Server.Exec.substring(1))" -$WorkingDirectory = "$(Get-Location)$($Server.Path.substring(1))" - Add-Member -InputObject $Server -Name "ArgumentList" -Type NoteProperty -Value $ArgumentList -Add-Member -InputObject $Server -Name "Launcher" -Type NoteProperty -Value $Launcher -Add-Member -InputObject $Server -Name "WorkingDirectory" -Type NoteProperty -Value $WorkingDirectory +Add-Member -InputObject $Server -Name "Launcher" -Type NoteProperty -Value $Server.Exec #--------------------------------------------------------- # Function that runs just before the server starts. diff --git a/templates/l4d2.psm1 b/templates/l4d2.psm1 new file mode 100644 index 0000000..4003e7e --- /dev/null +++ b/templates/l4d2.psm1 @@ -0,0 +1,178 @@ +<# + ".\servers\$Name\Multiplayer\config.cfg" +#> + +#Server Name, use the same name to share game files. +$Name = "Terraria" + +#--------------------------------------------------------- +# Server Configuration +#--------------------------------------------------------- + +$ServerDetails = @{ + + #Unique Identifier used to track processes. Must be unique to each servers. + UID = 9 + + #Login username used by SteamCMD + Login = "anonymous" + + #Name of the server in the Server Browser + ConfigFile = ".\servers\$Name\Multiplayer\config.cfg" + + #Rcon IP (not supported by valheim yet.) + 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" + + #Server configuration folder + ConfigFolder = "." + + #Steam Server App Id + AppID = + + #Name of the Beta Build + BetaBuild = "" + + #Beta Build Password + BetaBuildPassword = "" + + #Process name in the task manager + ProcessName = "TerrariaServer" + + #ProjectZomboid64.exe + Exec = ".\servers\$Name\TerrariaServer.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 + + #How long should it wait to check if the server is stable + StartupWaitTime = 10 +} +#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" +} +#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 +$ArgumentList = @( + "-batchmode ", + "-dedicated ", + "-nographics ", + "-nosteamclient ", + "-configfilepath `"$($Server.ConfigFile)`"" +) +Add-Member -InputObject $Server -Name "ArgumentList" -Type NoteProperty -Value $ArgumentList +Add-Member -InputObject $Server -Name "Launcher" -Type NoteProperty -Value $Server.Exec + +#--------------------------------------------------------- +# Function that runs just before the server starts. +#--------------------------------------------------------- + +function Start-ServerPrep { + + Write-ScriptMsg "Port Forward : $($server.Port) in TCP and UDP to $($Global.InternalIP)" + +} + +Export-ModuleMember -Function Start-ServerPrep -Variable @("Server","Backups","Warnings") \ No newline at end of file diff --git a/templates/mordhau.psm1 b/templates/mordhau.psm1 new file mode 100644 index 0000000..019434b --- /dev/null +++ b/templates/mordhau.psm1 @@ -0,0 +1,178 @@ +<# + ".\servers\$Name\Multiplayer\config.cfg" +#> + +#Server Name, use the same name to share game files. +$Name = "Mordhau" + +#--------------------------------------------------------- +# Server Configuration +#--------------------------------------------------------- + +$ServerDetails = @{ + + #Unique Identifier used to track processes. Must be unique to each servers. + UID = 9 + + #Login username used by SteamCMD + Login = "anonymous" + + #Name of the server in the Server Browser + ConfigFile = ".\servers\$Name\Multiplayer\config.cfg" + + #Rcon IP (not supported by valheim yet.) + 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" + + #Server configuration folder + ConfigFolder = ".\servers\$Name\Multiplayer\" + + #Steam Server App Id + AppID = 105610 + + #Name of the Beta Build + BetaBuild = "" + + #Beta Build Password + BetaBuildPassword = "" + + #Process name in the task manager + ProcessName = "TerrariaServer" + + #ProjectZomboid64.exe + Exec = ".\servers\$Name\TerrariaServer.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 + + #How long should it wait to check if the server is stable + StartupWaitTime = 10 +} +#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" +} +#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 +$ArgumentList = @( + "-batchmode ", + "-dedicated ", + "-nographics ", + "-nosteamclient ", + "-configfilepath `"$($Server.ConfigFile)`"" +) +Add-Member -InputObject $Server -Name "ArgumentList" -Type NoteProperty -Value $ArgumentList +Add-Member -InputObject $Server -Name "Launcher" -Type NoteProperty -Value $Server.Exec + +#--------------------------------------------------------- +# Function that runs just before the server starts. +#--------------------------------------------------------- + +function Start-ServerPrep { + + Write-ScriptMsg "Port Forward : $($server.Port) in TCP and UDP to $($Global.InternalIP)" + +} + +Export-ModuleMember -Function Start-ServerPrep -Variable @("Server","Backups","Warnings") \ No newline at end of file diff --git a/templates/pixark.psm1 b/templates/pixark.psm1 index dfa64c9..2a2b495 100644 --- a/templates/pixark.psm1 +++ b/templates/pixark.psm1 @@ -35,6 +35,9 @@ $ServerDetails = @{ #Unique Identifier used to track processes. Must be unique to each servers. UID = 3 + #Login username used by SteamCMD + Login = "anonymous" + #Name of the server in the Server Browser SessionName = "My Pixark Server" @@ -90,12 +93,12 @@ $ServerDetails = @{ #Server Installation Path Path = ".\servers\$Name" + #Server configuration folder + ConfigFolder = ".\servers\$Name\ShooterGame\Saved\Config\WindowsServer\" + #Steam Server App Id AppID = 824360 - #Use Beta builds $true or $false - Beta = $false - #Name of the Beta Build BetaBuild = "" @@ -206,7 +209,7 @@ $Warnings = New-Object -TypeName PsObject -Property $WarningsDetails #--------------------------------------------------------- #Launch Arguments -$Arguments = @( +$ArgumentList = @( "$($Server.WorldType)", "?listen", "?Multihome=$($Server.InternalIP)", @@ -230,24 +233,8 @@ $Arguments = @( "-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 = "$(Get-Location)$($Server.Exec.substring(1))" -$WorkingDirectory = "$(Get-Location)$($Server.Path.substring(1))" - Add-Member -InputObject $Server -Name "ArgumentList" -Type NoteProperty -Value $ArgumentList -Add-Member -InputObject $Server -Name "Launcher" -Type NoteProperty -Value $Launcher -Add-Member -InputObject $Server -Name "WorkingDirectory" -Type NoteProperty -Value $WorkingDirectory +Add-Member -InputObject $Server -Name "Launcher" -Type NoteProperty -Value $Server.Exec #--------------------------------------------------------- # Function that runs just before the server starts. diff --git a/templates/projectzomboid.psm1 b/templates/projectzomboid.psm1 index 0f48bc8..bb24247 100644 --- a/templates/projectzomboid.psm1 +++ b/templates/projectzomboid.psm1 @@ -42,6 +42,9 @@ $ServerDetails = @{ #Unique Identifier used to track processes. Must be unique to each servers. UID = 4 + #Login username used by SteamCMD + Login = "anonymous" + #Rcon IP, usually localhost ManagementIP = "127.0.0.1" @@ -61,12 +64,12 @@ $ServerDetails = @{ #Server Installation Path Path = ".\servers\$Name" + #Server configuration folder + ConfigFolder = "$Env:userprofile\Zomboid\Server\" + #Steam Server App Id AppID = 380870 - #Use Beta builds $true or $false - Beta = $false - #Name of the Beta Build BetaBuild = "iwillbackupmysave" @@ -189,7 +192,7 @@ $PZ_CLASSPATH_LIST = @( $PZ_CLASSPATH = $PZ_CLASSPATH_LIST -join "" #Launch Arguments -$Arguments = @( +$ArgumentList = @( "-Dzomboid.steam=1 ", "-Dzomboid.znetlog=1 ", "-XX:+UseConcMarkSweepGC ", @@ -200,24 +203,8 @@ $Arguments = @( "-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 "" - -#Server Launcher -$Launcher = "$(Get-Location)$($Server.Exec.substring(1))" -$WorkingDirectory = "$(Get-Location)$($Server.Path.substring(1))" - Add-Member -InputObject $Server -Name "ArgumentList" -Type NoteProperty -Value $ArgumentList -Add-Member -InputObject $Server -Name "Launcher" -Type NoteProperty -Value $Launcher -Add-Member -InputObject $Server -Name "WorkingDirectory" -Type NoteProperty -Value $WorkingDirectory +Add-Member -InputObject $Server -Name "Launcher" -Type NoteProperty -Value "$($Server.Path)\jre64\bin\java.exe" #--------------------------------------------------------- # Function that runs just before the server starts. diff --git a/templates/rust.psm1 b/templates/rust.psm1 index 732a9b5..d2614b2 100644 --- a/templates/rust.psm1 +++ b/templates/rust.psm1 @@ -5,6 +5,9 @@ Edit configuration in ".\servers\Rust\server\[Identity]\cfg\serverauto.cfg" #Server Name, use the same name to share game files. $Name = "Rust" +#Identity of the server +$Identity = "RustServer01" + #--------------------------------------------------------- # Server Configuration #--------------------------------------------------------- @@ -14,11 +17,14 @@ $ServerDetails = @{ #Unique Identifier used to track processes. Must be unique to each servers. UID = 8 + #Login username used by SteamCMD + Login = "anonymous" + #Name of the server Hostname = "My Rust Server" #Identity of the server - Identity = "RustServer01" + Identity = $Identity #Description of the server \n for new line Description = "Welcome to my server" @@ -93,12 +99,12 @@ $ServerDetails = @{ #Server Installation Path Path = ".\servers\$Name" + #Server configuration folder + ConfigFolder = ".\servers\$Name\server\$Identity\cfg\" + #Steam Server App Id AppID = 258550 - #Use Beta builds $true or $false - Beta = $false - #Name of the Beta Build BetaBuild = "" @@ -209,7 +215,7 @@ $Warnings = New-Object -TypeName PsObject -Property $WarningsDetails #--------------------------------------------------------- #Launch Arguments -$Arguments = @( +$ArgumentList = @( "-batchmode ", "-nographics ", "+server.ip $($Global.InternalIP) ", @@ -239,24 +245,8 @@ $Arguments = @( "+rcon.web $($Server.rconVersion) ", "-logfile $($Server.Identity).txt " ) - -[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 = "$(Get-Location)$($Server.Exec.substring(1))" -$WorkingDirectory = "$(Get-Location)$($Server.Path.substring(1))" - Add-Member -InputObject $Server -Name "ArgumentList" -Type NoteProperty -Value $ArgumentList -Add-Member -InputObject $Server -Name "Launcher" -Type NoteProperty -Value $Launcher -Add-Member -InputObject $Server -Name "WorkingDirectory" -Type NoteProperty -Value $WorkingDirectory +Add-Member -InputObject $Server -Name "Launcher" -Type NoteProperty -Value $Server.Exec #--------------------------------------------------------- # Function that runs just before the server starts. diff --git a/templates/squad.psm1 b/templates/squad.psm1 index 3e03914..ef78886 100644 --- a/templates/squad.psm1 +++ b/templates/squad.psm1 @@ -13,6 +13,9 @@ $ServerDetails = @{ #Unique Identifier used to track processes. Must be unique to each servers. UID = 1 + #Login username used by SteamCMD + Login = "anonymous" + #Randomize First Map NONE OR ALWAYS RandomMap = "ALWAYS" @@ -44,12 +47,12 @@ $ServerDetails = @{ #Server Installation Path Path = ".\servers\$Name" + #Server configuration folder + ConfigFolder = + #Steam Server App Id AppID = 403240 - #Use Beta builds $true or $false - Beta = $false - #Name of the Beta Build BetaBuild = "" @@ -160,7 +163,7 @@ $Warnings = New-Object -TypeName PsObject -Property $WarningsDetails #--------------------------------------------------------- #Launch Arguments -$Arguments = @( +$ArgumentList = @( "Multihome=$($Global.InternalIP) ", "Port=$($Server.Port) ", "QueryPort=$($Server.QueryPort) ", @@ -168,24 +171,8 @@ $Arguments = @( "RANDOM $($Server.RandomMap) ", "-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 = "$(Get-Location)$($Server.Exec.substring(1))" -$WorkingDirectory = "$(Get-Location)$($Server.Path.substring(1))" - Add-Member -InputObject $Server -Name "ArgumentList" -Type NoteProperty -Value $ArgumentList -Add-Member -InputObject $Server -Name "Launcher" -Type NoteProperty -Value $Launcher -Add-Member -InputObject $Server -Name "WorkingDirectory" -Type NoteProperty -Value $WorkingDirectory +Add-Member -InputObject $Server -Name "Launcher" -Type NoteProperty -Value $Server.Exec #--------------------------------------------------------- # Function that runs just before the server starts. @@ -193,7 +180,7 @@ Add-Member -InputObject $Server -Name "WorkingDirectory" -Type NoteProperty -Val function Start-ServerPrep { - Write-ScriptMsg "Port Forward : $($server.Port) in TCP and UDP to $($Global.InternalIP)" + Write-ScriptMsg "Port Forward : $($server.Port) and $($server.QueryPort) in TCP and UDP to $($Global.InternalIP)" } diff --git a/templates/starbound.psm1 b/templates/starbound.psm1 new file mode 100644 index 0000000..4003e7e --- /dev/null +++ b/templates/starbound.psm1 @@ -0,0 +1,178 @@ +<# + ".\servers\$Name\Multiplayer\config.cfg" +#> + +#Server Name, use the same name to share game files. +$Name = "Terraria" + +#--------------------------------------------------------- +# Server Configuration +#--------------------------------------------------------- + +$ServerDetails = @{ + + #Unique Identifier used to track processes. Must be unique to each servers. + UID = 9 + + #Login username used by SteamCMD + Login = "anonymous" + + #Name of the server in the Server Browser + ConfigFile = ".\servers\$Name\Multiplayer\config.cfg" + + #Rcon IP (not supported by valheim yet.) + 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" + + #Server configuration folder + ConfigFolder = "." + + #Steam Server App Id + AppID = + + #Name of the Beta Build + BetaBuild = "" + + #Beta Build Password + BetaBuildPassword = "" + + #Process name in the task manager + ProcessName = "TerrariaServer" + + #ProjectZomboid64.exe + Exec = ".\servers\$Name\TerrariaServer.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 + + #How long should it wait to check if the server is stable + StartupWaitTime = 10 +} +#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" +} +#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 +$ArgumentList = @( + "-batchmode ", + "-dedicated ", + "-nographics ", + "-nosteamclient ", + "-configfilepath `"$($Server.ConfigFile)`"" +) +Add-Member -InputObject $Server -Name "ArgumentList" -Type NoteProperty -Value $ArgumentList +Add-Member -InputObject $Server -Name "Launcher" -Type NoteProperty -Value $Server.Exec + +#--------------------------------------------------------- +# Function that runs just before the server starts. +#--------------------------------------------------------- + +function Start-ServerPrep { + + Write-ScriptMsg "Port Forward : $($server.Port) in TCP and UDP to $($Global.InternalIP)" + +} + +Export-ModuleMember -Function Start-ServerPrep -Variable @("Server","Backups","Warnings") \ No newline at end of file diff --git a/templates/stationeers.psm1 b/templates/stationeers.psm1 new file mode 100644 index 0000000..4003e7e --- /dev/null +++ b/templates/stationeers.psm1 @@ -0,0 +1,178 @@ +<# + ".\servers\$Name\Multiplayer\config.cfg" +#> + +#Server Name, use the same name to share game files. +$Name = "Terraria" + +#--------------------------------------------------------- +# Server Configuration +#--------------------------------------------------------- + +$ServerDetails = @{ + + #Unique Identifier used to track processes. Must be unique to each servers. + UID = 9 + + #Login username used by SteamCMD + Login = "anonymous" + + #Name of the server in the Server Browser + ConfigFile = ".\servers\$Name\Multiplayer\config.cfg" + + #Rcon IP (not supported by valheim yet.) + 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" + + #Server configuration folder + ConfigFolder = "." + + #Steam Server App Id + AppID = + + #Name of the Beta Build + BetaBuild = "" + + #Beta Build Password + BetaBuildPassword = "" + + #Process name in the task manager + ProcessName = "TerrariaServer" + + #ProjectZomboid64.exe + Exec = ".\servers\$Name\TerrariaServer.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 + + #How long should it wait to check if the server is stable + StartupWaitTime = 10 +} +#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" +} +#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 +$ArgumentList = @( + "-batchmode ", + "-dedicated ", + "-nographics ", + "-nosteamclient ", + "-configfilepath `"$($Server.ConfigFile)`"" +) +Add-Member -InputObject $Server -Name "ArgumentList" -Type NoteProperty -Value $ArgumentList +Add-Member -InputObject $Server -Name "Launcher" -Type NoteProperty -Value $Server.Exec + +#--------------------------------------------------------- +# Function that runs just before the server starts. +#--------------------------------------------------------- + +function Start-ServerPrep { + + Write-ScriptMsg "Port Forward : $($server.Port) in TCP and UDP to $($Global.InternalIP)" + +} + +Export-ModuleMember -Function Start-ServerPrep -Variable @("Server","Backups","Warnings") \ No newline at end of file diff --git a/templates/terraria.psm1 b/templates/terraria.psm1 new file mode 100644 index 0000000..4003e7e --- /dev/null +++ b/templates/terraria.psm1 @@ -0,0 +1,178 @@ +<# + ".\servers\$Name\Multiplayer\config.cfg" +#> + +#Server Name, use the same name to share game files. +$Name = "Terraria" + +#--------------------------------------------------------- +# Server Configuration +#--------------------------------------------------------- + +$ServerDetails = @{ + + #Unique Identifier used to track processes. Must be unique to each servers. + UID = 9 + + #Login username used by SteamCMD + Login = "anonymous" + + #Name of the server in the Server Browser + ConfigFile = ".\servers\$Name\Multiplayer\config.cfg" + + #Rcon IP (not supported by valheim yet.) + 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" + + #Server configuration folder + ConfigFolder = "." + + #Steam Server App Id + AppID = + + #Name of the Beta Build + BetaBuild = "" + + #Beta Build Password + BetaBuildPassword = "" + + #Process name in the task manager + ProcessName = "TerrariaServer" + + #ProjectZomboid64.exe + Exec = ".\servers\$Name\TerrariaServer.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 + + #How long should it wait to check if the server is stable + StartupWaitTime = 10 +} +#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" +} +#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 +$ArgumentList = @( + "-batchmode ", + "-dedicated ", + "-nographics ", + "-nosteamclient ", + "-configfilepath `"$($Server.ConfigFile)`"" +) +Add-Member -InputObject $Server -Name "ArgumentList" -Type NoteProperty -Value $ArgumentList +Add-Member -InputObject $Server -Name "Launcher" -Type NoteProperty -Value $Server.Exec + +#--------------------------------------------------------- +# Function that runs just before the server starts. +#--------------------------------------------------------- + +function Start-ServerPrep { + + Write-ScriptMsg "Port Forward : $($server.Port) in TCP and UDP to $($Global.InternalIP)" + +} + +Export-ModuleMember -Function Start-ServerPrep -Variable @("Server","Backups","Warnings") \ No newline at end of file diff --git a/templates/theforest.psm1 b/templates/theforest.psm1 new file mode 100644 index 0000000..7e21e47 --- /dev/null +++ b/templates/theforest.psm1 @@ -0,0 +1,178 @@ +<# + ".\servers\$Name\Multiplayer\config.cfg" +#> + +#Server Name, use the same name to share game files. +$Name = "TheForest" + +#--------------------------------------------------------- +# Server Configuration +#--------------------------------------------------------- + +$ServerDetails = @{ + + #Unique Identifier used to track processes. Must be unique to each servers. + UID = 9 + + #Login username used by SteamCMD + Login = "anonymous" + + #Name of the server in the Server Browser + ConfigFile = ".\servers\$Name\Multiplayer\config.cfg" + + #Rcon IP (not supported by valheim yet.) + 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" + + #Server configuration folder + ConfigFolder = "." + + #Steam Server App Id + AppID = 556450 + + #Name of the Beta Build + BetaBuild = "" + + #Beta Build Password + BetaBuildPassword = "" + + #Process name in the task manager + ProcessName = "TheForestDedicatedServer" + + #ProjectZomboid64.exe + Exec = ".\servers\$Name\TheForestDedicatedServer.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 + + #How long should it wait to check if the server is stable + StartupWaitTime = 10 +} +#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\Multiplayer" +} +#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 +$ArgumentList = @( + "-batchmode ", + "-dedicated ", + "-nographics ", + "-nosteamclient ", + "-configfilepath `"$($Server.ConfigFile)`"" +) +Add-Member -InputObject $Server -Name "ArgumentList" -Type NoteProperty -Value $ArgumentList +Add-Member -InputObject $Server -Name "Launcher" -Type NoteProperty -Value $Server.Exec + +#--------------------------------------------------------- +# Function that runs just before the server starts. +#--------------------------------------------------------- + +function Start-ServerPrep { + + Write-ScriptMsg "Port Forward : $($server.Port) in TCP and UDP to $($Global.InternalIP)" + +} + +Export-ModuleMember -Function Start-ServerPrep -Variable @("Server","Backups","Warnings") \ No newline at end of file diff --git a/templates/valheim.psm1 b/templates/valheim.psm1 index 9d3712f..71c02ee 100644 --- a/templates/valheim.psm1 +++ b/templates/valheim.psm1 @@ -1,4 +1,3 @@ - #Server Name, use the same name to share game files. $Name = "Valheim" @@ -11,6 +10,9 @@ $ServerDetails = @{ #Unique Identifier used to track processes. Must be unique to each servers. UID = 5 + #Login username used by SteamCMD + Login = "anonymous" + #Name of the server in the Server Browser SessionName = "My Valheim Server" @@ -24,7 +26,7 @@ $ServerDetails = @{ Port = 2459 #Rcon IP (not supported by valheim yet.) - ManagementIP = "" + ManagementIP = "127.0.0.1" #Rcon Port ManagementPort = "" @@ -42,12 +44,12 @@ $ServerDetails = @{ #Server Installation Path Path = ".\servers\$Name" + #Server configuration folder + ConfigFolder = "$Env:userprofile\AppData\LocalLow\IronGate\Valheim" + #Steam Server App Id AppID = 896660 - #Use Beta builds $true or $false - Beta = $false - #Name of the Beta Build BetaBuild = "" @@ -158,7 +160,7 @@ $Warnings = New-Object -TypeName PsObject -Property $WarningsDetails #--------------------------------------------------------- #Launch Arguments -$Arguments = @( +$ArgumentList = @( "-batchmode ", "-nographics ", "-name $($Server.SessionName) ", @@ -167,24 +169,8 @@ $Arguments = @( "-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 = "$(Get-Location)$($Server.Exec.substring(1))" -$WorkingDirectory = "$(Get-Location)$($Server.Path.substring(1))" - Add-Member -InputObject $Server -Name "ArgumentList" -Type NoteProperty -Value $ArgumentList -Add-Member -InputObject $Server -Name "Launcher" -Type NoteProperty -Value $Launcher -Add-Member -InputObject $Server -Name "WorkingDirectory" -Type NoteProperty -Value $WorkingDirectory +Add-Member -InputObject $Server -Name "Launcher" -Type NoteProperty -Value $Server.Exec #--------------------------------------------------------- # Function that runs just before the server starts. From 492db63591f4105a7cd13329993ab74ced89e973 Mon Sep 17 00:00:00 2001 From: Patrick Veilleux Date: Sat, 18 Sep 2021 21:37:12 -0400 Subject: [PATCH 02/12] Improve download speed and add Terraria --- functions/Get-WebFile.psm1 | 26 +++++++ functions/Install-Mcrcon.psm1 | 2 +- functions/Install-SevenZip.psm1 | 4 +- functions/Install-SteamCMD.psm1 | 2 +- functions/Update-Server.psm1 | 4 + launchers/run.cmd | 2 +- main.ps1 | 4 +- templates/7daystodie.psm1 | 4 +- templates/astroneer.psm1 | 8 +- templates/insurgencysandstorm.psm1 | 4 +- templates/killingfloor2.psm1 | 4 +- templates/{l4d2.psm1 => left4dead2.psm1} | 6 +- templates/mordhau.psm1 | 4 +- templates/pixark.psm1 | 4 +- templates/projectzomboid.psm1 | 4 +- templates/rust.psm1 | 4 +- templates/squad.psm1 | 4 +- templates/starbound.psm1 | 6 +- templates/stationeers.psm1 | 6 +- templates/terraria.psm1 | 93 ++++++++++++++++++++---- templates/theforest.psm1 | 6 +- templates/valheim.psm1 | 4 +- 22 files changed, 148 insertions(+), 57 deletions(-) create mode 100644 functions/Get-WebFile.psm1 rename templates/{l4d2.psm1 => left4dead2.psm1} (98%) diff --git a/functions/Get-WebFile.psm1 b/functions/Get-WebFile.psm1 new file mode 100644 index 0000000..7e20dfd --- /dev/null +++ b/functions/Get-WebFile.psm1 @@ -0,0 +1,26 @@ +function Invoke-Download { + [CmdletBinding()] + param ( + [Parameter(Mandatory)] + $Uri, + $OutFile + ) + + # Create the HTTP client download request + $httpClient = New-Object System.Net.Http.HttpClient + $response = $httpClient.GetAsync($Uri) + $response.Wait() + + # Create a file stream to pointed to the output file destination + $outputFileStream = [System.IO.FileStream]::new($OutFile, [System.IO.FileMode]::Create, [System.IO.FileAccess]::Write) + + # Stream the download to the destination file stream + $downloadTask = $response.Result.Content.CopyToAsync($outputFileStream) + $downloadTask.Wait() + + # Close the file stream + $outputFileStream.Close() + +} + +Export-ModuleMember -Function Invoke-Download \ No newline at end of file diff --git a/functions/Install-Mcrcon.psm1 b/functions/Install-Mcrcon.psm1 index 0054657..d17ad9e 100644 --- a/functions/Install-Mcrcon.psm1 +++ b/functions/Install-Mcrcon.psm1 @@ -8,7 +8,7 @@ function Install-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 + Invoke-Download -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. diff --git a/functions/Install-SevenZip.psm1 b/functions/Install-SevenZip.psm1 index 6d0e67d..8ee76fd 100644 --- a/functions/Install-SevenZip.psm1 +++ b/functions/Install-SevenZip.psm1 @@ -7,12 +7,12 @@ 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" + Invoke-Download -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 + Invoke-Download -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. diff --git a/functions/Install-SteamCMD.psm1 b/functions/Install-SteamCMD.psm1 index 2a00414..2ac31c4 100644 --- a/functions/Install-SteamCMD.psm1 +++ b/functions/Install-SteamCMD.psm1 @@ -6,7 +6,7 @@ function Install-SteamCMD { ) Write-ServerMsg "Downloading SteamCMD." #Download file - Invoke-WebRequest -Uri "https://steamcdn-a.akamaihd.net/client/installer/steamcmd.zip" -OutFile ".\downloads\steamcmd.zip" -ErrorAction SilentlyContinue + Invoke-Download -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/Update-Server.psm1 b/functions/Update-Server.psm1 index 96c1660..d0395a0 100644 --- a/functions/Update-Server.psm1 +++ b/functions/Update-Server.psm1 @@ -8,6 +8,10 @@ function Update-Server { if (-not (Test-Path -Path $Server.Path -ErrorAction SilentlyContinue)){ New-Item -ItemType "directory" -Path $Server.Path -ErrorAction SilentlyContinue } + #Skip install if AppID is 0 + if ($Server.AppID -eq 0){ + return + } <# String Part if value is null or false or empty string if () { diff --git a/launchers/run.cmd b/launchers/run.cmd index 0904e89..262a546 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 "terraria" \ No newline at end of file diff --git a/main.ps1 b/main.ps1 index ab51dcc..83e9af4 100644 --- a/main.ps1 +++ b/main.ps1 @@ -79,7 +79,6 @@ catch { #Parse configuration Read-Config -Write-Host $global #--------------------------------------------------------- # Install Server @@ -132,8 +131,9 @@ if (-not $FreshInstall) { #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..." + Write-ScriptMsg "Starting Server Preparation..." Start-ServerPrep + Write-ScriptMsg "Starting Server..." $App = Start-Process -FilePath $Server.Launcher -WorkingDirectory $Server.Path -ArgumentList $Server.Arguments -PassThru #Wait to see if the server is stable. Start-Sleep -Seconds $Server.StartupWaitTime diff --git a/templates/7daystodie.psm1 b/templates/7daystodie.psm1 index 99481e4..0e30009 100644 --- a/templates/7daystodie.psm1 +++ b/templates/7daystodie.psm1 @@ -12,7 +12,7 @@ $Name = "7DaysToDie" $ServerDetails = @{ #Unique Identifier used to track processes. Must be unique to each servers. - UID = 7 + UID = "7DaysToDie_1" #Login username used by SteamCMD Login = "anonymous" @@ -57,7 +57,7 @@ $ServerDetails = @{ #Process name in the task manager ProcessName = "7DaysToDieServer" - #ProjectZomboid64.exe + #Server Executable Exec = ".\servers\$Name\7DaysToDieServer.exe" #Allow force close, usefull for server without RCON and Multiple instances. diff --git a/templates/astroneer.psm1 b/templates/astroneer.psm1 index 4003e7e..ad07df2 100644 --- a/templates/astroneer.psm1 +++ b/templates/astroneer.psm1 @@ -3,7 +3,7 @@ #> #Server Name, use the same name to share game files. -$Name = "Terraria" +$Name = "Astroneer" #--------------------------------------------------------- # Server Configuration @@ -12,7 +12,7 @@ $Name = "Terraria" $ServerDetails = @{ #Unique Identifier used to track processes. Must be unique to each servers. - UID = 9 + UID = "Astroneer_1" #Login username used by SteamCMD Login = "anonymous" @@ -43,7 +43,7 @@ $ServerDetails = @{ ConfigFolder = "." #Steam Server App Id - AppID = + AppID = 0 #Name of the Beta Build BetaBuild = "" @@ -54,7 +54,7 @@ $ServerDetails = @{ #Process name in the task manager ProcessName = "TerrariaServer" - #ProjectZomboid64.exe + #Server Executable Exec = ".\servers\$Name\TerrariaServer.exe" #Allow force close, usefull for server without RCON and Multiple instances. diff --git a/templates/insurgencysandstorm.psm1 b/templates/insurgencysandstorm.psm1 index 68c54e1..d02e10d 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 = "InsurgencySandstorm_1" #Login username used by SteamCMD Login = "anonymous" @@ -97,7 +97,7 @@ $ServerDetails = @{ #Process name in the task manager ProcessName = "InsurgencyServer" - #ProjectZomboid64.exe + #Server Executable Exec = ".\servers\$Name\InsurgencyServer.exe" #Allow force close, usefull for server without RCON and Multiple instances. diff --git a/templates/killingfloor2.psm1 b/templates/killingfloor2.psm1 index c4e6a3a..a7622b5 100644 --- a/templates/killingfloor2.psm1 +++ b/templates/killingfloor2.psm1 @@ -14,7 +14,7 @@ $Name = "KillingFloor2" $ServerDetails = @{ #Unique Identifier used to track processes. Must be unique to each servers. - UID = 6 + UID = "KillingFloor2_1" #Login username used by SteamCMD Login = "anonymous" @@ -80,7 +80,7 @@ $ServerDetails = @{ #Process name in the task manager ProcessName = "KFServer" - #ProjectZomboid64.exe + #Server Executable Exec = ".\servers\$Name\Binaries\Win64\KFServer.exe" #Allow force close, usefull for server without RCON and Multiple instances. diff --git a/templates/l4d2.psm1 b/templates/left4dead2.psm1 similarity index 98% rename from templates/l4d2.psm1 rename to templates/left4dead2.psm1 index 4003e7e..b0ce8ef 100644 --- a/templates/l4d2.psm1 +++ b/templates/left4dead2.psm1 @@ -3,7 +3,7 @@ #> #Server Name, use the same name to share game files. -$Name = "Terraria" +$Name = "Left4Dead2" #--------------------------------------------------------- # Server Configuration @@ -12,7 +12,7 @@ $Name = "Terraria" $ServerDetails = @{ #Unique Identifier used to track processes. Must be unique to each servers. - UID = 9 + UID = "Left4Dead2_1" #Login username used by SteamCMD Login = "anonymous" @@ -54,7 +54,7 @@ $ServerDetails = @{ #Process name in the task manager ProcessName = "TerrariaServer" - #ProjectZomboid64.exe + #Server Executable Exec = ".\servers\$Name\TerrariaServer.exe" #Allow force close, usefull for server without RCON and Multiple instances. diff --git a/templates/mordhau.psm1 b/templates/mordhau.psm1 index 019434b..2747f28 100644 --- a/templates/mordhau.psm1 +++ b/templates/mordhau.psm1 @@ -12,7 +12,7 @@ $Name = "Mordhau" $ServerDetails = @{ #Unique Identifier used to track processes. Must be unique to each servers. - UID = 9 + UID = "Mordhau_1" #Login username used by SteamCMD Login = "anonymous" @@ -54,7 +54,7 @@ $ServerDetails = @{ #Process name in the task manager ProcessName = "TerrariaServer" - #ProjectZomboid64.exe + #Server Executable Exec = ".\servers\$Name\TerrariaServer.exe" #Allow force close, usefull for server without RCON and Multiple instances. diff --git a/templates/pixark.psm1 b/templates/pixark.psm1 index 2a2b495..80cd240 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 = "PixArk_1" #Login username used by SteamCMD Login = "anonymous" @@ -108,7 +108,7 @@ $ServerDetails = @{ #Process name in the task manager ProcessName = "PixArkServer" - #ProjectZomboid64.exe + #Server Executable Exec = ".\servers\$Name\ShooterGame\Binaries\Win64\PixARKServer.exe" #Allow force close, usefull for server without RCON and Multiple instances. diff --git a/templates/projectzomboid.psm1 b/templates/projectzomboid.psm1 index bb24247..546cbbe 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 = "ProjectZomboid_1" #Login username used by SteamCMD Login = "anonymous" @@ -79,7 +79,7 @@ $ServerDetails = @{ #Process name in the task manager ProcessName = "java" - #ProjectZomboid64.exe + #Server Executable Exec = ".\servers\$Name\ProjectZomboid64.exe" #Allow force close, usefull for server without RCON and Multiple instances. diff --git a/templates/rust.psm1 b/templates/rust.psm1 index d2614b2..c1ec410 100644 --- a/templates/rust.psm1 +++ b/templates/rust.psm1 @@ -15,7 +15,7 @@ $Identity = "RustServer01" $ServerDetails = @{ #Unique Identifier used to track processes. Must be unique to each servers. - UID = 8 + UID = "Rust_1" #Login username used by SteamCMD Login = "anonymous" @@ -114,7 +114,7 @@ $ServerDetails = @{ #Process name in the task manager ProcessName = "RustDedicated" - #ProjectZomboid64.exe + #Server Executable Exec = ".\servers\$Name\RustDedicated.exe" #Allow force close, usefull for server without RCON and Multiple instances. diff --git a/templates/squad.psm1 b/templates/squad.psm1 index ef78886..9133f82 100644 --- a/templates/squad.psm1 +++ b/templates/squad.psm1 @@ -11,7 +11,7 @@ $Name = "Squad" $ServerDetails = @{ #Unique Identifier used to track processes. Must be unique to each servers. - UID = 1 + UID = "Squad_1" #Login username used by SteamCMD Login = "anonymous" @@ -62,7 +62,7 @@ $ServerDetails = @{ #Process name in the task manager ProcessName = "SquadGameServer" - #ProjectZomboid64.exe + #Server Executable Exec = ".\servers\$Name\SquadGameServer.exe" #Allow force close, usefull for server without RCON and Multiple instances. diff --git a/templates/starbound.psm1 b/templates/starbound.psm1 index 4003e7e..8d45a0a 100644 --- a/templates/starbound.psm1 +++ b/templates/starbound.psm1 @@ -3,7 +3,7 @@ #> #Server Name, use the same name to share game files. -$Name = "Terraria" +$Name = "Starbound" #--------------------------------------------------------- # Server Configuration @@ -12,7 +12,7 @@ $Name = "Terraria" $ServerDetails = @{ #Unique Identifier used to track processes. Must be unique to each servers. - UID = 9 + UID = "Starbound_1" #Login username used by SteamCMD Login = "anonymous" @@ -54,7 +54,7 @@ $ServerDetails = @{ #Process name in the task manager ProcessName = "TerrariaServer" - #ProjectZomboid64.exe + #Server Executable Exec = ".\servers\$Name\TerrariaServer.exe" #Allow force close, usefull for server without RCON and Multiple instances. diff --git a/templates/stationeers.psm1 b/templates/stationeers.psm1 index 4003e7e..384dcfc 100644 --- a/templates/stationeers.psm1 +++ b/templates/stationeers.psm1 @@ -3,7 +3,7 @@ #> #Server Name, use the same name to share game files. -$Name = "Terraria" +$Name = "Stationeers" #--------------------------------------------------------- # Server Configuration @@ -12,7 +12,7 @@ $Name = "Terraria" $ServerDetails = @{ #Unique Identifier used to track processes. Must be unique to each servers. - UID = 9 + UID = "Stationeers_1" #Login username used by SteamCMD Login = "anonymous" @@ -54,7 +54,7 @@ $ServerDetails = @{ #Process name in the task manager ProcessName = "TerrariaServer" - #ProjectZomboid64.exe + #Server Executable Exec = ".\servers\$Name\TerrariaServer.exe" #Allow force close, usefull for server without RCON and Multiple instances. diff --git a/templates/terraria.psm1 b/templates/terraria.psm1 index 4003e7e..a337229 100644 --- a/templates/terraria.psm1 +++ b/templates/terraria.psm1 @@ -1,5 +1,5 @@ <# - ".\servers\$Name\Multiplayer\config.cfg" + ".\servers\$Name\serverconfig.txt" #> #Server Name, use the same name to share game files. @@ -12,13 +12,35 @@ $Name = "Terraria" $ServerDetails = @{ #Unique Identifier used to track processes. Must be unique to each servers. - UID = 9 + UID = "Terraria_1" #Login username used by SteamCMD Login = "anonymous" - #Name of the server in the Server Browser - ConfigFile = ".\servers\$Name\Multiplayer\config.cfg" + # Specifies the configuration file to use *(relative the the game) + ConfigFile = "serverconfig.txt" + + # Specifies the port to listen on. + Port = 7777 + + # Sets the max number of players + MaxPlayers = 8 + + # Sets the server password + Password = "CHANGEME" + + #Choose the world to load. Do not try to save it somewhere else, it won't work. + World = "$Env:userprofile\Documents\My Games\Terraria\Worlds\ServerWorld.wld" + + #Should match the above world. + WorldName = "ServerWorld" + + #Specifies the world seed when using -autocreate + Seed = "1234" + + #Creates a world if none is found in the path specified by World. + #World size is specified by: 1(small), 2(medium), and 3(large). + AutoCreate = 2 #Rcon IP (not supported by valheim yet.) ManagementIP = "127.0.0.1" @@ -40,10 +62,13 @@ $ServerDetails = @{ Path = ".\servers\$Name" #Server configuration folder - ConfigFolder = "." + ConfigFolder = ".\servers\$Name" + + #Server Version + Version = "1423" - #Steam Server App Id - AppID = + #Steam Server App Id *0 Skip SteamCMD Installation + AppID = 0 #Name of the Beta Build BetaBuild = "" @@ -54,7 +79,7 @@ $ServerDetails = @{ #Process name in the task manager ProcessName = "TerrariaServer" - #ProjectZomboid64.exe + #Server Executable Exec = ".\servers\$Name\TerrariaServer.exe" #Allow force close, usefull for server without RCON and Multiple instances. @@ -110,7 +135,7 @@ $BackupsDetails = @{ Weeks = 4 #Folder to include in backup - Saves = ".\servers\$Name" + Saves = "$Env:userprofile\Documents\My Games\Terraria\Worlds" } #Create the object $Backups = New-Object -TypeName PsObject -Property $BackupsDetails @@ -156,11 +181,17 @@ $Warnings = New-Object -TypeName PsObject -Property $WarningsDetails #Launch Arguments $ArgumentList = @( - "-batchmode ", - "-dedicated ", - "-nographics ", - "-nosteamclient ", - "-configfilepath `"$($Server.ConfigFile)`"" + "-config `"$($Server.ConfigFile)`" ", + "-port $($Server.Port) ", + "-maxplayers $($Server.MaxPlayers) ", + "-password `"$($Server.Password)`" ", + "-world `"$($Server.World)`" ", + "-worldname `"$($Server.WorldName)`" ", + "-seed `"$($Server.Seed)`" ", + "-autocreate $($Server.AutoCreate) ", + "-secure ", + "-noupnp ", + "-steam " ) Add-Member -InputObject $Server -Name "ArgumentList" -Type NoteProperty -Value $ArgumentList Add-Member -InputObject $Server -Name "Launcher" -Type NoteProperty -Value $Server.Exec @@ -170,9 +201,39 @@ Add-Member -InputObject $Server -Name "Launcher" -Type NoteProperty -Value $Serv #--------------------------------------------------------- function Start-ServerPrep { - + #If server is not installed, install it. + $Version = Get-Content -Path ".\servers\$($Server.Name)\Version.txt" -ErrorAction SilentlyContinue + if (-not (Test-Path -Path $Server.Exec -PathType "leaf" -ErrorAction SilentlyContinue) -or ($Version -ne $Server.Version)) { + Write-ScriptMsg "Installing Server..." + #Create Temporary Download Folder + New-Item -Path ".\downloads" -ItemType "directory" -ErrorAction SilentlyContinue + #Download Microsoft XNA Framework + Invoke-Download -Uri "https://download.microsoft.com/download/5/3/A/53A804C8-EC78-43CD-A0F0-2FB4D45603D3/xnafx40_redist.msi" -OutFile ".\downloads\xna.msi" -ErrorAction SilentlyContinue + #Install Microsoft XNA + $Package = Resolve-Path -Path ".\downloads\xna.msi" + Write-Host $Package + Read-Host + Start-Process -FilePath msiexec.exe -ArgumentList "/qn /i $Package" -Verb "RunAs" -Wait + Write-Host "Done" + Read-Host + #Download Server Zip + Invoke-Download -Uri "https://terraria.org/api/download/pc-dedicated-server/terraria-server-$($Server.Version).zip" -OutFile ".\downloads\terraria.zip" -ErrorAction SilentlyContinue + #Extract Server to Temporary Folder + Expand-Archive -Path ".\downloads\terraria.zip" -DestinationPath ".\downloads\terraria\" -Force + #Copy Server Files to Server Directory + Copy-Item -Path ".\downloads\terraria\$($Server.Version)\Windows\TerrariaServer.exe" -Destination $Server.Path -Force + Copy-Item -Path ".\downloads\terraria\$($Server.Version)\Windows\ReLogic.Native.dll" -Destination $Server.Path -Force + if (-not (Test-Path -Path $Server.ConfigFile -PathType "leaf" -ErrorAction SilentlyContinue)) { + Copy-Item -Path ".\downloads\terraria\$($Server.Version)\Windows\serverconfig.txt" -Destination $Server.Path + } + #Cleanup + Remove-Item -Path ".\downloads" -Recurse -Force -ErrorAction SilentlyContinue + #Remove old version file + Remove-Item -Path ".\servers\$($Server.Name)\Version.txt" -Confirm:$false -ErrorAction SilentlyContinue + #Write new Version File + New-Item -Path ".\servers\$($Server.Name)\" -Name "Version.txt" -ItemType "file" -Value "$($Server.Version)" -Force -ErrorAction SilentlyContinue + } Write-ScriptMsg "Port Forward : $($server.Port) in TCP and UDP to $($Global.InternalIP)" - } Export-ModuleMember -Function Start-ServerPrep -Variable @("Server","Backups","Warnings") \ No newline at end of file diff --git a/templates/theforest.psm1 b/templates/theforest.psm1 index 7e21e47..e0c80f0 100644 --- a/templates/theforest.psm1 +++ b/templates/theforest.psm1 @@ -12,12 +12,12 @@ $Name = "TheForest" $ServerDetails = @{ #Unique Identifier used to track processes. Must be unique to each servers. - UID = 9 + UID = "TheForest_1" #Login username used by SteamCMD Login = "anonymous" - #Name of the server in the Server Browser + #Configuration File ConfigFile = ".\servers\$Name\Multiplayer\config.cfg" #Rcon IP (not supported by valheim yet.) @@ -54,7 +54,7 @@ $ServerDetails = @{ #Process name in the task manager ProcessName = "TheForestDedicatedServer" - #ProjectZomboid64.exe + #Server Executable Exec = ".\servers\$Name\TheForestDedicatedServer.exe" #Allow force close, usefull for server without RCON and Multiple instances. diff --git a/templates/valheim.psm1 b/templates/valheim.psm1 index 71c02ee..50bd559 100644 --- a/templates/valheim.psm1 +++ b/templates/valheim.psm1 @@ -8,7 +8,7 @@ $Name = "Valheim" $ServerDetails = @{ #Unique Identifier used to track processes. Must be unique to each servers. - UID = 5 + UID = "Valheim_1" #Login username used by SteamCMD Login = "anonymous" @@ -59,7 +59,7 @@ $ServerDetails = @{ #Process name in the task manager ProcessName = "valheim_server" - #ProjectZomboid64.exe + #Server Executable Exec = ".\servers\$Name\valheim_server.exe" #Allow force close, usefull for server without RCON and Multiple instances. From 89895acf2493d04c99cca20a915529b479b218d9 Mon Sep 17 00:00:00 2001 From: Patrick Veilleux Date: Sun, 19 Sep 2021 00:46:30 -0400 Subject: [PATCH 03/12] Fix bugs improve TheForest Implementation. --- functions/Optimize-ArgumentList.psm1 | 19 +++++++ functions/Read-Config.psm1 | 41 +------------- functions/Resolve-CompletePath.psm1 | 21 +++++++ functions/Send-RestartWarning.psm1 | 2 +- functions/Stop-Server.psm1 | 82 ++++++++++++++++------------ functions/Stop-ServerProcess.psm1 | 41 ++++++++++++++ functions/Test-ServerState.psm1 | 55 ------------------- functions/Update-Server.psm1 | 32 +++++++---- launchers/run.cmd | 2 +- main.ps1 | 6 +- templates/7daystodie.psm1 | 3 + templates/astroneer.psm1 | 3 + templates/insurgencysandstorm.psm1 | 3 + templates/killingfloor2.psm1 | 3 + templates/left4dead2.psm1 | 3 + templates/mordhau.psm1 | 3 + templates/pixark.psm1 | 3 + templates/projectzomboid.psm1 | 3 + templates/rust.psm1 | 3 + templates/squad.psm1 | 3 + templates/starbound.psm1 | 3 + templates/stationeers.psm1 | 3 + templates/terraria.psm1 | 7 +-- templates/theforest.psm1 | 66 +++++++++++++++++++--- templates/valheim.psm1 | 3 + 25 files changed, 257 insertions(+), 156 deletions(-) create mode 100644 functions/Optimize-ArgumentList.psm1 create mode 100644 functions/Resolve-CompletePath.psm1 create mode 100644 functions/Stop-ServerProcess.psm1 delete mode 100644 functions/Test-ServerState.psm1 diff --git a/functions/Optimize-ArgumentList.psm1 b/functions/Optimize-ArgumentList.psm1 new file mode 100644 index 0000000..9653635 --- /dev/null +++ b/functions/Optimize-ArgumentList.psm1 @@ -0,0 +1,19 @@ +function Optimize-ArgumentList { + [OutputType([string])] + param ( + [Parameter(Mandatory)] + [array] $Arguments + ) + + #Create Server.Arguments from cleaned ArgumentList. + [System.Collections.ArrayList]$CleanedArguments=@() + + foreach($Argument in $Arguments){ + if (-not ($Argument.EndsWith('=""') -or $Argument.EndsWith('=') -or $Argument.EndsWith(' '))){ + $null = $CleanedArguments.Add($Argument) + } + } + return ($CleanedArguments -join "") +} + +Export-ModuleMember -Function Optimize-ArgumentList \ No newline at end of file diff --git a/functions/Read-Config.psm1 b/functions/Read-Config.psm1 index f151484..748d31c 100644 --- a/functions/Read-Config.psm1 +++ b/functions/Read-Config.psm1 @@ -1,40 +1,3 @@ -function Optimize-ArgumentList { - [CmdletBinding()] - [OutputType([System.Collections.ArrayList])] - param ( - [Parameter(Mandatory)] - [array] $ArgumentList - ) - #Create Server.Arguments from cleaned ArgumentList. - [System.Collections.ArrayList]$CleanedArguments=@() - - foreach($Argument in $ArgumentList){ - if (-not ($Argument.EndsWith('=""') -or $Argument.EndsWith('=') -or $Argument.EndsWith(' '))){ - $CleanedArguments.Add($Argument) - } - } - return ($CleanedArguments -join "") -} - -function Resolve-CompletePath { - [CmdletBinding()] - [OutputType([string])] - param ( - [Parameter(Mandatory)] - [string] $Path, - [string] $ParentPath - ) - #Add the full path to the path from the config file. - if ($Path.StartsWith($ParentPath)){ - return "$(Get-Location)$($Path.substring(1))" - } - $ReturnPath = Resolve-Path -LiteralPath $Path -ErrorAction SilentlyContinue - if ($null -eq $ReturnPath) { - $ReturnPath = $Path - } - return $ReturnPath -} - function Read-Config { #Read configuration data and improve it by parsing full paths and cleaning arguments @@ -50,6 +13,6 @@ function Read-Config { $Global.LogFolder = (Resolve-CompletePath -Path $Global.LogFolder -ParentPath ".\") #Create Arguments - Add-Member -InputObject $Server -Name "Arguments" -Type NoteProperty -Value (Optimize-ArgumentList -ArgumentList $Server.ArgumentList) + Add-Member -InputObject $Server -Name "Arguments" -Type NoteProperty -Value (Optimize-ArgumentList -Arguments $Server.ArgumentList) } -Export-ModuleMember -Function Read-Config, Resolve-CompletePath \ No newline at end of file +Export-ModuleMember -Function Read-Config \ No newline at end of file diff --git a/functions/Resolve-CompletePath.psm1 b/functions/Resolve-CompletePath.psm1 new file mode 100644 index 0000000..1ab537f --- /dev/null +++ b/functions/Resolve-CompletePath.psm1 @@ -0,0 +1,21 @@ + +function Resolve-CompletePath { + [CmdletBinding()] + [OutputType([string])] + param ( + [Parameter(Mandatory)] + [string] $Path, + [string] $ParentPath + ) + #Add the full path to the path from the config file. + if ($Path.StartsWith($ParentPath)){ + return "$(Get-Location)$($Path.substring(1))" + } + $ReturnPath = Resolve-Path -LiteralPath $Path -ErrorAction SilentlyContinue + if ($null -eq $ReturnPath) { + $ReturnPath = $Path + } + return $ReturnPath +} + +Export-ModuleMember -Function Resolve-CompletePath \ No newline at end of file diff --git a/functions/Send-RestartWarning.psm1 b/functions/Send-RestartWarning.psm1 index 762fd66..d6e23f8 100644 --- a/functions/Send-RestartWarning.psm1 +++ b/functions/Send-RestartWarning.psm1 @@ -60,7 +60,7 @@ function Send-RestartWarning { } #if the process is still running, if allowed, stop process. if(-not ($ServerProcess.HasExited) -and ($Server.AllowForceClose)){ - $Stopped = Stop-Server -ServerProcess $ServerProcess + $Stopped = Stop-ServerProcess -ServerProcess $ServerProcess } return $Stopped } diff --git a/functions/Stop-Server.psm1 b/functions/Stop-Server.psm1 index b1acc3c..558ba6c 100644 --- a/functions/Stop-Server.psm1 +++ b/functions/Stop-Server.psm1 @@ -1,41 +1,53 @@ function Stop-Server { - [CmdletBinding()] - [OutputType([boolean])] - param ( - [Parameter(Mandatory)] - $ServerProcess - ) - #if the server is still running - - 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{ - Write-Warning "Forcefully stopping server..." - Stop-Process $ServerProcess -Force - } + #Get the PID from the .PID market file. + $ServerPID = Get-PID + #If it returned 0, it failed to get a PID + if ($null -ne $ServerPID) { + $ServerProcess = Get-Process -ID $ServerPID -ErrorAction SilentlyContinue + } + #If the server process is none-existent, Get the process from the server process name. + if ($null -eq $ServerProcess) { + $ServerProcess = Get-Process -Name $Server.ProcessName -ErrorAction SilentlyContinue } - - #Safety timer for allowing the files to unlock before backup. - Start-Sleep -Seconds 10 - if ($ServerProcess.HasExited) { - return $true + #Check if the process was found. + if ($null -eq $ServerProcess) { + Write-ServerMsg "Server is not running." } else { - return $false + #Check if it's the right server via RCON if possible. + $Success = $false + if ($Warnings.Use){ + $Success = Send-Command("help") + if ($Success) { + Write-ServerMsg "Server is responding to remote messages." + } else { + Write-ServerMsg "Server is not responding to remote messages." + } + } + #If Rcon worked, send stop warning. + if ($Success) { + Write-ServerMsg "Server is running, warning users about upcomming restart." + $Stopped = Send-RestartWarning -ServerProcess $ServerProcess + } else { + #If Server is allow to be closed, close it. + if ($Server.AllowForceClose){ + Write-ServerMsg "Server is running, stopping server." + $Stopped = Stop-ServerProcess -ServerProcess $ServerProcess + } + } + #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." + } else { + if ($Server.AllowForceClose) { + Exit-WithError "Failed to stop server." + } else { + Write-ServerMsg "Server not stopped." + } + } + } + #Unregister the PID + if (-not $(Unregister-PID)) { + Write-ServerMsg "Failed to remove PID file." } } Export-ModuleMember -Function Stop-Server \ No newline at end of file diff --git a/functions/Stop-ServerProcess.psm1 b/functions/Stop-ServerProcess.psm1 new file mode 100644 index 0000000..1dce108 --- /dev/null +++ b/functions/Stop-ServerProcess.psm1 @@ -0,0 +1,41 @@ +function Stop-ServerProcess { + [CmdletBinding()] + [OutputType([boolean])] + param ( + [Parameter(Mandatory)] + $ServerProcess + ) + #if the server is still running + + Write-ServerMsg "Closing main window..." + #Close the main windows. + $ServerProcess.CloseMainWindow() + #Wait for exit for at most 30 seconds. + $ServerProcess.WaitForExit($Warnings.SaveDelay * 1000) + #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($Warnings.SaveDelay * 1000) + #If process is still running, force stop-process. + if ($ServerProcess.HasExited) { + Write-Warning "Server succesfully stopped on second try." + }else{ + Write-Warning "Forcefully stopping server..." + Stop-Process $ServerProcess -Force + } + } + + #Safety timer for allowing the files to unlock before backup. + Start-Sleep -Seconds 10 + if ($ServerProcess.HasExited) { + return $true + } else { + return $false + } +} +Export-ModuleMember -Function Stop-ServerProcess \ No newline at end of file diff --git a/functions/Test-ServerState.psm1 b/functions/Test-ServerState.psm1 deleted file mode 100644 index 1c41566..0000000 --- a/functions/Test-ServerState.psm1 +++ /dev/null @@ -1,55 +0,0 @@ -function Test-ServerState { - #Get the PID from the .PID market file. - $ServerPID = Get-PID - #If it returned 0, it failed to get a PID - if ($null -ne $ServerPID) { - $ServerProcess = Get-Process -ID $ServerPID -ErrorAction SilentlyContinue - } - #If the server process is none-existent, Get the process from the server process name. - if ($null -eq $ServerProcess) { - $ServerProcess = Get-Process -Name $Server.ProcessName -ErrorAction SilentlyContinue - } - #Check if the process was found. - if ($null -eq $ServerProcess) { - Write-ServerMsg "Server is not running." - } else { - #Check if it's the right server via RCON if possible. - $Success = $false - if ($Warnings.Use){ - $Success = Send-Command("help") - if ($Success) { - Write-ServerMsg "Server is responding to remote messages." - } else { - Write-ServerMsg "Server is not responding to remote messages." - } - } - - #If Rcon worked, send stop warning. - if ($Success) { - Write-ServerMsg "Server is running, warning users about upcomming restart." - $Stopped = Send-RestartWarning -ServerProcess $ServerProcess - } else { - #If Server is allow to be closed, close it. - if ($Server.AllowForceClose){ - Write-ServerMsg "Server is running, stopping server." - $Stopped = Stop-Server -ServerProcess $ServerProcess - } - } - - #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." - } else { - if ($Server.AllowForceClose) { - Exit-WithError "Failed to stop server." - } else { - Write-ServerMsg "Server not stopped." - } - } - } - #Unregister the PID - if (-not $(Unregister-PID)) { - Write-ServerMsg "Failed to remove PID file." - } -} -Export-ModuleMember -Function Test-ServerState \ No newline at end of file diff --git a/functions/Update-Server.psm1 b/functions/Update-Server.psm1 index d0395a0..34dd92f 100644 --- a/functions/Update-Server.psm1 +++ b/functions/Update-Server.psm1 @@ -19,35 +19,45 @@ function Update-Server { } #> #Login String - $LoginString = "+@ShutdownOnFailedCommand 1 +@NoPromptForPassword 1 +login anonymous" + $LoginString = "+@ShutdownOnFailedCommand 1 +@NoPromptForPassword 1 +login anonymous " if ($Server.Login -ne "anonymous") { - $LoginString = "+login $($Server.Login)" + $LoginString = "+login $($Server.Login) " } #Validation String - $ValidateString = "" + $ValidateString = " " $ValidatingString = "" if ($Server.Validate -ne $false){ - $ValidateString = "-validate" - $ValidatingString = "and validating" + $ValidateString = "validate " + $ValidatingString = "and Validating" } #Beta Build String - $BetaBuildString = "" + $BetaBuildString = " " $VersionString = "Regular" if ($Server.BetaBuild -ne ""){ - $BetaBuildString = "-beta $($Server.BetaBuild)" + $BetaBuildString = "-beta $($Server.BetaBuild) " $VersionString = "Beta" } #Beta Password String - $BetaPasswordString = "" + $BetaPasswordString = " " if ($Server.BetaBuildPassword -ne ""){ $BetaPasswordString = "-betapassword $($Server.BetaBuildPassword)" } - - $Arguments = "$LoginString +force_install_dir `"$($Server.Path)`" `"+app_update $($Server.AppID) $BetaBuildString $BetaPasswordString`" $ValidateString +quit" + #Generate String + $ArgumentList = @( + "$LoginString", + "+force_install_dir `"$($Server.Path)`" ", + "+app_update $($Server.AppID)", + "$BetaBuildString", + "$BetaPasswordString", + " $ValidateString", + "+quit" + ) + $Arguments = Optimize-ArgumentList -Arguments $ArgumentList #Run the update String Write-ServerMsg "$UpdateType $ValidatingString $VersionString Build." try { - Start-Process $Global.SteamCMD -ArgumentList $Arguments -Wait -PassThru -NoNewWindow + #$Task = Start-Process $Global.SteamCMD -ArgumentList $Arguments -Wait -PassThru -NoNewWindow + & $Global.SteamCMD "+login anonymous app_update 556450 validate +quit" } catch { Exit-WithError -ErrorMsg "SteamCMD failed to complete." diff --git a/launchers/run.cmd b/launchers/run.cmd index 262a546..81bb656 100644 --- a/launchers/run.cmd +++ b/launchers/run.cmd @@ -1,2 +1,2 @@ cd .. -start powershell.exe -noprofile -executionpolicy bypass -file ".\main.ps1" -ServerCfg "terraria" \ No newline at end of file +start powershell.exe -noprofile -executionpolicy bypass -file ".\main.ps1" -ServerCfg "theforest" \ No newline at end of file diff --git a/main.ps1 b/main.ps1 index 83e9af4..c4c8483 100644 --- a/main.ps1 +++ b/main.ps1 @@ -101,7 +101,7 @@ if (-not (Test-Path -Path $Server.Exec -ErrorAction SilentlyContinue)){ Write-ScriptMsg "Verifying Server State..." #If the server is not freshly installed. if (-not $FreshInstall) { - Test-ServerState + Stop-Server } #--------------------------------------------------------- @@ -119,7 +119,7 @@ if ($Backups.Use -and -not $FreshInstall) { #--------------------------------------------------------- #If not a fresh install, update and/or validate server. -if (-not $FreshInstall) { +if (-not $FreshInstall -and $Server.AutoUpdates) { Write-ScriptMsg "Updating Server..." Update-Server -UpdateType "Updating" Write-ServerMsg "Server successfully updated and/or validated." @@ -158,6 +158,8 @@ catch { if ($FreshInstall -and (Test-Path -Path $Server.ConfigFolder -PathType "Container" -ErrorAction SilentlyContinue)) { & explorer.exe $Server.ConfigFolder + #Stop Server because configuration is probably bad anyway + Stop-Server } #--------------------------------------------------------- diff --git a/templates/7daystodie.psm1 b/templates/7daystodie.psm1 index 0e30009..832465e 100644 --- a/templates/7daystodie.psm1 +++ b/templates/7daystodie.psm1 @@ -54,6 +54,9 @@ $ServerDetails = @{ #Beta Build Password BetaBuildPassword = "" + #Auto-Update Enable or Disable Auto-Updates, some games don't work well with SteamCMD + AutoUpdates = $true + #Process name in the task manager ProcessName = "7DaysToDieServer" diff --git a/templates/astroneer.psm1 b/templates/astroneer.psm1 index ad07df2..33c5a67 100644 --- a/templates/astroneer.psm1 +++ b/templates/astroneer.psm1 @@ -51,6 +51,9 @@ $ServerDetails = @{ #Beta Build Password BetaBuildPassword = "" + #Auto-Update Enable or Disable Auto-Updates, some games don't work well with SteamCMD + AutoUpdates = $true + #Process name in the task manager ProcessName = "TerrariaServer" diff --git a/templates/insurgencysandstorm.psm1 b/templates/insurgencysandstorm.psm1 index d02e10d..c9c72dd 100644 --- a/templates/insurgencysandstorm.psm1 +++ b/templates/insurgencysandstorm.psm1 @@ -94,6 +94,9 @@ $ServerDetails = @{ #Beta Build Password BetaBuildPassword = "" + #Auto-Update Enable or Disable Auto-Updates, some games don't work well with SteamCMD + AutoUpdates = $true + #Process name in the task manager ProcessName = "InsurgencyServer" diff --git a/templates/killingfloor2.psm1 b/templates/killingfloor2.psm1 index a7622b5..fc4e7ed 100644 --- a/templates/killingfloor2.psm1 +++ b/templates/killingfloor2.psm1 @@ -77,6 +77,9 @@ $ServerDetails = @{ #Beta Build Password BetaBuildPassword = "" + #Auto-Update Enable or Disable Auto-Updates, some games don't work well with SteamCMD + AutoUpdates = $true + #Process name in the task manager ProcessName = "KFServer" diff --git a/templates/left4dead2.psm1 b/templates/left4dead2.psm1 index b0ce8ef..127bbf5 100644 --- a/templates/left4dead2.psm1 +++ b/templates/left4dead2.psm1 @@ -51,6 +51,9 @@ $ServerDetails = @{ #Beta Build Password BetaBuildPassword = "" + #Auto-Update Enable or Disable Auto-Updates, some games don't work well with SteamCMD + AutoUpdates = $true + #Process name in the task manager ProcessName = "TerrariaServer" diff --git a/templates/mordhau.psm1 b/templates/mordhau.psm1 index 2747f28..3456c98 100644 --- a/templates/mordhau.psm1 +++ b/templates/mordhau.psm1 @@ -51,6 +51,9 @@ $ServerDetails = @{ #Beta Build Password BetaBuildPassword = "" + #Auto-Update Enable or Disable Auto-Updates, some games don't work well with SteamCMD + AutoUpdates = $true + #Process name in the task manager ProcessName = "TerrariaServer" diff --git a/templates/pixark.psm1 b/templates/pixark.psm1 index 80cd240..e533ad1 100644 --- a/templates/pixark.psm1 +++ b/templates/pixark.psm1 @@ -105,6 +105,9 @@ $ServerDetails = @{ #Beta Build Password BetaBuildPassword = "" + #Auto-Update Enable or Disable Auto-Updates, some games don't work well with SteamCMD + AutoUpdates = $true + #Process name in the task manager ProcessName = "PixArkServer" diff --git a/templates/projectzomboid.psm1 b/templates/projectzomboid.psm1 index 546cbbe..2d172a2 100644 --- a/templates/projectzomboid.psm1 +++ b/templates/projectzomboid.psm1 @@ -76,6 +76,9 @@ $ServerDetails = @{ #Beta Build Password BetaBuildPassword = "iaccepttheconsequences" + #Auto-Update Enable or Disable Auto-Updates, some games don't work well with SteamCMD + AutoUpdates = $true + #Process name in the task manager ProcessName = "java" diff --git a/templates/rust.psm1 b/templates/rust.psm1 index c1ec410..367cc04 100644 --- a/templates/rust.psm1 +++ b/templates/rust.psm1 @@ -111,6 +111,9 @@ $ServerDetails = @{ #Beta Build Password BetaBuildPassword = "" + #Auto-Update Enable or Disable Auto-Updates, some games don't work well with SteamCMD + AutoUpdates = $true + #Process name in the task manager ProcessName = "RustDedicated" diff --git a/templates/squad.psm1 b/templates/squad.psm1 index 9133f82..a6180d8 100644 --- a/templates/squad.psm1 +++ b/templates/squad.psm1 @@ -59,6 +59,9 @@ $ServerDetails = @{ #Beta Build Password BetaBuildPassword = "" + #Auto-Update Enable or Disable Auto-Updates, some games don't work well with SteamCMD + AutoUpdates = $true + #Process name in the task manager ProcessName = "SquadGameServer" diff --git a/templates/starbound.psm1 b/templates/starbound.psm1 index 8d45a0a..de56c5e 100644 --- a/templates/starbound.psm1 +++ b/templates/starbound.psm1 @@ -51,6 +51,9 @@ $ServerDetails = @{ #Beta Build Password BetaBuildPassword = "" + #Auto-Update Enable or Disable Auto-Updates, some games don't work well with SteamCMD + AutoUpdates = $true + #Process name in the task manager ProcessName = "TerrariaServer" diff --git a/templates/stationeers.psm1 b/templates/stationeers.psm1 index 384dcfc..8e39cd8 100644 --- a/templates/stationeers.psm1 +++ b/templates/stationeers.psm1 @@ -51,6 +51,9 @@ $ServerDetails = @{ #Beta Build Password BetaBuildPassword = "" + #Auto-Update Enable or Disable Auto-Updates, some games don't work well with SteamCMD + AutoUpdates = $true + #Process name in the task manager ProcessName = "TerrariaServer" diff --git a/templates/terraria.psm1 b/templates/terraria.psm1 index a337229..cbb2b78 100644 --- a/templates/terraria.psm1 +++ b/templates/terraria.psm1 @@ -76,6 +76,9 @@ $ServerDetails = @{ #Beta Build Password BetaBuildPassword = "" + #Auto-Update Enable or Disable Auto-Updates, some games don't work well with SteamCMD + AutoUpdates = $true + #Process name in the task manager ProcessName = "TerrariaServer" @@ -211,11 +214,7 @@ function Start-ServerPrep { Invoke-Download -Uri "https://download.microsoft.com/download/5/3/A/53A804C8-EC78-43CD-A0F0-2FB4D45603D3/xnafx40_redist.msi" -OutFile ".\downloads\xna.msi" -ErrorAction SilentlyContinue #Install Microsoft XNA $Package = Resolve-Path -Path ".\downloads\xna.msi" - Write-Host $Package - Read-Host Start-Process -FilePath msiexec.exe -ArgumentList "/qn /i $Package" -Verb "RunAs" -Wait - Write-Host "Done" - Read-Host #Download Server Zip Invoke-Download -Uri "https://terraria.org/api/download/pc-dedicated-server/terraria-server-$($Server.Version).zip" -OutFile ".\downloads\terraria.zip" -ErrorAction SilentlyContinue #Extract Server to Temporary Folder diff --git a/templates/theforest.psm1 b/templates/theforest.psm1 index e0c80f0..e9828e0 100644 --- a/templates/theforest.psm1 +++ b/templates/theforest.psm1 @@ -1,5 +1,5 @@ <# - ".\servers\$Name\Multiplayer\config.cfg" + ".\servers\TheForest\Multiplayer\config.cfg" #> #Server Name, use the same name to share game files. @@ -17,8 +17,41 @@ $ServerDetails = @{ #Login username used by SteamCMD Login = "anonymous" - #Configuration File - ConfigFile = ".\servers\$Name\Multiplayer\config.cfg" + #Configuration File #Command line parameters overwrite matching entries defined in the config file. + ConfigFile = ".\Multiplayer\config.cfg" + + #Steam Port + SteamPort = 8766 + + #Game Port + GamePort = 27015 + + #Query Port + QueryPort = 27016 + + #Set the server display name + SessionName = "My Server" + + #Maximum number of players + MaxPlayers = 8 + + #Join Password + Password = "CHANGEME" + + #Admin Password + AdminPassword = "CHANGEMETOO" + + #Set the autosave interval in minutes, default is 15 + AutoSaveInterval = 5 + + #Set Save Slot ( 1 | 2 | 3 | 4 | 5 ) + SaveSlot = 1 + + #Set Continue State ("New" | "Continue") + InitType = "Continue" + + #Set the game difficult level, default is Normal ("Peaceful" | "Normal" | "Hard") + Difficulty = "Normal" #Rcon IP (not supported by valheim yet.) ManagementIP = "127.0.0.1" @@ -37,10 +70,10 @@ $ServerDetails = @{ Name = $Name #Server Installation Path - Path = ".\servers\$Name" + Path = ".\servers\$Name\" #Server configuration folder - ConfigFolder = "." + ConfigFolder = ".\servers\$Name\Multiplayer" #Steam Server App Id AppID = 556450 @@ -51,6 +84,9 @@ $ServerDetails = @{ #Beta Build Password BetaBuildPassword = "" + #Auto-Update Enable or Disable Auto-Updates, some games don't work well with SteamCMD + AutoUpdates = $false + #Process name in the task manager ProcessName = "TheForestDedicatedServer" @@ -110,7 +146,8 @@ $BackupsDetails = @{ Weeks = 4 #Folder to include in backup - Saves = ".\servers\$Name\Multiplayer" + #Saves = "$Env:userprofile\AppData\LocalLow\SKS\TheForestDedicatedServer" + Saves = ".\servers\$($Server.Name)\Multiplayer" } #Create the object $Backups = New-Object -TypeName PsObject -Property $BackupsDetails @@ -160,7 +197,20 @@ $ArgumentList = @( "-dedicated ", "-nographics ", "-nosteamclient ", - "-configfilepath `"$($Server.ConfigFile)`"" + "-serverip $($Global.InternalIP) ", + "-serversteamport $($Server.SteamPort) ", + "-servergameport $($Server.GamePort) ", + "-serverqueryport $($Server.QueryPort) ", + "-servername `"$($Server.SessionName)`" ", + "-serverplayers $($Server.maxPlayers) ", + "-serverpassword `"$($Server.Password)`" ", + "-serverpassword_admin `"$($Server.AdminPassword)`" ", + "-serverautosaveinterval $($Server.AutoSaveInterval) ", + "-slot $($Server.SaveSlot) ", + "-serverautosaveinterval $($Server.InitType) ", + "-difficulty `"$($Server.Difficulty)`" ", + "-configfilepath `"$($Server.ConfigFile)`" ", + "-savefolderpath .\" ) Add-Member -InputObject $Server -Name "ArgumentList" -Type NoteProperty -Value $ArgumentList Add-Member -InputObject $Server -Name "Launcher" -Type NoteProperty -Value $Server.Exec @@ -171,7 +221,7 @@ Add-Member -InputObject $Server -Name "Launcher" -Type NoteProperty -Value $Serv function Start-ServerPrep { - Write-ScriptMsg "Port Forward : $($server.Port) in TCP and UDP to $($Global.InternalIP)" + Write-ScriptMsg "Port Forward : 8766, 27015, 27016 in TCP and UDP to $($Global.InternalIP)" } diff --git a/templates/valheim.psm1 b/templates/valheim.psm1 index 50bd559..7a1b8cd 100644 --- a/templates/valheim.psm1 +++ b/templates/valheim.psm1 @@ -56,6 +56,9 @@ $ServerDetails = @{ #Beta Build Password BetaBuildPassword = "" + #Auto-Update Enable or Disable Auto-Updates, some games don't work well with SteamCMD + AutoUpdates = $true + #Process name in the task manager ProcessName = "valheim_server" From 2279823ed70333df042911b3360de615ea378650 Mon Sep 17 00:00:00 2001 From: Patrick Veilleux Date: Sun, 19 Sep 2021 00:51:31 -0400 Subject: [PATCH 04/12] WIP --- templates/astroneer.psm1 | 2 +- templates/left4dead2.psm1 | 2 +- templates/mordhau.psm1 | 2 +- templates/starbound.psm1 | 2 +- templates/stationeers.psm1 | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/templates/astroneer.psm1 b/templates/astroneer.psm1 index 33c5a67..cb82169 100644 --- a/templates/astroneer.psm1 +++ b/templates/astroneer.psm1 @@ -43,7 +43,7 @@ $ServerDetails = @{ ConfigFolder = "." #Steam Server App Id - AppID = 0 + AppID = 728470 #Name of the Beta Build BetaBuild = "" diff --git a/templates/left4dead2.psm1 b/templates/left4dead2.psm1 index 127bbf5..6595c22 100644 --- a/templates/left4dead2.psm1 +++ b/templates/left4dead2.psm1 @@ -43,7 +43,7 @@ $ServerDetails = @{ ConfigFolder = "." #Steam Server App Id - AppID = + AppID = 222860 #Name of the Beta Build BetaBuild = "" diff --git a/templates/mordhau.psm1 b/templates/mordhau.psm1 index 3456c98..f942f23 100644 --- a/templates/mordhau.psm1 +++ b/templates/mordhau.psm1 @@ -43,7 +43,7 @@ $ServerDetails = @{ ConfigFolder = ".\servers\$Name\Multiplayer\" #Steam Server App Id - AppID = 105610 + AppID = 629800 #Name of the Beta Build BetaBuild = "" diff --git a/templates/starbound.psm1 b/templates/starbound.psm1 index de56c5e..e0403e6 100644 --- a/templates/starbound.psm1 +++ b/templates/starbound.psm1 @@ -43,7 +43,7 @@ $ServerDetails = @{ ConfigFolder = "." #Steam Server App Id - AppID = + AppID = 533830 #Name of the Beta Build BetaBuild = "" diff --git a/templates/stationeers.psm1 b/templates/stationeers.psm1 index 8e39cd8..f9093f5 100644 --- a/templates/stationeers.psm1 +++ b/templates/stationeers.psm1 @@ -43,7 +43,7 @@ $ServerDetails = @{ ConfigFolder = "." #Steam Server App Id - AppID = + AppID = 600760 #Name of the Beta Build BetaBuild = "" From 266d8eecaa604211df62589eb1ffc6d49a618e5e Mon Sep 17 00:00:00 2001 From: Patrick Veilleux Date: Sun, 19 Sep 2021 12:59:10 -0400 Subject: [PATCH 05/12] Spilt Start-Server, Fix a bug with Argumentlist, add Astroneer. --- configs/astroneer.psm1 | 185 +++++++++++++++++++++++++++++ functions/Read-Config.psm1 | 4 +- functions/Start-Server.psm1 | 28 +++++ functions/Stop-Server.psm1 | 12 +- functions/Update-Server.psm1 | 3 +- launchers/run.cmd | 2 +- main.ps1 | 22 +--- templates/7daystodie.psm1 | 3 + templates/astroneer.psm1 | 40 ++++--- templates/insurgencysandstorm.psm1 | 3 + templates/killingfloor2.psm1 | 3 + templates/left4dead2.psm1 | 3 + templates/mordhau.psm1 | 3 + templates/pixark.psm1 | 3 + templates/projectzomboid.psm1 | 3 + templates/rust.psm1 | 3 + templates/squad.psm1 | 3 + templates/starbound.psm1 | 3 + templates/stationeers.psm1 | 3 + templates/terraria.psm1 | 3 + templates/theforest.psm1 | 3 + templates/valheim.psm1 | 3 + 22 files changed, 290 insertions(+), 48 deletions(-) create mode 100644 configs/astroneer.psm1 create mode 100644 functions/Start-Server.psm1 diff --git a/configs/astroneer.psm1 b/configs/astroneer.psm1 new file mode 100644 index 0000000..9e5a873 --- /dev/null +++ b/configs/astroneer.psm1 @@ -0,0 +1,185 @@ +<# + Edit your configuration in .\servers\Astroneer\Astro\Saved\Config\WindowsServer + + https://blog.astroneer.space/p/astroneer-dedicated-server-details/ +#> + +#Server Name, use the same name to share game files. +$Name = "Astroneer" + +#--------------------------------------------------------- +# Server Configuration +#--------------------------------------------------------- + +$ServerDetails = @{ + + #Unique Identifier used to track processes. Must be unique to each servers. + UID = "Astroneer_1" + + #Login username used by SteamCMD + Login = "anonymous" + + #Rcon IP (not supported by astroneer yet.) + 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" + + #Server configuration folder + ConfigFolder = ".\servers\Astroneer\Astro\Saved\Config\WindowsServer" + + #Steam Server App Id + AppID = 728470 + + #Name of the Beta Build + BetaBuild = "" + + #Beta Build Password + BetaBuildPassword = "" + + #Auto-Update Enable or Disable Auto-Updates, some games don't work well with SteamCMD + AutoUpdates = $true + + #Process name in the task manager + ProcessName = "AstroServer-Win64-Shipping" + + #Use PID instead of Process Name, Will still use processname if the PID fails to find anything. + UsePID = $false + + #Server Executable + Exec = ".\servers\$Name\AstroServer.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 + + #How long should it wait to check if the server is stable + StartupWaitTime = 10 +} +#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\Astroneer\Astro\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 = $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 +$ArgumentList = @() +Add-Member -InputObject $Server -Name "ArgumentList" -Type NoteProperty -Value $ArgumentList +Add-Member -InputObject $Server -Name "Launcher" -Type NoteProperty -Value $Server.Exec + +#--------------------------------------------------------- +# Function that runs just before the server starts. +#--------------------------------------------------------- + +function Start-ServerPrep { + + Write-ScriptMsg "`nPort Forward : 8777 in TCP and UDP to $($Global.InternalIP)" + Write-ScriptMsg "`nAdd the following lines to engine.ini `n`n[URL]`nPort=8777" + Write-ScriptMsg "`nIn AstroServerSettings.ini change the following lines`n` + `nPublicIP=$($Global.ExternalIP)` + `nServerName=Your server Name` + `nOwnerName=Your Steam Username` + `nOwnerGuid=Your SteamID 64` + `nServerPassword=CHANGEME` + `nConsolePassword=CHANGEMETOO`n" +} + +Export-ModuleMember -Function Start-ServerPrep -Variable @("Server","Backups","Warnings") \ No newline at end of file diff --git a/functions/Read-Config.psm1 b/functions/Read-Config.psm1 index 748d31c..3c4908e 100644 --- a/functions/Read-Config.psm1 +++ b/functions/Read-Config.psm1 @@ -13,6 +13,8 @@ function Read-Config { $Global.LogFolder = (Resolve-CompletePath -Path $Global.LogFolder -ParentPath ".\") #Create Arguments - Add-Member -InputObject $Server -Name "Arguments" -Type NoteProperty -Value (Optimize-ArgumentList -Arguments $Server.ArgumentList) + if ($Server.ArgumentList.length -gt 0) { + Add-Member -InputObject $Server -Name "Arguments" -Type NoteProperty -Value (Optimize-ArgumentList -Arguments $Server.ArgumentList) + } } Export-ModuleMember -Function Read-Config \ No newline at end of file diff --git a/functions/Start-Server.psm1 b/functions/Start-Server.psm1 new file mode 100644 index 0000000..bc8a22b --- /dev/null +++ b/functions/Start-Server.psm1 @@ -0,0 +1,28 @@ +function Start-Server { + try { + Write-ScriptMsg "Starting Server Preparation..." + Start-ServerPrep + Write-ScriptMsg "Starting Server..." + if ($Server.Arguments.length -gt 0){ + $App = Start-Process -FilePath $Server.Launcher -WorkingDirectory $Server.Path -ArgumentList $Server.Arguments -PassThru + } else { + $App = Start-Process -FilePath $Server.Launcher -WorkingDirectory $Server.Path -PassThru + } + #Wait to see if the server is stable. + Start-Sleep -Seconds $Server.StartupWaitTime + if (($null -eq $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 $_ + Exit-WithError -ErrorMsg "Unable to start server." + } +} +Export-ModuleMember -Function Start-Server \ No newline at end of file diff --git a/functions/Stop-Server.psm1 b/functions/Stop-Server.psm1 index 558ba6c..9df83c0 100644 --- a/functions/Stop-Server.psm1 +++ b/functions/Stop-Server.psm1 @@ -1,9 +1,11 @@ function Stop-Server { - #Get the PID from the .PID market file. - $ServerPID = Get-PID - #If it returned 0, it failed to get a PID - if ($null -ne $ServerPID) { - $ServerProcess = Get-Process -ID $ServerPID -ErrorAction SilentlyContinue + if ($Server.UsePID){ + #Get the PID from the .PID market file. + $ServerPID = Get-PID + #If it returned 0, it failed to get a PID + if ($null -ne $ServerPID) { + $ServerProcess = Get-Process -ID $ServerPID -ErrorAction SilentlyContinue + } } #If the server process is none-existent, Get the process from the server process name. if ($null -eq $ServerProcess) { diff --git a/functions/Update-Server.psm1 b/functions/Update-Server.psm1 index 34dd92f..94972a5 100644 --- a/functions/Update-Server.psm1 +++ b/functions/Update-Server.psm1 @@ -56,8 +56,7 @@ function Update-Server { #Run the update String Write-ServerMsg "$UpdateType $ValidatingString $VersionString Build." try { - #$Task = Start-Process $Global.SteamCMD -ArgumentList $Arguments -Wait -PassThru -NoNewWindow - & $Global.SteamCMD "+login anonymous app_update 556450 validate +quit" + $Task = Start-Process $Global.SteamCMD -ArgumentList $Arguments -Wait -PassThru -NoNewWindow } catch { Exit-WithError -ErrorMsg "SteamCMD failed to complete." diff --git a/launchers/run.cmd b/launchers/run.cmd index 81bb656..8cc6677 100644 --- a/launchers/run.cmd +++ b/launchers/run.cmd @@ -1,2 +1,2 @@ cd .. -start powershell.exe -noprofile -executionpolicy bypass -file ".\main.ps1" -ServerCfg "theforest" \ No newline at end of file +start powershell.exe -noprofile -executionpolicy bypass -file ".\main.ps1" -ServerCfg "astroneer" \ No newline at end of file diff --git a/main.ps1 b/main.ps1 index c4c8483..b03de78 100644 --- a/main.ps1 +++ b/main.ps1 @@ -130,27 +130,7 @@ if (-not $FreshInstall -and $Server.AutoUpdates) { #--------------------------------------------------------- #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 Preparation..." - Start-ServerPrep - Write-ScriptMsg "Starting Server..." - $App = Start-Process -FilePath $Server.Launcher -WorkingDirectory $Server.Path -ArgumentList $Server.Arguments -PassThru - #Wait to see if the server is stable. - Start-Sleep -Seconds $Server.StartupWaitTime - if (($null -eq $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 $_ - Exit-WithError -ErrorMsg "Unable to start server." -} +Start-Server #--------------------------------------------------------- # Open FreshInstall Configuration folder diff --git a/templates/7daystodie.psm1 b/templates/7daystodie.psm1 index 832465e..e7a9a45 100644 --- a/templates/7daystodie.psm1 +++ b/templates/7daystodie.psm1 @@ -60,6 +60,9 @@ $ServerDetails = @{ #Process name in the task manager ProcessName = "7DaysToDieServer" + #Use PID instead of Process Name, Will still use processname if the PID fails to find anything. + UsePID = $true + #Server Executable Exec = ".\servers\$Name\7DaysToDieServer.exe" diff --git a/templates/astroneer.psm1 b/templates/astroneer.psm1 index cb82169..9e5a873 100644 --- a/templates/astroneer.psm1 +++ b/templates/astroneer.psm1 @@ -1,5 +1,7 @@ <# - ".\servers\$Name\Multiplayer\config.cfg" + Edit your configuration in .\servers\Astroneer\Astro\Saved\Config\WindowsServer + + https://blog.astroneer.space/p/astroneer-dedicated-server-details/ #> #Server Name, use the same name to share game files. @@ -17,10 +19,7 @@ $ServerDetails = @{ #Login username used by SteamCMD Login = "anonymous" - #Name of the server in the Server Browser - ConfigFile = ".\servers\$Name\Multiplayer\config.cfg" - - #Rcon IP (not supported by valheim yet.) + #Rcon IP (not supported by astroneer yet.) ManagementIP = "127.0.0.1" #Rcon Port @@ -40,7 +39,7 @@ $ServerDetails = @{ Path = ".\servers\$Name" #Server configuration folder - ConfigFolder = "." + ConfigFolder = ".\servers\Astroneer\Astro\Saved\Config\WindowsServer" #Steam Server App Id AppID = 728470 @@ -55,10 +54,13 @@ $ServerDetails = @{ AutoUpdates = $true #Process name in the task manager - ProcessName = "TerrariaServer" + ProcessName = "AstroServer-Win64-Shipping" + + #Use PID instead of Process Name, Will still use processname if the PID fails to find anything. + UsePID = $false #Server Executable - Exec = ".\servers\$Name\TerrariaServer.exe" + Exec = ".\servers\$Name\AstroServer.exe" #Allow force close, usefull for server without RCON and Multiple instances. AllowForceClose = $true @@ -113,7 +115,8 @@ $BackupsDetails = @{ Weeks = 4 #Folder to include in backup - Saves = ".\servers\$Name" + Saves = ".\servers\Astroneer\Astro\Saved" + } #Create the object $Backups = New-Object -TypeName PsObject -Property $BackupsDetails @@ -158,13 +161,7 @@ $Warnings = New-Object -TypeName PsObject -Property $WarningsDetails #--------------------------------------------------------- #Launch Arguments -$ArgumentList = @( - "-batchmode ", - "-dedicated ", - "-nographics ", - "-nosteamclient ", - "-configfilepath `"$($Server.ConfigFile)`"" -) +$ArgumentList = @() Add-Member -InputObject $Server -Name "ArgumentList" -Type NoteProperty -Value $ArgumentList Add-Member -InputObject $Server -Name "Launcher" -Type NoteProperty -Value $Server.Exec @@ -174,8 +171,15 @@ Add-Member -InputObject $Server -Name "Launcher" -Type NoteProperty -Value $Serv function Start-ServerPrep { - Write-ScriptMsg "Port Forward : $($server.Port) in TCP and UDP to $($Global.InternalIP)" - + Write-ScriptMsg "`nPort Forward : 8777 in TCP and UDP to $($Global.InternalIP)" + Write-ScriptMsg "`nAdd the following lines to engine.ini `n`n[URL]`nPort=8777" + Write-ScriptMsg "`nIn AstroServerSettings.ini change the following lines`n` + `nPublicIP=$($Global.ExternalIP)` + `nServerName=Your server Name` + `nOwnerName=Your Steam Username` + `nOwnerGuid=Your SteamID 64` + `nServerPassword=CHANGEME` + `nConsolePassword=CHANGEMETOO`n" } Export-ModuleMember -Function Start-ServerPrep -Variable @("Server","Backups","Warnings") \ No newline at end of file diff --git a/templates/insurgencysandstorm.psm1 b/templates/insurgencysandstorm.psm1 index c9c72dd..b9cc0bf 100644 --- a/templates/insurgencysandstorm.psm1 +++ b/templates/insurgencysandstorm.psm1 @@ -100,6 +100,9 @@ $ServerDetails = @{ #Process name in the task manager ProcessName = "InsurgencyServer" + #Use PID instead of Process Name, Will still use processname if the PID fails to find anything. + UsePID = $true + #Server Executable Exec = ".\servers\$Name\InsurgencyServer.exe" diff --git a/templates/killingfloor2.psm1 b/templates/killingfloor2.psm1 index fc4e7ed..4f18a84 100644 --- a/templates/killingfloor2.psm1 +++ b/templates/killingfloor2.psm1 @@ -83,6 +83,9 @@ $ServerDetails = @{ #Process name in the task manager ProcessName = "KFServer" + #Use PID instead of Process Name, Will still use processname if the PID fails to find anything. + UsePID = $true + #Server Executable Exec = ".\servers\$Name\Binaries\Win64\KFServer.exe" diff --git a/templates/left4dead2.psm1 b/templates/left4dead2.psm1 index 6595c22..9f7e70a 100644 --- a/templates/left4dead2.psm1 +++ b/templates/left4dead2.psm1 @@ -57,6 +57,9 @@ $ServerDetails = @{ #Process name in the task manager ProcessName = "TerrariaServer" + #Use PID instead of Process Name, Will still use processname if the PID fails to find anything. + UsePID = $true + #Server Executable Exec = ".\servers\$Name\TerrariaServer.exe" diff --git a/templates/mordhau.psm1 b/templates/mordhau.psm1 index f942f23..a3b2d4b 100644 --- a/templates/mordhau.psm1 +++ b/templates/mordhau.psm1 @@ -57,6 +57,9 @@ $ServerDetails = @{ #Process name in the task manager ProcessName = "TerrariaServer" + #Use PID instead of Process Name, Will still use processname if the PID fails to find anything. + UsePID = $true + #Server Executable Exec = ".\servers\$Name\TerrariaServer.exe" diff --git a/templates/pixark.psm1 b/templates/pixark.psm1 index e533ad1..7a79db1 100644 --- a/templates/pixark.psm1 +++ b/templates/pixark.psm1 @@ -111,6 +111,9 @@ $ServerDetails = @{ #Process name in the task manager ProcessName = "PixArkServer" + #Use PID instead of Process Name, Will still use processname if the PID fails to find anything. + UsePID = $true + #Server Executable Exec = ".\servers\$Name\ShooterGame\Binaries\Win64\PixARKServer.exe" diff --git a/templates/projectzomboid.psm1 b/templates/projectzomboid.psm1 index 2d172a2..81a455b 100644 --- a/templates/projectzomboid.psm1 +++ b/templates/projectzomboid.psm1 @@ -82,6 +82,9 @@ $ServerDetails = @{ #Process name in the task manager ProcessName = "java" + #Use PID instead of Process Name, Will still use processname if the PID fails to find anything. + UsePID = $true + #Server Executable Exec = ".\servers\$Name\ProjectZomboid64.exe" diff --git a/templates/rust.psm1 b/templates/rust.psm1 index 367cc04..f14ac5c 100644 --- a/templates/rust.psm1 +++ b/templates/rust.psm1 @@ -117,6 +117,9 @@ $ServerDetails = @{ #Process name in the task manager ProcessName = "RustDedicated" + #Use PID instead of Process Name, Will still use processname if the PID fails to find anything. + UsePID = $true + #Server Executable Exec = ".\servers\$Name\RustDedicated.exe" diff --git a/templates/squad.psm1 b/templates/squad.psm1 index a6180d8..7cac771 100644 --- a/templates/squad.psm1 +++ b/templates/squad.psm1 @@ -65,6 +65,9 @@ $ServerDetails = @{ #Process name in the task manager ProcessName = "SquadGameServer" + #Use PID instead of Process Name, Will still use processname if the PID fails to find anything. + UsePID = $true + #Server Executable Exec = ".\servers\$Name\SquadGameServer.exe" diff --git a/templates/starbound.psm1 b/templates/starbound.psm1 index e0403e6..cbe2a5b 100644 --- a/templates/starbound.psm1 +++ b/templates/starbound.psm1 @@ -57,6 +57,9 @@ $ServerDetails = @{ #Process name in the task manager ProcessName = "TerrariaServer" + #Use PID instead of Process Name, Will still use processname if the PID fails to find anything. + UsePID = $true + #Server Executable Exec = ".\servers\$Name\TerrariaServer.exe" diff --git a/templates/stationeers.psm1 b/templates/stationeers.psm1 index f9093f5..37d3d1d 100644 --- a/templates/stationeers.psm1 +++ b/templates/stationeers.psm1 @@ -57,6 +57,9 @@ $ServerDetails = @{ #Process name in the task manager ProcessName = "TerrariaServer" + #Use PID instead of Process Name, Will still use processname if the PID fails to find anything. + UsePID = $true + #Server Executable Exec = ".\servers\$Name\TerrariaServer.exe" diff --git a/templates/terraria.psm1 b/templates/terraria.psm1 index cbb2b78..432bd94 100644 --- a/templates/terraria.psm1 +++ b/templates/terraria.psm1 @@ -82,6 +82,9 @@ $ServerDetails = @{ #Process name in the task manager ProcessName = "TerrariaServer" + #Use PID instead of Process Name, Will still use processname if the PID fails to find anything. + UsePID = $true + #Server Executable Exec = ".\servers\$Name\TerrariaServer.exe" diff --git a/templates/theforest.psm1 b/templates/theforest.psm1 index e9828e0..121e984 100644 --- a/templates/theforest.psm1 +++ b/templates/theforest.psm1 @@ -90,6 +90,9 @@ $ServerDetails = @{ #Process name in the task manager ProcessName = "TheForestDedicatedServer" + #Use PID instead of Process Name, Will still use processname if the PID fails to find anything. + UsePID = $true + #Server Executable Exec = ".\servers\$Name\TheForestDedicatedServer.exe" diff --git a/templates/valheim.psm1 b/templates/valheim.psm1 index 7a1b8cd..3733b7f 100644 --- a/templates/valheim.psm1 +++ b/templates/valheim.psm1 @@ -62,6 +62,9 @@ $ServerDetails = @{ #Process name in the task manager ProcessName = "valheim_server" + #Use PID instead of Process Name, Will still use processname if the PID fails to find anything. + UsePID = $true + #Server Executable Exec = ".\servers\$Name\valheim_server.exe" From 4365dd6fb8cafabfdde96169f8c4f752cd0c3946 Mon Sep 17 00:00:00 2001 From: Patrick Veilleux Date: Sun, 19 Sep 2021 14:48:32 -0400 Subject: [PATCH 06/12] Add Left4Dead2 --- launchers/run.cmd | 2 +- templates/left4dead2.psm1 | 107 ++++++++++++++---- .../paperclip.psm1 | 106 +++++++++++++---- templates/rust.psm1 | 2 +- 4 files changed, 171 insertions(+), 46 deletions(-) rename configs/astroneer.psm1 => templates/paperclip.psm1 (53%) diff --git a/launchers/run.cmd b/launchers/run.cmd index 8cc6677..bc200cf 100644 --- a/launchers/run.cmd +++ b/launchers/run.cmd @@ -1,2 +1,2 @@ cd .. -start powershell.exe -noprofile -executionpolicy bypass -file ".\main.ps1" -ServerCfg "astroneer" \ No newline at end of file +start powershell.exe -noprofile -executionpolicy bypass -file ".\main.ps1" -ServerCfg "left4dead2" \ No newline at end of file diff --git a/templates/left4dead2.psm1 b/templates/left4dead2.psm1 index 9f7e70a..11d53be 100644 --- a/templates/left4dead2.psm1 +++ b/templates/left4dead2.psm1 @@ -1,5 +1,5 @@ <# - ".\servers\$Name\Multiplayer\config.cfg" + Edit configuration in : .\servers\Left4Dead2\left4dead2\cfg\server.cfg #> #Server Name, use the same name to share game files. @@ -17,14 +17,32 @@ $ServerDetails = @{ #Login username used by SteamCMD Login = "anonymous" - #Name of the server in the Server Browser - ConfigFile = ".\servers\$Name\Multiplayer\config.cfg" + #Server Host Name + SessionName = "My Left 4 Dead 2 Server" - #Rcon IP (not supported by valheim yet.) + #Game Port + Port = 27015 + + #Query Port + QueryPort = 27005 + + #Max number of players + MaxPlayers = 4 + + #Server Password + Password = "" + + #Map + Map = "c1m1_hotel" + + #Configuration File + ConfigFile = "server.cfg" + + #Rcon IP ManagementIP = "127.0.0.1" #Rcon Port - ManagementPort = "" + ManagementPort = "9000" #Rcon Password ManagementPassword = "" @@ -40,7 +58,7 @@ $ServerDetails = @{ Path = ".\servers\$Name" #Server configuration folder - ConfigFolder = "." + ConfigFolder = ".\servers\$Name\left4dead2\cfg\" #Steam Server App Id AppID = 222860 @@ -55,13 +73,13 @@ $ServerDetails = @{ AutoUpdates = $true #Process name in the task manager - ProcessName = "TerrariaServer" + ProcessName = "srcds" #Use PID instead of Process Name, Will still use processname if the PID fails to find anything. UsePID = $true #Server Executable - Exec = ".\servers\$Name\TerrariaServer.exe" + Exec = ".\servers\$Name\srcds.exe" #Allow force close, usefull for server without RCON and Multiple instances. AllowForceClose = $true @@ -90,7 +108,7 @@ $ServerDetails = @{ AppAffinity = 15 #Should the server validate install after installation or update *(recommended) - Validate = $true + Validate = $false #How long should it wait to check if the server is stable StartupWaitTime = 10 @@ -116,7 +134,7 @@ $BackupsDetails = @{ Weeks = 4 #Folder to include in backup - Saves = ".\servers\$Name" + Saves = ".\servers\$Name\left4dead2\cfg" } #Create the object $Backups = New-Object -TypeName PsObject -Property $BackupsDetails @@ -127,10 +145,10 @@ $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" + 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 @@ -145,13 +163,13 @@ $WarningsDetails = @{ CmdMessage = "say" #command to save the server - CmdSave = "saveworld" + CmdSave = "save" #How long to wait in seconds after the save command is sent. SaveDelay = 15 #command to stop the server - CmdStop = "shutdown" + CmdStop = "quit" } #Create the object $Warnings = New-Object -TypeName PsObject -Property $WarningsDetails @@ -162,11 +180,20 @@ $Warnings = New-Object -TypeName PsObject -Property $WarningsDetails #Launch Arguments $ArgumentList = @( - "-batchmode ", - "-dedicated ", - "-nographics ", - "-nosteamclient ", - "-configfilepath `"$($Server.ConfigFile)`"" + "-console ", + "-game left4dead2 ", + "-secure ", + "-nohltv ", + "-netconport $($Server.ManagementPort) ", + "-netconpassword $($Server.ManagementPassword) ", + "+map $($Server.Map) ", + "+log on ", + "+maxplayers $($Server.MaxPlayers) ", + "+hostport $($Server.Port) ", + "+clientport $($Server.QueryPort) ", + "-ip $($Global.InternalIP) ", + "+hostip $($Global.ExternalIP) ", + "+exec $($Server.ConfigFile)" ) Add-Member -InputObject $Server -Name "ArgumentList" -Type NoteProperty -Value $ArgumentList Add-Member -InputObject $Server -Name "Launcher" -Type NoteProperty -Value $Server.Exec @@ -175,8 +202,50 @@ Add-Member -InputObject $Server -Name "Launcher" -Type NoteProperty -Value $Serv # Function that runs just before the server starts. #--------------------------------------------------------- +$FileContentList = @( + "hostname `"$($Server.SessionName)`"", + "rcon_password `"$($Server.ManagementPassword)`"", + "sv_password `"$($Server.Password)`"", + "sv_contact `"contact@example.com`"", + "hostport $($Server.Port)", + "sv_lan 0", + "sv_region 0", + "sv_allow_lobby_connect_only 0", + "mp_disable_autokick 1", + "sv_allow_wait_command 0", + "sv_alternateticks 0", + "sv_clearhinthistory 0", + "sv_consistency 0", + "sv_pausable 0", + "sv_forcepreload 1", + "sv_pure_kick_clients 0", + "sv_pure 0", + "sv_voiceenable 1", + "sv_alltalk 1", + "log on", + "sv_logecho 0", + "sv_logfile 1", + "sv_log_onefile 0", + "sv_logbans 1", + "sv_logflush 0", + "sv_logsdir logs", + "exec banned_user.cfg", + "exec banned_ip.cfg", + "writeip", + "writeid" +) + +$FileContent = ($FileContentList -join "`n") + function Start-ServerPrep { + + #Copy Config File if not created. Do not modify the one in the server directory, it will be overwriten on updates. + if (-not (Test-Path -Path ".\servers\$($Server.Name)\left4dead2\cfg\$($Server.ConfigFile)" -ErrorAction SilentlyContinue)){ + Write-Host "Creating Config File" + New-Item -Path ".\servers\$($Server.Name)\left4dead2\cfg\" -Name "$($Server.ConfigFile)" -ItemType "file" -Value $FileContent + } + Write-ScriptMsg "Port Forward : $($server.Port) in TCP and UDP to $($Global.InternalIP)" } diff --git a/configs/astroneer.psm1 b/templates/paperclip.psm1 similarity index 53% rename from configs/astroneer.psm1 rename to templates/paperclip.psm1 index 9e5a873..432bd94 100644 --- a/configs/astroneer.psm1 +++ b/templates/paperclip.psm1 @@ -1,11 +1,9 @@ <# - Edit your configuration in .\servers\Astroneer\Astro\Saved\Config\WindowsServer - - https://blog.astroneer.space/p/astroneer-dedicated-server-details/ + ".\servers\$Name\serverconfig.txt" #> #Server Name, use the same name to share game files. -$Name = "Astroneer" +$Name = "Terraria" #--------------------------------------------------------- # Server Configuration @@ -14,12 +12,37 @@ $Name = "Astroneer" $ServerDetails = @{ #Unique Identifier used to track processes. Must be unique to each servers. - UID = "Astroneer_1" + UID = "Terraria_1" #Login username used by SteamCMD Login = "anonymous" - #Rcon IP (not supported by astroneer yet.) + # Specifies the configuration file to use *(relative the the game) + ConfigFile = "serverconfig.txt" + + # Specifies the port to listen on. + Port = 7777 + + # Sets the max number of players + MaxPlayers = 8 + + # Sets the server password + Password = "CHANGEME" + + #Choose the world to load. Do not try to save it somewhere else, it won't work. + World = "$Env:userprofile\Documents\My Games\Terraria\Worlds\ServerWorld.wld" + + #Should match the above world. + WorldName = "ServerWorld" + + #Specifies the world seed when using -autocreate + Seed = "1234" + + #Creates a world if none is found in the path specified by World. + #World size is specified by: 1(small), 2(medium), and 3(large). + AutoCreate = 2 + + #Rcon IP (not supported by valheim yet.) ManagementIP = "127.0.0.1" #Rcon Port @@ -39,10 +62,13 @@ $ServerDetails = @{ Path = ".\servers\$Name" #Server configuration folder - ConfigFolder = ".\servers\Astroneer\Astro\Saved\Config\WindowsServer" + ConfigFolder = ".\servers\$Name" - #Steam Server App Id - AppID = 728470 + #Server Version + Version = "1423" + + #Steam Server App Id *0 Skip SteamCMD Installation + AppID = 0 #Name of the Beta Build BetaBuild = "" @@ -54,13 +80,13 @@ $ServerDetails = @{ AutoUpdates = $true #Process name in the task manager - ProcessName = "AstroServer-Win64-Shipping" + ProcessName = "TerrariaServer" #Use PID instead of Process Name, Will still use processname if the PID fails to find anything. - UsePID = $false + UsePID = $true #Server Executable - Exec = ".\servers\$Name\AstroServer.exe" + Exec = ".\servers\$Name\TerrariaServer.exe" #Allow force close, usefull for server without RCON and Multiple instances. AllowForceClose = $true @@ -115,8 +141,7 @@ $BackupsDetails = @{ Weeks = 4 #Folder to include in backup - Saves = ".\servers\Astroneer\Astro\Saved" - + Saves = "$Env:userprofile\Documents\My Games\Terraria\Worlds" } #Create the object $Backups = New-Object -TypeName PsObject -Property $BackupsDetails @@ -161,7 +186,19 @@ $Warnings = New-Object -TypeName PsObject -Property $WarningsDetails #--------------------------------------------------------- #Launch Arguments -$ArgumentList = @() +$ArgumentList = @( + "-config `"$($Server.ConfigFile)`" ", + "-port $($Server.Port) ", + "-maxplayers $($Server.MaxPlayers) ", + "-password `"$($Server.Password)`" ", + "-world `"$($Server.World)`" ", + "-worldname `"$($Server.WorldName)`" ", + "-seed `"$($Server.Seed)`" ", + "-autocreate $($Server.AutoCreate) ", + "-secure ", + "-noupnp ", + "-steam " +) Add-Member -InputObject $Server -Name "ArgumentList" -Type NoteProperty -Value $ArgumentList Add-Member -InputObject $Server -Name "Launcher" -Type NoteProperty -Value $Server.Exec @@ -170,16 +207,35 @@ Add-Member -InputObject $Server -Name "Launcher" -Type NoteProperty -Value $Serv #--------------------------------------------------------- function Start-ServerPrep { - - Write-ScriptMsg "`nPort Forward : 8777 in TCP and UDP to $($Global.InternalIP)" - Write-ScriptMsg "`nAdd the following lines to engine.ini `n`n[URL]`nPort=8777" - Write-ScriptMsg "`nIn AstroServerSettings.ini change the following lines`n` - `nPublicIP=$($Global.ExternalIP)` - `nServerName=Your server Name` - `nOwnerName=Your Steam Username` - `nOwnerGuid=Your SteamID 64` - `nServerPassword=CHANGEME` - `nConsolePassword=CHANGEMETOO`n" + #If server is not installed, install it. + $Version = Get-Content -Path ".\servers\$($Server.Name)\Version.txt" -ErrorAction SilentlyContinue + if (-not (Test-Path -Path $Server.Exec -PathType "leaf" -ErrorAction SilentlyContinue) -or ($Version -ne $Server.Version)) { + Write-ScriptMsg "Installing Server..." + #Create Temporary Download Folder + New-Item -Path ".\downloads" -ItemType "directory" -ErrorAction SilentlyContinue + #Download Microsoft XNA Framework + Invoke-Download -Uri "https://download.microsoft.com/download/5/3/A/53A804C8-EC78-43CD-A0F0-2FB4D45603D3/xnafx40_redist.msi" -OutFile ".\downloads\xna.msi" -ErrorAction SilentlyContinue + #Install Microsoft XNA + $Package = Resolve-Path -Path ".\downloads\xna.msi" + Start-Process -FilePath msiexec.exe -ArgumentList "/qn /i $Package" -Verb "RunAs" -Wait + #Download Server Zip + Invoke-Download -Uri "https://terraria.org/api/download/pc-dedicated-server/terraria-server-$($Server.Version).zip" -OutFile ".\downloads\terraria.zip" -ErrorAction SilentlyContinue + #Extract Server to Temporary Folder + Expand-Archive -Path ".\downloads\terraria.zip" -DestinationPath ".\downloads\terraria\" -Force + #Copy Server Files to Server Directory + Copy-Item -Path ".\downloads\terraria\$($Server.Version)\Windows\TerrariaServer.exe" -Destination $Server.Path -Force + Copy-Item -Path ".\downloads\terraria\$($Server.Version)\Windows\ReLogic.Native.dll" -Destination $Server.Path -Force + if (-not (Test-Path -Path $Server.ConfigFile -PathType "leaf" -ErrorAction SilentlyContinue)) { + Copy-Item -Path ".\downloads\terraria\$($Server.Version)\Windows\serverconfig.txt" -Destination $Server.Path + } + #Cleanup + Remove-Item -Path ".\downloads" -Recurse -Force -ErrorAction SilentlyContinue + #Remove old version file + Remove-Item -Path ".\servers\$($Server.Name)\Version.txt" -Confirm:$false -ErrorAction SilentlyContinue + #Write new Version File + New-Item -Path ".\servers\$($Server.Name)\" -Name "Version.txt" -ItemType "file" -Value "$($Server.Version)" -Force -ErrorAction SilentlyContinue + } + Write-ScriptMsg "Port Forward : $($server.Port) in TCP and UDP to $($Global.InternalIP)" } Export-ModuleMember -Function Start-ServerPrep -Variable @("Server","Backups","Warnings") \ No newline at end of file diff --git a/templates/rust.psm1 b/templates/rust.psm1 index f14ac5c..c4dfec4 100644 --- a/templates/rust.psm1 +++ b/templates/rust.psm1 @@ -150,7 +150,7 @@ $ServerDetails = @{ AppAffinity = 15 #Should the server validate install after installation or update *(recommended) - Validate = $false + Validate = $true #How long should it wait to check if the server is stable StartupWaitTime = 0 From a3361b0fbc1b8f175e2b12e402f76b245be7a9c5 Mon Sep 17 00:00:00 2001 From: Patrick Veilleux Date: Mon, 20 Sep 2021 19:12:43 -0400 Subject: [PATCH 07/12] Add Starbound and Mordhau --- functions/Start-Server.psm1 | 4 +- functions/Stop-ServerProcess.psm1 | 3 +- launchers/run.cmd | 2 +- templates/7daystodie.psm1 | 3 +- templates/astroneer.psm1 | 5 ++- templates/insurgencysandstorm.psm1 | 3 +- templates/killingfloor2.psm1 | 5 ++- templates/left4dead2.psm1 | 5 ++- templates/mordhau.psm1 | 62 ++++++++++++++++++++---------- templates/paperclip.psm1 | 5 ++- templates/pixark.psm1 | 3 +- templates/projectzomboid.psm1 | 1 + templates/rust.psm1 | 5 ++- templates/squad.psm1 | 5 ++- templates/starbound.psm1 | 36 ++++++++--------- templates/stationeers.psm1 | 15 +++----- templates/terraria.psm1 | 5 ++- templates/theforest.psm1 | 5 ++- templates/valheim.psm1 | 3 +- 19 files changed, 99 insertions(+), 76 deletions(-) diff --git a/functions/Start-Server.psm1 b/functions/Start-Server.psm1 index bc8a22b..63b50f1 100644 --- a/functions/Start-Server.psm1 +++ b/functions/Start-Server.psm1 @@ -4,9 +4,9 @@ function Start-Server { Start-ServerPrep Write-ScriptMsg "Starting Server..." if ($Server.Arguments.length -gt 0){ - $App = Start-Process -FilePath $Server.Launcher -WorkingDirectory $Server.Path -ArgumentList $Server.Arguments -PassThru + $App = Start-Process -FilePath $Server.Launcher -WorkingDirectory $($Server.WorkingDirectory) -ArgumentList $Server.Arguments -PassThru } else { - $App = Start-Process -FilePath $Server.Launcher -WorkingDirectory $Server.Path -PassThru + $App = Start-Process -FilePath $Server.Launcher -WorkingDirectory $($Server.WorkingDirectory) -PassThru } #Wait to see if the server is stable. Start-Sleep -Seconds $Server.StartupWaitTime diff --git a/functions/Stop-ServerProcess.psm1 b/functions/Stop-ServerProcess.psm1 index 1dce108..e5021dd 100644 --- a/functions/Stop-ServerProcess.psm1 +++ b/functions/Stop-ServerProcess.psm1 @@ -22,14 +22,13 @@ function Stop-ServerProcess { #Wait for exit for at most 30 seconds. $ServerProcess.WaitForExit($Warnings.SaveDelay * 1000) #If process is still running, force stop-process. - if ($ServerProcess.HasExited) { + if ($null -eq (Get-Process -ID ($ServerProcess.Id) -ErrorAction SilentlyContinue)) { Write-Warning "Server succesfully stopped on second try." }else{ Write-Warning "Forcefully stopping server..." Stop-Process $ServerProcess -Force } } - #Safety timer for allowing the files to unlock before backup. Start-Sleep -Seconds 10 if ($ServerProcess.HasExited) { diff --git a/launchers/run.cmd b/launchers/run.cmd index bc200cf..e8705a4 100644 --- a/launchers/run.cmd +++ b/launchers/run.cmd @@ -1,2 +1,2 @@ cd .. -start powershell.exe -noprofile -executionpolicy bypass -file ".\main.ps1" -ServerCfg "left4dead2" \ No newline at end of file +start powershell.exe -noprofile -executionpolicy bypass -file ".\main.ps1" -ServerCfg "starbound" \ No newline at end of file diff --git a/templates/7daystodie.psm1 b/templates/7daystodie.psm1 index e7a9a45..df4290e 100644 --- a/templates/7daystodie.psm1 +++ b/templates/7daystodie.psm1 @@ -174,7 +174,8 @@ $ArgumentList = @( ) Add-Member -InputObject $Server -Name "ArgumentList" -Type NoteProperty -Value $ArgumentList -Add-Member -InputObject $Server -Name "Launcher" -Type NoteProperty -Value $Server.Exec +Add-Member -InputObject $Server -Name "Launcher" -Type NoteProperty -Value "$($Server.Exec)" +Add-Member -InputObject $Server -Name "WorkingDirectory" -Type NoteProperty -Value "$($Server.Path)" #--------------------------------------------------------- # Function that runs just before the server starts. diff --git a/templates/astroneer.psm1 b/templates/astroneer.psm1 index 9e5a873..a0e973e 100644 --- a/templates/astroneer.psm1 +++ b/templates/astroneer.psm1 @@ -115,7 +115,7 @@ $BackupsDetails = @{ Weeks = 4 #Folder to include in backup - Saves = ".\servers\Astroneer\Astro\Saved" + Saves = ".\servers\$($Server.Name)\Astro\Saved" } #Create the object @@ -163,7 +163,8 @@ $Warnings = New-Object -TypeName PsObject -Property $WarningsDetails #Launch Arguments $ArgumentList = @() Add-Member -InputObject $Server -Name "ArgumentList" -Type NoteProperty -Value $ArgumentList -Add-Member -InputObject $Server -Name "Launcher" -Type NoteProperty -Value $Server.Exec +Add-Member -InputObject $Server -Name "Launcher" -Type NoteProperty -Value "$($Server.Exec)" +Add-Member -InputObject $Server -Name "WorkingDirectory" -Type NoteProperty -Value "$($Server.Path)" #--------------------------------------------------------- # Function that runs just before the server starts. diff --git a/templates/insurgencysandstorm.psm1 b/templates/insurgencysandstorm.psm1 index b9cc0bf..fe73361 100644 --- a/templates/insurgencysandstorm.psm1 +++ b/templates/insurgencysandstorm.psm1 @@ -224,7 +224,8 @@ $ArgumentList = @( "-log" ) Add-Member -InputObject $Server -Name "ArgumentList" -Type NoteProperty -Value $ArgumentList -Add-Member -InputObject $Server -Name "Launcher" -Type NoteProperty -Value $Server.Exec +Add-Member -InputObject $Server -Name "Launcher" -Type NoteProperty -Value "$($Server.Exec)" +Add-Member -InputObject $Server -Name "WorkingDirectory" -Type NoteProperty -Value "$($Server.Path)" #--------------------------------------------------------- # Function that runs just before the server starts. diff --git a/templates/killingfloor2.psm1 b/templates/killingfloor2.psm1 index 4f18a84..c223438 100644 --- a/templates/killingfloor2.psm1 +++ b/templates/killingfloor2.psm1 @@ -142,7 +142,7 @@ $BackupsDetails = @{ Weeks = 4 #Folder to include in backup - Saves = ".\servers\$Name\KFGame\Config\" + Saves = ".\servers\$($Server.Name)\KFGame\Config\" } #Create the object $Backups = New-Object -TypeName PsObject -Property $BackupsDetails @@ -199,7 +199,8 @@ $ArgumentList = @( "-ConfigSubDir=KF$($Server.UID)" ) Add-Member -InputObject $Server -Name "ArgumentList" -Type NoteProperty -Value $ArgumentList -Add-Member -InputObject $Server -Name "Launcher" -Type NoteProperty -Value $Server.Exec +Add-Member -InputObject $Server -Name "Launcher" -Type NoteProperty -Value "$($Server.Exec)" +Add-Member -InputObject $Server -Name "WorkingDirectory" -Type NoteProperty -Value "$($Server.Path)" #--------------------------------------------------------- # Function that runs just before the server starts. diff --git a/templates/left4dead2.psm1 b/templates/left4dead2.psm1 index 11d53be..975a970 100644 --- a/templates/left4dead2.psm1 +++ b/templates/left4dead2.psm1 @@ -134,7 +134,7 @@ $BackupsDetails = @{ Weeks = 4 #Folder to include in backup - Saves = ".\servers\$Name\left4dead2\cfg" + Saves = ".\servers\$($Server.Name)\left4dead2\cfg" } #Create the object $Backups = New-Object -TypeName PsObject -Property $BackupsDetails @@ -196,7 +196,8 @@ $ArgumentList = @( "+exec $($Server.ConfigFile)" ) Add-Member -InputObject $Server -Name "ArgumentList" -Type NoteProperty -Value $ArgumentList -Add-Member -InputObject $Server -Name "Launcher" -Type NoteProperty -Value $Server.Exec +Add-Member -InputObject $Server -Name "Launcher" -Type NoteProperty -Value "$($Server.Exec)" +Add-Member -InputObject $Server -Name "WorkingDirectory" -Type NoteProperty -Value "$($Server.Path)" #--------------------------------------------------------- # Function that runs just before the server starts. diff --git a/templates/mordhau.psm1 b/templates/mordhau.psm1 index a3b2d4b..11f1fd0 100644 --- a/templates/mordhau.psm1 +++ b/templates/mordhau.psm1 @@ -1,5 +1,8 @@ <# - ".\servers\$Name\Multiplayer\config.cfg" + Edit configuration in : .\servers\Mordhau\Mordhau\Saved\Config\WindowsServer + Modify Game.ini and Engine.ini + Instructions here + https://mordhau.fandom.com/wiki/Dedicated_Server_Hosting_Guide#Configuring_and_Running_the_Server #> #Server Name, use the same name to share game files. @@ -17,17 +20,29 @@ $ServerDetails = @{ #Login username used by SteamCMD Login = "anonymous" - #Name of the server in the Server Browser - ConfigFile = ".\servers\$Name\Multiplayer\config.cfg" + #Server Port + Port = 7778 - #Rcon IP (not supported by valheim yet.) + #Query Port + QueryPort = 27016 + + #Beacon Port + Beaconport = 15000 + + #Modified Game.ini + GameIni = ".\servers\Mordhau\Mordhau\Saved\Config\WindowsServer\Game2.ini" + + #Modified Engine.ini + EngineIni = ".\servers\Mordhau\Mordhau\Saved\Config\WindowsServer\Engine2.ini" + + #Rcon IP ManagementIP = "127.0.0.1" #Rcon Port - ManagementPort = "" + ManagementPort = 15002 #Rcon Password - ManagementPassword = "" + ManagementPassword = "CHANGEME" #--------------------------------------------------------- # Server Installation Details @@ -40,7 +55,7 @@ $ServerDetails = @{ Path = ".\servers\$Name" #Server configuration folder - ConfigFolder = ".\servers\$Name\Multiplayer\" + ConfigFolder = ".\servers\Mordhau\Mordhau\Saved\Config\WindowsServer" #Steam Server App Id AppID = 629800 @@ -55,13 +70,13 @@ $ServerDetails = @{ AutoUpdates = $true #Process name in the task manager - ProcessName = "TerrariaServer" + ProcessName = "MordhauServer-Win64-Shipping" #Use PID instead of Process Name, Will still use processname if the PID fails to find anything. - UsePID = $true + UsePID = $false #Server Executable - Exec = ".\servers\$Name\TerrariaServer.exe" + Exec = ".\servers\$Name\MordhauServer.exe" #Allow force close, usefull for server without RCON and Multiple instances. AllowForceClose = $true @@ -116,7 +131,7 @@ $BackupsDetails = @{ Weeks = 4 #Folder to include in backup - Saves = ".\servers\$Name" + Saves = ".\servers\$($Server.Name)\Mordhau\Saved\Config\WindowsServer" } #Create the object $Backups = New-Object -TypeName PsObject -Property $BackupsDetails @@ -127,7 +142,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" @@ -145,7 +160,7 @@ $WarningsDetails = @{ CmdMessage = "say" #command to save the server - CmdSave = "saveworld" + CmdSave = "stats" #How long to wait in seconds after the save command is sent. SaveDelay = 15 @@ -160,16 +175,23 @@ $Warnings = New-Object -TypeName PsObject -Property $WarningsDetails # Launch Arguments #--------------------------------------------------------- +#Addresse parsing and slash flipping +$Server.GameIni = (Resolve-CompletePath -Path $Server.GameIni -ParentPath ".\servers\") -replace '\\','/' +$Server.EngineIni = (Resolve-CompletePath -Path $Server.EngineIni -ParentPath ".\servers\") -replace '\\','/' + #Launch Arguments $ArgumentList = @( - "-batchmode ", - "-dedicated ", - "-nographics ", - "-nosteamclient ", - "-configfilepath `"$($Server.ConfigFile)`"" + "-Port=$($Server.Port) ", + "-QueryPort=$($Server.QueryPort) ", + "-Beaconport=$($Server.Beaconport) ", + "-GAMEINI=`"$($Server.GameIni)`" ", + "-ENGINEINI=`"$($Server.EngineIni)`" ", + "-log" + ) Add-Member -InputObject $Server -Name "ArgumentList" -Type NoteProperty -Value $ArgumentList -Add-Member -InputObject $Server -Name "Launcher" -Type NoteProperty -Value $Server.Exec +Add-Member -InputObject $Server -Name "Launcher" -Type NoteProperty -Value "$($Server.Exec)" +Add-Member -InputObject $Server -Name "WorkingDirectory" -Type NoteProperty -Value "$($Server.Path)" #--------------------------------------------------------- # Function that runs just before the server starts. @@ -177,7 +199,7 @@ Add-Member -InputObject $Server -Name "Launcher" -Type NoteProperty -Value $Serv function Start-ServerPrep { - Write-ScriptMsg "Port Forward : $($server.Port) in TCP and UDP to $($Global.InternalIP)" + Write-ScriptMsg "Port Forward : $($server.Port), $($server.QueryPort), $($server.Beaconport) in TCP and UDP to $($Global.InternalIP)" } diff --git a/templates/paperclip.psm1 b/templates/paperclip.psm1 index 432bd94..b336048 100644 --- a/templates/paperclip.psm1 +++ b/templates/paperclip.psm1 @@ -42,7 +42,7 @@ $ServerDetails = @{ #World size is specified by: 1(small), 2(medium), and 3(large). AutoCreate = 2 - #Rcon IP (not supported by valheim yet.) + #Rcon IP ManagementIP = "127.0.0.1" #Rcon Port @@ -200,7 +200,8 @@ $ArgumentList = @( "-steam " ) Add-Member -InputObject $Server -Name "ArgumentList" -Type NoteProperty -Value $ArgumentList -Add-Member -InputObject $Server -Name "Launcher" -Type NoteProperty -Value $Server.Exec +Add-Member -InputObject $Server -Name "Launcher" -Type NoteProperty -Value "$($Server.Exec)" +Add-Member -InputObject $Server -Name "WorkingDirectory" -Type NoteProperty -Value "$($Server.Path)" #--------------------------------------------------------- # Function that runs just before the server starts. diff --git a/templates/pixark.psm1 b/templates/pixark.psm1 index 7a79db1..2de799b 100644 --- a/templates/pixark.psm1 +++ b/templates/pixark.psm1 @@ -240,7 +240,8 @@ $ArgumentList = @( "-log" ) Add-Member -InputObject $Server -Name "ArgumentList" -Type NoteProperty -Value $ArgumentList -Add-Member -InputObject $Server -Name "Launcher" -Type NoteProperty -Value $Server.Exec +Add-Member -InputObject $Server -Name "Launcher" -Type NoteProperty -Value "$($Server.Exec)" +Add-Member -InputObject $Server -Name "WorkingDirectory" -Type NoteProperty -Value "$($Server.Path)" #--------------------------------------------------------- # Function that runs just before the server starts. diff --git a/templates/projectzomboid.psm1 b/templates/projectzomboid.psm1 index 81a455b..471775a 100644 --- a/templates/projectzomboid.psm1 +++ b/templates/projectzomboid.psm1 @@ -211,6 +211,7 @@ $ArgumentList = @( ) Add-Member -InputObject $Server -Name "ArgumentList" -Type NoteProperty -Value $ArgumentList Add-Member -InputObject $Server -Name "Launcher" -Type NoteProperty -Value "$($Server.Path)\jre64\bin\java.exe" +Add-Member -InputObject $Server -Name "WorkingDirectory" -Type NoteProperty -Value "$($Server.Path)" #--------------------------------------------------------- # Function that runs just before the server starts. diff --git a/templates/rust.psm1 b/templates/rust.psm1 index c4dfec4..27e3a16 100644 --- a/templates/rust.psm1 +++ b/templates/rust.psm1 @@ -176,7 +176,7 @@ $BackupsDetails = @{ Weeks = 4 #Folder to include in backup - Saves = ".\servers\$Name\server\$($Server.Identity)" + Saves = ".\servers\$($Server.Name)\server\$($Server.Identity)" } #Create the object $Backups = New-Object -TypeName PsObject -Property $BackupsDetails @@ -252,7 +252,8 @@ $ArgumentList = @( "-logfile $($Server.Identity).txt " ) Add-Member -InputObject $Server -Name "ArgumentList" -Type NoteProperty -Value $ArgumentList -Add-Member -InputObject $Server -Name "Launcher" -Type NoteProperty -Value $Server.Exec +Add-Member -InputObject $Server -Name "Launcher" -Type NoteProperty -Value "$($Server.Exec)" +Add-Member -InputObject $Server -Name "WorkingDirectory" -Type NoteProperty -Value "$($Server.Path)" #--------------------------------------------------------- # Function that runs just before the server starts. diff --git a/templates/squad.psm1 b/templates/squad.psm1 index 7cac771..bc351c5 100644 --- a/templates/squad.psm1 +++ b/templates/squad.psm1 @@ -124,7 +124,7 @@ $BackupsDetails = @{ Weeks = 4 #Folder to include in backup - Saves = ".\servers\$Name\SquadGame\ServerConfig\" + Saves = ".\servers\$($Server.Name)\SquadGame\ServerConfig\" } #Create the object $Backups = New-Object -TypeName PsObject -Property $BackupsDetails @@ -178,7 +178,8 @@ $ArgumentList = @( "-log" ) Add-Member -InputObject $Server -Name "ArgumentList" -Type NoteProperty -Value $ArgumentList -Add-Member -InputObject $Server -Name "Launcher" -Type NoteProperty -Value $Server.Exec +Add-Member -InputObject $Server -Name "Launcher" -Type NoteProperty -Value "$($Server.Exec)" +Add-Member -InputObject $Server -Name "WorkingDirectory" -Type NoteProperty -Value "$($Server.Path)" #--------------------------------------------------------- # Function that runs just before the server starts. diff --git a/templates/starbound.psm1 b/templates/starbound.psm1 index cbe2a5b..3f6d934 100644 --- a/templates/starbound.psm1 +++ b/templates/starbound.psm1 @@ -1,5 +1,6 @@ <# - ".\servers\$Name\Multiplayer\config.cfg" + Edit : .\servers\Starbound\storage\starbound_server.config + https://starbounder.org/Guide:Setting_Up_Multiplayer #> #Server Name, use the same name to share game files. @@ -15,19 +16,16 @@ $ServerDetails = @{ UID = "Starbound_1" #Login username used by SteamCMD - Login = "anonymous" - - #Name of the server in the Server Browser - ConfigFile = ".\servers\$Name\Multiplayer\config.cfg" + Login = "Username" #Rcon IP (not supported by valheim yet.) ManagementIP = "127.0.0.1" #Rcon Port - ManagementPort = "" + ManagementPort = 21026 #Rcon Password - ManagementPassword = "" + ManagementPassword = "Changeme" #--------------------------------------------------------- # Server Installation Details @@ -40,7 +38,7 @@ $ServerDetails = @{ Path = ".\servers\$Name" #Server configuration folder - ConfigFolder = "." + ConfigFolder = ".\servers\$Name\storage" #Steam Server App Id AppID = 533830 @@ -52,16 +50,16 @@ $ServerDetails = @{ BetaBuildPassword = "" #Auto-Update Enable or Disable Auto-Updates, some games don't work well with SteamCMD - AutoUpdates = $true + AutoUpdates = $false #Process name in the task manager - ProcessName = "TerrariaServer" + ProcessName = "starbound_server" #Use PID instead of Process Name, Will still use processname if the PID fails to find anything. UsePID = $true #Server Executable - Exec = ".\servers\$Name\TerrariaServer.exe" + Exec = ".\servers\$Name\win64\starbound_server.exe" #Allow force close, usefull for server without RCON and Multiple instances. AllowForceClose = $true @@ -116,7 +114,7 @@ $BackupsDetails = @{ Weeks = 4 #Folder to include in backup - Saves = ".\servers\$Name" + Saves = ".\servers\$($Server.Name)\storage" } #Create the object $Backups = New-Object -TypeName PsObject -Property $BackupsDetails @@ -161,15 +159,10 @@ $Warnings = New-Object -TypeName PsObject -Property $WarningsDetails #--------------------------------------------------------- #Launch Arguments -$ArgumentList = @( - "-batchmode ", - "-dedicated ", - "-nographics ", - "-nosteamclient ", - "-configfilepath `"$($Server.ConfigFile)`"" -) +$ArgumentList = @() Add-Member -InputObject $Server -Name "ArgumentList" -Type NoteProperty -Value $ArgumentList -Add-Member -InputObject $Server -Name "Launcher" -Type NoteProperty -Value $Server.Exec +Add-Member -InputObject $Server -Name "Launcher" -Type NoteProperty -Value "$($Server.Exec)" +Add-Member -InputObject $Server -Name "WorkingDirectory" -Type NoteProperty -Value "$($Server.Path)\win64" #--------------------------------------------------------- # Function that runs just before the server starts. @@ -177,7 +170,8 @@ Add-Member -InputObject $Server -Name "Launcher" -Type NoteProperty -Value $Serv function Start-ServerPrep { - Write-ScriptMsg "Port Forward : $($server.Port) in TCP and UDP to $($Global.InternalIP)" + Write-ScriptMsg "Port Forward : 21025 and 21026 in TCP and UDP to $($Global.InternalIP)" + Write-ScriptMsg "Edit Server Configuration in .\servers\$Name\storage\starbound_server.config" } diff --git a/templates/stationeers.psm1 b/templates/stationeers.psm1 index 37d3d1d..3782c16 100644 --- a/templates/stationeers.psm1 +++ b/templates/stationeers.psm1 @@ -20,7 +20,7 @@ $ServerDetails = @{ #Name of the server in the Server Browser ConfigFile = ".\servers\$Name\Multiplayer\config.cfg" - #Rcon IP (not supported by valheim yet.) + #Rcon IP ManagementIP = "127.0.0.1" #Rcon Port @@ -116,7 +116,7 @@ $BackupsDetails = @{ Weeks = 4 #Folder to include in backup - Saves = ".\servers\$Name" + Saves = ".\servers\$($Server.Name)" } #Create the object $Backups = New-Object -TypeName PsObject -Property $BackupsDetails @@ -161,15 +161,10 @@ $Warnings = New-Object -TypeName PsObject -Property $WarningsDetails #--------------------------------------------------------- #Launch Arguments -$ArgumentList = @( - "-batchmode ", - "-dedicated ", - "-nographics ", - "-nosteamclient ", - "-configfilepath `"$($Server.ConfigFile)`"" -) +$ArgumentList = @() Add-Member -InputObject $Server -Name "ArgumentList" -Type NoteProperty -Value $ArgumentList -Add-Member -InputObject $Server -Name "Launcher" -Type NoteProperty -Value $Server.Exec +Add-Member -InputObject $Server -Name "Launcher" -Type NoteProperty -Value "$($Server.Exec)" +Add-Member -InputObject $Server -Name "WorkingDirectory" -Type NoteProperty -Value "$($Server.Path)" #--------------------------------------------------------- # Function that runs just before the server starts. diff --git a/templates/terraria.psm1 b/templates/terraria.psm1 index 432bd94..b336048 100644 --- a/templates/terraria.psm1 +++ b/templates/terraria.psm1 @@ -42,7 +42,7 @@ $ServerDetails = @{ #World size is specified by: 1(small), 2(medium), and 3(large). AutoCreate = 2 - #Rcon IP (not supported by valheim yet.) + #Rcon IP ManagementIP = "127.0.0.1" #Rcon Port @@ -200,7 +200,8 @@ $ArgumentList = @( "-steam " ) Add-Member -InputObject $Server -Name "ArgumentList" -Type NoteProperty -Value $ArgumentList -Add-Member -InputObject $Server -Name "Launcher" -Type NoteProperty -Value $Server.Exec +Add-Member -InputObject $Server -Name "Launcher" -Type NoteProperty -Value "$($Server.Exec)" +Add-Member -InputObject $Server -Name "WorkingDirectory" -Type NoteProperty -Value "$($Server.Path)" #--------------------------------------------------------- # Function that runs just before the server starts. diff --git a/templates/theforest.psm1 b/templates/theforest.psm1 index 121e984..0af5c6f 100644 --- a/templates/theforest.psm1 +++ b/templates/theforest.psm1 @@ -53,7 +53,7 @@ $ServerDetails = @{ #Set the game difficult level, default is Normal ("Peaceful" | "Normal" | "Hard") Difficulty = "Normal" - #Rcon IP (not supported by valheim yet.) + #Rcon IP ManagementIP = "127.0.0.1" #Rcon Port @@ -216,7 +216,8 @@ $ArgumentList = @( "-savefolderpath .\" ) Add-Member -InputObject $Server -Name "ArgumentList" -Type NoteProperty -Value $ArgumentList -Add-Member -InputObject $Server -Name "Launcher" -Type NoteProperty -Value $Server.Exec +Add-Member -InputObject $Server -Name "Launcher" -Type NoteProperty -Value "$($Server.Exec)" +Add-Member -InputObject $Server -Name "WorkingDirectory" -Type NoteProperty -Value "$($Server.Path)" #--------------------------------------------------------- # Function that runs just before the server starts. diff --git a/templates/valheim.psm1 b/templates/valheim.psm1 index 3733b7f..3d7e73b 100644 --- a/templates/valheim.psm1 +++ b/templates/valheim.psm1 @@ -176,7 +176,8 @@ $ArgumentList = @( "-public 1" ) Add-Member -InputObject $Server -Name "ArgumentList" -Type NoteProperty -Value $ArgumentList -Add-Member -InputObject $Server -Name "Launcher" -Type NoteProperty -Value $Server.Exec +Add-Member -InputObject $Server -Name "Launcher" -Type NoteProperty -Value "$($Server.Exec)" +Add-Member -InputObject $Server -Name "WorkingDirectory" -Type NoteProperty -Value "$($Server.Path)" #--------------------------------------------------------- # Function that runs just before the server starts. From 07cb6b9503c8d49ed4efe6f50e0599eb1f0ba68e Mon Sep 17 00:00:00 2001 From: Patrick Veilleux Date: Mon, 20 Sep 2021 20:01:21 -0400 Subject: [PATCH 08/12] add Stationeers --- configs/stationeers.psm1 | 238 +++++++++++++++++++++++++++++ launchers/run.cmd | 2 +- templates/insurgencysandstorm.psm1 | 2 +- templates/killingfloor2.psm1 | 4 +- templates/left4dead2.psm1 | 2 +- templates/mordhau.psm1 | 4 +- templates/paperclip.psm1 | 2 +- templates/pixark.psm1 | 2 +- templates/rust.psm1 | 2 +- templates/squad.psm1 | 2 +- templates/stationeers.psm1 | 87 +++++++++-- templates/terraria.psm1 | 2 +- templates/valheim.psm1 | 2 +- 13 files changed, 324 insertions(+), 27 deletions(-) create mode 100644 configs/stationeers.psm1 diff --git a/configs/stationeers.psm1 b/configs/stationeers.psm1 new file mode 100644 index 0000000..a077f7b --- /dev/null +++ b/configs/stationeers.psm1 @@ -0,0 +1,238 @@ +<# + Not tested but should work. + Edit .\servers\$Name\default.ini to configure this server +#> + +#Server Name, use the same name to share game files. +$Name = "Stationeers" + +#--------------------------------------------------------- +# Server Configuration +#--------------------------------------------------------- + +$ServerDetails = @{ + + #Unique Identifier used to track processes. Must be unique to each servers. + UID = "Stationeers_1" + + #Login username used by SteamCMD + Login = "anonymous" + + #Server Name + SessionName = "My Stationeers Server" + + #Auto Save Interval in seconds + AutoSaveInterval = 300 + + #Server Owner SteamID64 https://steamid.io/ + Creator = 76561197993918508 + + #World Type + WorldType = "Mars" + + #World Name *(Save name) + WorldName = "Mars1" + + #World that will be loaded + LoadWorld = "MyWorld" + + #Game Port + Port = 27500 + + #Steam Query Port + QueryPort = 27015 + + #Server Password + Password = "Changeme" + + #Max Players + MaxPlayers = 16 + + #Clear All Interval (Will delete disconnected players) + ClearAllInterval = 0 + + #Mod Folder Path + ModPath = ".\servers\$Name\mods" + + #Rcon IP + ManagementIP = "127.0.0.1" + + #Rcon Port + ManagementPort = 27500 + + #Rcon Password + ManagementPassword = "stationeers" + +#--------------------------------------------------------- +# Server Installation Details +#--------------------------------------------------------- + + #Name of the Server Instance + Name = $Name + + #Server Installation Path + Path = ".\servers\$Name" + + #Server configuration folder + ConfigFolder = ".\servers\$Name" + + #Steam Server App Id + AppID = 600760 + + #Name of the Beta Build + BetaBuild = "" + + #Beta Build Password + BetaBuildPassword = "" + + #Auto-Update Enable or Disable Auto-Updates, some games don't work well with SteamCMD + AutoUpdates = $true + + #Process name in the task manager + ProcessName = "rocketstation_DedicatedServer" + + #Use PID instead of Process Name, Will still use processname if the PID fails to find anything. + UsePID = $true + + #Server Executable + Exec = ".\servers\$Name\rocketstation_DedicatedServer.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 + + #How long should it wait to check if the server is stable + StartupWaitTime = 10 +} +#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)\saves" +} +#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 #Not quite supported. + + #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 = "notice" + + #command to save the server + CmdSave = "save $($Server.WorldName)" + + #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 +#--------------------------------------------------------- + +#Address parsing +if ($Server.ModPath -ne ""){ + $Server.ModPath = (Resolve-CompletePath -Path $Server.ModPath -ParentPath ".\servers\") +} +$LogFilePath = (Resolve-CompletePath -Path "$($Server.Path)\$($Server.UID).txt" -ParentPath ".\servers\") +Add-Member -InputObject $Server -Name "LogFile" -Type NoteProperty -Value $LogFilePath + +#Launch Arguments +$ArgumentList = @( + "-batchmode ", + "-nographics ", + "-autostart ", + "-logfile=$($Server.LogFile) ", + "-servername=$($Server.SessionName) ", + "-autosaveinterval=$($Server.AutoSaveInterval) ", + "-creator=$($Server.Creator) ", + "-worldtype=$($Server.WorldType) ", + "-worldname=$($Server.WorldName) ", + "-loadworld=$($Server.LoadWorld) ", + "-gameport=$($Server.Port) ", + "-updateport=$($Server.QueryPort) ", + "-password=$($Server.Password) ", + "-maxplayer=$($Server.MaxPlayers) ", + "-clearallinterval=$($Server.ClearAllInterval) ", + "-modpath=$($Server.ModPath) ", + "-bindip=$($Global.InternalIP)" +) +Add-Member -InputObject $Server -Name "ArgumentList" -Type NoteProperty -Value $ArgumentList +Add-Member -InputObject $Server -Name "Launcher" -Type NoteProperty -Value "$($Server.Exec)" +Add-Member -InputObject $Server -Name "WorkingDirectory" -Type NoteProperty -Value "$($Server.Path)" + +#--------------------------------------------------------- +# Function that runs just before the server starts. +#--------------------------------------------------------- + +function Start-ServerPrep { + + Write-ScriptMsg "Port Forward : $($Server.Port) and $($Server.QueryPort) in TCP and UDP to $($Global.InternalIP)" + +} + +Export-ModuleMember -Function Start-ServerPrep -Variable @("Server","Backups","Warnings") \ No newline at end of file diff --git a/launchers/run.cmd b/launchers/run.cmd index e8705a4..471e1db 100644 --- a/launchers/run.cmd +++ b/launchers/run.cmd @@ -1,2 +1,2 @@ cd .. -start powershell.exe -noprofile -executionpolicy bypass -file ".\main.ps1" -ServerCfg "starbound" \ No newline at end of file +start powershell.exe -noprofile -executionpolicy bypass -file ".\main.ps1" -ServerCfg "stationeers" \ No newline at end of file diff --git a/templates/insurgencysandstorm.psm1 b/templates/insurgencysandstorm.psm1 index fe73361..b6af074 100644 --- a/templates/insurgencysandstorm.psm1 +++ b/templates/insurgencysandstorm.psm1 @@ -233,7 +233,7 @@ Add-Member -InputObject $Server -Name "WorkingDirectory" -Type NoteProperty -Val function Start-ServerPrep { - Write-ScriptMsg "Port Forward : $($server.Port) and $($server.QueryPort) in TCP and UDP to $($Global.InternalIP)" + Write-ScriptMsg "Port Forward : $($Server.Port) and $($Server.QueryPort) in TCP and UDP to $($Global.InternalIP)" } diff --git a/templates/killingfloor2.psm1 b/templates/killingfloor2.psm1 index c223438..de0d1c5 100644 --- a/templates/killingfloor2.psm1 +++ b/templates/killingfloor2.psm1 @@ -208,8 +208,8 @@ Add-Member -InputObject $Server -Name "WorkingDirectory" -Type NoteProperty -Val function Start-ServerPrep { - 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.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." } diff --git a/templates/left4dead2.psm1 b/templates/left4dead2.psm1 index 975a970..77662b2 100644 --- a/templates/left4dead2.psm1 +++ b/templates/left4dead2.psm1 @@ -247,7 +247,7 @@ function Start-ServerPrep { New-Item -Path ".\servers\$($Server.Name)\left4dead2\cfg\" -Name "$($Server.ConfigFile)" -ItemType "file" -Value $FileContent } - Write-ScriptMsg "Port Forward : $($server.Port) in TCP and UDP to $($Global.InternalIP)" + Write-ScriptMsg "Port Forward : $($Server.Port) in TCP and UDP to $($Global.InternalIP)" } diff --git a/templates/mordhau.psm1 b/templates/mordhau.psm1 index 11f1fd0..657b7c5 100644 --- a/templates/mordhau.psm1 +++ b/templates/mordhau.psm1 @@ -175,7 +175,7 @@ $Warnings = New-Object -TypeName PsObject -Property $WarningsDetails # Launch Arguments #--------------------------------------------------------- -#Addresse parsing and slash flipping +#Address parsing and slash flipping $Server.GameIni = (Resolve-CompletePath -Path $Server.GameIni -ParentPath ".\servers\") -replace '\\','/' $Server.EngineIni = (Resolve-CompletePath -Path $Server.EngineIni -ParentPath ".\servers\") -replace '\\','/' @@ -199,7 +199,7 @@ Add-Member -InputObject $Server -Name "WorkingDirectory" -Type NoteProperty -Val function Start-ServerPrep { - Write-ScriptMsg "Port Forward : $($server.Port), $($server.QueryPort), $($server.Beaconport) in TCP and UDP to $($Global.InternalIP)" + Write-ScriptMsg "Port Forward : $($Server.Port), $($Server.QueryPort), $($Server.Beaconport) in TCP and UDP to $($Global.InternalIP)" } diff --git a/templates/paperclip.psm1 b/templates/paperclip.psm1 index b336048..ac33dcb 100644 --- a/templates/paperclip.psm1 +++ b/templates/paperclip.psm1 @@ -236,7 +236,7 @@ function Start-ServerPrep { #Write new Version File New-Item -Path ".\servers\$($Server.Name)\" -Name "Version.txt" -ItemType "file" -Value "$($Server.Version)" -Force -ErrorAction SilentlyContinue } - Write-ScriptMsg "Port Forward : $($server.Port) in TCP and UDP to $($Global.InternalIP)" + Write-ScriptMsg "Port Forward : $($Server.Port) in TCP and UDP to $($Global.InternalIP)" } Export-ModuleMember -Function Start-ServerPrep -Variable @("Server","Backups","Warnings") \ No newline at end of file diff --git a/templates/pixark.psm1 b/templates/pixark.psm1 index 2de799b..9e6e7b0 100644 --- a/templates/pixark.psm1 +++ b/templates/pixark.psm1 @@ -249,7 +249,7 @@ Add-Member -InputObject $Server -Name "WorkingDirectory" -Type NoteProperty -Val function Start-ServerPrep { - Write-ScriptMsg "Port Forward : $($server.Port), $($server.QueryPort) And $($server.CubePort) in TCP and UDP to $($Global.InternalIP)" + Write-ScriptMsg "Port Forward : $($Server.Port), $($Server.QueryPort) And $($Server.CubePort) in TCP and UDP to $($Global.InternalIP)" } diff --git a/templates/rust.psm1 b/templates/rust.psm1 index 27e3a16..36275a0 100644 --- a/templates/rust.psm1 +++ b/templates/rust.psm1 @@ -261,7 +261,7 @@ Add-Member -InputObject $Server -Name "WorkingDirectory" -Type NoteProperty -Val function Start-ServerPrep { - Write-ScriptMsg "Port Forward : $($server.Port), $($server.ManagementPort), $($Server.Port + 69) in TCP and UDP to $($Global.InternalIP)" + Write-ScriptMsg "Port Forward : $($Server.Port), $($Server.ManagementPort), $($Server.Port + 69) in TCP and UDP to $($Global.InternalIP)" } diff --git a/templates/squad.psm1 b/templates/squad.psm1 index bc351c5..d7ed920 100644 --- a/templates/squad.psm1 +++ b/templates/squad.psm1 @@ -187,7 +187,7 @@ Add-Member -InputObject $Server -Name "WorkingDirectory" -Type NoteProperty -Val function Start-ServerPrep { - Write-ScriptMsg "Port Forward : $($server.Port) and $($server.QueryPort) in TCP and UDP to $($Global.InternalIP)" + Write-ScriptMsg "Port Forward : $($Server.Port) and $($Server.QueryPort) in TCP and UDP to $($Global.InternalIP)" } diff --git a/templates/stationeers.psm1 b/templates/stationeers.psm1 index 3782c16..a077f7b 100644 --- a/templates/stationeers.psm1 +++ b/templates/stationeers.psm1 @@ -1,5 +1,6 @@ <# - ".\servers\$Name\Multiplayer\config.cfg" + Not tested but should work. + Edit .\servers\$Name\default.ini to configure this server #> #Server Name, use the same name to share game files. @@ -17,17 +18,50 @@ $ServerDetails = @{ #Login username used by SteamCMD Login = "anonymous" - #Name of the server in the Server Browser - ConfigFile = ".\servers\$Name\Multiplayer\config.cfg" + #Server Name + SessionName = "My Stationeers Server" + + #Auto Save Interval in seconds + AutoSaveInterval = 300 + + #Server Owner SteamID64 https://steamid.io/ + Creator = 76561197993918508 + + #World Type + WorldType = "Mars" + + #World Name *(Save name) + WorldName = "Mars1" + + #World that will be loaded + LoadWorld = "MyWorld" + + #Game Port + Port = 27500 + + #Steam Query Port + QueryPort = 27015 + + #Server Password + Password = "Changeme" + + #Max Players + MaxPlayers = 16 + + #Clear All Interval (Will delete disconnected players) + ClearAllInterval = 0 + + #Mod Folder Path + ModPath = ".\servers\$Name\mods" #Rcon IP ManagementIP = "127.0.0.1" #Rcon Port - ManagementPort = "" + ManagementPort = 27500 #Rcon Password - ManagementPassword = "" + ManagementPassword = "stationeers" #--------------------------------------------------------- # Server Installation Details @@ -40,7 +74,7 @@ $ServerDetails = @{ Path = ".\servers\$Name" #Server configuration folder - ConfigFolder = "." + ConfigFolder = ".\servers\$Name" #Steam Server App Id AppID = 600760 @@ -55,13 +89,13 @@ $ServerDetails = @{ AutoUpdates = $true #Process name in the task manager - ProcessName = "TerrariaServer" + ProcessName = "rocketstation_DedicatedServer" #Use PID instead of Process Name, Will still use processname if the PID fails to find anything. UsePID = $true #Server Executable - Exec = ".\servers\$Name\TerrariaServer.exe" + Exec = ".\servers\$Name\rocketstation_DedicatedServer.exe" #Allow force close, usefull for server without RCON and Multiple instances. AllowForceClose = $true @@ -116,7 +150,7 @@ $BackupsDetails = @{ Weeks = 4 #Folder to include in backup - Saves = ".\servers\$($Server.Name)" + Saves = ".\servers\$($Server.Name)\saves" } #Create the object $Backups = New-Object -TypeName PsObject -Property $BackupsDetails @@ -127,7 +161,7 @@ $Backups = New-Object -TypeName PsObject -Property $BackupsDetails $WarningsDetails = @{ #Use Rcon to restart server softly. - Use = $false + Use = $false #Not quite supported. #What protocol to use : Rcon, Telnet, Websocket Protocol = "Rcon" @@ -142,10 +176,10 @@ $WarningsDetails = @{ MessageSec = "The server will restart in % seconds !" #command to send a message. - CmdMessage = "say" + CmdMessage = "notice" #command to save the server - CmdSave = "saveworld" + CmdSave = "save $($Server.WorldName)" #How long to wait in seconds after the save command is sent. SaveDelay = 15 @@ -160,8 +194,33 @@ $Warnings = New-Object -TypeName PsObject -Property $WarningsDetails # Launch Arguments #--------------------------------------------------------- +#Address parsing +if ($Server.ModPath -ne ""){ + $Server.ModPath = (Resolve-CompletePath -Path $Server.ModPath -ParentPath ".\servers\") +} +$LogFilePath = (Resolve-CompletePath -Path "$($Server.Path)\$($Server.UID).txt" -ParentPath ".\servers\") +Add-Member -InputObject $Server -Name "LogFile" -Type NoteProperty -Value $LogFilePath + #Launch Arguments -$ArgumentList = @() +$ArgumentList = @( + "-batchmode ", + "-nographics ", + "-autostart ", + "-logfile=$($Server.LogFile) ", + "-servername=$($Server.SessionName) ", + "-autosaveinterval=$($Server.AutoSaveInterval) ", + "-creator=$($Server.Creator) ", + "-worldtype=$($Server.WorldType) ", + "-worldname=$($Server.WorldName) ", + "-loadworld=$($Server.LoadWorld) ", + "-gameport=$($Server.Port) ", + "-updateport=$($Server.QueryPort) ", + "-password=$($Server.Password) ", + "-maxplayer=$($Server.MaxPlayers) ", + "-clearallinterval=$($Server.ClearAllInterval) ", + "-modpath=$($Server.ModPath) ", + "-bindip=$($Global.InternalIP)" +) Add-Member -InputObject $Server -Name "ArgumentList" -Type NoteProperty -Value $ArgumentList Add-Member -InputObject $Server -Name "Launcher" -Type NoteProperty -Value "$($Server.Exec)" Add-Member -InputObject $Server -Name "WorkingDirectory" -Type NoteProperty -Value "$($Server.Path)" @@ -172,7 +231,7 @@ Add-Member -InputObject $Server -Name "WorkingDirectory" -Type NoteProperty -Val function Start-ServerPrep { - Write-ScriptMsg "Port Forward : $($server.Port) in TCP and UDP to $($Global.InternalIP)" + Write-ScriptMsg "Port Forward : $($Server.Port) and $($Server.QueryPort) in TCP and UDP to $($Global.InternalIP)" } diff --git a/templates/terraria.psm1 b/templates/terraria.psm1 index b336048..ac33dcb 100644 --- a/templates/terraria.psm1 +++ b/templates/terraria.psm1 @@ -236,7 +236,7 @@ function Start-ServerPrep { #Write new Version File New-Item -Path ".\servers\$($Server.Name)\" -Name "Version.txt" -ItemType "file" -Value "$($Server.Version)" -Force -ErrorAction SilentlyContinue } - Write-ScriptMsg "Port Forward : $($server.Port) in TCP and UDP to $($Global.InternalIP)" + Write-ScriptMsg "Port Forward : $($Server.Port) in TCP and UDP to $($Global.InternalIP)" } Export-ModuleMember -Function Start-ServerPrep -Variable @("Server","Backups","Warnings") \ No newline at end of file diff --git a/templates/valheim.psm1 b/templates/valheim.psm1 index 3d7e73b..fd7d132 100644 --- a/templates/valheim.psm1 +++ b/templates/valheim.psm1 @@ -185,7 +185,7 @@ Add-Member -InputObject $Server -Name "WorkingDirectory" -Type NoteProperty -Val function Start-ServerPrep { - Write-ScriptMsg "Port Forward : $($server.Port) in TCP and UDP to $($Global.InternalIP)" + Write-ScriptMsg "Port Forward : $($Server.Port) in TCP and UDP to $($Global.InternalIP)" } From 7b91dd68a60916d010f4659ba3241ef8dbaed74c Mon Sep 17 00:00:00 2001 From: Patrick Veilleux Date: Mon, 20 Sep 2021 21:55:37 -0400 Subject: [PATCH 09/12] Add Paperclip Minecraft Server --- configs/global.psm1 | 3 + configs/paperclip.psm1 | 285 +++++++++++++++++++++++++++++++++++++ configs/stationeers.psm1 | 238 ------------------------------- functions/Read-Config.psm1 | 1 + launchers/run.cmd | 2 +- templates/paperclip.psm1 | 157 ++++++++++++-------- 6 files changed, 390 insertions(+), 296 deletions(-) create mode 100644 configs/paperclip.psm1 delete mode 100644 configs/stationeers.psm1 diff --git a/configs/global.psm1 b/configs/global.psm1 index 0910008..60fb385 100644 --- a/configs/global.psm1 +++ b/configs/global.psm1 @@ -8,6 +8,9 @@ $GlobalDetails = @{ #SteamCMD SteamCMD = ".\tools\SteamCMD\steamcmd.exe" + #Java Directory + JavaDirectory =".\tools\java" + #Path of the logs folder. LogFolder = ".\logs" diff --git a/configs/paperclip.psm1 b/configs/paperclip.psm1 new file mode 100644 index 0000000..e1c1cde --- /dev/null +++ b/configs/paperclip.psm1 @@ -0,0 +1,285 @@ +<# + Edit .\servers\Paperclip\server.properties +#> + +#Server Name, use the same name to share game files. +$Name = "Paperclip" + +#--------------------------------------------------------- +# Server Configuration +#--------------------------------------------------------- + +$ServerDetails = @{ + + #Unique Identifier used to track processes. Must be unique to each servers. + UID = "Paperclip_1" + + #Login username used by SteamCMD + Login = "anonymous" + + # Server Name + SessionName = "My Minecraft Server" + + # Message of the day, also shows in server browser + MOTD = "\u00A76My Server - \u00A7AMinecraft 1.17.1" + + # Specifies the port to listen on. + Port = 25565 + + # Specifies the port to listen on. + QueryPort = 25565 + + # Sets the max number of players + MaxPlayers = 64 + + # Sets the server Game Mode + GameMode = "survival" + + #Level Name + World = "world" + + #Level Type + LevelType = "default" + + #Specifies the world seed when using -autocreate + Seed = 1234 + + #Difficulty + Difficulty = "normal" + + #Amount of ram dedicated to the server in Go + Ram = 2 + + #Rcon IP + ManagementIP = "127.0.0.1" + + #Rcon Port + ManagementPort = 25575 + + #Rcon Password + ManagementPassword = "CHANGEME" + +#--------------------------------------------------------- +# Server Installation Details +#--------------------------------------------------------- + + #Name of the Server Instance + Name = $Name + + #Server Installation Path + Path = ".\servers\$Name" + + #Server configuration folder + ConfigFolder = ".\servers\$Name" + + #Server Version https://adoptopenjdk.net/releases.html?variant=openjdk16&jvmVariant=hotspot + JavaVersionLink = "https://github.com/AdoptOpenJDK/openjdk16-binaries/releases/download/jdk-16.0.1%2B9/OpenJDK16U-jre_x64_windows_hotspot_16.0.1_9.msi" + + #Server Version https://papermc.io/downloads#Paper-1.17 + PaperclipVersionLink = "https://papermc.io/api/v2/projects/paper/versions/1.17.1/builds/265/downloads/paper-1.17.1-265.jar" + + #Steam Server App Id *0 Skip SteamCMD Installation + AppID = 0 + + #Name of the Beta Build + BetaBuild = "" + + #Beta Build Password + BetaBuildPassword = "" + + #Auto-Update Enable or Disable Auto-Updates, some games don't work well with SteamCMD + AutoUpdates = $false + + #Process name in the task manager + ProcessName = "java" + + #Use PID instead of Process Name, Will still use processname if the PID fails to find anything. + UsePID = $true + + #Server Executable + Exec = ".\servers\$Name\paperclip.jar" + + #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 + + #How long should it wait to check if the server is stable + StartupWaitTime = 10 +} +#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\Documents\My Games\Terraria\Worlds" +} +#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 = "save-all" + + #How long to wait in seconds after the save command is sent. + SaveDelay = 15 + + #command to stop the server + CmdStop = "stop" +} +#Create the object +$Warnings = New-Object -TypeName PsObject -Property $WarningsDetails + +#--------------------------------------------------------- +# Launch Arguments +#--------------------------------------------------------- + +#Launch Arguments +$ArgumentList = @( + "-Xms$($Server.Ram)G ", + "-Xmx$($Server.Ram)G ", + "-jar paperclip.jar ", + "--nogui" +) +Add-Member -InputObject $Server -Name "ArgumentList" -Type NoteProperty -Value $ArgumentList +Add-Member -InputObject $Server -Name "Launcher" -Type NoteProperty -Value "$($Global.JavaDirectory)\OpenJDK16\bin\java.exe" +Add-Member -InputObject $Server -Name "WorkingDirectory" -Type NoteProperty -Value "$($Server.Path)" + +#--------------------------------------------------------- +# server.properties +#--------------------------------------------------------- + +$FileContentList = @( + "difficulty=$($Server.Difficulty)", + "gamemode=$($Server.GameMode)", + "level-name=$($Server.World)", + "level-seed=$($Server.Seed)", + "level-type=$($Server.LevelType)", + "max-players=$($Server.MaxPlayers)", + "motd=$($Server.MOTD)", + "enable-rcon=true", + "rcon.password=$($Server.ManagementPassword)", + "rcon.port=$($Server.ManagementPort)", + "server-name=$($Server.SessionName)", + "server-port=$($Server.Port)", + "query.port=$($Server.QueryPort)" +) + +$FileContent = ($FileContentList -join "`n") + +#--------------------------------------------------------- +# Function that runs just before the server starts. +#--------------------------------------------------------- + +function Start-ServerPrep { + + #Create Config File if not created. + if (-not (Test-Path -Path ".\servers\$($Server.Name)\server.properties" -ErrorAction SilentlyContinue)){ + Write-Host "Creating Config File" + New-Item -Path ".\servers\$($Server.Name)\" -Name "server.properties" -ItemType "file" -Value $FileContent + } + #Create eula File if not created. + if (-not (Test-Path -Path ".\servers\$($Server.Name)\eula.txt" -ErrorAction SilentlyContinue)){ + Write-Host "Creating Config File" + New-Item -Path ".\servers\$($Server.Name)\" -Name "eula.txt" -ItemType "file" -Value "eula=true" + } + #If server is not installed, install it. + $JavaVersion = Get-Content -Path ".\servers\$($Server.Name)\JavaVersion.txt" -ErrorAction SilentlyContinue + if (-not (Test-Path -Path $Server.Exec -PathType "leaf" -ErrorAction SilentlyContinue) -or ($Version -ne $Server.Version)) { + Write-ScriptMsg "Installing Java..." + #Create Temporary Download Folder + New-Item -Path ".\downloads" -ItemType "directory" -ErrorAction SilentlyContinue + #Download Adopt Openjdk-16.0.2+7 + Invoke-Download -Uri $($Server.JavaVersionLink) -OutFile ".\downloads\OpenJDK16.msi" -ErrorAction SilentlyContinue + #Install Adopt Openjdk-16.0.2+7 + $Package = Resolve-Path -Path ".\downloads\OpenJDK16.msi" + Start-Process -FilePath msiexec.exe -ArgumentList "/qn /i $Package ADDLOCAL=FeatureMain,FeatureEnvironment,FeatureJarFileRunWith,FeatureJavaHome INSTALLDIR=`"$($Global.JavaDirectory)\OpenJDK16`" /passive" -Verb "RunAs" -Wait + #Cleanup + Remove-Item -Path ".\downloads" -Recurse -Force -ErrorAction SilentlyContinue + #Remove old version file + Remove-Item -Path ".\servers\$($Server.Name)\JavaVersion.txt" -Confirm:$false -ErrorAction SilentlyContinue + #Write new Version File + New-Item -Path ".\servers\$($Server.Name)\" -Name "JavaVersion.txt" -ItemType "file" -Value "$($Server.JavaVersionLink)" -Force -ErrorAction SilentlyContinue + } + $PaperclipVersion = Get-Content -Path ".\servers\$($Server.Name)\PaperVersion.txt" -ErrorAction SilentlyContinue + if (-not (Test-Path -Path $Server.Exec -PathType "leaf" -ErrorAction SilentlyContinue) -or ($Version -ne $Server.Version)) { + Write-ScriptMsg "Installing Paperclip..." + #Create Temporary Download Folder + New-Item -Path ".\downloads" -ItemType "directory" -ErrorAction SilentlyContinue + #Download Paperclip + Invoke-Download -Uri $($Server.PaperclipVersionLink) -OutFile ".\downloads\paperclip.jar" -ErrorAction SilentlyContinue + #Copy Server Files to Server Directory + Copy-Item -Path ".\downloads\paperclip.jar" -Destination $Server.Path -Force + #Cleanup + Remove-Item -Path ".\downloads" -Recurse -Force -ErrorAction SilentlyContinue + #Remove old version file + Remove-Item -Path ".\servers\$($Server.Name)\PaperVersion.txt" -Confirm:$false -ErrorAction SilentlyContinue + #Write new Version File + New-Item -Path ".\servers\$($Server.Name)\" -Name "PaperVersion.txt" -ItemType "file" -Value "$($Server.PaperclipVersionLink)" -Force -ErrorAction SilentlyContinue + } + Write-ScriptMsg "Port Forward : $($Server.Port) in TCP and UDP to $($Global.InternalIP)" +} + +Export-ModuleMember -Function Start-ServerPrep -Variable @("Server","Backups","Warnings") \ No newline at end of file diff --git a/configs/stationeers.psm1 b/configs/stationeers.psm1 deleted file mode 100644 index a077f7b..0000000 --- a/configs/stationeers.psm1 +++ /dev/null @@ -1,238 +0,0 @@ -<# - Not tested but should work. - Edit .\servers\$Name\default.ini to configure this server -#> - -#Server Name, use the same name to share game files. -$Name = "Stationeers" - -#--------------------------------------------------------- -# Server Configuration -#--------------------------------------------------------- - -$ServerDetails = @{ - - #Unique Identifier used to track processes. Must be unique to each servers. - UID = "Stationeers_1" - - #Login username used by SteamCMD - Login = "anonymous" - - #Server Name - SessionName = "My Stationeers Server" - - #Auto Save Interval in seconds - AutoSaveInterval = 300 - - #Server Owner SteamID64 https://steamid.io/ - Creator = 76561197993918508 - - #World Type - WorldType = "Mars" - - #World Name *(Save name) - WorldName = "Mars1" - - #World that will be loaded - LoadWorld = "MyWorld" - - #Game Port - Port = 27500 - - #Steam Query Port - QueryPort = 27015 - - #Server Password - Password = "Changeme" - - #Max Players - MaxPlayers = 16 - - #Clear All Interval (Will delete disconnected players) - ClearAllInterval = 0 - - #Mod Folder Path - ModPath = ".\servers\$Name\mods" - - #Rcon IP - ManagementIP = "127.0.0.1" - - #Rcon Port - ManagementPort = 27500 - - #Rcon Password - ManagementPassword = "stationeers" - -#--------------------------------------------------------- -# Server Installation Details -#--------------------------------------------------------- - - #Name of the Server Instance - Name = $Name - - #Server Installation Path - Path = ".\servers\$Name" - - #Server configuration folder - ConfigFolder = ".\servers\$Name" - - #Steam Server App Id - AppID = 600760 - - #Name of the Beta Build - BetaBuild = "" - - #Beta Build Password - BetaBuildPassword = "" - - #Auto-Update Enable or Disable Auto-Updates, some games don't work well with SteamCMD - AutoUpdates = $true - - #Process name in the task manager - ProcessName = "rocketstation_DedicatedServer" - - #Use PID instead of Process Name, Will still use processname if the PID fails to find anything. - UsePID = $true - - #Server Executable - Exec = ".\servers\$Name\rocketstation_DedicatedServer.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 - - #How long should it wait to check if the server is stable - StartupWaitTime = 10 -} -#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)\saves" -} -#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 #Not quite supported. - - #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 = "notice" - - #command to save the server - CmdSave = "save $($Server.WorldName)" - - #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 -#--------------------------------------------------------- - -#Address parsing -if ($Server.ModPath -ne ""){ - $Server.ModPath = (Resolve-CompletePath -Path $Server.ModPath -ParentPath ".\servers\") -} -$LogFilePath = (Resolve-CompletePath -Path "$($Server.Path)\$($Server.UID).txt" -ParentPath ".\servers\") -Add-Member -InputObject $Server -Name "LogFile" -Type NoteProperty -Value $LogFilePath - -#Launch Arguments -$ArgumentList = @( - "-batchmode ", - "-nographics ", - "-autostart ", - "-logfile=$($Server.LogFile) ", - "-servername=$($Server.SessionName) ", - "-autosaveinterval=$($Server.AutoSaveInterval) ", - "-creator=$($Server.Creator) ", - "-worldtype=$($Server.WorldType) ", - "-worldname=$($Server.WorldName) ", - "-loadworld=$($Server.LoadWorld) ", - "-gameport=$($Server.Port) ", - "-updateport=$($Server.QueryPort) ", - "-password=$($Server.Password) ", - "-maxplayer=$($Server.MaxPlayers) ", - "-clearallinterval=$($Server.ClearAllInterval) ", - "-modpath=$($Server.ModPath) ", - "-bindip=$($Global.InternalIP)" -) -Add-Member -InputObject $Server -Name "ArgumentList" -Type NoteProperty -Value $ArgumentList -Add-Member -InputObject $Server -Name "Launcher" -Type NoteProperty -Value "$($Server.Exec)" -Add-Member -InputObject $Server -Name "WorkingDirectory" -Type NoteProperty -Value "$($Server.Path)" - -#--------------------------------------------------------- -# Function that runs just before the server starts. -#--------------------------------------------------------- - -function Start-ServerPrep { - - Write-ScriptMsg "Port Forward : $($Server.Port) and $($Server.QueryPort) in TCP and UDP to $($Global.InternalIP)" - -} - -Export-ModuleMember -Function Start-ServerPrep -Variable @("Server","Backups","Warnings") \ No newline at end of file diff --git a/functions/Read-Config.psm1 b/functions/Read-Config.psm1 index 3c4908e..7e11168 100644 --- a/functions/Read-Config.psm1 +++ b/functions/Read-Config.psm1 @@ -10,6 +10,7 @@ function Read-Config { $Global.SevenZip = (Resolve-CompletePath -Path $Global.SevenZip -ParentPath ".\tools\") $Global.Mcrcon = (Resolve-CompletePath -Path $Global.Mcrcon -ParentPath ".\tools\") $Global.SteamCMD = (Resolve-CompletePath -Path $Global.SteamCMD -ParentPath ".\tools\") + $Global.JavaDirectory = (Resolve-CompletePath -Path $Global.JavaDirectory -ParentPath ".\tools\") $Global.LogFolder = (Resolve-CompletePath -Path $Global.LogFolder -ParentPath ".\") #Create Arguments diff --git a/launchers/run.cmd b/launchers/run.cmd index 471e1db..39678f8 100644 --- a/launchers/run.cmd +++ b/launchers/run.cmd @@ -1,2 +1,2 @@ cd .. -start powershell.exe -noprofile -executionpolicy bypass -file ".\main.ps1" -ServerCfg "stationeers" \ No newline at end of file +start powershell.exe -noprofile -executionpolicy bypass -file ".\main.ps1" -ServerCfg "paperclip" \ No newline at end of file diff --git a/templates/paperclip.psm1 b/templates/paperclip.psm1 index ac33dcb..e1c1cde 100644 --- a/templates/paperclip.psm1 +++ b/templates/paperclip.psm1 @@ -1,9 +1,9 @@ <# - ".\servers\$Name\serverconfig.txt" + Edit .\servers\Paperclip\server.properties #> #Server Name, use the same name to share game files. -$Name = "Terraria" +$Name = "Paperclip" #--------------------------------------------------------- # Server Configuration @@ -12,44 +12,52 @@ $Name = "Terraria" $ServerDetails = @{ #Unique Identifier used to track processes. Must be unique to each servers. - UID = "Terraria_1" + UID = "Paperclip_1" #Login username used by SteamCMD Login = "anonymous" - # Specifies the configuration file to use *(relative the the game) - ConfigFile = "serverconfig.txt" + # Server Name + SessionName = "My Minecraft Server" + + # Message of the day, also shows in server browser + MOTD = "\u00A76My Server - \u00A7AMinecraft 1.17.1" + + # Specifies the port to listen on. + Port = 25565 # Specifies the port to listen on. - Port = 7777 + QueryPort = 25565 # Sets the max number of players - MaxPlayers = 8 + MaxPlayers = 64 - # Sets the server password - Password = "CHANGEME" + # Sets the server Game Mode + GameMode = "survival" - #Choose the world to load. Do not try to save it somewhere else, it won't work. - World = "$Env:userprofile\Documents\My Games\Terraria\Worlds\ServerWorld.wld" + #Level Name + World = "world" - #Should match the above world. - WorldName = "ServerWorld" + #Level Type + LevelType = "default" #Specifies the world seed when using -autocreate - Seed = "1234" + Seed = 1234 - #Creates a world if none is found in the path specified by World. - #World size is specified by: 1(small), 2(medium), and 3(large). - AutoCreate = 2 + #Difficulty + Difficulty = "normal" + + #Amount of ram dedicated to the server in Go + Ram = 2 #Rcon IP ManagementIP = "127.0.0.1" #Rcon Port - ManagementPort = "" + ManagementPort = 25575 #Rcon Password - ManagementPassword = "" + ManagementPassword = "CHANGEME" #--------------------------------------------------------- # Server Installation Details @@ -64,8 +72,11 @@ $ServerDetails = @{ #Server configuration folder ConfigFolder = ".\servers\$Name" - #Server Version - Version = "1423" + #Server Version https://adoptopenjdk.net/releases.html?variant=openjdk16&jvmVariant=hotspot + JavaVersionLink = "https://github.com/AdoptOpenJDK/openjdk16-binaries/releases/download/jdk-16.0.1%2B9/OpenJDK16U-jre_x64_windows_hotspot_16.0.1_9.msi" + + #Server Version https://papermc.io/downloads#Paper-1.17 + PaperclipVersionLink = "https://papermc.io/api/v2/projects/paper/versions/1.17.1/builds/265/downloads/paper-1.17.1-265.jar" #Steam Server App Id *0 Skip SteamCMD Installation AppID = 0 @@ -77,16 +88,16 @@ $ServerDetails = @{ BetaBuildPassword = "" #Auto-Update Enable or Disable Auto-Updates, some games don't work well with SteamCMD - AutoUpdates = $true + AutoUpdates = $false #Process name in the task manager - ProcessName = "TerrariaServer" + ProcessName = "java" #Use PID instead of Process Name, Will still use processname if the PID fails to find anything. UsePID = $true #Server Executable - Exec = ".\servers\$Name\TerrariaServer.exe" + Exec = ".\servers\$Name\paperclip.jar" #Allow force close, usefull for server without RCON and Multiple instances. AllowForceClose = $true @@ -152,7 +163,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" @@ -170,13 +181,13 @@ $WarningsDetails = @{ CmdMessage = "say" #command to save the server - CmdSave = "saveworld" + CmdSave = "save-all" #How long to wait in seconds after the save command is sent. SaveDelay = 15 #command to stop the server - CmdStop = "shutdown" + CmdStop = "stop" } #Create the object $Warnings = New-Object -TypeName PsObject -Property $WarningsDetails @@ -187,54 +198,86 @@ $Warnings = New-Object -TypeName PsObject -Property $WarningsDetails #Launch Arguments $ArgumentList = @( - "-config `"$($Server.ConfigFile)`" ", - "-port $($Server.Port) ", - "-maxplayers $($Server.MaxPlayers) ", - "-password `"$($Server.Password)`" ", - "-world `"$($Server.World)`" ", - "-worldname `"$($Server.WorldName)`" ", - "-seed `"$($Server.Seed)`" ", - "-autocreate $($Server.AutoCreate) ", - "-secure ", - "-noupnp ", - "-steam " + "-Xms$($Server.Ram)G ", + "-Xmx$($Server.Ram)G ", + "-jar paperclip.jar ", + "--nogui" ) Add-Member -InputObject $Server -Name "ArgumentList" -Type NoteProperty -Value $ArgumentList -Add-Member -InputObject $Server -Name "Launcher" -Type NoteProperty -Value "$($Server.Exec)" +Add-Member -InputObject $Server -Name "Launcher" -Type NoteProperty -Value "$($Global.JavaDirectory)\OpenJDK16\bin\java.exe" Add-Member -InputObject $Server -Name "WorkingDirectory" -Type NoteProperty -Value "$($Server.Path)" +#--------------------------------------------------------- +# server.properties +#--------------------------------------------------------- + +$FileContentList = @( + "difficulty=$($Server.Difficulty)", + "gamemode=$($Server.GameMode)", + "level-name=$($Server.World)", + "level-seed=$($Server.Seed)", + "level-type=$($Server.LevelType)", + "max-players=$($Server.MaxPlayers)", + "motd=$($Server.MOTD)", + "enable-rcon=true", + "rcon.password=$($Server.ManagementPassword)", + "rcon.port=$($Server.ManagementPort)", + "server-name=$($Server.SessionName)", + "server-port=$($Server.Port)", + "query.port=$($Server.QueryPort)" +) + +$FileContent = ($FileContentList -join "`n") + #--------------------------------------------------------- # Function that runs just before the server starts. #--------------------------------------------------------- function Start-ServerPrep { + + #Create Config File if not created. + if (-not (Test-Path -Path ".\servers\$($Server.Name)\server.properties" -ErrorAction SilentlyContinue)){ + Write-Host "Creating Config File" + New-Item -Path ".\servers\$($Server.Name)\" -Name "server.properties" -ItemType "file" -Value $FileContent + } + #Create eula File if not created. + if (-not (Test-Path -Path ".\servers\$($Server.Name)\eula.txt" -ErrorAction SilentlyContinue)){ + Write-Host "Creating Config File" + New-Item -Path ".\servers\$($Server.Name)\" -Name "eula.txt" -ItemType "file" -Value "eula=true" + } #If server is not installed, install it. - $Version = Get-Content -Path ".\servers\$($Server.Name)\Version.txt" -ErrorAction SilentlyContinue + $JavaVersion = Get-Content -Path ".\servers\$($Server.Name)\JavaVersion.txt" -ErrorAction SilentlyContinue + if (-not (Test-Path -Path $Server.Exec -PathType "leaf" -ErrorAction SilentlyContinue) -or ($Version -ne $Server.Version)) { + Write-ScriptMsg "Installing Java..." + #Create Temporary Download Folder + New-Item -Path ".\downloads" -ItemType "directory" -ErrorAction SilentlyContinue + #Download Adopt Openjdk-16.0.2+7 + Invoke-Download -Uri $($Server.JavaVersionLink) -OutFile ".\downloads\OpenJDK16.msi" -ErrorAction SilentlyContinue + #Install Adopt Openjdk-16.0.2+7 + $Package = Resolve-Path -Path ".\downloads\OpenJDK16.msi" + Start-Process -FilePath msiexec.exe -ArgumentList "/qn /i $Package ADDLOCAL=FeatureMain,FeatureEnvironment,FeatureJarFileRunWith,FeatureJavaHome INSTALLDIR=`"$($Global.JavaDirectory)\OpenJDK16`" /passive" -Verb "RunAs" -Wait + #Cleanup + Remove-Item -Path ".\downloads" -Recurse -Force -ErrorAction SilentlyContinue + #Remove old version file + Remove-Item -Path ".\servers\$($Server.Name)\JavaVersion.txt" -Confirm:$false -ErrorAction SilentlyContinue + #Write new Version File + New-Item -Path ".\servers\$($Server.Name)\" -Name "JavaVersion.txt" -ItemType "file" -Value "$($Server.JavaVersionLink)" -Force -ErrorAction SilentlyContinue + } + $PaperclipVersion = Get-Content -Path ".\servers\$($Server.Name)\PaperVersion.txt" -ErrorAction SilentlyContinue if (-not (Test-Path -Path $Server.Exec -PathType "leaf" -ErrorAction SilentlyContinue) -or ($Version -ne $Server.Version)) { - Write-ScriptMsg "Installing Server..." + Write-ScriptMsg "Installing Paperclip..." #Create Temporary Download Folder New-Item -Path ".\downloads" -ItemType "directory" -ErrorAction SilentlyContinue - #Download Microsoft XNA Framework - Invoke-Download -Uri "https://download.microsoft.com/download/5/3/A/53A804C8-EC78-43CD-A0F0-2FB4D45603D3/xnafx40_redist.msi" -OutFile ".\downloads\xna.msi" -ErrorAction SilentlyContinue - #Install Microsoft XNA - $Package = Resolve-Path -Path ".\downloads\xna.msi" - Start-Process -FilePath msiexec.exe -ArgumentList "/qn /i $Package" -Verb "RunAs" -Wait - #Download Server Zip - Invoke-Download -Uri "https://terraria.org/api/download/pc-dedicated-server/terraria-server-$($Server.Version).zip" -OutFile ".\downloads\terraria.zip" -ErrorAction SilentlyContinue - #Extract Server to Temporary Folder - Expand-Archive -Path ".\downloads\terraria.zip" -DestinationPath ".\downloads\terraria\" -Force + #Download Paperclip + Invoke-Download -Uri $($Server.PaperclipVersionLink) -OutFile ".\downloads\paperclip.jar" -ErrorAction SilentlyContinue #Copy Server Files to Server Directory - Copy-Item -Path ".\downloads\terraria\$($Server.Version)\Windows\TerrariaServer.exe" -Destination $Server.Path -Force - Copy-Item -Path ".\downloads\terraria\$($Server.Version)\Windows\ReLogic.Native.dll" -Destination $Server.Path -Force - if (-not (Test-Path -Path $Server.ConfigFile -PathType "leaf" -ErrorAction SilentlyContinue)) { - Copy-Item -Path ".\downloads\terraria\$($Server.Version)\Windows\serverconfig.txt" -Destination $Server.Path - } + Copy-Item -Path ".\downloads\paperclip.jar" -Destination $Server.Path -Force #Cleanup Remove-Item -Path ".\downloads" -Recurse -Force -ErrorAction SilentlyContinue #Remove old version file - Remove-Item -Path ".\servers\$($Server.Name)\Version.txt" -Confirm:$false -ErrorAction SilentlyContinue + Remove-Item -Path ".\servers\$($Server.Name)\PaperVersion.txt" -Confirm:$false -ErrorAction SilentlyContinue #Write new Version File - New-Item -Path ".\servers\$($Server.Name)\" -Name "Version.txt" -ItemType "file" -Value "$($Server.Version)" -Force -ErrorAction SilentlyContinue + New-Item -Path ".\servers\$($Server.Name)\" -Name "PaperVersion.txt" -ItemType "file" -Value "$($Server.PaperclipVersionLink)" -Force -ErrorAction SilentlyContinue } Write-ScriptMsg "Port Forward : $($Server.Port) in TCP and UDP to $($Global.InternalIP)" } From 2608e651050d061e4f63644a414e568749f21a1f Mon Sep 17 00:00:00 2001 From: Patrick Veilleux Date: Mon, 20 Sep 2021 22:04:02 -0400 Subject: [PATCH 10/12] Remove unwanted file --- configs/paperclip.psm1 | 285 ----------------------------------------- 1 file changed, 285 deletions(-) delete mode 100644 configs/paperclip.psm1 diff --git a/configs/paperclip.psm1 b/configs/paperclip.psm1 deleted file mode 100644 index e1c1cde..0000000 --- a/configs/paperclip.psm1 +++ /dev/null @@ -1,285 +0,0 @@ -<# - Edit .\servers\Paperclip\server.properties -#> - -#Server Name, use the same name to share game files. -$Name = "Paperclip" - -#--------------------------------------------------------- -# Server Configuration -#--------------------------------------------------------- - -$ServerDetails = @{ - - #Unique Identifier used to track processes. Must be unique to each servers. - UID = "Paperclip_1" - - #Login username used by SteamCMD - Login = "anonymous" - - # Server Name - SessionName = "My Minecraft Server" - - # Message of the day, also shows in server browser - MOTD = "\u00A76My Server - \u00A7AMinecraft 1.17.1" - - # Specifies the port to listen on. - Port = 25565 - - # Specifies the port to listen on. - QueryPort = 25565 - - # Sets the max number of players - MaxPlayers = 64 - - # Sets the server Game Mode - GameMode = "survival" - - #Level Name - World = "world" - - #Level Type - LevelType = "default" - - #Specifies the world seed when using -autocreate - Seed = 1234 - - #Difficulty - Difficulty = "normal" - - #Amount of ram dedicated to the server in Go - Ram = 2 - - #Rcon IP - ManagementIP = "127.0.0.1" - - #Rcon Port - ManagementPort = 25575 - - #Rcon Password - ManagementPassword = "CHANGEME" - -#--------------------------------------------------------- -# Server Installation Details -#--------------------------------------------------------- - - #Name of the Server Instance - Name = $Name - - #Server Installation Path - Path = ".\servers\$Name" - - #Server configuration folder - ConfigFolder = ".\servers\$Name" - - #Server Version https://adoptopenjdk.net/releases.html?variant=openjdk16&jvmVariant=hotspot - JavaVersionLink = "https://github.com/AdoptOpenJDK/openjdk16-binaries/releases/download/jdk-16.0.1%2B9/OpenJDK16U-jre_x64_windows_hotspot_16.0.1_9.msi" - - #Server Version https://papermc.io/downloads#Paper-1.17 - PaperclipVersionLink = "https://papermc.io/api/v2/projects/paper/versions/1.17.1/builds/265/downloads/paper-1.17.1-265.jar" - - #Steam Server App Id *0 Skip SteamCMD Installation - AppID = 0 - - #Name of the Beta Build - BetaBuild = "" - - #Beta Build Password - BetaBuildPassword = "" - - #Auto-Update Enable or Disable Auto-Updates, some games don't work well with SteamCMD - AutoUpdates = $false - - #Process name in the task manager - ProcessName = "java" - - #Use PID instead of Process Name, Will still use processname if the PID fails to find anything. - UsePID = $true - - #Server Executable - Exec = ".\servers\$Name\paperclip.jar" - - #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 - - #How long should it wait to check if the server is stable - StartupWaitTime = 10 -} -#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\Documents\My Games\Terraria\Worlds" -} -#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 = "save-all" - - #How long to wait in seconds after the save command is sent. - SaveDelay = 15 - - #command to stop the server - CmdStop = "stop" -} -#Create the object -$Warnings = New-Object -TypeName PsObject -Property $WarningsDetails - -#--------------------------------------------------------- -# Launch Arguments -#--------------------------------------------------------- - -#Launch Arguments -$ArgumentList = @( - "-Xms$($Server.Ram)G ", - "-Xmx$($Server.Ram)G ", - "-jar paperclip.jar ", - "--nogui" -) -Add-Member -InputObject $Server -Name "ArgumentList" -Type NoteProperty -Value $ArgumentList -Add-Member -InputObject $Server -Name "Launcher" -Type NoteProperty -Value "$($Global.JavaDirectory)\OpenJDK16\bin\java.exe" -Add-Member -InputObject $Server -Name "WorkingDirectory" -Type NoteProperty -Value "$($Server.Path)" - -#--------------------------------------------------------- -# server.properties -#--------------------------------------------------------- - -$FileContentList = @( - "difficulty=$($Server.Difficulty)", - "gamemode=$($Server.GameMode)", - "level-name=$($Server.World)", - "level-seed=$($Server.Seed)", - "level-type=$($Server.LevelType)", - "max-players=$($Server.MaxPlayers)", - "motd=$($Server.MOTD)", - "enable-rcon=true", - "rcon.password=$($Server.ManagementPassword)", - "rcon.port=$($Server.ManagementPort)", - "server-name=$($Server.SessionName)", - "server-port=$($Server.Port)", - "query.port=$($Server.QueryPort)" -) - -$FileContent = ($FileContentList -join "`n") - -#--------------------------------------------------------- -# Function that runs just before the server starts. -#--------------------------------------------------------- - -function Start-ServerPrep { - - #Create Config File if not created. - if (-not (Test-Path -Path ".\servers\$($Server.Name)\server.properties" -ErrorAction SilentlyContinue)){ - Write-Host "Creating Config File" - New-Item -Path ".\servers\$($Server.Name)\" -Name "server.properties" -ItemType "file" -Value $FileContent - } - #Create eula File if not created. - if (-not (Test-Path -Path ".\servers\$($Server.Name)\eula.txt" -ErrorAction SilentlyContinue)){ - Write-Host "Creating Config File" - New-Item -Path ".\servers\$($Server.Name)\" -Name "eula.txt" -ItemType "file" -Value "eula=true" - } - #If server is not installed, install it. - $JavaVersion = Get-Content -Path ".\servers\$($Server.Name)\JavaVersion.txt" -ErrorAction SilentlyContinue - if (-not (Test-Path -Path $Server.Exec -PathType "leaf" -ErrorAction SilentlyContinue) -or ($Version -ne $Server.Version)) { - Write-ScriptMsg "Installing Java..." - #Create Temporary Download Folder - New-Item -Path ".\downloads" -ItemType "directory" -ErrorAction SilentlyContinue - #Download Adopt Openjdk-16.0.2+7 - Invoke-Download -Uri $($Server.JavaVersionLink) -OutFile ".\downloads\OpenJDK16.msi" -ErrorAction SilentlyContinue - #Install Adopt Openjdk-16.0.2+7 - $Package = Resolve-Path -Path ".\downloads\OpenJDK16.msi" - Start-Process -FilePath msiexec.exe -ArgumentList "/qn /i $Package ADDLOCAL=FeatureMain,FeatureEnvironment,FeatureJarFileRunWith,FeatureJavaHome INSTALLDIR=`"$($Global.JavaDirectory)\OpenJDK16`" /passive" -Verb "RunAs" -Wait - #Cleanup - Remove-Item -Path ".\downloads" -Recurse -Force -ErrorAction SilentlyContinue - #Remove old version file - Remove-Item -Path ".\servers\$($Server.Name)\JavaVersion.txt" -Confirm:$false -ErrorAction SilentlyContinue - #Write new Version File - New-Item -Path ".\servers\$($Server.Name)\" -Name "JavaVersion.txt" -ItemType "file" -Value "$($Server.JavaVersionLink)" -Force -ErrorAction SilentlyContinue - } - $PaperclipVersion = Get-Content -Path ".\servers\$($Server.Name)\PaperVersion.txt" -ErrorAction SilentlyContinue - if (-not (Test-Path -Path $Server.Exec -PathType "leaf" -ErrorAction SilentlyContinue) -or ($Version -ne $Server.Version)) { - Write-ScriptMsg "Installing Paperclip..." - #Create Temporary Download Folder - New-Item -Path ".\downloads" -ItemType "directory" -ErrorAction SilentlyContinue - #Download Paperclip - Invoke-Download -Uri $($Server.PaperclipVersionLink) -OutFile ".\downloads\paperclip.jar" -ErrorAction SilentlyContinue - #Copy Server Files to Server Directory - Copy-Item -Path ".\downloads\paperclip.jar" -Destination $Server.Path -Force - #Cleanup - Remove-Item -Path ".\downloads" -Recurse -Force -ErrorAction SilentlyContinue - #Remove old version file - Remove-Item -Path ".\servers\$($Server.Name)\PaperVersion.txt" -Confirm:$false -ErrorAction SilentlyContinue - #Write new Version File - New-Item -Path ".\servers\$($Server.Name)\" -Name "PaperVersion.txt" -ItemType "file" -Value "$($Server.PaperclipVersionLink)" -Force -ErrorAction SilentlyContinue - } - Write-ScriptMsg "Port Forward : $($Server.Port) in TCP and UDP to $($Global.InternalIP)" -} - -Export-ModuleMember -Function Start-ServerPrep -Variable @("Server","Backups","Warnings") \ No newline at end of file From 154344ffa18688d2335315a68bd8dfee13a134dd Mon Sep 17 00:00:00 2001 From: Patrick Veilleux Date: Mon, 20 Sep 2021 22:04:35 -0400 Subject: [PATCH 11/12] Valheim --- launchers/run.cmd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/launchers/run.cmd b/launchers/run.cmd index 39678f8..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 "paperclip" \ No newline at end of file +start powershell.exe -noprofile -executionpolicy bypass -file ".\main.ps1" -ServerCfg "valheim" \ No newline at end of file From 24b421d3d56d7586512e16807e1a2894b5a0fe61 Mon Sep 17 00:00:00 2001 From: Patrick Veilleux Date: Mon, 20 Sep 2021 22:07:28 -0400 Subject: [PATCH 12/12] Fix issues with Priorities --- templates/astroneer.psm1 | 2 +- templates/mordhau.psm1 | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/templates/astroneer.psm1 b/templates/astroneer.psm1 index a0e973e..7c5948f 100644 --- a/templates/astroneer.psm1 +++ b/templates/astroneer.psm1 @@ -66,7 +66,7 @@ $ServerDetails = @{ AllowForceClose = $true #Process Priority Realtime, High, Above normal, Normal, Below normal, Low - UsePriority = $true + UsePriority = $false AppPriority = "High" <# diff --git a/templates/mordhau.psm1 b/templates/mordhau.psm1 index 657b7c5..c976b1c 100644 --- a/templates/mordhau.psm1 +++ b/templates/mordhau.psm1 @@ -82,7 +82,7 @@ $ServerDetails = @{ AllowForceClose = $true #Process Priority Realtime, High, Above normal, Normal, Below normal, Low - UsePriority = $true + UsePriority = $false AppPriority = "High" <#