private void OnLoggedOn(SteamKit.SteamUser.LoggedOnCallback callback) { if (callback.Result == EResult.OK) { SuggestedCellId = callback.CellID; _clientReadyEvent.Set(); } else { if (callback.Result == EResult.AccountLogonDenied || callback.Result == EResult.AccountLoginDeniedNeedTwoFactor) { if (callback.Result == EResult.AccountLogonDenied) { EmailAuthCode = _codesProvider.GetEmailAuthenticationCode(Credentials); } else { TwoFactorCode = _codesProvider.GetTwoFactorAuthenticationCode(Credentials); } InternalClient.Connect(); } else { FaultException = new SteamLogonException(callback.Result); _clientFaultedEvent.Set(); } } }
private void OnDisconnected(SteamKit.SteamClient.DisconnectedCallback callback) { _clientReadyEvent.Reset(); if (_cancellationTokenSource.IsCancellationRequested || callback.UserInitiated) { return; } Task.Run(async() => { await Task.Delay(TimeSpan.FromMilliseconds(100)); InternalClient.Connect(); }); }
/// <summary> /// Asks the underlying client to connect to Steam and perform a login with the given <see cref="Credentials"/>. /// </summary> /// <param name="cancellationToken">Cancellation token.</param> /// <exception cref="SteamClientFaultedException">Client is faulted.</exception> public async Task ConnectAsync(CancellationToken cancellationToken) { if (_isClientRunning) { return; } InternalClient.Connect(); var readyTask = _clientReadyEvent.WaitAsync(cancellationToken); var faultedTask = _clientFaultedEvent.WaitAsync(); var task = await Task.WhenAny(readyTask, faultedTask); if (task == faultedTask) { throw new SteamClientFaultedException(FaultException); } }