feat(launcher): 增加 -SRV 1/2 统一切换前后端服务器(c1/c2)
This commit is contained in:
1 parent
1dd7143e67
commit
8820639feb
1 file changed
+35
-12
@@ -18,16 +18,26 @@
|
||||
// 资源缺失(页面 404 很多)时先镜像资源再起(首次约 70MB)
|
||||
.\Start-LocalAndRelay.ps1 -FetchAssets -OpenBrowser
|
||||
|
||||
.EXAMPLE
|
||||
// 端口被上次残留占用时,先杀掉再起
|
||||
.\Start-LocalAndRelay.ps1 -KillExisting -OpenBrowser
|
||||
#>
|
||||
[CmdletBinding()]
|
||||
param(
|
||||
[int]$MirrorPort = 8080,
|
||||
[int]$RelayPort = 9091,
|
||||
.EXAMPLE
|
||||
// 端口被上次残留占用时,先杀掉再起
|
||||
.\Start-LocalAndRelay.ps1 -KillExisting -OpenBrowser
|
||||
|
||||
.EXAMPLE
|
||||
// 强制整个链路(前端 config 来源 + 中继上游)都走 c1
|
||||
// 注意:PowerShell 不认 -SRV=1 这种等号写法,要写 -SRV 1 或 -SRV:1
|
||||
.\Start-LocalAndRelay.ps1 -SRV 1 -WithRelay -OpenBrowser
|
||||
|
||||
.EXAMPLE
|
||||
// 强制走 c2(官方默认主服)
|
||||
.\Start-LocalAndRelay.ps1 -SRV 2 -OpenBrowser
|
||||
#>
|
||||
[CmdletBinding()]
|
||||
param(
|
||||
[int]$MirrorPort = 8080,
|
||||
[int]$RelayPort = 9091,
|
||||
[string]$Upstream = 'wss://c2.3dtank.com:9090/', # 主上游(大厅:首帧 = Hash Request)
|
||||
[string]$UpstreamAlt = 'wss://c1.3dtank.com:9090/', # 备用上游(首帧直接 EnterSpace 的「二次进空间」连接)
|
||||
[string]$UpstreamAlt = 'wss://c1.3dtank.com:9090/', # 备用上游(首帧直接 EnterSpace 的「二次进空间」连接)
|
||||
[ValidateSet(0, 1, 2)][int]$SRV = 0, # 服务器选择:0=保持默认(c2);1=前后端都走 c1.3dtank.com;2=前后端都走 c2.3dtank.com
|
||||
[string]$Label = (Get-Date -Format 'yyyyMMdd-HHmmss'),
|
||||
[switch]$FetchAssets, # 先跑 fetch_assets.js 镜像资源(首次或资源缺失时用)
|
||||
[switch]$KillExisting, # 端口被占用时,先结束占用进程
|
||||
@@ -45,6 +55,18 @@ $Project = $PSScriptRoot # 3DTank/
|
||||
$Tools = Join-Path $Project 'tools'
|
||||
$PacketDir = Join-Path $Project ("packets\{0}" -f $Label)
|
||||
|
||||
# ---------- 服务器选择(-SRV 1/2)----------
|
||||
# 同时决定:① 前端 /config.xml 的回源(真实 config 里的 server address)
|
||||
# ② 中继 --upstream(后端实际连哪台)
|
||||
$ConfigUpstream = 'https://c2.3dtank.com'
|
||||
if ($SRV -eq 1 -or $SRV -eq 2) {
|
||||
$ServerHost = "c$SRV.3dtank.com"
|
||||
$Upstream = "wss://${ServerHost}:9090/"
|
||||
$UpstreamAlt = $Upstream
|
||||
$ConfigUpstream = "https://$ServerHost"
|
||||
Write-Host ("[服务器] -SRV={0} → 前端 config 与中继上游统一走 {1}" -f $SRV, $ServerHost) -ForegroundColor Yellow
|
||||
}
|
||||
|
||||
# ---------- 小工具 ----------
|
||||
function Get-CmdPath([string]$Name) {
|
||||
$c = Get-Command $Name -ErrorAction SilentlyContinue
|
||||
@@ -149,9 +171,9 @@ if ($WithRelay) {
|
||||
}
|
||||
|
||||
# ---------- 5) 启动本地镜像 ----------
|
||||
# 默认加 --real-config:/config.xml 取真实站点,游戏因此直连 wss://c1.3dtank.com:9090/
|
||||
# 默认加 --real-config:/config.xml 取真实站点(--config-upstream 决定 c1 / c2),游戏据此直连对应服务器
|
||||
# 走中继(-WithRelay)时改用 --relay-port:serve.js 动态把 config 改写为 ws://localhost:<RelayPort>/(不落盘)
|
||||
$MirrorArgs = @('serve.js', '--port', "$MirrorPort")
|
||||
$MirrorArgs = @('serve.js', '--port', "$MirrorPort", '--config-upstream', $ConfigUpstream)
|
||||
if ($WithRelay) { $MirrorArgs += @('--relay-port', "$RelayPort") } else { $MirrorArgs += '--real-config' }
|
||||
if ($Hook) { $MirrorArgs += '--ws-hook' }
|
||||
Write-Host ("[镜像] serve.js http://localhost:{0}/ {1}{2}" -f $MirrorPort, ($(if ($WithRelay) {'(config → 本地中继)'} else {'(config → 真实服务器,直连)'})), ($(if ($Hook) {' + ws 抓包'} else {''}))) -ForegroundColor Green
|
||||
@@ -176,7 +198,8 @@ if ($WithRelay) {
|
||||
Write-Host ("进程 : 中继 PID={0} 镜像 PID={1}" -f $RelayProc.Id, $MirrorProc.Id) -ForegroundColor White
|
||||
Write-Host ("自检 : 中继={0} 镜像={1}" -f ($(if ($RelayOk) {'OK'} else {'未监听'})), ($(if ($MirrorOk) {'OK'} else {'未监听'}))) -ForegroundColor White
|
||||
} else {
|
||||
Write-Host '连接路径 : 页面 → config 取自真实站点 → 直连 wss://c1.3dtank.com:9090/(未启动中继)' -ForegroundColor White
|
||||
Write-Host ("连接路径 : 页面 → config 取自 {0} → 直连 {1}(未启动中继)" -f $ConfigUpstream, $Upstream) -ForegroundColor White
|
||||
Write-Host ("服务器 : {0}" -f ($(if ($SRV -eq 0) {'-SRV 未指定(默认 c2)'} else {"-SRV=$SRV"}))) -ForegroundColor White
|
||||
Write-Host ("进程 : 镜像 PID={0}" -f $MirrorProc.Id) -ForegroundColor White
|
||||
Write-Host ("自检 : 镜像={0}" -f ($(if ($MirrorOk) {'OK'} else {'未监听'}))) -ForegroundColor White
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user