From 57d2a11fd55b0cfa58ebdeaeca016ca50d3acf4b Mon Sep 17 00:00:00 2001 From: Vinzenz Schroeter Date: Sat, 4 May 2024 13:16:40 +0200 Subject: [PATCH] deduplicate player info message --- .../TanksServer/Interactivity/PlayerInfoConnection.cs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tanks-backend/TanksServer/Interactivity/PlayerInfoConnection.cs b/tanks-backend/TanksServer/Interactivity/PlayerInfoConnection.cs index cd4d461..29ac8b6 100644 --- a/tanks-backend/TanksServer/Interactivity/PlayerInfoConnection.cs +++ b/tanks-backend/TanksServer/Interactivity/PlayerInfoConnection.cs @@ -48,6 +48,14 @@ internal sealed class PlayerInfoConnection : WebsocketServerConnection await Task.Yield(); var response = await GenerateMessageAsync(); + + var shouldDropPacket = _lastMessage != null && response.Memory.Span.SequenceEqual(_lastMessage.Memory.Span); + if (shouldDropPacket) + { + response.Dispose(); + return; + } + var wantsNow = Interlocked.Exchange(ref _wantsInfoOnTick, 0) != 0; if (wantsNow)