Skip to content

Commit 32238ba

Browse files
committed
Closes #3483
1 parent 2172f8b commit 32238ba

File tree

2 files changed

+35
-10
lines changed

2 files changed

+35
-10
lines changed

ArchiSteamFarm/Steam/Bot.cs

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3383,7 +3383,7 @@ private async void OnLoggedOn(SteamUser.LoggedOnCallback callback) {
33833383
}
33843384

33853385
if (callback.ParentalSettings != null) {
3386-
(SteamParentalActive, string? steamParentalCode) = ValidateSteamParental(callback.ParentalSettings, BotConfig.SteamParentalCode, Program.SteamParentalGeneration);
3386+
(SteamParentalActive, string? steamParentalCode) = ValidateSteamParental(callback.ParentalSettings, BotConfig.SteamParentalCode, BotDatabase.CachedSteamParentalCode, Program.SteamParentalGeneration);
33873387

33883388
if (SteamParentalActive) {
33893389
// Steam parental enabled
@@ -3412,6 +3412,8 @@ private async void OnLoggedOn(SteamUser.LoggedOnCallback callback) {
34123412
return;
34133413
}
34143414
}
3415+
3416+
BotDatabase.CachedSteamParentalCode = steamParentalCode;
34153417
}
34163418
} else {
34173419
// Steam parental disabled
@@ -4105,7 +4107,7 @@ private void UpdateTokens(string accessToken, string? refreshToken = null) {
41054107
}
41064108
}
41074109

4108-
private (bool IsSteamParentalEnabled, string? SteamParentalCode) ValidateSteamParental(ParentalSettings settings, string? steamParentalCode = null, bool allowGeneration = true) {
4110+
private (bool IsSteamParentalEnabled, string? SteamParentalCode) ValidateSteamParental(ParentalSettings settings, string? steamParentalCode = null, string? cachedSteamParentalCode = null, bool allowGeneration = true) {
41094111
ArgumentNullException.ThrowIfNull(settings);
41104112

41114113
if (!settings.is_enabled || (settings.passwordhash == null)) {
@@ -4133,21 +4135,27 @@ private void UpdateTokens(string accessToken, string? refreshToken = null) {
41334135
return (true, null);
41344136
}
41354137

4136-
if (!string.IsNullOrEmpty(steamParentalCode)) {
4138+
foreach (string? parentalCode in steamParentalCode.ToEnumerable().Append(cachedSteamParentalCode)) {
4139+
if (string.IsNullOrEmpty(parentalCode)) {
4140+
continue;
4141+
}
4142+
41374143
byte i = 0;
41384144

4139-
byte[] password = new byte[steamParentalCode.Length];
4145+
byte[] password = new byte[parentalCode.Length];
41404146

4141-
foreach (char character in steamParentalCode.TakeWhile(static character => character is >= '0' and <= '9')) {
4147+
foreach (char character in parentalCode.TakeWhile(static character => character is >= '0' and <= '9')) {
41424148
password[i++] = (byte) character;
41434149
}
41444150

4145-
if (i >= steamParentalCode.Length) {
4146-
byte[] passwordHash = ArchiCryptoHelper.Hash(password, settings.salt, (byte) settings.passwordhash.Length, steamParentalHashingMethod);
4151+
if (i < parentalCode.Length) {
4152+
continue;
4153+
}
41474154

4148-
if (passwordHash.SequenceEqual(settings.passwordhash)) {
4149-
return (true, steamParentalCode);
4150-
}
4155+
byte[] passwordHash = ArchiCryptoHelper.Hash(password, settings.salt, (byte) settings.passwordhash.Length, steamParentalHashingMethod);
4156+
4157+
if (passwordHash.SequenceEqual(settings.passwordhash)) {
4158+
return (true, parentalCode);
41514159
}
41524160
}
41534161

ArchiSteamFarm/Steam/Storage/BotDatabase.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,20 @@ internal string? AccessToken {
8181
}
8282
}
8383

84+
[JsonInclude]
85+
internal string? CachedSteamParentalCode {
86+
get;
87+
88+
set {
89+
if (field == value) {
90+
return;
91+
}
92+
93+
field = value;
94+
Utilities.InBackground(Save);
95+
}
96+
}
97+
8498
[JsonDisallowNull]
8599
[JsonInclude]
86100
[JsonObjectCreationHandling(JsonObjectCreationHandling.Populate)]
@@ -226,6 +240,9 @@ public void SaveToJsonStorage(string key, JsonElement value) {
226240
[UsedImplicitly]
227241
public bool ShouldSerializeAccessToken() => !string.IsNullOrEmpty(AccessToken);
228242

243+
[UsedImplicitly]
244+
public bool ShouldSerializeCachedSteamParentalCode() => !string.IsNullOrEmpty(CachedSteamParentalCode);
245+
229246
[UsedImplicitly]
230247
public bool ShouldSerializeExtraStorePackages() => ExtraStorePackages.Count > 0;
231248

0 commit comments

Comments
 (0)