mirror of
https://github.com/JustArchiNET/ArchiSteamFarm.git
synced 2026-01-01 06:00:46 +00:00
Cut excessive data from announcement
Now that we don't need to transmit whole inventory to the backend anymore, we can cut it to matchable types only
This commit is contained in:
@@ -4,7 +4,7 @@
|
|||||||
// / ___ \ | | | (__ | | | || | ___) || |_| __/| (_| || | | | | || _|| (_| || | | | | | | |
|
// / ___ \ | | | (__ | | | || | ___) || |_| __/| (_| || | | | | || _|| (_| || | | | | | | |
|
||||||
// /_/ \_\|_| \___||_| |_||_||____/ \__|\___| \__,_||_| |_| |_||_| \__,_||_| |_| |_| |_|
|
// /_/ \_\|_| \___||_| |_||_||____/ \__|\___| \__,_||_| |_| |_||_| \__,_||_| |_| |_| |_|
|
||||||
// |
|
// |
|
||||||
// Copyright 2015-2022 Łukasz "JustArchi" Domeradzki
|
// Copyright 2015-2023 Łukasz "JustArchi" Domeradzki
|
||||||
// Contact: JustArchi@JustArchi.net
|
// Contact: JustArchi@JustArchi.net
|
||||||
// |
|
// |
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
@@ -37,7 +37,7 @@ using ArchiSteamFarm.Web.Responses;
|
|||||||
namespace ArchiSteamFarm.OfficialPlugins.ItemsMatcher;
|
namespace ArchiSteamFarm.OfficialPlugins.ItemsMatcher;
|
||||||
|
|
||||||
internal static class Backend {
|
internal static class Backend {
|
||||||
internal static async Task<BasicResponse?> AnnounceForListing(Bot bot, WebBrowser webBrowser, IReadOnlyList<Asset> inventory, IReadOnlyCollection<Asset.EType> acceptedMatchableTypes, string tradeToken, string? nickname = null, string? avatarHash = null) {
|
internal static async Task<BasicResponse?> AnnounceForListing(Bot bot, WebBrowser webBrowser, IReadOnlyCollection<AssetForListing> inventory, IReadOnlyCollection<Asset.EType> acceptedMatchableTypes, string tradeToken, string? nickname = null, string? avatarHash = null) {
|
||||||
ArgumentNullException.ThrowIfNull(bot);
|
ArgumentNullException.ThrowIfNull(bot);
|
||||||
ArgumentNullException.ThrowIfNull(webBrowser);
|
ArgumentNullException.ThrowIfNull(webBrowser);
|
||||||
|
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ internal sealed class AnnouncementRequest {
|
|||||||
[JsonProperty(Required = Required.Always)]
|
[JsonProperty(Required = Required.Always)]
|
||||||
private readonly string TradeToken;
|
private readonly string TradeToken;
|
||||||
|
|
||||||
internal AnnouncementRequest(Guid guid, ulong steamID, string tradeToken, IReadOnlyList<Asset> inventory, IReadOnlyCollection<Asset.EType> matchableTypes, bool matchEverything, byte maxTradeHoldDuration, string? nickname = null, string? avatarHash = null) {
|
internal AnnouncementRequest(Guid guid, ulong steamID, string tradeToken, IReadOnlyCollection<AssetForListing> inventory, IReadOnlyCollection<Asset.EType> matchableTypes, bool matchEverything, byte maxTradeHoldDuration, string? nickname = null, string? avatarHash = null) {
|
||||||
if (guid == Guid.Empty) {
|
if (guid == Guid.Empty) {
|
||||||
throw new ArgumentOutOfRangeException(nameof(guid));
|
throw new ArgumentOutOfRangeException(nameof(guid));
|
||||||
}
|
}
|
||||||
@@ -83,22 +83,10 @@ internal sealed class AnnouncementRequest {
|
|||||||
throw new ArgumentNullException(nameof(matchableTypes));
|
throw new ArgumentNullException(nameof(matchableTypes));
|
||||||
}
|
}
|
||||||
|
|
||||||
uint index = 0;
|
|
||||||
ulong previousAssetID = 0;
|
|
||||||
|
|
||||||
Guid = guid;
|
Guid = guid;
|
||||||
SteamID = steamID;
|
SteamID = steamID;
|
||||||
TradeToken = tradeToken;
|
TradeToken = tradeToken;
|
||||||
|
Inventory = inventory.ToImmutableHashSet();
|
||||||
HashSet<AssetForListing> assetsForListing = new(inventory.Count);
|
|
||||||
|
|
||||||
foreach (Asset asset in inventory) {
|
|
||||||
assetsForListing.Add(new AssetForListing(asset, index++, previousAssetID));
|
|
||||||
|
|
||||||
previousAssetID = asset.AssetID;
|
|
||||||
}
|
|
||||||
|
|
||||||
Inventory = assetsForListing.ToImmutableHashSet();
|
|
||||||
MatchableTypes = matchableTypes.ToImmutableHashSet();
|
MatchableTypes = matchableTypes.ToImmutableHashSet();
|
||||||
MatchEverything = matchEverything;
|
MatchEverything = matchEverything;
|
||||||
MaxTradeHoldDuration = maxTradeHoldDuration;
|
MaxTradeHoldDuration = maxTradeHoldDuration;
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
// / ___ \ | | | (__ | | | || | ___) || |_| __/| (_| || | | | | || _|| (_| || | | | | | | |
|
// / ___ \ | | | (__ | | | || | ___) || |_| __/| (_| || | | | | || _|| (_| || | | | | | | |
|
||||||
// /_/ \_\|_| \___||_| |_||_||____/ \__|\___| \__,_||_| |_| |_||_| \__,_||_| |_| |_| |_|
|
// /_/ \_\|_| \___||_| |_||_||____/ \__|\___| \__,_||_| |_| |_||_| \__,_||_| |_| |_| |_|
|
||||||
// |
|
// |
|
||||||
// Copyright 2015-2022 Łukasz "JustArchi" Domeradzki
|
// Copyright 2015-2023 Łukasz "JustArchi" Domeradzki
|
||||||
// Contact: JustArchi@JustArchi.net
|
// Contact: JustArchi@JustArchi.net
|
||||||
// |
|
// |
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
@@ -208,6 +208,7 @@ internal sealed class RemoteCommunication : IAsyncDisposable, IDisposable {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// We require to fetch whole inventory as a list here, as we need to know the order for calculating index and previousAssetID
|
||||||
List<Asset> inventory;
|
List<Asset> inventory;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -228,8 +229,7 @@ internal sealed class RemoteCommunication : IAsyncDisposable, IDisposable {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// This is actual inventory
|
if (inventory.Count < MinItemsCount) {
|
||||||
if (inventory.Count(item => item.Tradable && acceptedMatchableTypes.Contains(item.Type)) < MinItemsCount) {
|
|
||||||
// We're not eligible, record this as a valid check
|
// We're not eligible, record this as a valid check
|
||||||
LastAnnouncement = DateTime.UtcNow;
|
LastAnnouncement = DateTime.UtcNow;
|
||||||
ShouldSendAnnouncementEarlier = ShouldSendHeartBeats = false;
|
ShouldSendAnnouncementEarlier = ShouldSendHeartBeats = false;
|
||||||
@@ -237,7 +237,34 @@ internal sealed class RemoteCommunication : IAsyncDisposable, IDisposable {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((inventory.Count == AnnouncedItems.Count) && inventory.All(item => AnnouncedItems.TryGetValue(item.AssetID, out uint amount) && (item.Amount == amount))) {
|
uint index = 0;
|
||||||
|
ulong previousAssetID = 0;
|
||||||
|
|
||||||
|
HashSet<AssetForListing> assetsForListing = new();
|
||||||
|
|
||||||
|
uint tradableCount = 0;
|
||||||
|
|
||||||
|
foreach (Asset asset in inventory) {
|
||||||
|
if (acceptedMatchableTypes.Contains(asset.Type)) {
|
||||||
|
if (asset.Tradable) {
|
||||||
|
tradableCount++;
|
||||||
|
}
|
||||||
|
|
||||||
|
assetsForListing.Add(new AssetForListing(asset, index++, previousAssetID));
|
||||||
|
}
|
||||||
|
|
||||||
|
previousAssetID = asset.AssetID;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tradableCount < MinItemsCount) {
|
||||||
|
// We're not eligible, record this as a valid check
|
||||||
|
LastAnnouncement = DateTime.UtcNow;
|
||||||
|
ShouldSendAnnouncementEarlier = ShouldSendHeartBeats = false;
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ShouldSendHeartBeats && (assetsForListing.Count == AnnouncedItems.Count) && assetsForListing.All(item => AnnouncedItems.TryGetValue(item.AssetID, out uint amount) && (item.Amount == amount))) {
|
||||||
// There is nothing new to announce, this is fine, skip the request
|
// There is nothing new to announce, this is fine, skip the request
|
||||||
LastAnnouncement = DateTime.UtcNow;
|
LastAnnouncement = DateTime.UtcNow;
|
||||||
ShouldSendAnnouncementEarlier = false;
|
ShouldSendAnnouncementEarlier = false;
|
||||||
@@ -266,10 +293,10 @@ internal sealed class RemoteCommunication : IAsyncDisposable, IDisposable {
|
|||||||
SignedInWithSteam = true;
|
SignedInWithSteam = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
Bot.ArchiLogger.LogGenericInfo(string.Format(CultureInfo.CurrentCulture, Localization.Strings.ListingAnnouncing, Bot.SteamID, nickname, inventory.Count));
|
Bot.ArchiLogger.LogGenericInfo(string.Format(CultureInfo.CurrentCulture, Localization.Strings.ListingAnnouncing, Bot.SteamID, nickname, assetsForListing.Count));
|
||||||
|
|
||||||
// ReSharper disable once RedundantSuppressNullableWarningExpression - required for .NET Framework
|
// ReSharper disable once RedundantSuppressNullableWarningExpression - required for .NET Framework
|
||||||
BasicResponse? response = await Backend.AnnounceForListing(Bot, WebBrowser, inventory, acceptedMatchableTypes, tradeToken!, nickname, avatarHash).ConfigureAwait(false);
|
BasicResponse? response = await Backend.AnnounceForListing(Bot, WebBrowser, assetsForListing, acceptedMatchableTypes, tradeToken!, nickname, avatarHash).ConfigureAwait(false);
|
||||||
|
|
||||||
if (response == null) {
|
if (response == null) {
|
||||||
// This is actually a network failure, so we'll stop sending heartbeats but not record it as valid check
|
// This is actually a network failure, so we'll stop sending heartbeats but not record it as valid check
|
||||||
@@ -333,7 +360,7 @@ internal sealed class RemoteCommunication : IAsyncDisposable, IDisposable {
|
|||||||
|
|
||||||
AnnouncedItems.Clear();
|
AnnouncedItems.Clear();
|
||||||
|
|
||||||
foreach (Asset item in inventory) {
|
foreach (AssetForListing item in assetsForListing) {
|
||||||
AnnouncedItems[item.AssetID] = item.Amount;
|
AnnouncedItems[item.AssetID] = item.Amount;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user