Add support for machine name

This commit is contained in:
Łukasz Domeradzki
2025-09-08 22:50:23 +02:00
parent c5f7565ac0
commit a313a19cec
2 changed files with 40 additions and 19 deletions

View File

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

View File

@@ -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<EAssetType> LootableTypes { get; init; } = DefaultLootableTypes;
[JsonInclude]
public string? MachineName { get; init; } = DefaultMachineName;
[JsonDisallowNull]
[JsonInclude]
public ImmutableHashSet<EAssetType> 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<EAssetType>? 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<SwaggerValidValuesAttribute>();
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<EAssetType>? 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<SwaggerValidValuesAttribute>();
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));
}
}