/** * stops server, delete world/, restore backup, and start server * stoping and starting server will be omitted if the server is down * @param string $path to minecraft folder ('backup/' will be added automaticaly) * @param string $filename name of the backup file * @param string $runtimeHash if is server running * @param string $jar name of jar file to run, needed only on running server * @return boolean TRUE when successful */ public function restore($path, $filename, $runtimeHash = NULL, $jar = NULL) { if (file_exists($path . 'backups/' . $filename)) { if ($runtimeHash !== NULL) { //stop server $this->serverCmd->stopServer($runtimeHash); } //delete world/ $this->removeDir($path . 'world/'); //extract backup archive try { $archive = new PharData($path . 'backups/' . $filename); $archive->extractTo($path . 'world/', NULL, TRUE); } catch (UnexpectedValueException $e) { echo $e->getTraceAsString(); return FALSE; } if ($runtimeHash !== NULL) { //start server again $this->serverCmd->startServer($path, $jar, $runtimeHash); return TRUE; } return TRUE; } else { //no such file return FALSE; } }
public function handleStartServer() { //check if running if ($this->runtimeHash != NULL) { $this->flashMessage('Server is already running! Or it looks to be like that. :/', 'error'); } else { //generte runtime hash $this->runtimeHash = $this->serverRepo->generateRuntimeHash(); $this->serverRepo->setRuntimeHash($this->selectedServerId, $this->runtimeHash); //set correct values from settings $params = $this->serverRepo->getRunParams($this->selectedServerId); $out = $this->serverCmd->startServer($params->path, $params->executable, $this->runtimeHash); if ($out === array()) { $this->flashMessage('Server naběhl. Adresa pro připojení: ' . $this->hostIp . ':' . $params->port, 'success'); } else { $this->flashMessage(implode(" \n", $out), 'error'); } } $this->redirect('this'); }