2022-07-03 22:07:00 +00:00
|
|
|
<?php
|
|
|
|
namespace Mince;
|
|
|
|
|
|
|
|
use Index\Http\HttpFx;
|
2023-08-16 23:17:14 +00:00
|
|
|
use Index\Security\CSRFP;
|
2022-07-03 22:07:00 +00:00
|
|
|
|
|
|
|
require_once __DIR__ . '/../mince.php';
|
|
|
|
|
2023-08-16 23:17:14 +00:00
|
|
|
// replace this with id.flashii.net shit
|
|
|
|
$authToken = (string)filter_input(INPUT_COOKIE, 'msz_auth');
|
2023-08-22 23:47:37 +00:00
|
|
|
$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;
|
2023-08-16 22:39:35 +00:00
|
|
|
|
2023-08-16 23:17:14 +00:00
|
|
|
$csrfp = new CSRFP(
|
|
|
|
$config['csrf_secret'],
|
2023-08-22 23:47:37 +00:00
|
|
|
$authInfo->success ? $authToken : $_SERVER['REMOTE_ADDR']
|
2023-08-16 23:17:14 +00:00
|
|
|
);
|
2023-08-16 22:39:35 +00:00
|
|
|
|
2023-08-16 23:17:14 +00:00
|
|
|
$templating = new Templating;
|
|
|
|
$templating->addPath(MCR_DIR_TPL);
|
|
|
|
|
|
|
|
$templating->addVars([
|
2023-08-16 22:39:35 +00:00
|
|
|
'global' => [
|
|
|
|
'title' => 'Flashii Minecraft Servers',
|
|
|
|
],
|
2023-08-22 23:47:37 +00:00
|
|
|
'is_authed' => $userInfo !== null,
|
|
|
|
'auth' => $authInfo,
|
|
|
|
'user' => $userInfo,
|
2023-08-16 23:17:14 +00:00
|
|
|
'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();
|
|
|
|
|
2023-08-16 22:39:35 +00:00
|
|
|
$router = new HttpFx;
|
2023-08-16 23:45:46 +00:00
|
|
|
$router->use('/', function($response, $request) {
|
|
|
|
$response->setPoweredBy('Mince');
|
|
|
|
});
|
2022-07-03 22:07:00 +00:00
|
|
|
|
2023-08-16 23:45:46 +00:00
|
|
|
$router->setDefaultErrorHandler(function($response, $request, $code, $text) use ($templating) {
|
2023-08-16 23:17:14 +00:00
|
|
|
$response->setContent($templating->render('http-error', [
|
2023-08-16 22:39:35 +00:00
|
|
|
'error' => [
|
|
|
|
'code' => sprintf('%03d', $code),
|
|
|
|
'text' => $text,
|
|
|
|
],
|
|
|
|
]));
|
2022-07-03 22:07:00 +00:00
|
|
|
});
|
|
|
|
|
2023-08-22 23:47:37 +00:00
|
|
|
(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))->register($router);
|
|
|
|
(new WhitelistRoutes(new Whitelist($db), $csrfp, $authInfo))->register($router);
|
|
|
|
|
|
|
|
MojangInterop::registerRoutes($router);
|
2022-07-03 22:07:00 +00:00
|
|
|
|
|
|
|
$router->dispatch();
|