Skip to content

Commit 0ba5ad5

Browse files
committed
Remove support for CustomGamePlayedWhileFarming and CustomGamePlayedWhileIdle, #3551
1 parent 8cf2c01 commit 0ba5ad5

File tree

6 files changed

+32
-92
lines changed

6 files changed

+32
-92
lines changed

ArchiSteamFarm/Steam/Bot.cs

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1429,32 +1429,6 @@ internal static string FormatBotResponse(string response, string botName) {
14291429
return ((ECommunityPrivacy) privacySettings.privacy_state == ECommunityPrivacy.Public) && ((ECommunityPrivacy) privacySettings.privacy_state_inventory == ECommunityPrivacy.Public);
14301430
}
14311431

1432-
internal async Task IdleGame(Game game) {
1433-
ArgumentNullException.ThrowIfNull(game);
1434-
1435-
string? gameName = null;
1436-
1437-
if (!string.IsNullOrEmpty(BotConfig.CustomGamePlayedWhileFarming)) {
1438-
gameName = string.Format(CultureInfo.CurrentCulture, BotConfig.CustomGamePlayedWhileFarming, game.AppID, game.GameName);
1439-
}
1440-
1441-
await ArchiHandler.PlayGames(new HashSet<uint>(1) { game.PlayableAppID }, gameName).ConfigureAwait(false);
1442-
}
1443-
1444-
internal async Task IdleGames(IReadOnlyCollection<Game> games) {
1445-
if ((games == null) || (games.Count == 0)) {
1446-
throw new ArgumentNullException(nameof(games));
1447-
}
1448-
1449-
string? gameName = null;
1450-
1451-
if (!string.IsNullOrEmpty(BotConfig.CustomGamePlayedWhileFarming)) {
1452-
gameName = string.Format(CultureInfo.CurrentCulture, BotConfig.CustomGamePlayedWhileFarming, string.Join(", ", games.Select(static game => game.AppID)), string.Join(", ", games.Select(static game => game.GameName)));
1453-
}
1454-
1455-
await ArchiHandler.PlayGames(games.Select(static game => game.PlayableAppID).ToHashSet(), gameName).ConfigureAwait(false);
1456-
}
1457-
14581432
internal async Task ImportKeysToRedeem(string filePath) {
14591433
ArgumentException.ThrowIfNullOrEmpty(filePath);
14601434

@@ -3858,7 +3832,7 @@ private async Task ResetGamesPlayed() {
38583832
ArchiLogger.LogGenericInfo(Strings.FormatBotIdlingSelectedGames(nameof(BotConfig.GamesPlayedWhileIdle), string.Join(", ", BotConfig.GamesPlayedWhileIdle)));
38593833
}
38603834

3861-
await ArchiHandler.PlayGames(BotConfig.GamesPlayedWhileIdle, BotConfig.CustomGamePlayedWhileIdle).ConfigureAwait(false);
3835+
ArchiHandler.PlayGames(BotConfig.GamesPlayedWhileIdle);
38623836
}
38633837

