From 00b1bc7cd2ee75acd89d5768460438d4a3e4262b Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Fri, 10 Mar 2017 18:21:34 +0000 Subject: [PATCH] Fix crash when master server query returns unexpected data. --- .../Widgets/Logic/MultiplayerLogic.cs | 29 ++++++++++++------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/OpenRA.Mods.Common/Widgets/Logic/MultiplayerLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/MultiplayerLogic.cs index ddd2a07b28..9df79f8ca4 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/MultiplayerLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/MultiplayerLogic.cs @@ -10,6 +10,7 @@ #endregion using System; +using System.Collections; using System.Collections.Generic; using System.Drawing; using System.Linq; @@ -56,7 +57,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic { 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."; default: return ""; } @@ -300,18 +301,24 @@ namespace OpenRA.Mods.Common.Widgets.Logic { currentQuery = null; - if (i.Error != null) + List games = null; + if (i.Error == null) { - RefreshServerListInner(null); - return; + try + { + var data = Encoding.UTF8.GetString(i.Result); + var yaml = MiniYaml.FromString(data); + + games = yaml.Select(a => new GameServer(a.Value)) + .Where(gs => gs.Address != null) + .ToList(); + } + catch + { + searchStatus = SearchStatus.Failed; + } } - var data = Encoding.UTF8.GetString(i.Result); - var yaml = MiniYaml.FromString(data); - - var games = yaml.Select(a => new GameServer(a.Value)) - .Where(gs => gs.Address != null); - Game.RunAfterTick(() => RefreshServerListInner(games)); }; @@ -343,7 +350,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic currentMap = server != null ? modData.MapCache[server.Map] : null; } - void RefreshServerListInner(IEnumerable games) + void RefreshServerListInner(List games) { if (games == null) return;