19 lines
708 B
JavaScript
19 lines
708 B
JavaScript
const crypto = require('crypto')
|
|
|
|
function getOfflineUUID (username) {
|
|
// Hash the UUID
|
|
const md5 = crypto.createHash('md5')
|
|
md5.update('OfflinePlayer:' + username, 'utf-8')
|
|
const hash = md5.digest()
|
|
|
|
// From https://github.com/openjdk/jdk/blob/master/src/java.base/share/classes/java/util/UUID.java#L182-L185
|
|
hash[6] &= 0x0f /* clear version */
|
|
hash[6] |= 0x30 /* set to version 3 */
|
|
hash[8] &= 0x3f /* clear variant */
|
|
hash[8] |= 0x80 /* set to IETF variant */
|
|
|
|
const hex = hash.toString('hex')
|
|
return `${hex.substring(0, 8)}-${hex.substring(8, 12)}-${hex.substring(12, 16)}-${hex.substring(16, 20)}-${hex.substring(20, 32)}`
|
|
}
|
|
|
|
module.exports = getOfflineUUID
|