commit 290738377b09f7ae12658d1a91a1d6b63837f325 Author: ErickSkrauch Date: Wed Jan 28 23:20:29 2015 +0300 Init commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..757fee3 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/.idea \ No newline at end of file diff --git a/.htaccess b/.htaccess new file mode 100644 index 0000000..aa6a7f7 --- /dev/null +++ b/.htaccess @@ -0,0 +1,5 @@ + + RewriteEngine on + RewriteRule ^$ public/ [L] + RewriteRule (.*) public/$1 [L] + \ No newline at end of file diff --git a/app.php b/app.php new file mode 100644 index 0000000..0406ef7 --- /dev/null +++ b/app.php @@ -0,0 +1,99 @@ +get('/skins/{nickname}', function ($nickname) use ($app) { + $nickname = strtolower($nickname); + $systemVersion = $app->request->get("version", "int"); + $minecraftVersion = $app->request->get("minecraft_version", "string"); + + // На всякий случай проверка на наличие .png для файла + if (strrpos($nickname, ".png") != -1) { + $nickname = explode(".", $nickname)[0]; + } + + // TODO: восстановить функцию деградации скинов + + $skin = Skins::findFirst(array(array( + "nickname" => $nickname + ))); + + if (!$skin || $skin->skinId == 0) + return $app->response->redirect("http://skins.minecraft.net/MinecraftSkins/".$nickname.".png", true); + + return $app->response->redirect($skin->url); +})->setName("skinSystem"); + +$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) { + $request = $app->request; + $skin = Skins::findFirst(array(array( + "userId" => $request->getPost("userId", "int") + ))); + + if (!$skin) { + $skin = new Skins(); + $skin->userId = $request->getPost("userId", "int"); + } + + $skin->hash = $request->getPost("hash", "string"); + $skin->nickname = $request->getPost("nickname", "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"; +}); + +/** + * Not found handler + */ +$app->notFound(function () use ($app) { + $app->response + ->setStatusCode(404, "Not Found") + ->setContent("Not Found") + ->send(); +}); diff --git a/config/config.php b/config/config.php new file mode 100644 index 0000000..21704e2 --- /dev/null +++ b/config/config.php @@ -0,0 +1,15 @@ + array( + 'host' => 'localhost', + 'port' => 27017, + 'username' => '', + 'password' => '', + 'dbname' => 'ely_skins', + ), + 'application' => array( + 'modelsDir' => __DIR__ . '/../models/', + 'baseUri' => '/', + ) +)); diff --git a/config/loader.php b/config/loader.php new file mode 100644 index 0000000..1b18081 --- /dev/null +++ b/config/loader.php @@ -0,0 +1,9 @@ +registerDirs(array( + $config->application->modelsDir +)); + +$loader->register(); diff --git a/config/services.php b/config/services.php new file mode 100644 index 0000000..09d9c23 --- /dev/null +++ b/config/services.php @@ -0,0 +1,50 @@ +set("view", function () { + $view = new \Phalcon\Mvc\View(); + $view->disable(); + + return $view; +}); + +/** + * The URL component is used to generate all kind of urls in the application + */ +$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 + ); + } + + return $mongo->selectDb($config->mongo->dbname); +}); + +//Registering the collectionManager service +$di->setShared('collectionManager', function() { + $modelsManager = new Phalcon\Mvc\Collection\Manager(); + return $modelsManager; +}); \ No newline at end of file diff --git a/models/Skins.php b/models/Skins.php new file mode 100644 index 0000000..235730e --- /dev/null +++ b/models/Skins.php @@ -0,0 +1,27 @@ +_id; + } + + public function getSource() { + return "skins"; + } +} \ No newline at end of file diff --git a/public/.htaccess b/public/.htaccess new file mode 100644 index 0000000..297b8a6 --- /dev/null +++ b/public/.htaccess @@ -0,0 +1,7 @@ +AddDefaultCharset UTF-8 + + + RewriteEngine On + RewriteCond %{REQUEST_FILENAME} !-f + RewriteRule ^(.*)$ index.php?_url=/$1 [QSA,L] + \ No newline at end of file diff --git a/public/index.php b/public/index.php new file mode 100644 index 0000000..ecdaaee --- /dev/null +++ b/public/index.php @@ -0,0 +1,22 @@ +handle(); + +} catch (Phalcon\Exception $e) { + echo $e->getMessage(); +} catch (PDOException $e) { + echo $e->getMessage(); +}