Fix crash when master server query returns unexpected data.

This commit is contained in:
Paul Chote
2017-03-10 18:21:34 +00:00
parent 5e737980fe
commit 00b1bc7cd2

View File

@@ -10,6 +10,7 @@
#endregion #endregion
using System; using System;
using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.Drawing; using System.Drawing;
using System.Linq; using System.Linq;
@@ -56,7 +57,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
{ {
switch (searchStatus) switch (searchStatus)
{ {
case SearchStatus.Failed: return "Failed to contact master server."; case SearchStatus.Failed: return "Failed to query server list.";
case SearchStatus.NoGames: return "No games found. Try changing filters."; case SearchStatus.NoGames: return "No games found. Try changing filters.";
default: return ""; default: return "";
} }
@@ -300,17 +301,23 @@ namespace OpenRA.Mods.Common.Widgets.Logic
{ {
currentQuery = null; currentQuery = null;
if (i.Error != null) List<GameServer> games = null;
if (i.Error == null)
{
try
{ {
RefreshServerListInner(null);
return;
}
var data = Encoding.UTF8.GetString(i.Result); var data = Encoding.UTF8.GetString(i.Result);
var yaml = MiniYaml.FromString(data); var yaml = MiniYaml.FromString(data);
var games = yaml.Select(a => new GameServer(a.Value)) games = yaml.Select(a => new GameServer(a.Value))
.Where(gs => gs.Address != null); .Where(gs => gs.Address != null)
.ToList();
}
catch
{
searchStatus = SearchStatus.Failed;
}
}
Game.RunAfterTick(() => RefreshServerListInner(games)); Game.RunAfterTick(() => RefreshServerListInner(games));
}; };
@@ -343,7 +350,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
currentMap = server != null ? modData.MapCache[server.Map] : null; currentMap = server != null ? modData.MapCache[server.Map] : null;
} }
void RefreshServerListInner(IEnumerable<GameServer> games) void RefreshServerListInner(List<GameServer> games)
{ {
if (games == null) if (games == null)
return; return;