mirror of
https://github.com/JustArchiNET/ArchiSteamFarm.git
synced 2026-01-06 17:10:13 +00:00
Closes #3483
This commit is contained in:
@@ -3383,7 +3383,7 @@ public sealed class Bot : IAsyncDisposable, IDisposable {
|
||||
}
|
||||
|
||||
if (callback.ParentalSettings != null) {
|
||||
(SteamParentalActive, string? steamParentalCode) = ValidateSteamParental(callback.ParentalSettings, BotConfig.SteamParentalCode, Program.SteamParentalGeneration);
|
||||
(SteamParentalActive, string? steamParentalCode) = ValidateSteamParental(callback.ParentalSettings, BotConfig.SteamParentalCode, BotDatabase.CachedSteamParentalCode, Program.SteamParentalGeneration);
|
||||
|
||||
if (SteamParentalActive) {
|
||||
// Steam parental enabled
|
||||
@@ -3412,6 +3412,8 @@ public sealed class Bot : IAsyncDisposable, IDisposable {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
BotDatabase.CachedSteamParentalCode = steamParentalCode;
|
||||
}
|
||||
} else {
|
||||
// Steam parental disabled
|
||||
@@ -4105,7 +4107,7 @@ public sealed class Bot : IAsyncDisposable, IDisposable {
|
||||
}
|
||||
}
|
||||
|
||||
private (bool IsSteamParentalEnabled, string? SteamParentalCode) ValidateSteamParental(ParentalSettings settings, string? steamParentalCode = null, bool allowGeneration = true) {
|
||||
private (bool IsSteamParentalEnabled, string? SteamParentalCode) ValidateSteamParental(ParentalSettings settings, string? steamParentalCode = null, string? cachedSteamParentalCode = null, bool allowGeneration = true) {
|
||||
ArgumentNullException.ThrowIfNull(settings);
|
||||
|
||||
if (!settings.is_enabled || (settings.passwordhash == null)) {
|
||||
@@ -4133,21 +4135,27 @@ public sealed class Bot : IAsyncDisposable, IDisposable {
|
||||
return (true, null);
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(steamParentalCode)) {
|
||||
foreach (string? parentalCode in steamParentalCode.ToEnumerable().Append(cachedSteamParentalCode)) {
|
||||
if (string.IsNullOrEmpty(parentalCode)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
byte i = 0;
|
||||
|
||||
byte[] password = new byte[steamParentalCode.Length];
|
||||
byte[] password = new byte[parentalCode.Length];
|
||||
|
||||
foreach (char character in steamParentalCode.TakeWhile(static character => character is >= '0' and <= '9')) {
|
||||
foreach (char character in parentalCode.TakeWhile(static character => character is >= '0' and <= '9')) {
|
||||
password[i++] = (byte) character;
|
||||
}
|
||||
|
||||
if (i >= steamParentalCode.Length) {
|
||||
byte[] passwordHash = ArchiCryptoHelper.Hash(password, settings.salt, (byte) settings.passwordhash.Length, steamParentalHashingMethod);
|
||||
if (i < parentalCode.Length) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (passwordHash.SequenceEqual(settings.passwordhash)) {
|
||||
return (true, steamParentalCode);
|
||||
}
|
||||
byte[] passwordHash = ArchiCryptoHelper.Hash(password, settings.salt, (byte) settings.passwordhash.Length, steamParentalHashingMethod);
|
||||
|
||||
if (passwordHash.SequenceEqual(settings.passwordhash)) {
|
||||
return (true, parentalCode);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -81,6 +81,20 @@ public sealed class BotDatabase : GenericDatabase {
|
||||
}
|
||||
}
|
||||
|
||||
[JsonInclude]
|
||||
internal string? CachedSteamParentalCode {
|
||||
get;
|
||||
|
||||
set {
|
||||
if (field == value) {
|
||||
return;
|
||||
}
|
||||
|
||||
field = value;
|
||||
Utilities.InBackground(Save);
|
||||
}
|
||||
}
|
||||
|
||||
[JsonDisallowNull]
|
||||
[JsonInclude]
|
||||
[JsonObjectCreationHandling(JsonObjectCreationHandling.Populate)]
|
||||
@@ -226,6 +240,9 @@ public sealed class BotDatabase : GenericDatabase {
|
||||
[UsedImplicitly]
|
||||
public bool ShouldSerializeAccessToken() => !string.IsNullOrEmpty(AccessToken);
|
||||
|
||||
[UsedImplicitly]
|
||||
public bool ShouldSerializeCachedSteamParentalCode() => !string.IsNullOrEmpty(CachedSteamParentalCode);
|
||||
|
||||
[UsedImplicitly]
|
||||
public bool ShouldSerializeExtraStorePackages() => ExtraStorePackages.Count > 0;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user