diff --git a/ArchiSteamFarm/Steam/Bot.cs b/ArchiSteamFarm/Steam/Bot.cs index 5e41daba8..704d771f8 100644 --- a/ArchiSteamFarm/Steam/Bot.cs +++ b/ArchiSteamFarm/Steam/Bot.cs @@ -2843,6 +2843,8 @@ public sealed class Bot : IAsyncDisposable, IDisposable { UpdateTokens(pollResult.AccessToken, pollResult.RefreshToken); } + string machineNameFormat = !string.IsNullOrEmpty(BotConfig.MachineName) ? BotConfig.MachineName : "{0} ({1}/{2})"; + SteamUser.LogOnDetails logOnDetails = new() { AccessToken = RefreshToken, CellID = ASF.GlobalDatabase?.CellID, @@ -2850,6 +2852,7 @@ public sealed class Bot : IAsyncDisposable, IDisposable { ClientLanguage = CultureInfo.CurrentCulture.ToSteamClientLanguage(), GamingDeviceType = BotConfig.GamingDeviceType, LoginID = LoginID, + MachineName = string.Format(CultureInfo.CurrentCulture, machineNameFormat, Environment.MachineName, SharedInfo.PublicIdentifier, SharedInfo.Version), ShouldRememberPassword = BotConfig.UseLoginKeys, UIMode = BotConfig.UserInterfaceMode, Username = username diff --git a/ArchiSteamFarm/Steam/Storage/BotConfig.cs b/ArchiSteamFarm/Steam/Storage/BotConfig.cs index 405e8e4f9..121b2a0c1 100644 --- a/ArchiSteamFarm/Steam/Storage/BotConfig.cs +++ b/ArchiSteamFarm/Steam/Storage/BotConfig.cs @@ -72,6 +72,9 @@ public sealed class BotConfig { [PublicAPI] public const byte DefaultHoursUntilCardDrops = 3; + [PublicAPI] + public const string? DefaultMachineName = null; + [PublicAPI] public const EPersonaStateFlag DefaultOnlineFlags = 0; @@ -237,6 +240,9 @@ public sealed class BotConfig { [JsonInclude] public ImmutableHashSet LootableTypes { get; init; } = DefaultLootableTypes; + [JsonInclude] + public string? MachineName { get; init; } = DefaultMachineName; + [JsonDisallowNull] [JsonInclude] public ImmutableHashSet MatchableTypes { get; init; } = DefaultMatchableTypes; @@ -409,6 +415,9 @@ public sealed class BotConfig { [UsedImplicitly] public bool ShouldSerializeLootableTypes() => !Saving || ((LootableTypes != DefaultLootableTypes) && !LootableTypes.SetEquals(DefaultLootableTypes)); + [UsedImplicitly] + public bool ShouldSerializeMachineName() => !Saving || (MachineName != DefaultMachineName); + [UsedImplicitly] public bool ShouldSerializeMatchableTypes() => !Saving || ((MatchableTypes != DefaultMatchableTypes) && !MatchableTypes.SetEquals(DefaultMatchableTypes)); @@ -490,6 +499,28 @@ public sealed class BotConfig { return (false, Strings.FormatErrorConfigPropertyInvalid(nameof(BotBehaviour), BotBehaviour)); } + HashSet? completeTypesToSendValidTypes = null; + + foreach (EAssetType completableType in CompleteTypesToSend) { + if (!Enum.IsDefined(completableType)) { + return (false, Strings.FormatErrorConfigPropertyInvalid(nameof(CompleteTypesToSend), completableType)); + } + + if (completeTypesToSendValidTypes == null) { + SwaggerValidValuesAttribute? completeTypesToSendValidValues = typeof(BotConfig).GetProperty(nameof(CompleteTypesToSend))?.GetCustomAttribute(); + + if (completeTypesToSendValidValues?.ValidIntValues == null) { + throw new InvalidOperationException(nameof(completeTypesToSendValidValues)); + } + + completeTypesToSendValidTypes = completeTypesToSendValidValues.ValidIntValues.Select(static value => (EAssetType) value).ToHashSet(); + } + + if (!completeTypesToSendValidTypes.Contains(completableType)) { + return (false, Strings.FormatErrorConfigPropertyInvalid(nameof(CompleteTypesToSend), completableType)); + } + } + if (!string.IsNullOrEmpty(CustomGamePlayedWhileFarming)) { try { // Test CustomGamePlayedWhileFarming against supported format, otherwise we'll throw later when used @@ -519,25 +550,12 @@ public sealed class BotConfig { return (false, Strings.FormatErrorConfigPropertyInvalid(nameof(LootableTypes), lootableType)); } - HashSet? completeTypesToSendValidTypes = null; - - foreach (EAssetType completableType in CompleteTypesToSend) { - if (!Enum.IsDefined(completableType)) { - return (false, Strings.FormatErrorConfigPropertyInvalid(nameof(CompleteTypesToSend), completableType)); - } - - if (completeTypesToSendValidTypes == null) { - SwaggerValidValuesAttribute? completeTypesToSendValidValues = typeof(BotConfig).GetProperty(nameof(CompleteTypesToSend))?.GetCustomAttribute(); - - if (completeTypesToSendValidValues?.ValidIntValues == null) { - throw new InvalidOperationException(nameof(completeTypesToSendValidValues)); - } - - completeTypesToSendValidTypes = completeTypesToSendValidValues.ValidIntValues.Select(static value => (EAssetType) value).ToHashSet(); - } - - if (!completeTypesToSendValidTypes.Contains(completableType)) { - return (false, Strings.FormatErrorConfigPropertyInvalid(nameof(CompleteTypesToSend), completableType)); + if (!string.IsNullOrEmpty(MachineName)) { + try { + // Test MachineName against supported format, otherwise we'll throw later when used + string _ = string.Format(CultureInfo.CurrentCulture, MachineName, null, null, null); + } catch (FormatException e) { + return (false, Strings.FormatErrorConfigPropertyInvalid(nameof(MachineName), e.Message)); } }