diff --git a/src/Launcher.cs b/src/Launcher.cs index 1d69519..4a09de5 100644 --- a/src/Launcher.cs +++ b/src/Launcher.cs @@ -14,7 +14,7 @@ static class Launcher { public static readonly CancellationTokenSource CancellationTokenSource = new(); - public static string PrepareGameLaunch(ParseResult commandLineResult, IPFilter ipFilter) + public static async ValueTask PrepareGameLaunch(ParseResult commandLineResult, IPFilter ipFilter) { var gameVersion = commandLineResult.GetValueForOption(LaunchOptions.Version); var (subFolder, binaryName, majorGameVersion, minGameBuild) = gameVersion switch @@ -112,6 +112,7 @@ static class Launcher Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine($"Developer mode: {(devModeEnabled ? "Enabled" : "Disabled")}"); Console.WriteLine(); + Console.WriteLine($"Client Portal '{portal.HostName}'"); Console.ForegroundColor = ConsoleColor.Gray; // Check for valid certificate when dev mode is disabled. @@ -119,11 +120,10 @@ static class Launcher { try { - using var tcpClient = new TcpClient(portal.HostName, portal.Port); + using var tcpClient = new TcpClient(); + using var tcpClientTimeout = new CancellationTokenSource(TimeSpan.FromSeconds(5)); - // Cancel after 5 seconds. - tcpClient.ReceiveTimeout = 5000; - tcpClient.SendTimeout = 5000; + await tcpClient.ConnectAsync(portal.HostName, portal.Port, tcpClientTimeout.Token); using var sslStream = new SslStream(tcpClient.GetStream(), false, (_, _, _, sslPolicyErrors) => @@ -144,7 +144,7 @@ static class Launcher sslStream.AuthenticateAsClient(portal.HostName); } - catch (SocketException) + catch (Exception exception) when (exception is SocketException or OperationCanceledException) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine($"{portal.HostName}:{portal.Port} is offline."); diff --git a/src/Program.cs b/src/Program.cs index 9e5f563..83976fa 100644 --- a/src/Program.cs +++ b/src/Program.cs @@ -12,12 +12,12 @@ if (!Process.GetCurrentProcess().ProcessName.Contains("arctium", StringCompariso PrintHeader("WoW Client Launcher"); -LaunchOptions.RootCommand.SetHandler(context => +LaunchOptions.RootCommand.SetHandler(async context => { CreateDevIPFilter(out var ipFilter); // Prefer / instead of \ for the client path. - var appPath = Launcher.PrepareGameLaunch(context.ParseResult, ipFilter).Replace("\\", "/"); + var appPath = (await Launcher.PrepareGameLaunch(context.ParseResult, ipFilter)).Replace("\\", "/"); var gameCommandLine = string.Join(" ", context.ParseResult.UnmatchedTokens); // Add config parameter to the game command line.