public bool CheckProtectionAccess(ProtectionEntry protection, TSPlayer player, bool fullAccessRequired = false) { bool hasAccess = (player.IsLoggedIn && protection.Owner == player.Account.ID); if (!hasAccess && !fullAccessRequired) { hasAccess = player.Group.HasPermission(ProtectorPlugin.UseEverything_Permission); if (!hasAccess) { hasAccess = protection.IsSharedWithPlayer(player); } } return(hasAccess); }
private void ProtectionSharePreValidation( TSPlayer player, DPoint tileLocation, bool shareOrUnshare, bool checkPermissions, out ProtectionEntry protection ) { ITile tile = TerrariaUtils.Tiles[tileLocation]; int blockType = tile.type; if (!ProtectionManager.IsShareableBlockType(blockType)) { throw new InvalidBlockTypeException(blockType); } if (checkPermissions) { if ( (tile.type == TileID.Containers || tile.type == TileID.Containers2 || tile.type == TileID.Dressers) && !player.Group.HasPermission(ProtectorPlugin.ChestSharing_Permission) ) { throw new MissingPermissionException(ProtectorPlugin.ChestSharing_Permission); } if ( TerrariaUtils.Tiles.IsSwitchableObject(tile.type) && !player.Group.HasPermission(ProtectorPlugin.SwitchSharing_Permission) ) { throw new MissingPermissionException(ProtectorPlugin.SwitchSharing_Permission); } if ( ( tile.type == TileID.Signs || tile.type == TileID.Tombstones || tile.type == TileID.Beds || tile.type == TileID.OpenDoor || tile.type == TileID.ClosedDoor ) && !player.Group.HasPermission(ProtectorPlugin.OtherSharing_Permission) ) { throw new MissingPermissionException(ProtectorPlugin.OtherSharing_Permission); } } tileLocation = TerrariaUtils.Tiles.MeasureObject(tileLocation).OriginTileLocation; lock (this.WorldMetadata.Protections) if (!this.WorldMetadata.Protections.TryGetValue(tileLocation, out protection)) { throw new NoProtectionException(tileLocation); } if (checkPermissions) { if ( protection.BankChestKey != BankChestDataKey.Invalid && !player.Group.HasPermission(ProtectorPlugin.BankChestShare_Permission) ) { throw new MissingPermissionException(ProtectorPlugin.BankChestShare_Permission); } } if (protection.Owner != player.Account.ID && !player.Group.HasPermission(ProtectorPlugin.ProtectionMaster_Permission)) { if (!protection.IsSharedWithPlayer(player)) { throw new TileProtectedException(tileLocation); } if (shareOrUnshare) { if (!this.Config.AllowChainedSharing) { throw new TileProtectedException(tileLocation); } } else if (!this.Config.AllowChainedShareAltering) { throw new TileProtectedException(tileLocation); } } }