2024-03-17 00:06:13 +01:00
// ----------------------------------------------------------------------------------------------
2019-02-16 17:34:17 +01:00
// _ _ _ ____ _ _____
2017-11-18 17:27:06 +01:00
// / \ _ __ ___ | |__ (_)/ ___| | |_ ___ __ _ _ __ ___ | ___|__ _ _ __ _ __ ___
// / _ \ | '__|/ __|| '_ \ | |\___ \ | __|/ _ \ / _` || '_ ` _ \ | |_ / _` || '__|| '_ ` _ \
// / ___ \ | | | (__ | | | || | ___) || |_| __/| (_| || | | | | || _|| (_| || | | | | | | |
// /_/ \_\|_| \___||_| |_||_||____/ \__|\___| \__,_||_| |_| |_||_| \__,_||_| |_| |_| |_|
2024-03-17 00:06:13 +01:00
// ----------------------------------------------------------------------------------------------
2024-03-17 02:35:40 +01:00
// |
2024-01-03 00:23:27 +01:00
// Copyright 2015-2024 Łukasz "JustArchi" Domeradzki
2018-07-27 04:52:14 +02:00
// Contact: JustArchi@JustArchi.net
2024-03-17 02:35:40 +01:00
// |
2018-07-27 04:52:14 +02:00
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
2024-03-17 02:35:40 +01:00
// |
2018-07-27 04:52:14 +02:00
// http://www.apache.org/licenses/LICENSE-2.0
2024-03-17 02:35:40 +01:00
// |
2018-07-27 04:52:14 +02:00
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
2016-12-04 01:07:37 +01:00
using System ;
2024-01-03 13:46:54 +01:00
using System.Collections.Frozen ;
2016-12-04 01:07:37 +01:00
using System.Collections.Generic ;
2018-12-14 16:07:46 +01:00
using System.Collections.Immutable ;
2020-11-14 22:37:00 +01:00
using System.Globalization ;
2023-11-29 00:08:16 +01:00
using System.IO ;
2018-02-21 17:44:06 +01:00
using System.Linq ;
2021-11-18 21:16:47 +01:00
using System.Net ;
2024-02-21 03:09:36 +01:00
using System.Text.Json ;
2016-12-04 02:49:56 +01:00
using System.Threading ;
2016-12-04 01:07:37 +01:00
using System.Threading.Tasks ;
2022-12-15 18:46:37 +01:00
using ArchiSteamFarm.Core ;
2023-11-29 00:08:16 +01:00
using ArchiSteamFarm.IPC.Responses ;
2022-12-16 19:57:32 +01:00
using ArchiSteamFarm.Localization ;
2022-12-15 19:16:28 +01:00
using ArchiSteamFarm.OfficialPlugins.ItemsMatcher.Data ;
2021-05-08 01:37:22 +02:00
using ArchiSteamFarm.Steam ;
2021-05-08 12:49:46 +02:00
using ArchiSteamFarm.Steam.Cards ;
2021-05-08 01:37:22 +02:00
using ArchiSteamFarm.Steam.Data ;
using ArchiSteamFarm.Steam.Exchange ;
2022-12-17 17:23:20 +01:00
using ArchiSteamFarm.Steam.Integration ;
2021-05-08 01:37:22 +02:00
using ArchiSteamFarm.Steam.Storage ;
using ArchiSteamFarm.Storage ;
Use custom WebBrowser for items matcher
Now this is dictated by at least several reasons:
- Firstly, we must have a WebBrowser per bot, and not per ASF instance, as we preserve ASF STM cookies that are on per-bot basis, which are required e.g. for Announce
- At the same time we shouldn't use Bot's one, because there are settings like WebProxy that shouldn't be used in regards to our own server
- We also require higher timeout than default one, especially for Announce, but also Inventories
- Best we can do is optimize that to not create a WebBrowser for bots that are neither configured for public listing, nor match actively. Since those settings need to be explicitly turned on, we shouldn't be duplicating WebBrowser per each bot instance, but rather only few selected bots configured to participate.
2022-12-23 18:21:43 +01:00
using ArchiSteamFarm.Web ;
2022-12-17 17:23:20 +01:00
using ArchiSteamFarm.Web.Responses ;
2023-01-24 22:49:41 +01:00
using SteamKit2 ;
2023-05-16 21:27:36 +02:00
using SteamKit2.Internal ;
2016-12-04 01:07:37 +01:00
2022-12-15 18:46:37 +01:00
namespace ArchiSteamFarm.OfficialPlugins.ItemsMatcher ;
2021-11-10 21:23:24 +01:00
2022-06-19 18:24:52 +02:00
internal sealed class RemoteCommunication : IAsyncDisposable , IDisposable {
2023-01-24 22:49:41 +01:00
private const string MatchActivelyTradeOfferIDsStorageKey = $"{nameof(ItemsMatcher)}-{nameof(MatchActively)}-TradeOfferIDs" ;
2023-01-13 17:16:15 +01:00
private const byte MaxAnnouncementTTL = 60 ; // Maximum amount of minutes we can wait if the next announcement doesn't happen naturally
2024-01-03 00:23:27 +01:00
private const byte MaxInactivityDays = 14 ; // How long the server is willing to keep information about us for
2023-05-31 15:39:42 +02:00
private const uint MaxItemsCount = 500000 ; // Server is unwilling to accept more items than this
2023-05-28 12:50:37 +02:00
private const byte MaxTradeOffersActive = 5 ; // The actual upper limit is 30, but we should use lower amount to allow some bots to react before we hit the maximum allowed
2022-12-16 19:57:32 +01:00
private const byte MinAnnouncementTTL = 5 ; // Minimum amount of minutes we must wait before the next Announcement
2021-11-10 21:23:24 +01:00
private const byte MinHeartBeatTTL = 10 ; // Minimum amount of minutes we must wait before sending next HeartBeat
2023-06-03 17:50:50 +02:00
private const byte MinimumPasswordResetCooldownDays = 5 ; // As imposed by Steam limits
2023-11-29 00:08:16 +01:00
private const byte MinimumSteamGuardEnabledDays = 15 ; // As imposed by Steam limits
2022-12-16 19:57:32 +01:00
private const byte MinPersonaStateTTL = 5 ; // Minimum amount of minutes we must wait before requesting persona state update
2021-11-10 21:23:24 +01:00
2024-03-17 02:29:04 +01:00
private static readonly FrozenSet < EAssetType > AcceptedMatchableTypes = new HashSet < EAssetType > ( 4 ) {
EAssetType . Emoticon ,
EAssetType . FoilTradingCard ,
EAssetType . ProfileBackground ,
EAssetType . TradingCard
2024-01-03 13:46:54 +01:00
} . ToFrozenSet ( ) ;
2021-11-10 21:23:24 +01:00
private readonly Bot Bot ;
2022-12-15 18:46:37 +01:00
private readonly Timer ? HeartBeatTimer ;
2023-01-21 23:23:08 +01:00
2022-12-16 19:57:32 +01:00
private readonly SemaphoreSlim MatchActivelySemaphore = new ( 1 , 1 ) ;
2022-02-03 17:33:04 +01:00
private readonly Timer ? MatchActivelyTimer ;
2021-11-10 21:23:24 +01:00
private readonly SemaphoreSlim RequestsSemaphore = new ( 1 , 1 ) ;
2023-01-18 23:11:17 +01:00
private readonly WebBrowser WebBrowser ;
2017-07-13 06:08:52 +02:00
2023-11-29 00:08:16 +01:00
private string BotCacheFilePath = > Path . Combine ( SharedInfo . ConfigDirectory , $"{Bot.BotName}.{nameof(ItemsMatcher)}.cache" ) ;
private BotCache ? BotCache ;
2022-12-16 19:57:32 +01:00
private DateTime LastAnnouncement ;
2021-11-10 21:23:24 +01:00
private DateTime LastHeartBeat ;
private DateTime LastPersonaStateRequest ;
2022-12-16 19:57:32 +01:00
private bool ShouldSendAnnouncementEarlier ;
2021-11-10 21:23:24 +01:00
private bool ShouldSendHeartBeats ;
2022-12-17 17:23:20 +01:00
private bool SignedInWithSteam ;
2016-12-04 02:08:45 +01:00
2022-02-03 17:33:04 +01:00
internal RemoteCommunication ( Bot bot ) {
2022-12-15 18:46:37 +01:00
ArgumentNullException . ThrowIfNull ( bot ) ;
2016-12-04 02:08:45 +01:00
2022-12-15 18:46:37 +01:00
Bot = bot ;
2022-12-27 03:13:07 +01:00
WebBrowser = new WebBrowser ( bot . ArchiLogger , ASF . GlobalConfig ? . WebProxy , true ) ;
Use custom WebBrowser for items matcher
Now this is dictated by at least several reasons:
- Firstly, we must have a WebBrowser per bot, and not per ASF instance, as we preserve ASF STM cookies that are on per-bot basis, which are required e.g. for Announce
- At the same time we shouldn't use Bot's one, because there are settings like WebProxy that shouldn't be used in regards to our own server
- We also require higher timeout than default one, especially for Announce, but also Inventories
- Best we can do is optimize that to not create a WebBrowser for bots that are neither configured for public listing, nor match actively. Since those settings need to be explicitly turned on, we shouldn't be duplicating WebBrowser per each bot instance, but rather only few selected bots configured to participate.
2022-12-23 18:21:43 +01:00
2023-01-18 23:11:17 +01:00
if ( Bot . BotConfig . TradingPreferences . HasFlag ( BotConfig . ETradingPreferences . SteamTradeMatcher ) & & Bot . BotConfig . RemoteCommunication . HasFlag ( BotConfig . ERemoteCommunication . PublicListing ) ) {
2022-12-15 18:46:37 +01:00
HeartBeatTimer = new Timer (
2023-11-29 00:08:16 +01:00
OnHeartBeatTimer ,
2022-02-03 17:33:04 +01:00
null ,
2022-12-16 19:57:32 +01:00
TimeSpan . FromMinutes ( 1 ) + TimeSpan . FromSeconds ( ASF . LoadBalancingDelay * Bot . Bots ? . Count ? ? 0 ) ,
2022-12-15 18:46:37 +01:00
TimeSpan . FromMinutes ( 1 )
2022-02-03 17:33:04 +01:00
) ;
}
2022-12-15 18:46:37 +01:00
if ( Bot . BotConfig . TradingPreferences . HasFlag ( BotConfig . ETradingPreferences . MatchActively ) ) {
if ( ( ASF . GlobalConfig ? . LicenseID ! = null ) & & ( ASF . GlobalConfig . LicenseID ! = Guid . Empty ) ) {
MatchActivelyTimer = new Timer (
MatchActively ,
null ,
TimeSpan . FromHours ( 1 ) + TimeSpan . FromSeconds ( ASF . LoadBalancingDelay * Bot . Bots ? . Count ? ? 0 ) ,
TimeSpan . FromHours ( 6 )
) ;
} else {
2022-12-16 19:57:32 +01:00
bot . ArchiLogger . LogGenericError ( string . Format ( CultureInfo . CurrentCulture , Strings . WarningNoLicense , nameof ( BotConfig . ETradingPreferences . MatchActively ) ) ) ;
2022-12-15 18:46:37 +01:00
}
}
2021-11-10 21:23:24 +01:00
}
2022-06-19 18:24:52 +02:00
public void Dispose ( ) {
2023-11-29 00:08:16 +01:00
// Dispose timers first so we won't launch new events
2022-12-15 18:46:37 +01:00
HeartBeatTimer ? . Dispose ( ) ;
Use custom WebBrowser for items matcher
Now this is dictated by at least several reasons:
- Firstly, we must have a WebBrowser per bot, and not per ASF instance, as we preserve ASF STM cookies that are on per-bot basis, which are required e.g. for Announce
- At the same time we shouldn't use Bot's one, because there are settings like WebProxy that shouldn't be used in regards to our own server
- We also require higher timeout than default one, especially for Announce, but also Inventories
- Best we can do is optimize that to not create a WebBrowser for bots that are neither configured for public listing, nor match actively. Since those settings need to be explicitly turned on, we shouldn't be duplicating WebBrowser per each bot instance, but rather only few selected bots configured to participate.
2022-12-23 18:21:43 +01:00
if ( MatchActivelyTimer ! = null ) {
// ReSharper disable once SuspiciousLockOverSynchronizationPrimitive - this is not a mistake, we need extra synchronization, and we can re-use the semaphore object for that
lock ( MatchActivelySemaphore ) {
MatchActivelyTimer . Dispose ( ) ;
}
}
2023-11-29 00:08:16 +01:00
// Ensure the semaphores are closed, then dispose the rest
try {
MatchActivelySemaphore . Wait ( ) ;
} catch ( ObjectDisposedException ) {
// Ignored, this is fine
}
try {
RequestsSemaphore . Wait ( ) ;
} catch ( ObjectDisposedException ) {
// Ignored, this is fine
}
BotCache ? . Dispose ( ) ;
MatchActivelySemaphore . Dispose ( ) ;
RequestsSemaphore . Dispose ( ) ;
WebBrowser . Dispose ( ) ;
2022-06-19 18:24:52 +02:00
}
2021-11-10 21:23:24 +01:00
public async ValueTask DisposeAsync ( ) {
2023-02-23 17:20:08 +01:00
// Dispose timers first so we won't launch new events
2022-12-15 18:46:37 +01:00
if ( HeartBeatTimer ! = null ) {
await HeartBeatTimer . DisposeAsync ( ) . ConfigureAwait ( false ) ;
}
2022-02-03 17:33:04 +01:00
if ( MatchActivelyTimer ! = null ) {
2022-12-17 18:27:41 +01:00
// ReSharper disable once SuspiciousLockOverSynchronizationPrimitive - this is not a mistake, we need extra synchronization, and we can re-use the semaphore object for that
lock ( MatchActivelySemaphore ) {
MatchActivelyTimer . Dispose ( ) ;
}
2022-02-03 17:33:04 +01:00
}
2023-02-23 17:20:08 +01:00
// Ensure the semaphores are closed, then dispose the rest
2023-11-29 00:08:16 +01:00
try {
await MatchActivelySemaphore . WaitAsync ( ) . ConfigureAwait ( false ) ;
} catch ( ObjectDisposedException ) {
// Ignored, this is fine
}
try {
await RequestsSemaphore . WaitAsync ( ) . ConfigureAwait ( false ) ;
} catch ( ObjectDisposedException ) {
// Ignored, this is fine
}
BotCache ? . Dispose ( ) ;
2023-02-23 17:20:08 +01:00
MatchActivelySemaphore . Dispose ( ) ;
RequestsSemaphore . Dispose ( ) ;
WebBrowser . Dispose ( ) ;
2021-11-10 21:23:24 +01:00
}
2020-04-18 17:52:11 +02:00
2022-12-16 19:57:32 +01:00
internal void OnNewItemsNotification ( ) = > ShouldSendAnnouncementEarlier = true ;
2019-04-05 14:29:35 +02:00
2021-11-10 21:23:24 +01:00
internal async Task OnPersonaState ( string? nickname = null , string? avatarHash = null ) {
2022-12-29 22:25:35 +01:00
if ( ! Bot . BotConfig . RemoteCommunication . HasFlag ( BotConfig . ERemoteCommunication . PublicListing ) | | ! Bot . BotConfig . TradingPreferences . HasFlag ( BotConfig . ETradingPreferences . SteamTradeMatcher ) ) {
return ;
}
2022-12-16 19:57:32 +01:00
if ( ( DateTime . UtcNow < LastAnnouncement . AddMinutes ( ShouldSendAnnouncementEarlier ? MinAnnouncementTTL : MaxAnnouncementTTL ) ) & & ShouldSendHeartBeats ) {
2021-11-10 21:23:24 +01:00
return ;
2019-05-19 15:38:06 +02:00
}
2017-11-26 19:08:48 +01:00
2023-01-18 22:52:25 +01:00
if ( MatchActivelySemaphore . CurrentCount = = 0 ) {
// We shouldn't bother with announcements while we're matching, it can wait until we're done
return ;
}
2021-11-10 21:23:24 +01:00
await RequestsSemaphore . WaitAsync ( ) . ConfigureAwait ( false ) ;
try {
2022-12-16 19:57:32 +01:00
if ( ( DateTime . UtcNow < LastAnnouncement . AddMinutes ( ShouldSendAnnouncementEarlier ? MinAnnouncementTTL : MaxAnnouncementTTL ) ) & & ShouldSendHeartBeats ) {
2017-03-19 21:56:36 +01:00
return ;
}
2023-01-18 22:52:25 +01:00
if ( MatchActivelySemaphore . CurrentCount = = 0 ) {
// We shouldn't bother with announcements while we're matching, it can wait until we're done
return ;
}
2021-11-10 21:23:24 +01:00
// Don't announce if we don't meet conditions
bool? eligible = await IsEligibleForListing ( ) . ConfigureAwait ( false ) ;
2016-12-04 02:49:56 +01:00
2021-11-10 21:23:24 +01:00
if ( ! eligible . HasValue ) {
// This is actually network failure, so we'll stop sending heartbeats but not record it as valid check
ShouldSendHeartBeats = false ;
2017-02-08 14:35:01 +01:00
2022-12-29 22:25:35 +01:00
Bot . ArchiLogger . LogGenericWarning ( string . Format ( CultureInfo . CurrentCulture , Strings . WarningFailedWithError , $"{nameof(IsEligibleForListing)}: {eligible?.ToString() ?? " null "}" ) ) ;
2021-11-10 21:23:24 +01:00
return ;
}
2018-12-15 00:27:15 +01:00
2021-11-10 21:23:24 +01:00
if ( ! eligible . Value ) {
2022-12-16 19:57:32 +01:00
// We're not eligible, record this as a valid check
LastAnnouncement = DateTime . UtcNow ;
ShouldSendAnnouncementEarlier = ShouldSendHeartBeats = false ;
2019-04-05 15:12:54 +02:00
2022-12-29 22:25:35 +01:00
Bot . ArchiLogger . LogGenericWarning ( string . Format ( CultureInfo . CurrentCulture , Strings . WarningFailedWithError , $"{nameof(IsEligibleForListing)}: {eligible.Value}" ) ) ;
2021-11-10 21:23:24 +01:00
return ;
}
2019-04-05 15:12:54 +02:00
2024-03-17 02:29:04 +01:00
HashSet < EAssetType > acceptedMatchableTypes = Bot . BotConfig . MatchableTypes . Where ( AcceptedMatchableTypes . Contains ) . ToHashSet ( ) ;
2022-12-15 18:46:37 +01:00
2022-12-16 19:57:32 +01:00
if ( acceptedMatchableTypes . Count = = 0 ) {
throw new InvalidOperationException ( nameof ( acceptedMatchableTypes ) ) ;
2021-11-10 21:23:24 +01:00
}
2019-04-05 15:12:54 +02:00
2022-12-16 19:57:32 +01:00
string? tradeToken = await Bot . ArchiHandler . GetTradeToken ( ) . ConfigureAwait ( false ) ;
2019-04-05 15:12:54 +02:00
2022-12-16 19:57:32 +01:00
if ( string . IsNullOrEmpty ( tradeToken ) ) {
// This is actually a network failure, so we'll stop sending heartbeats but not record it as valid check
2021-11-10 21:23:24 +01:00
ShouldSendHeartBeats = false ;
2019-04-05 15:12:54 +02:00
2022-12-16 19:57:32 +01:00
Bot . ArchiLogger . LogGenericWarning ( string . Format ( CultureInfo . CurrentCulture , Strings . WarningFailedWithError , nameof ( tradeToken ) ) ) ;
2021-11-10 21:23:24 +01:00
return ;
}
2018-12-15 00:27:15 +01:00
2023-01-14 15:08:28 +01:00
// We require to fetch whole inventory as a list here, as we need to know the order for calculating index and previousAssetID
2022-12-15 18:46:37 +01:00
List < Asset > inventory ;
2018-12-15 00:27:15 +01:00
2021-11-10 21:23:24 +01:00
try {
2024-03-17 02:57:25 +04:00
inventory = await Bot . ArchiHandler . GetMyInventoryAsync ( ) . ToListAsync ( ) . ConfigureAwait ( false ) ;
2024-03-27 19:55:07 +01:00
} catch ( TimeoutException e ) {
2022-12-16 19:57:32 +01:00
// This is actually a network failure, so we'll stop sending heartbeats but not record it as valid check
2021-11-10 21:23:24 +01:00
ShouldSendHeartBeats = false ;
Use IAsyncEnumerable for getting inventory (#1652)
* Use IAsyncEnumerable for getting inventory
* Don't suppress exceptions, catch them in ResponseUnpackBoosters
* Make sure we don't get duplicate assets during unpack
* Rewrite inventory filters to LINQ methods
* Add handling duplicate items, mark GetInventory as obsolete, catch exceptions from getting inventory errors
* Mark GetInventoryEnumerable as NotNull, don't check received inventory for null, use comparison with nullable values
* Use specific types of exceptions, log exceptions using LogGenericWarningException, handle IOException separately (without logging the exception), remove default null value
* Use old method signature for obsolete API
* Use error level for generic exceptions
* Fix wantedSets not being used
* Correct exception types, rename function
* Replace exception types
* Make SendTradeOfferAsync that accepts Func<Steam.Asset, bool> as a filter
* Fix missing targetSteamID in ResponseTransferByRealAppIDs
* Make parameter name readable
* Rename method
2020-02-22 20:03:22 +03:00
2022-12-16 19:57:32 +01:00
Bot . ArchiLogger . LogGenericWarningException ( e ) ;
2021-11-10 21:23:24 +01:00
return ;
} catch ( Exception e ) {
2022-12-16 19:57:32 +01:00
// This is actually a network failure, so we'll stop sending heartbeats but not record it as valid check
2021-11-10 21:23:24 +01:00
ShouldSendHeartBeats = false ;
Use IAsyncEnumerable for getting inventory (#1652)
* Use IAsyncEnumerable for getting inventory
* Don't suppress exceptions, catch them in ResponseUnpackBoosters
* Make sure we don't get duplicate assets during unpack
* Rewrite inventory filters to LINQ methods
* Add handling duplicate items, mark GetInventory as obsolete, catch exceptions from getting inventory errors
* Mark GetInventoryEnumerable as NotNull, don't check received inventory for null, use comparison with nullable values
* Use specific types of exceptions, log exceptions using LogGenericWarningException, handle IOException separately (without logging the exception), remove default null value
* Use old method signature for obsolete API
* Use error level for generic exceptions
* Fix wantedSets not being used
* Correct exception types, rename function
* Replace exception types
* Make SendTradeOfferAsync that accepts Func<Steam.Asset, bool> as a filter
* Fix missing targetSteamID in ResponseTransferByRealAppIDs
* Make parameter name readable
* Rename method
2020-02-22 20:03:22 +03:00
2022-12-16 19:57:32 +01:00
Bot . ArchiLogger . LogGenericException ( e ) ;
2021-11-10 21:23:24 +01:00
return ;
}
2017-02-08 14:35:01 +01:00
2023-01-14 23:08:13 +01:00
if ( inventory . Count = = 0 ) {
2022-12-16 19:57:32 +01:00
// We're not eligible, record this as a valid check
LastAnnouncement = DateTime . UtcNow ;
ShouldSendAnnouncementEarlier = ShouldSendHeartBeats = false ;
2016-12-04 02:49:56 +01:00
2021-11-10 21:23:24 +01:00
return ;
}
2018-12-20 17:40:51 +01:00
2023-01-14 23:41:25 +01:00
bool matchEverything = Bot . BotConfig . TradingPreferences . HasFlag ( BotConfig . ETradingPreferences . MatchEverything ) ;
2023-11-29 00:08:16 +01:00
uint index = 0 ;
2023-01-14 15:08:28 +01:00
ulong previousAssetID = 0 ;
2023-12-11 23:55:13 +01:00
List < AssetForListing > assetsForListing = [ ] ;
2023-01-14 15:08:28 +01:00
2024-03-17 02:29:04 +01:00
Dictionary < ( uint RealAppID , EAssetType Type , EAssetRarity Rarity ) , bool > tradableSets = new ( ) ;
2023-01-14 15:08:28 +01:00
2023-01-14 22:24:21 +01:00
foreach ( Asset item in inventory ) {
2024-03-17 02:29:04 +01:00
if ( item is { AssetID : > 0 , Amount : > 0 , ClassID : > 0 , RealAppID : > 0 , Type : > EAssetType . Unknown , Rarity : > EAssetRarity . Unknown , IsSteamPointsShopItem : false } & & acceptedMatchableTypes . Contains ( item . Type ) ) {
2023-01-14 23:41:25 +01:00
// Only tradable assets matter for MatchEverything bots
if ( ! matchEverything | | item . Tradable ) {
2023-11-29 00:08:16 +01:00
assetsForListing . Add ( new AssetForListing ( item , index , previousAssetID ) ) ;
2023-01-14 23:41:25 +01:00
}
2023-01-14 22:24:21 +01:00
2023-01-14 23:41:25 +01:00
// But even for Fair bots, we should track and skip sets where we don't have any item to trade with
if ( ! matchEverything ) {
2024-03-17 02:29:04 +01:00
( uint RealAppID , EAssetType Type , EAssetRarity Rarity ) key = ( item . RealAppID , item . Type , item . Rarity ) ;
2023-01-14 15:08:28 +01:00
2023-01-14 23:57:45 +01:00
if ( tradableSets . TryGetValue ( key , out bool tradable ) ) {
if ( ! tradable & & item . Tradable ) {
tradableSets [ key ] = true ;
}
2023-01-14 23:41:25 +01:00
} else {
2023-01-14 23:57:45 +01:00
tradableSets [ key ] = item . Tradable ;
2023-01-14 23:41:25 +01:00
}
2023-01-14 22:24:21 +01:00
}
2023-01-14 15:08:28 +01:00
}
2023-11-29 00:08:16 +01:00
index + + ;
2023-01-14 22:24:21 +01:00
previousAssetID = item . AssetID ;
2023-01-14 15:08:28 +01:00
}
2023-01-14 23:08:13 +01:00
if ( assetsForListing . Count = = 0 ) {
2023-01-14 15:08:28 +01:00
// We're not eligible, record this as a valid check
LastAnnouncement = DateTime . UtcNow ;
ShouldSendAnnouncementEarlier = ShouldSendHeartBeats = false ;
return ;
}
2023-01-14 23:41:25 +01:00
// We can now skip sets where we don't have any item to trade with, MatchEverything bots are already filtered to tradable only
if ( ! matchEverything ) {
2023-01-21 20:32:42 +01:00
assetsForListing . RemoveAll ( item = > tradableSets . TryGetValue ( ( item . RealAppID , item . Type , item . Rarity ) , out bool tradable ) & & ! tradable ) ;
2023-01-14 22:24:21 +01:00
2023-01-14 23:57:45 +01:00
if ( assetsForListing . Count = = 0 ) {
// We're not eligible, record this as a valid check
LastAnnouncement = DateTime . UtcNow ;
ShouldSendAnnouncementEarlier = ShouldSendHeartBeats = false ;
2023-01-14 22:24:21 +01:00
2023-01-14 23:57:45 +01:00
return ;
2023-01-14 22:24:21 +01:00
}
}
2023-11-29 14:26:57 +01:00
BotCache ? ? = await BotCache . CreateOrLoad ( BotCacheFilePath ) . ConfigureAwait ( false ) ;
string inventoryChecksumBeforeDeduplication = Backend . GenerateChecksumFor ( assetsForListing ) ;
2024-01-03 00:23:27 +01:00
if ( BotCache . LastRequestAt . HasValue & & ( DateTime . UtcNow . Subtract ( BotCache . LastRequestAt . Value ) . TotalDays < MaxInactivityDays ) & & ( tradeToken = = BotCache . LastAnnouncedTradeToken ) & & ! string . IsNullOrEmpty ( BotCache . LastInventoryChecksumBeforeDeduplication ) ) {
2023-11-29 14:26:57 +01:00
if ( inventoryChecksumBeforeDeduplication = = BotCache . LastInventoryChecksumBeforeDeduplication ) {
// We've determined our state to be the same, we can skip announce entirely and start sending heartbeats exclusively
bool triggerImmediately = ! ShouldSendHeartBeats ;
LastAnnouncement = DateTime . UtcNow ;
ShouldSendAnnouncementEarlier = false ;
ShouldSendHeartBeats = true ;
if ( triggerImmediately ) {
Utilities . InBackground ( ( ) = > OnHeartBeatTimer ( ) ) ;
}
return ;
}
}
2022-12-17 17:23:20 +01:00
if ( ! SignedInWithSteam ) {
2022-12-23 22:42:41 +01:00
HttpStatusCode ? signInWithSteam = await ArchiNet . SignInWithSteam ( Bot , WebBrowser ) . ConfigureAwait ( false ) ;
2022-12-17 17:23:20 +01:00
if ( signInWithSteam = = null ) {
// This is actually a network failure, so we'll stop sending heartbeats but not record it as valid check
ShouldSendHeartBeats = false ;
return ;
}
if ( ! signInWithSteam . Value . IsSuccessCode ( ) ) {
// SignIn procedure failed and it wasn't a network error, hold off with future tries at least for a full day
LastAnnouncement = DateTime . UtcNow . AddDays ( 1 ) ;
ShouldSendHeartBeats = false ;
return ;
}
SignedInWithSteam = true ;
}
2023-11-29 00:08:16 +01:00
if ( ! matchEverything ) {
// We should deduplicate our sets before sending them to the server, for doing that we'll use ASFB set parts data
2023-12-11 23:55:13 +01:00
HashSet < uint > realAppIDs = [ ] ;
2024-03-17 02:29:04 +01:00
Dictionary < ( uint RealAppID , EAssetType Type , EAssetRarity Rarity ) , Dictionary < ulong , uint > > state = new ( ) ;
2018-12-15 00:27:15 +01:00
2023-11-29 00:08:16 +01:00
foreach ( AssetForListing asset in assetsForListing ) {
realAppIDs . Add ( asset . RealAppID ) ;
2022-12-16 19:57:32 +01:00
2024-03-17 02:29:04 +01:00
( uint RealAppID , EAssetType Type , EAssetRarity Rarity ) key = ( asset . RealAppID , asset . Type , asset . Rarity ) ;
2022-12-23 22:42:41 +01:00
2023-11-29 00:08:16 +01:00
if ( state . TryGetValue ( key , out Dictionary < ulong , uint > ? set ) ) {
2024-02-28 21:40:54 +01:00
set [ asset . ClassID ] = set . GetValueOrDefault ( asset . ClassID ) + asset . Amount ;
2023-11-29 00:08:16 +01:00
} else {
state [ key ] = new Dictionary < ulong , uint > { { asset . ClassID , asset . Amount } } ;
}
}
2016-12-04 02:49:56 +01:00
2023-11-29 00:08:16 +01:00
ObjectResponse < GenericResponse < ImmutableHashSet < SetPart > > > ? setPartsResponse = await Backend . GetSetParts ( WebBrowser , Bot . SteamID , acceptedMatchableTypes , realAppIDs ) . ConfigureAwait ( false ) ;
2022-12-15 18:46:37 +01:00
2023-12-02 19:36:34 +01:00
if ( setPartsResponse = = null ) {
// This is actually a network failure, so we'll stop sending heartbeats but not record it as valid check
ShouldSendHeartBeats = false ;
Bot . ArchiLogger . LogGenericWarning ( string . Format ( CultureInfo . CurrentCulture , Strings . ErrorObjectIsNull , nameof ( setPartsResponse ) ) ) ;
return ;
}
if ( setPartsResponse . StatusCode . IsRedirectionCode ( ) ) {
ShouldSendHeartBeats = false ;
Bot . ArchiLogger . LogGenericWarning ( string . Format ( CultureInfo . CurrentCulture , Strings . WarningFailedWithError , setPartsResponse . StatusCode ) ) ;
if ( setPartsResponse . FinalUri . Host ! = ArchiWebHandler . SteamCommunityURL . Host ) {
ASF . ArchiLogger . LogGenericError ( string . Format ( CultureInfo . CurrentCulture , Strings . WarningUnknownValuePleaseReport , nameof ( setPartsResponse . FinalUri ) , setPartsResponse . FinalUri ) ) ;
return ;
}
// We've expected the result, not the redirection to the sign in, we need to authenticate again
SignedInWithSteam = false ;
return ;
}
if ( ! setPartsResponse . StatusCode . IsSuccessCode ( ) ) {
// ArchiNet told us that we've sent a bad request, so the process should restart from the beginning at later time
ShouldSendHeartBeats = false ;
Bot . ArchiLogger . LogGenericWarning ( string . Format ( CultureInfo . CurrentCulture , Strings . WarningFailedWithError , setPartsResponse . StatusCode ) ) ;
switch ( setPartsResponse . StatusCode ) {
case HttpStatusCode . Forbidden :
// ArchiNet told us to stop submitting data for now
LastAnnouncement = DateTime . UtcNow . AddYears ( 1 ) ;
return ;
case HttpStatusCode . TooManyRequests :
// ArchiNet told us to try again later
LastAnnouncement = DateTime . UtcNow . AddDays ( 1 ) ;
return ;
default :
// There is something wrong with our payload or the server, we shouldn't retry for at least several hours
LastAnnouncement = DateTime . UtcNow . AddHours ( 6 ) ;
return ;
}
}
if ( setPartsResponse . Content ? . Result = = null ) {
// This should never happen if we got the correct response
Bot . ArchiLogger . LogGenericError ( string . Format ( CultureInfo . CurrentCulture , Strings . WarningUnknownValuePleaseReport , nameof ( setPartsResponse ) , setPartsResponse . Content ? . Result ) ) ;
2023-11-29 00:08:16 +01:00
return ;
}
2022-12-23 22:42:41 +01:00
2024-03-17 02:29:04 +01:00
Dictionary < ( uint RealAppID , EAssetType Type , EAssetRarity Rarity ) , HashSet < ulong > > databaseSets = setPartsResponse . Content . Result . GroupBy ( static setPart = > ( setPart . RealAppID , setPart . Type , setPart . Rarity ) ) . ToDictionary ( static group = > group . Key , static group = > group . Select ( static setPart = > setPart . ClassID ) . ToHashSet ( ) ) ;
2023-11-29 00:08:16 +01:00
2023-12-23 23:37:29 +01:00
Dictionary < ulong , uint > setCopy = [ ] ;
2023-11-29 00:08:16 +01:00
2024-03-17 02:29:04 +01:00
foreach ( ( ( uint RealAppID , EAssetType Type , EAssetRarity Rarity ) key , Dictionary < ulong , uint > set ) in state ) {
2023-11-29 00:08:16 +01:00
if ( ! databaseSets . TryGetValue ( key , out HashSet < ulong > ? databaseSet ) ) {
// We have no clue about this set, we can't do any optimization
continue ;
}
if ( ( databaseSet . Count ! = set . Count ) | | ! databaseSet . SetEquals ( set . Keys ) ) {
// User either has more or less classIDs than we know about, we can't optimize this
continue ;
}
// User has all classIDs we know about, we can deduplicate his items based on lowest count
setCopy . Clear ( ) ;
uint minimumAmount = uint . MaxValue ;
foreach ( ( ulong classID , uint amount ) in set ) {
if ( amount < minimumAmount ) {
minimumAmount = amount ;
}
2023-12-23 23:37:29 +01:00
setCopy [ classID ] = amount ;
2023-11-29 00:08:16 +01:00
}
foreach ( ( ulong classID , uint amount ) in setCopy ) {
if ( minimumAmount > = amount ) {
set . Remove ( classID ) ;
continue ;
}
set [ classID ] = amount - minimumAmount ;
}
}
2023-12-11 23:55:13 +01:00
HashSet < AssetForListing > assetsForListingFiltered = [ ] ;
2023-11-29 00:08:16 +01:00
foreach ( AssetForListing asset in assetsForListing . Where ( asset = > state . TryGetValue ( ( asset . RealAppID , asset . Type , asset . Rarity ) , out Dictionary < ulong , uint > ? setState ) & & setState . TryGetValue ( asset . ClassID , out uint targetAmount ) & & ( targetAmount > 0 ) ) . OrderByDescending ( static asset = > asset . Tradable ) . ThenByDescending ( static asset = > asset . Index ) ) {
2024-03-17 02:29:04 +01:00
( uint RealAppID , EAssetType Type , EAssetRarity Rarity ) key = ( asset . RealAppID , asset . Type , asset . Rarity ) ;
2023-11-29 00:08:16 +01:00
if ( ! state . TryGetValue ( key , out Dictionary < ulong , uint > ? setState ) | | ! setState . TryGetValue ( asset . ClassID , out uint targetAmount ) | | ( targetAmount = = 0 ) ) {
// We're not interested in this combination
continue ;
}
if ( asset . Amount > = targetAmount ) {
asset . Amount = targetAmount ;
if ( setState . Remove ( asset . ClassID ) & & ( setState . Count = = 0 ) ) {
state . Remove ( key ) ;
}
} else {
setState [ asset . ClassID ] = targetAmount - asset . Amount ;
}
assetsForListingFiltered . Add ( asset ) ;
}
assetsForListing = assetsForListingFiltered . OrderBy ( static asset = > asset . Index ) . ToList ( ) ;
if ( assetsForListing . Count = = 0 ) {
// We're not eligible, record this as a valid check
LastAnnouncement = DateTime . UtcNow ;
ShouldSendAnnouncementEarlier = ShouldSendHeartBeats = false ;
2022-12-17 17:23:20 +01:00
2023-11-29 14:26:57 +01:00
// There is a possibility that our inventory has changed even if our announced assets did not, record that
BotCache . LastInventoryChecksumBeforeDeduplication = inventoryChecksumBeforeDeduplication ;
2022-12-17 17:23:20 +01:00
return ;
}
2023-11-29 00:08:16 +01:00
}
2022-12-17 17:23:20 +01:00
2023-11-29 00:08:16 +01:00
if ( assetsForListing . Count > MaxItemsCount ) {
// We're not eligible, record this as a valid check
LastAnnouncement = DateTime . UtcNow ;
ShouldSendAnnouncementEarlier = ShouldSendHeartBeats = false ;
2023-11-29 14:26:57 +01:00
// There is a possibility that our inventory has changed even if our announced assets did not, record that
BotCache . LastInventoryChecksumBeforeDeduplication = inventoryChecksumBeforeDeduplication ;
2023-11-29 00:08:16 +01:00
Bot . ArchiLogger . LogGenericWarning ( string . Format ( CultureInfo . CurrentCulture , Strings . WarningFailedWithError , $"{nameof(assetsForListing)} > {MaxItemsCount}" ) ) ;
2022-12-17 17:23:20 +01:00
return ;
}
2023-11-29 00:08:16 +01:00
string checksum = Backend . GenerateChecksumFor ( assetsForListing ) ;
string? previousChecksum = BotCache . LastAnnouncedAssetsForListing . Count > 0 ? Backend . GenerateChecksumFor ( BotCache . LastAnnouncedAssetsForListing ) : null ;
2019-04-05 16:24:02 +02:00
2024-01-03 00:34:12 +01:00
if ( BotCache . LastRequestAt . HasValue & & ( DateTime . UtcNow . Subtract ( BotCache . LastRequestAt . Value ) . TotalDays < MaxInactivityDays ) & & ( tradeToken = = BotCache . LastAnnouncedTradeToken ) & & ( checksum = = previousChecksum ) ) {
2023-11-29 00:08:16 +01:00
// We've determined our state to be the same, we can skip announce entirely and start sending heartbeats exclusively
2023-11-29 14:26:57 +01:00
bool triggerImmediately = ! ShouldSendHeartBeats ;
2023-11-29 00:08:16 +01:00
LastAnnouncement = DateTime . UtcNow ;
ShouldSendAnnouncementEarlier = false ;
ShouldSendHeartBeats = true ;
2023-11-29 14:26:57 +01:00
if ( triggerImmediately ) {
Utilities . InBackground ( ( ) = > OnHeartBeatTimer ( ) ) ;
}
// There is a possibility that our inventory has changed even if our announced assets did not, record that
BotCache . LastInventoryChecksumBeforeDeduplication = inventoryChecksumBeforeDeduplication ;
2022-12-16 19:57:32 +01:00
2023-11-29 00:08:16 +01:00
return ;
}
2022-12-15 18:46:37 +01:00
2023-11-29 00:08:16 +01:00
if ( BotCache . LastAnnouncedAssetsForListing . Count > 0 ) {
Dictionary < ulong , AssetForListing > previousInventoryState = BotCache . LastAnnouncedAssetsForListing . ToDictionary ( static asset = > asset . AssetID ) ;
2022-12-15 18:46:37 +01:00
2023-11-29 13:21:12 +01:00
HashSet < AssetForListing > inventoryAddedChanged = assetsForListing . Where ( asset = > ! previousInventoryState . Remove ( asset . AssetID , out AssetForListing ? previousAsset ) | | ( asset . BackendHashCode ! = previousAsset . BackendHashCode ) ) . ToHashSet ( ) ;
2023-11-29 00:08:16 +01:00
2024-08-05 02:15:58 +02:00
Bot . ArchiLogger . LogGenericInfo ( Localization . Strings . FormatListingAnnouncing ( Bot . SteamID , nickname ? ? Bot . SteamID . ToString ( CultureInfo . InvariantCulture ) , assetsForListing . Count ) ) ;
2023-11-29 00:08:16 +01:00
2023-12-02 19:36:34 +01:00
ObjectResponse < GenericResponse < BackgroundTaskResponse > > ? diffResponse = null ;
Guid diffRequestID = Guid . Empty ;
for ( byte i = 0 ; i < WebBrowser . MaxTries ; i + + ) {
if ( diffRequestID ! = Guid . Empty ) {
diffResponse = await Backend . PollResult ( WebBrowser , Bot . SteamID , diffRequestID ) . ConfigureAwait ( false ) ;
} else {
diffResponse = await Backend . AnnounceDiffForListing ( WebBrowser , Bot . SteamID , inventoryAddedChanged , checksum , acceptedMatchableTypes , ( uint ) inventory . Count , matchEverything , tradeToken , previousInventoryState . Values , previousChecksum , nickname , avatarHash ) . ConfigureAwait ( false ) ;
}
if ( diffResponse = = null ) {
// This is actually a network failure, so we'll stop sending heartbeats but not record it as valid check
ShouldSendHeartBeats = false ;
Bot . ArchiLogger . LogGenericWarning ( string . Format ( CultureInfo . CurrentCulture , Strings . ErrorObjectIsNull , nameof ( diffResponse ) ) ) ;
2022-12-15 18:46:37 +01:00
2023-12-02 19:36:34 +01:00
return ;
}
if ( diffResponse . StatusCode . IsRedirectionCode ( ) ) {
ShouldSendHeartBeats = false ;
Bot . ArchiLogger . LogGenericWarning ( string . Format ( CultureInfo . CurrentCulture , Strings . WarningFailedWithError , diffResponse . StatusCode ) ) ;
if ( diffResponse . FinalUri . Host ! = ArchiWebHandler . SteamCommunityURL . Host ) {
ASF . ArchiLogger . LogGenericError ( string . Format ( CultureInfo . CurrentCulture , Strings . WarningUnknownValuePleaseReport , nameof ( diffResponse . FinalUri ) , diffResponse . FinalUri ) ) ;
return ;
}
// We've expected the result, not the redirection to the sign in, we need to authenticate again
SignedInWithSteam = false ;
return ;
}
if ( ! diffResponse . StatusCode . IsSuccessCode ( ) ) {
// ArchiNet told us that we've sent a bad request, so the process should restart from the beginning at later time
ShouldSendHeartBeats = false ;
Bot . ArchiLogger . LogGenericWarning ( string . Format ( CultureInfo . CurrentCulture , Strings . WarningFailedWithError , diffResponse . StatusCode ) ) ;
switch ( diffResponse . StatusCode ) {
case HttpStatusCode . Conflict :
// ArchiNet told us to do full announcement instead, the only non-OK response we accept
break ;
case HttpStatusCode . Forbidden :
// ArchiNet told us to stop submitting data for now
LastAnnouncement = DateTime . UtcNow . AddYears ( 1 ) ;
return ;
case HttpStatusCode . TooManyRequests :
// ArchiNet told us to try again later
LastAnnouncement = DateTime . UtcNow . AddDays ( 1 ) ;
return ;
default :
// There is something wrong with our payload or the server, we shouldn't retry for at least several hours
LastAnnouncement = DateTime . UtcNow . AddHours ( 6 ) ;
return ;
}
break ;
}
// Great, do we need to wait?
if ( diffResponse . Content ? . Result = = null ) {
// This should never happen if we got the correct response
Bot . ArchiLogger . LogGenericError ( string . Format ( CultureInfo . CurrentCulture , Strings . WarningUnknownValuePleaseReport , nameof ( diffResponse ) , diffResponse . Content ? . Result ) ) ;
return ;
}
if ( diffResponse . Content . Result . Finished ) {
break ;
}
diffRequestID = diffResponse . Content . Result . RequestID ;
diffResponse = null ;
}
if ( diffResponse = = null ) {
// We've waited long enough, something is definitely wrong with us or the backend
Bot . ArchiLogger . LogGenericWarning ( string . Format ( CultureInfo . CurrentCulture , Strings . WarningFailedWithError , nameof ( diffResponse ) ) ) ;
return ;
}
if ( diffResponse . StatusCode . IsSuccessCode ( ) & & diffResponse . Content is { Success : true , Result . Finished : true } ) {
2023-11-29 00:08:16 +01:00
// Our diff announce has succeeded, we have nothing to do further
Bot . ArchiLogger . LogGenericInfo ( Strings . Success ) ;
2023-01-12 11:42:04 +01:00
2023-12-02 19:36:34 +01:00
LastAnnouncement = LastHeartBeat = DateTime . UtcNow ;
ShouldSendAnnouncementEarlier = false ;
ShouldSendHeartBeats = true ;
2024-01-03 00:23:27 +01:00
2023-12-02 19:36:34 +01:00
BotCache . LastAnnouncedAssetsForListing . ReplaceWith ( assetsForListing ) ;
BotCache . LastAnnouncedTradeToken = tradeToken ;
BotCache . LastInventoryChecksumBeforeDeduplication = inventoryChecksumBeforeDeduplication ;
2024-01-03 00:23:27 +01:00
BotCache . LastRequestAt = LastHeartBeat ;
2023-12-02 19:36:34 +01:00
2023-11-29 00:08:16 +01:00
return ;
}
2023-01-12 11:42:04 +01:00
}
2024-08-05 02:15:58 +02:00
Bot . ArchiLogger . LogGenericInfo ( Localization . Strings . FormatListingAnnouncing ( Bot . SteamID , nickname ? ? Bot . SteamID . ToString ( CultureInfo . InvariantCulture ) , assetsForListing . Count ) ) ;
2023-11-29 00:08:16 +01:00
2023-12-02 19:36:34 +01:00
ObjectResponse < GenericResponse < BackgroundTaskResponse > > ? announceResponse = null ;
Guid announceRequestID = Guid . Empty ;
2023-11-29 00:08:16 +01:00
2023-12-02 19:36:34 +01:00
for ( byte i = 0 ; i < WebBrowser . MaxTries ; i + + ) {
if ( announceRequestID ! = Guid . Empty ) {
announceResponse = await Backend . PollResult ( WebBrowser , Bot . SteamID , announceRequestID ) . ConfigureAwait ( false ) ;
} else {
announceResponse = await Backend . AnnounceForListing ( WebBrowser , Bot . SteamID , assetsForListing , checksum , acceptedMatchableTypes , ( uint ) inventory . Count , matchEverything , tradeToken , nickname , avatarHash ) . ConfigureAwait ( false ) ;
}
2023-01-12 11:47:45 +01:00
2023-12-02 19:36:34 +01:00
if ( announceResponse = = null ) {
// This is actually a network failure, so we'll stop sending heartbeats but not record it as valid check
ShouldSendHeartBeats = false ;
Bot . ArchiLogger . LogGenericWarning ( string . Format ( CultureInfo . CurrentCulture , Strings . ErrorObjectIsNull , nameof ( announceResponse ) ) ) ;
2022-12-16 19:57:32 +01:00
2023-12-02 19:36:34 +01:00
return ;
}
2022-12-17 18:27:41 +01:00
2023-12-02 19:36:34 +01:00
if ( announceResponse . StatusCode . IsRedirectionCode ( ) ) {
ShouldSendHeartBeats = false ;
Bot . ArchiLogger . LogGenericWarning ( string . Format ( CultureInfo . CurrentCulture , Strings . WarningFailedWithError , announceResponse . StatusCode ) ) ;
2022-12-17 18:27:41 +01:00
2023-12-02 19:36:34 +01:00
if ( announceResponse . FinalUri . Host ! = ArchiWebHandler . SteamCommunityURL . Host ) {
ASF . ArchiLogger . LogGenericError ( string . Format ( CultureInfo . CurrentCulture , Strings . WarningUnknownValuePleaseReport , nameof ( announceResponse . FinalUri ) , announceResponse . FinalUri ) ) ;
2022-12-16 19:57:32 +01:00
2023-12-02 19:36:34 +01:00
return ;
}
2022-12-16 19:57:32 +01:00
2023-12-02 19:36:34 +01:00
// We've expected the result, not the redirection to the sign in, we need to authenticate again
SignedInWithSteam = false ;
2022-12-16 19:57:32 +01:00
2023-12-02 19:36:34 +01:00
return ;
}
2022-12-16 19:57:32 +01:00
2023-12-02 19:36:34 +01:00
if ( ! announceResponse . StatusCode . IsSuccessCode ( ) ) {
// ArchiNet told us that we've sent a bad request, so the process should restart from the beginning at later time
ShouldSendHeartBeats = false ;
Bot . ArchiLogger . LogGenericWarning ( string . Format ( CultureInfo . CurrentCulture , Strings . WarningFailedWithError , announceResponse . StatusCode ) ) ;
2022-12-16 19:57:32 +01:00
2023-12-02 19:36:34 +01:00
switch ( announceResponse . StatusCode ) {
case HttpStatusCode . Conflict :
// ArchiNet told us to that we've applied wrong deduplication logic, we can try again in a second
LastAnnouncement = DateTime . UtcNow . AddMinutes ( 5 ) ;
2022-12-16 19:57:32 +01:00
2023-12-02 19:36:34 +01:00
return ;
case HttpStatusCode . Forbidden :
// ArchiNet told us to stop submitting data for now
LastAnnouncement = DateTime . UtcNow . AddYears ( 1 ) ;
2022-12-23 16:34:42 +01:00
2023-12-02 19:36:34 +01:00
return ;
case HttpStatusCode . TooManyRequests :
// ArchiNet told us to try again later
LastAnnouncement = DateTime . UtcNow . AddDays ( 1 ) ;
2022-12-23 22:42:41 +01:00
2023-12-02 19:36:34 +01:00
return ;
default :
// There is something wrong with our payload or the server, we shouldn't retry for at least several hours
LastAnnouncement = DateTime . UtcNow . AddHours ( 6 ) ;
2022-12-23 16:34:42 +01:00
2023-12-02 19:36:34 +01:00
return ;
}
}
2022-12-23 16:34:42 +01:00
2023-12-02 19:36:34 +01:00
// Great, do we need to wait?
if ( announceResponse . Content ? . Result = = null ) {
// This should never happen if we got the correct response
Bot . ArchiLogger . LogGenericError ( string . Format ( CultureInfo . CurrentCulture , Strings . WarningUnknownValuePleaseReport , nameof ( announceResponse ) , announceResponse . Content ? . Result ) ) ;
2022-12-23 16:34:42 +01:00
2023-12-02 19:36:34 +01:00
return ;
}
2022-12-23 16:34:42 +01:00
2023-12-02 19:36:34 +01:00
if ( announceResponse . Content . Result . Finished ) {
break ;
}
2022-12-16 19:57:32 +01:00
2023-12-02 19:36:34 +01:00
announceRequestID = announceResponse . Content . Result . RequestID ;
announceResponse = null ;
}
2022-12-23 22:42:41 +01:00
2023-12-02 19:36:34 +01:00
if ( announceResponse = = null ) {
// We've waited long enough, something is definitely wrong with us or the backend
Bot . ArchiLogger . LogGenericWarning ( string . Format ( CultureInfo . CurrentCulture , Strings . WarningFailedWithError , nameof ( announceResponse ) ) ) ;
2023-11-29 00:08:16 +01:00
2023-12-02 19:36:34 +01:00
return ;
2022-12-16 19:57:32 +01:00
}
2023-12-02 19:36:34 +01:00
if ( announceResponse . StatusCode . IsSuccessCode ( ) & & announceResponse . Content is { Success : true , Result . Finished : true } ) {
// Our diff announce has succeeded, we have nothing to do further
Bot . ArchiLogger . LogGenericInfo ( Strings . Success ) ;
2023-11-29 00:08:16 +01:00
2023-12-02 19:36:34 +01:00
LastAnnouncement = LastHeartBeat = DateTime . UtcNow ;
ShouldSendAnnouncementEarlier = false ;
ShouldSendHeartBeats = true ;
2024-01-03 00:23:27 +01:00
2023-12-02 19:36:34 +01:00
BotCache . LastAnnouncedAssetsForListing . ReplaceWith ( assetsForListing ) ;
BotCache . LastAnnouncedTradeToken = tradeToken ;
BotCache . LastInventoryChecksumBeforeDeduplication = inventoryChecksumBeforeDeduplication ;
2024-01-03 00:23:27 +01:00
BotCache . LastRequestAt = LastHeartBeat ;
2023-12-02 19:36:34 +01:00
return ;
}
// Everything we've tried has failed
Bot . ArchiLogger . LogGenericWarning ( Strings . WarningFailed ) ;
} finally {
RequestsSemaphore . Release ( ) ;
2021-11-10 21:23:24 +01:00
}
2023-12-02 19:36:34 +01:00
}
2023-11-29 00:08:16 +01:00
2024-01-01 23:00:58 +01:00
internal void TriggerMatchActivelyEarlier ( ) {
if ( MatchActivelyTimer = = null ) {
Utilities . InBackground ( ( ) = > MatchActively ( ) ) ;
} else {
// ReSharper disable once SuspiciousLockOverSynchronizationPrimitive - this is not a mistake, we need extra synchronization, and we can re-use the semaphore object for that
lock ( MatchActivelySemaphore ) {
MatchActivelyTimer . Change ( TimeSpan . Zero , TimeSpan . FromHours ( 6 ) ) ;
}
}
}
2019-04-05 16:25:44 +02:00
2021-11-10 21:23:24 +01:00
private async Task < bool? > IsEligibleForListing ( ) {
2022-12-29 22:25:35 +01:00
// Bot must be eligible for matching
2021-11-10 21:23:24 +01:00
bool? isEligibleForMatching = await IsEligibleForMatching ( ) . ConfigureAwait ( false ) ;
2018-12-15 00:27:15 +01:00
2021-11-10 21:23:24 +01:00
if ( isEligibleForMatching ! = true ) {
return isEligibleForMatching ;
Implement ETradingPreferences.MatchActively
This will probably need a lot more tests, tweaking and bugfixing, but basic logic is:
- MatchActively added to TradingPreferences with value of 16
- User must also use SteamTradeMatcher, can't use MatchEverything
- User must have statistics enabled and be eligible for being listed (no requirement of having 100 items minimum)
Once all requirements are passed, statistics module will communicate with the listing and fetch match everything bots:
- The matching will start in 1h since ASF start and will repeat every day (right now it starts in 1 minute to aid debugging).
- Each matching is composed of up to 10 rounds maximum.
- In each round ASF will fetch our inventory and inventory of listed bots in order to find MatchableTypes items to be matched. If match is found, offer is being sent and confirmed automatically.
- Each set (composition of item type + appID it's from) can be matched in a single round only once, this is to minimize "items no longer available" as much as possible and also avoid a need to wait for each bot to react before sending all trades.
- Round ends when we try to match a total of 20 bots, or we hit no items to match in consecutive 10 tries with 10 different bots.
- If last round resulted in at least a single trade being sent, next round starts within 5 minutes since last one, otherwise matching ends and repeats the next day.
We'll see how it works in practice, expect a lot of follow-up commits, unless I won't have anything to fix or improve.
2018-11-29 18:35:58 +01:00
}
2022-12-29 22:25:35 +01:00
// Bot must have a public inventory
2021-11-10 21:23:24 +01:00
bool? hasPublicInventory = await Bot . HasPublicInventory ( ) . ConfigureAwait ( false ) ;
2019-06-19 18:50:26 +02:00
2021-11-10 21:23:24 +01:00
if ( hasPublicInventory ! = true ) {
2022-12-16 19:57:32 +01:00
Bot . ArchiLogger . LogGenericTrace ( string . Format ( CultureInfo . CurrentCulture , Strings . WarningFailedWithError , $"{nameof(Bot.HasPublicInventory)}: {hasPublicInventory?.ToString() ?? " null "}" ) ) ;
2019-06-19 18:50:26 +02:00
2021-11-10 21:23:24 +01:00
return hasPublicInventory ;
}
2019-06-19 18:50:26 +02:00
2021-11-10 21:23:24 +01:00
return true ;
}
2019-06-19 18:50:26 +02:00
2021-11-10 21:23:24 +01:00
private async Task < bool? > IsEligibleForMatching ( ) {
2023-02-11 15:58:15 +01:00
// Bot can't be limited
if ( Bot . IsAccountLimited ) {
Bot . ArchiLogger . LogGenericTrace ( string . Format ( CultureInfo . CurrentCulture , Strings . WarningFailedWithError , $"{nameof(Bot.IsAccountLimited)}: {Bot.IsAccountLimited}" ) ) ;
return false ;
}
// Bot can't be on lockdown
if ( Bot . IsAccountLocked ) {
Bot . ArchiLogger . LogGenericTrace ( string . Format ( CultureInfo . CurrentCulture , Strings . WarningFailedWithError , $"{nameof(Bot.IsAccountLocked)}: {Bot.IsAccountLocked}" ) ) ;
return false ;
}
2021-11-10 21:23:24 +01:00
// Bot must have ASF 2FA
if ( ! Bot . HasMobileAuthenticator ) {
2022-12-16 19:57:32 +01:00
Bot . ArchiLogger . LogGenericTrace ( string . Format ( CultureInfo . CurrentCulture , Strings . WarningFailedWithError , $"{nameof(Bot.HasMobileAuthenticator)}: {Bot.HasMobileAuthenticator}" ) ) ;
2019-06-19 18:50:26 +02:00
2021-11-10 21:23:24 +01:00
return false ;
2019-06-19 18:50:26 +02:00
}
2021-11-10 21:23:24 +01:00
// Bot must have at least one accepted matchable type set
if ( ( Bot . BotConfig . MatchableTypes . Count = = 0 ) | | Bot . BotConfig . MatchableTypes . All ( static type = > ! AcceptedMatchableTypes . Contains ( type ) ) ) {
2022-12-16 19:57:32 +01:00
Bot . ArchiLogger . LogGenericTrace ( string . Format ( CultureInfo . CurrentCulture , Strings . WarningFailedWithError , $"{nameof(Bot.BotConfig.MatchableTypes)}: {string.Join(" , ", Bot.BotConfig.MatchableTypes)}" ) ) ;
2018-12-15 00:27:15 +01:00
2021-11-10 21:23:24 +01:00
return false ;
}
2018-03-24 17:14:01 +01:00
2023-05-16 21:27:36 +02:00
// Bot must pass some general trading requirements
CCredentials_GetSteamGuardDetails_Response ? steamGuardStatus = await Bot . ArchiHandler . GetSteamGuardStatus ( ) . ConfigureAwait ( false ) ;
if ( steamGuardStatus = = null ) {
Bot . ArchiLogger . LogGenericTrace ( string . Format ( CultureInfo . CurrentCulture , Strings . WarningFailedWithError , $"{nameof(steamGuardStatus)}: null" ) ) ;
return null ;
}
// Bot must have SteamGuard active for at least 15 days
2023-05-18 12:01:48 +02:00
if ( ! steamGuardStatus . is_steamguard_enabled | | ( ( steamGuardStatus . timestamp_steamguard_enabled > 0 ) & & ( ( DateTimeOffset . UtcNow - DateTimeOffset . FromUnixTimeSeconds ( steamGuardStatus . timestamp_steamguard_enabled ) ) . TotalDays < MinimumSteamGuardEnabledDays ) ) ) {
2023-05-16 21:27:36 +02:00
Bot . ArchiLogger . LogGenericTrace ( string . Format ( CultureInfo . CurrentCulture , Strings . WarningFailedWithError , $"{nameof(steamGuardStatus.is_steamguard_enabled)}/{nameof(steamGuardStatus.timestamp_steamguard_enabled)}: {steamGuardStatus.is_steamguard_enabled}/{steamGuardStatus.timestamp_steamguard_enabled}" ) ) ;
return false ;
}
// Bot must have 2FA enabled for matching to work
if ( ! steamGuardStatus . is_twofactor_enabled ) {
Bot . ArchiLogger . LogGenericTrace ( string . Format ( CultureInfo . CurrentCulture , Strings . WarningFailedWithError , $"{nameof(steamGuardStatus.is_twofactor_enabled)}: false" ) ) ;
return false ;
}
2023-06-03 17:56:27 +02:00
CCredentials_LastCredentialChangeTime_Response ? credentialChangeTimeDetails = await Bot . ArchiHandler . GetCredentialChangeTimeDetails ( ) . ConfigureAwait ( false ) ;
2023-06-03 17:50:50 +02:00
2023-06-03 17:56:27 +02:00
if ( credentialChangeTimeDetails = = null ) {
Bot . ArchiLogger . LogGenericTrace ( string . Format ( CultureInfo . CurrentCulture , Strings . WarningFailedWithError , $"{nameof(credentialChangeTimeDetails)}: null" ) ) ;
2023-06-03 17:50:50 +02:00
return null ;
}
// Bot didn't change password in last 5 days
2023-06-03 17:56:27 +02:00
if ( ( credentialChangeTimeDetails . timestamp_last_password_reset > 0 ) & & ( ( DateTimeOffset . UtcNow - DateTimeOffset . FromUnixTimeSeconds ( credentialChangeTimeDetails . timestamp_last_password_reset ) ) . TotalDays < MinimumPasswordResetCooldownDays ) ) {
Bot . ArchiLogger . LogGenericTrace ( string . Format ( CultureInfo . CurrentCulture , Strings . WarningFailedWithError , $"{nameof(credentialChangeTimeDetails.timestamp_last_password_reset)}: {credentialChangeTimeDetails.timestamp_last_password_reset}" ) ) ;
2023-06-03 17:50:50 +02:00
return false ;
}
2021-11-10 21:23:24 +01:00
return true ;
}
2019-04-05 15:12:54 +02:00
2021-11-10 21:23:24 +01:00
private async void MatchActively ( object? state = null ) {
2022-12-15 18:46:37 +01:00
if ( ASF . GlobalConfig = = null ) {
throw new InvalidOperationException ( nameof ( ASF . GlobalConfig ) ) ;
}
if ( ! ASF . GlobalConfig . LicenseID . HasValue | | ( ASF . GlobalConfig . LicenseID = = Guid . Empty ) ) {
throw new InvalidOperationException ( nameof ( ASF . GlobalConfig . LicenseID ) ) ;
}
2024-01-01 22:58:54 +01:00
if ( ! Bot . IsConnectedAndLoggedOn | | Bot . BotConfig . TradingPreferences . HasFlag ( BotConfig . ETradingPreferences . MatchEverything ) ) {
2022-12-16 19:57:32 +01:00
Bot . ArchiLogger . LogGenericTrace ( Strings . ErrorAborted ) ;
2018-12-08 01:45:13 +01:00
2021-11-10 21:23:24 +01:00
return ;
2018-03-24 17:14:01 +01:00
}
Implement ETradingPreferences.MatchActively
This will probably need a lot more tests, tweaking and bugfixing, but basic logic is:
- MatchActively added to TradingPreferences with value of 16
- User must also use SteamTradeMatcher, can't use MatchEverything
- User must have statistics enabled and be eligible for being listed (no requirement of having 100 items minimum)
Once all requirements are passed, statistics module will communicate with the listing and fetch match everything bots:
- The matching will start in 1h since ASF start and will repeat every day (right now it starts in 1 minute to aid debugging).
- Each matching is composed of up to 10 rounds maximum.
- In each round ASF will fetch our inventory and inventory of listed bots in order to find MatchableTypes items to be matched. If match is found, offer is being sent and confirmed automatically.
- Each set (composition of item type + appID it's from) can be matched in a single round only once, this is to minimize "items no longer available" as much as possible and also avoid a need to wait for each bot to react before sending all trades.
- Round ends when we try to match a total of 20 bots, or we hit no items to match in consecutive 10 tries with 10 different bots.
- If last round resulted in at least a single trade being sent, next round starts within 5 minutes since last one, otherwise matching ends and repeats the next day.
We'll see how it works in practice, expect a lot of follow-up commits, unless I won't have anything to fix or improve.
2018-11-29 18:35:58 +01:00
2022-12-29 22:25:35 +01:00
bool? eligible = await IsEligibleForMatching ( ) . ConfigureAwait ( false ) ;
if ( eligible ! = true ) {
Bot . ArchiLogger . LogGenericWarning ( string . Format ( CultureInfo . CurrentCulture , Strings . WarningFailedWithError , $"{nameof(IsEligibleForMatching)}: {eligible?.ToString() ?? " null "}" ) ) ;
return ;
}
2024-03-17 02:29:04 +01:00
HashSet < EAssetType > acceptedMatchableTypes = Bot . BotConfig . MatchableTypes . Where ( AcceptedMatchableTypes . Contains ) . ToHashSet ( ) ;
2018-12-02 06:24:36 +01:00
2021-11-10 21:23:24 +01:00
if ( acceptedMatchableTypes . Count = = 0 ) {
2022-12-15 18:46:37 +01:00
Bot . ArchiLogger . LogNullError ( acceptedMatchableTypes ) ;
2018-12-15 00:27:15 +01:00
2021-11-10 21:23:24 +01:00
return ;
}
2018-12-15 00:27:15 +01:00
2021-11-10 21:23:24 +01:00
if ( ! await MatchActivelySemaphore . WaitAsync ( 0 ) . ConfigureAwait ( false ) ) {
2022-12-16 19:57:32 +01:00
Bot . ArchiLogger . LogGenericTrace ( Strings . ErrorAborted ) ;
Implement ETradingPreferences.MatchActively
This will probably need a lot more tests, tweaking and bugfixing, but basic logic is:
- MatchActively added to TradingPreferences with value of 16
- User must also use SteamTradeMatcher, can't use MatchEverything
- User must have statistics enabled and be eligible for being listed (no requirement of having 100 items minimum)
Once all requirements are passed, statistics module will communicate with the listing and fetch match everything bots:
- The matching will start in 1h since ASF start and will repeat every day (right now it starts in 1 minute to aid debugging).
- Each matching is composed of up to 10 rounds maximum.
- In each round ASF will fetch our inventory and inventory of listed bots in order to find MatchableTypes items to be matched. If match is found, offer is being sent and confirmed automatically.
- Each set (composition of item type + appID it's from) can be matched in a single round only once, this is to minimize "items no longer available" as much as possible and also avoid a need to wait for each bot to react before sending all trades.
- Round ends when we try to match a total of 20 bots, or we hit no items to match in consecutive 10 tries with 10 different bots.
- If last round resulted in at least a single trade being sent, next round starts within 5 minutes since last one, otherwise matching ends and repeats the next day.
We'll see how it works in practice, expect a lot of follow-up commits, unless I won't have anything to fix or improve.
2018-11-29 18:35:58 +01:00
2021-11-10 21:23:24 +01:00
return ;
}
2018-12-15 00:27:15 +01:00
2023-01-18 22:52:25 +01:00
bool tradesSent ;
2021-11-10 21:23:24 +01:00
try {
2022-12-16 19:57:32 +01:00
Bot . ArchiLogger . LogGenericInfo ( Strings . Starting ) ;
2018-11-29 21:05:40 +01:00
2024-02-04 22:28:59 +01:00
HttpStatusCode ? licenseStatus = await Backend . GetLicenseStatus ( ASF . GlobalConfig . LicenseID . Value , WebBrowser ) . ConfigureAwait ( false ) ;
if ( licenseStatus = = null ) {
Bot . ArchiLogger . LogGenericWarning ( string . Format ( CultureInfo . CurrentCulture , Strings . WarningFailedWithError , nameof ( licenseStatus ) ) ) ;
return ;
}
if ( ! licenseStatus . Value . IsSuccessCode ( ) ) {
Bot . ArchiLogger . LogGenericWarning ( string . Format ( CultureInfo . CurrentCulture , Strings . WarningFailedWithError , licenseStatus . Value ) ) ;
return ;
}
2023-12-21 23:46:42 +01:00
HashSet < Asset > assetsForMatching ;
2018-12-15 00:27:15 +01:00
2022-12-15 18:46:37 +01:00
try {
2024-03-17 02:29:04 +01:00
assetsForMatching = await Bot . ArchiHandler . GetMyInventoryAsync ( ) . Where ( item = > item is { AssetID : > 0 , Amount : > 0 , ClassID : > 0 , RealAppID : > 0 , Type : > EAssetType . Unknown , Rarity : > EAssetRarity . Unknown , IsSteamPointsShopItem : false } & & acceptedMatchableTypes . Contains ( item . Type ) & & ! Bot . BotDatabase . MatchActivelyBlacklistAppIDs . Contains ( item . RealAppID ) ) . ToHashSetAsync ( ) . ConfigureAwait ( false ) ;
2024-03-27 19:55:07 +01:00
} catch ( TimeoutException e ) {
2022-12-15 18:46:37 +01:00
Bot . ArchiLogger . LogGenericWarningException ( e ) ;
2023-12-21 23:46:42 +01:00
Bot . ArchiLogger . LogGenericWarning ( string . Format ( CultureInfo . CurrentCulture , Strings . WarningFailedWithError , nameof ( assetsForMatching ) ) ) ;
2022-12-15 18:46:37 +01:00
return ;
} catch ( Exception e ) {
Bot . ArchiLogger . LogGenericException ( e ) ;
2023-12-21 23:46:42 +01:00
Bot . ArchiLogger . LogGenericWarning ( string . Format ( CultureInfo . CurrentCulture , Strings . WarningFailedWithError , nameof ( assetsForMatching ) ) ) ;
2022-12-15 18:46:37 +01:00
return ;
}
2023-12-21 23:46:42 +01:00
if ( assetsForMatching . Count = = 0 ) {
Bot . ArchiLogger . LogGenericInfo ( string . Format ( CultureInfo . CurrentCulture , Strings . ErrorIsEmpty , nameof ( assetsForMatching ) ) ) ;
2022-12-15 18:46:37 +01:00
return ;
}
2022-12-23 15:08:36 +01:00
// Remove from our inventory items that can't be possibly matched due to no dupes to offer available
2024-03-17 02:29:04 +01:00
HashSet < ( uint RealAppID , EAssetType Type , EAssetRarity Rarity ) > setsToKeep = Trading . GetInventorySets ( assetsForMatching ) . Where ( static set = > set . Value . Any ( static amount = > amount > 1 ) ) . Select ( static set = > set . Key ) . ToHashSet ( ) ;
2022-12-23 15:08:36 +01:00
2024-01-01 23:22:19 +01:00
if ( assetsForMatching . RemoveWhere ( item = > ! setsToKeep . Contains ( ( item . RealAppID , item . Type , item . Rarity ) ) ) > 0 ) {
if ( assetsForMatching . Count = = 0 ) {
Bot . ArchiLogger . LogGenericInfo ( string . Format ( CultureInfo . CurrentCulture , Strings . ErrorIsEmpty , nameof ( assetsForMatching ) ) ) ;
2022-12-26 16:25:26 +01:00
2024-01-01 23:22:19 +01:00
return ;
}
2023-12-21 23:46:42 +01:00
}
// We should deduplicate our sets before sending them to the server, for doing that we'll use ASFB set parts data
HashSet < uint > realAppIDs = [ ] ;
2024-03-17 02:29:04 +01:00
Dictionary < ( uint RealAppID , EAssetType Type , EAssetRarity Rarity ) , Dictionary < ulong , uint > > setsState = new ( ) ;
2023-12-21 23:46:42 +01:00
foreach ( Asset asset in assetsForMatching ) {
realAppIDs . Add ( asset . RealAppID ) ;
2024-03-17 02:29:04 +01:00
( uint RealAppID , EAssetType Type , EAssetRarity Rarity ) key = ( asset . RealAppID , asset . Type , asset . Rarity ) ;
2023-12-21 23:46:42 +01:00
if ( setsState . TryGetValue ( key , out Dictionary < ulong , uint > ? set ) ) {
2024-02-28 21:40:54 +01:00
set [ asset . ClassID ] = set . GetValueOrDefault ( asset . ClassID ) + asset . Amount ;
2023-12-21 23:46:42 +01:00
} else {
setsState [ key ] = new Dictionary < ulong , uint > { { asset . ClassID , asset . Amount } } ;
}
}
if ( ! SignedInWithSteam ) {
HttpStatusCode ? signInWithSteam = await ArchiNet . SignInWithSteam ( Bot , WebBrowser ) . ConfigureAwait ( false ) ;
if ( ( signInWithSteam = = null ) | | ! signInWithSteam . Value . IsSuccessCode ( ) ) {
// This is actually a network failure
return ;
}
SignedInWithSteam = true ;
}
ObjectResponse < GenericResponse < ImmutableHashSet < SetPart > > > ? setPartsResponse = await Backend . GetSetParts ( WebBrowser , Bot . SteamID , acceptedMatchableTypes , realAppIDs ) . ConfigureAwait ( false ) ;
if ( setPartsResponse = = null ) {
// This is actually a network failure
Bot . ArchiLogger . LogGenericWarning ( string . Format ( CultureInfo . CurrentCulture , Strings . ErrorObjectIsNull , nameof ( setPartsResponse ) ) ) ;
return ;
}
if ( setPartsResponse . StatusCode . IsRedirectionCode ( ) ) {
Bot . ArchiLogger . LogGenericWarning ( string . Format ( CultureInfo . CurrentCulture , Strings . WarningFailedWithError , setPartsResponse . StatusCode ) ) ;
if ( setPartsResponse . FinalUri . Host ! = ArchiWebHandler . SteamCommunityURL . Host ) {
ASF . ArchiLogger . LogGenericError ( string . Format ( CultureInfo . CurrentCulture , Strings . WarningUnknownValuePleaseReport , nameof ( setPartsResponse . FinalUri ) , setPartsResponse . FinalUri ) ) ;
return ;
}
// We've expected the result, not the redirection to the sign in, we need to authenticate again
SignedInWithSteam = false ;
return ;
}
if ( ! setPartsResponse . StatusCode . IsSuccessCode ( ) ) {
Bot . ArchiLogger . LogGenericWarning ( string . Format ( CultureInfo . CurrentCulture , Strings . WarningFailedWithError , setPartsResponse . StatusCode ) ) ;
return ;
2022-12-26 16:25:26 +01:00
}
2022-12-23 15:08:36 +01:00
2023-12-21 23:46:42 +01:00
if ( setPartsResponse . Content ? . Result = = null ) {
// This should never happen if we got the correct response
Bot . ArchiLogger . LogGenericError ( string . Format ( CultureInfo . CurrentCulture , Strings . WarningUnknownValuePleaseReport , nameof ( setPartsResponse ) , setPartsResponse . Content ? . Result ) ) ;
2022-12-23 15:08:36 +01:00
return ;
}
2024-03-17 02:29:04 +01:00
Dictionary < ( uint RealAppID , EAssetType Type , EAssetRarity Rarity ) , HashSet < ulong > > databaseSets = setPartsResponse . Content . Result . GroupBy ( static setPart = > ( setPart . RealAppID , setPart . Type , setPart . Rarity ) ) . ToDictionary ( static group = > group . Key , static group = > group . Select ( static setPart = > setPart . ClassID ) . ToHashSet ( ) ) ;
2023-12-21 23:46:42 +01:00
2023-12-23 23:16:44 +01:00
Dictionary < ulong , uint > setCopy = [ ] ;
2023-12-21 23:46:42 +01:00
2024-03-17 02:29:04 +01:00
foreach ( ( ( uint RealAppID , EAssetType Type , EAssetRarity Rarity ) key , Dictionary < ulong , uint > set ) in setsState ) {
2023-12-22 00:18:52 +01:00
uint minimumAmount = uint . MaxValue ;
uint maximumAmount = uint . MinValue ;
foreach ( uint amount in set . Values ) {
if ( amount < minimumAmount ) {
minimumAmount = amount ;
}
if ( amount > maximumAmount ) {
maximumAmount = amount ;
}
}
if ( maximumAmount < 2 ) {
// We don't have anything to swap with, remove all entries from this set
set . Clear ( ) ;
continue ;
}
2023-12-21 23:46:42 +01:00
if ( ! databaseSets . TryGetValue ( key , out HashSet < ulong > ? databaseSet ) ) {
// We have no clue about this set, we can't do any optimization
continue ;
}
if ( ( databaseSet . Count ! = set . Count ) | | ! databaseSet . SetEquals ( set . Keys ) ) {
// User either has more or less classIDs than we know about, we can't optimize this
continue ;
}
2023-12-22 00:18:52 +01:00
if ( maximumAmount - minimumAmount < 2 ) {
// We don't have anything to swap with, remove all entries from this set
set . Clear ( ) ;
continue ;
}
2023-12-21 23:46:42 +01:00
// User has all classIDs we know about, we can deduplicate his items based on lowest count
setCopy . Clear ( ) ;
foreach ( ( ulong classID , uint amount ) in set ) {
2023-12-23 23:16:44 +01:00
setCopy [ classID ] = amount ;
2023-12-21 23:46:42 +01:00
}
foreach ( ( ulong classID , uint amount ) in setCopy ) {
if ( minimumAmount > = amount ) {
set . Remove ( classID ) ;
continue ;
}
set [ classID ] = amount - minimumAmount ;
}
}
HashSet < Asset > assetsForMatchingFiltered = [ ] ;
foreach ( Asset asset in assetsForMatching . Where ( asset = > setsState . TryGetValue ( ( asset . RealAppID , asset . Type , asset . Rarity ) , out Dictionary < ulong , uint > ? setState ) & & setState . TryGetValue ( asset . ClassID , out uint targetAmount ) & & ( targetAmount > 0 ) ) . OrderByDescending ( static asset = > asset . Tradable ) ) {
2024-03-17 02:29:04 +01:00
( uint RealAppID , EAssetType Type , EAssetRarity Rarity ) key = ( asset . RealAppID , asset . Type , asset . Rarity ) ;
2023-12-21 23:46:42 +01:00
if ( ! setsState . TryGetValue ( key , out Dictionary < ulong , uint > ? setState ) | | ! setState . TryGetValue ( asset . ClassID , out uint targetAmount ) | | ( targetAmount = = 0 ) ) {
// We're not interested in this combination
continue ;
}
if ( asset . Amount > = targetAmount ) {
asset . Amount = targetAmount ;
if ( setState . Remove ( asset . ClassID ) & & ( setState . Count = = 0 ) ) {
setsState . Remove ( key ) ;
}
} else {
setState [ asset . ClassID ] = targetAmount - asset . Amount ;
}
assetsForMatchingFiltered . Add ( asset ) ;
}
assetsForMatching = assetsForMatchingFiltered ;
if ( assetsForMatching . Count = = 0 ) {
Bot . ArchiLogger . LogGenericInfo ( string . Format ( CultureInfo . CurrentCulture , Strings . ErrorIsEmpty , nameof ( assetsForMatching ) ) ) ;
2023-05-31 15:32:56 +02:00
return ;
}
2023-12-21 23:46:42 +01:00
if ( assetsForMatching . Count > MaxItemsCount ) {
Bot . ArchiLogger . LogGenericWarning ( string . Format ( CultureInfo . CurrentCulture , Strings . WarningFailedWithError , $"{nameof(assetsForMatching)} > {MaxItemsCount}" ) ) ;
return ;
}
( HttpStatusCode StatusCode , ImmutableHashSet < ListedUser > Users ) ? response = await Backend . GetListedUsersForMatching ( ASF . GlobalConfig . LicenseID . Value , Bot , WebBrowser , assetsForMatching , acceptedMatchableTypes ) . ConfigureAwait ( false ) ;
2022-12-15 18:46:37 +01:00
if ( response = = null ) {
2022-12-16 19:57:32 +01:00
Bot . ArchiLogger . LogGenericWarning ( string . Format ( CultureInfo . CurrentCulture , Strings . WarningFailedWithError , nameof ( response ) ) ) ;
2022-12-15 18:46:37 +01:00
return ;
}
if ( ! response . Value . StatusCode . IsSuccessCode ( ) ) {
2022-12-16 19:57:32 +01:00
Bot . ArchiLogger . LogGenericWarning ( string . Format ( CultureInfo . CurrentCulture , Strings . WarningFailedWithError , response . Value . StatusCode ) ) ;
2022-12-15 18:46:37 +01:00
return ;
}
if ( response . Value . Users . IsEmpty ) {
2023-01-11 20:15:19 +01:00
Bot . ArchiLogger . LogGenericInfo ( string . Format ( CultureInfo . CurrentCulture , Strings . ErrorIsEmpty , nameof ( response . Value . Users ) ) ) ;
2022-12-15 18:46:37 +01:00
return ;
}
2018-12-03 05:21:12 +01:00
2022-12-15 18:46:37 +01:00
using ( await Bot . Actions . GetTradingLock ( ) . ConfigureAwait ( false ) ) {
2023-12-21 23:46:42 +01:00
tradesSent = await MatchActively ( response . Value . Users , assetsForMatching , acceptedMatchableTypes ) . ConfigureAwait ( false ) ;
Implement ETradingPreferences.MatchActively
This will probably need a lot more tests, tweaking and bugfixing, but basic logic is:
- MatchActively added to TradingPreferences with value of 16
- User must also use SteamTradeMatcher, can't use MatchEverything
- User must have statistics enabled and be eligible for being listed (no requirement of having 100 items minimum)
Once all requirements are passed, statistics module will communicate with the listing and fetch match everything bots:
- The matching will start in 1h since ASF start and will repeat every day (right now it starts in 1 minute to aid debugging).
- Each matching is composed of up to 10 rounds maximum.
- In each round ASF will fetch our inventory and inventory of listed bots in order to find MatchableTypes items to be matched. If match is found, offer is being sent and confirmed automatically.
- Each set (composition of item type + appID it's from) can be matched in a single round only once, this is to minimize "items no longer available" as much as possible and also avoid a need to wait for each bot to react before sending all trades.
- Round ends when we try to match a total of 20 bots, or we hit no items to match in consecutive 10 tries with 10 different bots.
- If last round resulted in at least a single trade being sent, next round starts within 5 minutes since last one, otherwise matching ends and repeats the next day.
We'll see how it works in practice, expect a lot of follow-up commits, unless I won't have anything to fix or improve.
2018-11-29 18:35:58 +01:00
}
2022-12-16 19:57:32 +01:00
Bot . ArchiLogger . LogGenericInfo ( Strings . Done ) ;
2021-11-10 21:23:24 +01:00
} finally {
MatchActivelySemaphore . Release ( ) ;
}
2023-01-18 22:52:25 +01:00
if ( tradesSent & & ShouldSendHeartBeats & & ( DateTime . UtcNow > LastAnnouncement . AddMinutes ( ShouldSendAnnouncementEarlier ? MinAnnouncementTTL : MaxAnnouncementTTL ) ) ) {
// If we're announced, it makes sense to update our state now, at least once
Bot . RequestPersonaStateUpdate ( ) ;
}
2021-11-10 21:23:24 +01:00
}
2020-11-14 22:37:00 +01:00
2024-06-25 00:18:13 +02:00
private async Task < bool > MatchActively ( ImmutableHashSet < ListedUser > listedUsers , HashSet < Asset > ourAssets , HashSet < EAssetType > acceptedMatchableTypes ) {
2022-12-15 18:46:37 +01:00
if ( ( listedUsers = = null ) | | ( listedUsers . Count = = 0 ) ) {
throw new ArgumentNullException ( nameof ( listedUsers ) ) ;
2021-11-10 21:23:24 +01:00
}
Implement ETradingPreferences.MatchActively
This will probably need a lot more tests, tweaking and bugfixing, but basic logic is:
- MatchActively added to TradingPreferences with value of 16
- User must also use SteamTradeMatcher, can't use MatchEverything
- User must have statistics enabled and be eligible for being listed (no requirement of having 100 items minimum)
Once all requirements are passed, statistics module will communicate with the listing and fetch match everything bots:
- The matching will start in 1h since ASF start and will repeat every day (right now it starts in 1 minute to aid debugging).
- Each matching is composed of up to 10 rounds maximum.
- In each round ASF will fetch our inventory and inventory of listed bots in order to find MatchableTypes items to be matched. If match is found, offer is being sent and confirmed automatically.
- Each set (composition of item type + appID it's from) can be matched in a single round only once, this is to minimize "items no longer available" as much as possible and also avoid a need to wait for each bot to react before sending all trades.
- Round ends when we try to match a total of 20 bots, or we hit no items to match in consecutive 10 tries with 10 different bots.
- If last round resulted in at least a single trade being sent, next round starts within 5 minutes since last one, otherwise matching ends and repeats the next day.
We'll see how it works in practice, expect a lot of follow-up commits, unless I won't have anything to fix or improve.
2018-11-29 18:35:58 +01:00
2023-12-21 23:46:42 +01:00
if ( ( ourAssets = = null ) | | ( ourAssets . Count = = 0 ) ) {
throw new ArgumentNullException ( nameof ( ourAssets ) ) ;
2021-11-10 21:23:24 +01:00
}
2018-12-15 00:27:15 +01:00
2022-12-15 18:46:37 +01:00
if ( ( acceptedMatchableTypes = = null ) | | ( acceptedMatchableTypes . Count = = 0 ) ) {
throw new ArgumentNullException ( nameof ( acceptedMatchableTypes ) ) ;
2021-11-10 21:23:24 +01:00
}
Implement ETradingPreferences.MatchActively
This will probably need a lot more tests, tweaking and bugfixing, but basic logic is:
- MatchActively added to TradingPreferences with value of 16
- User must also use SteamTradeMatcher, can't use MatchEverything
- User must have statistics enabled and be eligible for being listed (no requirement of having 100 items minimum)
Once all requirements are passed, statistics module will communicate with the listing and fetch match everything bots:
- The matching will start in 1h since ASF start and will repeat every day (right now it starts in 1 minute to aid debugging).
- Each matching is composed of up to 10 rounds maximum.
- In each round ASF will fetch our inventory and inventory of listed bots in order to find MatchableTypes items to be matched. If match is found, offer is being sent and confirmed automatically.
- Each set (composition of item type + appID it's from) can be matched in a single round only once, this is to minimize "items no longer available" as much as possible and also avoid a need to wait for each bot to react before sending all trades.
- Round ends when we try to match a total of 20 bots, or we hit no items to match in consecutive 10 tries with 10 different bots.
- If last round resulted in at least a single trade being sent, next round starts within 5 minutes since last one, otherwise matching ends and repeats the next day.
We'll see how it works in practice, expect a lot of follow-up commits, unless I won't have anything to fix or improve.
2018-11-29 18:35:58 +01:00
2024-03-18 13:45:13 +01:00
( Dictionary < ( uint RealAppID , EAssetType Type , EAssetRarity Rarity ) , Dictionary < ulong , uint > > ourFullState , Dictionary < ( uint RealAppID , EAssetType Type , EAssetRarity Rarity ) , Dictionary < ulong , uint > > ourTradableState ) = MatchingUtilities . GetDividedInventoryState ( ourAssets ) ;
2018-12-15 00:27:15 +01:00
2024-03-18 13:45:13 +01:00
if ( MatchingUtilities . IsEmptyForMatching ( ourFullState , ourTradableState ) ) {
2021-11-10 21:23:24 +01:00
// User doesn't have any more dupes in the inventory
2022-12-16 19:57:32 +01:00
Bot . ArchiLogger . LogGenericTrace ( string . Format ( CultureInfo . CurrentCulture , Strings . ErrorIsEmpty , $"{nameof(ourFullState)} || {nameof(ourTradableState)}" ) ) ;
Implement ETradingPreferences.MatchActively
This will probably need a lot more tests, tweaking and bugfixing, but basic logic is:
- MatchActively added to TradingPreferences with value of 16
- User must also use SteamTradeMatcher, can't use MatchEverything
- User must have statistics enabled and be eligible for being listed (no requirement of having 100 items minimum)
Once all requirements are passed, statistics module will communicate with the listing and fetch match everything bots:
- The matching will start in 1h since ASF start and will repeat every day (right now it starts in 1 minute to aid debugging).
- Each matching is composed of up to 10 rounds maximum.
- In each round ASF will fetch our inventory and inventory of listed bots in order to find MatchableTypes items to be matched. If match is found, offer is being sent and confirmed automatically.
- Each set (composition of item type + appID it's from) can be matched in a single round only once, this is to minimize "items no longer available" as much as possible and also avoid a need to wait for each bot to react before sending all trades.
- Round ends when we try to match a total of 20 bots, or we hit no items to match in consecutive 10 tries with 10 different bots.
- If last round resulted in at least a single trade being sent, next round starts within 5 minutes since last one, otherwise matching ends and repeats the next day.
We'll see how it works in practice, expect a lot of follow-up commits, unless I won't have anything to fix or improve.
2018-11-29 18:35:58 +01:00
2023-01-18 22:52:25 +01:00
return false ;
2021-11-10 21:23:24 +01:00
}
2018-12-15 00:27:15 +01:00
2023-01-24 22:49:41 +01:00
// Cancel previous trade offers sent and deprioritize SteamIDs that didn't answer us in this round
HashSet < ulong > ? matchActivelyTradeOfferIDs = null ;
2024-02-21 03:09:36 +01:00
JsonElement matchActivelyTradeOfferIDsToken = Bot . BotDatabase . LoadFromJsonStorage ( MatchActivelyTradeOfferIDsStorageKey ) ;
2023-01-24 22:49:41 +01:00
2024-02-21 03:09:36 +01:00
if ( matchActivelyTradeOfferIDsToken . ValueKind = = JsonValueKind . Array ) {
2023-01-24 22:49:41 +01:00
try {
2024-02-21 03:09:36 +01:00
matchActivelyTradeOfferIDs = new HashSet < ulong > ( matchActivelyTradeOfferIDsToken . GetArrayLength ( ) ) ;
foreach ( JsonElement tradeIDElement in matchActivelyTradeOfferIDsToken . EnumerateArray ( ) ) {
if ( ! tradeIDElement . TryGetUInt64 ( out ulong tradeID ) ) {
continue ;
}
matchActivelyTradeOfferIDs . Add ( tradeID ) ;
}
2023-01-24 22:49:41 +01:00
} catch ( Exception e ) {
Bot . ArchiLogger . LogGenericWarningException ( e ) ;
}
}
2023-12-11 23:55:13 +01:00
matchActivelyTradeOfferIDs ? ? = [ ] ;
2023-01-24 22:49:41 +01:00
2023-12-11 23:55:13 +01:00
HashSet < ulong > deprioritizedSteamIDs = [ ] ;
2023-01-24 22:49:41 +01:00
if ( matchActivelyTradeOfferIDs . Count > 0 ) {
// This is not a mandatory step, we allow it to fail
HashSet < TradeOffer > ? sentTradeOffers = await Bot . ArchiWebHandler . GetTradeOffers ( true , false , true , false ) . ConfigureAwait ( false ) ;
if ( sentTradeOffers ! = null ) {
2023-12-11 23:55:13 +01:00
HashSet < ulong > activeTradeOfferIDs = [ ] ;
2023-01-24 22:49:41 +01:00
foreach ( TradeOffer tradeOffer in sentTradeOffers . Where ( tradeOffer = > ( tradeOffer . State = = ETradeOfferState . Active ) & & matchActivelyTradeOfferIDs . Contains ( tradeOffer . TradeOfferID ) ) ) {
deprioritizedSteamIDs . Add ( tradeOffer . OtherSteamID64 ) ;
if ( ! await Bot . ArchiWebHandler . CancelTradeOffer ( tradeOffer . TradeOfferID ) . ConfigureAwait ( false ) ) {
activeTradeOfferIDs . Add ( tradeOffer . TradeOfferID ) ;
}
}
if ( ! matchActivelyTradeOfferIDs . SetEquals ( activeTradeOfferIDs ) ) {
matchActivelyTradeOfferIDs = activeTradeOfferIDs ;
if ( matchActivelyTradeOfferIDs . Count > 0 ) {
2024-02-21 03:09:36 +01:00
Bot . BotDatabase . SaveToJsonStorage ( MatchActivelyTradeOfferIDsStorageKey , matchActivelyTradeOfferIDs ) ;
2023-01-24 22:49:41 +01:00
} else {
Bot . BotDatabase . DeleteFromJsonStorage ( MatchActivelyTradeOfferIDsStorageKey ) ;
}
}
}
}
2023-12-21 23:46:42 +01:00
Dictionary < ulong , Asset > ourInventory = ourAssets . ToDictionary ( static asset = > asset . AssetID ) ;
2023-12-11 23:55:13 +01:00
HashSet < ulong > pendingMobileTradeOfferIDs = [ ] ;
2023-01-17 19:00:31 +01:00
2021-11-10 21:23:24 +01:00
byte maxTradeHoldDuration = ASF . GlobalConfig ? . MaxTradeHoldDuration ? ? GlobalConfig . DefaultMaxTradeHoldDuration ;
2019-02-04 03:09:20 +01:00
2023-01-17 19:42:29 +01:00
byte failuresInRow = 0 ;
2022-12-26 16:25:26 +01:00
uint matchedSets = 0 ;
2024-03-18 13:52:12 +01:00
HashSet < ( uint RealAppID , EAssetType Type , EAssetRarity Rarity ) > skippedSetsThisUser = [ ] ;
HashSet < ( uint RealAppID , EAssetType Type , EAssetRarity Rarity ) > skippedSetsThisTrade = [ ] ;
Dictionary < ulong , uint > classIDsToGive = new ( ) ;
Dictionary < ulong , uint > classIDsToReceive = new ( ) ;
Dictionary < ulong , uint > fairClassIDsToGive = new ( ) ;
Dictionary < ulong , uint > fairClassIDsToReceive = new ( ) ;
2024-01-11 16:46:45 +01:00
foreach ( ListedUser listedUser in listedUsers . Where ( listedUser = > ( listedUser . SteamID ! = Bot . SteamID ) & & acceptedMatchableTypes . Any ( listedUser . MatchableTypes . Contains ) & & ! Bot . IsBlacklistedFromTrades ( listedUser . SteamID ) ) . OrderByDescending ( listedUser = > ! deprioritizedSteamIDs . Contains ( listedUser . SteamID ) ) . ThenByDescending ( static listedUser = > listedUser . TotalGamesCount > 1 ) . ThenByDescending ( static listedUser = > listedUser . MatchEverything ) . ThenBy ( static listedUser = > listedUser . TotalInventoryCount ) ) {
2023-01-17 19:42:29 +01:00
if ( failuresInRow > = WebBrowser . MaxTries ) {
Bot . ArchiLogger . LogGenericWarning ( string . Format ( CultureInfo . CurrentCulture , Strings . WarningFailedWithError , $"{nameof(failuresInRow)} >= {WebBrowser.MaxTries}" ) ) ;
break ;
}
2023-05-23 14:28:30 +02:00
if ( ! Bot . IsConnectedAndLoggedOn ) {
Bot . ArchiLogger . LogGenericWarning ( Strings . BotNotConnected ) ;
break ;
}
2024-03-17 02:29:04 +01:00
HashSet < ( uint RealAppID , EAssetType Type , EAssetRarity Rarity ) > wantedSets = ourTradableState . Keys . Where ( set = > listedUser . MatchableTypes . Contains ( set . Type ) ) . ToHashSet ( ) ;
2019-02-04 03:09:20 +01:00
2021-11-10 21:23:24 +01:00
if ( wantedSets . Count = = 0 ) {
continue ;
}
2019-08-26 00:49:34 +02:00
2021-11-10 21:23:24 +01:00
Bot . ArchiLogger . LogGenericTrace ( $"{listedUser.SteamID}..." ) ;
2020-08-06 20:03:15 +03:00
2022-06-11 18:07:06 +02:00
byte? tradeHoldDuration = await Bot . ArchiWebHandler . GetCombinedTradeHoldDurationAgainstUser ( listedUser . SteamID , listedUser . TradeToken ) . ConfigureAwait ( false ) ;
2020-08-06 20:03:15 +03:00
2022-06-11 18:07:06 +02:00
switch ( tradeHoldDuration ) {
2021-11-10 21:23:24 +01:00
case null :
2022-12-16 19:57:32 +01:00
Bot . ArchiLogger . LogGenericTrace ( string . Format ( CultureInfo . CurrentCulture , Strings . ErrorIsEmpty , nameof ( tradeHoldDuration ) ) ) ;
2020-08-06 20:03:15 +03:00
2021-11-10 21:23:24 +01:00
continue ;
2022-06-11 18:07:06 +02:00
case > 0 when ( tradeHoldDuration . Value > maxTradeHoldDuration ) | | ( tradeHoldDuration . Value > listedUser . MaxTradeHoldDuration ) :
Bot . ArchiLogger . LogGenericTrace ( $"{tradeHoldDuration.Value} > {maxTradeHoldDuration} || {listedUser.MaxTradeHoldDuration}" ) ;
2020-08-06 20:03:15 +03:00
2021-11-10 21:23:24 +01:00
continue ;
}
Use IAsyncEnumerable for getting inventory (#1652)
* Use IAsyncEnumerable for getting inventory
* Don't suppress exceptions, catch them in ResponseUnpackBoosters
* Make sure we don't get duplicate assets during unpack
* Rewrite inventory filters to LINQ methods
* Add handling duplicate items, mark GetInventory as obsolete, catch exceptions from getting inventory errors
* Mark GetInventoryEnumerable as NotNull, don't check received inventory for null, use comparison with nullable values
* Use specific types of exceptions, log exceptions using LogGenericWarningException, handle IOException separately (without logging the exception), remove default null value
* Use old method signature for obsolete API
* Use error level for generic exceptions
* Fix wantedSets not being used
* Correct exception types, rename function
* Replace exception types
* Make SendTradeOfferAsync that accepts Func<Steam.Asset, bool> as a filter
* Fix missing targetSteamID in ResponseTransferByRealAppIDs
* Make parameter name readable
* Rename method
2020-02-22 20:03:22 +03:00
2024-03-17 02:29:04 +01:00
HashSet < Asset > theirInventory = listedUser . Assets . Where ( item = > ( ! listedUser . MatchEverything | | item . Tradable ) & & wantedSets . Contains ( ( item . RealAppID , item . Type , item . Rarity ) ) & & ( ( tradeHoldDuration . Value = = 0 ) | | ! ( item . Type is EAssetType . FoilTradingCard or EAssetType . TradingCard & & CardsFarmer . SalesBlacklist . Contains ( item . RealAppID ) ) ) ) . Select ( static asset = > asset . ToAsset ( ) ) . ToHashSet ( ) ;
2018-12-09 18:08:14 +01:00
2022-12-17 13:09:01 +01:00
if ( theirInventory . Count = = 0 ) {
continue ;
}
2024-03-18 13:52:12 +01:00
skippedSetsThisUser . Clear ( ) ;
Implement ETradingPreferences.MatchActively
This will probably need a lot more tests, tweaking and bugfixing, but basic logic is:
- MatchActively added to TradingPreferences with value of 16
- User must also use SteamTradeMatcher, can't use MatchEverything
- User must have statistics enabled and be eligible for being listed (no requirement of having 100 items minimum)
Once all requirements are passed, statistics module will communicate with the listing and fetch match everything bots:
- The matching will start in 1h since ASF start and will repeat every day (right now it starts in 1 minute to aid debugging).
- Each matching is composed of up to 10 rounds maximum.
- In each round ASF will fetch our inventory and inventory of listed bots in order to find MatchableTypes items to be matched. If match is found, offer is being sent and confirmed automatically.
- Each set (composition of item type + appID it's from) can be matched in a single round only once, this is to minimize "items no longer available" as much as possible and also avoid a need to wait for each bot to react before sending all trades.
- Round ends when we try to match a total of 20 bots, or we hit no items to match in consecutive 10 tries with 10 different bots.
- If last round resulted in at least a single trade being sent, next round starts within 5 minutes since last one, otherwise matching ends and repeats the next day.
We'll see how it works in practice, expect a lot of follow-up commits, unless I won't have anything to fix or improve.
2018-11-29 18:35:58 +01:00
2024-03-18 13:45:13 +01:00
Dictionary < ( uint RealAppID , EAssetType Type , EAssetRarity Rarity ) , Dictionary < ulong , uint > > theirTradableState = MatchingUtilities . GetTradableInventoryState ( theirInventory ) ;
Implement ETradingPreferences.MatchActively
This will probably need a lot more tests, tweaking and bugfixing, but basic logic is:
- MatchActively added to TradingPreferences with value of 16
- User must also use SteamTradeMatcher, can't use MatchEverything
- User must have statistics enabled and be eligible for being listed (no requirement of having 100 items minimum)
Once all requirements are passed, statistics module will communicate with the listing and fetch match everything bots:
- The matching will start in 1h since ASF start and will repeat every day (right now it starts in 1 minute to aid debugging).
- Each matching is composed of up to 10 rounds maximum.
- In each round ASF will fetch our inventory and inventory of listed bots in order to find MatchableTypes items to be matched. If match is found, offer is being sent and confirmed automatically.
- Each set (composition of item type + appID it's from) can be matched in a single round only once, this is to minimize "items no longer available" as much as possible and also avoid a need to wait for each bot to react before sending all trades.
- Round ends when we try to match a total of 20 bots, or we hit no items to match in consecutive 10 tries with 10 different bots.
- If last round resulted in at least a single trade being sent, next round starts within 5 minutes since last one, otherwise matching ends and repeats the next day.
We'll see how it works in practice, expect a lot of follow-up commits, unless I won't have anything to fix or improve.
2018-11-29 18:35:58 +01:00
2021-11-10 21:23:24 +01:00
for ( byte i = 0 ; i < Trading . MaxTradesPerAccount ; i + + ) {
byte itemsInTrade = 0 ;
Implement ETradingPreferences.MatchActively
This will probably need a lot more tests, tweaking and bugfixing, but basic logic is:
- MatchActively added to TradingPreferences with value of 16
- User must also use SteamTradeMatcher, can't use MatchEverything
- User must have statistics enabled and be eligible for being listed (no requirement of having 100 items minimum)
Once all requirements are passed, statistics module will communicate with the listing and fetch match everything bots:
- The matching will start in 1h since ASF start and will repeat every day (right now it starts in 1 minute to aid debugging).
- Each matching is composed of up to 10 rounds maximum.
- In each round ASF will fetch our inventory and inventory of listed bots in order to find MatchableTypes items to be matched. If match is found, offer is being sent and confirmed automatically.
- Each set (composition of item type + appID it's from) can be matched in a single round only once, this is to minimize "items no longer available" as much as possible and also avoid a need to wait for each bot to react before sending all trades.
- Round ends when we try to match a total of 20 bots, or we hit no items to match in consecutive 10 tries with 10 different bots.
- If last round resulted in at least a single trade being sent, next round starts within 5 minutes since last one, otherwise matching ends and repeats the next day.
We'll see how it works in practice, expect a lot of follow-up commits, unless I won't have anything to fix or improve.
2018-11-29 18:35:58 +01:00
2024-03-18 13:52:12 +01:00
skippedSetsThisTrade . Clear ( ) ;
classIDsToGive . Clear ( ) ;
classIDsToReceive . Clear ( ) ;
fairClassIDsToGive . Clear ( ) ;
fairClassIDsToReceive . Clear ( ) ;
2018-12-09 18:08:14 +01:00
2024-03-17 02:29:04 +01:00
foreach ( ( ( uint RealAppID , EAssetType Type , EAssetRarity Rarity ) set , Dictionary < ulong , uint > ourFullItems ) in ourFullState . Where ( set = > ! skippedSetsThisUser . Contains ( set . Key ) & & listedUser . MatchableTypes . Contains ( set . Key . Type ) & & set . Value . Values . Any ( static count = > count > 1 ) ) ) {
2021-11-10 21:23:24 +01:00
if ( ! ourTradableState . TryGetValue ( set , out Dictionary < ulong , uint > ? ourTradableItems ) | | ( ourTradableItems . Count = = 0 ) ) {
2022-12-26 16:25:26 +01:00
// We may have no more tradable items from this set
2021-11-10 21:23:24 +01:00
continue ;
}
Implement ETradingPreferences.MatchActively
This will probably need a lot more tests, tweaking and bugfixing, but basic logic is:
- MatchActively added to TradingPreferences with value of 16
- User must also use SteamTradeMatcher, can't use MatchEverything
- User must have statistics enabled and be eligible for being listed (no requirement of having 100 items minimum)
Once all requirements are passed, statistics module will communicate with the listing and fetch match everything bots:
- The matching will start in 1h since ASF start and will repeat every day (right now it starts in 1 minute to aid debugging).
- Each matching is composed of up to 10 rounds maximum.
- In each round ASF will fetch our inventory and inventory of listed bots in order to find MatchableTypes items to be matched. If match is found, offer is being sent and confirmed automatically.
- Each set (composition of item type + appID it's from) can be matched in a single round only once, this is to minimize "items no longer available" as much as possible and also avoid a need to wait for each bot to react before sending all trades.
- Round ends when we try to match a total of 20 bots, or we hit no items to match in consecutive 10 tries with 10 different bots.
- If last round resulted in at least a single trade being sent, next round starts within 5 minutes since last one, otherwise matching ends and repeats the next day.
We'll see how it works in practice, expect a lot of follow-up commits, unless I won't have anything to fix or improve.
2018-11-29 18:35:58 +01:00
2021-11-10 21:23:24 +01:00
if ( ! theirTradableState . TryGetValue ( set , out Dictionary < ulong , uint > ? theirTradableItems ) | | ( theirTradableItems . Count = = 0 ) ) {
2022-12-26 16:25:26 +01:00
// They may have no more tradable items from this set
continue ;
}
2024-03-18 13:45:13 +01:00
if ( MatchingUtilities . IsEmptyForMatching ( ourFullItems , ourTradableItems ) ) {
2022-12-26 16:25:26 +01:00
// We may have no more matchable items from this set
2021-11-10 21:23:24 +01:00
continue ;
}
2018-12-09 21:26:22 +01:00
2022-12-26 16:25:26 +01:00
// Those 2 collections are on user-basis since we can't be sure that the trade passes through (and therefore we need to keep original state in case of a failure)
2024-03-18 13:52:12 +01:00
Dictionary < ulong , uint > ourFullSet = ourFullItems . ToDictionary ( ) ;
Dictionary < ulong , uint > ourTradableSet = ourTradableItems . ToDictionary ( ) ;
2018-12-15 00:27:15 +01:00
2021-11-10 21:23:24 +01:00
bool match ;
Implement ETradingPreferences.MatchActively
This will probably need a lot more tests, tweaking and bugfixing, but basic logic is:
- MatchActively added to TradingPreferences with value of 16
- User must also use SteamTradeMatcher, can't use MatchEverything
- User must have statistics enabled and be eligible for being listed (no requirement of having 100 items minimum)
Once all requirements are passed, statistics module will communicate with the listing and fetch match everything bots:
- The matching will start in 1h since ASF start and will repeat every day (right now it starts in 1 minute to aid debugging).
- Each matching is composed of up to 10 rounds maximum.
- In each round ASF will fetch our inventory and inventory of listed bots in order to find MatchableTypes items to be matched. If match is found, offer is being sent and confirmed automatically.
- Each set (composition of item type + appID it's from) can be matched in a single round only once, this is to minimize "items no longer available" as much as possible and also avoid a need to wait for each bot to react before sending all trades.
- Round ends when we try to match a total of 20 bots, or we hit no items to match in consecutive 10 tries with 10 different bots.
- If last round resulted in at least a single trade being sent, next round starts within 5 minutes since last one, otherwise matching ends and repeats the next day.
We'll see how it works in practice, expect a lot of follow-up commits, unless I won't have anything to fix or improve.
2018-11-29 18:35:58 +01:00
2021-11-10 21:23:24 +01:00
do {
match = false ;
2018-12-02 19:04:53 +01:00
2021-11-10 21:23:24 +01:00
foreach ( ( ulong ourItem , uint ourFullAmount ) in ourFullSet . Where ( static item = > item . Value > 1 ) . OrderByDescending ( static item = > item . Value ) ) {
if ( ! ourTradableSet . TryGetValue ( ourItem , out uint ourTradableAmount ) | | ( ourTradableAmount = = 0 ) ) {
continue ;
}
2024-02-28 21:40:54 +01:00
foreach ( ( ulong theirItem , uint theirTradableAmount ) in theirTradableItems . OrderBy ( item = > ourFullSet . GetValueOrDefault ( item . Key ) ) ) {
2021-11-10 21:23:24 +01:00
if ( ourFullSet . TryGetValue ( theirItem , out uint ourAmountOfTheirItem ) & & ( ourFullAmount < = ourAmountOfTheirItem + 1 ) ) {
2018-12-09 18:08:14 +01:00
continue ;
}
2021-11-10 21:23:24 +01:00
if ( ! listedUser . MatchEverything ) {
// We have a potential match, let's check fairness for them
2024-02-28 21:40:54 +01:00
uint fairGivenAmount = fairClassIDsToGive . GetValueOrDefault ( ourItem ) ;
uint fairReceivedAmount = fairClassIDsToReceive . GetValueOrDefault ( theirItem ) ;
2021-11-10 21:23:24 +01:00
fairClassIDsToGive [ ourItem ] = + + fairGivenAmount ;
fairClassIDsToReceive [ theirItem ] = + + fairReceivedAmount ;
// Filter their inventory for the sets we're trading or have traded with this user
2024-03-18 13:45:13 +01:00
HashSet < Asset > fairFiltered = theirInventory . Where ( item = > ( ( item . RealAppID = = set . RealAppID ) & & ( item . Type = = set . Type ) & & ( item . Rarity = = set . Rarity ) ) | | skippedSetsThisTrade . Contains ( ( item . RealAppID , item . Type , item . Rarity ) ) ) . ToHashSet ( ) ;
2021-11-10 21:23:24 +01:00
2024-03-18 13:45:13 +01:00
// Get tradable items from our and their inventory
HashSet < Asset > fairItemsToGive = MatchingUtilities . GetTradableItemsFromInventory ( ourInventory . Values . Where ( item = > ( ( item . RealAppID = = set . RealAppID ) & & ( item . Type = = set . Type ) & & ( item . Rarity = = set . Rarity ) ) | | skippedSetsThisTrade . Contains ( ( item . RealAppID , item . Type , item . Rarity ) ) ) . ToHashSet ( ) , fairClassIDsToGive ) ;
HashSet < Asset > fairItemsToReceive = MatchingUtilities . GetTradableItemsFromInventory ( fairFiltered , fairClassIDsToReceive ) ;
2021-11-10 21:23:24 +01:00
2024-03-18 13:45:13 +01:00
// Actual check, since we do this against remote user, we flip places for items
2021-11-10 21:23:24 +01:00
if ( ! Trading . IsTradeNeutralOrBetter ( fairFiltered , fairItemsToReceive , fairItemsToGive ) ) {
2022-12-26 16:25:26 +01:00
// Revert the changes
2021-11-10 21:23:24 +01:00
if ( fairGivenAmount > 1 ) {
fairClassIDsToGive [ ourItem ] = fairGivenAmount - 1 ;
} else {
fairClassIDsToGive . Remove ( ourItem ) ;
2019-08-26 00:21:54 +02:00
}
2021-11-10 21:23:24 +01:00
if ( fairReceivedAmount > 1 ) {
fairClassIDsToReceive [ theirItem ] = fairReceivedAmount - 1 ;
} else {
fairClassIDsToReceive . Remove ( theirItem ) ;
}
2018-12-09 21:26:22 +01:00
2021-11-10 21:23:24 +01:00
continue ;
2018-12-09 21:26:22 +01:00
}
2021-11-10 21:23:24 +01:00
}
Implement ETradingPreferences.MatchActively
This will probably need a lot more tests, tweaking and bugfixing, but basic logic is:
- MatchActively added to TradingPreferences with value of 16
- User must also use SteamTradeMatcher, can't use MatchEverything
- User must have statistics enabled and be eligible for being listed (no requirement of having 100 items minimum)
Once all requirements are passed, statistics module will communicate with the listing and fetch match everything bots:
- The matching will start in 1h since ASF start and will repeat every day (right now it starts in 1 minute to aid debugging).
- Each matching is composed of up to 10 rounds maximum.
- In each round ASF will fetch our inventory and inventory of listed bots in order to find MatchableTypes items to be matched. If match is found, offer is being sent and confirmed automatically.
- Each set (composition of item type + appID it's from) can be matched in a single round only once, this is to minimize "items no longer available" as much as possible and also avoid a need to wait for each bot to react before sending all trades.
- Round ends when we try to match a total of 20 bots, or we hit no items to match in consecutive 10 tries with 10 different bots.
- If last round resulted in at least a single trade being sent, next round starts within 5 minutes since last one, otherwise matching ends and repeats the next day.
We'll see how it works in practice, expect a lot of follow-up commits, unless I won't have anything to fix or improve.
2018-11-29 18:35:58 +01:00
2021-11-10 21:23:24 +01:00
// Skip this set from the remaining of this round
skippedSetsThisTrade . Add ( set ) ;
Implement ETradingPreferences.MatchActively
This will probably need a lot more tests, tweaking and bugfixing, but basic logic is:
- MatchActively added to TradingPreferences with value of 16
- User must also use SteamTradeMatcher, can't use MatchEverything
- User must have statistics enabled and be eligible for being listed (no requirement of having 100 items minimum)
Once all requirements are passed, statistics module will communicate with the listing and fetch match everything bots:
- The matching will start in 1h since ASF start and will repeat every day (right now it starts in 1 minute to aid debugging).
- Each matching is composed of up to 10 rounds maximum.
- In each round ASF will fetch our inventory and inventory of listed bots in order to find MatchableTypes items to be matched. If match is found, offer is being sent and confirmed automatically.
- Each set (composition of item type + appID it's from) can be matched in a single round only once, this is to minimize "items no longer available" as much as possible and also avoid a need to wait for each bot to react before sending all trades.
- Round ends when we try to match a total of 20 bots, or we hit no items to match in consecutive 10 tries with 10 different bots.
- If last round resulted in at least a single trade being sent, next round starts within 5 minutes since last one, otherwise matching ends and repeats the next day.
We'll see how it works in practice, expect a lot of follow-up commits, unless I won't have anything to fix or improve.
2018-11-29 18:35:58 +01:00
2021-11-10 21:23:24 +01:00
// Update our state based on given items
2024-02-28 21:40:54 +01:00
classIDsToGive [ ourItem ] = classIDsToGive . GetValueOrDefault ( ourItem ) + 1 ;
2021-11-10 21:23:24 +01:00
ourFullSet [ ourItem ] = ourFullAmount - 1 ; // We don't need to remove anything here because we can guarantee that ourItem.Value is at least 2
2018-12-09 18:08:14 +01:00
2021-11-10 21:23:24 +01:00
// Update our state based on received items
2024-02-28 21:40:54 +01:00
classIDsToReceive [ theirItem ] = classIDsToReceive . GetValueOrDefault ( theirItem ) + 1 ;
2021-11-10 21:23:24 +01:00
ourFullSet [ theirItem ] = ourAmountOfTheirItem + 1 ;
2018-12-15 00:27:15 +01:00
2021-11-10 21:23:24 +01:00
if ( ourTradableAmount > 1 ) {
ourTradableSet [ ourItem ] = ourTradableAmount - 1 ;
} else {
ourTradableSet . Remove ( ourItem ) ;
Implement ETradingPreferences.MatchActively
This will probably need a lot more tests, tweaking and bugfixing, but basic logic is:
- MatchActively added to TradingPreferences with value of 16
- User must also use SteamTradeMatcher, can't use MatchEverything
- User must have statistics enabled and be eligible for being listed (no requirement of having 100 items minimum)
Once all requirements are passed, statistics module will communicate with the listing and fetch match everything bots:
- The matching will start in 1h since ASF start and will repeat every day (right now it starts in 1 minute to aid debugging).
- Each matching is composed of up to 10 rounds maximum.
- In each round ASF will fetch our inventory and inventory of listed bots in order to find MatchableTypes items to be matched. If match is found, offer is being sent and confirmed automatically.
- Each set (composition of item type + appID it's from) can be matched in a single round only once, this is to minimize "items no longer available" as much as possible and also avoid a need to wait for each bot to react before sending all trades.
- Round ends when we try to match a total of 20 bots, or we hit no items to match in consecutive 10 tries with 10 different bots.
- If last round resulted in at least a single trade being sent, next round starts within 5 minutes since last one, otherwise matching ends and repeats the next day.
We'll see how it works in practice, expect a lot of follow-up commits, unless I won't have anything to fix or improve.
2018-11-29 18:35:58 +01:00
}
2021-11-10 21:23:24 +01:00
// Update their state based on taken items
if ( theirTradableAmount > 1 ) {
theirTradableItems [ theirItem ] = theirTradableAmount - 1 ;
} else {
theirTradableItems . Remove ( theirItem ) ;
2018-12-02 19:04:53 +01:00
}
2021-11-10 21:23:24 +01:00
itemsInTrade + = 2 ;
match = true ;
break ;
Implement ETradingPreferences.MatchActively
This will probably need a lot more tests, tweaking and bugfixing, but basic logic is:
- MatchActively added to TradingPreferences with value of 16
- User must also use SteamTradeMatcher, can't use MatchEverything
- User must have statistics enabled and be eligible for being listed (no requirement of having 100 items minimum)
Once all requirements are passed, statistics module will communicate with the listing and fetch match everything bots:
- The matching will start in 1h since ASF start and will repeat every day (right now it starts in 1 minute to aid debugging).
- Each matching is composed of up to 10 rounds maximum.
- In each round ASF will fetch our inventory and inventory of listed bots in order to find MatchableTypes items to be matched. If match is found, offer is being sent and confirmed automatically.
- Each set (composition of item type + appID it's from) can be matched in a single round only once, this is to minimize "items no longer available" as much as possible and also avoid a need to wait for each bot to react before sending all trades.
- Round ends when we try to match a total of 20 bots, or we hit no items to match in consecutive 10 tries with 10 different bots.
- If last round resulted in at least a single trade being sent, next round starts within 5 minutes since last one, otherwise matching ends and repeats the next day.
We'll see how it works in practice, expect a lot of follow-up commits, unless I won't have anything to fix or improve.
2018-11-29 18:35:58 +01:00
}
2021-11-10 21:23:24 +01:00
if ( match ) {
break ;
}
Implement ETradingPreferences.MatchActively
This will probably need a lot more tests, tweaking and bugfixing, but basic logic is:
- MatchActively added to TradingPreferences with value of 16
- User must also use SteamTradeMatcher, can't use MatchEverything
- User must have statistics enabled and be eligible for being listed (no requirement of having 100 items minimum)
Once all requirements are passed, statistics module will communicate with the listing and fetch match everything bots:
- The matching will start in 1h since ASF start and will repeat every day (right now it starts in 1 minute to aid debugging).
- Each matching is composed of up to 10 rounds maximum.
- In each round ASF will fetch our inventory and inventory of listed bots in order to find MatchableTypes items to be matched. If match is found, offer is being sent and confirmed automatically.
- Each set (composition of item type + appID it's from) can be matched in a single round only once, this is to minimize "items no longer available" as much as possible and also avoid a need to wait for each bot to react before sending all trades.
- Round ends when we try to match a total of 20 bots, or we hit no items to match in consecutive 10 tries with 10 different bots.
- If last round resulted in at least a single trade being sent, next round starts within 5 minutes since last one, otherwise matching ends and repeats the next day.
We'll see how it works in practice, expect a lot of follow-up commits, unless I won't have anything to fix or improve.
2018-11-29 18:35:58 +01:00
}
2021-11-10 21:23:24 +01:00
} while ( match & & ( itemsInTrade < Trading . MaxItemsPerTrade - 1 ) ) ;
2018-12-15 00:27:15 +01:00
2021-11-10 21:23:24 +01:00
if ( itemsInTrade > = Trading . MaxItemsPerTrade - 1 ) {
Implement ETradingPreferences.MatchActively
This will probably need a lot more tests, tweaking and bugfixing, but basic logic is:
- MatchActively added to TradingPreferences with value of 16
- User must also use SteamTradeMatcher, can't use MatchEverything
- User must have statistics enabled and be eligible for being listed (no requirement of having 100 items minimum)
Once all requirements are passed, statistics module will communicate with the listing and fetch match everything bots:
- The matching will start in 1h since ASF start and will repeat every day (right now it starts in 1 minute to aid debugging).
- Each matching is composed of up to 10 rounds maximum.
- In each round ASF will fetch our inventory and inventory of listed bots in order to find MatchableTypes items to be matched. If match is found, offer is being sent and confirmed automatically.
- Each set (composition of item type + appID it's from) can be matched in a single round only once, this is to minimize "items no longer available" as much as possible and also avoid a need to wait for each bot to react before sending all trades.
- Round ends when we try to match a total of 20 bots, or we hit no items to match in consecutive 10 tries with 10 different bots.
- If last round resulted in at least a single trade being sent, next round starts within 5 minutes since last one, otherwise matching ends and repeats the next day.
We'll see how it works in practice, expect a lot of follow-up commits, unless I won't have anything to fix or improve.
2018-11-29 18:35:58 +01:00
break ;
}
2021-11-10 21:23:24 +01:00
}
Implement ETradingPreferences.MatchActively
This will probably need a lot more tests, tweaking and bugfixing, but basic logic is:
- MatchActively added to TradingPreferences with value of 16
- User must also use SteamTradeMatcher, can't use MatchEverything
- User must have statistics enabled and be eligible for being listed (no requirement of having 100 items minimum)
Once all requirements are passed, statistics module will communicate with the listing and fetch match everything bots:
- The matching will start in 1h since ASF start and will repeat every day (right now it starts in 1 minute to aid debugging).
- Each matching is composed of up to 10 rounds maximum.
- In each round ASF will fetch our inventory and inventory of listed bots in order to find MatchableTypes items to be matched. If match is found, offer is being sent and confirmed automatically.
- Each set (composition of item type + appID it's from) can be matched in a single round only once, this is to minimize "items no longer available" as much as possible and also avoid a need to wait for each bot to react before sending all trades.
- Round ends when we try to match a total of 20 bots, or we hit no items to match in consecutive 10 tries with 10 different bots.
- If last round resulted in at least a single trade being sent, next round starts within 5 minutes since last one, otherwise matching ends and repeats the next day.
We'll see how it works in practice, expect a lot of follow-up commits, unless I won't have anything to fix or improve.
2018-11-29 18:35:58 +01:00
2021-11-10 21:23:24 +01:00
if ( skippedSetsThisTrade . Count = = 0 ) {
2022-12-16 19:57:32 +01:00
Bot . ArchiLogger . LogGenericTrace ( string . Format ( CultureInfo . CurrentCulture , Strings . ErrorIsEmpty , nameof ( skippedSetsThisTrade ) ) ) ;
2018-12-09 18:08:14 +01:00
2021-11-10 21:23:24 +01:00
break ;
}
2018-12-15 00:27:15 +01:00
2021-11-10 21:23:24 +01:00
// Remove the items from inventories
2024-03-18 13:45:13 +01:00
HashSet < Asset > itemsToGive = MatchingUtilities . GetTradableItemsFromInventory ( ourInventory . Values , classIDsToGive ) ;
HashSet < Asset > itemsToReceive = MatchingUtilities . GetTradableItemsFromInventory ( theirInventory , classIDsToReceive , true ) ;
Implement ETradingPreferences.MatchActively
This will probably need a lot more tests, tweaking and bugfixing, but basic logic is:
- MatchActively added to TradingPreferences with value of 16
- User must also use SteamTradeMatcher, can't use MatchEverything
- User must have statistics enabled and be eligible for being listed (no requirement of having 100 items minimum)
Once all requirements are passed, statistics module will communicate with the listing and fetch match everything bots:
- The matching will start in 1h since ASF start and will repeat every day (right now it starts in 1 minute to aid debugging).
- Each matching is composed of up to 10 rounds maximum.
- In each round ASF will fetch our inventory and inventory of listed bots in order to find MatchableTypes items to be matched. If match is found, offer is being sent and confirmed automatically.
- Each set (composition of item type + appID it's from) can be matched in a single round only once, this is to minimize "items no longer available" as much as possible and also avoid a need to wait for each bot to react before sending all trades.
- Round ends when we try to match a total of 20 bots, or we hit no items to match in consecutive 10 tries with 10 different bots.
- If last round resulted in at least a single trade being sent, next round starts within 5 minutes since last one, otherwise matching ends and repeats the next day.
We'll see how it works in practice, expect a lot of follow-up commits, unless I won't have anything to fix or improve.
2018-11-29 18:35:58 +01:00
2021-11-10 21:23:24 +01:00
if ( ( itemsToGive . Count ! = itemsToReceive . Count ) | | ! Trading . IsFairExchange ( itemsToGive , itemsToReceive ) ) {
// Failsafe
2023-01-18 22:52:25 +01:00
throw new InvalidOperationException ( $"{nameof(itemsToGive)} && {nameof(itemsToReceive)}" ) ;
2021-11-10 21:23:24 +01:00
}
2018-12-05 23:13:55 +01:00
2024-08-05 02:15:58 +02:00
Bot . ArchiLogger . LogGenericInfo ( Localization . Strings . FormatMatchingFound ( itemsToReceive . Count , listedUser . SteamID , listedUser . Nickname ) ) ;
Implement ETradingPreferences.MatchActively
This will probably need a lot more tests, tweaking and bugfixing, but basic logic is:
- MatchActively added to TradingPreferences with value of 16
- User must also use SteamTradeMatcher, can't use MatchEverything
- User must have statistics enabled and be eligible for being listed (no requirement of having 100 items minimum)
Once all requirements are passed, statistics module will communicate with the listing and fetch match everything bots:
- The matching will start in 1h since ASF start and will repeat every day (right now it starts in 1 minute to aid debugging).
- Each matching is composed of up to 10 rounds maximum.
- In each round ASF will fetch our inventory and inventory of listed bots in order to find MatchableTypes items to be matched. If match is found, offer is being sent and confirmed automatically.
- Each set (composition of item type + appID it's from) can be matched in a single round only once, this is to minimize "items no longer available" as much as possible and also avoid a need to wait for each bot to react before sending all trades.
- Round ends when we try to match a total of 20 bots, or we hit no items to match in consecutive 10 tries with 10 different bots.
- If last round resulted in at least a single trade being sent, next round starts within 5 minutes since last one, otherwise matching ends and repeats the next day.
We'll see how it works in practice, expect a lot of follow-up commits, unless I won't have anything to fix or improve.
2018-11-29 18:35:58 +01:00
2022-12-15 18:46:37 +01:00
Bot . ArchiLogger . LogGenericTrace ( $"{Bot.SteamID} <- {string.Join(" , ", itemsToReceive.Select(static item => $" { item . RealAppID } / { item . Type } / { item . Rarity } / { item . ClassID } # { item . Amount } "))} | {string.Join(" , ", itemsToGive.Select(static item => $" { item . RealAppID } / { item . Type } / { item . Rarity } / { item . ClassID } # { item . Amount } "))} -> {listedUser.SteamID}" ) ;
2019-01-23 17:58:37 +01:00
2024-08-03 15:36:45 +02:00
( bool success , HashSet < ulong > ? tradeOfferIDs , HashSet < ulong > ? mobileTradeOfferIDs ) = await Bot . ArchiWebHandler . SendTradeOffer ( listedUser . SteamID , itemsToGive , itemsToReceive , listedUser . TradeToken , nameof ( MatchActively ) , true ) . ConfigureAwait ( false ) ;
2023-01-24 22:49:41 +01:00
if ( tradeOfferIDs ? . Count > 0 ) {
matchActivelyTradeOfferIDs . UnionWith ( tradeOfferIDs ) ;
2024-02-21 03:09:36 +01:00
Bot . BotDatabase . SaveToJsonStorage ( MatchActivelyTradeOfferIDsStorageKey , matchActivelyTradeOfferIDs ) ;
2023-01-24 22:49:41 +01:00
}
2018-12-15 00:27:15 +01:00
2023-01-17 19:00:31 +01:00
if ( mobileTradeOfferIDs ? . Count > 0 ) {
2023-01-17 19:19:27 +01:00
pendingMobileTradeOfferIDs . UnionWith ( mobileTradeOfferIDs ) ;
2023-01-18 14:16:35 +01:00
if ( pendingMobileTradeOfferIDs . Count > = MaxTradeOffersActive ) {
2023-06-29 22:34:26 +02:00
( bool twoFactorSuccess , IReadOnlyCollection < Confirmation > ? handledConfirmations , _ ) = await Bot . Actions . HandleTwoFactorAuthenticationConfirmations ( true , Confirmation . EConfirmationType . Trade , pendingMobileTradeOfferIDs , true ) . ConfigureAwait ( false ) ;
2023-01-18 14:16:35 +01:00
if ( ! twoFactorSuccess ) {
2024-08-05 02:15:58 +02:00
Bot . ArchiLogger . LogGenericWarning ( Localization . Strings . FormatActivelyMatchingSomeConfirmationsFailed ( handledConfirmations ? . Count ? ? 0 , pendingMobileTradeOfferIDs . Count ) ) ;
2023-01-18 14:16:35 +01:00
}
pendingMobileTradeOfferIDs . Clear ( ) ;
}
Implement ETradingPreferences.MatchActively
This will probably need a lot more tests, tweaking and bugfixing, but basic logic is:
- MatchActively added to TradingPreferences with value of 16
- User must also use SteamTradeMatcher, can't use MatchEverything
- User must have statistics enabled and be eligible for being listed (no requirement of having 100 items minimum)
Once all requirements are passed, statistics module will communicate with the listing and fetch match everything bots:
- The matching will start in 1h since ASF start and will repeat every day (right now it starts in 1 minute to aid debugging).
- Each matching is composed of up to 10 rounds maximum.
- In each round ASF will fetch our inventory and inventory of listed bots in order to find MatchableTypes items to be matched. If match is found, offer is being sent and confirmed automatically.
- Each set (composition of item type + appID it's from) can be matched in a single round only once, this is to minimize "items no longer available" as much as possible and also avoid a need to wait for each bot to react before sending all trades.
- Round ends when we try to match a total of 20 bots, or we hit no items to match in consecutive 10 tries with 10 different bots.
- If last round resulted in at least a single trade being sent, next round starts within 5 minutes since last one, otherwise matching ends and repeats the next day.
We'll see how it works in practice, expect a lot of follow-up commits, unless I won't have anything to fix or improve.
2018-11-29 18:35:58 +01:00
}
2021-11-10 21:23:24 +01:00
if ( ! success ) {
2023-01-17 19:00:31 +01:00
// The user likely no longer has the items we need, this is fine, we can continue the matching with other ones
2023-01-17 19:42:29 +01:00
failuresInRow + + ;
2024-08-05 02:15:58 +02:00
Bot . ArchiLogger . LogGenericWarning ( Localization . Strings . FormatTradeOfferFailed ( listedUser . SteamID , listedUser . Nickname ) ) ;
2018-12-05 19:13:46 +01:00
2021-11-10 21:23:24 +01:00
break ;
Implement ETradingPreferences.MatchActively
This will probably need a lot more tests, tweaking and bugfixing, but basic logic is:
- MatchActively added to TradingPreferences with value of 16
- User must also use SteamTradeMatcher, can't use MatchEverything
- User must have statistics enabled and be eligible for being listed (no requirement of having 100 items minimum)
Once all requirements are passed, statistics module will communicate with the listing and fetch match everything bots:
- The matching will start in 1h since ASF start and will repeat every day (right now it starts in 1 minute to aid debugging).
- Each matching is composed of up to 10 rounds maximum.
- In each round ASF will fetch our inventory and inventory of listed bots in order to find MatchableTypes items to be matched. If match is found, offer is being sent and confirmed automatically.
- Each set (composition of item type + appID it's from) can be matched in a single round only once, this is to minimize "items no longer available" as much as possible and also avoid a need to wait for each bot to react before sending all trades.
- Round ends when we try to match a total of 20 bots, or we hit no items to match in consecutive 10 tries with 10 different bots.
- If last round resulted in at least a single trade being sent, next round starts within 5 minutes since last one, otherwise matching ends and repeats the next day.
We'll see how it works in practice, expect a lot of follow-up commits, unless I won't have anything to fix or improve.
2018-11-29 18:35:58 +01:00
}
2023-01-17 19:42:29 +01:00
failuresInRow = 0 ;
2022-12-26 16:25:26 +01:00
Bot . ArchiLogger . LogGenericInfo ( Strings . Success ) ;
// Assume the trade offer has went through and was accepted, this will allow us to keep matching the same set with different users as if we've got what we wanted
foreach ( Asset itemToGive in itemsToGive ) {
if ( ! ourInventory . TryGetValue ( itemToGive . AssetID , out Asset ? item ) | | ( itemToGive . Amount > item . Amount ) ) {
throw new InvalidOperationException ( nameof ( item ) ) ;
}
if ( itemToGive . Amount = = item . Amount ) {
ourInventory . Remove ( itemToGive . AssetID ) ;
} else {
item . Amount - = itemToGive . Amount ;
}
if ( ! ourFullState . TryGetValue ( ( itemToGive . RealAppID , itemToGive . Type , itemToGive . Rarity ) , out Dictionary < ulong , uint > ? fullAmounts ) | | ! fullAmounts . TryGetValue ( itemToGive . ClassID , out uint fullAmount ) | | ( itemToGive . Amount > fullAmount ) ) {
// We're giving items we don't even have?
throw new InvalidOperationException ( nameof ( fullAmounts ) ) ;
}
if ( itemToGive . Amount = = fullAmount ) {
fullAmounts . Remove ( itemToGive . ClassID ) ;
} else {
fullAmounts [ itemToGive . ClassID ] = fullAmount - itemToGive . Amount ;
}
if ( ! ourTradableState . TryGetValue ( ( itemToGive . RealAppID , itemToGive . Type , itemToGive . Rarity ) , out Dictionary < ulong , uint > ? tradableAmounts ) | | ! tradableAmounts . TryGetValue ( itemToGive . ClassID , out uint tradableAmount ) | | ( itemToGive . Amount > tradableAmount ) ) {
// We're giving items we don't even have?
throw new InvalidOperationException ( nameof ( tradableAmounts ) ) ;
}
if ( itemToGive . Amount = = tradableAmount ) {
tradableAmounts . Remove ( itemToGive . ClassID ) ;
} else {
tradableAmounts [ itemToGive . ClassID ] = tradableAmount - itemToGive . Amount ;
}
}
// However, since this is only an assumption, we must mark newly acquired items as untradable so we're sure that they're not considered for trading, only for matching
foreach ( Asset itemToReceive in itemsToReceive ) {
if ( ourInventory . TryGetValue ( itemToReceive . AssetID , out Asset ? item ) ) {
2024-03-17 02:29:04 +01:00
item . Description ? ? = new InventoryDescription ( itemToReceive . AppID , itemToReceive . ClassID , itemToReceive . InstanceID , realAppID : itemToReceive . RealAppID , type : itemToReceive . Type , rarity : itemToReceive . Rarity ) ;
item . Description . Body . tradable = false ;
2022-12-26 16:25:26 +01:00
item . Amount + = itemToReceive . Amount ;
} else {
2024-03-17 02:29:04 +01:00
itemToReceive . Description ? ? = new InventoryDescription ( itemToReceive . AppID , itemToReceive . ClassID , itemToReceive . InstanceID , realAppID : itemToReceive . RealAppID , type : itemToReceive . Type , rarity : itemToReceive . Rarity ) ;
itemToReceive . Description . Body . tradable = false ;
2022-12-26 16:25:26 +01:00
ourInventory [ itemToReceive . AssetID ] = itemToReceive ;
}
if ( ! ourFullState . TryGetValue ( ( itemToReceive . RealAppID , itemToReceive . Type , itemToReceive . Rarity ) , out Dictionary < ulong , uint > ? fullAmounts ) ) {
// We're receiving items from a set we don't even have?
throw new InvalidOperationException ( nameof ( fullAmounts ) ) ;
}
2024-02-28 21:40:54 +01:00
fullAmounts [ itemToReceive . ClassID ] = fullAmounts . GetValueOrDefault ( itemToReceive . ClassID ) + itemToReceive . Amount ;
2022-12-26 16:25:26 +01:00
}
Implement ETradingPreferences.MatchActively
This will probably need a lot more tests, tweaking and bugfixing, but basic logic is:
- MatchActively added to TradingPreferences with value of 16
- User must also use SteamTradeMatcher, can't use MatchEverything
- User must have statistics enabled and be eligible for being listed (no requirement of having 100 items minimum)
Once all requirements are passed, statistics module will communicate with the listing and fetch match everything bots:
- The matching will start in 1h since ASF start and will repeat every day (right now it starts in 1 minute to aid debugging).
- Each matching is composed of up to 10 rounds maximum.
- In each round ASF will fetch our inventory and inventory of listed bots in order to find MatchableTypes items to be matched. If match is found, offer is being sent and confirmed automatically.
- Each set (composition of item type + appID it's from) can be matched in a single round only once, this is to minimize "items no longer available" as much as possible and also avoid a need to wait for each bot to react before sending all trades.
- Round ends when we try to match a total of 20 bots, or we hit no items to match in consecutive 10 tries with 10 different bots.
- If last round resulted in at least a single trade being sent, next round starts within 5 minutes since last one, otherwise matching ends and repeats the next day.
We'll see how it works in practice, expect a lot of follow-up commits, unless I won't have anything to fix or improve.
2018-11-29 18:35:58 +01:00
2021-11-10 21:23:24 +01:00
skippedSetsThisUser . UnionWith ( skippedSetsThisTrade ) ;
}
Implement ETradingPreferences.MatchActively
This will probably need a lot more tests, tweaking and bugfixing, but basic logic is:
- MatchActively added to TradingPreferences with value of 16
- User must also use SteamTradeMatcher, can't use MatchEverything
- User must have statistics enabled and be eligible for being listed (no requirement of having 100 items minimum)
Once all requirements are passed, statistics module will communicate with the listing and fetch match everything bots:
- The matching will start in 1h since ASF start and will repeat every day (right now it starts in 1 minute to aid debugging).
- Each matching is composed of up to 10 rounds maximum.
- In each round ASF will fetch our inventory and inventory of listed bots in order to find MatchableTypes items to be matched. If match is found, offer is being sent and confirmed automatically.
- Each set (composition of item type + appID it's from) can be matched in a single round only once, this is to minimize "items no longer available" as much as possible and also avoid a need to wait for each bot to react before sending all trades.
- Round ends when we try to match a total of 20 bots, or we hit no items to match in consecutive 10 tries with 10 different bots.
- If last round resulted in at least a single trade being sent, next round starts within 5 minutes since last one, otherwise matching ends and repeats the next day.
We'll see how it works in practice, expect a lot of follow-up commits, unless I won't have anything to fix or improve.
2018-11-29 18:35:58 +01:00
2021-11-10 21:23:24 +01:00
if ( skippedSetsThisUser . Count = = 0 ) {
continue ;
Implement ETradingPreferences.MatchActively
This will probably need a lot more tests, tweaking and bugfixing, but basic logic is:
- MatchActively added to TradingPreferences with value of 16
- User must also use SteamTradeMatcher, can't use MatchEverything
- User must have statistics enabled and be eligible for being listed (no requirement of having 100 items minimum)
Once all requirements are passed, statistics module will communicate with the listing and fetch match everything bots:
- The matching will start in 1h since ASF start and will repeat every day (right now it starts in 1 minute to aid debugging).
- Each matching is composed of up to 10 rounds maximum.
- In each round ASF will fetch our inventory and inventory of listed bots in order to find MatchableTypes items to be matched. If match is found, offer is being sent and confirmed automatically.
- Each set (composition of item type + appID it's from) can be matched in a single round only once, this is to minimize "items no longer available" as much as possible and also avoid a need to wait for each bot to react before sending all trades.
- Round ends when we try to match a total of 20 bots, or we hit no items to match in consecutive 10 tries with 10 different bots.
- If last round resulted in at least a single trade being sent, next round starts within 5 minutes since last one, otherwise matching ends and repeats the next day.
We'll see how it works in practice, expect a lot of follow-up commits, unless I won't have anything to fix or improve.
2018-11-29 18:35:58 +01:00
}
2022-12-26 16:25:26 +01:00
matchedSets + = ( uint ) skippedSetsThisUser . Count ;
2021-11-10 21:23:24 +01:00
2024-03-18 13:45:13 +01:00
if ( MatchingUtilities . IsEmptyForMatching ( ourFullState , ourTradableState ) ) {
2021-11-10 21:23:24 +01:00
// User doesn't have any more dupes in the inventory
break ;
}
Implement ETradingPreferences.MatchActively
This will probably need a lot more tests, tweaking and bugfixing, but basic logic is:
- MatchActively added to TradingPreferences with value of 16
- User must also use SteamTradeMatcher, can't use MatchEverything
- User must have statistics enabled and be eligible for being listed (no requirement of having 100 items minimum)
Once all requirements are passed, statistics module will communicate with the listing and fetch match everything bots:
- The matching will start in 1h since ASF start and will repeat every day (right now it starts in 1 minute to aid debugging).
- Each matching is composed of up to 10 rounds maximum.
- In each round ASF will fetch our inventory and inventory of listed bots in order to find MatchableTypes items to be matched. If match is found, offer is being sent and confirmed automatically.
- Each set (composition of item type + appID it's from) can be matched in a single round only once, this is to minimize "items no longer available" as much as possible and also avoid a need to wait for each bot to react before sending all trades.
- Round ends when we try to match a total of 20 bots, or we hit no items to match in consecutive 10 tries with 10 different bots.
- If last round resulted in at least a single trade being sent, next round starts within 5 minutes since last one, otherwise matching ends and repeats the next day.
We'll see how it works in practice, expect a lot of follow-up commits, unless I won't have anything to fix or improve.
2018-11-29 18:35:58 +01:00
}
2023-01-17 19:19:27 +01:00
if ( pendingMobileTradeOfferIDs . Count > 0 ) {
2023-06-29 22:34:26 +02:00
( bool twoFactorSuccess , IReadOnlyCollection < Confirmation > ? handledConfirmations , _ ) = Bot . IsConnectedAndLoggedOn ? await Bot . Actions . HandleTwoFactorAuthenticationConfirmations ( true , Confirmation . EConfirmationType . Trade , pendingMobileTradeOfferIDs , true ) . ConfigureAwait ( false ) : ( false , null , null ) ;
2023-01-17 19:19:27 +01:00
if ( ! twoFactorSuccess ) {
2024-08-05 02:15:58 +02:00
Bot . ArchiLogger . LogGenericWarning ( Localization . Strings . FormatActivelyMatchingSomeConfirmationsFailed ( handledConfirmations ? . Count ? ? 0 , pendingMobileTradeOfferIDs . Count ) ) ;
2023-01-17 19:19:27 +01:00
}
}
2024-08-05 02:15:58 +02:00
Bot . ArchiLogger . LogGenericInfo ( Localization . Strings . FormatActivelyMatchingItemsRound ( matchedSets ) ) ;
2023-01-18 22:52:25 +01:00
return matchedSets > 0 ;
2021-11-10 21:23:24 +01:00
}
2023-11-29 00:08:16 +01:00
private async void OnHeartBeatTimer ( object? state = null ) {
if ( ! Bot . IsConnectedAndLoggedOn | | ( Bot . HeartBeatFailures > 0 ) ) {
return ;
}
// Request persona update if needed
if ( ( DateTime . UtcNow > LastPersonaStateRequest . AddMinutes ( MinPersonaStateTTL ) ) & & ( DateTime . UtcNow > LastAnnouncement . AddMinutes ( ShouldSendAnnouncementEarlier ? MinAnnouncementTTL : MaxAnnouncementTTL ) ) ) {
LastPersonaStateRequest = DateTime . UtcNow ;
Bot . RequestPersonaStateUpdate ( ) ;
}
if ( ! ShouldSendHeartBeats | | ( DateTime . UtcNow < LastHeartBeat . AddMinutes ( MinHeartBeatTTL ) ) ) {
return ;
}
if ( ! await RequestsSemaphore . WaitAsync ( 0 ) . ConfigureAwait ( false ) ) {
return ;
}
try {
if ( ! SignedInWithSteam ) {
HttpStatusCode ? signInWithSteam = await ArchiNet . SignInWithSteam ( Bot , WebBrowser ) . ConfigureAwait ( false ) ;
if ( signInWithSteam = = null ) {
// This is actually a network failure, so we'll stop sending heartbeats but not record it as valid check
ShouldSendHeartBeats = false ;
return ;
}
if ( ! signInWithSteam . Value . IsSuccessCode ( ) ) {
// SignIn procedure failed and it wasn't a network error, hold off with future tries at least for a full day
LastAnnouncement = DateTime . UtcNow . AddDays ( 1 ) ;
ShouldSendHeartBeats = false ;
return ;
}
SignedInWithSteam = true ;
}
BasicResponse ? response = await Backend . HeartBeatForListing ( Bot , WebBrowser ) . ConfigureAwait ( false ) ;
if ( response = = null ) {
// This is actually a network failure, we should keep sending heartbeats for now
return ;
}
if ( response . StatusCode . IsRedirectionCode ( ) ) {
ShouldSendHeartBeats = false ;
Bot . ArchiLogger . LogGenericWarning ( string . Format ( CultureInfo . CurrentCulture , Strings . WarningFailedWithError , response . StatusCode ) ) ;
if ( response . FinalUri . Host ! = ArchiWebHandler . SteamCommunityURL . Host ) {
ASF . ArchiLogger . LogGenericError ( string . Format ( CultureInfo . CurrentCulture , Strings . WarningUnknownValuePleaseReport , nameof ( response . FinalUri ) , response . FinalUri ) ) ;
return ;
}
// We've expected the result, not the redirection to the sign in, we need to authenticate again
SignedInWithSteam = false ;
return ;
}
2024-01-03 00:23:27 +01:00
BotCache ? ? = await BotCache . CreateOrLoad ( BotCacheFilePath ) . ConfigureAwait ( false ) ;
if ( ! response . StatusCode . IsSuccessCode ( ) ) {
2023-11-29 00:08:16 +01:00
ShouldSendHeartBeats = false ;
Bot . ArchiLogger . LogGenericWarning ( string . Format ( CultureInfo . CurrentCulture , Strings . WarningFailedWithError , response . StatusCode ) ) ;
2024-01-03 00:23:27 +01:00
switch ( response . StatusCode ) {
case HttpStatusCode . Conflict :
// ArchiNet told us to that we need to announce again
LastAnnouncement = DateTime . MinValue ;
BotCache . LastAnnouncedAssetsForListing . Clear ( ) ;
BotCache . LastInventoryChecksumBeforeDeduplication = BotCache . LastAnnouncedTradeToken = null ;
BotCache . LastRequestAt = null ;
return ;
case HttpStatusCode . Forbidden :
// ArchiNet told us to stop submitting data for now
LastAnnouncement = DateTime . UtcNow . AddYears ( 1 ) ;
return ;
case HttpStatusCode . TooManyRequests :
// ArchiNet told us to try again later
LastAnnouncement = DateTime . UtcNow . AddDays ( 1 ) ;
return ;
default :
// There is something wrong with our payload or the server, we shouldn't retry for at least several hours
LastAnnouncement = DateTime . UtcNow . AddHours ( 6 ) ;
return ;
}
2023-11-29 00:08:16 +01:00
}
2024-01-03 00:23:27 +01:00
BotCache . LastRequestAt = LastHeartBeat = DateTime . UtcNow ;
2023-11-29 00:08:16 +01:00
} finally {
RequestsSemaphore . Release ( ) ;
}
}
2018-09-08 00:46:40 +02:00
}