Skip to content

Commit

Permalink
Fix TaskCanceledException during login
Browse files Browse the repository at this point in the history
  • Loading branch information
SeRi0uS007 committed Oct 31, 2023
1 parent 51b2be5 commit b069247
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 21 deletions.
2 changes: 1 addition & 1 deletion SteamAccountDataFetcher/SteamAccountDataFetcher.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<Authors>Andrii Lavrenko</Authors>
<Description>Utility for collecting Steam account information</Description>
<Copyright>Andrii Lavrenko</Copyright>
<Version>3.0.0</Version>
<Version>3.0.1</Version>
</PropertyGroup>

<ItemGroup>
Expand Down
47 changes: 27 additions & 20 deletions SteamAccountDataFetcher/SteamDataClient/Client.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ internal Client(string username, string password, string sharedSecret)
_callbackManager.Subscribe<SteamUser.LoggedOnCallback>(OnLoggedOn);
_callbackManager.Subscribe<SteamUser.LoggedOffCallback>(OnLoggedOffAsync);
_callbackManager.Subscribe<SteamApps.LicenseListCallback>(OnLicenseListAsync);

_callbackManager.Subscribe<DataFetcher.IsLimitedAccountCallback>(OnIsLimitedAccount);

_autoTwoFactorAuthenticator = new(this, sharedSecret);
Expand Down Expand Up @@ -118,28 +117,35 @@ internal async Task RunAsync()

private async Task LoginAsync()
{
CredentialsAuthSession authSession = await _steamClient.Authentication.BeginAuthSessionViaCredentialsAsync(new()
{
Username = Username,
Password = Password,
Authenticator = _autoTwoFactorAuthenticator
});

AuthPollResult authPollResult;
try
while (true)
{
authPollResult = await authSession.PollingWaitForResultAsync();
}
catch (AuthenticationException e)
{
Log($"Unable to authenticate user to Steam Client with error {e.Message}.", Logger.Level.Error);
_steamClient.Disconnect();
return;
try
{
CredentialsAuthSession authSession = await _steamClient.Authentication.BeginAuthSessionViaCredentialsAsync(new()
{
Username = Username,
Password = Password,
Authenticator = _autoTwoFactorAuthenticator
});
AuthPollResult authPollResult = await authSession.PollingWaitForResultAsync();
AccessToken = authPollResult.AccessToken;
RefreshToken = authPollResult.RefreshToken;
break;
}
catch (AuthenticationException e)
{
Log($"Unable to authenticate user to Steam Client with error {e.Message}.", Logger.Level.Error);
_steamClient.Disconnect();
return;
}
catch (TaskCanceledException)
{
Log("Failure to authenticate user to Steam Client. Retrying...", Logger.Level.Warning);
await Task.Delay(1000);
continue;
}
}

AccessToken = authPollResult.AccessToken;
RefreshToken = authPollResult.RefreshToken;

_steamUser.LogOn(new()
{
Username = Username,
Expand Down Expand Up @@ -207,6 +213,7 @@ private void OnLoggedOn(SteamUser.LoggedOnCallback callback)
return;
}
_responseAccountInfo.SteamId = callback.ClientSteamID.ConvertToUInt64();
Log("Logged into Steam.");
_steamWebClient.InitAsync();
}

Expand Down

0 comments on commit b069247

Please sign in to comment.