From 586723926a7405b004b61f04fcf0525645fa92b5 Mon Sep 17 00:00:00 2001 From: Igor Popov Date: Sat, 23 Mar 2013 19:27:53 +0400 Subject: [PATCH 1/3] auto-map-downloading updated. (sync) --- OpenRA.Game/Game.cs | 24 ++++++++++++++++++++++ OpenRA.Game/GameRules/Settings.cs | 2 ++ OpenRA.Game/Network/GameServer.cs | 3 ++- OpenRA.Game/Network/UnitOrders.cs | 7 ++++++- OpenRA.Mods.RA/Widgets/Logic/LobbyLogic.cs | 11 ++++++++-- 5 files changed, 43 insertions(+), 4 deletions(-) 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"); From 1005c0bc08129a3e14ad4aabf12d251b809c2c22 Mon Sep 17 00:00:00 2001 From: Igor Popov Date: Sat, 23 Mar 2013 19:29:52 +0400 Subject: [PATCH 2/3] auto-map-downloading --- OpenRA.Mods.RA/Widgets/Logic/LobbyLogic.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OpenRA.Mods.RA/Widgets/Logic/LobbyLogic.cs b/OpenRA.Mods.RA/Widgets/Logic/LobbyLogic.cs index 3ce7fbf326..04ce580b5c 100644 --- a/OpenRA.Mods.RA/Widgets/Logic/LobbyLogic.cs +++ b/OpenRA.Mods.RA/Widgets/Logic/LobbyLogic.cs @@ -313,7 +313,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic Sound.PlayNotification(null, "Sounds", "ChatLine", null); } - void UpdateCurrentMap () + void UpdateCurrentMap() { if (MapUid == orderManager.LobbyInfo.GlobalSettings.Map) return; From 10ec82d1bb07c6f221c0fcc2033182b726f335f2 Mon Sep 17 00:00:00 2001 From: Igor Popov Date: Sat, 23 Mar 2013 19:46:41 +0400 Subject: [PATCH 3/3] give user info that new map has been downloaded (being in lobby). so he is not confused with the reason of black screen --- OpenRA.Mods.RA/Widgets/Logic/LobbyLogic.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/OpenRA.Mods.RA/Widgets/Logic/LobbyLogic.cs b/OpenRA.Mods.RA/Widgets/Logic/LobbyLogic.cs index 04ce580b5c..b286a304b3 100644 --- a/OpenRA.Mods.RA/Widgets/Logic/LobbyLogic.cs +++ b/OpenRA.Mods.RA/Widgets/Logic/LobbyLogic.cs @@ -321,7 +321,10 @@ namespace OpenRA.Mods.RA.Widgets.Logic 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);