mince/public/index.php
2023-08-24 23:13:29 +00:00

61 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($config['chat_endpoint'], $config['chat_secret'], $authToken);
$users = new Users($db);
if($authInfo->success) {
$users->syncChatUser($authInfo);
$userInfo = $users->getUser($authInfo->user_id);
} else $userInfo = null;
$csrfp = new CSRFP(
$config['csrf_secret'],
$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,
],
]));
});
(new RpcRoutes($users, $accountLinks, $authorisations, $verifications, $config['rpc_secret'], $config['clients_url']))->register($router);
(new HomeRoutes($templating, new Servers($db), $authInfo, $config['login_url']))->register($router);
(new ClientsRoutes($templating, $accountLinks, $authorisations, $verifications, $csrfp, $authInfo))->register($router);
(new SkinsRoutes($templating, $accountLinks, new Skins($db), new Capes($db), $csrfp, $authInfo, $config['skins_base_url']))->register($router);
MojangInterop::registerRoutes($router);
$router->dispatch();