mince/public/index.php
2023-08-22 23:54:15 +00:00

65 lines
2.1 KiB
PHP

<?php
namespace Mince;
use Index\Http\HttpFx;
use Index\Security\CSRFP;
require_once __DIR__ . '/../mince.php';
// replace this with id.flashii.net shit
$authToken = (string)filter_input(INPUT_COOKIE, 'msz_auth');
$authInfo = ChatAuth::attempt($db, $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 Templating;
$templating->addPath(MCR_DIR_TPL);
$templating->addVars([
'global' => [
'title' => 'Flashii Minecraft Servers',
],
'is_authed' => $userInfo !== null,
'auth' => $authInfo,
'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(new Servers($db), $templating, $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);
(new WhitelistRoutes(new Whitelist($db), $csrfp, $authInfo))->register($router);
MojangInterop::registerRoutes($router);
$router->dispatch();