mirror of
https://github.com/elyby/accounts.git
synced 2025-05-31 14:11:46 +05:30
Добавлена логика HasJoined для сервера авторизации Minecraft
Исправлена ошибка в JoinForm Добавлено базовое API для общения с сервером системы скинов
This commit is contained in:
29
common/components/SkinSystem/Api.php
Normal file
29
common/components/SkinSystem/Api.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
namespace common\components\SkinSystem;
|
||||
|
||||
use GuzzleHttp\Client as GuzzleClient;
|
||||
use Yii;
|
||||
|
||||
class Api {
|
||||
|
||||
const BASE_DOMAIN = 'http://skinsystem.ely.by';
|
||||
|
||||
public function textures($username) : array {
|
||||
$response = $this->getClient()->get($this->getBuildUrl('/textures/' . $username));
|
||||
$textures = json_decode($response->getBody(), true);
|
||||
|
||||
return $textures;
|
||||
}
|
||||
|
||||
protected function getBuildUrl(string $url) : string {
|
||||
return self::BASE_DOMAIN . $url;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return GuzzleClient
|
||||
*/
|
||||
protected function getClient() : GuzzleClient {
|
||||
return Yii::$app->guzzle;
|
||||
}
|
||||
|
||||
}
|
@@ -23,6 +23,9 @@ return [
|
||||
'amqp' => [
|
||||
'class' => \common\components\RabbitMQ\Component::class,
|
||||
],
|
||||
'guzzle' => [
|
||||
'class' => \GuzzleHttp\Client::class,
|
||||
],
|
||||
],
|
||||
'aliases' => [
|
||||
'@bower' => '@vendor/bower-asset',
|
||||
|
71
common/models/Textures.php
Normal file
71
common/models/Textures.php
Normal file
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
namespace common\models;
|
||||
|
||||
use common\components\SkinSystem\Api as SkinSystemApi;
|
||||
|
||||
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 = [
|
||||
'timestamp' => time() + 60 * 60 * 24 * 2,
|
||||
'profileId' => str_replace('-', '', $this->account->uuid),
|
||||
'profileName' => $this->account->username,
|
||||
'textures' => $this->getTextures(),
|
||||
];
|
||||
|
||||
if ($this->displayElyMark) {
|
||||
$array['ely'] = true;
|
||||
}
|
||||
|
||||
if (!$encrypted) {
|
||||
return $array;
|
||||
} else {
|
||||
return $this->encrypt($array);
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user