Added some rudimentary server finding
This commit is contained in:
parent
1fd7bb7a9a
commit
25b68c4bc6
45
src/Minecraft/Server.php
Normal file
45
src/Minecraft/Server.php
Normal file
@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace BitGoblin\MCST\Minecraft;
|
||||
|
||||
class Server {
|
||||
|
||||
// server root directory
|
||||
private string $rootDir;
|
||||
// PID file path
|
||||
private string $pidFilePath;
|
||||
// server run status
|
||||
private bool $state = false;
|
||||
|
||||
// class constructor
|
||||
public function __construct($dir) {
|
||||
$this->rootDir = $dir;
|
||||
$this->pidFilePath = $dir . '/pid.txt';
|
||||
|
||||
// search for server state
|
||||
if (file_exists($this->pidFilePath)) {
|
||||
$this->state = true;
|
||||
}
|
||||
}
|
||||
|
||||
// start the server
|
||||
public function start(): void {
|
||||
// TODO - for now just set the state to true
|
||||
$this->state = true;
|
||||
}
|
||||
|
||||
// stop the server
|
||||
public function stop(): void {
|
||||
// TODO - for now just set the state to false
|
||||
$this->state = false;
|
||||
}
|
||||
|
||||
// getters & setters
|
||||
public function getDirectory(): string {
|
||||
return $this->rootDir;
|
||||
}
|
||||
public function getState(): bool {
|
||||
return $this->state;
|
||||
}
|
||||
|
||||
}
|
@ -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');
|
||||
|
||||
|
@ -15,7 +15,9 @@
|
||||
<div class="columns twelve">
|
||||
<h3>List of servers:</h3>
|
||||
<span><p>There are currently no servers registered.</p></span>
|
||||
<p>Home directory: {{ server_dir }}</p>
|
||||
{% for m in servers %}
|
||||
<p>Server directory: {{ m.getDirectory() }}</p>
|
||||
{% endfor %}
|
||||
</div>
|
||||
</section>
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user