XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet

XFEWarframe

【WinUI】基于Warframe游戏本体的公开服务器以及安装器

公开
关注 0 Fork 0 Star 0
UTF-8
#requires -Version 7.0
param(
    [Parameter(Mandatory)][string]$ServerPath,
    [Parameter(Mandatory)][string]$InventoryFixture,
    [string]$ReportDirectory
)
$ErrorActionPreference = 'Stop'
$taskRoot = [IO.Path]::GetFullPath((Join-Path $PSScriptRoot '..'))
$taskExe = [IO.Path]::GetFullPath($ServerPath)
if (-not $ReportDirectory) { $ReportDirectory = Join-Path $taskRoot ('artifacts/railjack-http-' + [guid]::NewGuid().ToString('N')) }
$ReportDirectory = [IO.Path]::GetFullPath($ReportDirectory)
if (Test-Path -LiteralPath $ReportDirectory) { throw 'Use a new isolated report directory.' }
New-Item -ItemType Directory -Path $ReportDirectory -Force | Out-Null
Add-Type -LiteralPath (Join-Path (Split-Path $taskExe) 'Newtonsoft.Json.dll')
$taskJson = [IO.File]::ReadAllText([IO.Path]::GetFullPath($InventoryFixture))
$taskFixture = [Newtonsoft.Json.Linq.JObject]::Parse($taskJson)
$taskQuestType = '/Lotus/Types/Keys/RailJackBuildQuest/RailjackBuildQuestKeyChain'
$taskQuest = @($taskFixture['QuestKeys'] | Where-Object { [string]$_['ItemType'] -eq $taskQuestType -and [string]$_['Completed'] -eq 'True' })[0]
if (-not $taskQuest -or -not $taskFixture['CrewShips'].HasValues) { throw 'Expected a completed Rising Tide and an owned Railjack.' }
$taskProbe = [Net.Sockets.TcpListener]::new([Net.IPAddress]::Loopback, 0)
$taskPorts = @(1..2 | ForEach-Object { $taskProbe.Start(); $taskProbe.LocalEndpoint.Port; $taskProbe.Stop() })
$taskOrigin = 'http://127.0.0.1:' + $taskPorts[0]
$taskTlsOrigin = 'https://127.0.0.1:' + $taskPorts[1]
$taskServer = Start-Process -FilePath $taskExe -WindowStyle Hidden -PassThru -ArgumentList @(
    ('"--root=' + (Join-Path $ReportDirectory 'runtime') + '"'), ('--port=' + $taskPorts[0]),
    ('--game-port=' + $taskPorts[1]), '--no-irc') -RedirectStandardOutput (Join-Path $ReportDirectory 'stdout.log') -RedirectStandardError (Join-Path $ReportDirectory 'stderr.log')
