diff --git a/AUTHORS b/AUTHORS index 5b63aad20b..9b52323741 100644 --- a/AUTHORS +++ b/AUTHORS @@ -61,6 +61,7 @@ Also thanks to: * Gordon Martin (Happy0) * Guido Lipke (LipkeGu) * Gyula Zimmermann (Graion Dilach) + * Hervé Matysiak (Herve-M) * Huw Pascoe * Ian T. Jacobsen (Smilex) * Imago diff --git a/OpenRA.Game/Network/ReplayConnection.cs b/OpenRA.Game/Network/ReplayConnection.cs index 0eb8b93cb7..6bd2a5f603 100644 --- a/OpenRA.Game/Network/ReplayConnection.cs +++ b/OpenRA.Game/Network/ReplayConnection.cs @@ -27,6 +27,7 @@ namespace OpenRA.Network Queue chunks = new Queue(); List sync = new List(); int ordersFrame; + Dictionary lastClientsFrame = new Dictionary(); public int LocalClientId { get { return 0; } } public ConnectionState ConnectionState { get { return ConnectionState.Connected; } } @@ -55,6 +56,14 @@ namespace OpenRA.Network var frame = BitConverter.ToInt32(packet, 0); chunk.Packets.Add(Pair.New(client, packet)); + if (frame != int.MaxValue) + { + if (!lastClientsFrame.ContainsKey(client)) + lastClientsFrame[client] = frame; + else if (frame > lastClientsFrame[client]) + lastClientsFrame[client] = frame; + } + if (packet.Length == 5 && packet[4] == 0xBF) continue; // disconnect else if (packet.Length >= 5 && packet[4] == 0x65) @@ -81,6 +90,25 @@ namespace OpenRA.Network TickCount = Math.Max(TickCount, frame); } } + + // 2nd parse : replace all disconnect packets without frame with real + // disconnect frame + // NOTE: to modify/remove if a reconnect feature is set + foreach (var tmpChunk in chunks) + { + foreach (var tmpPacketPair in tmpChunk.Packets) + { + var client = tmpPacketPair.First; + var packet = tmpPacketPair.Second; + if (packet.Length == 5 && packet[4] == 0xBF) + { + int lastClientFrame = lastClientsFrame[client]; + byte[] lastFramePacket = BitConverter.GetBytes(lastClientFrame); + if (lastFramePacket.Length == 4) + Array.Copy(lastFramePacket, packet, lastFramePacket.Length); + } + } + } } ordersFrame = LobbyInfo.GlobalSettings.OrderLatency;