mince/public/index.php

60 lines
2 KiB
PHP

<?php
namespace Mince;
use Index\Http\HttpFx;
use Index\Security\CSRFP;
use Sasae\SasaeEnvironment;
require_once __DIR__ . '/../mince.php';
// replace this with id.flashii.net shit
$authToken = (string)filter_input(INPUT_COOKIE, 'msz_auth');
$authInfo = ChatAuth::attempt($cfg->scopeTo('cauth'), $authToken);
$users = new Users($db);
if($authInfo->success) {
$users->syncChatUser($authInfo);
$userInfo = $users->getUser($authInfo->user_id);
} else $userInfo = null;
$csrfp = new CSRFP(
$cfg->getString('csrfp:secret', 'wowof'),
$authInfo->success ? $authToken : $_SERVER['REMOTE_ADDR']
);
$templating = new SasaeEnvironment(MCR_DIR_TPL, ['Mince'], debug: MCR_DEBUG);
$templating->addGlobal('globals', [
'title' => 'Flashii Minecraft Servers',
'is_authed' => $userInfo !== null,
'user' => $userInfo,
'csrfp' => $csrfp->createToken(),
]);
$accountLinks = new AccountLinks($db);
$authorisations = new Authorisations($db);
$authorisations->prune();
$verifications = new Verifications($db);
$verifications->prune();
$router = new HttpFx;
$router->use('/', function($response, $request) {
$response->setPoweredBy('Mince');
});
$router->setDefaultErrorHandler(function($response, $request, $code, $text) use ($templating) {
$response->setContent($templating->render('http-error', [
'error' => [
'code' => sprintf('%03d', $code),
'text' => $text,
],
]));
});
$router->register(new RpcRoutes($users, $accountLinks, $authorisations, $verifications, $cfg->getString('rpc:secret'), $cfg->getString('urls:clients')));
$router->register(new HomeRoutes($templating, new Servers($db), $authInfo, $cfg->getString('site:login')));
$router->register(new ClientsRoutes($templating, $accountLinks, $authorisations, $verifications, $csrfp, $authInfo));
$router->register(new SkinsRoutes($templating, $accountLinks, new Skins($db), new Capes($db), $csrfp, $authInfo, $cfg->getString('urls:skins_base')));
MojangInterop::registerRoutes($router);
$router->dispatch();