Created
June 5, 2018 14:20
-
-
Save bigenergy/e1c3e57603bb2e4b0bf63a70e0e44584 to your computer and use it in GitHub Desktop.
Generates a offline-mode player UUID minecraft
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<? | |
/** | |
* Generates a offline-mode player UUID. | |
* | |
* @param $username string | |
* @return string | |
*/ | |
function constructOfflinePlayerUuid($username) { | |
//extracted from the java code: | |
//new GameProfile(UUID.nameUUIDFromBytes(("OfflinePlayer:" + name).getBytes(Charsets.UTF_8)), name)); | |
$data = hex2bin(md5("OfflinePlayer:" . $username)); | |
//set the version to 3 -> Name based md5 hash | |
$data[6] = chr(ord($data[6]) & 0x0f | 0x30); | |
//IETF variant | |
$data[8] = chr(ord($data[8]) & 0x3f | 0x80); | |
return createJavaUuid(bin2hex($data)); | |
} | |
function createJavaUuid($striped) { | |
//example: 069a79f4-44e9-4726-a5be-fca90e38aaf5 | |
$components = array( | |
substr($striped, 0, 8), | |
substr($striped, 8, 4), | |
substr($striped, 12, 4), | |
substr($striped, 16, 4), | |
substr($striped, 20), | |
); | |
return implode('-', $components); | |
} | |
echo constructOfflinePlayerUuid('тутник'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment