mirror of
https://github.com/JustArchiNET/ArchiSteamFarm
synced 2024-11-14 08:57:56 +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:
parent
160bfd612f
commit
1df2c3b042
3 changed files with 29 additions and 8 deletions
|
@ -323,7 +323,7 @@ namespace ArchiSteamFarm {
|
|||
string request = SteamCommunityURL + "/mobileconf/details/" + confirmation.ID + "?l=english&p=" + deviceID + "&a=" + SteamID + "&k=" + WebUtility.UrlEncode(confirmationHash) + "&t=" + time + "&m=android&tag=conf";
|
||||
|
||||
Steam.ConfirmationDetails response = await WebBrowser.UrlGetToJsonResultRetry<Steam.ConfirmationDetails>(request).ConfigureAwait(false);
|
||||
if (response == null) {
|
||||
if ((response == null) || !response.Success) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
|
@ -871,8 +871,12 @@ namespace ArchiSteamFarm {
|
|||
return "That bot doesn't have ASF 2FA enabled!";
|
||||
}
|
||||
|
||||
byte timeLeft = (byte) (30 - await BotDatabase.MobileAuthenticator.GetSteamTime().ConfigureAwait(false) % 30);
|
||||
return "2FA Token: " + await BotDatabase.MobileAuthenticator.GenerateToken().ConfigureAwait(false) + " (expires in " + timeLeft + " seconds)";
|
||||
Tuple<string, byte> tokenTimePair = await BotDatabase.MobileAuthenticator.GenerateTokenTimePair().ConfigureAwait(false);
|
||||
if (tokenTimePair == null) {
|
||||
return "Error!";
|
||||
}
|
||||
|
||||
return "2FA Token: " + tokenTimePair.Item1 + " (expires in " + tokenTimePair.Item2 + " seconds)";
|
||||
}
|
||||
|
||||
private static async Task<string> Response2FA(ulong steamID, string botName) {
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue