use MHF_Steve and MHF_Alex instead of steve and alex in default parameter

See #142 (not fixed by this commit!)
Basically, this just adds mhf_steve and mhf_alex as special cases for the default parameter only
This commit is contained in:
jomo 2015-09-30 00:38:32 +02:00
parent fd4fb0764c
commit ecfec6a407
11 changed files with 84 additions and 75 deletions

View File

Before

Width:  |  Height:  |  Size: 150 B

After

Width:  |  Height:  |  Size: 150 B

View File

Before

Width:  |  Height:  |  Size: 997 B

After

Width:  |  Height:  |  Size: 997 B

View File

Before

Width:  |  Height:  |  Size: 222 B

After

Width:  |  Height:  |  Size: 222 B

View File

Before

Width:  |  Height:  |  Size: 835 B

After

Width:  |  Height:  |  Size: 835 B

View File

@ -176,7 +176,7 @@ h4 {
background-image: url("/avatars/853c80ef3c3749fdaa49938b674adae6");
}
#avatar-example-5:hover .preview {
background-image: url("/avatars/0?default=alex");
background-image: url("/avatars/0?default=mhf_alex");
}
#avatar-example-6:hover .preview {
background-image: url("/avatars/0?default=https%3A%2F%2Fi.imgur.com%2FocJVWAc.png");
@ -193,7 +193,7 @@ h4 {
background-image: url("/skins/jeb_");
}
#skin-example-2:hover .preview {
background-image: url("/skins/0?default=alex");
background-image: url("/skins/0?default=mhf_alex");
}
#cape-example-1:hover .preview {

View File

