mirror of
https://github.com/azures04/crafatar.git
synced 2026-05-06 19:10:38 +02:00
proper handling of steve/alex
it's more complex than just even/odd UUID
This commit is contained in:
@@ -84,12 +84,23 @@ exp.resize_img = function(inname, size, callback) {
|
||||
});
|
||||
};
|
||||
|
||||
// returns "alex" or "steve" calculated by the +userId+
|
||||
exp.default_skin = function(userId) {
|
||||
if (Number("0x" + userId[31]) % 2 === 0) {
|
||||
return "alex";
|
||||
} else {
|
||||
// returns "alex" or "steve" calculated by the +uuid+
|
||||
exp.default_skin = function(uuid) {
|
||||
if (uuid.length <= 16) {
|
||||
// we can't get the
|
||||
return "steve";
|
||||
} else {
|
||||
// great thanks to Minecrell for research into Minecraft and Java's UUID hashing!
|
||||
// https://git.io/xJpV
|
||||
// MC uses `uuid.hashCode() & 1` for alex
|
||||
// that can be compacted to counting the LSBs of every 4th byte in the UUID
|
||||
// an odd sum means alex, an even sum means steve
|
||||
// XOR-ing all the LSBs gives us 1 for alex and 0 for steve
|
||||
var lsbs_even = parseInt(uuid[07], 16) ^
|
||||
parseInt(uuid[15], 16) ^
|
||||
parseInt(uuid[23], 16) ^
|
||||
parseInt(uuid[31], 16);
|
||||
return lsbs_even ? "alex" : "steve";
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user