@@ -244,36 +244,43 @@ private static bool CanAccess(PlatformUserIdentifierAbs internalId, TileEntitySi
244244 {
245245 if ( CanAccess ( internalId , target , out var targetHasPassword ) )
246246 {
247+ _log . Debug ( $ "CAN ACCESS because: player { internalId } already has permission to the target panel.") ;
247248 return true ;
248- } // targetBlockPos is locked and entityPlayer doesn't have access
249- if ( ! targetHasPassword
250- || source == null
251- || ! source . IsLocked ( )
252- || ! source . HasPassword ( ) )
249+ } // so target is locked and entityPlayer isn't already registered as an authorized user
250+ if ( ! targetHasPassword )
253251 {
254- _log . Debug ( $ "CANNOT ACCESS because: !targetHasPassword ( { ! targetHasPassword } ) || source == null( { source == null } ) || !source.IsLocked()( { ! source . IsLocked ( ) } ) || !source.HasPassword()( { ! source . HasPassword ( ) } ) ") ;
252+ _log . Debug ( "CANNOT ACCESS because: target does not have a password. " ) ;
255253 return false ;
256- } // source and targetBlockPos have passwords, source is locked
257- if ( source . GetOwner ( ) . Equals ( target . GetOwner ( ) )
258- && source . GetPassword ( ) . Equals ( target . GetPassword ( ) ) )
254+ } // so target does have a password set
255+ if ( source == null )
259256 {
260- _log . Debug ( $ "CAN ACCESS because: source.GetOwner() == targetBlockPos.GetOwner()({ source . GetOwner ( ) == target . GetOwner ( ) } ) && source.GetPassword() == targetBlockPos.GetPassword()({ source . GetPassword ( ) == target . GetPassword ( ) } )") ;
261- target . GetUsers ( ) . Add ( internalId ) ; // dynamically register this user to targetBlockPos!
262- target . SetModified ( ) ;
263- return true ;
264- } // source/targetBlockPos owners or passwords don't match=
265- _log . Debug ( $@ "CANNOT ACCESS because: source.GetOwner() != targetBlockPos.GetOwner() || source.GetPassword() != targetBlockPos.GetPassword()
266- source.owner:
267- CombinedString:{ source . GetOwner ( ) . CombinedString }
268- PlatformIdentifierString:{ source . GetOwner ( ) . PlatformIdentifierString }
269- ReadablePlatformUserIdentifier:{ source . GetOwner ( ) . ReadablePlatformUserIdentifier }
270- targetBlockPos.owner:
271- CombinedString:{ target . GetOwner ( ) . CombinedString }
272- PlatformIdentifierString:{ target . GetOwner ( ) . PlatformIdentifierString }
273- ReadablePlatformUserIdentifier:{ target . GetOwner ( ) . ReadablePlatformUserIdentifier }
274- source.pass:{ source . GetPassword ( ) }
275- targetBlockPos.pass:{ target . GetPassword ( ) } " ) ;
276- return false ;
257+ _log . Debug ( "CANNOT ACCESS because: source is a portable panel, which we cannot apply a password from." ) ;
258+ return false ;
259+ } // so source is not a portable panel and might have a password for us to apply to target
260+ if ( ! source . IsLocked ( ) )
261+ {
262+ _log . Debug ( "CANNOT ACCESS because: source is not locked, so we know it does NOT have a password we could try applying to target." ) ;
263+ return false ;
264+ } // so source is locked
265+ if ( ! source . HasPassword ( ) )
266+ {
267+ _log . Debug ( "CANNOT ACCESS because: source is locked but has no password, so we have no password to try applying to target." ) ;
268+ return false ;
269+ } // so source and target each have passwords and we might be able to apply the password from source to target
270+ if ( ! source . GetOwner ( ) . Equals ( target . GetOwner ( ) ) )
271+ {
272+ _log . Debug ( "CANNOT ACCESS because: source owner does not match target owner, so a password cannot be applied to target even if it matches." ) ;
273+ return false ;
274+ } // so source and target have the same owners...
275+ if ( ! source . GetPassword ( ) . Equals ( target . GetPassword ( ) ) )
276+ {
277+ _log . Debug ( "CANNOT ACCESS because: source and target do not share the same password." ) ;
278+ return false ;
279+ } // so source and target share the same password...
280+ _log . Debug ( "CAN ACCESS because: source panel shares owner and password with target panel." ) ;
281+ target . GetUsers ( ) . Add ( internalId ) ; // dynamically register this user to targetBlockPos
282+ target . SetModified ( ) ;
283+ return true ;
277284 }
278285
279286 /// <summary>
0 commit comments