Move GetServerTime() from AWH to AH

This commit is contained in:
Archi 2024-03-18 23:48:30 +01:00
parent 970ba437a0
commit 0dd6f38748
No known key found for this signature in database
GPG key ID: 6B138B4C64555AEA
3 changed files with 31 additions and 45 deletions

View file

@ -623,6 +623,36 @@ public sealed class ArchiHandler : ClientMsgHandler {
return body.privacy_settings;
}
internal async Task<ulong> GetServerTime() {
if (Client == null) {
throw new InvalidOperationException(nameof(Client));
}
if (!Client.IsConnected) {
return 0;
}
CTwoFactor_Time_Request request = new();
SteamUnifiedMessages.ServiceMethodResponse response;
try {
response = await UnifiedTwoFactorService.SendMessage(x => x.QueryTime(request)).ToLongRunningTask().ConfigureAwait(false);
} catch (Exception e) {
ArchiLogger.LogGenericWarningException(e);
return 0;
}
if (response.Result != EResult.OK) {
return 0;
}
CTwoFactor_Time_Response body = response.GetDeserializedResponse<CTwoFactor_Time_Response>();
return body.server_time;
}
internal async Task<string?> GetTwoFactorDeviceIdentifier(ulong steamID) {
if ((steamID == 0) || !new SteamID(steamID).IsIndividualAccount) {
throw new ArgumentOutOfRangeException(nameof(steamID));

View file

@ -58,7 +58,6 @@ public sealed class ArchiWebHandler : IDisposable {
private const ushort MaxItemsInSingleInventoryRequest = 5000;
private const byte MinimumSessionValidityInSeconds = 10;
private const string SteamAppsService = "ISteamApps";
private const string TwoFactorService = "ITwoFactorService";
[PublicAPI]
public static Uri SteamCheckoutURL => new("https://checkout.steampowered.com");
@ -1859,49 +1858,6 @@ public sealed class ArchiWebHandler : IDisposable {
return response?.Content;
}
internal async Task<ulong> GetServerTime() {
KeyValue? response = null;
for (byte i = 0; (i < WebBrowser.MaxTries) && (response == null); i++) {
if ((i > 0) && (WebLimiterDelay > 0)) {
await Task.Delay(WebLimiterDelay).ConfigureAwait(false);
}
using WebAPI.AsyncInterface twoFactorService = Bot.SteamConfiguration.GetAsyncWebAPIInterface(TwoFactorService);
twoFactorService.Timeout = WebBrowser.Timeout;
try {
response = await WebLimitRequest(
WebAPI.DefaultBaseAddress,
// ReSharper disable once AccessToDisposedClosure
async () => await twoFactorService.CallAsync(HttpMethod.Post, "QueryTime").ConfigureAwait(false)
).ConfigureAwait(false);
} catch (TaskCanceledException e) {
Bot.ArchiLogger.LogGenericDebuggingException(e);
} catch (Exception e) {
Bot.ArchiLogger.LogGenericWarningException(e);
}
}
if (response == null) {
Bot.ArchiLogger.LogGenericWarning(string.Format(CultureInfo.CurrentCulture, Strings.ErrorRequestFailedTooManyTimes, WebBrowser.MaxTries));
return 0;
}
ulong result = response["server_time"].AsUnsignedLong();
if (result == 0) {
Bot.ArchiLogger.LogNullError(result);
return 0;
}
return result;
}
internal async Task<byte?> GetTradeHoldDurationForTrade(ulong tradeID) {
ArgumentOutOfRangeException.ThrowIfZero(tradeID);

View file

@ -208,7 +208,7 @@ public sealed class MobileAuthenticator : IDisposable {
return Utilities.MathAdd(Utilities.GetUnixTime(), steamTimeDifference.Value);
}
ulong serverTime = await Bot.ArchiWebHandler.GetServerTime().ConfigureAwait(false);
ulong serverTime = await Bot.ArchiHandler.GetServerTime().ConfigureAwait(false);
if (serverTime == 0) {
return Utilities.GetUnixTime();