Рефакторинг, удалён лишний метод /minecraft.php

This commit is contained in:
ErickSkrauch 2015-04-05 00:11:42 +03:00
parent 6b2fb1bf0d
commit 84cfe9afa0

110
app.php
View File

@ -1,48 +1,49 @@
<?php <?php
define('ENCODING', "UTF-8"); define('ENCODING', 'UTF-8');
$app->get('/skins/{nickname}', function ($nickname) use ($app) { $app->get('/skins/{nickname}', function ($nickname) use ($app) {
$systemVersion = $app->request->get("version", "int"); $systemVersion = $app->request->get('version', 'int');
$minecraftVersion = $app->request->get("minecraft_version", "string"); $minecraftVersion = $app->request->get('minecraft_version', 'string');
// На всякий случай проверка на наличие .png для файла // На всякий случай проверка на наличие .png для файла
if (strrpos($nickname, ".png") != -1) { if (strrpos($nickname, '.png') != -1) {
$nickname = explode(".", $nickname)[0]; $nickname = explode('.', $nickname)[0];
} }
// TODO: восстановить функцию деградации скинов // TODO: восстановить функцию деградации скинов
$skin = Skins::findFirst(array(array( $skin = Skins::findFirst(array(array(
"nickname" => mb_convert_case($nickname, MB_CASE_LOWER, ENCODING) 'nickname' => mb_convert_case($nickname, MB_CASE_LOWER, ENCODING)
))); )));
if (!$skin || $skin->skinId == 0) if (!$skin || $skin->skinId == 0) {
return $app->response->redirect("http://skins.minecraft.net/MinecraftSkins/".$nickname.".png", true); return $app->response->redirect('http://skins.minecraft.net/MinecraftSkins/' . $nickname . '.png', true);
}
return $app->response->redirect($skin->url); return $app->response->redirect($skin->url);
})->setName("skinSystem"); })->setName('skinSystem');
$app->get('/cloaks/{nickname}', function ($nickname) use ($app) { $app->get('/cloaks/{nickname}', function ($nickname) use ($app) {
// На всякий случай проверка на наличие .png для файла // На всякий случай проверка на наличие .png для файла
if (strrpos($nickname, ".png") != -1) { if (strrpos($nickname, '.png') != -1) {
$nickname = explode(".", $nickname)[0]; $nickname = explode('.', $nickname)[0];
} }
return $app->response->redirect('http://skins.minecraft.net/MinecraftCloaks/'.$nickname.'.png'); return $app->response->redirect('http://skins.minecraft.net/MinecraftCloaks/'.$nickname.'.png');
}); });
$app->get("/textures/{nickname}", function($nickname) use ($app) { $app->get('/textures/{nickname}', function($nickname) use ($app) {
$skin = Skins::findFirst(array(array( $skin = Skins::findFirst(array(array(
"nickname" => mb_convert_case($nickname, MB_CASE_LOWER, ENCODING) 'nickname' => mb_convert_case($nickname, MB_CASE_LOWER, ENCODING)
))); )));
if ($skin && $skin->skinId != 0) { if ($skin && $skin->skinId != 0) {
$url = $skin->url; $url = $skin->url;
$hash = $skin->hash; $hash = $skin->hash;
} else { } else {
$url = "http://skins.minecraft.net/MinecraftSkins/".$nickname.".png"; $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( $textures = array(
@ -50,7 +51,7 @@ $app->get("/textures/{nickname}", function($nickname) use ($app) {
'url' => $url, 'url' => $url,
'hash' => $hash, 'hash' => $hash,
'metadata' => array( 'metadata' => array(
'model' => ($skin && $skin->isSlim) ? "slim" : "default" 'model' => ($skin && $skin->isSlim) ? 'slim' : 'default'
) )
), ),
'CAPE' => array( 'CAPE' => array(
@ -62,75 +63,34 @@ $app->get("/textures/{nickname}", function($nickname) use ($app) {
return $app->response->setJsonContent($textures); return $app->response->setJsonContent($textures);
}); });
/** $app->post('/system/setSkin', function() use ($app) {
* Должно проксироваться средствами nginx, но мало-ли
*/
$app->get("/minecraft.php", function() use ($app) {
$nickname = $app->request->get("name", "string");
$type = $app->request->get("type", "string");
$minecraft_version = str_replace('_', '.', $app->request->get("mine_ver", "string", NULL));
$authlib_version = $app->request->get("auth_lib", "string", NULL);
$version = $app->request->get("ver", "string");
if ($version == "1_0_0")
$version = "1";
if ($type === "cloack" || $type === "cloak")
return $app->response->redirect('http://skins.minecraft.net/MinecraftCloaks/'.$nickname.'.png');
// Если запрос идёт через authlib, то мы не знаем версию Minecraft
if ($authlib_version && !$minecraft_version) {
$auth_to_mine = array(
"1.3" => "1.7.2",
"1.2" => "1.7.4",
"1.3.1" => "1.7.5",
"1.5.13" => "1.7.9",
"1.5.16" => "1.7.10",
"1.5.17" => "1.8.1"
);
if (array_key_exists($authlib_version, $auth_to_mine))
$minecraft_version = $auth_to_mine[$authlib_version];
}
// Отправляем на новую систему скинов в правильном формате
return $app->response->redirect($app->url->get(
array(
"for" => "skinSystem",
"nickname" => $nickname
), array(
"minecraft_version" => $minecraft_version,
"version" => $version
)
), true);
})->setName("fallbackSkinSystem");
$app->post("/system/setSkin", function() use ($app) {
$headers = getallheaders(); $headers = getallheaders();
if (!array_key_exists("X-Ely-key", $headers) || $headers['X-Ely-key'] != "43fd2ce61b3f5704dfd729c1f2d6ffdb") if (!array_key_exists('X-Ely-key', $headers) || $headers['X-Ely-key'] != '43fd2ce61b3f5704dfd729c1f2d6ffdb') {
return $app->response->setStatusCode(403, "Forbidden")->setContent("Хорошая попытка, мерзкий хакер."); return $app->response->setStatusCode(403, 'Forbidden')->setContent('Хорошая попытка, мерзкий хакер.');
}
$request = $app->request; $request = $app->request;
$skin = Skins::findFirst(array(array( $skin = Skins::findFirst(array(array(
"userId" => (int) $request->getPost("userId", "int") 'userId' => (int) $request->getPost('userId', 'int')
))); )));
if (!$skin) { if (!$skin) {
$skin = new Skins(); $skin = new Skins();
$skin->userId = (int) $request->getPost("userId", "int"); $skin->userId = (int) $request->getPost('userId', 'int');
} }
$skin->nickname = mb_convert_case($request->getPost("nickname", "string"), MB_CASE_LOWER, ENCODING); $skin->nickname = mb_convert_case($request->getPost('nickname', 'string'), MB_CASE_LOWER, ENCODING);
$skin->skinId = (int) $request->getPost("skinId", "int"); $skin->skinId = (int) $request->getPost('skinId', 'int');
$skin->hash = $request->getPost("hash", "string"); $skin->hash = $request->getPost('hash', 'string');
$skin->is1_8 = (bool) $request->getPost("is1_8", "int"); $skin->is1_8 = (bool) $request->getPost('is1_8', 'int');
$skin->isSlim = (bool) $request->getPost("isSlim", "int"); $skin->isSlim = (bool) $request->getPost('isSlim', 'int');
$skin->url = $request->getPost("url", "string"); $skin->url = $request->getPost('url', 'string');
if ($skin->save()) if ($skin->save()) {
echo "OK"; echo 'OK';
else } else {
echo "ERROR"; echo 'ERROR';
}
}); });
/** /**
@ -138,7 +98,7 @@ $app->post("/system/setSkin", function() use ($app) {
*/ */
$app->notFound(function () use ($app) { $app->notFound(function () use ($app) {
$app->response $app->response
->setStatusCode(404, "Not Found") ->setStatusCode(404, 'Not Found')
->setContent('Not Found<br /> <a href="http://ely.by">Система скинов Ely.by</a>.') ->setContent('Not Found<br /> <a href="http://ely.by">Система скинов Ely.by</a>.')
->send(); ->send();
}); });