mirror of
https://github.com/elyby/chrly.git
synced 2024-12-22 21:19:55 +05:30
Исправлен формат массива с текстурами, освежён код проекта
This commit is contained in:
parent
800523aef2
commit
10be2a66ca
54
app.php
54
app.php
@ -3,8 +3,8 @@
|
||||
define('ENCODING', 'UTF-8');
|
||||
|
||||
$app->get('/skins/{nickname}', function ($nickname) use ($app) {
|
||||
$systemVersion = $app->request->get('version', 'int');
|
||||
$minecraftVersion = $app->request->get('minecraft_version', 'string');
|
||||
// $systemVersion = $app->request->get('version', 'int');
|
||||
// $minecraftVersion = $app->request->get('minecraft_version', 'string');
|
||||
|
||||
// На всякий случай проверка на наличие .png для файла
|
||||
if (strrpos($nickname, '.png') != -1) {
|
||||
@ -13,10 +13,7 @@ $app->get('/skins/{nickname}', function ($nickname) use ($app) {
|
||||
|
||||
// TODO: восстановить функцию деградации скинов
|
||||
|
||||
$skin = Skins::findFirst(array(array(
|
||||
'nickname' => mb_convert_case($nickname, MB_CASE_LOWER, ENCODING)
|
||||
)));
|
||||
|
||||
$skin = Skins::findByNickname($nickname);
|
||||
if (!$skin || $skin->skinId == 0) {
|
||||
return $app->response->redirect('http://skins.minecraft.net/MinecraftSkins/' . $nickname . '.png', true);
|
||||
}
|
||||
@ -34,33 +31,30 @@ $app->get('/cloaks/{nickname}', function ($nickname) use ($app) {
|
||||
});
|
||||
|
||||
$app->get('/textures/{nickname}', function($nickname) use ($app) {
|
||||
$skin = Skins::findFirst(array(array(
|
||||
'nickname' => mb_convert_case($nickname, MB_CASE_LOWER, ENCODING)
|
||||
)));
|
||||
|
||||
$skin = Skins::findByNickname($nickname);
|
||||
if ($skin && $skin->skinId != 0) {
|
||||
$url = $skin->url;
|
||||
$hash = $skin->hash;
|
||||
} else {
|
||||
$url = 'http://skins.minecraft.net/MinecraftSkins/'.$nickname.'.png';
|
||||
$hash = md5('non-ely-'.mktime(date('H'), 0, 0).'-'.$nickname);
|
||||
$hash = md5('non-ely-' . mktime(date('H'), 0, 0) . '-' . $nickname);
|
||||
}
|
||||
|
||||
$textures = array(
|
||||
'SKIN' => array(
|
||||
// TODO: в authserver.ely.by есть готовый класс для работы с форматом текстур. Так что если мы его вынесем в
|
||||
// common library, то нужно будет заменить его здесь
|
||||
|
||||
$textures = [
|
||||
'SKIN' => [
|
||||
'url' => $url,
|
||||
'hash' => $hash,
|
||||
'metadata' => array(
|
||||
'model' => ($skin && $skin->isSlim) ? 'slim' : 'default'
|
||||
)
|
||||
),
|
||||
'CAPE' => array(
|
||||
'url' => '',
|
||||
'hash' => ''
|
||||
)
|
||||
);
|
||||
],
|
||||
];
|
||||
|
||||
return $app->response->setJsonContent($textures);
|
||||
if ($skin && $skin->isSlim) {
|
||||
$textures['SKIN']['metadata']['model'] = 'slim';
|
||||
}
|
||||
|
||||
return $app->response->setContentType('application/json')->setJsonContent($textures);
|
||||
});
|
||||
|
||||
$app->post('/system/setSkin', function() use ($app) {
|
||||
@ -72,10 +66,7 @@ $app->post('/system/setSkin', function() use ($app) {
|
||||
$request = $app->request;
|
||||
$nickname = mb_convert_case($request->getPost('nickname', 'string'), MB_CASE_LOWER, ENCODING);
|
||||
|
||||
$skin = Skins::findFirst(array(array(
|
||||
'nickname' => $nickname
|
||||
)));
|
||||
|
||||
$skin = Skins::findByNickname($nickname);
|
||||
if (!$skin) {
|
||||
$skin = new Skins();
|
||||
$skin->nickname = $nickname;
|
||||
@ -88,16 +79,9 @@ $app->post('/system/setSkin', function() use ($app) {
|
||||
$skin->isSlim = (bool) $request->getPost('isSlim', 'int');
|
||||
$skin->url = $request->getPost('url', 'string');
|
||||
|
||||
if ($skin->save()) {
|
||||
echo 'OK';
|
||||
} else {
|
||||
echo 'ERROR';
|
||||
}
|
||||
return $app->view->setContent($skin->save() ? 'OK' : 'ERROR');
|
||||
});
|
||||
|
||||
/**
|
||||
* Not found handler
|
||||
*/
|
||||
$app->notFound(function () use ($app) {
|
||||
$app->response
|
||||
->setStatusCode(404, 'Not Found')
|
||||
|
@ -1,15 +1,15 @@
|
||||
<?php
|
||||
|
||||
return new \Phalcon\Config(array(
|
||||
'mongo' => array(
|
||||
'host' => 'localhost',
|
||||
'port' => 27017,
|
||||
'username' => '',
|
||||
'password' => '',
|
||||
'dbname' => 'ely_skins',
|
||||
),
|
||||
'application' => array(
|
||||
'modelsDir' => __DIR__ . '/../models/',
|
||||
'baseUri' => '/',
|
||||
)
|
||||
));
|
||||
return new \Phalcon\Config([
|
||||
'mongo' => [
|
||||
'host' => 'localhost',
|
||||
'port' => 27017,
|
||||
'username' => '',
|
||||
'password' => '',
|
||||
'dbname' => 'ely_skins',
|
||||
],
|
||||
'application' => [
|
||||
'modelsDir' => __DIR__ . '/../models/',
|
||||
'baseUri' => '/',
|
||||
]
|
||||
]);
|
||||
|
@ -1,4 +1,7 @@
|
||||
<?php
|
||||
/**
|
||||
* @var \Phalcon\Config $config
|
||||
*/
|
||||
|
||||
$loader = new \Phalcon\Loader();
|
||||
|
||||
|
@ -1,13 +1,17 @@
|
||||
<?php
|
||||
/**
|
||||
* @var \Phalcon\Config $config
|
||||
*/
|
||||
|
||||
use Phalcon\Mvc\Collection\Manager;
|
||||
use Phalcon\Mvc\View;
|
||||
use Phalcon\Mvc\Url as UrlResolver;
|
||||
use Phalcon\DI\FactoryDefault;
|
||||
|
||||
$di = new FactoryDefault();
|
||||
|
||||
$di->set("view", function () {
|
||||
$view = new \Phalcon\Mvc\View();
|
||||
$di->set('view', function () {
|
||||
$view = new View();
|
||||
$view->disable();
|
||||
|
||||
return $view;
|
||||
@ -16,35 +20,27 @@ $di->set("view", function () {
|
||||
/**
|
||||
* The URL component is used to generate all kind of urls in the application
|
||||
*/
|
||||
$di->set("url", function () use ($config) {
|
||||
$di->set('url', function () use ($config) {
|
||||
$url = new UrlResolver();
|
||||
$url->setBaseUri($config->application->baseUri);
|
||||
|
||||
return $url;
|
||||
});
|
||||
|
||||
$di->set("mongo", function() use ($config) {
|
||||
if (!$config->mongo->username || !$config->mongo->password) {
|
||||
$mongo = new MongoClient(
|
||||
"mongodb://".
|
||||
$config->mongo->host.":".
|
||||
$config->mongo->port
|
||||
);
|
||||
} else {
|
||||
$mongo = new MongoClient(
|
||||
"mongodb://".
|
||||
$config->mongo->username.":".
|
||||
$config->mongo->password."@".
|
||||
$config->mongo->host.":".
|
||||
$config->mongo->port
|
||||
);
|
||||
$di->set('mongo', function() use ($config) {
|
||||
/** @var StdClass $mongoConfig */
|
||||
$mongoConfig = $config->mongo;
|
||||
$connectionString = 'mongodb://';
|
||||
if ($mongoConfig->username && $mongoConfig->password) {
|
||||
$connectionString .= "{$mongoConfig->username}:{$mongoConfig->password}@";
|
||||
}
|
||||
|
||||
return $mongo->selectDb($config->mongo->dbname);
|
||||
$connectionString .= $mongoConfig->host . ':' . $mongoConfig->port;
|
||||
$mongo = new MongoClient($connectionString);
|
||||
|
||||
return $mongo->selectDb($mongoConfig->dbname);
|
||||
});
|
||||
|
||||
//Registering the collectionManager service
|
||||
$di->setShared('collectionManager', function() {
|
||||
$modelsManager = new Phalcon\Mvc\Collection\Manager();
|
||||
return $modelsManager;
|
||||
});
|
||||
return new Manager();
|
||||
});
|
||||
|
@ -3,11 +3,10 @@
|
||||
use Phalcon\Mvc\Collection;
|
||||
|
||||
/**
|
||||
* @method static Skins findFirst()
|
||||
*
|
||||
* @property string $id
|
||||
*/
|
||||
class Skins extends Collection {
|
||||
|
||||
public $_id;
|
||||
public $userId;
|
||||
public $nickname;
|
||||
@ -22,6 +21,19 @@ class Skins extends Collection {
|
||||
}
|
||||
|
||||
public function getSource() {
|
||||
return "skins";
|
||||
return 'skins';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $nickname
|
||||
* @return bool|Skins
|
||||
*/
|
||||
public static function findByNickname($nickname) {
|
||||
return static::findFirst([
|
||||
[
|
||||
'nickname' => mb_convert_case($nickname, MB_CASE_LOWER, ENCODING),
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,16 +1,18 @@
|
||||
<?php
|
||||
|
||||
use Phalcon\Mvc\Micro;
|
||||
|
||||
error_reporting(E_ALL);
|
||||
|
||||
try {
|
||||
/** @var \Phalcon\Config $config */
|
||||
$config = include __DIR__ . "/../config/config.php";
|
||||
$config = include __DIR__ . '/../config/config.php';
|
||||
/** @var \Phalcon\Loader $loader */
|
||||
include __DIR__ . '/../config/loader.php';
|
||||
/** @var Phalcon\DI\FactoryDefault $di */
|
||||
include __DIR__ . '/../config/services.php';
|
||||
|
||||
$app = new \Phalcon\Mvc\Micro($di);
|
||||
$app = new Micro($di);
|
||||
include __DIR__ . '/../app.php';
|
||||
|
||||
$app->handle();
|
||||
|
Loading…
Reference in New Issue
Block a user