2015-01-29 01:50:29 +05:30
|
|
|
|
<?php
|
|
|
|
|
|
2015-04-05 02:41:42 +05:30
|
|
|
|
define('ENCODING', 'UTF-8');
|
2015-02-07 23:33:07 +05:30
|
|
|
|
|
2015-01-29 01:50:29 +05:30
|
|
|
|
$app->get('/skins/{nickname}', function ($nickname) use ($app) {
|
2015-10-15 16:31:23 +05:30
|
|
|
|
// $systemVersion = $app->request->get('version', 'int');
|
|
|
|
|
// $minecraftVersion = $app->request->get('minecraft_version', 'string');
|
2015-01-29 01:50:29 +05:30
|
|
|
|
|
|
|
|
|
// На всякий случай проверка на наличие .png для файла
|
2015-04-05 02:41:42 +05:30
|
|
|
|
if (strrpos($nickname, '.png') != -1) {
|
|
|
|
|
$nickname = explode('.', $nickname)[0];
|
2015-01-29 01:50:29 +05:30
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// TODO: восстановить функцию деградации скинов
|
|
|
|
|
|
2015-10-15 16:31:23 +05:30
|
|
|
|
$skin = Skins::findByNickname($nickname);
|
2015-04-05 02:41:42 +05:30
|
|
|
|
if (!$skin || $skin->skinId == 0) {
|
|
|
|
|
return $app->response->redirect('http://skins.minecraft.net/MinecraftSkins/' . $nickname . '.png', true);
|
|
|
|
|
}
|
2015-01-29 01:50:29 +05:30
|
|
|
|
|
|
|
|
|
return $app->response->redirect($skin->url);
|
2015-04-05 02:41:42 +05:30
|
|
|
|
})->setName('skinSystem');
|
2015-01-29 01:50:29 +05:30
|
|
|
|
|
2015-01-29 15:50:44 +05:30
|
|
|
|
$app->get('/cloaks/{nickname}', function ($nickname) use ($app) {
|
|
|
|
|
// На всякий случай проверка на наличие .png для файла
|
2015-04-05 02:41:42 +05:30
|
|
|
|
if (strrpos($nickname, '.png') != -1) {
|
|
|
|
|
$nickname = explode('.', $nickname)[0];
|
2015-01-29 15:50:44 +05:30
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $app->response->redirect('http://skins.minecraft.net/MinecraftCloaks/'.$nickname.'.png');
|
|
|
|
|
});
|
|
|
|
|
|
2015-04-05 02:41:42 +05:30
|
|
|
|
$app->get('/textures/{nickname}', function($nickname) use ($app) {
|
2015-10-15 16:31:23 +05:30
|
|
|
|
$skin = Skins::findByNickname($nickname);
|
2015-01-31 20:28:45 +05:30
|
|
|
|
if ($skin && $skin->skinId != 0) {
|
|
|
|
|
$url = $skin->url;
|
|
|
|
|
$hash = $skin->hash;
|
|
|
|
|
} else {
|
2015-04-05 02:41:42 +05:30
|
|
|
|
$url = 'http://skins.minecraft.net/MinecraftSkins/'.$nickname.'.png';
|
2015-10-15 16:31:23 +05:30
|
|
|
|
$hash = md5('non-ely-' . mktime(date('H'), 0, 0) . '-' . $nickname);
|
2015-01-31 20:28:45 +05:30
|
|
|
|
}
|
|
|
|
|
|
2015-10-15 16:31:23 +05:30
|
|
|
|
// TODO: в authserver.ely.by есть готовый класс для работы с форматом текстур. Так что если мы его вынесем в
|
|
|
|
|
// common library, то нужно будет заменить его здесь
|
|
|
|
|
|
|
|
|
|
$textures = [
|
|
|
|
|
'SKIN' => [
|
2015-01-31 20:28:45 +05:30
|
|
|
|
'url' => $url,
|
|
|
|
|
'hash' => $hash,
|
2015-10-15 16:31:23 +05:30
|
|
|
|
],
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
if ($skin && $skin->isSlim) {
|
|
|
|
|
$textures['SKIN']['metadata']['model'] = 'slim';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $app->response->setContentType('application/json')->setJsonContent($textures);
|
2015-01-31 20:28:45 +05:30
|
|
|
|
});
|
|
|
|
|
|
2015-04-05 02:41:42 +05:30
|
|
|
|
$app->post('/system/setSkin', function() use ($app) {
|
2015-01-29 15:50:44 +05:30
|
|
|
|
$headers = getallheaders();
|
2015-04-05 02:41:42 +05:30
|
|
|
|
if (!array_key_exists('X-Ely-key', $headers) || $headers['X-Ely-key'] != '43fd2ce61b3f5704dfd729c1f2d6ffdb') {
|
|
|
|
|
return $app->response->setStatusCode(403, 'Forbidden')->setContent('Хорошая попытка, мерзкий хакер.');
|
|
|
|
|
}
|
2015-01-29 15:50:44 +05:30
|
|
|
|
|
2015-01-29 01:50:29 +05:30
|
|
|
|
$request = $app->request;
|
2015-04-05 02:56:35 +05:30
|
|
|
|
$nickname = mb_convert_case($request->getPost('nickname', 'string'), MB_CASE_LOWER, ENCODING);
|
|
|
|
|
|
2015-10-15 16:31:23 +05:30
|
|
|
|
$skin = Skins::findByNickname($nickname);
|
2015-01-29 01:50:29 +05:30
|
|
|
|
if (!$skin) {
|
|
|
|
|
$skin = new Skins();
|
2015-04-05 02:56:35 +05:30
|
|
|
|
$skin->nickname = $nickname;
|
2015-01-29 01:50:29 +05:30
|
|
|
|
}
|
|
|
|
|
|
2015-04-05 02:56:35 +05:30
|
|
|
|
$skin->userId = (int) $request->getPost('userId', 'int');
|
2015-04-05 02:41:42 +05:30
|
|
|
|
$skin->skinId = (int) $request->getPost('skinId', 'int');
|
|
|
|
|
$skin->hash = $request->getPost('hash', 'string');
|
|
|
|
|
$skin->is1_8 = (bool) $request->getPost('is1_8', 'int');
|
|
|
|
|
$skin->isSlim = (bool) $request->getPost('isSlim', 'int');
|
|
|
|
|
$skin->url = $request->getPost('url', 'string');
|
|
|
|
|
|
2015-10-15 16:31:23 +05:30
|
|
|
|
return $app->view->setContent($skin->save() ? 'OK' : 'ERROR');
|
2015-01-29 01:50:29 +05:30
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
$app->notFound(function () use ($app) {
|
|
|
|
|
$app->response
|
2015-04-05 02:41:42 +05:30
|
|
|
|
->setStatusCode(404, 'Not Found')
|
2015-01-29 15:50:44 +05:30
|
|
|
|
->setContent('Not Found<br /> <a href="http://ely.by">Система скинов Ely.by</a>.')
|
2015-01-29 01:50:29 +05:30
|
|
|
|
->send();
|
|
|
|
|
});
|