@@ -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
0 commit comments