diff --git a/scripts/class.FactorioServer.php b/scripts/class.FactorioServer.php index 9621d44..7e97fe8 100644 --- a/scripts/class.FactorioServer.php +++ b/scripts/class.FactorioServer.php @@ -23,10 +23,46 @@ class FactorioServer { */ private $mods; + /** + * @var ValveRcon for handling Valve Rcon to server + */ + private $rcon; + /** * @var string Name of the Save to load when starting the server */ - private $saveName; + private $save_name; + + /** + * @var string Path to the Server Directory + */ + private $server_dir = INDEX_DIR . "/factorio"; + + /** + * @var string Path to the Mods Directory + */ + private $mod_dir = INDEX_DIR . "/factorio/mods"; + + /** + * @var string Path to the Save-File Directory + */ + private $save_dir = INDEX_DIR . "/factorio/saves"; + + /** + * @var string Name of the user who owns the files and runs this server + */ + private $user_name = "factorio"; + + /** + * @var string Name of the user-group who owns the files and runs this server + */ + private $user_group = "factorio"; + + + /** + * @var string Name of the Service in systemd/systemctl + */ + private $service_name = "factorio"; /** * @var callcable Custom function for stopping the server (return bool) @@ -38,6 +74,16 @@ class FactorioServer { */ private $customStart = null; + /** + * @var callable Custom function for restarting the server (return bool) + */ + private $customReStart = null; + + /** + * @var callable Custom function for checking the server status (return bool - true means server is running, false means server is not running) + */ + private $customIsRunning = null; + /** * @var array Server Settings */ @@ -51,7 +97,7 @@ class FactorioServer { /** * @var array Server Admin List */ - private $adminList = []; + private $admin_list = []; /** @@ -137,7 +183,7 @@ class FactorioServer { return call_user_func($this->customStart); } - $command = "systemctl start factorio-server"; + $command = "systemctl start ".$this->getServiceName(); exec($command, $output, $return); return ( $return === 0 ); @@ -150,7 +196,11 @@ class FactorioServer { */ public function restart() : bool { - exec("systemctl restart factorio-server > /dev/null", $output, $return); + if(is_callable($this->customReStart)) { + return call_user_func($this->customReStart); + } + + exec("systemctl restart ".$this->getServiceName()." > /dev/null", $output, $return); return ( $return === 0 ); @@ -163,10 +213,37 @@ class FactorioServer { */ public function isRunning() : bool { - exec("systemctl is-active factorio-server", $output, $return); + if(is_callable($this->customIsRunning)) { + return call_user_func($this->customIsRunning); + } + + exec("systemctl is-active ".$this->getServiceName(), $output, $return); return ( $return === 0 ); } + /** + * Get the Name of the Service in systemd/systemctl. + * @return string Name of the service + */ + public function getServiceName() : string { + + return $this->service_name; + + } + + /** + * Sets the Name of the Service in systemd/systemctl. + * @param string $serviceName Name of the Service + * @return FactorioServer $this for chaining. + */ + public function setServiceName(string $serviceName) : FactorioServer { + + $this->service_name = $serviceName; + + return $this; + + } + } \ No newline at end of file