From 01bf32d8edd4e54e57a772d46e41b67a21522f82 Mon Sep 17 00:00:00 2001 From: printempw Date: Thu, 4 Feb 2016 23:46:58 +0800 Subject: [PATCH] supported both CustomSkinLoader API and UniSkinAPI --- config.php | 4 ++-- get.php | 13 +++++++++---- includes/user.class.php | 24 ++++++++++++++++-------- 3 files changed, 27 insertions(+), 14 deletions(-) diff --git a/config.php b/config.php index 7f062e40..847ec57e 100644 --- a/config.php +++ b/config.php @@ -17,5 +17,5 @@ define('SALT', '9tvsh55d*s'); /* Max amount of accounts per IP */ define('REGS_PER_IP', 2); -/* Do not change this */ -define('DIR', dirname(__FILE__)); +/* Which API to use, 0 for CustomSkinLoader API, 1 for UniSkinAPI */ +define('API_TYPE', 0); diff --git a/get.php b/get.php index 36bb8064..38bbbad4 100644 --- a/get.php +++ b/get.php @@ -3,17 +3,18 @@ * @Author: prpr * @Date: 2016-02-02 20:56:42 * @Last Modified by: prpr - * @Last Modified time: 2016-02-03 13:37:33 + * @Last Modified time: 2016-02-04 22:06:20 + * + * All textures requests of legacy link will be handle here. */ $dir = dirname(__FILE__); require "$dir/includes/autoload.inc.php"; -require "$dir/config.php"; if (isset($_GET['type']) && isset($_GET['uname'])) { $user = new user($_GET['uname']); if (!$user->is_registered) utils::raise(1, 'Non-existent user.'); - + // Cache friendly $if_modified_since = isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) ? strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) : null; if ($_GET['type'] == "skin" || $_GET['type'] == "cape") { @@ -23,7 +24,11 @@ if (isset($_GET['type']) && isset($_GET['uname'])) { echo $user->getBinaryTexture($_GET['type']); } } else if ($_GET['type'] == "json") { - echo $user->getJsonProfile(); + if (isset($_GET['api'])) { + echo $user->getJsonProfile(($_GET['api'] == 'csl') ? 0 : 1); + } else { + echo $user->getJsonProfile(API_TYPE); + } } else { utils::raise(1, 'Illegal parameters.'); } diff --git a/includes/user.class.php b/includes/user.class.php index 7f540e7c..f25bb602 100644 --- a/includes/user.class.php +++ b/includes/user.class.php @@ -3,7 +3,7 @@ * @Author: printempw * @Date: 2016-01-16 23:01:33 * @Last Modified by: prpr - * @Last Modified time: 2016-02-04 13:48:48 + * @Last Modified time: 2016-02-04 20:38:42 */ class user @@ -121,15 +121,23 @@ class user return $this->db->select('username', $this->uname)['preference']; } - public function getJsonProfile() { + public function getJsonProfile($api_type) { header('Content-type: application/json'); if ($this->is_registered) { - $json['player_name'] = $this->uname; - $json['last_update'] = $this->getLastModified(); - $preference = $this->getPreference(); - $json['model_preference'] = [$preference]; - $json['skins'][$preference] = $this->getTexture('skin'); - $json['cape'] = $this->getTexture('cape'); + if ($api_type == 0 || $api_type == 1) { + $json[($api_type == 0) ? 'username' : 'player_name'] = $this->uname; + $model = $this->getPreference(); + $sec_model = ($model == 'default') ? 'slim' : 'default'; + if ($api_type == 1) { + $json['last_update'] = $this->getLastModified(); + $json['model_preference'] = [$model, $sec_model]; + } + $json['skins'][$model] = $this->getTexture('skin'); + $json['skins'][$sec_model] = $this->getTexture('skin'); + $json['cape'] = $this->getTexture('cape'); + } else { + utils::raise(-1, 'Configuration error. Non-supported API_TYPE.'); + } } else { $json['errno'] = 1; $json['msg'] = "Non-existent user.";