Overhaul replay parsing. Fixes #4608.

This commit is contained in:
Paul Chote
2014-03-05 18:08:18 +13:00
parent 6385e7ebaa
commit bce0a7b39e
2 changed files with 64 additions and 44 deletions

View File

@@ -12,7 +12,6 @@ using System;
namespace OpenRA.Network
{
/* HACK: a maze of twisty little hacks... */
public class Replay
{
public readonly string Filename;
@@ -22,34 +21,12 @@ namespace OpenRA.Network
public Replay(string filename)
{
Filename = filename;
var lastFrame = 0;
var hasSeenGameStart = false;
var lobbyInfo = null as Session;
using (var conn = new ReplayConnection(filename))
conn.Receive((client, packet) =>
{
var frame = BitConverter.ToInt32(packet, 0);
if (packet.Length == 5 && packet[4] == 0xBF)
return; // disconnect
else if (packet.Length >= 5 && packet[4] == 0x65)
return; // sync
else if (frame == 0)
{
/* decode this to recover lobbyinfo, etc */
var orders = packet.ToOrderList(null);
foreach (var o in orders)
if (o.OrderString == "StartGame")
hasSeenGameStart = true;
else if (o.OrderString == "SyncInfo" && !hasSeenGameStart)
lobbyInfo = Session.Deserialize(o.TargetString);
}
else
lastFrame = Math.Max(lastFrame, frame);
});
Duration = lastFrame * Game.NetTickScale;
LobbyInfo = lobbyInfo;
{
Duration = conn.TickCount * Game.NetTickScale;
LobbyInfo = conn.LobbyInfo;
}
}
public Map Map()