diff --git a/OpenRA.Game/Game.cs b/OpenRA.Game/Game.cs index 8f33d9500e..59623b873b 100755 --- a/OpenRA.Game/Game.cs +++ b/OpenRA.Game/Game.cs @@ -455,5 +455,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; + } + } } } diff --git a/OpenRA.Game/GameRules/Settings.cs b/OpenRA.Game/GameRules/Settings.cs index aa2e97cec1..b9c4b7ccd5 100644 --- a/OpenRA.Game/GameRules/Settings.cs +++ b/OpenRA.Game/GameRules/Settings.cs @@ -118,6 +118,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 diff --git a/OpenRA.Game/Network/GameServer.cs b/OpenRA.Game/Network/GameServer.cs index 83e4945078..d77f44c76f 100644 --- a/OpenRA.Game/Network/GameServer.cs +++ b/OpenRA.Game/Network/GameServer.cs @@ -54,7 +54,8 @@ namespace OpenRA.Network // Don't have the map locally if (!Game.modData.AvailableMaps.ContainsKey(Map)) - return false; + if (!Game.Settings.Game.AllowDownloading) + return false; return CompatibleVersion(); } diff --git a/OpenRA.Game/Network/UnitOrders.cs b/OpenRA.Game/Network/UnitOrders.cs index e1db2476f1..a342ab16e6 100755 --- a/OpenRA.Game/Network/UnitOrders.cs +++ b/OpenRA.Game/Network/UnitOrders.cs @@ -118,7 +118,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)) - throw new InvalidOperationException("Missing map {0}".F(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() { diff --git a/OpenRA.Mods.RA/Widgets/Logic/LobbyLogic.cs b/OpenRA.Mods.RA/Widgets/Logic/LobbyLogic.cs index 9f2aaf3acc..3ce7fbf326 100644 --- a/OpenRA.Mods.RA/Widgets/Logic/LobbyLogic.cs +++ b/OpenRA.Mods.RA/Widgets/Logic/LobbyLogic.cs @@ -313,10 +313,17 @@ namespace OpenRA.Mods.RA.Widgets.Logic Sound.PlayNotification(null, "Sounds", "ChatLine", null); } - void UpdateCurrentMap() + 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); + 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("TITLE");