mince/public/index.php

63 lines
2.1 KiB
PHP
Raw Normal View History

2022-07-03 22:07:00 +00:00
<?php
namespace Mince;
2024-10-05 14:48:18 +00:00
use Index\CsrfToken;
2024-03-28 23:28:19 +00:00
use Index\Http\Routing\HttpRouter;
2024-10-05 14:48:18 +00:00
use Index\Templating\TplEnvironment;
2024-10-05 15:25:27 +00:00
use Index\Urls\ArrayUrlRegistry;
2022-07-03 22:07:00 +00:00
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);
2023-08-22 23:47:37 +00:00
$users = new Users($db);
if($authInfo->success) {
$users->syncChatUser($authInfo);
$userInfo = $users->getUser($authInfo->user_id);
} else $userInfo = null;
2023-08-16 22:39:35 +00:00
2024-10-05 14:48:18 +00:00
$csrfp = new CsrfToken(
$cfg->getString('csrfp:secret', 'wowof'),
2023-08-22 23:47:37 +00:00
$authInfo->success ? $authToken : $_SERVER['REMOTE_ADDR']
);
2023-08-16 22:39:35 +00:00
2024-10-05 14:48:18 +00:00
$templating = new TplEnvironment(MCR_DIR_TPL, ['Mince'], debug: MCR_DEBUG);
2023-08-24 23:13:29 +00:00
$templating->addGlobal('globals', [
'title' => 'Flashii Minecraft Servers',
2023-08-22 23:47:37 +00:00
'is_authed' => $userInfo !== null,
'user' => $userInfo,
'csrfp' => $csrfp->createToken(),
]);
2022-07-03 22:07:00 +00:00
2023-08-22 23:47:37 +00:00
$accountLinks = new AccountLinks($db);
$authorisations = new Authorisations($db);
$authorisations->prune();
$verifications = new Verifications($db);
$verifications->prune();
2024-10-05 15:25:27 +00:00
$urls = new ArrayUrlRegistry;
$templating->addFunction('url', $urls->format(...));
2024-03-28 23:28:19 +00:00
$router = new HttpRouter(errorHandler: new RouterErrorHandler($templating));
$router->use('/', function($response, $request) { $response->setPoweredBy('Mince'); });
2022-07-03 22:07:00 +00:00
2024-02-21 16:08:45 +00:00
$router->register(new RpcRoutes($users, $accountLinks, $authorisations, $verifications, $cfg->getString('rpc:secret'), $cfg->getString('urls:clients')));
2024-10-05 15:25:27 +00:00
$homeRoutes = new HomeRoutes($templating, $urls, new Servers($db), $authInfo, $cfg->getString('site:login'));
$router->register($homeRoutes);
$urls->register($homeRoutes);
$clientRoutes = new ClientsRoutes($templating, $urls, $accountLinks, $authorisations, $verifications, $csrfp, $authInfo);
$router->register($clientRoutes);
$urls->register($clientRoutes);
$skinsRoutes = new SkinsRoutes($templating, $urls, $accountLinks, new Skins($db), new Capes($db), $csrfp, $authInfo, $cfg->getString('urls:skins_base'));
$router->register($skinsRoutes);
$urls->register($skinsRoutes);
2023-08-22 23:47:37 +00:00
MojangInterop::registerRoutes($router);
2022-07-03 22:07:00 +00:00
$router->dispatch();