Skip to content

Commit

Permalink
Do not rely on secret file name when searching for a matching file
Browse files Browse the repository at this point in the history
  • Loading branch information
yakikotori committed May 9, 2023
1 parent 966e19e commit 58d0373
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 17 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;
}
}

0 comments on commit 58d0373

Please sign in to comment.