From dfea6bcf8360e5ebdb4a40f9af46ed2b59581164 Mon Sep 17 00:00:00 2001 From: DuckieTM Date: Sat, 30 May 2026 07:52:02 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=86=99=20Updated=20SQL?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../008_soundboard_fortune_wheel.sql | 131 ++++++++++-------- .../022_wheel_admin_permission.sql | 51 ------- 2 files changed, 71 insertions(+), 111 deletions(-) delete mode 100644 Database Updates/Own_Database_RunFirst/022_wheel_admin_permission.sql diff --git a/Database Updates/008_soundboard_fortune_wheel.sql b/Database Updates/008_soundboard_fortune_wheel.sql index b5dba5ba..49e2c59b 100644 --- a/Database Updates/008_soundboard_fortune_wheel.sql +++ b/Database Updates/008_soundboard_fortune_wheel.sql @@ -1,78 +1,89 @@ --- Soundboard --- The room flag column + sounds table are also created at boot by - -ALTER TABLE `rooms` ADD COLUMN IF NOT EXISTS `soundboard_enabled` TINYINT(1) NOT NULL DEFAULT 0; +ALTER TABLE `rooms` + ADD COLUMN IF NOT EXISTS `soundboard_enabled` TINYINT(1) NOT NULL DEFAULT 0; CREATE TABLE IF NOT EXISTS `soundboard_sounds` ( - `id` INT(11) NOT NULL AUTO_INCREMENT, - `name` VARCHAR(64) NOT NULL DEFAULT '', -- pad label shown in the client - `url` VARCHAR(255) NOT NULL DEFAULT '', -- audio url (uploaded via CMS, like custom badges) - `enabled` TINYINT(1) NOT NULL DEFAULT 1, - `sort_order` INT(11) NOT NULL DEFAULT 0, + `id` INT(11) NOT NULL AUTO_INCREMENT, + `name` VARCHAR(64) NOT NULL DEFAULT '', -- pad label shown in the client + `url` VARCHAR(255) NOT NULL DEFAULT '', -- audio url (uploaded via CMS, like custom badges) + `enabled` TINYINT(1) NOT NULL DEFAULT 1, + `sort_order` INT(11) NOT NULL DEFAULT 0, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; - --- Fortune Wheel --- Tables are also created at boot by WheelManager (CREATE TABLE IF NOT EXISTS), --- so applying this file is only needed to seed prizes + settings. - +-- ---------------------------------------------------------------------------- +-- Fortune Wheel — tables +-- ---------------------------------------------------------------------------- CREATE TABLE IF NOT EXISTS `wheel_prizes` ( - `id` INT(11) NOT NULL AUTO_INCREMENT, - `type` VARCHAR(16) NOT NULL DEFAULT 'nothing', -- item | badge | credits | points | spin | nothing - `value` VARCHAR(64) NOT NULL DEFAULT '', -- item: base item id ; badge: badge code ; others: unused - `amount` INT(11) NOT NULL DEFAULT 1, -- item qty / credits / points / extra spins - `points_type` INT(11) NOT NULL DEFAULT 5, -- for type=points (diamond default 5) - `weight` INT(11) NOT NULL DEFAULT 1, -- relative probability - `label` VARCHAR(64) NOT NULL DEFAULT '', -- slice label override (optional) - `enabled` TINYINT(1) NOT NULL DEFAULT 1, - `sort_order` INT(11) NOT NULL DEFAULT 0, + `id` INT(11) NOT NULL AUTO_INCREMENT, + `type` VARCHAR(16) NOT NULL DEFAULT 'nothing', -- item | badge | credits | points | spin | nothing + `value` VARCHAR(64) NOT NULL DEFAULT '', -- item: base item id ; badge: badge code ; others: unused + `amount` INT(11) NOT NULL DEFAULT 1, -- item qty / credits / points / extra spins + `points_type` INT(11) NOT NULL DEFAULT 5, -- for type=points (diamond default 5) + `weight` INT(11) NOT NULL DEFAULT 1, -- relative probability + `label` VARCHAR(64) NOT NULL DEFAULT '', -- slice label override (optional) + `enabled` TINYINT(1) NOT NULL DEFAULT 1, + `sort_order` INT(11) NOT NULL DEFAULT 0, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; CREATE TABLE IF NOT EXISTS `wheel_user_state` ( - `user_id` INT(11) NOT NULL, - `free_spins` INT(11) NOT NULL DEFAULT 0, -- remaining free spins for the current day - `extra_spins` INT(11) NOT NULL DEFAULT 0, -- bought / won spins - `last_reset` INT(11) NOT NULL DEFAULT 0, -- day index of last daily reset (unix / 86400) + `user_id` INT(11) NOT NULL, + `free_spins` INT(11) NOT NULL DEFAULT 0, -- remaining free spins for the current day + `extra_spins` INT(11) NOT NULL DEFAULT 0, -- bought / won spins + `last_reset` INT(11) NOT NULL DEFAULT 0, -- day index of last daily reset (unix / 86400) PRIMARY KEY (`user_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; CREATE TABLE IF NOT EXISTS `wheel_recent_wins` ( - `id` INT(11) NOT NULL AUTO_INCREMENT, - `user_id` INT(11) NOT NULL, - `username` VARCHAR(64) NOT NULL DEFAULT '', - `look` VARCHAR(255) NOT NULL DEFAULT '', - `prize_label` VARCHAR(64) NOT NULL DEFAULT '', - `won_at` INT(11) NOT NULL DEFAULT 0, - PRIMARY KEY (`id`), - KEY `idx_wheel_recent_wins_id` (`id`) + `id` INT(11) NOT NULL AUTO_INCREMENT, + `user_id` INT(11) NOT NULL, + `username` VARCHAR(64) NOT NULL DEFAULT '', + `look` VARCHAR(255) NOT NULL DEFAULT '', + `prize_label` VARCHAR(64) NOT NULL DEFAULT '', + `won_at` INT(11) NOT NULL DEFAULT 0, + PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; INSERT INTO `emulator_settings` (`key`, `value`, `comment`) VALUES - ('wheel.free_spins_per_day', '1', 'Fortune wheel: free spins granted each day.') - ON DUPLICATE KEY UPDATE `comment` = VALUES(`comment`); -INSERT INTO `emulator_settings` (`key`, `value`, `comment`) VALUES - ('wheel.spin_cost', '50', 'Fortune wheel: cost of one extra spin.') - ON DUPLICATE KEY UPDATE `comment` = VALUES(`comment`); -INSERT INTO `emulator_settings` (`key`, `value`, `comment`) VALUES - ('wheel.spin_cost_type', '5', 'Fortune wheel: currency type for the spin cost (5 = diamonds; -1 = credits).') - ON DUPLICATE KEY UPDATE `comment` = VALUES(`comment`); - - -INSERT INTO `wheel_prizes` (`type`, `amount`, `points_type`, `weight`, `label`, `sort_order`) VALUES - ('points',25, 5, 20, '25 diamonds',1), - ('points',50, 5, 12, '50 diamonds',2), - ('points',200, 5, 3, '200 diamonds',3), - ('credits',100, 0, 15, '100 credits',4), - ('spin',1, 0, 15, '1 Extra spin', 5), - ('spin',2, 0, 6, '2 Extra spins',6), - ('nothing',0, 0, 29, 'Oh to bad!',7); - -INSERT INTO `permission_definitions` - (`permission_key`, `max_value`, `comment`, - `rank_1`, `rank_2`, `rank_3`, `rank_4`, `rank_5`, `rank_6`, `rank_7`) -VALUES - ('acc_wheeladmin', 1, 'Required to open the Fortune Wheel settings popup and edit prize rows.', - 0, 0, 0, 0, 0, 0, 1) + ('wheel.free_spins_per_day', '1', 'Fortune wheel: free spins granted each day.'), + ('wheel.spin_cost', '50', 'Fortune wheel: cost of one extra spin.'), + ('wheel.spin_cost_type', '5', 'Fortune wheel: currency type for the spin cost (5 = diamonds; -1 = credits).') ON DUPLICATE KEY UPDATE `comment` = VALUES(`comment`); + +INSERT INTO `wheel_prizes` (`type`, `amount`, `points_type`, `weight`, `label`, `sort_order`) +SELECT `type`, `amount`, `points_type`, `weight`, `label`, `sort_order` +FROM ( + SELECT 'points' AS `type`, 25 AS `amount`, 5 AS `points_type`, 20 AS `weight`, '25 diamonds' AS `label`, 1 AS `sort_order` + UNION ALL SELECT 'points', 50, 5, 12, '50 diamonds', 2 + UNION ALL SELECT 'points', 200, 5, 3, '200 diamonds', 3 + UNION ALL SELECT 'credits', 100, 0, 15, '100 credits', 4 + UNION ALL SELECT 'spin', 1, 0, 15, '1 Extra spin', 5 + UNION ALL SELECT 'spin', 2, 0, 6, '2 Extra spins', 6 + UNION ALL SELECT 'nothing', 0, 0, 29, 'Oh to bad!', 7 +) AS seed +WHERE NOT EXISTS (SELECT 1 FROM `wheel_prizes`); + +INSERT IGNORE INTO `permission_definitions` (`permission_key`, `max_value`, `comment`) +VALUES ( + 'acc_wheeladmin', + 1, + 'Allows opening the Fortune Wheel prize editor (FortuneWheelSettingsView) to add/edit prize slices. Gated server-side by the same key.' +); + +SET @cols := NULL; +SELECT GROUP_CONCAT(CONCAT('dst.`', `column_name`, '` = src.`', `column_name`, '`') SEPARATOR ', ') + INTO @cols +FROM `information_schema`.`columns` +WHERE `table_schema` = DATABASE() + AND `table_name` = 'permission_definitions' + AND `column_name` REGEXP '^rank_[0-9]+$'; + +SET @sql := CONCAT( + 'UPDATE `permission_definitions` dst ', + 'JOIN `permission_definitions` src ON src.`permission_key` = ''acc_ads_background'' ', + 'SET ', @cols, ' ', + 'WHERE dst.`permission_key` = ''acc_wheeladmin''' +); +PREPARE stmt FROM @sql; +EXECUTE stmt; +DEALLOCATE PREPARE stmt; \ No newline at end of file diff --git a/Database Updates/Own_Database_RunFirst/022_wheel_admin_permission.sql b/Database Updates/Own_Database_RunFirst/022_wheel_admin_permission.sql deleted file mode 100644 index a33b544d..00000000 --- a/Database Updates/Own_Database_RunFirst/022_wheel_admin_permission.sql +++ /dev/null @@ -1,51 +0,0 @@ --- Fortune Wheel — admin permission grant (`acc_wheeladmin`) --- --- Both the client (FortuneWheelView "Settings" button) and the server handlers --- (WheelAdminGetPrizesEvent / WheelAdminSavePrizesEvent, PERMISSION_KEY = --- "acc_wheeladmin") gate the prize editor on `acc_wheeladmin`. --- --- The key itself is registered upstream in --- `Database Updates/008_soundboard_fortune_wheel.sql`, but that file only grants --- it to `rank_7` (its author's 7-rank hotel) and its ON DUPLICATE clause touches --- the comment only. So on a hotel with a different rank layout the key would end --- up granted to nobody useful. This file supplies the portable grant. --- --- Idempotent + portable: registers the key as a no-op safety (in case 008 hasn't --- run yet) and grants it to the same ranks that hold acc_ads_background — the --- adjacent "manage room-ad furni" permission — with dynamic SQL over the per-rank --- columns, so no rank ids are hardcoded. If acc_ads_background is absent the JOIN --- matches nothing and the key stays ungranted (safe; the button just stays --- hidden until granted by hand). --- --- After applying, reload at runtime with `:update_permissions` (rebinds online --- users to the fresh rank and rebroadcasts the permission map — no relog) or --- restart the emulator. - --- 1) Safety no-op registration (008 is the canonical registrar). rank_* default 0. -INSERT IGNORE INTO `permission_definitions` (`permission_key`, `max_value`, `comment`) -VALUES ( - 'acc_wheeladmin', - 1, - 'Allows opening the fortune wheel prize editor (FortuneWheelSettingsView) to add/edit prize slices. Gated server-side by the same key.' -); - --- 2) Grant to the same ranks as acc_ads_background, portably. -SET @cols := NULL; - -SELECT GROUP_CONCAT(CONCAT('dst.`', `column_name`, '` = src.`', `column_name`, '`') SEPARATOR ', ') - INTO @cols -FROM `information_schema`.`columns` -WHERE `table_schema` = DATABASE() - AND `table_name` = 'permission_definitions' - AND `column_name` REGEXP '^rank_[0-9]+$'; - -SET @sql := CONCAT( - 'UPDATE `permission_definitions` dst ', - 'JOIN `permission_definitions` src ON src.`permission_key` = ''acc_ads_background'' ', - 'SET ', @cols, ' ', - 'WHERE dst.`permission_key` = ''acc_wheeladmin''' -); - -PREPARE stmt FROM @sql; -EXECUTE stmt; -DEALLOCATE PREPARE stmt;