|
@@ -10,112 +10,145 @@ var fs = require("fs");
|
|
var valid_uuid = /^([0-9a-f-A-F-]{32,36}|[a-zA-Z0-9_]{1,16})$/; // uuid|username
|
|
var valid_uuid = /^([0-9a-f-A-F-]{32,36}|[a-zA-Z0-9_]{1,16})$/; // uuid|username
|
|
var hash_pattern = /[0-9a-f]+$/;
|
|
var hash_pattern = /[0-9a-f]+$/;
|
|
|
|
|
|
|
|
+// gets the hash from the textures.minecraft.net +url+
|
|
function get_hash(url) {
|
|
function get_hash(url) {
|
|
return hash_pattern.exec(url)[0].toLowerCase();
|
|
return hash_pattern.exec(url)[0].toLowerCase();
|
|
}
|
|
}
|
|
|
|
|
|
-// requests skin for +uuid+ and extracts face/helm if image hash in +details+ changed
|
|
|
|
-// callback contains error, image hash
|
|
|
|
-function store_images(uuid, details, callback) {
|
|
|
|
- // get skin_url for +uuid+
|
|
|
|
- networking.get_skin_url(uuid, function(err, skin_url) {
|
|
|
|
- if (err) {
|
|
|
|
- callback(err, null);
|
|
|
|
- } else {
|
|
|
|
- if (skin_url) {
|
|
|
|
- logging.log(uuid + " " + skin_url);
|
|
|
|
- // set file paths
|
|
|
|
- var hash = get_hash(skin_url);
|
|
|
|
- if (details && details.hash == hash) {
|
|
|
|
- // hash hasn't changed
|
|
|
|
- logging.log(uuid + " hash has not changed");
|
|
|
|
- cache.update_timestamp(uuid, hash);
|
|
|
|
- callback(null, hash);
|
|
|
|
- } else {
|
|
|
|
- // hash has changed
|
|
|
|
- logging.log(uuid + " new hash: " + hash);
|
|
|
|
- var facepath = __dirname + "/../" + config.faces_dir + hash + ".png";
|
|
|
|
- var helmpath = __dirname + "/../" + config.helms_dir + hash + ".png";
|
|
|
|
-
|
|
|
|
- fs.exists(facepath, function (exists) {
|
|
|
|
- if (exists) {
|
|
|
|
- logging.log(uuid + " Avatar already exists, not downloading");
|
|
|
|
- cache.save_hash(uuid, hash);
|
|
|
|
- callback(null, hash);
|
|
|
|
- } else {
|
|
|
|
- // download skin
|
|
|
|
- networking.get_skin(skin_url, uuid, function(err, img) {
|
|
|
|
- if (err || !img) {
|
|
|
|
- callback(err, null);
|
|
|
|
- } else {
|
|
|
|
- // extract face / helm
|
|
|
|
- skins.extract_face(img, facepath, function(err) {
|
|
|
|
- if (err) {
|
|
|
|
- callback(err);
|
|
|
|
- } else {
|
|
|
|
- logging.log(uuid + " face extracted");
|
|
|
|
- logging.debug(uuid + " " + facepath);
|
|
|
|
- skins.extract_helm(uuid, facepath, img, helmpath, function(err) {
|
|
|
|
- logging.log(uuid + " helm extracted");
|
|
|
|
- logging.debug(uuid + " " + helmpath);
|
|
|
|
- cache.save_hash(uuid, hash);
|
|
|
|
- callback(err, hash);
|
|
|
|
- });
|
|
|
|
- }
|
|
|
|
- });
|
|
|
|
- }
|
|
|
|
- });
|
|
|
|
- }
|
|
|
|
- });
|
|
|
|
- }
|
|
|
|
|
|
+function store_skin(uuid, profile, details, callback) {
|
|
|
|
+ networking.get_skin_url(uuid, profile, function(url) {
|
|
|
|
+ if (url) {
|
|
|
|
+ var hash = get_hash(url);
|
|
|
|
+ if (details && details.skin === hash) {
|
|
|
|
+ cache.update_timestamp(uuid, hash);
|
|
|
|
+ callback(null, hash);
|
|
} else {
|
|
} else {
|
|
- // profile found, but has no skin
|
|
|
|
- cache.save_hash(uuid, null);
|
|
|
|
- callback(null, null);
|
|
|
|
|
|
+ logging.log(uuid + " new skin hash: " + hash);
|
|
|
|
+ var facepath = __dirname + "/../" + config.faces_dir + hash + ".png";
|
|
|
|
+ var helmpath = __dirname + "/../" + config.helms_dir + hash + ".png"
|
|
|
|
+ fs.exists(facepath, function(exists) {
|
|
|
|
+ if (exists) {
|
|
|
|
+ logging.log(uuid + " skin already exists, not downloading");
|
|
|
|
+ callback(null, hash);
|
|
|
|
+ } else {
|
|
|
|
+ networking.get_from(url, function(img, response, err) {
|
|
|
|
+ if (err || !img) {
|
|
|
|
+ callback(err, null);
|
|
|
|
+ } else {
|
|
|
|
+ skins.extract_face(img, facepath, function(err) {
|
|
|
|
+ if (err) {
|
|
|
|
+ logging.error(err);
|
|
|
|
+ callback(err, null);
|
|
|
|
+ } else {
|
|
|
|
+ logging.log(uuid + " face extracted");
|
|
|
|
+ skins.extract_helm(facepath, img, helmpath, function(err) {
|
|
|
|
+ logging.log(uuid + " helm extracted");
|
|
|
|
+ logging.debug(helmpath);
|
|
|
|
+ callback(err, hash);
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ });
|
|
}
|
|
}
|
|
|
|
+ } else {
|
|
|
|
+ callback(null, null);
|
|
}
|
|
}
|
|
});
|
|
});
|
|
|
|
+}
|
|
|
|
|
|
- networking.get_cape_url(uuid, function(err, cape_url) {
|
|
|
|
- if (err) {
|
|
|
|
- callback(err, null);
|
|
|
|
- } else {
|
|
|
|
- if (cape_url) {
|
|
|
|
- logging.log(uuid + " " + cape_url);
|
|
|
|
- // set file paths
|
|
|
|
- var hash = get_hash(cape_url);
|
|
|
|
- if (details && details.hash == hash) {
|
|
|
|
- // hash hasn't changed
|
|
|
|
- logging.log(uuid + " hash has not changed");
|
|
|
|
- cache.update_timestamp(uuid, hash);
|
|
|
|
- callback(null, hash);
|
|
|
|
- } else {
|
|
|
|
- // hash has changed
|
|
|
|
- logging.log(uuid + " new hash: " + hash);
|
|
|
|
- var capepath = __dirname + "/../" + config.capes_dir + hash + ".png";
|
|
|
|
-
|
|
|
|
- if (fs.existsSync(capepath)) {
|
|
|
|
- logging.log(uuid + " Cape already exists, not downloading");
|
|
|
|
- cache.save_hash(uuid, hash);
|
|
|
|
|
|
+function store_cape(uuid, profile, details, callback) {
|
|
|
|
+ networking.get_cape_url(uuid, profile, function(url) {
|
|
|
|
+ if (url) {
|
|
|
|
+ var hash = get_hash(url);
|
|
|
|
+ if (details && details.cape === hash) {
|
|
|
|
+ cache.update_timestamp(uuid, hash);
|
|
|
|
+ callback(null, hash);
|
|
|
|
+ } else {
|
|
|
|
+ logging.log(uuid + " new cape hash: " + hash);
|
|
|
|
+ var capepath = __dirname + "/../" + config.capes_dir + hash + ".png";
|
|
|
|
+ fs.exists(capepath, function(exists) {
|
|
|
|
+ if (exists) {
|
|
|
|
+ logging.log(uuid + " cape already exists, not downloading");
|
|
callback(null, hash);
|
|
callback(null, hash);
|
|
} else {
|
|
} else {
|
|
- // download cape
|
|
|
|
- networking.get_cape(cape_url, function(err, img) {
|
|
|
|
|
|
+ networking.get_from(url, function(img, response, err) {
|
|
if (err || !img) {
|
|
if (err || !img) {
|
|
|
|
+ logging.error(err);
|
|
callback(err, null);
|
|
callback(err, null);
|
|
|
|
+ } else {
|
|
|
|
+ skins.save_image(img, capepath, function(err) {
|
|
|
|
+ logging.log(uuid + " cape saved");
|
|
|
|
+ callback(err, hash);
|
|
|
|
+ });
|
|
}
|
|
}
|
|
});
|
|
});
|
|
}
|
|
}
|
|
- }
|
|
|
|
- } else {
|
|
|
|
- // profile found, but has no cape
|
|
|
|
- cache.save_hash(uuid, null);
|
|
|
|
- callback(null, null);
|
|
|
|
|
|
+ });
|
|
}
|
|
}
|
|
|
|
+ } else {
|
|
|
|
+ callback(null, null);
|
|
}
|
|
}
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+function remove_from_array(arr, item) {
|
|
|
|
+ var i;
|
|
|
|
+ while((i = arr.indexOf(item)) !== -1) {
|
|
|
|
+ arr.splice(i, 1);
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+// downloads the images for +uuid+ while checking the cache
|
|
|
|
+// status based on +details+. +whichhash+ specifies which
|
|
|
|
+// image is more important, and should be called back on
|
|
|
|
+// +callback+ contains the error buffer and image hash
|
|
|
|
+var currently_running = [];
|
|
|
|
+function callback_for(uuid, which, err, cape_hash, skin_hash) {
|
|
|
|
+ for (var i = 0; i < currently_running.length; i++) {
|
|
|
|
+ if (currently_running[i] && currently_running[i].uuid === uuid && (currently_running[i].which === which || which === null)) {
|
|
|
|
+ var will_call = currently_running[i];
|
|
|
|
+ will_call.callback(err, will_call.which === 'skin' ? skin_hash : cape_hash);
|
|
|
|
+ //remove_from_array(currently_running, i);
|
|
|
|
+ delete(currently_running[i]);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+function array_has_hash(arr, property, value) {
|
|
|
|
+ for (var i = 0; i < arr.length; i++) {
|
|
|
|
+ if (arr[i] && arr[i][property] === value) {
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return false;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+function store_images(uuid, details, whichhash, callback) {
|
|
|
|
+ var isUUID = uuid.length > 16;
|
|
|
|
+ var new_hash = { 'uuid': uuid, 'which': whichhash, 'callback': callback };
|
|
|
|
+ if (!array_has_hash(currently_running, 'uuid', uuid)) {
|
|
|
|
+ currently_running.push(new_hash);
|
|
|
|
+ networking.get_profile((isUUID ? uuid : null), function(err, profile) {
|
|
|
|
+ if (err || (isUUID && !profile)) {
|
|
|
|
+ callback_for(uuid, err, null, null);
|
|
|
|
+ } else {
|
|
|
|
+ store_skin(uuid, profile, details, function(err, skin_hash) {
|
|
|
|
+ cache.save_hash(uuid, skin_hash, null);
|
|
|
|
+ callback_for(uuid, 'skin', err, null, skin_hash);
|
|
|
|
+ store_cape(uuid, profile, details, function(err, cape_hash) {
|
|
|
|
+ cache.save_hash(uuid, skin_hash, cape_hash);
|
|
|
|
+ callback_for(uuid, 'cape', err, cape_hash, skin_hash);
|
|
|
|
+ });
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ } else {
|
|
|
|
+ currently_running.push(new_hash);
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
|
|
var exp = {};
|
|
var exp = {};
|
|
|
|
|
|
@@ -125,7 +158,6 @@ exp.uuid_valid = function(uuid) {
|
|
return valid_uuid.test(uuid);
|
|
return valid_uuid.test(uuid);
|
|
};
|
|
};
|
|
|
|
|
|
-
|
|
|
|
// decides whether to get an image from disk or to download it
|
|
// decides whether to get an image from disk or to download it
|
|
// callback contains error, status, hash
|
|
// callback contains error, status, hash
|
|
// the status gives information about how the image was received
|
|
// the status gives information about how the image was received
|
|
@@ -134,49 +166,33 @@ exp.uuid_valid = function(uuid) {
|
|
// 1: "cached" - found on disk
|
|
// 1: "cached" - found on disk
|
|
// 2: "downloaded" - profile downloaded, skin downloaded from mojang servers
|
|
// 2: "downloaded" - profile downloaded, skin downloaded from mojang servers
|
|
// 3: "checked" - profile re-downloaded (was too old), but it has either not changed or has no skin
|
|
// 3: "checked" - profile re-downloaded (was too old), but it has either not changed or has no skin
|
|
-exp.get_image_hash = function(uuid, callback) {
|
|
|
|
|
|
+exp.get_image_hash = function(uuid, raw_type, callback) {
|
|
cache.get_details(uuid, function(err, details) {
|
|
cache.get_details(uuid, function(err, details) {
|
|
|
|
+ var type = (details !== null ? (raw_type === "skin" ? details.skin : details.cape) : null);
|
|
if (err) {
|
|
if (err) {
|
|
callback(err, -1, null);
|
|
callback(err, -1, null);
|
|
} else {
|
|
} else {
|
|
- if (details && details.time + config.local_cache_time * 1000 >= new Date().getTime()) {
|
|
|
|
- // uuid known + recently updated
|
|
|
|
- logging.log(uuid + " uuid cached & recently updated");
|
|
|
|
- callback(null, (details.hash ? 1 : 0), details.hash);
|
|
|
|
|
|
+ if (details && details.time + config.local_cache_time * 1000 >= new Date().getTime()) {logging.log(uuid + " uuid cached & recently updated");
|
|
|
|
+ callback(null, (type ? 1 : 0), type);
|
|
|
|
+ } else {
|
|
|
|
+ if (details) {
|
|
|
|
+ logging.log(uuid + " uuid cached, but too old");
|
|
} else {
|
|
} else {
|
|
- if (details) {
|
|
|
|
- logging.log(uuid + " uuid cached, but too old");
|
|
|
|
|
|
+ logging.log(uuid + " uuid not cached");
|
|
|
|
+ }
|
|
|
|
+ store_images(uuid, details, raw_type, function(err, hash) {
|
|
|
|
+ if (err) {
|
|
|
|
+ callback(err, -1, details && type);
|
|
} else {
|
|
} else {
|
|
- logging.log(uuid + " uuid not cached");
|
|
|
|
|
|
+ var status = details && (type === hash) ? 3 : 2;
|
|
|
|
+ logging.debug(uuid + " old hash: " + (details && type));
|
|
|
|
+ logging.log(uuid + " hash: " + hash);
|
|
|
|
+ callback(null, status, hash);
|
|
}
|
|
}
|
|
- store_images(uuid, details, function(err, hash) {
|
|
|
|
- if (err) {
|
|
|
|
- callback(err, -1, details && details.hash);
|
|
|
|
- } else {
|
|
|
|
- // skin is only checked (3) when uuid known AND hash didn't change
|
|
|
|
- // in all other cases the skin is downloaded (2)
|
|
|
|
- var status = details && (details.hash == hash) ? 3 : 2;
|
|
|
|
- logging.debug(uuid + " old hash: " + (details && details.hash));
|
|
|
|
- logging.log(uuid + " hash: " + hash);
|
|
|
|
- callback(null, status, hash);
|
|
|
|
- }
|
|
|
|
- });
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- });
|
|
|
|
-};
|
|
|
|
-
|
|
|
|
-exp.get_cape_hash = function(uuid, callback) {
|
|
|
|
- cache.get_details(uuid, function(err, details) {
|
|
|
|
- if (err) {
|
|
|
|
- callback(err, -1, null);
|
|
|
|
- } else {
|
|
|
|
- if (details && details.time + config.local_cache_time * 1000 >= new Date().getTime()) {
|
|
|
|
- logging.log(uuid + " uuid cached & recently updated");
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
|
|
+ });
|
|
}
|
|
}
|
|
- })
|
|
|
|
|
|
+ }
|
|
|
|
+});
|
|
};
|
|
};
|
|
|
|
|
|
|
|
|
|
@@ -185,17 +201,16 @@ exp.get_cape_hash = function(uuid, callback) {
|
|
// image is the user's face+helm when helm is true, or the face otherwise
|
|
// image is the user's face+helm when helm is true, or the face otherwise
|
|
// for status, see get_image_hash
|
|
// for status, see get_image_hash
|
|
exp.get_avatar = function(uuid, helm, size, callback) {
|
|
exp.get_avatar = function(uuid, helm, size, callback) {
|
|
- exp.get_image_hash(uuid, function(err, status, hash) {
|
|
|
|
|
|
+ logging.log("request: " + uuid);
|
|
|
|
+ exp.get_image_hash(uuid, "skin", function(err, status, hash) {
|
|
if (hash) {
|
|
if (hash) {
|
|
var facepath = __dirname + "/../" + config.faces_dir + hash + ".png";
|
|
var facepath = __dirname + "/../" + config.faces_dir + hash + ".png";
|
|
var helmpath = __dirname + "/../" + config.helms_dir + hash + ".png";
|
|
var helmpath = __dirname + "/../" + config.helms_dir + hash + ".png";
|
|
var filepath = facepath;
|
|
var filepath = facepath;
|
|
-
|
|
|
|
fs.exists(helmpath, function (exists) {
|
|
fs.exists(helmpath, function (exists) {
|
|
if (helm && exists) {
|
|
if (helm && exists) {
|
|
filepath = helmpath;
|
|
filepath = helmpath;
|
|
}
|
|
}
|
|
-
|
|
|
|
skins.resize_img(filepath, size, function(img_err, result) {
|
|
skins.resize_img(filepath, size, function(img_err, result) {
|
|
if (img_err) {
|
|
if (img_err) {
|
|
callback(img_err, -1, null, hash);
|
|
callback(img_err, -1, null, hash);
|
|
@@ -216,7 +231,8 @@ exp.get_avatar = function(uuid, helm, size, callback) {
|
|
// handles requests for +uuid+ skins
|
|
// handles requests for +uuid+ skins
|
|
// callback contains error, hash, image buffer
|
|
// callback contains error, hash, image buffer
|
|
exp.get_skin = function(uuid, callback) {
|
|
exp.get_skin = function(uuid, callback) {
|
|
- exp.get_image_hash(uuid, function(err, status, hash) {
|
|
|
|
|
|
+ logging.log(uuid + " skin request");
|
|
|
|
+ exp.get_image_hash(uuid, 'skin', function(err, status, hash) {
|
|
var skinpath = __dirname + "/../" + config.skins_dir + hash + ".png";
|
|
var skinpath = __dirname + "/../" + config.skins_dir + hash + ".png";
|
|
fs.exists(skinpath, function (exists) {
|
|
fs.exists(skinpath, function (exists) {
|
|
if (exists) {
|
|
if (exists) {
|
|
@@ -235,7 +251,7 @@ exp.get_skin = function(uuid, callback) {
|
|
|
|
|
|
function get_type(helm, body) {
|
|
function get_type(helm, body) {
|
|
var text = body ? "body" : "head";
|
|
var text = body ? "body" : "head";
|
|
- return helm ? text+"helm" : text;
|
|
|
|
|
|
+ return helm ? text + "helm" : text;
|
|
}
|
|
}
|
|
|
|
|
|
// handles creations of skin renders
|
|
// handles creations of skin renders
|
|
@@ -247,51 +263,84 @@ exp.get_render = function(uuid, scale, helm, body, callback) {
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
var renderpath = __dirname + "/../" + config.renders_dir + hash + "-" + scale + "-" + get_type(helm, body) + ".png";
|
|
var renderpath = __dirname + "/../" + config.renders_dir + hash + "-" + scale + "-" + get_type(helm, body) + ".png";
|
|
- fs.exists(renderpath, function (exists) {
|
|
|
|
|
|
+ fs.exists(renderpath, function(exists) {
|
|
if (exists) {
|
|
if (exists) {
|
|
renders.open_render(uuid, renderpath, function(err, img) {
|
|
renders.open_render(uuid, renderpath, function(err, img) {
|
|
callback(err, 1, hash, img);
|
|
callback(err, 1, hash, img);
|
|
});
|
|
});
|
|
return;
|
|
return;
|
|
|
|
+ } else {
|
|
|
|
+ if (!img) {
|
|
|
|
+ callback(err, 0, hash, null);
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ renders.draw_model(uuid, img, scale, helm, body, function(err, img) {
|
|
|
|
+ if (err) {
|
|
|
|
+ callback(err, -1, hash, null);
|
|
|
|
+ } else if (!img) {
|
|
|
|
+ callback(null, 0, hash, null);
|
|
|
|
+ } else {
|
|
|
|
+ fs.writeFile(renderpath, img, "binary", function(err) {
|
|
|
|
+ if (err) {
|
|
|
|
+ logging.log(err);
|
|
|
|
+ }
|
|
|
|
+ callback(null, 2, hash, img);
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ });
|
|
}
|
|
}
|
|
- if (!img) {
|
|
|
|
- callback(err, 0, hash, null);
|
|
|
|
- return;
|
|
|
|
|
|
+ });
|
|
|
|
+ });
|
|
|
|
+};
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+// handles requests for +uuid+ skins
|
|
|
|
+// callback contains error, hash, image buffer
|
|
|
|
+exp.get_skin = function(uuid, callback) {
|
|
|
|
+ logging.log(uuid + " skin request");
|
|
|
|
+ exp.get_image_hash(uuid, "skin", function(err, status, hash) {
|
|
|
|
+ var skinpath = __dirname + "/../" + config.skins_dir + hash + ".png";
|
|
|
|
+ fs.exists(skinpath, function(exists) {
|
|
|
|
+ if (exists) {
|
|
|
|
+ logging.log("skin already exists, not downloading");
|
|
|
|
+ skins.open_skin(skinpath, function(err, img) {
|
|
|
|
+ callback(err, hash, img);
|
|
|
|
+ });
|
|
|
|
+ } else {
|
|
|
|
+ networking.save_texture(uuid, hash, skinpath, function(err, response, img) {
|
|
|
|
+ callback(err, hash, img);
|
|
|
|
+ });
|
|
}
|
|
}
|
|
- renders.draw_model(uuid, img, scale, helm, body, function(err, img) {
|
|
|
|
- if (err) {
|
|
|
|
- callback(err, -1, hash, null);
|
|
|
|
- } else if (!img) {
|
|
|
|
- callback(null, 0, hash, null);
|
|
|
|
- } else {
|
|
|
|
- fs.writeFile(renderpath, img, "binary", function(err){
|
|
|
|
- if (err) {
|
|
|
|
- logging.log(uuid + " error: " + err);
|
|
|
|
- }
|
|
|
|
- callback(null, 2, hash, img);
|
|
|
|
- });
|
|
|
|
- }
|
|
|
|
- });
|
|
|
|
});
|
|
});
|
|
});
|
|
});
|
|
};
|
|
};
|
|
|
|
|
|
|
|
+// handles requests for +uuid+ capes
|
|
|
|
+// callback contains error, hash, image buffer
|
|
exp.get_cape = function(uuid, callback) {
|
|
exp.get_cape = function(uuid, callback) {
|
|
logging.log(uuid + " cape request");
|
|
logging.log(uuid + " cape request");
|
|
- exp.get_image_hash(uuid, function(err, status, hash) {
|
|
|
|
- if (hash) {
|
|
|
|
- var capeurl = "http://textures.minecraft.net/texture/" + hash;
|
|
|
|
- networking.get_cape(capeurl, function(err, img) {
|
|
|
|
- if (err) {
|
|
|
|
- logging.error("error while downloading cape");
|
|
|
|
- callback(err, hash, null);
|
|
|
|
- } else {
|
|
|
|
- callback(null, hash, img);
|
|
|
|
- }
|
|
|
|
- });
|
|
|
|
- } else {
|
|
|
|
|
|
+ exp.get_image_hash(uuid, "cape", function(err, status, hash) {
|
|
|
|
+ if (!hash) {
|
|
callback(err, null, null);
|
|
callback(err, null, null);
|
|
|
|
+ return;
|
|
}
|
|
}
|
|
|
|
+ var capepath = __dirname + "/../" + config.capes_path + hash + ".png";
|
|
|
|
+ fs.exists(capepath, function(exists) {
|
|
|
|
+ if (exists) {
|
|
|
|
+ logging.log("cape already exists, not downloading");
|
|
|
|
+ skins.open_skin(capepath, function(err, img) {
|
|
|
|
+ callback(err, hash, img);
|
|
|
|
+ });
|
|
|
|
+ } else {
|
|
|
|
+ networking.save_texture(uuid, hash, capepath, function(err, response, img) {
|
|
|
|
+ if (response && response.statusCode === 404) {
|
|
|
|
+ callback(err, hash, null);
|
|
|
|
+ } else {
|
|
|
|
+ callback(err, hash, img);
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ });
|
|
});
|
|
});
|
|
};
|
|
};
|
|
|
|
|