Fix logging in when steam API is unavailable

Or at least part of it...
This commit is contained in:
JustArchi
2016-09-14 19:00:03 +02:00
parent ccfad31053
commit 5a267eb225
2 changed files with 31 additions and 5 deletions

View File

@@ -195,6 +195,16 @@ 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<HashSet<Confirmation>> GetConfirmations() {
if (!HasCorrectDeviceID) {
Logging.LogGenericWarning("Can't execute properly due to invalid DeviceID!", Bot.BotName);
@@ -274,16 +284,32 @@ namespace ArchiSteamFarm {
return (uint) (Utilities.GetUnixTime() + SteamTimeDifference.GetValueOrDefault());
}
await TimeSemaphore.WaitAsync().ConfigureAwait(false);
if (!await TimeSemaphore.WaitAsync(0).ConfigureAwait(false)) {
return (uint) (Utilities.GetUnixTime() + SteamTimeDifference.GetValueOrDefault());
}
try {
if (SteamTimeDifference.HasValue) {
return (uint) (Utilities.GetUnixTime() + SteamTimeDifference.GetValueOrDefault());
}
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());
}