supported both CustomSkinLoader API and UniSkinAPI

This commit is contained in:
printempw 2016-02-04 23:46:58 +08:00
parent f113876f1b
commit 01bf32d8ed
3 changed files with 27 additions and 14 deletions

View File

@ -17,5 +17,5 @@ define('SALT', '9tvsh55d*s');
/* Max amount of accounts per IP */ /* Max amount of accounts per IP */
define('REGS_PER_IP', 2); define('REGS_PER_IP', 2);
/* Do not change this */ /* Which API to use, 0 for CustomSkinLoader API, 1 for UniSkinAPI */
define('DIR', dirname(__FILE__)); define('API_TYPE', 0);

13
get.php
View File

@ -3,17 +3,18 @@
* @Author: prpr * @Author: prpr
* @Date: 2016-02-02 20:56:42 * @Date: 2016-02-02 20:56:42
* @Last Modified by: prpr * @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__); $dir = dirname(__FILE__);
require "$dir/includes/autoload.inc.php"; require "$dir/includes/autoload.inc.php";
require "$dir/config.php";
if (isset($_GET['type']) && isset($_GET['uname'])) { if (isset($_GET['type']) && isset($_GET['uname'])) {
$user = new user($_GET['uname']); $user = new user($_GET['uname']);
if (!$user->is_registered) utils::raise(1, 'Non-existent user.'); 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_modified_since = isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) ? strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) : null;
if ($_GET['type'] == "skin" || $_GET['type'] == "cape") { if ($_GET['type'] == "skin" || $_GET['type'] == "cape") {
@ -23,7 +24,11 @@ if (isset($_GET['type']) && isset($_GET['uname'])) {
echo $user->getBinaryTexture($_GET['type']); echo $user->getBinaryTexture($_GET['type']);
} }
} else if ($_GET['type'] == "json") { } 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 { } else {
utils::raise(1, 'Illegal parameters.'); utils::raise(1, 'Illegal parameters.');
} }

View File

@ -3,7 +3,7 @@
* @Author: printempw * @Author: printempw
* @Date: 2016-01-16 23:01:33 * @Date: 2016-01-16 23:01:33
* @Last Modified by: prpr * @Last Modified by: prpr
* @Last Modified time: 2016-02-04 13:48:48 * @Last Modified time: 2016-02-04 20:38:42
*/ */
class user class user
@ -121,15 +121,23 @@ class user
return $this->db->select('username', $this->uname)['preference']; return $this->db->select('username', $this->uname)['preference'];
} }
public function getJsonProfile() { public function getJsonProfile($api_type) {
header('Content-type: application/json'); header('Content-type: application/json');
if ($this->is_registered) { if ($this->is_registered) {
$json['player_name'] = $this->uname; if ($api_type == 0 || $api_type == 1) {
$json['last_update'] = $this->getLastModified(); $json[($api_type == 0) ? 'username' : 'player_name'] = $this->uname;
$preference = $this->getPreference(); $model = $this->getPreference();
$json['model_preference'] = [$preference]; $sec_model = ($model == 'default') ? 'slim' : 'default';
$json['skins'][$preference] = $this->getTexture('skin'); if ($api_type == 1) {
$json['cape'] = $this->getTexture('cape'); $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 { } else {
$json['errno'] = 1; $json['errno'] = 1;
$json['msg'] = "Non-existent user."; $json['msg'] = "Non-existent user.";