|
@@ -7,7 +7,7 @@ var renders = require("./renders");
|
|
|
var fs = require("fs");
|
|
|
|
|
|
// 0098cb60-fa8e-427c-b299-793cbd302c9a
|
|
|
-var valid_uuid = /^([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}|[a-zA-Z0-9_]{1,16})$/; // uuid|username
|
|
|
var hash_pattern = /[0-9a-f]+$/;
|
|
|
|
|
|
// gets the hash from the textures.minecraft.net +url+
|
|
@@ -15,12 +15,12 @@ function get_hash(url) {
|
|
|
return hash_pattern.exec(url)[0].toLowerCase();
|
|
|
}
|
|
|
|
|
|
-function store_skin(rid, uuid, profile, details, callback) {
|
|
|
- networking.get_skin_url(rid, uuid, profile, function(url) {
|
|
|
+function store_skin(rid, userId, profile, details, callback) {
|
|
|
+ networking.get_skin_url(rid, userId, profile, function(url) {
|
|
|
if (url) {
|
|
|
var hash = get_hash(url);
|
|
|
if (details && details.skin === hash) {
|
|
|
- cache.update_timestamp(rid, uuid, hash);
|
|
|
+ cache.update_timestamp(rid, userId, hash);
|
|
|
callback(null, hash);
|
|
|
} else {
|
|
|
logging.log(rid + "new skin hash: " + hash);
|
|
@@ -59,12 +59,12 @@ function store_skin(rid, uuid, profile, details, callback) {
|
|
|
});
|
|
|
}
|
|
|
|
|
|
-function store_cape(rid, uuid, profile, details, callback) {
|
|
|
- networking.get_cape_url(rid, uuid, profile, function(url) {
|
|
|
+function store_cape(rid, userId, profile, details, callback) {
|
|
|
+ networking.get_cape_url(rid, userId, profile, function(url) {
|
|
|
if (url) {
|
|
|
var hash = get_hash(url);
|
|
|
if (details && details.cape === hash) {
|
|
|
- cache.update_timestamp(rid, uuid, hash);
|
|
|
+ cache.update_timestamp(rid, userId, hash);
|
|
|
callback(null, hash);
|
|
|
} else {
|
|
|
logging.log(rid + "new cape hash: " + hash);
|
|
@@ -94,15 +94,15 @@ function store_cape(rid, uuid, profile, details, callback) {
|
|
|
});
|
|
|
}
|
|
|
|
|
|
-// used by store_images to queue simultaneous requests for identical uuid
|
|
|
+// used by store_images to queue simultaneous requests for identical userId
|
|
|
// the first request has to be completed until all others are continued
|
|
|
var currently_running = [];
|
|
|
-// calls back all queued requests that match uuid and type
|
|
|
-function callback_for(uuid, type, err, hash) {
|
|
|
+// calls back all queued requests that match userId and type
|
|
|
+function callback_for(userId, type, err, hash) {
|
|
|
var req_count = 0;
|
|
|
for (var i = 0; i < currently_running.length; i++) {
|
|
|
var current = currently_running[i];
|
|
|
- if (current.uuid === uuid && current.type === type) {
|
|
|
+ if (current.userid === userId && current.type === type) {
|
|
|
req_count++;
|
|
|
if (req_count !== 1) {
|
|
|
// otherwise this would show up on single/first requests, too
|
|
@@ -114,7 +114,7 @@ function callback_for(uuid, type, err, hash) {
|
|
|
}
|
|
|
}
|
|
|
if (req_count > 1) {
|
|
|
- logging.debug(req_count + " simultaneous requests for " + uuid);
|
|
|
+ logging.debug(req_count + " simultaneous requests for " + userId);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -128,30 +128,30 @@ function deep_property_check(arr, property, value) {
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
-// downloads the images for +uuid+ while checking the cache
|
|
|
+// downloads the images for +userId+ while checking the cache
|
|
|
// status based on +details+. +type+ specifies which
|
|
|
// image type should be called back on
|
|
|
// +callback+ contains the error buffer and image hash
|
|
|
-function store_images(rid, uuid, details, type, callback) {
|
|
|
- var is_uuid = uuid.length > 16;
|
|
|
+function store_images(rid, userId, details, type, callback) {
|
|
|
+ var is_uuid = userId.length > 16;
|
|
|
var new_hash = {
|
|
|
rid: rid,
|
|
|
- uuid: uuid,
|
|
|
+ userid: userId,
|
|
|
type: type,
|
|
|
callback: callback
|
|
|
};
|
|
|
- if (!deep_property_check(currently_running, "uuid", uuid)) {
|
|
|
+ if (!deep_property_check(currently_running, "userid", userId)) {
|
|
|
currently_running.push(new_hash);
|
|
|
- networking.get_profile(rid, (is_uuid ? uuid : null), function(err, profile) {
|
|
|
+ networking.get_profile(rid, (is_uuid ? userId : null), function(err, profile) {
|
|
|
if (err || (is_uuid && !profile)) {
|
|
|
- callback_for(uuid, type, err, null);
|
|
|
+ callback_for(userId, type, err, null);
|
|
|
} else {
|
|
|
- store_skin(rid, uuid, profile, details, function(err, skin_hash) {
|
|
|
- cache.save_hash(rid, uuid, skin_hash, null);
|
|
|
- callback_for(uuid, "skin", err, skin_hash);
|
|
|
- store_cape(rid, uuid, profile, details, function(err, cape_hash) {
|
|
|
- cache.save_hash(rid, uuid, skin_hash, cape_hash);
|
|
|
- callback_for(uuid, "cape", err, cape_hash);
|
|
|
+ store_skin(rid, userId, profile, details, function(err, skin_hash) {
|
|
|
+ cache.save_hash(rid, userId, skin_hash, null);
|
|
|
+ callback_for(userId, "skin", err, skin_hash);
|
|
|
+ store_cape(rid, userId, profile, details, function(err, cape_hash) {
|
|
|
+ cache.save_hash(rid, userId, skin_hash, cape_hash);
|
|
|
+ callback_for(userId, "cape", err, cape_hash);
|
|
|
});
|
|
|
});
|
|
|
}
|
|
@@ -164,10 +164,10 @@ function store_images(rid, uuid, details, type, callback) {
|
|
|
|
|
|
var exp = {};
|
|
|
|
|
|
-// returns true if the +uuid+ is a valid uuid or username
|
|
|
-// the uuid may be not exist, however
|
|
|
-exp.uuid_valid = function(uuid) {
|
|
|
- return valid_uuid.test(uuid);
|
|
|
+// returns true if the +userId+ is a valid userId or username
|
|
|
+// the userId may be not exist, however
|
|
|
+exp.id_valid = function(userId) {
|
|
|
+ return valid_user_id.test(userId);
|
|
|
};
|
|
|
|
|
|
// decides whether to get an image from disk or to download it
|
|
@@ -178,22 +178,22 @@ exp.uuid_valid = function(uuid) {
|
|
|
// 1: "cached" - found on disk
|
|
|
// 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
|
|
|
-exp.get_image_hash = function(rid, uuid, raw_type, callback) {
|
|
|
- cache.get_details(uuid, function(err, details) {
|
|
|
+exp.get_image_hash = function(rid, userId, raw_type, callback) {
|
|
|
+ cache.get_details(userId, function(err, details) {
|
|
|
var type = (details !== null ? (raw_type === "skin" ? details.skin : details.cape) : null);
|
|
|
if (err) {
|
|
|
callback(err, -1, null);
|
|
|
} else {
|
|
|
if (details && details.time + config.local_cache_time * 1000 >= new Date().getTime()) {
|
|
|
- logging.log(rid + "uuid cached & recently updated");
|
|
|
+ logging.log(rid + "userId cached & recently updated");
|
|
|
callback(null, (type ? 1 : 0), type);
|
|
|
} else {
|
|
|
if (details) {
|
|
|
- logging.log(rid + "uuid cached, but too old");
|
|
|
+ logging.log(rid + "userId cached, but too old");
|
|
|
} else {
|
|
|
- logging.log(rid + "uuid not cached");
|
|
|
+ logging.log(rid + "userId not cached");
|
|
|
}
|
|
|
- store_images(rid, uuid, details, raw_type, function(err, hash) {
|
|
|
+ store_images(rid, userId, details, raw_type, function(err, hash) {
|
|
|
if (err) {
|
|
|
callback(err, -1, details && type);
|
|
|
} else {
|
|
@@ -209,12 +209,12 @@ exp.get_image_hash = function(rid, uuid, raw_type, callback) {
|
|
|
};
|
|
|
|
|
|
|
|
|
-// handles requests for +uuid+ avatars with +size+
|
|
|
+// handles requests for +userId+ avatars with +size+
|
|
|
// callback contains error, status, image buffer, hash
|
|
|
// 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, uuid, helm, size, callback) {
|
|
|
- exp.get_image_hash(rid, uuid, "skin", function(err, status, hash) {
|
|
|
+exp.get_avatar = function(rid, userId, helm, size, callback) {
|
|
|
+ exp.get_image_hash(rid, userId, "skin", function(err, status, hash) {
|
|
|
if (hash) {
|
|
|
var facepath = __dirname + "/../" + config.faces_dir + hash + ".png";
|
|
|
var helmpath = __dirname + "/../" + config.helms_dir + hash + ".png";
|
|
@@ -234,17 +234,17 @@ exp.get_avatar = function(rid, uuid, helm, size, callback) {
|
|
|
});
|
|
|
});
|
|
|
} else {
|
|
|
- // hash is null when uuid has no skin
|
|
|
+ // hash is null when userId has no skin
|
|
|
callback(err, status, null, null);
|
|
|
}
|
|
|
});
|
|
|
};
|
|
|
|
|
|
-// handles requests for +uuid+ skins
|
|
|
+// handles requests for +userId+ skins
|
|
|
// callback contains error, hash, image buffer
|
|
|
-exp.get_skin = function(rid, uuid, callback) {
|
|
|
+exp.get_skin = function(rid, userId, callback) {
|
|
|
logging.log(rid + "skin request");
|
|
|
- exp.get_image_hash(rid, uuid, "skin", function(err, status, hash) {
|
|
|
+ exp.get_image_hash(rid, userId, "skin", function(err, status, hash) {
|
|
|
var skinpath = __dirname + "/../" + config.skins_dir + hash + ".png";
|
|
|
fs.exists(skinpath, function(exists) {
|
|
|
if (exists) {
|
|
@@ -268,8 +268,8 @@ function get_type(helm, body) {
|
|
|
|
|
|
// handles creations of skin renders
|
|
|
// callback contanis error, hash, image buffer
|
|
|
-exp.get_render = function(rid, uuid, scale, helm, body, callback) {
|
|
|
- exp.get_skin(rid, uuid, function(err, hash, img) {
|
|
|
+exp.get_render = function(rid, userId, scale, helm, body, callback) {
|
|
|
+ exp.get_skin(rid, userId, function(err, hash, img) {
|
|
|
if (!hash) {
|
|
|
callback(err, -1, hash, null);
|
|
|
return;
|
|
@@ -305,11 +305,11 @@ exp.get_render = function(rid, uuid, scale, helm, body, callback) {
|
|
|
});
|
|
|
};
|
|
|
|
|
|
-// handles requests for +uuid+ capes
|
|
|
+// handles requests for +userId+ capes
|
|
|
// callback contains error, hash, image buffer
|
|
|
-exp.get_cape = function(rid, uuid, callback) {
|
|
|
+exp.get_cape = function(rid, userId, callback) {
|
|
|
logging.log(rid + "cape request");
|
|
|
- exp.get_image_hash(rid, uuid, "cape", function(err, status, hash) {
|
|
|
+ exp.get_image_hash(rid, userId, "cape", function(err, status, hash) {
|
|
|
if (!hash) {
|
|
|
callback(err, null, null);
|
|
|
return;
|