2015-01-28 23:20:29 +03:00
|
|
|
|
<?php
|
|
|
|
|
|
2015-04-05 00:11:42 +03:00
|
|
|
|
define('ENCODING', 'UTF-8');
|
2015-02-07 21:03:07 +03:00
|
|
|
|
|
2015-01-28 23:20:29 +03:00
|
|
|
|
$app->get('/skins/{nickname}', function ($nickname) use ($app) {
|
2015-04-05 00:11:42 +03:00
|
|
|
|
$systemVersion = $app->request->get('version', 'int');
|
|
|
|
|
$minecraftVersion = $app->request->get('minecraft_version', 'string');
|
2015-01-28 23:20:29 +03:00
|
|
|
|
|
|
|
|
|
// На всякий случай проверка на наличие .png для файла
|
2015-04-05 00:11:42 +03:00
|
|
|
|
if (strrpos($nickname, '.png') != -1) {
|
|
|
|
|
$nickname = explode('.', $nickname)[0];
|
2015-01-28 23:20:29 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// TODO: восстановить функцию деградации скинов
|
|
|
|
|
|
|
|
|
|
$skin = Skins::findFirst(array(array(
|
2015-04-05 00:11:42 +03:00
|
|
|
|
'nickname' => mb_convert_case($nickname, MB_CASE_LOWER, ENCODING)
|
2015-01-28 23:20:29 +03:00
|
|
|
|
)));
|
|
|
|
|
|
2015-04-05 00:11:42 +03:00
|
|
|
|
if (!$skin || $skin->skinId == 0) {
|
|
|
|
|
return $app->response->redirect('http://skins.minecraft.net/MinecraftSkins/' . $nickname . '.png', true);
|
|
|
|
|
}
|
2015-01-28 23:20:29 +03:00
|
|
|
|
|
|
|
|
|
return $app->response->redirect($skin->url);
|
2015-04-05 00:11:42 +03:00
|
|
|
|
})->setName('skinSystem');
|
2015-01-28 23:20:29 +03:00
|
|
|
|
|
2015-01-29 13:20:44 +03:00
|
|
|
|
$app->get('/cloaks/{nickname}', function ($nickname) use ($app) {
|
|
|
|
|
// На всякий случай проверка на наличие .png для файла
|
2015-04-05 00:11:42 +03:00
|
|
|
|
if (strrpos($nickname, '.png') != -1) {
|
|
|
|
|
$nickname = explode('.', $nickname)[0];
|
2015-01-29 13:20:44 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $app->response->redirect('http://skins.minecraft.net/MinecraftCloaks/'.$nickname.'.png');
|
|
|
|
|
});
|
|
|
|
|
|
2015-04-05 00:11:42 +03:00
|
|
|
|
$app->get('/textures/{nickname}', function($nickname) use ($app) {
|
2015-01-31 17:58:45 +03:00
|
|
|
|
$skin = Skins::findFirst(array(array(
|
2015-04-05 00:11:42 +03:00
|
|
|
|
'nickname' => mb_convert_case($nickname, MB_CASE_LOWER, ENCODING)
|
2015-01-31 17:58:45 +03:00
|
|
|
|
)));
|
|
|
|
|
|
|
|
|
|
if ($skin && $skin->skinId != 0) {
|
|
|
|
|
$url = $skin->url;
|
|
|
|
|
$hash = $skin->hash;
|
|
|
|
|
} else {
|
2015-04-05 00:11:42 +03:00
|
|
|
|
$url = 'http://skins.minecraft.net/MinecraftSkins/'.$nickname.'.png';
|
|
|
|
|
$hash = md5('non-ely-'.mktime(date('H'), 0, 0).'-'.$nickname);
|
2015-01-31 17:58:45 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$textures = array(
|
|
|
|
|
'SKIN' => array(
|
|
|
|
|
'url' => $url,
|
|
|
|
|
'hash' => $hash,
|
|
|
|
|
'metadata' => array(
|
2015-04-05 00:11:42 +03:00
|
|
|
|
'model' => ($skin && $skin->isSlim) ? 'slim' : 'default'
|
2015-01-31 17:58:45 +03:00
|
|
|
|
)
|
|
|
|
|
),
|
|
|
|
|
'CAPE' => array(
|
|
|
|
|
'url' => '',
|
|
|
|
|
'hash' => ''
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
return $app->response->setJsonContent($textures);
|
|
|
|
|
});
|
|
|
|
|
|
2015-04-05 00:11:42 +03:00
|
|
|
|
$app->post('/system/setSkin', function() use ($app) {
|
2015-01-29 13:20:44 +03:00
|
|
|
|
$headers = getallheaders();
|
2015-04-05 00:11:42 +03:00
|
|
|
|
if (!array_key_exists('X-Ely-key', $headers) || $headers['X-Ely-key'] != '43fd2ce61b3f5704dfd729c1f2d6ffdb') {
|
|
|
|
|
return $app->response->setStatusCode(403, 'Forbidden')->setContent('Хорошая попытка, мерзкий хакер.');
|
|
|
|
|
}
|
2015-01-29 13:20:44 +03:00
|
|
|
|
|
2015-01-28 23:20:29 +03:00
|
|
|
|
$request = $app->request;
|
2015-04-05 00:26:35 +03:00
|
|
|
|
$nickname = mb_convert_case($request->getPost('nickname', 'string'), MB_CASE_LOWER, ENCODING);
|
|
|
|
|
|
2015-01-28 23:20:29 +03:00
|
|
|
|
$skin = Skins::findFirst(array(array(
|
2015-04-05 00:26:35 +03:00
|
|
|
|
'nickname' => $nickname
|
2015-01-28 23:20:29 +03:00
|
|
|
|
)));
|
|
|
|
|
|
|
|
|
|
if (!$skin) {
|
|
|
|
|
$skin = new Skins();
|
2015-04-05 00:26:35 +03:00
|
|
|
|
$skin->nickname = $nickname;
|
2015-01-28 23:20:29 +03:00
|
|
|
|
}
|
|
|
|
|
|
2015-04-05 00:26:35 +03:00
|
|
|
|
$skin->userId = (int) $request->getPost('userId', 'int');
|
2015-04-05 00:11:42 +03:00
|
|
|
|
$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');
|
|
|
|
|
|
|
|
|
|
if ($skin->save()) {
|
|
|
|
|
echo 'OK';
|
|
|
|
|
} else {
|
|
|
|
|
echo 'ERROR';
|
|
|
|
|
}
|
2015-01-28 23:20:29 +03:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Not found handler
|
|
|
|
|
*/
|
|
|
|
|
$app->notFound(function () use ($app) {
|
|
|
|
|
$app->response
|
2015-04-05 00:11:42 +03:00
|
|
|
|
->setStatusCode(404, 'Not Found')
|
2015-01-29 13:20:44 +03:00
|
|
|
|
->setContent('Not Found<br /> <a href="http://ely.by">Система скинов Ely.by</a>.')
|
2015-01-28 23:20:29 +03:00
|
|
|
|
->send();
|
|
|
|
|
});
|