$taskHandler = [Net.Http.HttpClientHandler]::new()
$taskHandler.UseProxy = $false
# The TLS exception applies only to this disposable loopback server.
$taskHandler.ServerCertificateCustomValidationCallback = [Net.Http.HttpClientHandler]::DangerousAcceptAnyServerCertificateValidator
$taskClient = [Net.Http.HttpClient]::new($taskHandler)
$taskClient.Timeout = [TimeSpan]::FromSeconds(30)
$taskChecks = [Collections.Generic.List[object]]::new()
$taskAdmin = $null
function Check([bool]$Condition, [string]$Name) {
    if (-not $Condition) { throw "FAILED: $Name" }
    $taskChecks.Add(@{name=$Name;passed=$true}); Write-Output "PASS $Name"
}
function Request([string]$Path, [string]$Json, [switch]$Admin, [switch]$Tls) {
    $taskUrl = $(if ($Tls) { $taskTlsOrigin } else { $taskOrigin }) + $Path
    $taskMessage = [Net.Http.HttpRequestMessage]::new($(if ($PSBoundParameters.ContainsKey('Json')) {'POST'} else {'GET'}), $taskUrl)
    try {
        if ($Admin) { $taskMessage.Headers.Authorization = [Net.Http.Headers.AuthenticationHeaderValue]::new('Bearer', $taskAdmin) }
        if ($PSBoundParameters.ContainsKey('Json')) { $taskMessage.Content = [Net.Http.StringContent]::new($Json, [Text.Encoding]::UTF8, 'application/json') }
        $taskReply = $taskClient.SendAsync($taskMessage).GetAwaiter().GetResult()
        try { return @{status=[int]$taskReply.StatusCode;body=$taskReply.Content.ReadAsStringAsync().GetAwaiter().GetResult()} }
        finally { $taskReply.Dispose() }
    } finally { $taskMessage.Dispose() }
}
function Read-Json($Reply) {
    if ($Reply.status -ne 200) { throw "Unexpected HTTP status $($Reply.status)." }
    return ,([Newtonsoft.Json.Linq.JObject]::Parse($Reply.body))
}
function Assert-Activation($Ship) {
    $taskFeatures = @($Ship['Features'] | ForEach-Object { [string]$_ })
    Check ($taskFeatures -contains '/Lotus/Types/Items/ShipFeatureItems/RailjackCephalonShipFeatureItem') 'Railjack Cephalon is installed'
    Check ($taskFeatures -contains '/Lotus/Types/Items/ShipFeatureItems/RailjackKeyShipFeatureItem') 'Reliquary key is installed'
    foreach ($taskPart in @('Hull','HoodBrace','Hood','NacelleLeft','NacelleRight','Tail')) {
        Check ($taskFeatures -contains "/Lotus/Types/Items/ShipFeatureItems/Railjack/Railjack${taskPart}FeatureItem") "Built Railjack part retained: $taskPart"
    }
    Check ($taskFeatures.Count -eq @($taskFeatures | Select-Object -Unique).Count) 'Installed features contain no duplicates'
}
try {
    $taskReady = $false
    for ($taskAttempt = 0; $taskAttempt -lt 40; $taskAttempt++) {
        if ($taskServer.HasExited) { throw 'Isolated server exited.' }
        try { if ((Request '/health').status -eq 200) { $taskReady = $true; break } } catch { }
        Start-Sleep -Milliseconds 250
    }
    Check $taskReady 'Published ServerInteractive starts on isolated ports'
    $taskAdmin = (Get-Content -LiteralPath (Join-Path $ReportDirectory 'runtime/server.json') -Raw | ConvertFrom-Json).AdminToken
    $taskLoginBody = '{"email":"railjack-replay@example.invalid","password":"isolated-client-digest","ClientType":"Windows","kick":true}'
    $taskLoginPath = '/api/login.php?buildLabel=2026.08.19.11.06/SakCydygO6-qG7S-xI5diQ&clientMod=XFEWarframe'
    $taskLogin = Read-Json (Request $taskLoginPath -Json $taskLoginBody -Tls)
    Check ([string]$taskLogin['id'] -ne '') 'Isolated game session signs in over HTTPS'
    $taskQuery = 'accountId=' + [string]$taskLogin['id'] + '&nonce=' + [string]$taskLogin['Nonce']
    $taskAccountPath = '/control/v1/accounts/' + [string]$taskLogin['id']
    Check ((Request ($taskAccountPath + '/import') -Json ('{"inventory":' + $taskJson + '}') -Admin).status -eq 200) 'Current inventory copy imports without tutorial or quest replay'
    $taskShip = Read-Json (Request ('/api/getShip.php?' + $taskQuery) -Tls)
    Assert-Activation $taskShip['Ship']
    $taskStored = Read-Json (Request ($taskAccountPath + '/export') -Admin)
    foreach ($taskField in @('CrewShips','CrewShipHarnesses','CrewShipWeapons','CrewShipWeaponSkins','CrewMembers','Suits','LongGuns','Pistols','Melee','Upgrades','RawUpgrades','MiscItems','LoadOutPresets','CurrentLoadOutIds','QuestKeys','ActiveQuest','NodeIntrosCompleted','RegularCredits','PremiumCredits')) {
        Check ([Newtonsoft.Json.Linq.JToken]::DeepEquals($taskFixture[$taskField], $taskStored[$taskField])) "Inventory preserved: $taskField"
    }
    $taskOldShip = $taskFixture['Ship'].DeepClone(); $taskNewShip = $taskStored['Ship'].DeepClone()
    foreach ($taskField in @('Features','ContentUrlSignature')) { $null = $taskOldShip.Remove($taskField); $null = $taskNewShip.Remove($taskField) }
    Check ([Newtonsoft.Json.Linq.JToken]::DeepEquals($taskOldShip, $taskNewShip)) 'Orbiter rooms, decoration and settings preserved'
    $taskGameInventory = Read-Json (Request ('/api/inventory.php?' + $taskQuery) -Tls)
    foreach ($taskField in @('CrewShips','CrewShipHarnesses','CrewShipWeapons')) {
        Check ([Newtonsoft.Json.Linq.JToken]::DeepEquals($taskFixture[$taskField], $taskGameInventory[$taskField])) "Native game inventory retains $taskField"
    }
    $taskReplay = Read-Json (Request ('/api/updateQuest.php?' + $taskQuery) -Json ('{"QuestKeys":[' + $taskQuest.ToString([Newtonsoft.Json.Formatting]::None) + ']}') -Tls)
    Check (-not $taskReplay['InventoryChanges'].HasValues) 'Already completed quest does not replay rewards'
    $taskAfter = Read-Json (Request ($taskAccountPath + '/export') -Admin)
    Check ([Newtonsoft.Json.Linq.JToken]::DeepEquals($taskStored['Ship']['Features'], $taskAfter['Ship']['Features'])) 'Repeated reads and completion do not duplicate activation'
    Check ([Newtonsoft.Json.Linq.JToken]::DeepEquals($taskFixture['ActiveQuest'], $taskAfter['ActiveQuest'])) 'Unrelated active quest remains selected'
    $taskLogin = Read-Json (Request $taskLoginPath -Json $taskLoginBody -Tls)
    $taskQuery = 'accountId=' + [string]$taskLogin['id'] + '&nonce=' + [string]$taskLogin['Nonce']
    $taskRelogged = Read-Json (Request ('/api/getShip.php?' + $taskQuery) -Tls)
    Check ([Newtonsoft.Json.Linq.JToken]::DeepEquals($taskStored['Ship']['Features'], $taskRelogged['Ship']['Features'])) 'Activation survives a new game session'
    Check ((Request '/control/v1/shutdown' -Json '{}' -Admin).status -eq 200 -and $taskServer.WaitForExit(5000) -and $taskServer.ExitCode -eq 0) 'Only the isolated server shuts down cleanly'
    @{passed=$true;scope='Published ServerInteractive HTTP/HTTPS with a copy of the existing inventory; no game process or desktop input';
        fixtureSha256=(Get-FileHash -LiteralPath $InventoryFixture -Algorithm SHA256).Hash;
        coreSha256=(Get-FileHash -LiteralPath (Join-Path (Split-Path $taskExe) 'XFEWarframe.Core.dll') -Algorithm SHA256).Hash;
        checks=$taskChecks} | ConvertTo-Json -Depth 8 | Set-Content -LiteralPath (Join-Path $ReportDirectory 'result.json') -Encoding utf8
    Write-Output "Railjack HTTP results: $ReportDirectory"
} finally {
    $taskClient.Dispose()
    if (-not $taskServer.HasExited) { Stop-Process -Id $taskServer.Id -ErrorAction SilentlyContinue }
    $taskServer.Dispose(); $taskAdmin = $null
}