diff --git a/lib/helpers.js b/lib/helpers.js index f9ba0b6..5afe2fa 100644 --- a/lib/helpers.js +++ b/lib/helpers.js @@ -8,7 +8,7 @@ var path = require("path"); var fs = require("fs"); // 0098cb60-fa8e-427c-b299-793cbd302c9a -var valid_user_id = /^([0-9a-f-A-F-]{32,36}|[a-zA-Z0-9_]{1,16})$/; // uuid|username +var valid_user_id = /^[0-9a-f-A-F-]{32,36}$/; // uuid var hash_pattern = /[0-9a-f]+$/; // gets the hash from the textures.minecraft.net +url+ @@ -22,10 +22,7 @@ function get_hash(url) { // callback: error, skin hash, slim function store_skin(rid, userId, profile, cache_details, callback) { networking.get_skin_info(rid, userId, profile, function(err, url, slim) { - if (!err && userId.length > 16) { - // updating username with model info from uuid details - cache.set_slim(rid, profile.name, slim); - } else { + if (err) { slim = cache_details ? cache_details.slim : undefined; } @@ -161,7 +158,6 @@ function resume(userId, type, err, hash, slim) { // image type should be called back on // callback: error, image hash, slim function store_images(rid, userId, cache_details, type, callback) { - var is_uuid = userId.length > 16; if (requests[type]["!" + userId]) { logging.debug(rid, "adding to request queue"); push_request(userId, type, callback); @@ -169,8 +165,8 @@ function store_images(rid, userId, cache_details, type, callback) { // add request to the queue push_request(userId, type, callback); - networking.get_profile(rid, (is_uuid ? userId : null), function(err, profile) { - if (err || (is_uuid && !profile)) { + networking.get_profile(rid, userId, function(err, profile) { + if (err || !profile) { // error or uuid without profile if (!err && !profile) { // no error, but uuid without profile @@ -212,8 +208,8 @@ function store_images(rid, userId, cache_details, type, callback) { var exp = {}; -// returns true if the +userId+ is a valid userId or username -// the userId may be not exist, however +// returns true if the +userId+ is a valid userId +// the UUID might not exist, however exp.id_valid = function(userId) { return valid_user_id.test(userId); }; diff --git a/lib/networking.js b/lib/networking.js index 84fd4af..2d51f9f 100644 --- a/lib/networking.js +++ b/lib/networking.js @@ -6,29 +6,10 @@ var skins = require("./skins"); require("./object-patch"); var session_url = "https://sessionserver.mojang.com/session/minecraft/profile/"; -var skins_url = "https://skins.minecraft.net/MinecraftSkins/"; -var capes_url = "https://skins.minecraft.net/MinecraftCloaks/"; var textures_url = "http://textures.minecraft.net/texture/"; -var mojang_urls = [skins_url, capes_url]; var exp = {}; -// helper method that calls `get_username_url` or `get_uuid_info` based on the +usedId+ -// +userId+ is used for usernames, while +profile+ is used for UUIDs -// callback: error, url, slim -function get_info(rid, userId, profile, type, callback) { - if (userId.length <= 16) { - // username - exp.get_username_url(rid, userId, type, function(err, url) { - callback(err, url || null, undefined); - }); - } else { - exp.get_uuid_info(profile, type, function(url, slim) { - callback(null, url || null, slim); - }); - } -} - // performs a GET request to the +url+ // +options+ object includes these options: // encoding (string), default is to return a buffer @@ -103,24 +84,6 @@ exp.get_from = function(rid, url, callback) { }); }; -// make a request to skins.miencraft.net -// the skin url is taken from the HTTP redirect -// type reference is above -exp.get_username_url = function(rid, name, type, callback) { - type = Number(type === "CAPE"); - exp.get_from(rid, mojang_urls[type] + name + ".png", function(body, response, err) { - if (!err) { - if (response) { - callback(err, response.statusCode === 404 ? null : response.headers.location); - } else { - callback(err, null); - } - } else { - callback(err, null); - } - }); -}; - // gets the URL for a skin/cape from the profile // +type+ "SKIN" or "CAPE", specifies which to retrieve // callback: url, slim @@ -139,43 +102,39 @@ exp.get_uuid_info = function(profile, type, callback) { slim = Object.get(profile, "textures.SKIN.metadata.model") === "slim"; } - callback(url || null, !!slim); + callback(null, url || null, !!slim); }; // make a request to sessionserver for +uuid+ // callback: error, profile exp.get_profile = function(rid, uuid, callback) { - if (!uuid) { - callback(null, null); - } else { - exp.get_from_options(rid, session_url + uuid, { encoding: "utf8" }, function(body, response, err) { - try { - body = body ? JSON.parse(body) : null; - callback(err || null, body); - } catch(e) { - if (e instanceof SyntaxError) { - logging.warn(rid, "Failed to parse JSON", e); - logging.debug(rid, body); - callback(err || null, null); - } else { - throw e; - } + exp.get_from_options(rid, session_url + uuid, { encoding: "utf8" }, function(body, response, err) { + try { + body = body ? JSON.parse(body) : null; + callback(err || null, body); + } catch(e) { + if (e instanceof SyntaxError) { + logging.warn(rid, "Failed to parse JSON", e); + logging.debug(rid, body); + callback(err || null, null); + } else { + throw e; } - }); - } + } + }); }; // get the skin URL and type for +userId+ // +profile+ is used if +userId+ is a uuid // callback: error, url, slim exp.get_skin_info = function(rid, userId, profile, callback) { - get_info(rid, userId, profile, "SKIN", callback); + exp.get_uuid_info(profile, "SKIN", callback); }; // get the cape URL for +userId+ // +profile+ is used if +userId+ is a uuid exp.get_cape_url = function(rid, userId, profile, callback) { - get_info(rid, userId, profile, "CAPE", callback); + exp.get_uuid_info(profile, "CAPE", callback); }; // download the +tex_hash+ image from the texture server diff --git a/lib/public/javascript/crafatar.js b/lib/public/javascript/crafatar.js index ee828b8..b8d9624 100644 --- a/lib/public/javascript/crafatar.js +++ b/lib/public/javascript/crafatar.js @@ -1,4 +1,4 @@ -var valid_user_id = /^([0-9a-f-A-F-]{32,36}|[a-zA-Z0-9_]{1,16})$/; // uuid|username +var valid_user_id = /^[0-9a-f-A-F-]{32,36}$/; // uuid var xhr = new XMLHttpRequest(); xhr.onload = function() { @@ -9,24 +9,14 @@ xhr.onload = function() { status[key] = elem[key]; }); - var textures = status["textures.minecraft.net"] !== "green"; - var session = status["sessionserver.mojang.com"] !== "green"; - var skins = status["skins.minecraft.net"] !== "green"; - var error = null; + var textures_err = status["textures.minecraft.net"] !== "green"; + var session_err = status["sessionserver.mojang.com"] !== "green"; - if (textures || session && skins) { - error = "all"; - } else if (skins) { - error = "username"; - } else if (session) { - error = "UUID"; - } - - if (error) { + if (textures_err || session_err) { var warn = document.createElement("div"); warn.setAttribute("class", "alert alert-warning"); warn.setAttribute("role", "alert"); - warn.innerHTML = "