added inspection for occupied texture
This commit is contained in:
parent
bf65bee5e6
commit
c4339e37de
|
|
@ -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: printempw
|
* @Last Modified by: printempw
|
||||||
* @Last Modified time: 2016-03-26 20:38:36
|
* @Last Modified time: 2016-03-26 21:41:40
|
||||||
*/
|
*/
|
||||||
|
|
||||||
use Database\Database;
|
use Database\Database;
|
||||||
|
|
@ -71,27 +71,22 @@ class User
|
||||||
}
|
}
|
||||||
|
|
||||||
public function unRegister() {
|
public function unRegister() {
|
||||||
if ($this->getTexture('steve') != "")
|
$skin_type_map = ["steve", "alex", "cape"];
|
||||||
Utils::remove("./textures/".$this->getTexture('steve'));
|
for ($i = 0; $i <= 2; $i++) {
|
||||||
if ($this->getTexture('alex') != "")
|
if ($this->getTexture($skin_type_map[$i]) != "" && !Utils::checkTextureOccupied($this->getTexture($skin_type_map[$i])))
|
||||||
Utils::remove("./textures/".$this->getTexture('alex'));
|
Utils::remove("./textures/".$this->getTexture($skin_type_map[$i]));
|
||||||
if ($this->getTexture('cape') != "")
|
}
|
||||||
Utils::remove("./textures/".$this->getTexture('cape'));
|
|
||||||
return $this->db->delete($this->uname);
|
return $this->db->delete($this->uname);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function reset() {
|
public function reset() {
|
||||||
for ($i = 1; $i <= 3; $i++) {
|
$skin_type_map = ["steve", "alex", "cape"];
|
||||||
switch($i) {
|
for ($i = 0; $i <= 2; $i++) {
|
||||||
case 1: $type = "steve"; break;
|
if ($this->getTexture($skin_type_map[$i]) != "" && !Utils::checkTextureOccupied($this->getTexture($skin_type_map[$i])))
|
||||||
case 2: $type = "alex"; break;
|
Utils::remove("./textures/".$this->getTexture($skin_type_map[$i]));
|
||||||
case 3: $type = "cape"; break;
|
$this->db->update($this->uname, 'hash_'.$skin_type_map[$i], '');
|
||||||
}
|
|
||||||
if ($this->getTexture($type) != "")
|
|
||||||
Utils::remove("./textures/".$this->getTexture($type));
|
|
||||||
$this->db->update($this->uname, 'hash_'.$type, '');
|
|
||||||
}
|
}
|
||||||
$this->db->update($this->uname, 'preference', 'default');
|
return $this->db->update($this->uname, 'preference', 'default');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -149,7 +144,7 @@ class User
|
||||||
|
|
||||||
public function setTexture($type, $file) {
|
public function setTexture($type, $file) {
|
||||||
// Remove the original texture first
|
// Remove the original texture first
|
||||||
if ($this->getTexture($type) != "")
|
if ($this->getTexture($type) != "" && !Utils::checkTextureOccupied($this->getTexture($type)))
|
||||||
Utils::remove("./textures/".$this->getTexture($type));
|
Utils::remove("./textures/".$this->getTexture($type));
|
||||||
$this->updateLastModified();
|
$this->updateLastModified();
|
||||||
$hash = Utils::upload($file);
|
$hash = Utils::upload($file);
|
||||||
|
|
@ -205,7 +200,7 @@ class User
|
||||||
}
|
}
|
||||||
|
|
||||||
public function updateLastModified() {
|
public function updateLastModified() {
|
||||||
// http://stackoverflow.com/questions/2215354/php-date-format-when-inserting-into-datetime-in-mysql
|
// @see http://stackoverflow.com/questions/2215354/php-date-format-when-inserting-into-datetime-in-mysql
|
||||||
return $this->db->update($this->uname, 'last_modified', date("Y-m-d H:i:s"));
|
return $this->db->update($this->uname, 'last_modified', date("Y-m-d H:i:s"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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: printempw
|
* @Last Modified by: printempw
|
||||||
* @Last Modified time: 2016-03-26 20:32:03
|
* @Last Modified time: 2016-03-26 21:35:53
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class Utils
|
class Utils
|
||||||
|
|
@ -161,4 +161,23 @@ class Utils
|
||||||
return $dest;
|
return $dest;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if given texture is occupied
|
||||||
|
*
|
||||||
|
* @param string $hash
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public static function checkTextureOccupied($hash) {
|
||||||
|
$db = new Database\Database();
|
||||||
|
if ($db->getNumRows('hash_steve', $hash) > 1) {
|
||||||
|
return true;
|
||||||
|
} elseif ($db->getNumRows('hash_alex', $hash) > 1) {
|
||||||
|
return true;
|
||||||
|
} elseif ($db->getNumRows('hash_cape', $hash) > 1) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
// finally if given texture is not used by anyone else
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user