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/coda-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
$taskFixtureJson = [IO.File]::ReadAllText([IO.Path]::GetFullPath($InventoryFixture))
$taskFixture = $taskFixtureJson | ConvertFrom-Json -AsHashtable
if ($taskFixture.Nemesis.Faction -ne 'FC_INFESTATION') { throw 'Expected an active Coda fixture.' }
$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
# Only this disposable loopback server uses a self-signed test certificate.
$taskHandler.ServerCertificateCustomValidationCallback = [Net.Http.HttpClientHandler]::DangerousAcceptAnyServerCertificateValidator
$taskClient = [Net.Http.HttpClient]::new($taskHandler)
$taskClient.Timeout = [TimeSpan]::FromSeconds(15)
$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, $Body = $null, [switch]$Admin, [switch]$Tls, [switch]$Gzip) {
    $taskUrl = $(if ($Tls) { $taskTlsOrigin } else { $taskOrigin }) + $Path
    $taskMessage = [Net.Http.HttpRequestMessage]::new($(if ($null -eq $Body) {'GET'} else {'POST'}), $taskUrl)
    try {
        if ($Admin) { $taskMessage.Headers.Authorization = [Net.Http.Headers.AuthenticationHeaderValue]::new('Bearer', $taskAdmin) }
        if ($null -ne $Body) {
            $taskBytes = [Text.Encoding]::UTF8.GetBytes(($Body | ConvertTo-Json -Depth 80 -Compress))
            if ($Gzip) {
                $taskBuffer = [IO.MemoryStream]::new()
                $taskZip = [IO.Compression.GZipStream]::new($taskBuffer, [IO.Compression.CompressionMode]::Compress, $true)
                $taskZip.Write($taskBytes); $taskZip.Dispose(); $taskBytes = $taskBuffer.ToArray(); $taskBuffer.Dispose()
            }
            $taskMessage.Content = [Net.Http.ByteArrayContent]::new($taskBytes)
            $taskMessage.Content.Headers.ContentType = [Net.Http.Headers.MediaTypeHeaderValue]::new('application/octet-stream')
            if ($Gzip) { $taskMessage.Content.Headers.ContentEncoding.Add('gzip') }
        }
        $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 Id($Value) { if ($Value -is [Collections.IDictionary]) { return $Value['$oid'] }; return [string]$Value }
function Get-Inventory {
    $taskReply = Request ('/api/inventory.php?' + $taskQuery) -Tls
    if ($taskReply.status -ne 200) { throw 'Failed to read isolated inventory.' }
    return $taskReply.body | ConvertFrom-Json -AsHashtable
}
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
    $taskLogin = Request '/api/login.php?buildLabel=2026.08.19.11.06/SakCydygO6-qG7S-xI5diQ&clientMod=XFEWarframe' @{
        email='coda-replay@example.invalid';password='isolated-client-digest';ClientType='Windows';kick=$true} -Tls -Gzip
    Check ($taskLogin.status -eq 200) 'Native game login protocol succeeds over gzip/HTTPS'
    $taskAccount = $taskLogin.body | ConvertFrom-Json
    $taskQuery = 'accountId=' + $taskAccount.id + '&nonce=' + $taskAccount.Nonce
    $taskAccountPath = '/control/v1/accounts/' + $taskAccount.id
    $taskPresets = @($taskFixture.LoadOutPresets.DATAKNIFE)
    $taskPreset = @($taskPresets | Where-Object { (Id $_.ItemId) -eq (Id $taskFixture.CurrentLoadOutIds[7]) })[0]
    if (-not $taskPreset) { $taskPreset = $taskPresets[0] }
    $taskKnife = @($taskFixture.DataKnives | Where-Object { (Id $_.ItemId) -eq (Id $taskPreset.s.ItemId) })[0]
    if (-not $taskKnife) { $taskKnife = $taskFixture.DataKnives[0] }
    $taskModSlot = [int]$taskPreset.s.mod
    $taskAttached = @($taskKnife.Configs[$taskModSlot].Upgrades | Where-Object { $_ } | ForEach-Object {
        $taskReference = $_
        if ($taskReference.StartsWith('/Lotus/')) { @{ItemType=$taskReference;UpgradeFingerprint='{}';ItemId=@{'$oid'='000000000000000000000000'}} }
        else { @($taskFixture.Upgrades | Where-Object { (Id $_.ItemId) -eq $taskReference })[0] }
    })
    $taskWords = @('One','Two','Three','Four','Five','Six','Seven','Eight')
    $taskSymbols = @($taskAttached | Where-Object { $_.ItemType -match '/Immortal/Antivirus(One|Two|Three|Four|Five|Six|Seven|Eight)Mod$' } |
        ForEach-Object { [array]::IndexOf($taskWords, $Matches[1]) })
    if ($taskSymbols.Count -lt 1 -or $taskSymbols.Count -gt 3) { throw 'Fixture needs equipped antivirus.' }
    while ($taskSymbols.Count -lt 3) { $taskSymbols += 8 }
    $taskGuess = $taskSymbols[0] -bor ($taskSymbols[1] -shl 4) -bor ($taskSymbols[2] -shl 8)
    # Reimport before each scenario; all mutations below affect only this disposable account.
    foreach ($taskProgress in @(0,65,95)) {
        if ($taskProgress -ne 0) {
            $taskLogin = Request '/api/login.php?buildLabel=2026.08.19.11.06/SakCydygO6-qG7S-xI5diQ&clientMod=XFEWarframe' @{
                email="coda-replay-$taskProgress@example.invalid";password='isolated-client-digest';ClientType='Windows';kick=$true} -Tls -Gzip
            Check ($taskLogin.status -eq 200) 'Each completion scenario uses a separate disposable account'
            $taskAccount = $taskLogin.body | ConvertFrom-Json
            $taskQuery = 'accountId=' + $taskAccount.id + '&nonce=' + $taskAccount.Nonce
            $taskAccountPath = '/control/v1/accounts/' + $taskAccount.id
        }
        $taskCopy = $taskFixtureJson | ConvertFrom-Json -AsHashtable
        $taskCopy.Nemesis.HenchmenKilled = [double]$taskProgress
        $taskCopy.Nemesis.Weakened = $false; $taskCopy.Nemesis.GuessHistory = @()
        $taskReply = Request ($taskAccountPath + '/import') @{inventory=$taskCopy} -Admin
        Check ($taskReply.status -eq 200) "Inventory copy imports at $taskProgress percent"
        $taskPrecheck = Request ('/api/nemesis.php?' + $taskQuery + '&mode=p') @{guess=$taskSymbols} -Tls -Gzip
        Check ($taskPrecheck.status -eq 200 -and ($taskPrecheck.body | ConvertFrom-Json).GuessResult -gt 0) 'Actual equipped antivirus passes native prespawn check'
        $taskBody = @{guess=$taskGuess;position=0;knife=@{Item=$taskKnife;ModSlot=$taskModSlot;CustSlot=0;AttachedUpgrades=$taskAttached;Skins=@();HiddenWhenHolstered=$false}}
        $taskStab = Request ('/api/nemesis.php?' + $taskQuery + '&mode=r') $taskBody -Tls -Gzip
        Check ($taskStab.status -eq 200) "Native knife payload is accepted at $taskProgress percent"
        $taskInventory = Get-Inventory
        $taskExpected = [Math]::Min(100, $taskProgress + 35)
        Check ($taskInventory.Nemesis.HenchmenKilled -eq $taskExpected) "Two 15-percent potency mods: $taskProgress -> $taskExpected"
        Check ($taskInventory.Nemesis.HenchmenKilled -is [long]) 'Inventory progress uses an integer JSON token'
        $taskWeakened = $taskExpected -eq 100
        Check ($taskInventory.Nemesis.Weakened -eq $taskWeakened) 'Completion flag follows the antivirus threshold'
        $taskCharges = @((($taskStab.body | ConvertFrom-Json).UpgradeIds))
        Check ($taskCharges.Count -eq $(if ($taskWeakened) {3} else {2})) 'Potency and final antivirus charges are consumed at the correct time'
        if ($taskWeakened) {
            Check ($taskInventory.Nemesis.InfNodes.Count -eq 1 -and $taskInventory.Nemesis.InfNodes[0].Node -eq 'CrewBattleNode559') 'Final Coda confrontation becomes available'
        }
        $taskRetry = Request ('/api/nemesis.php?' + $taskQuery + '&mode=r') $taskBody -Tls -Gzip
        Check ($taskRetry.status -eq 200 -and $taskRetry.body -eq $taskStab.body) 'Network retry returns the same receipt without another charge'
        $taskTarget = Request ('/api/nemesis.php?' + $taskQuery + '&mode=w') @{} -Tls
        Check ($taskTarget.status -eq 200 -and ($taskTarget.body | ConvertFrom-Json).target.HenchmenKilled -is [long]) 'Nemesis target response also uses native integer progress'
    }
    $taskShutdown = Request '/control/v1/shutdown' @{} -Admin
    Check ($taskShutdown.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, native gzip knife payload replay, isolated inventory copy; no game or desktop input';
        serverSha256=(Get-FileHash -LiteralPath $taskExe -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 "Coda HTTP results: $ReportDirectory"
} finally {
    $taskClient.Dispose()
    if (-not $taskServer.HasExited) { Stop-Process -Id $taskServer.Id -ErrorAction SilentlyContinue }
    $taskServer.Dispose(); $taskAdmin = $null
}