From c6fd0b55a67ba5836dc2ce96289a02ed14c7678d Mon Sep 17 00:00:00 2001 From: printempw Date: Tue, 2 Feb 2016 21:34:07 +0800 Subject: [PATCH] fix some shit --- get.php | 11 ++++++----- includes/user.class.php | 12 +++++++++--- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/get.php b/get.php index 39c1daa1..ec701c29 100644 --- a/get.php +++ b/get.php @@ -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.'); diff --git a/includes/user.class.php b/includes/user.class.php index 11959d4c..4e9d49ae 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-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();