diff --git a/OpenRA.Game/Exts.cs b/OpenRA.Game/Exts.cs index 1bb45d548b..3186fbbfff 100644 --- a/OpenRA.Game/Exts.cs +++ b/OpenRA.Game/Exts.cs @@ -32,12 +32,6 @@ namespace OpenRA return string.Format(CultureInfo.CurrentCulture, format, args); } - public static T WithDefault(T def, Func f) - { - try { return f(); } - catch { return def; } - } - public static Lazy Lazy(Func p) { return new Lazy(p); } public static IEnumerable GetNamespaces(this Assembly a) diff --git a/OpenRA.Mods.Common/Widgets/Logic/DirectConnectLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/DirectConnectLogic.cs index 2a360212b7..cbc32386fc 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/DirectConnectLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/DirectConnectLogic.cs @@ -46,7 +46,8 @@ namespace OpenRA.Mods.Common.Widgets.Logic joinButton.OnClick = () => { - var port = Exts.WithDefault(1234, () => int.Parse(portField.Text, NumberFormatInfo.CurrentInfo)); + if (!int.TryParse(portField.Text, NumberStyles.Integer, NumberFormatInfo.CurrentInfo, out var port)) + port = 1234; Game.Settings.Player.LastServer = $"{ipField.Text}:{port}"; Game.Settings.Save();