@ -7,7 +7,7 @@ var url = require("url");
function handle_default(img_status, userId, size, def, req, err, callback) {
def = def || skins.default_skin(userId);
if (def !== "steve" && def !== "alex") {
if (def !== "steve" && def !== "mhf_steve" && def !== "alex" && def !== "mhf_alex") {
if (helpers.id_valid(def)) {
// clean up the old URL to match new image
var parsed = req.url;
@ -29,6 +29,9 @@ function handle_default(img_status, userId, size, def, req, err, callback) {
}
} else {
// handle steve and alex
if (def.substr(0, 4) !== "mhf_") {
def = "mhf_" + def;
}
skins.resize_img(path.join(__dirname, "..", "public", "images", def + ".png"), size, function(resize_err, image) {
callback({
status: img_status,

View File

@ -12,7 +12,7 @@ var fs = require("fs");
// helmet is query param
function handle_default(rid, scale, helm, body, img_status, userId, size, def, req, err, callback) {
def = def || skins.default_skin(userId);
if (def !== "steve" && def !== "alex") {
if (def !== "steve" && def !== "mhf_steve" && def !== "alex" && def !== "mhf_alex") {
if (helpers.id_valid(def)) {
// clean up the old URL to match new image
var parsed = req.url;
@ -34,6 +34,9 @@ function handle_default(rid, scale, helm, body, img_status, userId, size, def, r
}
} else {
// handle steve and alex
if (def.substr(0, 4) !== "mhf_") {
def = "mhf_" + def;
}
fs.readFile(path.join(__dirname, "..", "public", "images", def + "_skin.png"), function (fs_err, buf) {
// we render the default skins, but not custom images
renders.draw_model(rid, buf, scale, helm, body, function(render_err, def_img) {

View File

@ -8,7 +8,7 @@ var url = require("url");
function handle_default(img_status, userId, def, req, err, callback) {
def = def || skins.default_skin(userId);
if (def !== "steve" && def !== "alex") {
if (def !== "steve" && def !== "mhf_steve" && def !== "alex" && def !== "mhf_alex") {
if (helpers.id_valid(def)) {
// clean up the old URL to match new image
var parsed = req.url;
@ -30,6 +30,9 @@ function handle_default(img_status, userId, def, req, err, callback) {
}
} else {
// handle steve and alex
if (def.substr(0, 4) !== "mhf_") {
def = "mhf_" + def;
}
lwip.open(path.join(__dirname, "..", "public", "images", def + "_skin.png"), function(lwip_err, image) {
if (image) {
image.toBuffer("png", function(buf_err, buffer) {

View File

@ -56,7 +56,7 @@ exp.extract_helm = function(rid, facefile, buffer, outname, callback) {
} else {
face_helm_img.toBuffer("png", {compression: "none"}, function(buf_err2, face_helm_buffer) {
if (buf_err2) {
callback(buf_err2)
callback(buf_err2);
} else {
if (face_helm_buffer.toString() !== face_buffer.toString()) {
face_helm_img.writeFile(outname, function(write_err) {
@ -101,11 +101,11 @@ exp.resize_img = function(inname, size, callback) {
});
};
// returns "alex" or "steve" calculated by the +uuid+
// returns "mhf_alex" or "mhf_steve" calculated by the +uuid+
exp.default_skin = function(uuid) {
if (uuid.length <= 16) {
// we can't get the skin type by username
return "steve";
return "mhf_steve";
} else {
// great thanks to Minecrell for research into Minecraft and Java's UUID hashing!
// https://git.io/xJpV
@ -117,7 +117,7 @@ exp.default_skin = function(uuid) {
parseInt(uuid[15], 16) ^
parseInt(uuid[23], 16) ^
parseInt(uuid[31], 16);
return lsbs_even ? "alex" : "steve";
return lsbs_even ? "mhf_alex" : "mhf_steve";
}
};

View File

@ -62,14 +62,14 @@ block content
td default
td string
td
| The standard value is calculated based on the UUID (even = alex, odd = steve).<br>
| Usernames always default to steve.
| The standard value is calculated based on the UUID (even = MHF_Alex, odd = MHF_Steve).<br>
| Usernames always default to MHF_Steve.
td
| The image to be served when the userid has no skin.<br>
| Valid options are
a(href="/avatars/0?default=steve") steve
| ,
a(href="/avatars/0?default=alex") alex
| Valid options are any userid, including
a(href="/avatars/0?default=MHF_Steve") MHF_Steve
| and
a(href="/avatars/0?default=MHF_Alex") MHF_Alex
| , or a custom URL.
tr
td helm
@ -95,8 +95,8 @@ block content
.example #{domain}/avatars/853c80ef3c3749fdaa49938b674adae6
p.preview Jeb's avatar by UUID
#avatar-example-5.example-wrapper
.example #{domain}/avatars/jeb_?default=alex
p.preview Jeb's avatar, or fall back to alex <i>(this example assumes jeb_ does not exist)</i>
.example #{domain}/avatars/jeb_?default=MHF_Alex
p.preview Jeb's avatar, or fall back to MHF_Alex <i>(this example assumes jeb_ does not exist)</i>
#avatar-example-6.example-wrapper
.example #{domain}/avatars/jeb_?default=https%3A%2F%2Fi.imgur.com%2FocJVWAc.png
p.preview
@ -195,14 +195,14 @@ block content
td default
td string
td
| The standard value is calculated based on the UUID (even = alex, odd = steve).<br>
| Usernames always default to steve.
| The standard value is calculated based on the UUID (even = MHF_Alex, odd = MHF_Steve).<br>
| Usernames always default to MHF_Steve.
td
| The image to be served when the userid has no skin.<br>
| Valid options are
a(href="/skins/0?default=steve") steve
| ,
a(href="/skins/0?default=alex") alex
| Valid options are any userid, including
a(href="/skins/0?default=MHF_Steve") MHF_Steve
| and
a(href="/skins/0?default=MHF_Alex") MHF_Alex
| , or a custom URL.
section
@ -214,8 +214,8 @@ block content
.example #{domain}/skins/jeb_
p.preview Jeb's skin
#skin-example-2.example-wrapper
.example #{domain}/skins/jeb_?default=alex
p.preview Jeb's skin, or fall back to alex <i>(this example assumes jeb_ does not exist)</i>
.example #{domain}/skins/jeb_?default=MHF_Alex
p.preview Jeb's skin, or fall back to MHF_Alex <i>(this example assumes jeb_ does not exist)</i>
p.preview-placeholder
| Hover over the example URLs above for a preview!
.preview-background
@ -347,7 +347,7 @@ block content
img.preload(src="/avatars/020242a17b9441799eff511eea1221da?size=64", alt="preloaded image")
img.preload(src="/avatars/020242a17b9441799eff511eea1221da?size=64&helm", alt="preloaded image")
img.preload(src="/avatars/069a79f444e94726a5befca90e38aaf5?size=64", alt="preloaded image")
img.preload(src="/avatars/0?default=alex", alt="preloaded image")
img.preload(src="/avatars/0?default=MHF_Alex", alt="preloaded image")
img.preload(src="/avatars/0?default=https%3A%2F%2Fi.imgur.com%2FocJVWAc.png", alt="preloaded image")
img.preload(src="/avatars/0ea8eca3dbf647cc9d1ac64551ca975c?size=64", alt="preloaded image")
img.preload(src="/avatars/0ea8eca3dbf647cc9d1ac64551ca975c?size=64&helm", alt="preloaded image")
@ -393,5 +393,5 @@ block content
img.preload(src="/capes/md_5", alt="preloaded image")
img.preload(src="/renders/body/jeb_?helm&scale=4", alt="preloaded image")
img.preload(src="/renders/head/853c80ef3c3749fdaa49938b674adae6?scale=8", alt="preloaded image")
img.preload(src="/skins/0?default=alex", alt="preloaded image")
img.preload(src="/skins/0?default=MHF_Alex", alt="preloaded image")
img.preload(src="/skins/jeb_", alt="preloaded image")

View File

@ -145,15 +145,15 @@ describe("Crafatar", function() {
});
});
});
it("Username should default to Steve", function(done) {
assert.strictEqual(skins.default_skin("TestUser"), "steve");
it("Username should default to MHF_Steve", function(done) {
assert.strictEqual(skins.default_skin("TestUser"), "mhf_steve");
done();
});
for (var a in alex_ids) {
var alexid = alex_ids[a];
(function(alex_id) {
it("UUID " + alex_id + " should default to Alex", function(done) {
assert.strictEqual(skins.default_skin(alex_id), "alex");
it("UUID " + alex_id + " should default to MHF_Alex", function(done) {
assert.strictEqual(skins.default_skin(alex_id), "mhf_alex");
done();
});
}(alexid));
@ -161,8 +161,8 @@ describe("Crafatar", function() {
for (var s in steve_ids) {
var steveid = steve_ids[s];
(function(steve_id) {
it("UUID " + steve_id + " should default to Steve", function(done) {
assert.strictEqual(skins.default_skin(steve_id), "steve");
it("UUID " + steve_id + " should default to MHF_Steve", function(done) {
assert.strictEqual(skins.default_skin(steve_id), "mhf_steve");
done();
});
}(steveid));
@ -343,12 +343,12 @@ describe("Crafatar", function() {
},
"avatar with non-existent username": {
url: "http://localhost:3000/avatars/0?size=16",
etag: '"steve"',
etag: '"mhf_steve"',
crc32: [2416827277, 1243826040]
},
"avatar with non-existent username defaulting to alex": {
url: "http://localhost:3000/avatars/0?size=16&default=alex",
etag: '"alex"',
url: "http://localhost:3000/avatars/0?size=16&default=mhf_alex",
etag: '"mhf_alex"',
crc32: [862751081, 809395677]
},
"avatar with non-existent username defaulting to username": {
@ -373,12 +373,12 @@ describe("Crafatar", function() {
},
"helm avatar with non-existent username": {
url: "http://localhost:3000/avatars/0?size=16&helm",
etag: '"steve"',
etag: '"mhf_steve"',
crc32: [2416827277, 1243826040]
},
"helm avatar with non-existent username defaulting to alex": {
url: "http://localhost:3000/avatars/0?size=16&helm&default=alex",
etag: '"alex"',
url: "http://localhost:3000/avatars/0?size=16&helm&default=mhf_alex",
etag: '"mhf_alex"',
crc32: [862751081, 809395677]
},
"helm avatar with non-existent username defaulting to username": {
@ -403,12 +403,12 @@ describe("Crafatar", function() {
},
"avatar with non-existent uuid": {
url: "http://localhost:3000/avatars/00000000000000000000000000000000?size=16",
etag: '"steve"',
etag: '"mhf_steve"',
crc32: [2416827277, 1243826040]
},
"avatar with non-existent uuid defaulting to alex": {
url: "http://localhost:3000/avatars/00000000000000000000000000000000?size=16&default=alex",
etag: '"alex"',
url: "http://localhost:3000/avatars/00000000000000000000000000000000?size=16&default=mhf_alex",
etag: '"mhf_alex"',
crc32: [862751081, 809395677]
},
"avatar with non-existent uuid defaulting to username": {
@ -433,12 +433,12 @@ describe("Crafatar", function() {
},
"helm avatar with non-existent uuid": {
url: "http://localhost:3000/avatars/00000000000000000000000000000000?size=16&helm",
etag: '"steve"',
etag: '"mhf_steve"',
crc32: [2416827277, 1243826040]
},
"helm avatar with non-existent uuid defaulting to alex": {
url: "http://localhost:3000/avatars/00000000000000000000000000000000?size=16&helm&default=alex",
etag: '"alex"',
url: "http://localhost:3000/avatars/00000000000000000000000000000000?size=16&helm&default=mhf_alex",
etag: '"mhf_alex"',
crc32: [862751081, 809395677]
},
"helm avatar with non-existent uuid defaulting to username": {
@ -491,12 +491,12 @@ describe("Crafatar", function() {
},
"skin with non-existent username": {
url: "http://localhost:3000/skins/0",
etag: '"steve"',
etag: '"mhf_steve"',
crc32: 981937087
},
"skin with non-existent username defaulting to alex": {
url: "http://localhost:3000/skins/0?default=alex",
etag: '"alex"',
url: "http://localhost:3000/skins/0?default=mhf_alex",
etag: '"mhf_alex"',
crc32: 2298915739
},
"skin with non-existent username defaulting to username": {
@ -521,12 +521,12 @@ describe("Crafatar", function() {
},
"skin with non-existent uuid": {
url: "http://localhost:3000/skins/00000000000000000000000000000000",
etag: '"steve"',
etag: '"mhf_steve"',
crc32: 981937087
},
"skin with non-existent uuid defaulting to alex": {
url: "http://localhost:3000/skins/00000000000000000000000000000000?default=alex",
etag: '"alex"',
url: "http://localhost:3000/skins/00000000000000000000000000000000?default=mhf_alex",
etag: '"mhf_alex"',
crc32: 2298915739
},
"skin with non-existent uuid defaulting to username": {
@ -551,12 +551,12 @@ describe("Crafatar", function() {
},
"head render with non-existent username": {
url: "http://localhost:3000/renders/head/0?scale=2",
etag: '"steve"',
etag: '"mhf_steve"',
crc32: [897270661, 1026982335]
},
"head render with non-existent username defaulting to alex": {
url: "http://localhost:3000/renders/head/0?scale=2&default=alex",
etag: '"alex"',
url: "http://localhost:3000/renders/head/0?scale=2&default=mhf_alex",
etag: '"mhf_alex"',
crc32: [2357619670, 3172866498]
},
"head render with non-existent username defaulting to username": {
@ -581,12 +581,12 @@ describe("Crafatar", function() {
},
"helm head render with non-existent username": {
url: "http://localhost:3000/renders/head/0?scale=2&helm",
etag: '"steve"',
etag: '"mhf_steve"',
crc32: [507497693, 3868868707]
},
"helm head render with non-existent username defaulting to alex": {
url: "http://localhost:3000/renders/head/0?scale=2&helm&default=alex",
etag: '"alex"',
url: "http://localhost:3000/renders/head/0?scale=2&helm&default=mhf_alex",
etag: '"mhf_alex"',
crc32: [891113664, 1785326216]
},
"helm head render with non-existent username defaulting to username": {
@ -611,12 +611,12 @@ describe("Crafatar", function() {
},
"head render with non-existent uuid": {
url: "http://localhost:3000/renders/head/00000000000000000000000000000000?scale=2",
etag: '"steve"',
etag: '"mhf_steve"',
crc32: [897270661, 1026982335]
},
"head render with non-existent uuid defaulting to alex": {
url: "http://localhost:3000/renders/head/00000000000000000000000000000000?scale=2&default=alex",
etag: '"alex"',
url: "http://localhost:3000/renders/head/00000000000000000000000000000000?scale=2&default=mhf_alex",
etag: '"mhf_alex"',
crc32: [2357619670, 3172866498]
},
"head render with non-existent uuid defaulting to username": {
@ -641,12 +641,12 @@ describe("Crafatar", function() {
},
"helm head render with non-existent uuid": {
url: "http://localhost:3000/renders/head/00000000000000000000000000000000?scale=2&helm",
etag: '"steve"',
etag: '"mhf_steve"',
crc32: [507497693, 3868868707]
},
"helm head render with non-existent uuid defaulting to alex": {
url: "http://localhost:3000/renders/head/00000000000000000000000000000000?scale=2&helm&default=alex",
etag: '"alex"',
url: "http://localhost:3000/renders/head/00000000000000000000000000000000?scale=2&helm&default=mhf_alex",
etag: '"mhf_alex"',
crc32: [891113664, 1785326216]
},
"helm head with non-existent uuid defaulting to username": {
@ -671,12 +671,12 @@ describe("Crafatar", function() {
},
"body render with non-existent username": {
url: "http://localhost:3000/renders/body/0?scale=2",
etag: '"steve"',
etag: '"mhf_steve"',
crc32: [3559591930, 3663447404]
},
"body render with non-existent username defaulting to alex": {
url: "http://localhost:3000/renders/body/0?scale=2&default=alex",
etag: '"alex"',
url: "http://localhost:3000/renders/body/0?scale=2&default=mhf_alex",
etag: '"mhf_alex"',
crc32: [470529151, 1823026927]
},
"body render with non-existent username defaulting to username": {
@ -701,12 +701,12 @@ describe("Crafatar", function() {
},
"helm body render with non-existent username": {
url: "http://localhost:3000/renders/body/0?scale=2&helm",
etag: '"steve"',
etag: '"mhf_steve"',
crc32: [3992841063, 1025743887]
},
"helm body render with non-existent username defaulting to alex": {
url: "http://localhost:3000/renders/body/0?scale=2&helm&default=alex",
etag: '"alex"',
url: "http://localhost:3000/renders/body/0?scale=2&helm&default=mhf_alex",
etag: '"mhf_alex"',
crc32: [3317518715, 3621585514]
},
"helm body render with non-existent username defaulting to username": {
@ -731,12 +731,12 @@ describe("Crafatar", function() {
},
"body render with non-existent uuid": {
url: "http://localhost:3000/renders/body/00000000000000000000000000000000?scale=2",
etag: '"steve"',
etag: '"mhf_steve"',
crc32: [3559591930, 3663447404]
},
"body render with non-existent uuid defaulting to alex": {
url: "http://localhost:3000/renders/body/00000000000000000000000000000000?scale=2&default=alex",
etag: '"alex"',
url: "http://localhost:3000/renders/body/00000000000000000000000000000000?scale=2&default=mhf_alex",
etag: '"mhf_alex"',
crc32: [470529151, 1823026927]
},
"body render with non-existent uuid defaulting to username": {
@ -761,12 +761,12 @@ describe("Crafatar", function() {
},
"helm body render with non-existent uuid": {
url: "http://localhost:3000/renders/body/00000000000000000000000000000000?scale=2&helm",
etag: '"steve"',
etag: '"mhf_steve"',
crc32: [3992841063, 1025743887]
},
"helm body render with non-existent uuid defaulting to alex": {
url: "http://localhost:3000/renders/body/00000000000000000000000000000000?scale=2&helm&default=alex",
etag: '"alex"',
url: "http://localhost:3000/renders/body/00000000000000000000000000000000?scale=2&helm&default=mhf_alex",
etag: '"mhf_alex"',
crc32: [3317518715, 3621585514]
},
"helm body render with non-existent uuid defaulting to url": {