From 966e19e58b89bd0c7a0ab9071f3f2c9c6a6be2ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E9=B3=A5?= <44732554+Lyrapuff@users.noreply.github.com> Date: Tue, 9 May 2023 20:20:38 +0300 Subject: [PATCH 1/2] Do not send not tradable assets --- BotLooter/Steam/LootClient.cs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/BotLooter/Steam/LootClient.cs b/BotLooter/Steam/LootClient.cs index c84df80..ed0d3c6 100644 --- a/BotLooter/Steam/LootClient.cs +++ b/BotLooter/Steam/LootClient.cs @@ -87,6 +87,8 @@ public LootClient(SteamAccountCredentials credentials, SteamSession steamSession private async Task<(List? Assets, string message)> GetAssetsToSend(SteamWeb web, ulong steamId64, List inventories) { + var filteredOut = new HashSet(); + var assets = new List(); var index = 0; @@ -115,7 +117,14 @@ public LootClient(SteamAccountCredentials credentials, SteamSession steamSession continue; } - assets.AddRange(inventoryAssets); + foreach (var description in inventoryData.Descriptions.Where(d => d.Tradable == 0)) + { + filteredOut.Add(description.Classid); + } + + var notFilteredOutAssets = inventoryAssets.Where(a => !filteredOut.Contains(a.Classid)); + + assets.AddRange(notFilteredOutAssets); var isLast = index == inventories.Count - 1; From 58d0373558a667ebab14a21c40bcc3a53c82a5a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E9=B3=A5?= <44732554+Lyrapuff@users.noreply.github.com> Date: Tue, 9 May 2023 22:01:54 +0300 Subject: [PATCH 2/2] Do not rely on secret file name when searching for a matching file --- BotLooter/Program.cs | 2 +- .../Resources/SteamAccountCredentials.cs | 68 ++++++++++++++----- 2 files changed, 53 insertions(+), 17 deletions(-) diff --git a/BotLooter/Program.cs b/BotLooter/Program.cs index ee9fa6a..b09eeab 100644 --- a/BotLooter/Program.cs +++ b/BotLooter/Program.cs @@ -17,7 +17,7 @@ Console.ReadKey(); }; -var version = new Version(0, 1, 0); +var version = new Version(0, 1, 1); var versionChecker = new VersionChecker(Log.Logger); await versionChecker.Check(version); diff --git a/BotLooter/Resources/SteamAccountCredentials.cs b/BotLooter/Resources/SteamAccountCredentials.cs index 83792c0..9177c17 100644 --- a/BotLooter/Resources/SteamAccountCredentials.cs +++ b/BotLooter/Resources/SteamAccountCredentials.cs @@ -28,7 +28,9 @@ public SteamAccountCredentials(string login, string password, SteamGuardAccount { return (null, $"Папки с секретами '{secretsDirectory}' не существует"); } - + + var secrets = await GetSecretFiles(secretsDirectory); + var accounts = new List(); var accountsFileLines = await File.ReadAllLinesAsync(accountsFile); @@ -50,37 +52,71 @@ public SteamAccountCredentials(string login, string password, SteamGuardAccount var login = split[0]; var password = split[1]; - var secretFilePath = Path.Combine(secretsDirectory, login + ".maFile"); + var secret = FindSecretFile(secrets, login); - if (!File.Exists(secretFilePath)) + if (secret is null) { - Log.Logger.Warning("{Login} - Не найден секретный файл для аккаунта", login); + Log.Logger.Warning("{Login} - Не найден секретный файл", login); continue; } - var secretFileContents = await File.ReadAllTextAsync(secretFilePath); - - SteamGuardAccount? steamGuardAccount; + if (secret is not { SharedSecret: not null, IdentitySecret: not null, DeviceID: not null}) + { + Log.Logger.Warning("{Login} - В секретном файле отсутствует shared_secret, identity_secret или device_id", login); + continue; + } + + accounts.Add(new SteamAccountCredentials(login, password, secret)); + } + + return (accounts, ""); + } + private static async Task> GetSecretFiles(string directoryPath) + { + var steamGuardAccounts = new List(); + + var files = Directory.GetFiles(directoryPath); + + foreach (var filePath in files) + { try { - steamGuardAccount = JsonConvert.DeserializeObject(secretFileContents); + var contents = await File.ReadAllTextAsync(filePath); + + var json = JsonConvert.DeserializeObject(contents); + + if (json is null) + { + Log.Logger.Warning("Невалидный секретный файл: {FilePath}", filePath); + continue; + } + + steamGuardAccounts.Add(json); } catch { - Log.Logger.Warning("{Login} - Не удалось десериализовать секретный файл", login); - continue; + Log.Logger.Warning("Невалидный секретный файл: {FilePath}", filePath); } + } + + return steamGuardAccounts; + } + + private static SteamGuardAccount? FindSecretFile(List steamGuardAccounts, string login) + { + foreach (var steamGuardAccount in steamGuardAccounts) + { + var isMatch = steamGuardAccount.AccountName.ToLower() == login.ToLower(); - if (steamGuardAccount is not { SharedSecret: not null, IdentitySecret: not null, DeviceID: not null}) + if (!isMatch) { - Log.Logger.Warning("{Login} - В секретном файле отсутствует SharedSecret, IdentitySecret или DeviceId", login); continue; } - - accounts.Add(new SteamAccountCredentials(login, password, steamGuardAccount)); + + return steamGuardAccount; } - - return (accounts, ""); + + return null; } } \ No newline at end of file