Skip to content

Commit

Permalink
Resolve trade offers being stuck for too long when ASF API connection…
Browse files Browse the repository at this point in the history
… is down
  • Loading branch information
JustArchi committed Mar 31, 2024
1 parent 79fb392 commit cb8668f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
8 changes: 7 additions & 1 deletion ArchiSteamFarm/Core/ArchiNet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,13 @@ internal static class ArchiNet {

Uri request = new(URL, "/Api/BadBots");

ObjectResponse<GenericResponse<ImmutableHashSet<ulong>>>? response = await ASF.WebBrowser.UrlGetToJsonObject<GenericResponse<ImmutableHashSet<ulong>>>(request, cancellationToken: cancellationToken).ConfigureAwait(false);
ObjectResponse<GenericResponse<ImmutableHashSet<ulong>>>? response = null;

try {
response = await ASF.WebBrowser.UrlGetToJsonObject<GenericResponse<ImmutableHashSet<ulong>>>(request, cancellationToken: cancellationToken).ConfigureAwait(false);
} catch (OperationCanceledException e) {
ASF.ArchiLogger.LogGenericDebuggingException(e);
}

if (response?.Content?.Result == null) {
return (false, ASF.GlobalDatabase.CachedBadBots);
Expand Down
5 changes: 4 additions & 1 deletion ArchiSteamFarm/Steam/Exchange/Trading.cs
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,10 @@ private async Task<ParseTradeResult> ParseTrade(TradeOffer tradeOffer) {

// Deny trades from bad steamIDs if user wishes to do so
if (ASF.GlobalConfig?.FilterBadBots ?? GlobalConfig.DefaultFilterBadBots) {
bool? isBadBot = await ArchiNet.IsBadBot(tradeOffer.OtherSteamID64).ConfigureAwait(false);
// Allow no longer than 10 seconds timeout for BadBot call, as we don't want to hold the trade offer for too long
using CancellationTokenSource cts = new(TimeSpan.FromSeconds(10));

bool? isBadBot = await ArchiNet.IsBadBot(tradeOffer.OtherSteamID64, cts.Token).ConfigureAwait(false);

if (isBadBot == true) {
Bot.ArchiLogger.LogGenericDebug(string.Format(CultureInfo.CurrentCulture, Strings.BotTradeOfferResult, tradeOffer.TradeOfferID, ParseTradeResult.EResult.Blacklisted, $"{nameof(tradeOffer.OtherSteamID64)} {tradeOffer.OtherSteamID64}"));
Expand Down

0 comments on commit cb8668f

Please sign in to comment.