Skip to content

Instantly share code, notes, and snippets.

@Wector11211
Created August 26, 2023 08:56
Show Gist options
  • Save Wector11211/1f95e573123f18b4a3cd0d05266037aa to your computer and use it in GitHub Desktop.
Save Wector11211/1f95e573123f18b4a3cd0d05266037aa to your computer and use it in GitHub Desktop.
Generate an offline minecraft UUID v3 based on the case sensitive player name
CREATE OR REPLACE FUNCTION generate_offline_uuid(
username_p VARCHAR(20)
) RETURNS VARCHAR(36) BEGIN
DECLARE uuid_bytes VARCHAR(36);
SELECT MD5(CONCAT('OfflinePlayer:', username_p)) INTO uuid_bytes;
SELECT INSERT(uuid_bytes, 13, 2, HEX(CONV(SUBSTR(uuid_bytes, 13, 2), 16, 10) & 0x0f | 0x30)) INTO uuid_bytes;
SELECT INSERT(uuid_bytes, 17, 2, HEX(CONV(SUBSTR(uuid_bytes, 17, 2), 16, 10) & 0x3f | 0x80)) INTO uuid_bytes;
RETURN (SELECT LCASE(CONCAT_WS('-',
SUBSTR(uuid_bytes, 1, 8),
SUBSTR(uuid_bytes, 9, 4),
SUBSTR(uuid_bytes, 13, 4),
SUBSTR(uuid_bytes, 17, 4),
SUBSTR(uuid_bytes, 21)
)));
END;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment