-
Notifications
You must be signed in to change notification settings - Fork 0
/
start.ps1
74 lines (61 loc) · 2.17 KB
/
start.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#requires -Version 5
[CmdletBinding()]
param(
[Parameter(HelpMessage = 'Path to the `valheim_server` executable')]
[Alias('ValheimPath')]
[System.IO.DirectoryInfo]
$Path = "Z:\Steam\steamapps\common\Valheim dedicated server",
[Parameter(HelpMessage = 'Name of the savefile minus its extension')]
[string]
$World = 'EXTRASEEDY',
[Parameter(HelpMessage = 'Name of the server displayed in lists')]
[Alias('ServerName')]
[string]
$Name = 'Hall of Halkcyon',
[Parameter(HelpMessage = 'Determines whether the server is visible in the community list')]
[bool]
$IsCommunityServer = $true,
[Parameter(DontShow, HelpMessage = 'Port the game server binds to. Recommends forwarding 2456-2458')]
[uint16]
$Port = 2456
)
$script:ErrorActionPreference = 'Stop'
if (-not $Path.Exists) {
throw "Cannot find path ``${Path}``!"
}
$valheimServer = $Path | Get-ChildItem -Filter valheim_server.exe | Select-Object -First 1
if (-not $valheimServer) {
throw "Cannot find ``valheim_server.exe`` in ``${Path}``!"
}
$password = $Env:VALHEIM_SERVER_PWD
if (-not $password) {
# an ugly hack to mask the password at the console for pwsh <v6
$password = [pscredential]::new(
'TMP', (Read-Host -AsSecureString -Prompt 'Valheim Dedicated Server Password')
).GetNetworkCredential().Password
}
else {
'Retrieved server password from `VALHEIM_SERVER_PWD` environment variable.'
}
if ($Name.ToLower().Contains($password.ToLower())) {
throw 'Password cannot be a part of the server name!'
}
if ($password.Length -lt 5) {
throw 'Password must be longer than four characters!'
}
# unsure if this is needed, but it was configured in the template script
$Env:SteamAppId = Get-Content -LiteralPath "${Path}\steam_appid.txt"
"Starting server; press CTRL-C to exit.`n"
# TODO! backup and rotate savefiles. the existing server impl only saves hourly or on shutdown
$valheimParms = @(
'-nographics'
'-batchmode'
'-name', $Name
'-port', $Port
'-world', $World
'-password', $password
# path to the `worlds/` folder
'-savedir', $PSScriptRoot
'-public', [int]$IsCommunityServer
)
& $valheimServer.FullName @valheimParms