2022-07-03 22:07:00 +00:00
|
|
|
<?php
|
|
|
|
namespace Mince;
|
|
|
|
|
2024-11-16 16:32:38 +00:00
|
|
|
use Flashii\{FlashiiClient,FlashiiUrls};
|
|
|
|
use Flashii\Credentials\MisuzuCredentials;
|
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';
|
|
|
|
|
2023-08-16 23:17:14 +00:00
|
|
|
// replace this with id.flashii.net shit
|
|
|
|
$authToken = (string)filter_input(INPUT_COOKIE, 'msz_auth');
|
2024-11-16 16:32:38 +00:00
|
|
|
|
|
|
|
$flashii = new FlashiiClient('Mince', new MisuzuCredentials($authToken), new FlashiiUrls(
|
|
|
|
$cfg->getString('apii:api', FlashiiUrls::PROD_API_URL),
|
|
|
|
$cfg->getString('apii:id', FlashiiUrls::PROD_ID_URL)
|
|
|
|
));
|
|
|
|
$authInfo = $flashii->v1()->me();
|
2023-08-22 23:47:37 +00:00
|
|
|
|
|
|
|
$users = new Users($db);
|
2024-11-16 16:32:38 +00:00
|
|
|
if($authInfo !== null) {
|
|
|
|
$users->syncApiUser($authInfo);
|
|
|
|
$userInfo = $users->getUser($authInfo->getId());
|
2023-08-22 23:47:37 +00:00
|
|
|
} else $userInfo = null;
|
2023-08-16 22:39:35 +00:00
|
|
|
|
2024-10-05 14:48:18 +00:00
|
|
|
$csrfp = new CsrfToken(
|
2023-12-15 02:14:55 +00:00
|
|
|
$cfg->getString('csrfp:secret', 'wowof'),
|
2024-11-16 16:32:38 +00:00
|
|
|
$authInfo === null ? $_SERVER['REMOTE_ADDR'] : $authToken
|
2023-08-16 23:17:14 +00:00
|
|
|
);
|
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,
|
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();
|
|
|
|
|
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();
|