Added a nice table for displaying currently available servers
This commit is contained in:
@ -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;
|
||||
}
|
||||
|
@ -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);
|
||||
|
Reference in New Issue
Block a user