diff --git a/src/Minecraft/Server.php b/src/Minecraft/Server.php index 002886d..23dada3 100644 --- a/src/Minecraft/Server.php +++ b/src/Minecraft/Server.php @@ -14,6 +14,8 @@ class Server { private string $pidFilePath; // server run status private bool $state = false; + // server config properties + private ServerConfig $properties; // class constructor public function __construct($dir) { @@ -21,6 +23,7 @@ class Server { $this->rootDir = $dir; $this->serverName = $dirBits[count($dirBits) - 1]; $this->pidFilePath = $this->rootDir . '/pid.txt'; + $this->properties = new ServerConfig($this->rootDir . '/server.properties'); // get server version $versionFile = join('/', array($this->rootDir, 'current_version.txt')); @@ -81,6 +84,11 @@ class Server { return -1; } + // get parameter from server properties file + public function getProperty(string $param) { + return $this->properties->get($param); + } + // getters & setters public function getDirectory(): string { return $this->rootDir; diff --git a/src/Minecraft/ServerConfig.php b/src/Minecraft/ServerConfig.php new file mode 100644 index 0000000..94dcbaf --- /dev/null +++ b/src/Minecraft/ServerConfig.php @@ -0,0 +1,29 @@ +config = array(); // initialize array + + // parse config file + $fh = fopen($propertiesFile, 'r+'); + while (!feof($fh)) { + $line = fgets($fh); + $eqpos = strpos($line, '='); + $parameterName = substr($line, 0, $eqpos); + $parameterValue = substr($line, ($eqpos + 1)); + + // assign parameter values to the config array + $this->config[$parameterName] = $parameterValue; + } + } + + public function get(string $param) { + return $this->config[$param]; + } + +} diff --git a/views/index.twig b/views/index.twig index c0ed4f0..f386735 100644 --- a/views/index.twig +++ b/views/index.twig @@ -22,6 +22,7 @@ Server name Minecraft version + Port State Actions @@ -31,6 +32,7 @@ {{ m.getName() }} {{ m.getVersion() }} + {{ m.getProperty('server-port') }} {{ m.getState() ? 'Running' : 'Stopped' }}