Compare commits

...

2 Commits

2 changed files with 83 additions and 6 deletions

View File

@ -1,6 +1,6 @@
<?PHP <?PHP
define("INDEX_DIR", __DIR__);
require __DIR__.'/scripts/class.TerminalMessage.php'; require __DIR__.'/scripts/class.TerminalMessage.php';
require __DIR__.'/scripts/func.downloadFile.php'; require __DIR__.'/scripts/func.downloadFile.php';

View File

@ -23,10 +23,46 @@ class FactorioServer {
*/ */
private $mods; private $mods;
/**
* @var ValveRcon for handling Valve Rcon to server
*/
private $rcon;
/** /**
* @var string Name of the Save to load when starting the server * @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) * @var callcable Custom function for stopping the server (return bool)
@ -38,6 +74,16 @@ class FactorioServer {
*/ */
private $customStart = null; 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 * @var array Server Settings
*/ */
@ -51,7 +97,7 @@ class FactorioServer {
/** /**
* @var array Server Admin List * @var array Server Admin List
*/ */
private $adminList = []; private $admin_list = [];
/** /**
@ -137,7 +183,7 @@ class FactorioServer {
return call_user_func($this->customStart); return call_user_func($this->customStart);
} }
$command = "systemctl start factorio-server"; $command = "systemctl start ".$this->getServiceName();
exec($command, $output, $return); exec($command, $output, $return);
return ( $return === 0 ); return ( $return === 0 );
@ -150,7 +196,11 @@ class FactorioServer {
*/ */
public function restart() : bool { 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 ); return ( $return === 0 );
@ -163,10 +213,37 @@ class FactorioServer {
*/ */
public function isRunning() : bool { 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 ); 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;
}
} }