Add extra bulltetproofing to AH's PlayGames()

We don't want to ever have duplicates there, even if userspace supplies them (which should never happen)
This commit is contained in:
Archi
2021-06-21 23:51:26 +02:00
parent db3d4e465d
commit 2cee5e442f
3 changed files with 14 additions and 8 deletions

View File

@@ -1226,7 +1226,7 @@ namespace ArchiSteamFarm.Steam {
gameName = string.Format(CultureInfo.CurrentCulture, BotConfig.CustomGamePlayedWhileFarming!, game.AppID, game.GameName);
}
await ArchiHandler.PlayGames(game.PlayableAppID.ToEnumerable(), gameName).ConfigureAwait(false);
await ArchiHandler.PlayGames(new HashSet<uint>(1) { game.PlayableAppID }, gameName).ConfigureAwait(false);
}
internal async Task IdleGames(IReadOnlyCollection<Game> games) {
@@ -1240,7 +1240,7 @@ namespace ArchiSteamFarm.Steam {
gameName = string.Format(CultureInfo.CurrentCulture, BotConfig.CustomGamePlayedWhileFarming!, string.Join(", ", games.Select(game => game.AppID)), string.Join(", ", games.Select(game => game.GameName)));
}
await ArchiHandler.PlayGames(games.Select(game => game.PlayableAppID), gameName).ConfigureAwait(false);
await ArchiHandler.PlayGames(games.Select(game => game.PlayableAppID).ToHashSet(), gameName).ConfigureAwait(false);
}
internal async Task ImportKeysToRedeem(string filePath) {

View File

@@ -471,7 +471,7 @@ namespace ArchiSteamFarm.Steam.Integration {
return response.Result == EResult.OK;
}
internal async Task PlayGames(IEnumerable<uint> gameIDs, string? gameName = null) {
internal async Task PlayGames(IReadOnlyCollection<uint> gameIDs, string? gameName = null) {
if (gameIDs == null) {
throw new ArgumentNullException(nameof(gameIDs));
}
@@ -512,11 +512,17 @@ namespace ArchiSteamFarm.Steam.Integration {
maxGamesCount++;
}
foreach (uint gameID in gameIDs.Where(gameID => gameID != 0)) {
request.Body.games_played.Add(new CMsgClientGamesPlayed.GamePlayed { game_id = new GameID(gameID) });
if (gameIDs.Count > 0) {
#pragma warning disable CA1508 // False positive, not every IReadOnlyCollection is ISet
IEnumerable<uint> uniqueValidGameIDs = (gameIDs as ISet<uint> ?? gameIDs.Distinct()).Where(gameID => gameID > 0);
#pragma warning restore CA1508 // False positive, not every IReadOnlyCollection is ISet
if (request.Body.games_played.Count >= maxGamesCount) {
break;
foreach (uint gameID in uniqueValidGameIDs) {
request.Body.games_played.Add(new CMsgClientGamesPlayed.GamePlayed { game_id = new GameID(gameID) });
if (request.Body.games_played.Count >= maxGamesCount) {
break;
}
}
}

View File

@@ -201,7 +201,7 @@ namespace ArchiSteamFarm.Steam.Interaction {
// We add extra delay because OnFarmingStopped() also executes PlayGames()
// Despite of proper order on our end, Steam network might not respect it
await Task.Delay(Bot.CallbackSleep).ConfigureAwait(false);
await Bot.ArchiHandler.PlayGames(Enumerable.Empty<uint>(), Bot.BotConfig.CustomGamePlayedWhileIdle).ConfigureAwait(false);
await Bot.ArchiHandler.PlayGames(Array.Empty<uint>(), Bot.BotConfig.CustomGamePlayedWhileIdle).ConfigureAwait(false);
}
if (resumeInSeconds > 0) {