Ensure replays end when the recorder disconnects.
When ReplayConnection fixes up disconnection packets, this allows the game to continue past the point of a player disconnecting. Unfortunately this also applies to the player who actually disconnected which means the replay continues in an invalid manner. To fix this - we now explicitly don't replace their packet in order to ensure such replays end at the correct time.
This commit is contained in:
@@ -56,13 +56,9 @@ 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 (frame != int.MaxValue &&
|
||||
(!lastClientsFrame.ContainsKey(client) || frame > lastClientsFrame[client]))
|
||||
lastClientsFrame[client] = frame;
|
||||
|
||||
if (packet.Length == 5 && packet[4] == 0xBF)
|
||||
continue; // disconnect
|
||||
@@ -91,6 +87,8 @@ namespace OpenRA.Network
|
||||
}
|
||||
}
|
||||
|
||||
var lastClientToDisconnect = lastClientsFrame.MaxBy(kvp => kvp.Value).Key;
|
||||
|
||||
// 2nd parse : replace all disconnect packets without frame with real
|
||||
// disconnect frame
|
||||
// NOTE: to modify/remove if a reconnect feature is set
|
||||
@@ -99,13 +97,17 @@ namespace OpenRA.Network
|
||||
foreach (var tmpPacketPair in tmpChunk.Packets)
|
||||
{
|
||||
var client = tmpPacketPair.First;
|
||||
|
||||
// Don't replace the final disconnection packet - we still want this to end the replay.
|
||||
if (client == lastClientToDisconnect)
|
||||
continue;
|
||||
|
||||
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);
|
||||
var lastClientFrame = lastClientsFrame[client];
|
||||
var lastFramePacket = BitConverter.GetBytes(lastClientFrame);
|
||||
Array.Copy(lastFramePacket, packet, lastFramePacket.Length);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user