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;
|
2017-03-26 19:44:55 +02:00
|
|
|
use ManiaControl\General\UsageInformationAble;
|
|
|
|
use ManiaControl\General\UsageInformationTrait;
|
2014-06-20 15:58:41 +02:00
|
|
|
use ManiaControl\ManiaControl;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class offering Operations for the Server Directory
|
|
|
|
*
|
|
|
|
* @author ManiaControl Team <mail@maniacontrol.com>
|
2019-01-05 21:02:24 +01:00
|
|
|
* @copyright 2014-2019 ManiaControl Team
|
2014-06-20 15:58:41 +02:00
|
|
|
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
|
|
|
*/
|
2017-03-26 19:44:55 +02:00
|
|
|
class Directory implements CallbackListener, UsageInformationAble {
|
|
|
|
use UsageInformationTrait;
|
|
|
|
|
2014-08-02 22:31:46 +02:00
|
|
|
/*
|
2014-07-25 16:28:47 +02:00
|
|
|
* Private properties
|
2014-06-20 15:58:41 +02:00
|
|
|
*/
|
2014-08-02 22:31:46 +02:00
|
|
|
/** @var ManiaControl $maniaControl */
|
2014-06-20 15:58:41 +02:00
|
|
|
private $maniaControl = null;
|
|
|
|
|
|
|
|
/**
|
2014-08-03 01:34:18 +02:00
|
|
|
* Construct 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
|
|
|
|
2014-08-03 01:34:18 +02:00
|
|
|
// Callbacks
|
2014-08-13 11:05:52 +02:00
|
|
|
$this->maniaControl->getCallbackManager()->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() {
|
2014-08-13 11:05:52 +02:00
|
|
|
return $this->maniaControl->getClient()->getMapsDirectory();
|
2014-06-20 15:58:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieve the Skins Folder Path
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getSkinsFolder() {
|
2014-08-13 11:05:52 +02:00
|
|
|
return $this->maniaControl->getClient()->getSkinsDirectory();
|
2014-06-20 15:58:41 +02:00
|
|
|
}
|
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() {
|
2017-05-15 19:30:22 +02:00
|
|
|
return $this->getUserDataFolder() . '..' . DIRECTORY_SEPARATOR . 'Logs' . DIRECTORY_SEPARATOR;
|
2014-06-20 16:14:15 +02:00
|
|
|
}
|
|
|
|
|
2014-07-25 16:28:47 +02:00
|
|
|
/**
|
2017-05-15 19:30:22 +02:00
|
|
|
* Retrieve the GameData Folder Path
|
2014-07-25 16:28:47 +02:00
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
2017-05-15 19:30:22 +02:00
|
|
|
public function getGameDataFolder(){
|
|
|
|
return $this->getUserDataFolder() . '..' . DIRECTORY_SEPARATOR . 'GameData' . DIRECTORY_SEPARATOR;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieve the User Data Folder Path
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getUserDataFolder() {
|
2014-08-13 11:05:52 +02:00
|
|
|
return $this->maniaControl->getClient()->gameDataDirectory();
|
2014-07-25 16:28:47 +02:00
|
|
|
}
|
|
|
|
|
2017-05-15 19:30:22 +02:00
|
|
|
/**
|
|
|
|
* Retrieve the Scripts Folder Path
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getScriptsFolder(){
|
|
|
|
return $this->getGameDataFolder() . 'Scripts' . DIRECTORY_SEPARATOR;
|
|
|
|
}
|
|
|
|
|
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() {
|
2017-05-15 19:30:22 +02:00
|
|
|
return $this->getUserDataFolder() . '..' . DIRECTORY_SEPARATOR . 'CommonData' . DIRECTORY_SEPARATOR . 'Cache' . DIRECTORY_SEPARATOR;
|
2014-06-20 16:14:15 +02:00
|
|
|
}
|
2014-06-20 15:58:41 +02:00
|
|
|
}
|