From ecfec6a4074a8dbcd9e54429d52c8c1f4441a7f5 Mon Sep 17 00:00:00 2001 From: jomo Date: Wed, 30 Sep 2015 00:38:32 +0200 Subject: [PATCH] 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 --- lib/public/images/{alex.png => mhf_alex.png} | Bin .../{alex_skin.png => mhf_alex_skin.png} | Bin .../images/{steve.png => mhf_steve.png} | Bin .../{steve_skin.png => mhf_steve_skin.png} | Bin lib/public/stylesheets/style.css | 4 +- lib/routes/avatars.js | 5 +- lib/routes/renders.js | 5 +- lib/routes/skins.js | 5 +- lib/skins.js | 8 +- lib/views/index.jade | 36 +++---- test/test.js | 96 +++++++++--------- 11 files changed, 84 insertions(+), 75 deletions(-) rename lib/public/images/{alex.png => mhf_alex.png} (100%) rename lib/public/images/{alex_skin.png => mhf_alex_skin.png} (100%) rename lib/public/images/{steve.png => mhf_steve.png} (100%) rename lib/public/images/{steve_skin.png => mhf_steve_skin.png} (100%) diff --git a/lib/public/images/alex.png b/lib/public/images/mhf_alex.png similarity index 100% rename from lib/public/images/alex.png rename to lib/public/images/mhf_alex.png diff --git a/lib/public/images/alex_skin.png b/lib/public/images/mhf_alex_skin.png similarity index 100% rename from lib/public/images/alex_skin.png rename to lib/public/images/mhf_alex_skin.png diff --git a/lib/public/images/steve.png b/lib/public/images/mhf_steve.png similarity index 100% rename from lib/public/images/steve.png rename to lib/public/images/mhf_steve.png diff --git a/lib/public/images/steve_skin.png b/lib/public/images/mhf_steve_skin.png similarity index 100% rename from lib/public/images/steve_skin.png rename to lib/public/images/mhf_steve_skin.png diff --git a/lib/public/stylesheets/style.css b/lib/public/stylesheets/style.css index 7d4de14..b6d9ebe 100644 --- a/lib/public/stylesheets/style.css +++ b/lib/public/stylesheets/style.css @@ -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 { diff --git a/lib/routes/avatars.js b/lib/routes/avatars.js index f8e9076..e5a6cf6 100644 --- a/lib/routes/avatars.js +++ b/lib/routes/avatars.js @@ -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, diff --git a/lib/routes/renders.js b/lib/routes/renders.js index edef93b..9f26d6e 100644 --- a/lib/routes/renders.js +++ b/lib/routes/renders.js @@ -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) { diff --git a/lib/routes/skins.js b/lib/routes/skins.js index 8b926ac..8cb1a77 100644 --- a/lib/routes/skins.js +++ b/lib/routes/skins.js @@ -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) { diff --git a/lib/skins.js b/lib/skins.js index 5df64ee..a6e1637 100644 --- a/lib/skins.js +++ b/lib/skins.js @@ -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"; } }; diff --git a/lib/views/index.jade b/lib/views/index.jade index 251a5c0..49cadd3 100644 --- a/lib/views/index.jade +++ b/lib/views/index.jade @@ -62,14 +62,14 @@ block content td default td string td - | The standard value is calculated based on the UUID (even = alex, odd = steve).
- | Usernames always default to steve. + | The standard value is calculated based on the UUID (even = MHF_Alex, odd = MHF_Steve).
+ | Usernames always default to MHF_Steve. td | The image to be served when the userid has no skin.
- | 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 (this example assumes jeb_ does not exist) + .example #{domain}/avatars/jeb_?default=MHF_Alex + p.preview Jeb's avatar, or fall back to MHF_Alex (this example assumes jeb_ does not exist) #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).
- | Usernames always default to steve. + | The standard value is calculated based on the UUID (even = MHF_Alex, odd = MHF_Steve).
+ | Usernames always default to MHF_Steve. td | The image to be served when the userid has no skin.
- | 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 (this example assumes jeb_ does not exist) + .example #{domain}/skins/jeb_?default=MHF_Alex + p.preview Jeb's skin, or fall back to MHF_Alex (this example assumes jeb_ does not exist) 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") \ No newline at end of file diff --git a/test/test.js b/test/test.js index ee5ff7b..312ae14 100644 --- a/test/test.js +++ b/test/test.js @@ -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": {