From b4cbe85b36664f31699617b29c4920cc7f7b8d88 Mon Sep 17 00:00:00 2001 From: JustArchi Date: Mon, 31 Jul 2017 16:57:10 +0200 Subject: [PATCH] Closes #605 --- ArchiSteamFarm/Bot.cs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/ArchiSteamFarm/Bot.cs b/ArchiSteamFarm/Bot.cs index 9911c9145..b22dda8dc 100755 --- a/ArchiSteamFarm/Bot.cs +++ b/ArchiSteamFarm/Bot.cs @@ -50,11 +50,13 @@ namespace ArchiSteamFarm { private const ushort MaxSteamMessageLength = 2048; private const byte MaxTwoFactorCodeFailures = 3; private const byte MinHeartBeatTTL = GlobalConfig.DefaultConnectionTimeout; // Assume client is responsive for at least that amount of seconds + private const byte PICSCooldownInMiliseconds = 200; // We might need to tune this further internal static readonly ConcurrentDictionary Bots = new ConcurrentDictionary(); private static readonly SemaphoreSlim GiftsSemaphore = new SemaphoreSlim(1); private static readonly SemaphoreSlim LoginSemaphore = new SemaphoreSlim(1); + private static readonly SemaphoreSlim PICSSemaphore = new SemaphoreSlim(1); private static readonly SteamConfiguration SteamConfiguration = new SteamConfiguration(); internal readonly ArchiLogger ArchiLogger; @@ -347,6 +349,8 @@ namespace ArchiSteamFarm { } } + await LimitPICSRequestsAsync().ConfigureAwait(false); + AsyncJobMultiple.ResultSet productInfoResultSet; try { @@ -450,6 +454,8 @@ namespace ArchiSteamFarm { } internal async Task>> GetAppIDsToPackageIDs(IEnumerable packageIDs) { + await LimitPICSRequestsAsync().ConfigureAwait(false); + AsyncJobMultiple.ResultSet productInfoResultSet; try { @@ -1380,6 +1386,14 @@ namespace ArchiSteamFarm { }).Forget(); } + private static async Task LimitPICSRequestsAsync() { + await PICSSemaphore.WaitAsync().ConfigureAwait(false); + Task.Run(async () => { + await Task.Delay(PICSCooldownInMiliseconds).ConfigureAwait(false); + PICSSemaphore.Release(); + }).Forget(); + } + private async Task MarkInventoryIfNeeded() { if (!BotConfig.DismissInventoryNotifications) { return;