Init commit

This commit is contained in:
ErickSkrauch 2015-01-28 23:20:29 +03:00
commit 290738377b
9 changed files with 235 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
/.idea

5
.htaccess Normal file
View File

@ -0,0 +1,5 @@
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ public/ [L]
RewriteRule (.*) public/$1 [L]
</IfModule>

99
app.php Normal file
View File

@ -0,0 +1,99 @@
<?php
/**
* Add your routes here
*/
$app->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();
});

15
config/config.php Normal file
View File

@ -0,0 +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' => '/',
)
));

9
config/loader.php Normal file
View File

@ -0,0 +1,9 @@
<?php
$loader = new \Phalcon\Loader();
$loader->registerDirs(array(
$config->application->modelsDir
));
$loader->register();

50
config/services.php Normal file
View File

@ -0,0 +1,50 @@
<?php
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();
$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;
});

27
models/Skins.php Normal file
View File

@ -0,0 +1,27 @@
<?php
use Phalcon\Mvc\Collection;
/**
* @method static Skins findFirst()
*
* @property string $id
*/
class Skins extends Collection {
public $_id;
public $userId;
public $nickname;
public $skinId;
public $url;
public $is1_8;
public $isSlim;
public $hash;
public function getId() {
return $this->_id;
}
public function getSource() {
return "skins";
}
}

7
public/.htaccess Normal file
View File

@ -0,0 +1,7 @@
AddDefaultCharset UTF-8
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?_url=/$1 [QSA,L]
</IfModule>

22
public/index.php Normal file
View File

@ -0,0 +1,22 @@
<?php
error_reporting(E_ALL);
try {
/** @var \Phalcon\Config $config */
$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);
include __DIR__ . '/../app.php';
$app->handle();
} catch (Phalcon\Exception $e) {
echo $e->getMessage();
} catch (PDOException $e) {
echo $e->getMessage();
}