mince/public/index.php

50 lines
1.8 KiB
PHP

<?php
namespace Mince;
use Index\Http\Routing\HttpRouter;
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 HttpRouter(errorHandler: new RouterErrorHandler($templating));
$router->use('/', function($response, $request) { $response->setPoweredBy('Mince'); });
$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();