Files
TankIC/TankiOffline/tools/RunAutoTest.ps1
T
TermiNexus 0ca28ff9b2 feat(autotest): 新增双连接接入测试与链路密钥探测
- AutoTest:大厅 Hash Request → 取 digest/空间 id → 空间连接 EnterSpace → 收空间帧
- StreamDecoder:首条密文即穷举单字节链路密钥(K),之后 s2c 自动解密
- 首条空间帧到达后再加密发送 G.q1wd,服务端才会继续下发容器数据
- RunAutoTest.ps1:自动拉起大厅/空间两条中继,跑完自动回收
- 实测通过:握手成功、K 唯一命中、容器 1 条、回编码一致
2026-10-21 00:38:59 +08:00

88 lines
3.4 KiB
PowerShell
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# RunAutoTest.ps1 —— 启动两条中继并跑 TankiOffline 接入测试
#
# 真实链路是两段连接:
# 大厅:9091 → wss://c2.3dtank.com:9090/(Hash Request / Hash Response)
# 空间:9092 → wss://c2.3dtank.com:9090/(首帧 EnterSpace → 空间帧;实测 c2 才会回空间数据)
#
# 用法:
# powershell -ExecutionPolicy Bypass -File .\tools\RunAutoTest.ps1
# powershell -ExecutionPolicy Bypass -File .\tools\RunAutoTest.ps1 -TimeoutSec 30 -SpaceId 100073070
param(
[long]$SpaceId = 100073070,
[int]$TimeoutSec = 25,
[int]$LobbyPort = 9091,
[int]$SpacePort = 9092,
[string]$LobbyUpstream = 'wss://c2.3dtank.com:9090/',
[string]$SpaceUpstream = 'wss://c2.3dtank.com:9090/'
)
$ErrorActionPreference = 'Stop'
$Root = Split-Path -Parent $PSScriptRoot
$Tools = Join-Path (Split-Path -Parent $Root) '3DTank\tools'
$RelayLobbyOut = Join-Path $env:TEMP 'tankioffline-relay-lobby.out.log'
$RelayLobbyErr = Join-Path $env:TEMP 'tankioffline-relay-lobby.err.log'
$RelaySpaceOut = Join-Path $env:TEMP 'tankioffline-relay-space.out.log'
$RelaySpaceErr = Join-Path $env:TEMP 'tankioffline-relay-space.err.log'
if (-not (Test-Path (Join-Path $Tools 'wss_server.js'))) {
throw "找不到中继脚本:$Tools\wss_server.js"
}
function Start-Relay([int]$Port, [string]$Upstream, [string]$Out, [string]$Err, [string]$Label) {
$Args = @(
'wss_server.js',
'--port', "$Port",
'--upstream', $Upstream,
'--dump-every', '0',
'--log', '0',
'--quiet', '1',
'--tunnel-reconnect', '0',
'--label', $Label
)
Write-Host "启动中继 $Label:$Upstream → localhost:$Port"
return Start-Process -FilePath 'node' -ArgumentList $Args -WorkingDirectory $Tools -PassThru -WindowStyle Hidden `
-RedirectStandardOutput $Out -RedirectStandardError $Err
}
function Wait-Port([int]$Port, [string]$Name) {
for ($I = 0; $I -lt 50; $I++) {
Start-Sleep -Milliseconds 200
try {
$Client = New-Object System.Net.Sockets.TcpClient
$Client.Connect('127.0.0.1', $Port)
$Client.Close()
return
} catch {
}
}
throw "$Name 端口 $Port 未启动"
}
$RelayLobby = Start-Relay $LobbyPort $LobbyUpstream $RelayLobbyOut $RelayLobbyErr 'autotest-lobby'
$RelaySpace = Start-Relay $SpacePort $SpaceUpstream $RelaySpaceOut $RelaySpaceErr 'autotest-space'
try {
Wait-Port $LobbyPort '大厅中继'
Wait-Port $SpacePort '空间中继'
$env:TANKIOFFLINE_AUTOTEST = '1'
$env:TANKIOFFLINE_AUTOTEST_URL = "ws://localhost:$LobbyPort/"
$env:TANKIOFFLINE_AUTOTEST_SPACE_URL = "ws://localhost:$SpacePort/"
$env:TANKIOFFLINE_AUTOTEST_SPACE = "$SpaceId"
$env:TANKIOFFLINE_AUTOTEST_TIMEOUT = "$($TimeoutSec * 1000)"
Write-Host "运行客户端:大厅 $($env:TANKIOFFLINE_AUTOTEST_URL) / 空间 $($env:TANKIOFFLINE_AUTOTEST_SPACE_URL)"
& (Join-Path $Root 'gradlew.bat') ':app:jsNodeDevelopmentRun' '--console=plain'
$Code = $LASTEXITCODE
Write-Host "客户端退出码:$Code"
exit $Code
} finally {
foreach ($P in @($RelayLobby, $RelaySpace)) {
if ($P -and -not $P.HasExited) {
Stop-Process -Id $P.Id -Force -ErrorAction SilentlyContinue
}
}
Write-Host '中继已停止'
}