change ReplaySummary to Replay; move to OpenRA.Network
This commit is contained in:
68
OpenRA.Game/Network/Replay.cs
Normal file
68
OpenRA.Game/Network/Replay.cs
Normal file
@@ -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];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -204,6 +204,7 @@
|
||||
<Compile Include="Widgets\ScrollItemWidget.cs" />
|
||||
<Compile Include="Widgets\ListLayout.cs" />
|
||||
<Compile Include="Widgets\GridLayout.cs" />
|
||||
<Compile Include="Network\Replay.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\OpenRA.FileFormats\OpenRA.FileFormats.csproj">
|
||||
|
||||
@@ -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<LabelWidget>("DURATION").GetText =
|
||||
|
||||
@@ -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<LabelWidget>("DURATION").GetText =
|
||||
@@ -92,56 +90,4 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
||||
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];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user