diff --git a/OpenRA.Game/Chrome.cs b/OpenRA.Game/Chrome.cs
index 3815d52f55..a4c0b0a7a9 100644
--- a/OpenRA.Game/Chrome.cs
+++ b/OpenRA.Game/Chrome.cs
@@ -152,8 +152,6 @@ namespace OpenRA
public void Draw( World world )
{
- DrawDownloadBar();
-
chromeCollection = "chrome-" + world.LocalPlayer.Country.Race;
radarCollection = "radar-" + world.LocalPlayer.Country.Race;
paletteCollection = "palette-" + world.LocalPlayer.Country.Race;
@@ -175,36 +173,6 @@ namespace OpenRA
DrawChat();
}
- public void DrawDownloadBar()
- {
- if (PackageDownloader.IsIdle())
- return;
-
- var r = new Rectangle((Game.viewport.Width - 400) / 2, Game.viewport.Height - 110, 400, 100);
- DrawDialogBackground(r, "dialog");
-
- DrawCentered("Downloading: {0} (+{1} more)".F(
- PackageDownloader.CurrentPackage.Split(':')[0],
- PackageDownloader.RemainingPackages),
- new int2( Game.viewport.Width /2, Game.viewport.Height - 90),
- Color.White);
-
- DrawDialogBackground(new Rectangle(r.Left + 30, r.Top + 50, r.Width - 60, 20),
- "dialog2");
-
- var x1 = r.Left + 35;
- var x2 = r.Right - 35;
- var x = float2.Lerp(x1, x2, PackageDownloader.Fraction);
-
- for (var y = r.Top + 55; y < r.Top + 65; y++)
- lineRenderer.DrawLine(
- new float2(x1, y) + Game.viewport.Location,
- new float2(x, y) + Game.viewport.Location,
- Color.White, Color.White);
-
- lineRenderer.Flush();
- }
-
public void DrawDialog(string text)
{
DrawDialog(text, null, _ => { }, null, _ => { });
@@ -416,7 +384,6 @@ namespace OpenRA
public void DrawLobby()
{
buttons.Clear();
- DrawDownloadBar();
if (showMapChooser)
{
diff --git a/OpenRA.Game/Game.cs b/OpenRA.Game/Game.cs
index c6dfe0a37f..6dfa10385a 100644
--- a/OpenRA.Game/Game.cs
+++ b/OpenRA.Game/Game.cs
@@ -231,7 +231,7 @@ namespace OpenRA
public static void Tick()
{
- if (packageChangePending && PackageDownloader.IsIdle())
+ if (packageChangePending)
{
// TODO: Only do this on mod change
Timer.Time("----begin maplist");
@@ -241,7 +241,7 @@ namespace OpenRA
return;
}
- if (mapChangePending && PackageDownloader.IsIdle())
+ if (mapChangePending)
{
ChangeMap(LobbyInfo.GlobalSettings.Map);
return;
@@ -331,9 +331,6 @@ namespace OpenRA
Debug("Order lag is now {0} frames.".F(LobbyInfo.GlobalSettings.OrderLatency));
}
- if (PackageDownloader.SetPackageList(LobbyInfo.GlobalSettings.Packages))
- packageChangePending = true;
-
if (mapName != LobbyInfo.GlobalSettings.Map)
mapChangePending = true;
diff --git a/OpenRA.Game/Network/UnitOrders.cs b/OpenRA.Game/Network/UnitOrders.cs
index 0d3dd77b18..9d02b54ff8 100755
--- a/OpenRA.Game/Network/UnitOrders.cs
+++ b/OpenRA.Game/Network/UnitOrders.cs
@@ -48,12 +48,6 @@ namespace OpenRA.Network
Game.SyncLobbyInfo(order.TargetString);
break;
}
- case "FileChunk":
- {
- PackageDownloader.ReceiveChunk(order.TargetString);
- break;
- }
-
default:
{
if( !order.IsImmediate )
diff --git a/OpenRA.Game/OpenRA.Game.csproj b/OpenRA.Game/OpenRA.Game.csproj
index 2527adadc5..fbe5be43b1 100755
--- a/OpenRA.Game/OpenRA.Game.csproj
+++ b/OpenRA.Game/OpenRA.Game.csproj
@@ -117,7 +117,6 @@
-
diff --git a/OpenRA.Game/PackageDownloader.cs b/OpenRA.Game/PackageDownloader.cs
deleted file mode 100644
index 572f20b33d..0000000000
--- a/OpenRA.Game/PackageDownloader.cs
+++ /dev/null
@@ -1,144 +0,0 @@
-#region Copyright & License Information
-/*
- * Copyright 2007,2009,2010 Chris Forbes, Robert Pepperell, Matthew Bowra-Dean, Paul Chote, Alli Witheford.
- * This file is part of OpenRA.
- *
- * OpenRA is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * OpenRA is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with OpenRA. If not, see .
- */
-#endregion
-
-using System;
-using System.Collections.Generic;
-using System.Drawing;
-using System.IO;
-using System.Linq;
-using System.Security.Cryptography;
-using OpenRA.FileFormats;
-
-namespace OpenRA
-{
- static class PackageDownloader
- {
- static string[] allPackages = { };
- static List missingPackages = new List();
- static string currentPackage = null;
- static MemoryStream content = null;
-
- public static string CurrentPackage { get { return currentPackage; } }
- public static int RemainingPackages { get { return missingPackages.Count; } }
- public static float Fraction { get; private set; }
- public static int DownloadedBytes { get { return (int)content.Length; } }
-
- public static bool SetPackageList(string[] packages)
- {
- if (!(allPackages.Except(packages).Any()
- || packages.Except(allPackages).Any()))
- return false;
-
- allPackages = packages;
- missingPackages = allPackages.Where(p => !HavePackage(p)).ToList();
-
- if (currentPackage == null || !missingPackages.Contains(currentPackage))
- BeginDownload();
- else
- missingPackages.Remove(currentPackage);
-
- return true;
- }
-
- class Chunk { public int Index = 0; public int Count = 0; public string Data = ""; }
-
- public static void ReceiveChunk(string data)
- {
- var c = new Chunk();
- FieldLoader.Load(c, new MiniYaml(null, MiniYaml.FromString(data)));
- var bytes = Convert.FromBase64String(c.Data);
- content.Write(bytes, 0, bytes.Length);
-
- Fraction = (float)c.Index / c.Count;
-
- if (c.Index == c.Count - 1)
- EndDownload();
- }
-
- static void BeginDownload()
- {
- if (missingPackages.Count == 0) // we're finished downloading resources!
- {
- currentPackage = null;
- return;
- }
-
- currentPackage = missingPackages[0];
- missingPackages.RemoveAt(0);
-
- content = new MemoryStream();
-
- Game.Debug("Requesting package: {0}".F(currentPackage));
-
- Game.IssueOrder(
- new Order("RequestFile", null, currentPackage) { IsImmediate = true });
-
- Fraction = 0f;
- }
-
- static void EndDownload()
- {
- // commit this data to disk
- var parts = currentPackage.Split(':');
- File.WriteAllBytes(parts[0], content.ToArray());
-
- if (CalculateSHA1(parts[0]) != parts[1])
- throw new InvalidOperationException("Broken download");
-
- Game.Debug("Finished receiving package: {0}".F(currentPackage));
-
- currentPackage = null;
-
- BeginDownload();
- }
-
- public static bool IsIdle()
- {
- return currentPackage == null
- && missingPackages.Count == 0;
- }
-
- static bool HavePackage(string p)
- {
- var parts = p.Split(':');
- if (!File.Exists(parts[0]))
- {
- Game.Debug("Missing package: {0}".F(p));
- return false;
- }
-
- if (CalculateSHA1(parts[0]) != parts[1])
- {
- Game.Debug("Bad SHA1 for package; redownloading: {0}".F(p));
- return false;
- }
-
- Game.Debug("Verified package: {0}".F(p));
- return true;
- }
-
- public static string CalculateSHA1(string filename)
- {
- using (var csp = SHA1.Create())
- return new string(csp.ComputeHash(File.ReadAllBytes(filename))
- .SelectMany(a => a.ToString("x2")).ToArray());
- }
- }
-}
diff --git a/OpenRA.Game/Server/Connection.cs b/OpenRA.Game/Server/Connection.cs
index 760fe59e55..ce27ec74e2 100644
--- a/OpenRA.Game/Server/Connection.cs
+++ b/OpenRA.Game/Server/Connection.cs
@@ -39,12 +39,6 @@ namespace OpenRA.Server
/* client data */
public int PlayerIndex;
- /* file server state */
- public int NextChunk = 0;
- public int NumChunks = 0;
- public int RemainingBytes = 0;
- public Stream Stream = null;
-
public byte[] PopBytes(int n)
{
var result = data.GetRange(0, n);
diff --git a/OpenRA.Game/Server/Server.cs b/OpenRA.Game/Server/Server.cs
index 248d2aec08..b4bbbd7c7a 100644
--- a/OpenRA.Game/Server/Server.cs
+++ b/OpenRA.Game/Server/Server.cs
@@ -92,18 +92,13 @@ namespace OpenRA.Server
checkRead.Add( listener.Server );
foreach( var c in conns ) checkRead.Add( c.socket );
- var isSendingPackages = conns.Any( c => c.Stream != null );
-
/* msdn lies, -1 doesnt work. this is ~1h instead. */
- Socket.Select( checkRead, null, null, isSendingPackages ? DownloadChunkInterval : MasterPingInterval * 1000000 );
+ Socket.Select( checkRead, null, null, MasterPingInterval * 1000000 );
foreach( Socket s in checkRead )
if( s == listener.Server ) AcceptConnection();
else conns.Single( c => c.socket == s ).ReadData();
- foreach( var c in conns.Where( a => a.Stream != null ).ToArray() )
- SendNextChunk( c );
-
if (Environment.TickCount - lastPing > MasterPingInterval * 1000)
PingMasterServer();
}
@@ -185,40 +180,6 @@ namespace OpenRA.Server
}
}
- class Chunk { public int Index = 0; public int Count = 0; public string Data = ""; }
-
- static void SendNextChunk(Connection c)
- {
- try
- {
- var data = c.Stream.Read(Math.Min(DownloadChunkSize, c.RemainingBytes));
- if (data.Length != 0)
- {
- var chunk = new Chunk
- {
- Index = c.NextChunk++,
- Count = c.NumChunks,
- Data = Convert.ToBase64String(data)
- };
-
- DispatchOrdersToClient(c, 0, 0,
- new ServerOrder("FileChunk",
- FieldSaver.Save(chunk).Nodes.WriteToString()).Serialize());
- }
-
- c.RemainingBytes -= data.Length;
- if (c.RemainingBytes == 0)
- {
- GetClient(c).State = Session.ClientState.NotReady;
- c.Stream.Dispose();
- c.Stream = null;
-
- SyncLobbyInfo();
- }
- }
- catch (Exception e) { DropClient(c, e); }
- }
-
static void DispatchOrdersToClient(Connection c, int client, int frame, byte[] data)
{
try
@@ -514,29 +475,6 @@ namespace OpenRA.Server
foreach (var c in conns.Except(conn).ToArray())
DispatchOrdersToClient(c, GetClient(conn).Index, 0, so.Serialize());
break;
-
- case "RequestFile":
- {
- Console.WriteLine("** Requesting file: `{0}`", so.Data);
- var client = GetClient(conn);
- client.State = Session.ClientState.Downloading;
-
- var filename = so.Data.Split(':')[0];
-
- if (conn.Stream != null)
- conn.Stream.Dispose();
-
- conn.Stream = File.OpenRead(filename);
- // todo: validate that the SHA1 they asked for matches what we've got.
-
- var length = (int) new FileInfo(filename).Length;
- conn.NextChunk = 0;
- conn.NumChunks = (length + DownloadChunkSize - 1) / DownloadChunkSize;
- conn.RemainingBytes = length;
-
- SyncLobbyInfo();
- }
- break;
}
}