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:
@@ -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";
|
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);
|
Steam.ConfirmationDetails response = await WebBrowser.UrlGetToJsonResultRetry<Steam.ConfirmationDetails>(request).ConfigureAwait(false);
|
||||||
if (response == null) {
|
if ((response == null) || !response.Success) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -871,8 +871,12 @@ namespace ArchiSteamFarm {
|
|||||||
return "That bot doesn't have ASF 2FA enabled!";
|
return "That bot doesn't have ASF 2FA enabled!";
|
||||||
}
|
}
|
||||||
|
|
||||||
byte timeLeft = (byte) (30 - await BotDatabase.MobileAuthenticator.GetSteamTime().ConfigureAwait(false) % 30);
|
Tuple<string, byte> tokenTimePair = await BotDatabase.MobileAuthenticator.GenerateTokenTimePair().ConfigureAwait(false);
|
||||||
return "2FA Token: " + await BotDatabase.MobileAuthenticator.GenerateToken().ConfigureAwait(false) + " (expires in " + timeLeft + " seconds)";
|
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) {
|
private static async Task<string> Response2FA(ulong steamID, string botName) {
|
||||||
|
|||||||
@@ -55,6 +55,7 @@ namespace ArchiSteamFarm {
|
|||||||
|
|
||||||
private const byte CodeDigits = 5;
|
private const byte CodeDigits = 5;
|
||||||
private const byte CodeInterval = 30;
|
private const byte CodeInterval = 30;
|
||||||
|
private const byte MinimumTimeLeft = 5;
|
||||||
|
|
||||||
private static readonly char[] CodeCharacters = {
|
private static readonly char[] CodeCharacters = {
|
||||||
'2', '3', '4', '5', '6', '7', '8', '9', 'B', 'C',
|
'2', '3', '4', '5', '6', '7', '8', '9', 'B', 'C',
|
||||||
@@ -186,15 +187,31 @@ namespace ArchiSteamFarm {
|
|||||||
}
|
}
|
||||||
|
|
||||||
internal async Task<string> GenerateToken() {
|
internal async Task<string> GenerateToken() {
|
||||||
uint time = await GetSteamTime().ConfigureAwait(false);
|
Tuple<string, byte> tokenTimePair = await GenerateTokenTimePair().ConfigureAwait(false);
|
||||||
if (time != 0) {
|
if (tokenTimePair != null) {
|
||||||
return GenerateTokenForTime(time);
|
return tokenTimePair.Item1;
|
||||||
}
|
}
|
||||||
|
|
||||||
Logging.LogNullError(nameof(time), Bot.BotName);
|
Logging.LogNullError(nameof(tokenTimePair), Bot.BotName);
|
||||||
return null;
|
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() {
|
internal async Task<HashSet<Confirmation>> GetConfirmations() {
|
||||||
if (!HasCorrectDeviceID) {
|
if (!HasCorrectDeviceID) {
|
||||||
Logging.LogGenericWarning("Can't execute properly due to invalid DeviceID!", Bot.BotName);
|
Logging.LogGenericWarning("Can't execute properly due to invalid DeviceID!", Bot.BotName);
|
||||||
@@ -269,7 +286,7 @@ namespace ArchiSteamFarm {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal async Task<uint> GetSteamTime() {
|
private async Task<uint> GetSteamTime() {
|
||||||
if (SteamTimeDifference.HasValue) {
|
if (SteamTimeDifference.HasValue) {
|
||||||
return (uint) (Utilities.GetUnixTime() + SteamTimeDifference.GetValueOrDefault());
|
return (uint) (Utilities.GetUnixTime() + SteamTimeDifference.GetValueOrDefault());
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user