Added some rudimentary server finding

This commit is contained in:
2022-09-24 16:26:57 -04:00
parent 1fd7bb7a9a
commit 25b68c4bc6
3 changed files with 59 additions and 2 deletions

View File

@ -4,13 +4,23 @@ use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
use Slim\Views\Twig;
use BitGoblin\MCST\Minecraft\Server;
// index GET route - this page should welcome the user and direct them to the available actions
$app->get('/', function (Request $request, Response $response, $args) {
$config = $this->get('config');
// find servers
$minecraftDir = $config->get('server_directory');
$serverDirs = glob($minecraftDir . "/*", GLOB_ONLYDIR);
$minecraftServers = array();
foreach ($serverDirs as $i => $m) {
array_push($minecraftServers, new Server($m));
}
$view = Twig::fromRequest($request);
return $view->render($response, 'index.twig', [
'server_dir' => $config->get('server_directory'),
'servers' => $minecraftServers,
]);
})->setName('index');