38643838
private void ResetPlayingWasBlockedWithTimer(object? state = null) {

ArchiSteamFarm/Steam/Cards/CardsFarmer.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -890,7 +890,7 @@ private async Task<bool> FarmCards(Game game) {
890890
Bot.ArchiLogger.LogGenericWarning(Strings.FormatWarningIdlingGameMismatch(game.AppID, game.GameName, game.PlayableAppID));
891891
}
892892

893-
await Bot.IdleGame(game).ConfigureAwait(false);
893+
Bot.ArchiHandler.PlayGames(new HashSet<uint>(1) { game.PlayableAppID });
894894

895895
bool keepFarming = true;
896896
DateTime endFarmingDate = DateTime.UtcNow.AddHours(ASF.GlobalConfig?.MaxFarmingTime ?? GlobalConfig.DefaultMaxFarmingTime);
@@ -949,7 +949,7 @@ private async Task<bool> FarmHours(HashSet<Game> games) {
949949
return true;
950950
}
951951

952-
await Bot.IdleGames(games).ConfigureAwait(false);
952+
Bot.ArchiHandler.PlayGames(games.Select(static game => game.PlayableAppID).ToHashSet());
953953

954954
bool keepFarming = true;
955955

ArchiSteamFarm/Steam/Integration/ArchiHandler.cs

Lines changed: 6 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -949,9 +949,13 @@ internal async Task<ulong> GetServerTime() {
949949
return response.Result == EResult.OK ? response.Body.device_identifier : null;
950950
}
951951

952-
internal async Task PlayGames(IReadOnlyCollection<uint> gameIDs, string? gameName = null) {
952+
internal void PlayGames(IReadOnlyCollection<uint> gameIDs) {
953953
ArgumentNullException.ThrowIfNull(gameIDs);
954954

955+
if (gameIDs.Count > MaxGamesPlayedConcurrently) {
956+
throw new InvalidOperationException(nameof(gameIDs));
957+
}
958+
955959
if (Client == null) {
956960
throw new InvalidOperationException(nameof(Client));
957961
}
@@ -967,39 +971,10 @@ internal async Task PlayGames(IReadOnlyCollection<uint> gameIDs, string? gameNam
967971
}
968972
};
969973

970-
if (!string.IsNullOrEmpty(gameName)) {
971-
// If we have custom name to display, we must workaround the Steam network broken behaviour and send request on clean non-playing session
972-
// This ensures that custom name will in fact display properly (if it's not omitted due to MaxGamesPlayedConcurrently, that is)
973-
Client.Send(request);
974-
975-
await Task.Delay(Bot.CallbackSleep).ConfigureAwait(false);
976-
977-
request.Body.games_played.Add(
978-
new CMsgClientGamesPlayed.GamePlayed {
979-
game_extra_info = gameName,
980-
game_id = new GameID {
981-
AppType = GameID.GameType.Shortcut,
982-
ModID = uint.MaxValue
983-
}
984-
}
985-
);
986-
}
987-
988974
if (gameIDs.Count > 0) {
989-
IEnumerable<uint> uniqueGameIDs = gameIDs as IReadOnlySet<uint> ?? gameIDs.Distinct();
975+
IEnumerable<uint> uniqueGameIDs = gameIDs is IReadOnlySet<uint> or ISet<uint> ? gameIDs : gameIDs.Distinct();
990976

991977
foreach (uint gameID in uniqueGameIDs.Where(static gameID => gameID > 0)) {
992-
if (request.Body.games_played.Count >= MaxGamesPlayedConcurrently) {
993-
if (string.IsNullOrEmpty(gameName)) {
994-
throw new ArgumentOutOfRangeException(nameof(gameIDs));
995-
}
996-
997-
// Make extra space by ditching custom gameName
998-
gameName = null;
999-
1000-
request.Body.games_played.RemoveAt(0);
1001-
}
1002-
1003978
request.Body.games_played.Add(new CMsgClientGamesPlayed.GamePlayed { game_id = new GameID(gameID) });
1004979
}
1005980
}

ArchiSteamFarm/Steam/Interaction/Actions.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ public static string Hash(ArchiCryptoHelper.EHashingMethod hashingMethod, string
307307
// Despite of proper order on our end, Steam network might not respect it
308308
await Task.Delay(Bot.CallbackSleep).ConfigureAwait(false);
309309

310-
await Bot.ArchiHandler.PlayGames([], Bot.BotConfig.CustomGamePlayedWhileIdle).ConfigureAwait(false);
310+
Bot.ArchiHandler.PlayGames([]);
311311
}
312312

313313
if (resumeInSeconds > 0) {
@@ -327,7 +327,7 @@ public static string Hash(ArchiCryptoHelper.EHashingMethod hashingMethod, string
327327
}
328328

329329
[PublicAPI]
330-
public async Task<(bool Success, string Message)> Play(IReadOnlyCollection<uint> gameIDs, string? gameName = null) {
330+
public async Task<(bool Success, string Message)> Play(IReadOnlyCollection<uint> gameIDs) {
331331
ArgumentNullException.ThrowIfNull(gameIDs);
332332

333333
if (!Bot.IsConnectedAndLoggedOn) {
@@ -338,7 +338,7 @@ public static string Hash(ArchiCryptoHelper.EHashingMethod hashingMethod, string
338338
await Bot.CardsFarmer.Pause(true).ConfigureAwait(false);
339339
}
340340

341-
await Bot.ArchiHandler.PlayGames(gameIDs, gameName).ConfigureAwait(false);
341+
Bot.ArchiHandler.PlayGames(gameIDs);
342342

343343
return (true, gameIDs.Count > 0 ? Strings.FormatBotIdlingSelectedGames(nameof(gameIDs), string.Join(", ", gameIDs)) : Strings.Done);
344344
}

ArchiSteamFarm/Steam/Interaction/Commands.cs

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2316,7 +2316,7 @@ internal void OnNewLicenseList() {
23162316
return responses.Count > 0 ? string.Join(Environment.NewLine, responses) : null;
23172317
}
23182318

2319-
private async Task<string?> ResponsePlay(EAccess access, HashSet<uint> gameIDs, string? gameName = null) {
2319+
private async Task<string?> ResponsePlay(EAccess access, HashSet<uint> gameIDs) {
23202320
if (!Enum.IsDefined(access)) {
23212321
throw new InvalidEnumArgumentException(nameof(access), (int) access, typeof(EAccess));
23222322
}
@@ -2335,7 +2335,7 @@ internal void OnNewLicenseList() {
23352335
return FormatBotResponse(Strings.BotNotConnected);
23362336
}
23372337

2338-
(bool success, string message) = await Bot.Actions.Play(gameIDs, gameName).ConfigureAwait(false);
2338+
(bool success, string message) = await Bot.Actions.Play(gameIDs).ConfigureAwait(false);
23392339

23402340
return FormatBotResponse(success ? message : Strings.FormatWarningFailedWithError(message));
23412341
}
@@ -2357,32 +2357,24 @@ internal void OnNewLicenseList() {
23572357

23582358
string[] games = targetGameIDs.Split(SharedInfo.ListElementSeparators, StringSplitOptions.RemoveEmptyEntries);
23592359

2360-
if (games.Length == 0) {
2361-
return FormatBotResponse(Strings.FormatErrorIsEmpty(nameof(games)));
2360+
switch (games.Length) {
2361+
case 0:
2362+
return FormatBotResponse(Strings.FormatErrorIsEmpty(nameof(games)));
2363+
case > ArchiHandler.MaxGamesPlayedConcurrently:
2364+
return FormatBotResponse(Strings.FormatWarningFailedWithError($"{nameof(games)} > {ArchiHandler.MaxGamesPlayedConcurrently}"));
23622365
}
23632366

2364-
HashSet<uint> gamesToPlay = new(Math.Min(games.Length, ArchiHandler.MaxGamesPlayedConcurrently));
2365-
StringBuilder gameName = new();
2367+
HashSet<uint> gamesToPlay = new(games.Length);
23662368

23672369
foreach (string game in games) {
23682370
if (!uint.TryParse(game, out uint gameID) || (gameID == 0)) {
2369-
if (gameName.Length > 0) {
2370-
gameName.Append(' ');
2371-
}
2372-
2373-
gameName.Append(game);
2374-
2375-
continue;
2376-
}
2377-
2378-
if (gamesToPlay.Count >= ArchiHandler.MaxGamesPlayedConcurrently) {
2379-
return FormatBotResponse(Strings.FormatWarningFailedWithError($"{nameof(gamesToPlay)} > {ArchiHandler.MaxGamesPlayedConcurrently}"));
2371+
return FormatBotResponse(Strings.FormatErrorIsInvalid(nameof(game)));
23802372
}
23812373

23822374
gamesToPlay.Add(gameID);
23832375
}
23842376

2385-
return await ResponsePlay(access, gamesToPlay, gameName.Length > 0 ? gameName.ToString() : null).ConfigureAwait(false);
2377+
return await ResponsePlay(access, gamesToPlay).ConfigureAwait(false);
23862378
}
23872379

23882380
private static async Task<string?> ResponsePlay(EAccess access, string botNames, string targetGameIDs, ulong steamID = 0) {

ArchiSteamFarm/Steam/Storage/BotConfig.cs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,11 @@ public sealed class BotConfig {
5454
[PublicAPI]
5555
public const EBotBehaviour DefaultBotBehaviour = EBotBehaviour.None;
5656

57+
[Obsolete("Functionality deprecated, will be removed in the next version")]
5758
[PublicAPI]
5859
public const string? DefaultCustomGamePlayedWhileFarming = null;
5960

61+
[Obsolete("Functionality deprecated, will be removed in the next version")]
6062
[PublicAPI]
6163
public const string? DefaultCustomGamePlayedWhileIdle = null;
6264

@@ -207,9 +209,11 @@ public WebProxy? WebProxy {
207209
public ImmutableHashSet<EAssetType> CompleteTypesToSend { get; init; } = DefaultCompleteTypesToSend;
208210

209211
[JsonInclude]
212+
[Obsolete("Functionality deprecated, will be removed in the next version")]
210213
public string? CustomGamePlayedWhileFarming { get; init; } = DefaultCustomGamePlayedWhileFarming;
211214

212215
[JsonInclude]
216+
[Obsolete("Functionality deprecated, will be removed in the next version")]
213217
public string? CustomGamePlayedWhileIdle { get; init; } = DefaultCustomGamePlayedWhileIdle;
214218

215219
[JsonInclude]
@@ -388,11 +392,15 @@ public BotConfig() { }
388392
[UsedImplicitly]
389393
public bool ShouldSerializeCompleteTypesToSend() => !Saving || ((CompleteTypesToSend != DefaultCompleteTypesToSend) && !CompleteTypesToSend.SetEquals(DefaultCompleteTypesToSend));
390394

395+
#pragma warning disable CA1822
396+
[Obsolete("Functionality deprecated, will be removed in the next version")]
391397
[UsedImplicitly]
392-
public bool ShouldSerializeCustomGamePlayedWhileFarming() => !Saving || (CustomGamePlayedWhileFarming != DefaultCustomGamePlayedWhileFarming);
398+
public bool ShouldSerializeCustomGamePlayedWhileFarming() => false;
393399

400+
[Obsolete("Functionality deprecated, will be removed in the next version")]
394401
[UsedImplicitly]
395-
public bool ShouldSerializeCustomGamePlayedWhileIdle() => !Saving || (CustomGamePlayedWhileIdle != DefaultCustomGamePlayedWhileIdle);
402+
public bool ShouldSerializeCustomGamePlayedWhileIdle() => false;
403+
#pragma warning restore CA1822
396404

397405
[UsedImplicitly]
398406
public bool ShouldSerializeEnabled() => !Saving || (Enabled != DefaultEnabled);
@@ -521,15 +529,6 @@ public static async Task<bool> Write(string filePath, BotConfig botConfig) {
521529
}
522530
}
523531

524-
if (!string.IsNullOrEmpty(CustomGamePlayedWhileFarming)) {
525-
try {
526-
// Test CustomGamePlayedWhileFarming against supported format, otherwise we'll throw later when used
527-
string _ = string.Format(CultureInfo.CurrentCulture, CustomGamePlayedWhileFarming, null, null);
528-
} catch (FormatException e) {
529-
return (false, Strings.FormatErrorConfigPropertyInvalid(nameof(CustomGamePlayedWhileFarming), e.Message));
530-
}
531-
}
532-
533532
foreach (EFarmingOrder farmingOrder in FarmingOrders.Where(static farmingOrder => !Enum.IsDefined(farmingOrder))) {
534533
return (false, Strings.FormatErrorConfigPropertyInvalid(nameof(FarmingOrders), farmingOrder));
535534
}

0 commit comments

Comments
 (0)