2016-09-06 15:26:39 +05:30
|
|
|
<?php
|
|
|
|
namespace common\models;
|
|
|
|
|
|
|
|
use common\components\SkinSystem\Api as SkinSystemApi;
|
2016-11-01 22:06:39 +05:30
|
|
|
use DateInterval;
|
|
|
|
use DateTime;
|
2016-09-06 15:26:39 +05:30
|
|
|
|
|
|
|
class Textures {
|
|
|
|
|
|
|
|
public $displayElyMark = true;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var Account
|
|
|
|
*/
|
|
|
|
protected $account;
|
|
|
|
|
|
|
|
public function __construct(Account $account) {
|
|
|
|
$this->account = $account;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getMinecraftResponse() {
|
|
|
|
$response = [
|
|
|
|
'name' => $this->account->username,
|
|
|
|
'id' => str_replace('-', '', $this->account->uuid),
|
|
|
|
'properties' => [
|
|
|
|
[
|
|
|
|
'name' => 'textures',
|
|
|
|
'signature' => 'Cg==',
|
|
|
|
'value' => $this->getTexturesValue(),
|
|
|
|
],
|
|
|
|
],
|
|
|
|
];
|
|
|
|
|
|
|
|
if ($this->displayElyMark) {
|
|
|
|
$response['ely'] = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $response;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getTexturesValue($encrypted = true) {
|
|
|
|
$array = [
|
2016-11-01 22:06:39 +05:30
|
|
|
'timestamp' => (new DateTime())->add(new DateInterval('P2D'))->getTimestamp(),
|
2016-09-06 15:26:39 +05:30
|
|
|
'profileId' => str_replace('-', '', $this->account->uuid),
|
|
|
|
'profileName' => $this->account->username,
|
|
|
|
'textures' => $this->getTextures(),
|
|
|
|
];
|
|
|
|
|
|
|
|
if ($this->displayElyMark) {
|
|
|
|
$array['ely'] = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!$encrypted) {
|
|
|
|
return $array;
|
|
|
|
} else {
|
2016-11-01 22:06:39 +05:30
|
|
|
return static::encrypt($array);
|
2016-09-06 15:26:39 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getTextures() {
|
|
|
|
$api = new SkinSystemApi();
|
|
|
|
return $api->textures($this->account->username);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function encrypt(array $data) {
|
|
|
|
return base64_encode(stripcslashes(json_encode($data)));
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function decrypt($string, $assoc = true) {
|
|
|
|
return json_decode(base64_decode($string), $assoc);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|