diff --git a/src/Minecraft/Server.php b/src/Minecraft/Server.php index 34add6d..cccd939 100644 --- a/src/Minecraft/Server.php +++ b/src/Minecraft/Server.php @@ -6,6 +6,10 @@ class Server { // server root directory private string $rootDir; + // server name + private string $serverName; + // server Minecraft version + private string $serverVersion; // PID file path private string $pidFilePath; // server run status @@ -13,9 +17,17 @@ class Server { // class constructor public function __construct($dir) { + $dirBits = explode('/', $dir); $this->rootDir = $dir; + $this->serverName = $dirBits[count($dirBits) - 1]; $this->pidFilePath = $dir . '/pid.txt'; + // get server version + $versionFile = join('/', array($this->rootDir, 'current_version.txt')); + if (file_exists($versionFile)) { + $this->serverVersion = file($versionFile)[0]; + } + // search for server state if (file_exists($this->pidFilePath)) { $this->state = true; @@ -38,6 +50,12 @@ class Server { public function getDirectory(): string { return $this->rootDir; } + public function getName(): string { + return $this->serverName; + } + public function getVersion(): string { + return $this->serverVersion; + } public function getState(): bool { return $this->state; } diff --git a/src/routes.php b/src/routes.php index f84c10a..c12a81e 100644 --- a/src/routes.php +++ b/src/routes.php @@ -54,6 +54,15 @@ $app->post('/create', function (Request $request, Response $response, $args) { fclose($scriptFile); chmod($scriptFilePath, 0755); + // save the current version to a text file - this will hopefully be temporary solution + $versionFilePath = join('/', array($serverDir, 'current_version.txt')); + $versionFile = fopen($versionFilePath, 'w'); + $versionContent = $params['serverVersion']; + fwrite($versionFile, $versionContent); + fclose($versionFile); + chmod($versionFilePath, 0644); + + // redirect the user back to the home page return $response ->withHeader('Location', '/') ->withStatus(302); diff --git a/views/index.twig b/views/index.twig index af93129..3df085e 100644 --- a/views/index.twig +++ b/views/index.twig @@ -14,10 +14,33 @@

List of servers:

-

There are currently no servers registered.

- {% for m in servers %} -

Server directory: {{ m.getDirectory() }}

- {% endfor %} + {% if servers|length < 1 %} +

There are currently no servers registered.

+ {% else %} + + + + + + + + + + + + {% for m in servers %} + + + + + {% endfor %} + + +
Server nameMinecraft versionStateActions
{{ m.getName() }}{{ m.getVersion() }}{{ m.getState() ? 'Running' : 'Stopped' }} + Start + Stop +
+ {% endif %}