diff --git a/OpenRA.Game/Network/ReplayConnection.cs b/OpenRA.Game/Network/ReplayConnection.cs index a705a2196b..7ee257a06f 100755 --- a/OpenRA.Game/Network/ReplayConnection.cs +++ b/OpenRA.Game/Network/ReplayConnection.cs @@ -1,6 +1,6 @@ #region Copyright & License Information /* - * Copyright 2007-2011 The OpenRA Developers (see AUTHORS) + * Copyright 2007-2014 The OpenRA Developers (see AUTHORS) * This file is part of OpenRA, which is free software. It is made * available to you under the terms of the GNU General Public License * as published by the Free Software Foundation. For more information, @@ -19,41 +19,45 @@ namespace OpenRA.Network FileStream replayStream; List sync = new List(); - public ReplayConnection( string replayFilename ) { replayStream = File.OpenRead( replayFilename ); } - public int LocalClientId { get { return 0; } } public ConnectionState ConnectionState { get { return ConnectionState.Connected; } } - // do nothing; ignore locally generated orders - public void Send( int frame, List orders ) { } - public void SendImmediate( List orders ) { } - - public void SendSync( int frame, byte[] syncData ) + public ReplayConnection(string replayFilename) { - var ms = new MemoryStream(); - ms.Write( BitConverter.GetBytes( frame ) ); - ms.Write( syncData ); - sync.Add( ms.ToArray() ); + replayStream = File.OpenRead(replayFilename); } - public void Receive( Action packetFn ) + // do nothing; ignore locally generated orders + public void Send(int frame, List orders) { } + public void SendImmediate(List orders) { } + + public void SendSync(int frame, byte[] syncData) { - while( sync.Count != 0 ) + var ms = new MemoryStream(); + ms.Write(BitConverter.GetBytes(frame)); + ms.Write(syncData); + sync.Add(ms.ToArray()); + } + + public void Receive(Action packetFn) + { + while (sync.Count != 0) { - packetFn( LocalClientId, sync[ 0 ] ); - sync.RemoveAt( 0 ); + packetFn(LocalClientId, sync[0]); + sync.RemoveAt(0); } - if( replayStream == null ) return; + if (replayStream == null) + return; - var reader = new BinaryReader( replayStream ); + var reader = new BinaryReader(replayStream); - while( replayStream.Position < replayStream.Length ) + while (replayStream.Position < replayStream.Length) { var client = reader.ReadInt32(); var packetLen = reader.ReadInt32(); - var packet = reader.ReadBytes( packetLen ); - packetFn( client, packet ); + var packet = reader.ReadBytes(packetLen); + packetFn(client, packet); } replayStream = null;