Make DB admin ranks more useful (#29906)

* Make DB admin ranks more useful

* Avoid error message when cancelling permission toggle, allow adding localhost admins as real admins.

* Lint.

* Don't SQL error when a previously-unseen player connects.

* Use ckey of permission editor, not mob name.

* Strikethrough

* Order in the list.

* Deadmin, readmin, and 2fa.

* Correct merge error

---------

Co-authored-by: Burzah <116982774+Burzah@users.noreply.github.com>
This commit is contained in:
Charlie Nolan
2025-08-10 12:05:19 +01:00
committed by GitHub
co-authored by Burzah
parent f67dd166cb
commit 2b98749d32
20 changed files with 1037 additions and 469 deletions
+21 -4
View File
@@ -171,14 +171,32 @@ DROP TABLE IF EXISTS `admin`;
CREATE TABLE `admin` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`ckey` varchar(32) COLLATE utf8mb4_unicode_ci NOT NULL,
`admin_rank` varchar(32) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'Administrator',
`level` int(2) NOT NULL DEFAULT '0',
`flags` int(16) NOT NULL DEFAULT '0',
`display_rank` varchar(32) COLLATE utf8mb4_unicode_ci,
`permissions_rank` int(11) COMMENT 'Foreign key for admin_ranks.id',
`extra_permissions` int(16) NOT NULL DEFAULT '0',
`removed_permissions` int(16) NOT NULL DEFAULT '0',
PRIMARY KEY (`id`),
KEY `ckey` (`ckey`)
) ENGINE=InnoDB AUTO_INCREMENT=99 DEFAULT CHARSET=utf8mb4;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Table structure for table `admin_ranks`
--
DROP TABLE IF EXISTS `admin_ranks`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `admin_ranks` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(32) COLLATE utf8mb4_unicode_ci NOT NULL,
`default_permissions` int(16) NOT NULL DEFAULT '0',
PRIMARY KEY (`id`),
KEY `name` (`name`)
) ENGINE=InnoDB AUTO_INCREMENT=99 DEFAULT CHARSET=utf8mb4;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Table structure for table `admin_log`
--
@@ -273,7 +291,6 @@ CREATE TABLE `player` (
`lastseen` datetime NOT NULL,
`ip` varchar(18) COLLATE utf8mb4_unicode_ci NOT NULL,
`computerid` varchar(32) COLLATE utf8mb4_unicode_ci NOT NULL,
`lastadminrank` varchar(32) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'Player',
`ooccolor` varchar(7) COLLATE utf8mb4_unicode_ci DEFAULT '#b82e00',
`UI_style` varchar(10) COLLATE utf8mb4_unicode_ci DEFAULT 'Midnight',
`UI_style_color` varchar(7) COLLATE utf8mb4_unicode_ci DEFAULT '#ffffff',
+39
View File
@@ -0,0 +1,39 @@
# Updating DB from 69-70 -FunnyMan3595
# Adds the admin_ranks table
# Create the new table.
CREATE TABLE `admin_ranks` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(32) COLLATE utf8mb4_unicode_ci NOT NULL,
`default_permissions` int(16) NOT NULL DEFAULT '0',
PRIMARY KEY (`id`),
KEY `name` (`name`)
) ENGINE=InnoDB AUTO_INCREMENT=99 DEFAULT CHARSET=utf8mb4;
# Create official ranks for every existing display rank, with the minimum common permissions.
INSERT INTO admin_ranks (name, default_permissions)
SELECT admin_rank, BIT_AND(flags) FROM admin GROUP BY admin_rank;
# Add new columns to admin table.
ALTER TABLE admin
ADD COLUMN `display_rank` varchar(32) COLLATE utf8mb4_unicode_ci,
ADD COLUMN `permissions_rank` int(11) COMMENT 'Foreign key for admin_ranks.id',
ADD COLUMN `extra_permissions` int(16) NOT NULL DEFAULT '0',
ADD COLUMN `removed_permissions` int(16) NOT NULL DEFAULT '0';
# Set the rank and any extra_permissions for each admin.
# There won't be any removed_permissions because we took the minimum common permissions earlier.
# We also leave display_rank blank, since admin_ranks.name matches their old admin_rank.
UPDATE admin JOIN admin_ranks ON admin.admin_rank = admin_ranks.name
SET
admin.permissions_rank = admin_ranks.id,
admin.extra_permissions = admin.flags & ~admin_ranks.default_permissions;
# Drop the old columns from the admin table.
ALTER TABLE admin
DROP COLUMN admin_rank,
DROP COLUMN level,
DROP COLUMN flags;
# Drop the lastadminrank column from the player table.
ALTER TABLE player DROP COLUMN lastadminrank;