2014-06-20 15:58:41 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace ManiaControl\Server;
|
|
|
|
|
2014-06-20 18:51:40 +02:00
|
|
|
use ManiaControl\Callbacks\CallbackListener;
|
|
|
|
use ManiaControl\Callbacks\CallbackManager;
|
|
|
|
use ManiaControl\Files\FileUtil;
|
2014-06-20 15:58:41 +02:00
|
|
|
use ManiaControl\ManiaControl;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class offering Operations for the Server Directory
|
|
|
|
*
|
|
|
|
* @author ManiaControl Team <mail@maniacontrol.com>
|
|
|
|
* @copyright 2014 ManiaControl Team
|
|
|
|
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
|
|
|
*/
|
2014-06-20 18:51:40 +02:00
|
|
|
class Directory implements CallbackListener {
|
2014-06-20 15:58:41 +02:00
|
|
|
/**
|
2014-07-25 16:28:47 +02:00
|
|
|
* Private properties
|
2014-06-20 15:58:41 +02:00
|
|
|
*/
|
|
|
|
private $maniaControl = null;
|
|
|
|
|
|
|
|
/**
|
2014-07-25 16:28:47 +02:00
|
|
|
* Create new server directory instance
|
2014-06-20 15:58:41 +02:00
|
|
|
*
|
|
|
|
* @param ManiaControl $maniaControl
|
|
|
|
*/
|
|
|
|
public function __construct(ManiaControl $maniaControl) {
|
|
|
|
$this->maniaControl = $maniaControl;
|
2014-06-20 18:51:40 +02:00
|
|
|
|
|
|
|
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MP_SERVERSTOP, $this, 'handleServerStopCallback');
|
2014-06-20 15:58:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieve the Maps Folder Path
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getMapsFolder() {
|
|
|
|
return $this->maniaControl->client->getMapsDirectory();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieve the Skins Folder Path
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getSkinsFolder() {
|
|
|
|
return $this->maniaControl->client->getSkinsDirectory();
|
|
|
|
}
|
2014-06-20 16:14:15 +02:00
|
|
|
|
2014-06-20 18:51:40 +02:00
|
|
|
/**
|
|
|
|
* Handle Server Stop Callback
|
|
|
|
*/
|
|
|
|
public function handleServerStopCallback() {
|
|
|
|
$this->cleanLogsFolder();
|
|
|
|
$this->cleanCacheFolder();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Clean the server logs folder
|
|
|
|
*
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
private function cleanLogsFolder() {
|
|
|
|
return FileUtil::cleanDirectory($this->getLogsFolder());
|
|
|
|
}
|
|
|
|
|
2014-06-20 16:14:15 +02:00
|
|
|
/**
|
|
|
|
* Retrieve the Logs Folder Path
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getLogsFolder() {
|
|
|
|
return $this->getGameDataFolder() . '..' . DIRECTORY_SEPARATOR . 'Logs' . DIRECTORY_SEPARATOR;
|
|
|
|
}
|
|
|
|
|
2014-07-25 16:28:47 +02:00
|
|
|
/**
|
|
|
|
* Retrieve the Game Data Folder Path
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getGameDataFolder() {
|
|
|
|
return $this->maniaControl->client->gameDataDirectory();
|
|
|
|
}
|
|
|
|
|
2014-06-20 16:14:15 +02:00
|
|
|
/**
|
2014-06-20 18:51:40 +02:00
|
|
|
* @return bool
|
2014-06-20 16:14:15 +02:00
|
|
|
*/
|
2014-06-20 18:51:40 +02:00
|
|
|
private function cleanCacheFolder() {
|
|
|
|
return FileUtil::cleanDirectory($this->getCacheFolder(), 50);
|
2014-06-20 16:14:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieve the Cache Folder Path
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getCacheFolder() {
|
|
|
|
return $this->getGameDataFolder() . '..' . DIRECTORY_SEPARATOR . 'CommonData' . DIRECTORY_SEPARATOR . 'Cache' . DIRECTORY_SEPARATOR;
|
|
|
|
}
|
2014-06-20 15:58:41 +02:00
|
|
|
}
|