Merge pull request #5353 from pchote/map-validation

Disable maps with invalid rules
This commit is contained in:
Matthias Mailänder
2014-05-22 09:55:06 +02:00
13 changed files with 180 additions and 34 deletions

View File

@@ -42,16 +42,19 @@ namespace OpenRA
public void LoadMaps()
{
var paths = modData.Manifest.MapFolders.SelectMany(f => FindMapsIn(f));
foreach (var path in paths)
// Expand the dictionary (dir path, dir type) to a dictionary of (map path, dir type)
var mapPaths = modData.Manifest.MapFolders.SelectMany(kv =>
FindMapsIn(kv.Key).ToDictionary(p => p, p => string.IsNullOrEmpty(kv.Value) ? MapClassification.Unknown : Enum<MapClassification>.Parse(kv.Value)));
foreach (var path in mapPaths)
{
try
{
using (new Support.PerfTimer(path))
using (new Support.PerfTimer(path.Key))
{
var map = new Map(path, modData.Manifest.Mod.Id);
var map = new Map(path.Key, modData.Manifest.Mod.Id);
if (modData.Manifest.MapCompatibility.Contains(map.RequiresMod))
previews[map.Uid].UpdateFromMap(map);
previews[map.Uid].UpdateFromMap(map, path.Value);
}
}
catch (Exception e)

View File

@@ -24,6 +24,12 @@ namespace OpenRA
{
public enum MapStatus { Available, Unavailable, Searching, DownloadAvailable, Downloading, DownloadError }
// Used for grouping maps in the UI
public enum MapClassification { Unknown, System, User, Remote }
// Used for verifying map availability in the lobby
public enum MapRuleStatus { Unknown, Cached, Invalid }
// Fields names must match the with the remote API
public class RemoteMapData
{
@@ -53,6 +59,9 @@ namespace OpenRA
public Bitmap CustomPreview { get; private set; }
public Map Map { get; private set; }
public MapStatus Status { get; private set; }
public MapClassification Class { get; private set; }
public MapRuleStatus RuleStatus { get; private set; }
Download download;
public long DownloadBytes { get; private set; }
@@ -94,9 +103,10 @@ namespace OpenRA
Bounds = Rectangle.Empty;
SpawnPoints = NoSpawns;
Status = MapStatus.Unavailable;
Class = MapClassification.Unknown;
}
public void UpdateFromMap(Map m)
public void UpdateFromMap(Map m, MapClassification classification)
{
Map = m;
Title = m.Title;
@@ -108,6 +118,7 @@ namespace OpenRA
SpawnPoints = m.GetSpawnPoints().ToList();
CustomPreview = m.CustomPreview;
Status = MapStatus.Available;
Class = classification;
}
public void UpdateRemoteSearch(MapStatus status, MiniYaml yaml)
@@ -146,8 +157,9 @@ namespace OpenRA
if (CustomPreview != null)
cache.CacheMinimap(this);
}
Status = status;
Status = status;
Class = MapClassification.Remote;
});
}
@@ -199,7 +211,7 @@ namespace OpenRA
}
Log.Write("debug", "Downloaded map to '{0}'", mapPath);
Game.RunAfterTick(() => UpdateFromMap(new Map(mapPath)));
Game.RunAfterTick(() => UpdateFromMap(new Map(mapPath), MapClassification.User));
};
download = new Download(mapUrl, mapPath, onDownloadProgress, onDownloadComplete);
@@ -220,5 +232,22 @@ namespace OpenRA
download.Cancel();
download = null;
}
public void CacheRules()
{
if (RuleStatus != MapRuleStatus.Unknown)
return;
try
{
Map.PreloadRules();
RuleStatus = MapRuleStatus.Cached;
}
catch (Exception e)
{
Log.Write("debug", "Map {0} failed validation with an exception:\n{1}", Uid, e.Message);
RuleStatus = MapRuleStatus.Invalid;
}
}
}
}