diff --git a/OpenRA.Game/Network/Replay.cs b/OpenRA.Game/Network/Replay.cs
new file mode 100644
index 0000000000..87b93204e6
--- /dev/null
+++ b/OpenRA.Game/Network/Replay.cs
@@ -0,0 +1,68 @@
+#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 OpenRA.Network;
+
+namespace OpenRA.Network
+{
+ /* a maze of twisty little hacks,... */
+ public class Replay
+ {
+ public readonly string Filename;
+ public readonly int Duration;
+ public readonly Session LobbyInfo;
+
+ 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;
+ LobbyInfo = lobbyInfo;
+ }
+
+ public Map Map()
+ {
+ if (LobbyInfo == null)
+ return null;
+
+ var map = LobbyInfo.GlobalSettings.Map;
+ if (!Game.modData.AvailableMaps.ContainsKey(map))
+ return null;
+
+ return Game.modData.AvailableMaps[map];
+ }
+ }
+}
+
diff --git a/OpenRA.Game/OpenRA.Game.csproj b/OpenRA.Game/OpenRA.Game.csproj
index 865b5e0642..6b97904528 100755
--- a/OpenRA.Game/OpenRA.Game.csproj
+++ b/OpenRA.Game/OpenRA.Game.csproj
@@ -204,6 +204,7 @@
+
diff --git a/OpenRA.Mods.Cnc/Widgets/Logic/CncReplayBrowserLogic.cs b/OpenRA.Mods.Cnc/Widgets/Logic/CncReplayBrowserLogic.cs
index a1c4b1db7e..2977f84951 100644
--- a/OpenRA.Mods.Cnc/Widgets/Logic/CncReplayBrowserLogic.cs
+++ b/OpenRA.Mods.Cnc/Widgets/Logic/CncReplayBrowserLogic.cs
@@ -11,7 +11,7 @@
using System;
using System.IO;
using System.Linq;
-using OpenRA.Mods.RA.Widgets.Logic;
+using OpenRA.Network;
using OpenRA.Widgets;
namespace OpenRA.Mods.Cnc.Widgets.Logic
@@ -59,7 +59,7 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
panel.GetWidget("REPLAY_INFO").IsVisible = () => currentSummary != null;
}
- ReplaySummary currentSummary;
+ Replay currentSummary;
Map currentMap;
void SelectReplay(string filename)
@@ -69,7 +69,7 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
try
{
- currentSummary = new ReplaySummary(filename);
+ currentSummary = new Replay(filename);
currentMap = currentSummary.Map();
panel.GetWidget("DURATION").GetText =
diff --git a/OpenRA.Mods.RA/Widgets/Logic/ReplayBrowserLogic.cs b/OpenRA.Mods.RA/Widgets/Logic/ReplayBrowserLogic.cs
index 6530f8b22e..414219a0da 100644
--- a/OpenRA.Mods.RA/Widgets/Logic/ReplayBrowserLogic.cs
+++ b/OpenRA.Mods.RA/Widgets/Logic/ReplayBrowserLogic.cs
@@ -9,10 +9,8 @@
#endregion
using System;
-using System.Drawing;
using System.IO;
using System.Linq;
-using OpenRA.FileFormats;
using OpenRA.Network;
using OpenRA.Widgets;
@@ -64,7 +62,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
{
try
{
- var summary = new ReplaySummary(currentReplay);
+ var summary = new Replay(currentReplay);
var mapStub = summary.Map();
widget.GetWidget("DURATION").GetText =
@@ -85,63 +83,11 @@ namespace OpenRA.Mods.RA.Widgets.Logic
void AddReplay(ScrollPanelWidget list, string filename, ScrollItemWidget template)
{
var item = ScrollItemWidget.Setup(template,
- () => CurrentReplay == filename,
- () => CurrentReplay = filename);
+ () => CurrentReplay == filename,
+ () => CurrentReplay = filename);
var f = Path.GetFileName(filename);
item.GetWidget("TITLE").GetText = () => f;
list.AddChild(item);
}
}
-
- /* a maze of twisty little hacks,... */
- public class ReplaySummary
- {
- public readonly string Filename;
- public readonly int Duration;
- public readonly Session LobbyInfo;
-
- public ReplaySummary(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;
- LobbyInfo = lobbyInfo;
- }
-
- public Map Map()
- {
- if (LobbyInfo == null)
- return null;
-
- var map = LobbyInfo.GlobalSettings.Map;
- if (!Game.modData.AvailableMaps.ContainsKey(map))
- return null;
-
- return Game.modData.AvailableMaps[map];
- }
- }
}