This commit is contained in:
Archi
2024-03-19 13:03:09 +01:00
parent 04b534bda1
commit 6f2fd4eccc
5 changed files with 48 additions and 76 deletions

View File

@@ -22,7 +22,6 @@
// limitations under the License.
using System;
using System.Collections.Frozen;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.ComponentModel;
@@ -52,7 +51,6 @@ using SteamKit2;
namespace ArchiSteamFarm.Steam.Integration;
public sealed class ArchiWebHandler : IDisposable {
private const string AccountPrivateAppsService = "IAccountPrivateAppsService";
private const string EconService = "IEconService";
private const string LoyaltyRewardsService = "ILoyaltyRewardsService";
private const ushort MaxItemsInSingleInventoryRequest = 5000;
@@ -76,8 +74,6 @@ public sealed class ArchiWebHandler : IDisposable {
[PublicAPI]
public WebBrowser WebBrowser { get; }
internal readonly ArchiCacheable<FrozenSet<uint>> CachedPrivateAppIDs;
private readonly Bot Bot;
private readonly SemaphoreSlim SessionSemaphore = new(1, 1);
@@ -91,12 +87,10 @@ public sealed class ArchiWebHandler : IDisposable {
ArgumentNullException.ThrowIfNull(bot);
Bot = bot;
CachedPrivateAppIDs = new ArchiCacheable<FrozenSet<uint>>(ResolvePrivateAppIDs, TimeSpan.FromMinutes(5));
WebBrowser = new WebBrowser(bot.ArchiLogger, ASF.GlobalConfig?.WebProxy);
}
public void Dispose() {
CachedPrivateAppIDs.Dispose();
SessionSemaphore.Dispose();
WebBrowser.Dispose();
}
@@ -2123,8 +2117,6 @@ public sealed class ArchiWebHandler : IDisposable {
internal void OnDisconnected() => Initialized = false;
internal void OnInitModules() => Utilities.InBackground(() => CachedPrivateAppIDs.Reset());
internal void OnVanityURLChanged(string? vanityURL = null) => VanityURL = !string.IsNullOrEmpty(vanityURL) ? vanityURL : null;
internal async Task<(EResult Result, EPurchaseResultDetail? PurchaseResult, string? BalanceText)?> RedeemWalletKey(string key) {
@@ -2294,69 +2286,6 @@ public sealed class ArchiWebHandler : IDisposable {
}
}
private async Task<(bool Success, FrozenSet<uint>? Result)> ResolvePrivateAppIDs(CancellationToken cancellationToken) {
string? accessToken = Bot.AccessToken;
if (string.IsNullOrEmpty(accessToken)) {
return (false, null);
}
Dictionary<string, object?> arguments = new(1, StringComparer.Ordinal) {
{ "access_token", accessToken }
};
KeyValue? response = null;
for (byte i = 0; (i < WebBrowser.MaxTries) && (response == null); i++) {
if ((i > 0) && (WebLimiterDelay > 0)) {
await Task.Delay(WebLimiterDelay, cancellationToken).ConfigureAwait(false);
}
using WebAPI.AsyncInterface accountPrivateAppsService = Bot.SteamConfiguration.GetAsyncWebAPIInterface(AccountPrivateAppsService);
accountPrivateAppsService.Timeout = WebBrowser.Timeout;
try {
response = await WebLimitRequest(
WebAPI.DefaultBaseAddress,
// ReSharper disable once AccessToDisposedClosure
async () => await accountPrivateAppsService.CallAsync(HttpMethod.Get, "GetPrivateAppList", args: arguments).ConfigureAwait(false), cancellationToken
).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 (false, null);
}
List<KeyValue> nodes = response["private_apps"]["appids"].Children;
if (nodes.Count == 0) {
return (true, FrozenSet<uint>.Empty);
}
HashSet<uint> result = new(nodes.Count);
foreach (uint appID in nodes.Select(static node => node.AsUnsignedInteger())) {
if (appID == 0) {
Bot.ArchiLogger.LogNullError(appID);
return (false, null);
}
result.Add(appID);
}
return (true, result.ToFrozenSet());
}
private static void SetDescriptionsToAssets(IEnumerable<Asset> assets, [SuppressMessage("ReSharper", "SuggestBaseTypeForParameter")] Dictionary<(uint AppID, ulong ClassID, ulong InstanceID), InventoryDescription> descriptions) {
ArgumentNullException.ThrowIfNull(assets);
ArgumentNullException.ThrowIfNull(descriptions);