2016-01-16 22:54:24 +08:00
|
|
|
<?php
|
2016-01-17 00:15:26 +08:00
|
|
|
/**
|
|
|
|
* @Author: printempw
|
|
|
|
* @Date: 2016-01-16 23:01:33
|
|
|
|
* @Last Modified by: prpr
|
2016-01-22 14:54:12 +08:00
|
|
|
* @Last Modified time: 2016-01-22 14:52:44
|
2016-01-17 00:15:26 +08:00
|
|
|
*/
|
2016-01-16 22:54:24 +08:00
|
|
|
|
|
|
|
class user {
|
|
|
|
private $uname = "";
|
|
|
|
private $passwd = "";
|
|
|
|
private $token = "";
|
|
|
|
|
|
|
|
public $is_registered = false;
|
|
|
|
public $is_admin = false;
|
|
|
|
|
|
|
|
function __construct($uname) {
|
2016-01-22 14:47:18 +08:00
|
|
|
$this->uname = utils::convertString($uname);
|
|
|
|
if (utils::select('username', $this->uname)['uid'] == 1) {
|
|
|
|
$this->is_admin = true;
|
2016-01-16 22:54:24 +08:00
|
|
|
}
|
2016-01-22 14:47:18 +08:00
|
|
|
if (utils::select('username', $this->uname)['password'] != "") {
|
|
|
|
$this->passwd = utils::select('username', $this->uname)['password'];
|
|
|
|
$this->is_registered = true;
|
|
|
|
$this->token = md5($this->uname . $this->passwd.SALT);
|
2016-01-16 22:54:24 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function checkPasswd($raw_passwd) {
|
2016-01-22 14:47:18 +08:00
|
|
|
if (md5($raw_passwd) == $this->passwd) {
|
2016-01-16 22:54:24 +08:00
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getToken() {
|
2016-01-22 14:47:18 +08:00
|
|
|
return $this->token;
|
2016-01-16 22:54:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public function register($passwd, $ip) {
|
2016-01-17 11:35:12 +08:00
|
|
|
if (utils::insert(array(
|
2016-01-22 14:47:18 +08:00
|
|
|
"uname" => $this->uname,
|
2016-01-17 11:35:12 +08:00
|
|
|
"passwd" => $passwd,
|
|
|
|
"ip" => $ip
|
2016-01-17 12:14:19 +08:00
|
|
|
)))
|
|
|
|
{
|
2016-01-16 22:54:24 +08:00
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getTexture($type) {
|
|
|
|
if ($type == "skin") {
|
2016-01-22 14:47:18 +08:00
|
|
|
return utils::select('username', $this->uname)['skin_hash'];
|
2016-01-16 22:54:24 +08:00
|
|
|
} else if ($type == "cape") {
|
2016-01-22 14:47:18 +08:00
|
|
|
return utils::select('username', $this->uname)['cape_hash'];
|
2016-01-16 22:54:24 +08:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-01-22 14:47:18 +08:00
|
|
|
public function getBinaryTexture($type) {
|
|
|
|
$filename = "./textures/".$this->getTexture($type);
|
|
|
|
$data = fread(fopen($filename, 'r'), filesize($filename));
|
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
|
2016-01-16 22:54:24 +08:00
|
|
|
public function setTexture($type, $file) {
|
|
|
|
$hash = utils::upload($file);
|
|
|
|
if ($type == "skin") {
|
2016-01-21 22:36:27 +08:00
|
|
|
// remove the original texture first
|
|
|
|
utils::remove("./textures/".$this->getTexture('skin'));
|
2016-01-22 14:47:18 +08:00
|
|
|
return utils::update($this->uname, 'skin_hash', $hash);
|
2016-01-16 22:54:24 +08:00
|
|
|
} else if ($type == "cape") {
|
2016-01-21 22:36:27 +08:00
|
|
|
utils::remove("./textures/".$this->getTexture('cape'));
|
2016-01-22 14:47:18 +08:00
|
|
|
return utils::update($this->uname, 'cape_hash', $hash);
|
2016-01-16 22:54:24 +08:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-01-22 14:54:12 +08:00
|
|
|
public function setPreference($type) {
|
|
|
|
return utils::update($this->uname, 'preference', $type);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getPreference() {
|
|
|
|
return utils::select('username', $this->uname)['preference'];
|
|
|
|
}
|
|
|
|
|
2016-01-22 14:47:18 +08:00
|
|
|
public function getJsonProfile() {
|
|
|
|
if ($this->is_registered) {
|
|
|
|
$json['player_name'] = $this->uname;
|
2016-01-22 14:54:12 +08:00
|
|
|
$preference = $this->getPreference();
|
|
|
|
$json['model_preference'] = [$preference];
|
|
|
|
$json['skins'][$preference] = $this->getTexture('skin');
|
2016-01-22 14:47:18 +08:00
|
|
|
$json['cape'] = $this->getTexture('cape');
|
|
|
|
} else {
|
|
|
|
$json['errno'] = 1;
|
|
|
|
$json['msg'] = "Non-existent user.";
|
|
|
|
}
|
|
|
|
return json_encode($json);
|
|
|
|
}
|
|
|
|
|
2016-01-16 22:54:24 +08:00
|
|
|
}
|
|
|
|
?>
|