Fix client portal check timeout.

Log client portal in console.
This commit is contained in:
Fabian
2023-07-28 17:46:58 +02:00
parent 834b2d5f73
commit 94c7810307
2 changed files with 8 additions and 8 deletions

View File

@@ -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<string> 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.");

View File

@@ -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.