private bool Handle(Inventory.SyncListItemInfo inv, Keycard.Permissions perms, bool requireAll = true) { if (perms == Keycard.Permissions.None) { return(true); } foreach (var item in inv) { RemoteKeycard.Debug($"Processing an item in the player’s inventory: {item.id} ({(int)item.id})"); if (RKConfig.Cards?.Length > 0 && !RKConfig.Cards.Contains(item.id)) { continue; } var gameItem = Array.Find(GetItems(), i => i.id == item.id); RemoteKeycard.Debug($"Game item is null: {gameItem == null}"); // Relevant for items whose type was not found if (gameItem == null) { continue; } var itemPerms = Keycard.ToTruthyPermissions(gameItem.permissions); RemoteKeycard.Debug($"Game item processing: C {gameItem.itemCategory} ({(int)gameItem.itemCategory}) | T {item.id} ({(int)item.id}) | P {itemPerms} | P:string[] {string.Join(", ", gameItem.permissions)}"); if (itemPerms.HasFlagFast(perms, requireAll)) { RemoteKeycard.Debug($"Item has successfully passed permission validation: {gameItem.id} ({(int)gameItem.id})"); return(true); } } return(false); }
public void OnLockerAccess(InteractingLockerEventArgs ev) { if (!CanInteract(ev.Player) || !RKConfig.HandleLockersAccess) { return; } RemoteKeycard.Debug($"Player {ev.Player.Nickname} ({ev.Player.UserId}) is trying to access the locker"); RemoteKeycard.Debug($"Locker permissions: {(!string.IsNullOrEmpty(ev.Chamber.accessToken) ? "(null)" : ev.Chamber.accessToken)}"); if (ev.IsAllowed) { RemoteKeycard.Debug("Locker access is allowed"); return; } RemoteKeycard.Debug("Further processing is allowed..."); var permissions = Keycard.ToTruthyPermissions(ev.Chamber.accessToken); var playerIntentory = ev.Player.Inventory.items; ev.IsAllowed = Handle(playerIntentory, permissions); }