|
@@ -21,12 +21,12 @@ function get_hash(url) {
|
|
|
// face and face+helm images are extracted and stored to files
|
|
|
// callback: error, skin hash
|
|
|
function store_skin(rid, userId, profile, cache_details, callback) {
|
|
|
- networking.get_skin_url(rid, userId, profile, function(err, url) {
|
|
|
+ networking.get_skin_info(rid, userId, profile, function(err, url, slim) {
|
|
|
if (!err && url) {
|
|
|
var skin_hash = get_hash(url);
|
|
|
if (cache_details && cache_details.skin === skin_hash) {
|
|
|
cache.update_timestamp(rid, userId, skin_hash, false, function(cache_err) {
|
|
|
- callback(cache_err, skin_hash);
|
|
|
+ callback(cache_err, skin_hash, slim);
|
|
|
});
|
|
|
} else {
|
|
|
logging.debug(rid, "new skin hash:", skin_hash);
|
|
@@ -36,27 +36,27 @@ function store_skin(rid, userId, profile, cache_details, callback) {
|
|
|
fs.exists(facepath, function(exists) {
|
|
|
if (exists) {
|
|
|
logging.debug(rid, "skin already exists, not downloading");
|
|
|
- callback(null, skin_hash);
|
|
|
+ callback(null, skin_hash, slim);
|
|
|
} else {
|
|
|
networking.get_from(rid, url, function(img, response, err1) {
|
|
|
if (err1 || !img) {
|
|
|
- callback(err1, null);
|
|
|
+ callback(err1, null, slim);
|
|
|
} else {
|
|
|
skins.save_image(img, skinpath, function(skin_err) {
|
|
|
if (skin_err) {
|
|
|
logging.error(rid, skin_err);
|
|
|
- callback(skin_err, null);
|
|
|
+ callback(skin_err, null, slim);
|
|
|
} else {
|
|
|
skins.extract_face(img, facepath, function(err2) {
|
|
|
if (err2) {
|
|
|
logging.error(rid, err2.stack);
|
|
|
- callback(err2, null);
|
|
|
+ callback(err2, null, slim);
|
|
|
} else {
|
|
|
logging.debug(rid, "face extracted");
|
|
|
skins.extract_helm(rid, facepath, img, helmpath, function(err3) {
|
|
|
logging.debug(rid, "helm extracted");
|
|
|
logging.debug(rid, helmpath);
|
|
|
- callback(err3, skin_hash);
|
|
|
+ callback(err3, skin_hash, slim);
|
|
|
});
|
|
|
}
|
|
|
});
|
|
@@ -129,7 +129,7 @@ function push_request(userId, type, fun) {
|
|
|
}
|
|
|
|
|
|
// calls back all queued requests that match userId and type
|
|
|
-function resume(userId, type, err, hash) {
|
|
|
+function resume(userId, type, err, hash, slim) {
|
|
|
var callbacks = requests[type][userId];
|
|
|
if (callbacks) {
|
|
|
if (callbacks.length > 1) {
|
|
@@ -138,7 +138,7 @@ function resume(userId, type, err, hash) {
|
|
|
|
|
|
for (var i = 0; i < callbacks.length; i++) {
|
|
|
// continue the request
|
|
|
- callbacks[i](err, hash);
|
|
|
+ callbacks[i](err, hash, slim);
|
|
|
// remove from array
|
|
|
callbacks.splice(i, 1);
|
|
|
i--;
|
|
@@ -167,34 +167,34 @@ function store_images(rid, userId, cache_details, type, callback) {
|
|
|
// error or uuid without profile
|
|
|
if (!err && !profile) {
|
|
|
// no error, but uuid without profile
|
|
|
- cache.save_hash(rid, userId, null, null, function(cache_err) {
|
|
|
+ cache.save_hash(rid, userId, null, null, undefined, function(cache_err) {
|
|
|
// we have no profile, so we have neither skin nor cape
|
|
|
- resume(userId, "skin", cache_err, null);
|
|
|
- resume(userId, "cape", cache_err, null);
|
|
|
+ resume(userId, "skin", cache_err, null, false);
|
|
|
+ resume(userId, "cape", cache_err, null, false);
|
|
|
});
|
|
|
} else {
|
|
|
// an error occured, not caching. we can try in 60 seconds
|
|
|
- resume(userId, type, err, null);
|
|
|
+ resume(userId, type, err, null, false);
|
|
|
}
|
|
|
} else {
|
|
|
// no error and we have a profile (if it's a uuid)
|
|
|
- store_skin(rid, userId, profile, cache_details, function(store_err, skin_hash) {
|
|
|
+ store_skin(rid, userId, profile, cache_details, function(store_err, skin_hash, slim) {
|
|
|
if (store_err && !skin_hash) {
|
|
|
// an error occured, not caching. we can try in 60 seconds
|
|
|
- resume(userId, "skin", store_err, null);
|
|
|
+ resume(userId, "skin", store_err, null, slim);
|
|
|
} else {
|
|
|
- cache.save_hash(rid, userId, skin_hash, undefined, function(cache_err) {
|
|
|
- resume(userId, "skin", (store_err || cache_err), skin_hash);
|
|
|
+ cache.save_hash(rid, userId, skin_hash, undefined, slim, function(cache_err) {
|
|
|
+ resume(userId, "skin", (store_err || cache_err), skin_hash, slim);
|
|
|
});
|
|
|
}
|
|
|
});
|
|
|
store_cape(rid, userId, profile, cache_details, function(store_err, cape_hash) {
|
|
|
if (store_err && !cape_hash) {
|
|
|
// an error occured, not caching. we can try in 60 seconds
|
|
|
- resume(userId, "cape", (store_err), cape_hash);
|
|
|
+ resume(userId, "cape", (store_err), cape_hash, false);
|
|
|
} else {
|
|
|
- cache.save_hash(rid, userId, undefined, cape_hash, function(cache_err) {
|
|
|
- resume(userId, "cape", (store_err || cache_err), cape_hash);
|
|
|
+ cache.save_hash(rid, userId, undefined, cape_hash, undefined, function(cache_err) {
|
|
|
+ resume(userId, "cape", (store_err || cache_err), cape_hash, false);
|
|
|
});
|
|
|
}
|
|
|
});
|
|
@@ -212,7 +212,7 @@ exp.id_valid = function(userId) {
|
|
|
};
|
|
|
|
|
|
// decides whether to get a +type+ image for +userId+ from disk or to download it
|
|
|
-// callback: error, status, hash
|
|
|
+// callback: error, status, hash, slim
|
|
|
// for status, see response.js
|
|
|
exp.get_image_hash = function(rid, userId, type, callback) {
|
|
|
cache.get_details(userId, function(err, cache_details) {
|
|
@@ -221,12 +221,12 @@ exp.get_image_hash = function(rid, userId, type, callback) {
|
|
|
cached_hash = type === "skin" ? cache_details.skin : cache_details.cape;
|
|
|
}
|
|
|
if (err) {
|
|
|
- callback(err, -1, null);
|
|
|
+ callback(err, -1, null, false);
|
|
|
} else {
|
|
|
if (cache_details && cache_details[type] !== undefined && cache_details.time + config.caching.local * 1000 >= Date.now()) {
|
|
|
// use cached image
|
|
|
logging.debug(rid, "userId cached & recently updated");
|
|
|
- callback(null, (cached_hash ? 1 : 0), cached_hash);
|
|
|
+ callback(null, (cached_hash ? 1 : 0), cached_hash, cache_details.slim);
|
|
|
} else {
|
|
|
// download image
|
|
|
if (cache_details) {
|
|
@@ -234,18 +234,18 @@ exp.get_image_hash = function(rid, userId, type, callback) {
|
|
|
} else {
|
|
|
logging.debug(rid, "userId not cached");
|
|
|
}
|
|
|
- store_images(rid, userId, cache_details, type, function(store_err, new_hash) {
|
|
|
+ store_images(rid, userId, cache_details, type, function(store_err, new_hash, slim) {
|
|
|
if (store_err) {
|
|
|
// we might have a cached hash although an error occured
|
|
|
// (e.g. Mojang servers not reachable, using outdated hash)
|
|
|
cache.update_timestamp(rid, userId, cached_hash, true, function(err2) {
|
|
|
- callback(err2 || store_err, -1, cache_details && cached_hash);
|
|
|
+ callback(err2 || store_err, -1, cache_details && cached_hash, slim);
|
|
|
});
|
|
|
} else {
|
|
|
var status = cache_details && (cached_hash === new_hash) ? 3 : 2;
|
|
|
logging.debug(rid, "cached hash:", (cache_details && cached_hash));
|
|
|
logging.debug(rid, "new hash:", new_hash);
|
|
|
- callback(null, status, new_hash);
|
|
|
+ callback(null, status, new_hash, slim);
|
|
|
}
|
|
|
});
|
|
|
}
|
|
@@ -259,7 +259,7 @@ exp.get_image_hash = function(rid, userId, type, callback) {
|
|
|
// image is the user's face+helm when helm is true, or the face otherwise
|
|
|
// for status, see get_image_hash
|
|
|
exp.get_avatar = function(rid, userId, helm, size, callback) {
|
|
|
- exp.get_image_hash(rid, userId, "skin", function(err, status, skin_hash) {
|
|
|
+ exp.get_image_hash(rid, userId, "skin", function(err, status, skin_hash, slim) {
|
|
|
if (skin_hash) {
|
|
|
var facepath = path.join(__dirname, "..", config.directories.faces, skin_hash + ".png");
|
|
|
var helmpath = path.join(__dirname, "..", config.directories.helms, skin_hash + ".png");
|
|
@@ -286,23 +286,23 @@ exp.get_avatar = function(rid, userId, helm, size, callback) {
|
|
|
// handles requests for +userId+ skins
|
|
|
// callback: error, skin hash, status, image buffer
|
|
|
exp.get_skin = function(rid, userId, callback) {
|
|
|
- exp.get_image_hash(rid, userId, "skin", function(err, status, skin_hash) {
|
|
|
+ exp.get_image_hash(rid, userId, "skin", function(err, status, skin_hash, slim) {
|
|
|
if (skin_hash) {
|
|
|
var skinpath = path.join(__dirname, "..", config.directories.skins, skin_hash + ".png");
|
|
|
fs.exists(skinpath, function(exists) {
|
|
|
if (exists) {
|
|
|
logging.debug(rid, "skin already exists, not downloading");
|
|
|
skins.open_skin(rid, skinpath, function(skin_err, img) {
|
|
|
- callback(skin_err || err, skin_hash, status, img);
|
|
|
+ callback(skin_err || err, skin_hash, status, img, slim);
|
|
|
});
|
|
|
} else {
|
|
|
networking.save_texture(rid, skin_hash, skinpath, function(net_err, response, img) {
|
|
|
- callback(net_err || err, skin_hash, status, img);
|
|
|
+ callback(net_err || err, skin_hash, status, img, slim);
|
|
|
});
|
|
|
}
|
|
|
});
|
|
|
} else {
|
|
|
- callback(err, null, status, null);
|
|
|
+ callback(err, null, status, null, slim);
|
|
|
}
|
|
|
});
|
|
|
};
|
|
@@ -318,12 +318,12 @@ function get_type(helm, body) {
|
|
|
// handles creations of 3D renders
|
|
|
// callback: error, skin hash, image buffer
|
|
|
exp.get_render = function(rid, userId, scale, helm, body, callback) {
|
|
|
- exp.get_skin(rid, userId, function(err, skin_hash, status, img) {
|
|
|
+ exp.get_skin(rid, userId, function(err, skin_hash, status, img, slim) {
|
|
|
if (!skin_hash) {
|
|
|
callback(err, status, skin_hash, null);
|
|
|
return;
|
|
|
}
|
|
|
- var renderpath = path.join(__dirname, "..", config.directories.renders, [skin_hash, scale, get_type(helm, body)].join("-") + ".png");
|
|
|
+ var renderpath = path.join(__dirname, "..", config.directories.renders, [skin_hash, scale, get_type(helm, body), slim ? "s" : "t"].join("-") + ".png");
|
|
|
fs.exists(renderpath, function(exists) {
|
|
|
if (exists) {
|
|
|
renders.open_render(rid, renderpath, function(render_err, rendered_img) {
|
|
@@ -335,7 +335,7 @@ exp.get_render = function(rid, userId, scale, helm, body, callback) {
|
|
|
callback(err, 0, skin_hash, null);
|
|
|
return;
|
|
|
}
|
|
|
- renders.draw_model(rid, img, scale, helm, body, function(draw_err, drawn_img) {
|
|
|
+ renders.draw_model(rid, img, scale, helm, body, slim, function(draw_err, drawn_img) {
|
|
|
if (draw_err) {
|
|
|
callback(draw_err, -1, skin_hash, null);
|
|
|
} else if (!drawn_img) {
|
|
@@ -357,7 +357,7 @@ exp.get_render = function(rid, userId, scale, helm, body, callback) {
|
|
|
// handles requests for +userId+ capes
|
|
|
// callback: error, cape hash, status, image buffer
|
|
|
exp.get_cape = function(rid, userId, callback) {
|
|
|
- exp.get_image_hash(rid, userId, "cape", function(err, status, cape_hash) {
|
|
|
+ exp.get_image_hash(rid, userId, "cape", function(err, status, cape_hash, slim) {
|
|
|
if (!cape_hash) {
|
|
|
callback(err, null, status, null);
|
|
|
return;
|