Remove map download support.

This commit is contained in:
Paul Chote
2014-03-13 11:58:32 +13:00
parent c5ba8548c4
commit f5f84244eb
3 changed files with 14 additions and 61 deletions

View File

@@ -531,46 +531,5 @@ namespace OpenRA
{ {
return orderManager != null && orderManager.world == world; return orderManager != null && orderManager.world == world;
} }
public static bool DownloadMap(string mapHash)
{
var mod = Game.modData.Manifest.Mod;
var dirPath = new[] { Platform.SupportDir, "maps", mod.Id }.Aggregate(Path.Combine);
var tempFile = Path.Combine(dirPath, Path.GetRandomFileName());
if (!Directory.Exists(dirPath))
Directory.CreateDirectory(dirPath);
foreach (var MapRepository in Game.Settings.Game.MapRepositories)
{
try
{
var url = MapRepository + mapHash;
var request = WebRequest.Create(url);
request.Method = "HEAD";
var res = request.GetResponse();
if (res.Headers["Content-Disposition"] == null)
continue;
var mapPath = Path.Combine(dirPath, res.Headers ["Content-Disposition"].Replace("attachment; filename = ", ""));
Log.Write("debug", "Trying to download map to '{0}' using {1}", mapPath, MapRepository);
WebClient webClient = new WebClient();
webClient.DownloadFile(url, tempFile);
File.Move(tempFile, mapPath);
Game.modData.MapCache[mapHash].UpdateFromMap(new Map(mapPath));
Log.Write("debug", "New map has been downloaded to '{0}'", mapPath);
return true;
}
catch (WebException e)
{
Log.Write("debug", "Could not download map '{0}' using {1}", mapHash, MapRepository);
Log.Write("debug", e.ToString());
File.Delete(tempFile);
continue;
}
}
return false;
}
} }
} }

View File

@@ -527,21 +527,14 @@ namespace OpenRA.Mods.RA.Widgets.Logic
return; return;
Map = Game.modData.MapCache[uid]; Map = Game.modData.MapCache[uid];
if (Map.Status != MapStatus.Available)
{
if (Game.Settings.Game.AllowDownloading)
{
Game.DownloadMap(uid);
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");
}
// Restore default starting cash if the last map set it to something invalid if (Map.Status == MapStatus.Available)
var pri = Rules.Info["player"].Traits.Get<PlayerResourcesInfo>(); {
if (!Map.Map.Options.StartingCash.HasValue && !pri.SelectableCash.Contains(orderManager.LobbyInfo.GlobalSettings.StartingCash)) // Restore default starting cash if the last map set it to something invalid
orderManager.IssueOrder(Order.Command("startingcash {0}".F(pri.DefaultCash))); var pri = Rules.Info["player"].Traits.Get<PlayerResourcesInfo>();
if (!Map.Map.Options.StartingCash.HasValue && !pri.SelectableCash.Contains(orderManager.LobbyInfo.GlobalSettings.StartingCash))
orderManager.IssueOrder(Order.Command("startingcash {0}".F(pri.DefaultCash)));
}
} }
void UpdatePlayerList() void UpdatePlayerList()
@@ -590,8 +583,8 @@ namespace OpenRA.Mods.RA.Widgets.Logic
LobbyUtils.SetupEditableColorWidget(template, slot, client, orderManager, colorPreview); LobbyUtils.SetupEditableColorWidget(template, slot, client, orderManager, colorPreview);
LobbyUtils.SetupEditableFactionWidget(template, slot, client, orderManager, countryNames); LobbyUtils.SetupEditableFactionWidget(template, slot, client, orderManager, countryNames);
LobbyUtils.SetupEditableTeamWidget(template, slot, client, orderManager, Map.SpawnPoints.Count); LobbyUtils.SetupEditableTeamWidget(template, slot, client, orderManager, Map);
LobbyUtils.SetupEditableReadyWidget(template, slot, client, orderManager); LobbyUtils.SetupEditableReadyWidget(template, slot, client, orderManager, Map);
} }
else else
{ {

View File

@@ -363,11 +363,11 @@ namespace OpenRA.Mods.RA.Widgets.Logic
factionflag.GetImageCollection = () => "flags"; factionflag.GetImageCollection = () => "flags";
} }
public static void SetupEditableTeamWidget(Widget parent, Session.Slot s, Session.Client c, OrderManager orderManager, int teamCount) public static void SetupEditableTeamWidget(Widget parent, Session.Slot s, Session.Client c, OrderManager orderManager, MapPreview map)
{ {
var dropdown = parent.Get<DropDownButtonWidget>("TEAM"); var dropdown = parent.Get<DropDownButtonWidget>("TEAM");
dropdown.IsDisabled = () => s.LockTeam || orderManager.LocalClient.IsReady; dropdown.IsDisabled = () => s.LockTeam || orderManager.LocalClient.IsReady;
dropdown.OnMouseDown = _ => ShowTeamDropDown(dropdown, c, orderManager, teamCount); dropdown.OnMouseDown = _ => ShowTeamDropDown(dropdown, c, orderManager, map.PlayerCount);
dropdown.GetText = () => (c.Team == 0) ? "-" : c.Team.ToString(); dropdown.GetText = () => (c.Team == 0) ? "-" : c.Team.ToString();
} }
@@ -376,12 +376,13 @@ namespace OpenRA.Mods.RA.Widgets.Logic
parent.Get<LabelWidget>("TEAM").GetText = () => (c.Team == 0) ? "-" : c.Team.ToString(); parent.Get<LabelWidget>("TEAM").GetText = () => (c.Team == 0) ? "-" : c.Team.ToString();
} }
public static void SetupEditableReadyWidget(Widget parent, Session.Slot s, Session.Client c, OrderManager orderManager) public static void SetupEditableReadyWidget(Widget parent, Session.Slot s, Session.Client c, OrderManager orderManager, MapPreview map)
{ {
var status = parent.Get<CheckboxWidget>("STATUS_CHECKBOX"); var status = parent.Get<CheckboxWidget>("STATUS_CHECKBOX");
status.IsChecked = () => orderManager.LocalClient.IsReady || c.Bot != null; status.IsChecked = () => orderManager.LocalClient.IsReady || c.Bot != null;
status.IsVisible = () => true; status.IsVisible = () => true;
status.IsDisabled = () => c.Bot != null; status.IsDisabled = () => c.Bot != null || map.Status != MapStatus.Available;
status.OnClick = () => orderManager.IssueOrder(Order.Command("ready")); status.OnClick = () => orderManager.IssueOrder(Order.Command("ready"));
} }