mirror of
https://github.com/JustArchiNET/ArchiSteamFarm.git
synced 2026-01-16 08:25:28 +00:00
Make descriptions optional, open constructors for plugins
In rare occurances, we might not have a description assigned to the item. This is most notable in inactive trade offers, but we permit this to happen even in inventory fetches. Assigning "default" description is unwanted if caller wants to have a way to determine that description wasn't there to begin with. It makes more sense to make it nullable and *expect* it to be null, then caller can do appropriate checking and decide what they want to do with that. Also open constructors for plugins usage in case they'd like to construct assets manually, e.g. for sending.
This commit is contained in:
@@ -230,28 +230,15 @@ public sealed class ArchiHandler : ClientMsgHandler {
|
||||
descriptions.Add(key, new InventoryDescription(description));
|
||||
}
|
||||
|
||||
foreach (CEcon_Asset? asset in response.assets) {
|
||||
if (!assetIDs.Add(asset.assetid)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
(ulong ClassID, ulong InstanceID) key = (asset.classid, asset.instanceid);
|
||||
|
||||
if (!descriptions.TryGetValue(key, out InventoryDescription? description)) {
|
||||
// Best effort only
|
||||
description = new InventoryDescription(appID, asset.classid, asset.instanceid);
|
||||
|
||||
descriptions.Add(key, description);
|
||||
}
|
||||
foreach (CEcon_Asset? asset in response.assets.Where(asset => assetIDs.Add(asset.assetid))) {
|
||||
InventoryDescription? description = descriptions.GetValueOrDefault((asset.classid, asset.instanceid));
|
||||
|
||||
// Extra bulletproofing against Steam showing us middle finger
|
||||
if ((tradableOnly && !description.Tradable) || (marketableOnly && !description.Marketable)) {
|
||||
if ((tradableOnly && (description?.Tradable != true)) || (marketableOnly && (description?.Marketable != true))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Asset convertedAsset = new(asset.appid, asset.contextid, asset.classid, (uint) asset.amount, description, asset.assetid, asset.instanceid);
|
||||
|
||||
yield return convertedAsset;
|
||||
yield return new Asset(asset.appid, asset.contextid, asset.classid, (uint) asset.amount, description, asset.assetid, asset.instanceid);
|
||||
}
|
||||
|
||||
if (!response.more_items) {
|
||||
|
||||
Reference in New Issue
Block a user