tidy ReplayConnection

This commit is contained in:
Chris Forbes
2011-12-24 10:11:31 +13:00
parent 727b897994
commit f7e35899cf
2 changed files with 10 additions and 18 deletions

View File

@@ -10,35 +10,26 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.IO;
namespace OpenRA.Network
{
public class ReplayConnection : IConnection
{
//uint nextFrame = 1;
FileStream replayStream;
List<byte[]> sync = new List<byte[]>();
public ReplayConnection( string replayFilename )
{
replayStream = File.OpenRead( replayFilename );
}
public ReplayConnection( string replayFilename ) { replayStream = File.OpenRead( replayFilename ); }
public int LocalClientId
{
get { return 0; }
}
public ConnectionState ConnectionState
{
get { return ConnectionState.Connected; }
}
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<byte[]> orders ) { }
public void SendImmediate( List<byte[]> orders ) { }
public void SendSync( int frame, byte[] syncData )
{
var ms = new MemoryStream();
@@ -47,8 +38,6 @@ namespace OpenRA.Network
sync.Add( ms.ToArray() );
}
List<byte[]> sync = new List<byte[]>();
public void Receive( Action<int, byte[]> packetFn )
{
while( sync.Count != 0 )
@@ -56,9 +45,11 @@ namespace OpenRA.Network
packetFn( LocalClientId, sync[ 0 ] );
sync.RemoveAt( 0 );
}
if( replayStream == null ) return;
var reader = new BinaryReader( replayStream );
while( replayStream.Position < replayStream.Length )
{
var client = reader.ReadInt32();
@@ -66,6 +57,7 @@ namespace OpenRA.Network
var packet = reader.ReadBytes( packetLen );
packetFn( client, packet );
}
replayStream = null;
}

View File

@@ -10,9 +10,9 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.IO;
namespace OpenRA.Network
{