net: enforce 1152B RUDP wire MTU cap, skip self-walker in P1, scrub occluded drop picker
This commit is contained in:
parent
39ad46cd14
commit
9081d2bb5c
4 changed files with 102 additions and 20 deletions
|
|
@ -5,6 +5,7 @@ using System.Net;
|
|||
using System.Numerics;
|
||||
using System.Threading;
|
||||
using GameCult.Mesh;
|
||||
using GameCult.Networking;
|
||||
using RustToDust.Core;
|
||||
using RustToDust.Net;
|
||||
using RustToDust.Ymir;
|
||||
|
|
@ -93,12 +94,23 @@ namespace RustToDust.Tests
|
|||
byte[] pIn = SnapshotCodec.EncodeClientInput(new ClientInputPacket(1, 99, 1234, new PlayerInput(1f, -0.5f, 10f, 20f, true, true, false, 2f, 0.5f)));
|
||||
byte[] wIn = SnapshotCodec.WrapLatest(pIn, 1, 4, SnapshotCodec.SchemaInputId);
|
||||
|
||||
_output.WriteLine($"Max wire bytes: Packet1={w1.Length}B, Packet2={w2.Length}B, Packet3={w3.Length}B, Input={wIn.Length}B");
|
||||
byte[] udp1 = EncodeRudpLatestDatagram(w1, 1);
|
||||
byte[] udp2 = EncodeRudpLatestDatagram(w2, 2);
|
||||
byte[] udp3 = EncodeRudpLatestDatagram(w3, 3);
|
||||
byte[] udpIn = EncodeRudpLatestDatagram(wIn, 4);
|
||||
|
||||
Assert.True(w1.Length <= SnapshotCodec.MaxLatestDatagramBytes, $"Packet1 {w1.Length}B > {SnapshotCodec.MaxLatestDatagramBytes}B");
|
||||
Assert.True(w2.Length <= SnapshotCodec.MaxLatestDatagramBytes, $"Packet2 {w2.Length}B > {SnapshotCodec.MaxLatestDatagramBytes}B");
|
||||
Assert.True(w3.Length <= SnapshotCodec.MaxLatestDatagramBytes, $"Packet3 {w3.Length}B > {SnapshotCodec.MaxLatestDatagramBytes}B");
|
||||
Assert.True(wIn.Length <= SnapshotCodec.MaxLatestDatagramBytes, $"Input {wIn.Length}B > {SnapshotCodec.MaxLatestDatagramBytes}B");
|
||||
_output.WriteLine($"Max frame bytes: Packet1={w1.Length}B, Packet2={w2.Length}B, Packet3={w3.Length}B, Input={wIn.Length}B");
|
||||
_output.WriteLine($"Max UDP wire bytes: Packet1={udp1.Length}B, Packet2={udp2.Length}B, Packet3={udp3.Length}B, Input={udpIn.Length}B");
|
||||
|
||||
Assert.True(w1.Length <= SnapshotCodec.MaxLatestFrameBytes, $"Packet1 frame {w1.Length}B > {SnapshotCodec.MaxLatestFrameBytes}B");
|
||||
Assert.True(w2.Length <= SnapshotCodec.MaxLatestFrameBytes, $"Packet2 frame {w2.Length}B > {SnapshotCodec.MaxLatestFrameBytes}B");
|
||||
Assert.True(w3.Length <= SnapshotCodec.MaxLatestFrameBytes, $"Packet3 frame {w3.Length}B > {SnapshotCodec.MaxLatestFrameBytes}B");
|
||||
Assert.True(wIn.Length <= SnapshotCodec.MaxLatestFrameBytes, $"Input frame {wIn.Length}B > {SnapshotCodec.MaxLatestFrameBytes}B");
|
||||
|
||||
Assert.True(udp1.Length <= SnapshotCodec.MaxLatestDatagramBytes, $"Packet1 UDP {udp1.Length}B > {SnapshotCodec.MaxLatestDatagramBytes}B");
|
||||
Assert.True(udp2.Length <= SnapshotCodec.MaxLatestDatagramBytes, $"Packet2 UDP {udp2.Length}B > {SnapshotCodec.MaxLatestDatagramBytes}B");
|
||||
Assert.True(udp3.Length <= SnapshotCodec.MaxLatestDatagramBytes, $"Packet3 UDP {udp3.Length}B > {SnapshotCodec.MaxLatestDatagramBytes}B");
|
||||
Assert.True(udpIn.Length <= SnapshotCodec.MaxLatestDatagramBytes, $"Input UDP {udpIn.Length}B > {SnapshotCodec.MaxLatestDatagramBytes}B");
|
||||
|
||||
var decoded = SnapshotCodec.DecodeCorePvs(SnapshotCodec.Unwrap(w1).Payload.Span);
|
||||
Assert.Equal(12, decoded.Contenders.Count);
|
||||
|
|
@ -669,8 +681,10 @@ namespace RustToDust.Tests
|
|||
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);
|
||||
Assert.True(w1.Length <= SnapshotCodec.MaxLatestFrameBytes);
|
||||
Assert.True(w2.Length <= SnapshotCodec.MaxLatestFrameBytes);
|
||||
Assert.True(EncodeRudpLatestDatagram(w1, 1).Length <= SnapshotCodec.MaxLatestDatagramBytes);
|
||||
Assert.True(EncodeRudpLatestDatagram(w2, 2).Length <= SnapshotCodec.MaxLatestDatagramBytes);
|
||||
|
||||
var dec1 = SnapshotCodec.DecodeCorePvs(SnapshotCodec.Unwrap(w1).Payload.Span);
|
||||
var dec2 = SnapshotCodec.DecodeSpectatorOrbitHalf(SnapshotCodec.Unwrap(w2).Payload.Span);
|
||||
|
|
@ -727,6 +741,73 @@ namespace RustToDust.Tests
|
|||
Assert.Equal(0, host.ConnectedHumanCount);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Cut5cFix6_Dense12QuadWalkersAndExemplar_OmitsSelfWalkerAndDeliversExemplar()
|
||||
{
|
||||
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, "QuadLead");
|
||||
long nowMs = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
|
||||
Assert.True(PumpUntil(host, new[] { client }, () => client.IsJoined, ref nowMs, 3000));
|
||||
int slot = client.LocalContenderId;
|
||||
|
||||
// Place all 12 contenders as Bastion quad walkers in a tight open cluster around the Exemplar
|
||||
var exemplar = host.Session.State.Spectators.Spectators.First(s => s.Tier == SpectatorTier.Exemplar && s.Alive);
|
||||
exemplar.Stance = SpectatorStance.Provoked;
|
||||
exemplar.TargetContenderId = slot;
|
||||
|
||||
for (int i = 0; i < MatchState.ContenderCount; i++)
|
||||
{
|
||||
host.Session.State.Contenders[i].Grid.SwapChassis(Catalog.Bastion);
|
||||
float angle = i * (MathF.PI * 2f / MatchState.ContenderCount);
|
||||
float dist = i == slot ? 12f : 28f + i * 2f;
|
||||
host.Session.SetContenderPose(i, exemplar.X + MathF.Cos(angle) * dist, exemplar.Z + MathF.Sin(angle) * dist, angle + MathF.PI);
|
||||
}
|
||||
|
||||
DecodedCorePvsSnapshot? lastCore = null;
|
||||
int maxUdpBytes = 0;
|
||||
client.DebugInboundLatestDropFilter = payload =>
|
||||
{
|
||||
if (SnapshotCodec.TryDecodeCorePvs(payload, out var core))
|
||||
{
|
||||
lastCore = core;
|
||||
byte[] frame = SnapshotCodec.WrapLatest(payload, 1, core.SnapshotSeq);
|
||||
maxUdpBytes = Math.Max(maxUdpBytes, EncodeRudpLatestDatagram(frame, core.SnapshotSeq).Length);
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
for (int t = 0; t < 20; t++)
|
||||
{
|
||||
nowMs += 16;
|
||||
host.StepOnce(nowMs);
|
||||
client.BeginRenderFrame(1.0 / 60.0, 1f);
|
||||
Thread.Sleep(1);
|
||||
}
|
||||
|
||||
byte exemplarIdx = (byte)host.Session.State.Spectators.Spectators.Select((s, idx) => (s, idx)).First(x => ReferenceEquals(x.s, exemplar)).idx;
|
||||
Assert.NotNull(lastCore);
|
||||
_output.WriteLine($"Cut5cFix6: maxUdpBytes={maxUdpBytes}B, walkers=[{string.Join(",", lastCore!.Walkers.Select(w => $"{(w.IsContender ? 'C' : 'S')}{w.EntityId}"))}]");
|
||||
Assert.True(maxUdpBytes > 0 && maxUdpBytes <= SnapshotCodec.MaxLatestDatagramBytes,
|
||||
$"Packet 1 UDP datagram must be <= {SnapshotCodec.MaxLatestDatagramBytes}B, got {maxUdpBytes}B");
|
||||
Assert.DoesNotContain(lastCore.Walkers, w => w.IsContender && w.EntityId == slot);
|
||||
Assert.Contains(lastCore.Walkers, w => !w.IsContender && w.EntityId == exemplarIdx);
|
||||
Assert.True(client.TrySampleInterpolatedWalkerPose(false, exemplar.Id, 1f, out _),
|
||||
"Client must receive Exemplar walker snapshot even under dense 12 quad-walker contention");
|
||||
}
|
||||
|
||||
private static byte[] EncodeRudpLatestDatagram(byte[] frameBytes, uint sequence) =>
|
||||
CultNetRudpPacketCodec.Encode(new CultNetRudpPacket
|
||||
{
|
||||
PacketType = CultNetRudpPacketType.Data,
|
||||
ConnectionId = 0x52544431,
|
||||
Sequence = sequence,
|
||||
ChannelId = SnapshotCodec.ChannelLatest,
|
||||
Sequenced = true,
|
||||
Payload = frameBytes
|
||||
});
|
||||
|
||||
private static bool PumpUntil(
|
||||
ServerMatchHost host,
|
||||
RemoteArenaSession[] clients,
|
||||
|
|
|
|||
Loading…
Reference in a new issue