Merge pull request #10304 from whinis/ReplayReworkPR
Reworking ReplayRecorderConnection to be not be a Connection
This commit is contained in:
@@ -52,9 +52,9 @@ namespace OpenRA
|
|||||||
|
|
||||||
public static OrderManager JoinServer(string host, int port, string password, bool recordReplay = true)
|
public static OrderManager JoinServer(string host, int port, string password, bool recordReplay = true)
|
||||||
{
|
{
|
||||||
IConnection connection = new NetworkConnection(host, port);
|
var connection = new NetworkConnection(host, port);
|
||||||
if (recordReplay)
|
if (recordReplay)
|
||||||
connection = new ReplayRecorderConnection(connection, TimestampedFilename);
|
connection.StartRecording(TimestampedFilename);
|
||||||
|
|
||||||
var om = new OrderManager(host, port, password, connection);
|
var om = new OrderManager(host, port, password, connection);
|
||||||
JoinInner(om);
|
JoinInner(om);
|
||||||
|
|||||||
@@ -44,6 +44,7 @@ namespace OpenRA.Network
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected List<ReceivedPacket> receivedPackets = new List<ReceivedPacket>();
|
protected List<ReceivedPacket> receivedPackets = new List<ReceivedPacket>();
|
||||||
|
public ReplayRecorder Recorder { get; private set; }
|
||||||
|
|
||||||
public virtual int LocalClientId
|
public virtual int LocalClientId
|
||||||
{
|
{
|
||||||
@@ -99,10 +100,26 @@ namespace OpenRA.Network
|
|||||||
}
|
}
|
||||||
|
|
||||||
foreach (var p in packets)
|
foreach (var p in packets)
|
||||||
|
{
|
||||||
packetFn(p.FromClient, p.Data);
|
packetFn(p.FromClient, p.Data);
|
||||||
|
if (Recorder != null)
|
||||||
|
Recorder.Receive(p.FromClient, p.Data);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected virtual void Dispose(bool disposing) { }
|
public void StartRecording(Func<string> chooseFilename)
|
||||||
|
{
|
||||||
|
// If we have a previous recording then save/dispose it and start a new one.
|
||||||
|
if (Recorder != null)
|
||||||
|
Recorder.Dispose();
|
||||||
|
Recorder = new ReplayRecorder(chooseFilename);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected virtual void Dispose(bool disposing)
|
||||||
|
{
|
||||||
|
if (disposing && Recorder != null)
|
||||||
|
Recorder.Dispose();
|
||||||
|
}
|
||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -16,11 +16,9 @@ using OpenRA.FileFormats;
|
|||||||
|
|
||||||
namespace OpenRA.Network
|
namespace OpenRA.Network
|
||||||
{
|
{
|
||||||
sealed class ReplayRecorderConnection : IConnection
|
sealed class ReplayRecorder
|
||||||
{
|
{
|
||||||
public ReplayMetadata Metadata;
|
public ReplayMetadata Metadata;
|
||||||
|
|
||||||
IConnection inner;
|
|
||||||
BinaryWriter writer;
|
BinaryWriter writer;
|
||||||
Func<string> chooseFilename;
|
Func<string> chooseFilename;
|
||||||
MemoryStream preStartBuffer = new MemoryStream();
|
MemoryStream preStartBuffer = new MemoryStream();
|
||||||
@@ -36,10 +34,9 @@ namespace OpenRA.Network
|
|||||||
return frame == 0 && data.ToOrderList(null).Any(o => o.OrderString == "StartGame");
|
return frame == 0 && data.ToOrderList(null).Any(o => o.OrderString == "StartGame");
|
||||||
}
|
}
|
||||||
|
|
||||||
public ReplayRecorderConnection(IConnection inner, Func<string> chooseFilename)
|
public ReplayRecorder(Func<string> chooseFilename)
|
||||||
{
|
{
|
||||||
this.chooseFilename = chooseFilename;
|
this.chooseFilename = chooseFilename;
|
||||||
this.inner = inner;
|
|
||||||
|
|
||||||
writer = new BinaryWriter(preStartBuffer);
|
writer = new BinaryWriter(preStartBuffer);
|
||||||
}
|
}
|
||||||
@@ -70,16 +67,7 @@ namespace OpenRA.Network
|
|||||||
this.writer = new BinaryWriter(file);
|
this.writer = new BinaryWriter(file);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int LocalClientId { get { return inner.LocalClientId; } }
|
public void Receive(int clientID, byte[] data)
|
||||||
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) =>
|
|
||||||
{
|
{
|
||||||
if (preStartBuffer != null && IsGameStart(data))
|
if (preStartBuffer != null && IsGameStart(data))
|
||||||
{
|
{
|
||||||
@@ -89,11 +77,9 @@ namespace OpenRA.Network
|
|||||||
StartSavingReplay(preStartData);
|
StartSavingReplay(preStartData);
|
||||||
}
|
}
|
||||||
|
|
||||||
writer.Write(client);
|
writer.Write(clientID);
|
||||||
writer.Write(data.Length);
|
writer.Write(data.Length);
|
||||||
writer.Write(data);
|
writer.Write(data);
|
||||||
packetFn(client, data);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool disposed;
|
bool disposed;
|
||||||
@@ -114,7 +100,6 @@ namespace OpenRA.Network
|
|||||||
if (preStartBuffer != null)
|
if (preStartBuffer != null)
|
||||||
preStartBuffer.Dispose();
|
preStartBuffer.Dispose();
|
||||||
writer.Close();
|
writer.Close();
|
||||||
inner.Dispose();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -189,7 +189,7 @@
|
|||||||
<Compile Include="World.cs" />
|
<Compile Include="World.cs" />
|
||||||
<Compile Include="WorldUtils.cs" />
|
<Compile Include="WorldUtils.cs" />
|
||||||
<Compile Include="VoiceExts.cs" />
|
<Compile Include="VoiceExts.cs" />
|
||||||
<Compile Include="Network\ReplayRecorderConnection.cs" />
|
<Compile Include="Network\ReplayRecorder.cs" />
|
||||||
<Compile Include="Traits\DebugPauseState.cs" />
|
<Compile Include="Traits\DebugPauseState.cs" />
|
||||||
<Compile Include="Network\UPnP.cs" />
|
<Compile Include="Network\UPnP.cs" />
|
||||||
<Compile Include="Graphics\Renderable.cs" />
|
<Compile Include="Graphics\Renderable.cs" />
|
||||||
|
|||||||
@@ -213,7 +213,9 @@ namespace OpenRA
|
|||||||
foreach (var player in Players)
|
foreach (var player in Players)
|
||||||
gameInfo.AddPlayer(player, OrderManager.LobbyInfo);
|
gameInfo.AddPlayer(player, OrderManager.LobbyInfo);
|
||||||
|
|
||||||
var rc = OrderManager.Connection as ReplayRecorderConnection;
|
var echo = OrderManager.Connection as EchoConnection;
|
||||||
|
var rc = echo != null ? echo.Recorder : null;
|
||||||
|
|
||||||
if (rc != null)
|
if (rc != null)
|
||||||
rc.Metadata = new ReplayMetadata(gameInfo);
|
rc.Metadata = new ReplayMetadata(gameInfo);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user