From 4cb3eabd4cafc666cb5b73e2d2419a779ef77cb9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Domeradzki?= Date: Wed, 27 Mar 2024 09:19:22 +0100 Subject: [PATCH] Add missing error-handling to GetMyInventoryAsync() --- .../Steam/Integration/ArchiHandler.cs | 47 ++++++++++--------- 1 file changed, 26 insertions(+), 21 deletions(-) diff --git a/ArchiSteamFarm/Steam/Integration/ArchiHandler.cs b/ArchiSteamFarm/Steam/Integration/ArchiHandler.cs index 0fd1017aa..5ed15a883 100644 --- a/ArchiSteamFarm/Steam/Integration/ArchiHandler.cs +++ b/ArchiSteamFarm/Steam/Integration/ArchiHandler.cs @@ -182,36 +182,41 @@ public sealed class ArchiHandler : ClientMsgHandler { throw new InvalidOperationException(nameof(Client.SteamID)); } - ulong steamID = Client.SteamID; - - ulong startAssetID = 0; - // We need to store asset IDs to make sure we won't get duplicate items HashSet? assetIDs = null; Dictionary<(ulong ClassID, ulong InstanceID), InventoryDescription>? descriptions = null; + CEcon_GetInventoryItemsWithDescriptions_Request request = new() { + appid = appID, + contextid = contextID, + + filters = new CEcon_GetInventoryItemsWithDescriptions_Request.FilterOptions { + tradable_only = tradableOnly, + marketable_only = marketableOnly + }, + + get_descriptions = true, + steamid = Client.SteamID, + count = itemsCountPerRequest + }; + while (true) { - ulong currentStartAssetID = startAssetID; + SteamUnifiedMessages.ServiceMethodResponse serviceMethodResponse; - CEcon_GetInventoryItemsWithDescriptions_Request request = new() { - appid = appID, - contextid = contextID, + try { + serviceMethodResponse = await UnifiedEconService.SendMessage(x => x.GetInventoryItemsWithDescriptions(request)).ToLongRunningTask().ConfigureAwait(false); + } catch (Exception e) { + ArchiLogger.LogGenericWarningException(e); - filters = new CEcon_GetInventoryItemsWithDescriptions_Request.FilterOptions { - tradable_only = tradableOnly, - marketable_only = marketableOnly - }, + throw new TimeoutException(string.Format(CultureInfo.CurrentCulture, Strings.ErrorObjectIsNull, nameof(serviceMethodResponse))); + } - get_descriptions = true, - steamid = steamID, - start_assetid = currentStartAssetID, - count = itemsCountPerRequest - }; + if (serviceMethodResponse.Result != EResult.OK) { + throw new TimeoutException(string.Format(CultureInfo.CurrentCulture, Strings.WarningFailedWithError, serviceMethodResponse.Result)); + } - SteamUnifiedMessages.ServiceMethodResponse genericResponse = await UnifiedEconService.SendMessage(x => x.GetInventoryItemsWithDescriptions(request)).ToLongRunningTask().ConfigureAwait(false); - - CEcon_GetInventoryItemsWithDescriptions_Response response = genericResponse.GetDeserializedResponse(); + CEcon_GetInventoryItemsWithDescriptions_Response response = serviceMethodResponse.GetDeserializedResponse(); if ((response.total_inventory_count == 0) || (response.assets.Count == 0)) { // Empty inventory @@ -268,7 +273,7 @@ public sealed class ArchiHandler : ClientMsgHandler { throw new NotSupportedException(string.Format(CultureInfo.CurrentCulture, Strings.ErrorObjectIsNull, nameof(response.last_assetid))); } - startAssetID = response.last_assetid; + request.start_assetid = response.last_assetid; } }