fix some shit

This commit is contained in:
printempw 2016-02-02 21:34:07 +08:00
parent 0bb571e6fd
commit c6fd0b55a6
2 changed files with 15 additions and 8 deletions

11
get.php
View File

@ -3,7 +3,7 @@
* @Author: prpr
* @Date: 2016-02-02 20:56:42
* @Last Modified by: prpr
* @Last Modified time: 2016-02-02 21:20:29
* @Last Modified time: 2016-02-02 21:33:12
*/
$dir = dirname(__FILE__);
@ -11,16 +11,17 @@ require "$dir/includes/autoload.inc.php";
if (isset($_GET['type']) && isset($_GET['uname'])) {
$user = new user($_GET['uname']);
if (!$user->is_registered) utils::raise(1, 'Non-existent user.');
if ($_GET['type'] == "skin") {
header('Content-Type: image/png');
echo $user->getBinaryTexture('skin');
} else if ($_GET['type'] == "cape") {
header('Content-Type: image/png');
echo $user->getBinaryTexture('cape');
} else {
header('Content-type: application/json');
} else if ($_GET['type'] == "json") {
echo $user->getJsonProfile();
} else {
utils::raise(1, 'Illegal parameters.');
}
} else {
utils::raise(1, 'Illegal parameters.');

View File

@ -3,7 +3,7 @@
* @Author: printempw
* @Date: 2016-01-16 23:01:33
* @Last Modified by: prpr
* @Last Modified time: 2016-01-22 15:47:36
* @Last Modified time: 2016-02-02 21:31:36
*/
class user {
@ -68,8 +68,13 @@ class user {
public function getBinaryTexture($type) {
$filename = "./textures/".$this->getTexture($type);
$data = fread(fopen($filename, 'r'), filesize($filename));
return $data;
if (file_exists($filename)) {
header('Content-Type: image/png');
$data = fread(fopen($filename, 'r'), filesize($filename));
return $data;
} else {
utils::raise(-1, 'Texture no longer exists.');
}
}
public function setTexture($type, $file) {
@ -96,6 +101,7 @@ class user {
}
public function getJsonProfile() {
header('Content-type: application/json');
if ($this->is_registered) {
$json['player_name'] = $this->uname;
$preference = $this->getPreference();