From feb80fbf49f9330dbdd07dae0d43c01edbba40ec Mon Sep 17 00:00:00 2001 From: JustArchi Date: Fri, 16 Sep 2016 22:46:10 +0200 Subject: [PATCH] Revert "Fix logging in when steam API is unavailable" This reverts commit 5a267eb225015059646abfe7a97c0d53a75c0238. --- ArchiSteamFarm/Bot.cs | 4 ++-- ArchiSteamFarm/MobileAuthenticator.cs | 32 +++------------------------ 2 files changed, 5 insertions(+), 31 deletions(-) diff --git a/ArchiSteamFarm/Bot.cs b/ArchiSteamFarm/Bot.cs index b6f99b8bb..972a018a7 100755 --- a/ArchiSteamFarm/Bot.cs +++ b/ArchiSteamFarm/Bot.cs @@ -1596,7 +1596,7 @@ namespace ArchiSteamFarm { ArchiHandler.PlayGames(BotConfig.GamesPlayedWhileIdle, BotConfig.CustomGamePlayedWhileIdle); } - private void OnConnected(SteamClient.ConnectedCallback callback) { + private async void OnConnected(SteamClient.ConnectedCallback callback) { if (callback == null) { Logging.LogNullError(nameof(callback), BotName); return; @@ -1636,7 +1636,7 @@ namespace ArchiSteamFarm { // If we have ASF 2FA enabled, we can always provide TwoFactorCode, and save a request if (BotDatabase.MobileAuthenticator != null) { - TwoFactorCode = BotDatabase.MobileAuthenticator.GenerateTokenImmediately(); + TwoFactorCode = await BotDatabase.MobileAuthenticator.GenerateToken().ConfigureAwait(false); } SteamUser.LogOnDetails logOnDetails = new SteamUser.LogOnDetails { diff --git a/ArchiSteamFarm/MobileAuthenticator.cs b/ArchiSteamFarm/MobileAuthenticator.cs index d7b06a052..576f0c366 100644 --- a/ArchiSteamFarm/MobileAuthenticator.cs +++ b/ArchiSteamFarm/MobileAuthenticator.cs @@ -195,16 +195,6 @@ namespace ArchiSteamFarm { return null; } - internal string GenerateTokenImmediately() { - uint time = GetSteamTimeImmediately(); - if (time != 0) { - return GenerateTokenForTime(time); - } - - Logging.LogNullError(nameof(time), Bot.BotName); - return null; - } - internal async Task> GetConfirmations() { if (!HasCorrectDeviceID) { Logging.LogGenericWarning("Can't execute properly due to invalid DeviceID!", Bot.BotName); @@ -284,32 +274,16 @@ namespace ArchiSteamFarm { return (uint) (Utilities.GetUnixTime() + SteamTimeDifference.GetValueOrDefault()); } - if (!await TimeSemaphore.WaitAsync(0).ConfigureAwait(false)) { - return (uint) (Utilities.GetUnixTime() + SteamTimeDifference.GetValueOrDefault()); - } - - try { - if (SteamTimeDifference.HasValue) { - return (uint) (Utilities.GetUnixTime() + SteamTimeDifference.GetValueOrDefault()); - } + await TimeSemaphore.WaitAsync().ConfigureAwait(false); + if (!SteamTimeDifference.HasValue) { uint serverTime = Bot.ArchiWebHandler.GetServerTime(); if (serverTime != 0) { SteamTimeDifference = (short) (serverTime - Utilities.GetUnixTime()); } - - return (uint) (Utilities.GetUnixTime() + SteamTimeDifference.GetValueOrDefault()); - } finally { - TimeSemaphore.Release(); - } - } - - private uint GetSteamTimeImmediately() { - if (!SteamTimeDifference.HasValue) { - // We must return time immediately, schedule update in the background and proceed - GetSteamTime().Forget(); } + TimeSemaphore.Release(); return (uint) (Utilities.GetUnixTime() + SteamTimeDifference.GetValueOrDefault()); }