split ReplayRecorderConnection out into its own file
This commit is contained in:
@@ -71,51 +71,4 @@ namespace OpenRA.Network
|
|||||||
|
|
||||||
public void Dispose() { }
|
public void Dispose() { }
|
||||||
}
|
}
|
||||||
|
|
||||||
class ReplayRecorderConnection : IConnection
|
|
||||||
{
|
|
||||||
IConnection inner;
|
|
||||||
BinaryWriter writer;
|
|
||||||
|
|
||||||
public ReplayRecorderConnection( IConnection inner, FileStream replayFile )
|
|
||||||
{
|
|
||||||
this.inner = inner;
|
|
||||||
this.writer = new BinaryWriter( replayFile );
|
|
||||||
}
|
|
||||||
|
|
||||||
public int LocalClientId { get { return inner.LocalClientId; } }
|
|
||||||
public ConnectionState ConnectionState { get { return inner.ConnectionState; } }
|
|
||||||
|
|
||||||
public void Send( int frame, List<byte[]> orders ) { inner.Send( frame, orders ); }
|
|
||||||
public void SendImmediate( List<byte[]> orders ) { inner.SendImmediate( orders ); }
|
|
||||||
public void SendSync( int frame, byte[] syncData ) { inner.SendSync( frame, syncData ); }
|
|
||||||
|
|
||||||
public void Receive( Action<int, byte[]> packetFn )
|
|
||||||
{
|
|
||||||
inner.Receive( ( client, data ) =>
|
|
||||||
{
|
|
||||||
writer.Write( client );
|
|
||||||
writer.Write( data.Length );
|
|
||||||
writer.Write( data );
|
|
||||||
packetFn( client, data );
|
|
||||||
} );
|
|
||||||
}
|
|
||||||
|
|
||||||
bool disposed;
|
|
||||||
|
|
||||||
public void Dispose()
|
|
||||||
{
|
|
||||||
if( disposed )
|
|
||||||
return;
|
|
||||||
|
|
||||||
writer.Close();
|
|
||||||
inner.Dispose();
|
|
||||||
disposed = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
~ReplayRecorderConnection()
|
|
||||||
{
|
|
||||||
Dispose();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
66
OpenRA.Game/Network/ReplayRecorderConnection.cs
Normal file
66
OpenRA.Game/Network/ReplayRecorderConnection.cs
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
#region Copyright & License Information
|
||||||
|
/*
|
||||||
|
* Copyright 2007-2011 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,
|
||||||
|
* see COPYING.
|
||||||
|
*/
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.IO;
|
||||||
|
|
||||||
|
namespace OpenRA.Network
|
||||||
|
{
|
||||||
|
class ReplayRecorderConnection : IConnection
|
||||||
|
{
|
||||||
|
IConnection inner;
|
||||||
|
BinaryWriter writer;
|
||||||
|
|
||||||
|
public ReplayRecorderConnection( IConnection inner, FileStream replayFile )
|
||||||
|
{
|
||||||
|
this.inner = inner;
|
||||||
|
this.writer = new BinaryWriter( replayFile );
|
||||||
|
}
|
||||||
|
|
||||||
|
public int LocalClientId { get { return inner.LocalClientId; } }
|
||||||
|
public ConnectionState ConnectionState { get { return inner.ConnectionState; } }
|
||||||
|
|
||||||
|
public void Send( int frame, List<byte[]> orders ) { inner.Send( frame, orders ); }
|
||||||
|
public void SendImmediate( List<byte[]> orders ) { inner.SendImmediate( orders ); }
|
||||||
|
public void SendSync( int frame, byte[] syncData ) { inner.SendSync( frame, syncData ); }
|
||||||
|
|
||||||
|
public void Receive( Action<int, byte[]> packetFn )
|
||||||
|
{
|
||||||
|
inner.Receive( ( client, data ) =>
|
||||||
|
{
|
||||||
|
writer.Write( client );
|
||||||
|
writer.Write( data.Length );
|
||||||
|
writer.Write( data );
|
||||||
|
packetFn( client, data );
|
||||||
|
} );
|
||||||
|
}
|
||||||
|
|
||||||
|
bool disposed;
|
||||||
|
|
||||||
|
public void Dispose()
|
||||||
|
{
|
||||||
|
if( disposed )
|
||||||
|
return;
|
||||||
|
|
||||||
|
writer.Close();
|
||||||
|
inner.Dispose();
|
||||||
|
disposed = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
~ReplayRecorderConnection()
|
||||||
|
{
|
||||||
|
Dispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -59,7 +59,6 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Reference Include="System" />
|
<Reference Include="System" />
|
||||||
<Reference Include="System.Core">
|
<Reference Include="System.Core">
|
||||||
<RequiredTargetFramework>3.5</RequiredTargetFramework>
|
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="System.Data" />
|
<Reference Include="System.Data" />
|
||||||
<Reference Include="System.Drawing" />
|
<Reference Include="System.Drawing" />
|
||||||
@@ -206,6 +205,7 @@
|
|||||||
<Compile Include="Widgets\WorldInteractionControllerWidget.cs" />
|
<Compile Include="Widgets\WorldInteractionControllerWidget.cs" />
|
||||||
<Compile Include="World.cs" />
|
<Compile Include="World.cs" />
|
||||||
<Compile Include="WorldUtils.cs" />
|
<Compile Include="WorldUtils.cs" />
|
||||||
|
<Compile Include="Network\ReplayRecorderConnection.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\OpenRA.FileFormats\OpenRA.FileFormats.csproj">
|
<ProjectReference Include="..\OpenRA.FileFormats\OpenRA.FileFormats.csproj">
|
||||||
|
|||||||
Reference in New Issue
Block a user