fix(launcher): 兼容 -SRV=1 等号写法(改用 args 手动解析)

This commit is contained in:
TermiNexus committed 2026-10-19 20:30:40 +08:00
1 parent 8820639feb
commit 42e1944cce
1 file changed
+13 -1
+13 -1
View File
@@ -31,7 +31,9 @@
// 强制走 c2(官方默认主服) // 强制走 c2(官方默认主服)
.\Start-LocalAndRelay.ps1 -SRV 2 -OpenBrowser .\Start-LocalAndRelay.ps1 -SRV 2 -OpenBrowser
#> #>
[CmdletBinding()] # 注意:这里刻意不用 [CmdletBinding()]。
# PowerShell 原生不支持 -SRV=1 这种等号写法(会报 "parameter cannot be found"),
# 去掉 CmdletBinding 后,未绑定的 -SRV=1 会落进 $args,由下面手动解析兼容。
param( param(
[int]$MirrorPort = 8080, [int]$MirrorPort = 8080,
[int]$RelayPort = 9091, [int]$RelayPort = 9091,
@@ -51,6 +53,16 @@ param(
) )
$ErrorActionPreference = 'Stop' $ErrorActionPreference = 'Stop'
# ---------- 兼容 -SRV=1 / --SRV=1 等号写法 ----------
# PowerShell 只认 -SRV 1 或 -SRV:1;等号形式会被当作未绑定参数落进 $args,这里手动识别
foreach ($A in $args) {
if ($A -is [string] -and $A -match '^--?SRV=(.+)$') {
$SRV = [int]$Matches[1]
}
}
if ($SRV -notin 0, 1, 2) { throw "-SRV 只能是 0 / 1 / 2(收到: $SRV)" }
$Project = $PSScriptRoot # 3DTank/ $Project = $PSScriptRoot # 3DTank/
$Tools = Join-Path $Project 'tools' $Tools = Join-Path $Project 'tools'
$PacketDir = Join-Path $Project ("packets\{0}" -f $Label) $PacketDir = Join-Path $Project ("packets\{0}" -f $Label)