From 63e1774cb69633fba712563ffad82b6ab6e4f4f8 Mon Sep 17 00:00:00 2001 From: RaidMax Date: Sat, 9 Jul 2022 10:52:27 -0500 Subject: [PATCH] gracefully handle when infoString does not include all expected data --- Application/IW4MServer.cs | 47 ++++++++++++++++++++++++++++++--------- 1 file changed, 37 insertions(+), 10 deletions(-) diff --git a/Application/IW4MServer.cs b/Application/IW4MServer.cs index c4b00d0fa..f703cf2e1 100644 --- a/Application/IW4MServer.cs +++ b/Application/IW4MServer.cs @@ -689,23 +689,50 @@ namespace IW4MAdmin else { - Gametype = dict["gametype"]; - Hostname = dict["hostname"]; + if (dict.ContainsKey("gametype")) + { + Gametype = dict["gametype"]; + } - string mapname = dict["mapname"] ?? CurrentMap.Name; - UpdateMap(mapname); + if (dict.ContainsKey("hostname")) + { + Hostname = dict["hostname"]; + } + + var newMapName = dict.ContainsKey("mapname") + ? dict["mapname"] ?? CurrentMap.Name + : CurrentMap.Name; + UpdateMap(newMapName); } } else { - var dict = (Dictionary) E.Extra; - Gametype = dict["g_gametype"]; - Hostname = dict["sv_hostname"]; - MaxClients = int.Parse(dict["sv_maxclients"]); + var dict = (Dictionary)E.Extra; + if (dict.ContainsKey("g_gametype")) + { + Gametype = dict["g_gametype"]; + } - string mapname = dict["mapname"]; - UpdateMap(mapname); + if (dict.ContainsKey("sv_hostname")) + { + Hostname = dict["sv_hostname"]; + } + + if (dict.ContainsKey("sv_maxclients")) + { + MaxClients = int.Parse(dict["sv_maxclients"]); + } + + else if (dict.ContainsKey("com_maxclients")) + { + MaxClients = int.Parse(dict["com_maxclients"]); + } + + if (dict.ContainsKey("mapname")) + { + UpdateMap(dict["mapname"]); + } } if (E.GameTime.HasValue)