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 * @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-02 21:20:29 * @Last Modified time: 2016-02-02 21:33:12
*/ */
$dir = dirname(__FILE__); $dir = dirname(__FILE__);
@ -11,16 +11,17 @@ require "$dir/includes/autoload.inc.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.');
if ($_GET['type'] == "skin") { if ($_GET['type'] == "skin") {
header('Content-Type: image/png');
echo $user->getBinaryTexture('skin'); echo $user->getBinaryTexture('skin');
} else if ($_GET['type'] == "cape") { } else if ($_GET['type'] == "cape") {
header('Content-Type: image/png');
echo $user->getBinaryTexture('cape'); echo $user->getBinaryTexture('cape');
} else { } else if ($_GET['type'] == "json") {
header('Content-type: application/json');
echo $user->getJsonProfile(); echo $user->getJsonProfile();
} else {
utils::raise(1, 'Illegal parameters.');
} }
} 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-01-22 15:47:36 * @Last Modified time: 2016-02-02 21:31:36
*/ */
class user { class user {
@ -68,8 +68,13 @@ class user {
public function getBinaryTexture($type) { public function getBinaryTexture($type) {
$filename = "./textures/".$this->getTexture($type); $filename = "./textures/".$this->getTexture($type);
$data = fread(fopen($filename, 'r'), filesize($filename)); if (file_exists($filename)) {
return $data; 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) { public function setTexture($type, $file) {
@ -96,6 +101,7 @@ class user {
} }
public function getJsonProfile() { public function getJsonProfile() {
header('Content-type: application/json');
if ($this->is_registered) { if ($this->is_registered) {
$json['player_name'] = $this->uname; $json['player_name'] = $this->uname;
$preference = $this->getPreference(); $preference = $this->getPreference();