Skip to content

Commit

Permalink
Merge pull request #4 from SmallTailTeam/latest
Browse files Browse the repository at this point in the history
0.1.1
  • Loading branch information
yakikotori authored May 9, 2023
2 parents 5abaa1e + 58d0373 commit 90d35f9
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 18 deletions.
2 changes: 1 addition & 1 deletion BotLooter/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
68 changes: 52 additions & 16 deletions BotLooter/Resources/SteamAccountCredentials.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ public SteamAccountCredentials(string login, string password, SteamGuardAccount
{
return (null, $"Папки с секретами '{secretsDirectory}' не существует");
}


var secrets = await GetSecretFiles(secretsDirectory);

var accounts = new List<SteamAccountCredentials>();

var accountsFileLines = await File.ReadAllLinesAsync(accountsFile);
Expand All @@ -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<List<SteamGuardAccount>> GetSecretFiles(string directoryPath)
{
var steamGuardAccounts = new List<SteamGuardAccount>();

var files = Directory.GetFiles(directoryPath);

foreach (var filePath in files)
{
try
{
steamGuardAccount = JsonConvert.DeserializeObject<SteamGuardAccount>(secretFileContents);
var contents = await File.ReadAllTextAsync(filePath);

var json = JsonConvert.DeserializeObject<SteamGuardAccount>(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<SteamGuardAccount> 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;
}
}
11 changes: 10 additions & 1 deletion BotLooter/Steam/LootClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ public LootClient(SteamAccountCredentials credentials, SteamSession steamSession

private async Task<(List<Asset>? Assets, string message)> GetAssetsToSend(SteamWeb web, ulong steamId64, List<string> inventories)
{
var filteredOut = new HashSet<string>();

var assets = new List<Asset>();

var index = 0;
Expand Down Expand Up @@ -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;

Expand Down

0 comments on commit 90d35f9

Please sign in to comment.