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

@@ -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;
}
}
}