mirror of
https://github.com/JustArchiNET/ArchiSteamFarm.git
synced 2026-01-16 08:25:28 +00:00
Implement my previous idea
Thanks to that, we can guarantee some room for networking, but also make users more happy as they'll never get 2FA tokens no human is capable of entering in time
This commit is contained in:
@@ -55,6 +55,7 @@ namespace ArchiSteamFarm {
|
||||
|
||||
private const byte CodeDigits = 5;
|
||||
private const byte CodeInterval = 30;
|
||||
private const byte MinimumTimeLeft = 5;
|
||||
|
||||
private static readonly char[] CodeCharacters = {
|
||||
'2', '3', '4', '5', '6', '7', '8', '9', 'B', 'C',
|
||||
@@ -186,15 +187,31 @@ namespace ArchiSteamFarm {
|
||||
}
|
||||
|
||||
internal async Task<string> GenerateToken() {
|
||||
uint time = await GetSteamTime().ConfigureAwait(false);
|
||||
if (time != 0) {
|
||||
return GenerateTokenForTime(time);
|
||||
Tuple<string, byte> tokenTimePair = await GenerateTokenTimePair().ConfigureAwait(false);
|
||||
if (tokenTimePair != null) {
|
||||
return tokenTimePair.Item1;
|
||||
}
|
||||
|
||||
Logging.LogNullError(nameof(time), Bot.BotName);
|
||||
Logging.LogNullError(nameof(tokenTimePair), Bot.BotName);
|
||||
return null;
|
||||
}
|
||||
|
||||
internal async Task<Tuple<string, byte>> GenerateTokenTimePair() {
|
||||
uint time = await GetSteamTime().ConfigureAwait(false);
|
||||
if (time == 0) {
|
||||
Logging.LogNullError(nameof(time), Bot.BotName);
|
||||
return null;
|
||||
}
|
||||
|
||||
byte timeLeft = (byte) (CodeInterval - time % CodeInterval);
|
||||
if (timeLeft >= MinimumTimeLeft) {
|
||||
return new Tuple<string, byte>(GenerateTokenForTime(time), timeLeft);
|
||||
}
|
||||
|
||||
await Task.Delay(timeLeft * 1000).ConfigureAwait(false);
|
||||
return new Tuple<string, byte>(GenerateTokenForTime(time + timeLeft), CodeInterval);
|
||||
}
|
||||
|
||||
internal async Task<HashSet<Confirmation>> GetConfirmations() {
|
||||
if (!HasCorrectDeviceID) {
|
||||
Logging.LogGenericWarning("Can't execute properly due to invalid DeviceID!", Bot.BotName);
|
||||
@@ -269,7 +286,7 @@ namespace ArchiSteamFarm {
|
||||
return result;
|
||||
}
|
||||
|
||||
internal async Task<uint> GetSteamTime() {
|
||||
private async Task<uint> GetSteamTime() {
|
||||
if (SteamTimeDifference.HasValue) {
|
||||
return (uint) (Utilities.GetUnixTime() + SteamTimeDifference.GetValueOrDefault());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user