Fix Cut 5c Soul findings: PVS wire isolation, walker clock/swap/spectator sync, Release Box3D build graph, Packet 2 overflow & bounds checks, L1 timeout/reconnect
This commit is contained in:
parent
8ab62655d5
commit
39ad46cd14
15 changed files with 1231 additions and 177 deletions
|
|
@ -332,6 +332,401 @@ namespace RustToDust.Tests
|
|||
Assert.Equal(0, host.ConnectedHumanCount);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Cut5cFix1_Sion30mAcrossBuilding_OmitsOccludedRivalFromInitialStateCorePvsAndEvents()
|
||||
{
|
||||
using var host = new ServerMatchHost(IPAddress.Loopback, 0, seed: 42, ArenaMapKind.Sion, maxHumans: 12, autoRestartSec: 0);
|
||||
var ep = new IPEndPoint(IPAddress.Loopback, host.BoundPort);
|
||||
|
||||
// Pick a solid Sion Old Town building ~30m wide and place contender 0 & 1 on opposite sides BEFORE client B joins!
|
||||
var sion = host.Session.State.SionMap!;
|
||||
var terrain = host.Session.State.Terrain;
|
||||
float halfH = Catalog.Jackal.HalfHeight;
|
||||
SionBuildingAabb? chosen = null;
|
||||
float z1 = 0f, z2 = 0f;
|
||||
for (int i = 0; i < sion.Buildings.Count; i++)
|
||||
{
|
||||
var b = sion.Buildings[i];
|
||||
if (b.Class != "Gebaeude Einzelhaus" || b.HalfX < 6f || b.HalfZ < 6f || (b.RoofY - b.GroundY) < 9f ||
|
||||
MathF.Abs(b.CenterX) > 600f || MathF.Abs(b.CenterZ) > 600f)
|
||||
continue;
|
||||
float candZ1 = b.CenterZ - b.HalfZ - 5f;
|
||||
float candZ2 = b.CenterZ + b.HalfZ + 5f;
|
||||
if (MathF.Abs(candZ2 - candZ1) > 48f) continue;
|
||||
if (sion.IsInsideAnyBuildingXz(b.CenterX, candZ1, 3.5f) || sion.IsInsideAnyBuildingXz(b.CenterX, candZ2, 3.5f))
|
||||
continue;
|
||||
float y1 = terrain.SampleHeight(b.CenterX, candZ1) + halfH + 0.15f;
|
||||
float y2 = terrain.SampleHeight(b.CenterX, candZ2) + halfH + 0.15f;
|
||||
if (!host.Session.HasLineOfSight(b.CenterX, MatchRules.GetObserverEyeY(y1, halfH), candZ1,
|
||||
b.CenterX, MatchRules.GetTargetAimY(y2, halfH), candZ2))
|
||||
{
|
||||
chosen = b;
|
||||
z1 = candZ1;
|
||||
z2 = candZ2;
|
||||
break;
|
||||
}
|
||||
}
|
||||
Assert.NotNull(chosen);
|
||||
var building = chosen!.Value;
|
||||
|
||||
using var clientA = new RemoteArenaSession(ep, "Alpha");
|
||||
long nowMs = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
|
||||
Assert.True(PumpUntil(host, new[] { clientA }, () => clientA.IsJoined, ref nowMs, 3000));
|
||||
int slotA = clientA.LocalContenderId;
|
||||
|
||||
// Place A on side 1, and pick an AI/B slot on side 2 (~30m away across the building) BEFORE clientB joins
|
||||
int slotB = (slotA + 1) % MatchState.ContenderCount;
|
||||
host.Session.SetContenderPose(slotA, building.CenterX, z1, 0f);
|
||||
host.Session.SetContenderPose(slotB, building.CenterX, z2, MathF.PI);
|
||||
host.Session.State.SpawnChassisDrop(building.CenterX, z2 + 2f, Catalog.Anvil);
|
||||
host.StepOnce(nowMs += 16);
|
||||
|
||||
// Re-place B after step and join B while A & B are ~30m apart across the building
|
||||
host.Session.SetContenderPose(slotA, building.CenterX, z1, 0f);
|
||||
host.Session.SetContenderPose(slotB, building.CenterX, z2, MathF.PI);
|
||||
host.StepOnce(nowMs += 16);
|
||||
|
||||
Assert.False(host.Session.IsEntityInPeerPvs(slotA, true, slotB),
|
||||
"Occluded rival 30m across Sion building must NOT be in Peer A PVS (no 65m blind bypass)");
|
||||
|
||||
using var clientB = new RemoteArenaSession(ep, "Bravo");
|
||||
Assert.True(PumpUntil(host, new[] { clientA, clientB }, () => clientB.IsJoined, ref nowMs, 3000));
|
||||
int realSlotB = clientB.LocalContenderId;
|
||||
|
||||
// Verify InitialMatchStateDto omits occluded rival at ~30m across Sion building:
|
||||
// Retire clientA, pin slotA at z1 and slotB at z2, then reconnect clientA with its token!
|
||||
Guid tokenA = clientA.ReconnectToken;
|
||||
clientA.DisconnectGracefully("RejoinTest");
|
||||
clientA.Dispose();
|
||||
for (int t = 0; t < 35; t++)
|
||||
{
|
||||
host.Session.SetContenderPose(slotA, building.CenterX, z1, 0f);
|
||||
host.Session.SetContenderPose(realSlotB, building.CenterX, z2, MathF.PI);
|
||||
nowMs += 16;
|
||||
host.StepOnce(nowMs);
|
||||
clientB.BeginRenderFrame(1.0 / 60.0, 1f);
|
||||
Thread.Sleep(1);
|
||||
}
|
||||
|
||||
using var clientARejoin = new RemoteArenaSession(ep, "Alpha", tokenA);
|
||||
Assert.True(PumpUntil(host, new[] { clientARejoin, clientB }, () => clientARejoin.IsJoined, ref nowMs, 3000));
|
||||
Assert.Equal(slotA, clientARejoin.LocalContenderId);
|
||||
Assert.False(clientARejoin.IsContenderVisible(realSlotB), "Occluded rival 30m across building must not be visible in InitialMatchStateDto");
|
||||
Assert.Equal(0f, clientARejoin.ViewState.Contenders[realSlotB].X);
|
||||
Assert.Equal(0f, clientARejoin.ViewState.Contenders[realSlotB].Z);
|
||||
|
||||
// Re-pin & test live events while occluded behind building
|
||||
host.Session.SetContenderPose(slotA, building.CenterX, z1, 0f);
|
||||
host.Session.SetContenderPose(realSlotB, building.CenterX, z2, MathF.PI);
|
||||
if (host.Session.State.ObserverStates.TryGetValue(slotA, out var obsA)) obsA.ContenderContacts.Remove(realSlotB);
|
||||
|
||||
int dropsBefore = clientARejoin.ViewState.GroundDrops.Count(d => !d.PickedUp && Vector2.Distance(new Vector2(d.X, d.Z), new Vector2(building.CenterX, z2)) < 12f);
|
||||
host.Session.State.SpawnChassisDrop(building.CenterX, z2 + 3f, Catalog.Paladin);
|
||||
int hitsBefore = clientARejoin.ViewState.HitEvents.Count;
|
||||
int tracersBefore = clientARejoin.ViewState.Tracers.Count;
|
||||
|
||||
for (int t = 0; t < 10; t++)
|
||||
{
|
||||
clientARejoin.SubmitLocalInput(new PlayerInput(0f, 0f, building.CenterX, z1 - 10f, false, false, false), true);
|
||||
clientB.SubmitLocalInput(new PlayerInput(0f, 0f, building.CenterX + 3f, z2 + 6f, Fire: true, false, false, AimWorldY: terrain.SampleHeight(building.CenterX + 3f, z2 + 6f)), true);
|
||||
nowMs += 16;
|
||||
host.StepOnce(nowMs);
|
||||
clientARejoin.BeginRenderFrame(1.0 / 60.0, 1f);
|
||||
clientB.BeginRenderFrame(1.0 / 60.0, 1f);
|
||||
Thread.Sleep(1);
|
||||
}
|
||||
|
||||
Assert.False(host.Session.IsEntityInPeerPvs(slotA, true, realSlotB));
|
||||
Assert.False(clientARejoin.IsContenderVisible(realSlotB));
|
||||
int dropsAfter = clientARejoin.ViewState.GroundDrops.Count(d => !d.PickedUp && Vector2.Distance(new Vector2(d.X, d.Z), new Vector2(building.CenterX, z2)) < 12f);
|
||||
Assert.Equal(dropsBefore, dropsAfter);
|
||||
// Any HitImpactEvent or ShotFiredEvent from occluded B behind the building must NOT leak B's coordinates to A!
|
||||
for (int i = tracersBefore; i < clientARejoin.ViewState.Tracers.Count; i++)
|
||||
{
|
||||
var tr = clientARejoin.ViewState.Tracers[i];
|
||||
Assert.True(Vector2.Distance(new Vector2(tr.StartX, tr.StartZ), new Vector2(building.CenterX, z2)) > 5f,
|
||||
"Occluded ShotFiredEvent must not leak rival shooter coords");
|
||||
}
|
||||
for (int i = hitsBefore; i < clientARejoin.ViewState.HitEvents.Count; i++)
|
||||
{
|
||||
var he = clientARejoin.ViewState.HitEvents[i];
|
||||
Assert.True(Vector2.Distance(new Vector2(he.SourceX, he.SourceZ), new Vector2(building.CenterX, z2)) > 5f,
|
||||
"Occluded HitImpactEvent must scrub SourceX/Y/Z if shooter not in PVS");
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Cut5cFix2_WalkerGaitClock_ChassisSwapSink_AndSpectatorWalkerSync()
|
||||
{
|
||||
using var host = new ServerMatchHost(IPAddress.Loopback, 0, seed: 42, ArenaMapKind.Desert, maxHumans: 12, autoRestartSec: 0);
|
||||
var serverEp = new IPEndPoint(IPAddress.Loopback, host.BoundPort);
|
||||
|
||||
// Real 120ms RTT UDP delay proxy (60ms uplink + 60ms downlink)
|
||||
using var proxyToClient = new System.Net.Sockets.Socket(System.Net.Sockets.AddressFamily.InterNetwork, System.Net.Sockets.SocketType.Dgram, System.Net.Sockets.ProtocolType.Udp) { Blocking = false };
|
||||
using var proxyToServer = new System.Net.Sockets.Socket(System.Net.Sockets.AddressFamily.InterNetwork, System.Net.Sockets.SocketType.Dgram, System.Net.Sockets.ProtocolType.Udp) { Blocking = false };
|
||||
proxyToClient.Bind(new IPEndPoint(IPAddress.Loopback, 0));
|
||||
proxyToServer.Bind(new IPEndPoint(IPAddress.Loopback, 0));
|
||||
var proxyEp = new IPEndPoint(IPAddress.Loopback, ((IPEndPoint)proxyToClient.LocalEndPoint!).Port);
|
||||
|
||||
var uplink = new Queue<(long DeliverMs, byte[] Data)>();
|
||||
var downlink = new Queue<(long DeliverMs, byte[] Data)>();
|
||||
EndPoint? clientRemoteEp = null;
|
||||
void PumpProxy(long tMs, int oneWayMs)
|
||||
{
|
||||
var buf = new byte[4096];
|
||||
while (proxyToClient.Available > 0)
|
||||
{
|
||||
EndPoint from = new IPEndPoint(IPAddress.Any, 0);
|
||||
int n = proxyToClient.ReceiveFrom(buf, ref from);
|
||||
clientRemoteEp = from;
|
||||
uplink.Enqueue((tMs + oneWayMs, buf.AsSpan(0, n).ToArray()));
|
||||
}
|
||||
while (proxyToServer.Available > 0)
|
||||
{
|
||||
EndPoint from = new IPEndPoint(IPAddress.Any, 0);
|
||||
int n = proxyToServer.ReceiveFrom(buf, ref from);
|
||||
downlink.Enqueue((tMs + oneWayMs, buf.AsSpan(0, n).ToArray()));
|
||||
}
|
||||
while (uplink.Count > 0 && uplink.Peek().DeliverMs <= tMs)
|
||||
{
|
||||
proxyToServer.SendTo(uplink.Dequeue().Data, serverEp);
|
||||
}
|
||||
while (downlink.Count > 0 && downlink.Peek().DeliverMs <= tMs && clientRemoteEp is not null)
|
||||
{
|
||||
proxyToClient.SendTo(downlink.Dequeue().Data, clientRemoteEp);
|
||||
}
|
||||
}
|
||||
|
||||
using var client = new RemoteArenaSession(proxyEp, "Walker");
|
||||
long nowMs = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
|
||||
var deadline = DateTimeOffset.UtcNow.AddMilliseconds(4000);
|
||||
while (DateTimeOffset.UtcNow < deadline && !client.IsJoined)
|
||||
{
|
||||
nowMs += 16;
|
||||
PumpProxy(nowMs, 60);
|
||||
host.StepOnce(nowMs);
|
||||
PumpProxy(nowMs, 60);
|
||||
client.PumpNetwork(nowMs);
|
||||
Thread.Sleep(2);
|
||||
}
|
||||
Assert.True(client.IsJoined);
|
||||
int slot = client.LocalContenderId;
|
||||
|
||||
// a) Swap local contender to Paladin (biped walker), walk 2.0s @ 120ms simulated RTT
|
||||
host.Session.SetContenderPose(slot, 0f, 0f, 0f);
|
||||
host.Session.State.SpawnChassisDrop(0f, 0f, Catalog.Paladin);
|
||||
Assert.True(host.Session.TrySwapNearbyChassis(slot));
|
||||
for (int t = 0; t < 16; t++)
|
||||
{
|
||||
client.SubmitLocalInput(new PlayerInput(0f, 0f, 0f, 120f, false, false, false), true);
|
||||
nowMs += 16;
|
||||
PumpProxy(nowMs, 60);
|
||||
host.StepOnce(nowMs);
|
||||
PumpProxy(nowMs, 60);
|
||||
client.BeginRenderFrame(1.0 / 60.0, 1f);
|
||||
Thread.Sleep(1);
|
||||
}
|
||||
|
||||
float clientStartTime = client.PredictedWalkerSimTime ?? 0f;
|
||||
float serverStartTime = host.Session.GetWalkerSimTime(true, slot) ?? 0f;
|
||||
int maxUnackedObserved = 0;
|
||||
for (int t = 0; t < 120; t++)
|
||||
{
|
||||
client.SubmitLocalInput(new PlayerInput(0.8f, 0f, 0f, 120f, false, false, false), true);
|
||||
maxUnackedObserved = Math.Max(maxUnackedObserved, client.UnackedInputCount);
|
||||
nowMs += 16;
|
||||
PumpProxy(nowMs, 60);
|
||||
host.StepOnce(nowMs);
|
||||
PumpProxy(nowMs, 60);
|
||||
client.BeginRenderFrame(1.0 / 60.0, 1f);
|
||||
Thread.Sleep(1);
|
||||
}
|
||||
Assert.True(maxUnackedObserved >= 5, $"Expected >=5 unacked inputs under 120ms RTT, saw {maxUnackedObserved}");
|
||||
|
||||
float? serverWalkerTime = host.Session.GetWalkerSimTime(true, slot);
|
||||
float? clientWalkerTime = client.PredictedWalkerSimTime;
|
||||
Assert.NotNull(serverWalkerTime);
|
||||
Assert.NotNull(clientWalkerTime);
|
||||
float clientDelta = clientWalkerTime!.Value - clientStartTime;
|
||||
float serverDelta = serverWalkerTime!.Value - serverStartTime;
|
||||
Assert.True(MathF.Abs(clientDelta - serverDelta) <= 0.20f,
|
||||
$"Walker SimTime must track 1x within +-0.20s (no 4.83x overdrive): client={clientDelta:F3}s server={serverDelta:F3}s");
|
||||
|
||||
// b) Mid-match Jackal -> Breaker chassis swap must produce 0.0m vertical underground _predErrorPos
|
||||
host.Session.State.SpawnChassisDrop(host.Session.State.Contenders[slot].X, host.Session.State.Contenders[slot].Z, Catalog.Jackal);
|
||||
Assert.True(host.Session.TrySwapNearbyChassis(slot));
|
||||
for (int t = 0; t < 16; t++)
|
||||
{
|
||||
nowMs += 16;
|
||||
PumpProxy(nowMs, 60);
|
||||
host.StepOnce(nowMs);
|
||||
PumpProxy(nowMs, 60);
|
||||
client.BeginRenderFrame(1.0 / 60.0, 1f);
|
||||
Thread.Sleep(1);
|
||||
}
|
||||
var cServer = host.Session.State.Contenders[slot];
|
||||
host.Session.State.SpawnChassisDrop(cServer.X, cServer.Z, Catalog.Breaker);
|
||||
Assert.True(host.Session.TrySwapNearbyChassis(slot));
|
||||
for (int t = 0; t < 16; t++)
|
||||
{
|
||||
client.SubmitLocalInput(new PlayerInput(0f, 0f, cServer.X, cServer.Z + 120f, false, false, false), true);
|
||||
nowMs += 16;
|
||||
PumpProxy(nowMs, 60);
|
||||
host.StepOnce(nowMs);
|
||||
PumpProxy(nowMs, 60);
|
||||
client.BeginRenderFrame(1.0 / 60.0, 1f);
|
||||
var visPos = client.GetInterpolatedContenderPose(slot, 1f).Pos;
|
||||
float gh = host.Session.State.Terrain.SampleHeight(visPos.X, visPos.Z);
|
||||
Assert.True(visPos.Y >= gh + Catalog.Jackal.HalfHeight * 0.5f,
|
||||
$"Jackal->Breaker swap must not sink underground: visY={visPos.Y:F3}m gh={gh:F3}m");
|
||||
Assert.True(MathF.Abs(client.CurrentPredictionError.Y) < 0.15f,
|
||||
$"Jackal->Breaker swap must not accumulate vertical sink error: predErrorY={client.CurrentPredictionError.Y:F3}m");
|
||||
Thread.Sleep(1);
|
||||
}
|
||||
|
||||
// c) Combat spectator walker (Exemplar) has valid GeomScale > 0, IsDigitigrade, non-zero ComRot, and synced Exemplar HP/armor
|
||||
var exemplar = host.Session.State.Spectators.Spectators.First(s => s.Tier == SpectatorTier.Exemplar && s.Alive);
|
||||
exemplar.Stance = SpectatorStance.Provoked;
|
||||
exemplar.TargetContenderId = slot;
|
||||
host.Session.SetContenderPose(slot, exemplar.X, exemplar.Z - 24f, 0f);
|
||||
for (int t = 0; t < 20; t++)
|
||||
{
|
||||
nowMs += 16;
|
||||
PumpProxy(nowMs, 60);
|
||||
host.StepOnce(nowMs);
|
||||
PumpProxy(nowMs, 60);
|
||||
client.BeginRenderFrame(1.0 / 60.0, 1f);
|
||||
Thread.Sleep(1);
|
||||
}
|
||||
Assert.True(client.TrySampleInterpolatedWalkerPose(false, exemplar.Id, 1f, out var exSnap),
|
||||
"Combat Exemplar walker snapshot should be available");
|
||||
Assert.True(exSnap.GeomScale > 0.1f, $"Exemplar GeomScale must be > 0, got {exSnap.GeomScale}");
|
||||
Assert.True(exSnap.IsDigitigrade, "Exemplar walker must have IsDigitigrade=true");
|
||||
Assert.True(exSnap.ComRot.LengthSquared() > 0.5f, "Exemplar walker ComRot must be valid normalized quaternion");
|
||||
var clientExemplar = client.ViewState.Spectators.Spectators.First(s => s.Id == exemplar.Id);
|
||||
Assert.Equal(SpectatorRing.ExemplarSpec.Id, clientExemplar.Grid.Spec.Id);
|
||||
Assert.InRange(clientExemplar.Grid.CoreHp, exemplar.Grid.CoreHp - 1f, exemplar.Grid.CoreHp + 1f);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Cut5cFix4_Packet2OverflowDeliversAll10CombatSpectators_AndMalformedPacketDoesNotThrow()
|
||||
{
|
||||
var state = new MatchState(seed: 42, ArenaMapKind.Desert);
|
||||
var local = state.Contenders[0];
|
||||
local.Grid.SwapChassis(Catalog.Bastion); // large 8x8 local grid
|
||||
|
||||
var contenders = new List<NetContenderState>(12);
|
||||
var walkers = new List<NetWalkerEntry>(12);
|
||||
var combatSpecs = new List<NetSpectatorState>(10);
|
||||
|
||||
for (int i = 0; i < 12; i++)
|
||||
{
|
||||
contenders.Add(new NetContenderState
|
||||
{
|
||||
SlotId = (byte)i,
|
||||
Alive = true,
|
||||
IsHuman = true,
|
||||
Pos = new Vector3(i * 8f, 3f, 0f),
|
||||
Rot = Quaternion.Identity,
|
||||
CoreHpRatio = 1f
|
||||
});
|
||||
var ws = new WalkerVisualSnapshot { LegCount = 4 };
|
||||
for (int l = 0; l < 4; l++) ws.FootNormal[l] = Vector3.UnitY;
|
||||
walkers.Add(new NetWalkerEntry { IsContender = true, EntityId = (byte)i, Snapshot = ws });
|
||||
}
|
||||
for (int i = 0; i < 10; i++)
|
||||
{
|
||||
combatSpecs.Add(new NetSpectatorState
|
||||
{
|
||||
Id = (byte)i,
|
||||
Alive = true,
|
||||
Stance = SpectatorStance.Provoked,
|
||||
TargetContenderId = 0,
|
||||
Pos = new Vector3(40f + i * 4f, 3f, -20f),
|
||||
Rot = Quaternion.Identity
|
||||
});
|
||||
}
|
||||
|
||||
byte[] p1 = SnapshotCodec.EncodeCorePvs(
|
||||
1, 7, 14, 0.25f, 5, 100, 450f, MatchPhase.Active, null, 1, 0xFFF,
|
||||
local, Vector3.Zero, contenders, walkers, combatSpecs, out int writtenInP1);
|
||||
byte[] w1 = SnapshotCodec.WrapLatest(p1, 1, 1);
|
||||
|
||||
var packet2List = new List<NetSpectatorState>();
|
||||
for (int i = writtenInP1; i < combatSpecs.Count; i++) packet2List.Add(combatSpecs[i]);
|
||||
for (int i = 0; i < 20; i++)
|
||||
{
|
||||
packet2List.Add(new NetSpectatorState
|
||||
{
|
||||
Id = (byte)(20 + i),
|
||||
Alive = true,
|
||||
Stance = SpectatorStance.Neutral,
|
||||
TargetContenderId = -1,
|
||||
Pos = new Vector3(200f, 3f, 200f),
|
||||
Rot = Quaternion.Identity
|
||||
});
|
||||
}
|
||||
byte[] p2 = SnapshotCodec.EncodeSpectatorOrbitHalf(1, 7, 0, packet2List);
|
||||
byte[] w2 = SnapshotCodec.WrapLatest(p2, 1, 2);
|
||||
|
||||
Assert.True(w1.Length <= SnapshotCodec.MaxLatestDatagramBytes);
|
||||
Assert.True(w2.Length <= SnapshotCodec.MaxLatestDatagramBytes);
|
||||
|
||||
var dec1 = SnapshotCodec.DecodeCorePvs(SnapshotCodec.Unwrap(w1).Payload.Span);
|
||||
var dec2 = SnapshotCodec.DecodeSpectatorOrbitHalf(SnapshotCodec.Unwrap(w2).Payload.Span);
|
||||
var deliveredCombatIds = dec1.CombatSpectators.Select(s => s.Id)
|
||||
.Concat(dec2.Spectators.Where(s => s.Stance != SpectatorStance.Neutral).Select(s => s.Id))
|
||||
.OrderBy(id => id)
|
||||
.ToList();
|
||||
Assert.Equal(Enumerable.Range(0, 10).Select(i => (byte)i).ToList(), deliveredCombatIds);
|
||||
|
||||
// b) Malformed 120B packet with cellCount=200 must return false cleanly without throwing!
|
||||
byte[] bad = new byte[120];
|
||||
bad[0] = (byte)LatestPacketKind.CorePvs;
|
||||
bad[88] = 200; // cellCount = 200 > 64 and > remaining bytes
|
||||
Assert.False(SnapshotCodec.TryDecodeCorePvs(bad, out _));
|
||||
bad[0] = (byte)LatestPacketKind.SpectatorOrbitHalf;
|
||||
bad[10] = 250;
|
||||
Assert.False(SnapshotCodec.TryDecodeSpectatorOrbitHalf(bad, out _));
|
||||
bad[0] = (byte)LatestPacketKind.RadarContacts;
|
||||
bad[9] = 250;
|
||||
Assert.False(SnapshotCodec.TryDecodeRadarContacts(bad, out _));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Cut5cFix5_TimedOutClientDisconnectsCleanly_AndDeadSlotReconnectIsRejected()
|
||||
{
|
||||
using var host = new ServerMatchHost(IPAddress.Loopback, 0, seed: 42, ArenaMapKind.Desert, maxHumans: 12, autoRestartSec: 0);
|
||||
var ep = new IPEndPoint(IPAddress.Loopback, host.BoundPort);
|
||||
|
||||
using var client = new RemoteArenaSession(ep, "Ghost");
|
||||
long nowMs = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
|
||||
Assert.True(PumpUntil(host, new[] { client }, () => client.IsJoined, ref nowMs, 3000));
|
||||
int slot = client.LocalContenderId;
|
||||
Guid token = client.ReconnectToken;
|
||||
Assert.True(client.ConnectionStatus.Connected);
|
||||
|
||||
// a) Simulate > 6000ms server silence -> client MUST transition to Disconnected (not stuck Connected)!
|
||||
client.PumpNetwork(nowMs + 7000);
|
||||
Assert.False(client.ConnectionStatus.Connected);
|
||||
Assert.False(client.IsJoined);
|
||||
Assert.Contains("DISCONNECTED", client.ConnectionStatus.StateLabel, StringComparison.OrdinalIgnoreCase);
|
||||
|
||||
// Server also times out client & destroys that slot's chassis
|
||||
nowMs += ServerMatchHost.IdleTimeoutMs + 500;
|
||||
host.StepOnce(nowMs);
|
||||
var deadContender = host.Session.State.Contenders[slot];
|
||||
deadContender.Grid.ApplyReplicatedDamage(0, 0, 0f, 20f, 0f, deadContender.Grid.HitSequence + 1);
|
||||
Assert.False(deadContender.Alive);
|
||||
|
||||
// b) Reconnecting with dead-slot ReconnectToken MUST be rejected cleanly instead of hijacking another AI slot!
|
||||
using var deadReconnect = new RemoteArenaSession(ep, "Ghost", token);
|
||||
Assert.False(PumpUntil(host, new[] { deadReconnect }, () => deadReconnect.IsJoined, ref nowMs, 800));
|
||||
Assert.NotNull(deadReconnect.ConnectionStatus.LastError);
|
||||
Assert.Contains("destroyed", deadReconnect.ConnectionStatus.LastError!, StringComparison.OrdinalIgnoreCase);
|
||||
Assert.Equal(0, host.ConnectedHumanCount);
|
||||
}
|
||||
|
||||
private static bool PumpUntil(
|
||||
ServerMatchHost host,
|
||||
RemoteArenaSession[] clients,
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@
|
|||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>disable</ImplicitUsings>
|
||||
<IsPackable>false</IsPackable>
|
||||
<YmirNativeConfiguration Condition="'$(YmirNativeConfiguration)' == ''">Release</YmirNativeConfiguration>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
|
|
|||
Loading…
Reference in a new issue