Skip to content

Commit a313a19

Browse files
committed
Add support for machine name
1 parent c5f7565 commit a313a19

File tree

2 files changed

+40
-19
lines changed

2 files changed

+40
-19
lines changed

ArchiSteamFarm/Steam/Bot.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2843,13 +2843,16 @@ private async void OnConnected(SteamClient.ConnectedCallback callback) {
28432843
UpdateTokens(pollResult.AccessToken, pollResult.RefreshToken);
28442844
}
28452845

2846+
string machineNameFormat = !string.IsNullOrEmpty(BotConfig.MachineName) ? BotConfig.MachineName : "{0} ({1}/{2})";
2847+
28462848
SteamUser.LogOnDetails logOnDetails = new() {
28472849
AccessToken = RefreshToken,
28482850
CellID = ASF.GlobalDatabase?.CellID,
28492851
ChatMode = SteamUser.ChatMode.NewSteamChat,
28502852
ClientLanguage = CultureInfo.CurrentCulture.ToSteamClientLanguage(),
28512853
GamingDeviceType = BotConfig.GamingDeviceType,
28522854
LoginID = LoginID,
2855+
MachineName = string.Format(CultureInfo.CurrentCulture, machineNameFormat, Environment.MachineName, SharedInfo.PublicIdentifier, SharedInfo.Version),
28532856
ShouldRememberPassword = BotConfig.UseLoginKeys,
28542857
UIMode = BotConfig.UserInterfaceMode,
28552858
Username = username

ArchiSteamFarm/Steam/Storage/BotConfig.cs

Lines changed: 37 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ public sealed class BotConfig {
7272
[PublicAPI]
7373
public const byte DefaultHoursUntilCardDrops = 3;
7474

75+
[PublicAPI]
76+
public const string? DefaultMachineName = null;
77+
7578
[PublicAPI]
7679
public const EPersonaStateFlag DefaultOnlineFlags = 0;
7780

@@ -237,6 +240,9 @@ public WebProxy? WebProxy {
237240
[JsonInclude]
238241
public ImmutableHashSet<EAssetType> LootableTypes { get; init; } = DefaultLootableTypes;
239242

243+
[JsonInclude]
244+
public string? MachineName { get; init; } = DefaultMachineName;
245+
240246
[JsonDisallowNull]
241247
[JsonInclude]
242248
public ImmutableHashSet<EAssetType> MatchableTypes { get; init; } = DefaultMatchableTypes;
@@ -409,6 +415,9 @@ public BotConfig() { }
409415
[UsedImplicitly]
410416
public bool ShouldSerializeLootableTypes() => !Saving || ((LootableTypes != DefaultLootableTypes) && !LootableTypes.SetEquals(DefaultLootableTypes));
411417

418+
[UsedImplicitly]
419+
public bool ShouldSerializeMachineName() => !Saving || (MachineName != DefaultMachineName);
420+
412421
[UsedImplicitly]
413422
public bool ShouldSerializeMatchableTypes() => !Saving || ((MatchableTypes != DefaultMatchableTypes) && !MatchableTypes.SetEquals(DefaultMatchableTypes));
414423

@@ -490,6 +499,28 @@ public static async Task<bool> Write(string filePath, BotConfig botConfig) {
490499
return (false, Strings.FormatErrorConfigPropertyInvalid(nameof(BotBehaviour), BotBehaviour));
491500
}
492501

502+
HashSet<EAssetType>? completeTypesToSendValidTypes = null;
503+
504+
foreach (EAssetType completableType in CompleteTypesToSend) {
505+
if (!Enum.IsDefined(completableType)) {
506+
return (false, Strings.FormatErrorConfigPropertyInvalid(nameof(CompleteTypesToSend), completableType));
507+
}
508+
509+
if (completeTypesToSendValidTypes == null) {
510+
SwaggerValidValuesAttribute? completeTypesToSendValidValues = typeof(BotConfig).GetProperty(nameof(CompleteTypesToSend))?.GetCustomAttribute<SwaggerValidValuesAttribute>();
511+
512+
if (completeTypesToSendValidValues?.ValidIntValues == null) {
513+
throw new InvalidOperationException(nameof(completeTypesToSendValidValues));
514+
}
515+
516+
completeTypesToSendValidTypes = completeTypesToSendValidValues.ValidIntValues.Select(static value => (EAssetType) value).ToHashSet();
517+
}
518+
519+
if (!completeTypesToSendValidTypes.Contains(completableType)) {
520+
return (false, Strings.FormatErrorConfigPropertyInvalid(nameof(CompleteTypesToSend), completableType));
521+
}
522+
}
523+
493524
if (!string.IsNullOrEmpty(CustomGamePlayedWhileFarming)) {
494525
try {
495526
// Test CustomGamePlayedWhileFarming against supported format, otherwise we'll throw later when used
@@ -519,25 +550,12 @@ public static async Task<bool> Write(string filePath, BotConfig botConfig) {
519550
return (false, Strings.FormatErrorConfigPropertyInvalid(nameof(LootableTypes), lootableType));
520551
}
521552

522-
HashSet<EAssetType>? completeTypesToSendValidTypes = null;
523-
524-
foreach (EAssetType completableType in CompleteTypesToSend) {
525-
if (!Enum.IsDefined(completableType)) {
526-
return (false, Strings.FormatErrorConfigPropertyInvalid(nameof(CompleteTypesToSend), completableType));
527-
}
528-
529-
if (completeTypesToSendValidTypes == null) {
530-
SwaggerValidValuesAttribute? completeTypesToSendValidValues = typeof(BotConfig).GetProperty(nameof(CompleteTypesToSend))?.GetCustomAttribute<SwaggerValidValuesAttribute>();
531-
532-
if (completeTypesToSendValidValues?.ValidIntValues == null) {
533-
throw new InvalidOperationException(nameof(completeTypesToSendValidValues));
534-
}
535-
536-
completeTypesToSendValidTypes = completeTypesToSendValidValues.ValidIntValues.Select(static value => (EAssetType) value).ToHashSet();
537-
}
538-
539-
if (!completeTypesToSendValidTypes.Contains(completableType)) {
540-
return (false, Strings.FormatErrorConfigPropertyInvalid(nameof(CompleteTypesToSend), completableType));
553+
if (!string.IsNullOrEmpty(MachineName)) {
554+
try {
555+
// Test MachineName against supported format, otherwise we'll throw later when used
556+
string _ = string.Format(CultureInfo.CurrentCulture, MachineName, null, null, null);
557+
} catch (FormatException e) {
558+
return (false, Strings.FormatErrorConfigPropertyInvalid(nameof(MachineName), e.Message));
541559
}
542560
}
543561

0 commit comments

Comments
 (0)