Skip to content

Commit

Permalink
Closes #3203
Browse files Browse the repository at this point in the history
When excessive amount of "missing amounts", so items in the set was missing on our side, there was a possibility for our logic to classify a good trade as bad one, because we didn't fill in enough holes, as the subtraction in the condition was calculated on each loop rather than once initially.

Since this could only worsen the neutrality score, but never improve it (as the amounts were sorted ascending), there was no abusive possibility due to that, only ignoring otherwise valid trades classifying them as worse than they were in reality.
  • Loading branch information
JustArchi committed May 13, 2024
1 parent b438e38 commit 3b2ca10
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
24 changes: 24 additions & 0 deletions ArchiSteamFarm.Tests/Trading.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,30 @@ public void ExploitingNewSetsIsFairButNotNeutral() {
Assert.IsFalse(IsTradeNeutralOrBetter(inventory, itemsToGive, itemsToReceive));
}

[TestMethod]
public void Issue3203() {
HashSet<Asset> inventory = [
CreateItem(1, amount: 2),
CreateItem(2, amount: 6),
CreateItem(3),
CreateItem(4)
];

HashSet<Asset> itemsToGive = [
CreateItem(1),
CreateItem(2, amount: 2)
];

HashSet<Asset> itemsToReceive = [
CreateItem(5),
CreateItem(6),
CreateItem(7)
];

Assert.IsTrue(IsFairExchange(itemsToGive, itemsToReceive));
Assert.IsTrue(IsTradeNeutralOrBetter(inventory, itemsToGive, itemsToReceive));
}

[TestMethod]
public void MismatchRarityIsNotFair() {
HashSet<Asset> itemsToGive = [
Expand Down
4 changes: 3 additions & 1 deletion ArchiSteamFarm/Steam/Exchange/Trading.cs
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,9 @@ public static bool IsTradeNeutralOrBetter(IReadOnlyCollection<Asset> inventory,
}

// Otherwise, fill the missing holes in our data if needed, since we actually had zeros there
for (byte i = 0; i < afterAmounts.Count - beforeAmounts.Count; i++) {
byte missingAmounts = (byte) (afterAmounts.Count - beforeAmounts.Count);

for (byte i = 0; i < missingAmounts; i++) {
beforeAmounts.Insert(0, 0);
}

Expand Down

0 comments on commit 3b2ca10

Please sign in to comment.