Merge pull request #2823 from ihptru/auto-map-dl

Auto map downloading
This commit is contained in:
Matthias Mailänder
2013-04-01 09:11:25 -07:00
5 changed files with 45 additions and 3 deletions

View File

@@ -458,5 +458,29 @@ namespace OpenRA
Game.JoinServer(host, port);
}
public static bool DownloadMap(string mapHash)
{
try
{
var mod = Game.CurrentMods.FirstOrDefault().Value.Id;
var dirPath = "{1}maps{0}{2}".F(Path.DirectorySeparatorChar, Platform.SupportDir, mod);
if(!Directory.Exists(dirPath))
Directory.CreateDirectory(dirPath);
var mapPath = "{1}{0}{2}".F(Path.DirectorySeparatorChar, dirPath, mapHash+".oramap");
Console.Write("Trying to download map to {0} ... ".F(mapPath));
WebClient webClient = new WebClient();
webClient.DownloadFile(Game.Settings.Game.MapRepository + mapHash, mapPath);
Game.modData.AvailableMaps.Add(mapHash, new Map(mapPath));
Console.WriteLine("done");
return true;
}
catch (WebException e)
{
Log.Write("debug", "Could not download map '{0}'", mapHash);
Log.Write("debug", e.ToString());
return false;
}
}
}
}

View File

@@ -123,6 +123,8 @@ namespace OpenRA.GameRules
public int Timestep = 40;
public string ConnectTo = "";
public bool AllowDownloading = true;
public string MapRepository = "http://content.open-ra.org/map/";
}
public class KeySettings

View File

@@ -54,6 +54,7 @@ namespace OpenRA.Network
// Don't have the map locally
if (!Game.modData.AvailableMaps.ContainsKey(Map))
if (!Game.Settings.Game.AllowDownloading)
return false;
return CompatibleVersion();

View File

@@ -119,7 +119,12 @@ namespace OpenRA.Network
throw new InvalidOperationException("Server's mod ({0}) and yours ({1}) don't match".F(localMods.FirstOrDefault().ToString().Split('@')[0], request.Mods.FirstOrDefault().ToString().Split('@')[0]));
// Check that the map exists on the client
if (!Game.modData.AvailableMaps.ContainsKey(request.Map))
{
if (Game.Settings.Game.AllowDownloading)
Game.DownloadMap(request.Map);
else
throw new InvalidOperationException("Missing map {0}".F(request.Map));
}
var info = new Session.Client()
{

View File

@@ -328,8 +328,18 @@ namespace OpenRA.Mods.RA.Widgets.Logic
void UpdateCurrentMap()
{
if (MapUid == orderManager.LobbyInfo.GlobalSettings.Map) return;
if (MapUid == orderManager.LobbyInfo.GlobalSettings.Map)
return;
MapUid = orderManager.LobbyInfo.GlobalSettings.Map;
if (!Game.modData.AvailableMaps.ContainsKey (MapUid))
if (Game.Settings.Game.AllowDownloading)
{
Game.DownloadMap (MapUid);
Game.Debug("A new map has been downloaded...");
}
else
throw new InvalidOperationException("Server's new map doesn't exist on your system and Downloading turned off");
Map = new Map(Game.modData.AvailableMaps[MapUid].Path);
var title = Ui.Root.Get<LabelWidget>("TITLE");