2014-05-06 02:17:11 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace ManiaControl\Server;
|
|
|
|
|
2014-08-05 01:49:13 +02:00
|
|
|
use ManiaControl\Logger;
|
2014-05-06 02:17:11 +02:00
|
|
|
use ManiaControl\ManiaControl;
|
2015-06-18 16:18:19 +02:00
|
|
|
use Maniaplanet\DedicatedServer\Xmlrpc\GameModeException;
|
2014-05-06 02:17:11 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Manager for Game Mode Script related Stuff
|
|
|
|
*
|
|
|
|
* @author ManiaControl Team <mail@maniacontrol.com>
|
2016-05-04 09:57:31 +02:00
|
|
|
* @copyright 2014-2016 ManiaControl Team
|
2014-05-06 02:17:11 +02:00
|
|
|
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
|
|
|
*/
|
|
|
|
class ScriptManager {
|
|
|
|
/*
|
2014-08-02 22:31:46 +02:00
|
|
|
* Private properties
|
2014-05-06 02:17:11 +02:00
|
|
|
*/
|
2014-08-02 22:31:46 +02:00
|
|
|
/** @var ManiaControl $maniaControl */
|
2014-07-25 16:28:47 +02:00
|
|
|
private $maniaControl = null;
|
2014-05-11 14:41:14 +02:00
|
|
|
private $isScriptMode = null;
|
|
|
|
|
2014-05-06 02:17:11 +02:00
|
|
|
/**
|
2014-07-25 16:28:47 +02:00
|
|
|
* Construct a new script manager instance
|
2014-05-06 02:17:11 +02:00
|
|
|
*
|
|
|
|
* @param ManiaControl $maniaControl
|
|
|
|
*/
|
|
|
|
public function __construct(ManiaControl $maniaControl) {
|
|
|
|
$this->maniaControl = $maniaControl;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-07-25 16:28:47 +02:00
|
|
|
* Enable script callbacks
|
2014-05-06 02:17:11 +02:00
|
|
|
*
|
|
|
|
* @param bool $enable
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function enableScriptCallbacks($enable = true) {
|
2014-05-11 14:41:14 +02:00
|
|
|
if (!$this->isScriptMode()) {
|
2014-05-06 02:17:11 +02:00
|
|
|
return false;
|
|
|
|
}
|
2015-06-18 16:18:19 +02:00
|
|
|
|
|
|
|
try {
|
|
|
|
$scriptSettings = $this->maniaControl->getClient()->getModeScriptSettings();
|
|
|
|
} catch (GameModeException $e) {
|
|
|
|
return false;
|
|
|
|
}
|
2014-05-06 02:17:11 +02:00
|
|
|
|
|
|
|
if (!array_key_exists('S_UseScriptCallbacks', $scriptSettings)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-06-18 16:18:19 +02:00
|
|
|
$scriptSettings['S_UseScriptCallbacks'] = (bool) $enable;
|
2014-05-09 17:30:31 +02:00
|
|
|
$actionName = ($enable ? 'en' : 'dis');
|
2014-05-06 02:17:11 +02:00
|
|
|
|
2014-08-13 11:05:52 +02:00
|
|
|
$this->maniaControl->getClient()->setModeScriptSettings($scriptSettings);
|
2014-08-05 01:49:13 +02:00
|
|
|
Logger::logInfo("Script Callbacks successfully {$actionName}abled!");
|
2014-05-09 17:30:31 +02:00
|
|
|
return true;
|
2014-05-06 02:17:11 +02:00
|
|
|
}
|
2014-05-11 14:41:14 +02:00
|
|
|
|
|
|
|
/**
|
2014-07-25 16:28:47 +02:00
|
|
|
* Check whether the Server is running in Script Mode
|
2014-05-11 14:41:14 +02:00
|
|
|
*
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function isScriptMode() {
|
2014-06-22 18:37:56 +02:00
|
|
|
if (is_null($this->isScriptMode)) {
|
2014-08-13 11:05:52 +02:00
|
|
|
$gameMode = $this->maniaControl->getClient()->getGameMode();
|
2014-05-11 14:41:14 +02:00
|
|
|
$this->isScriptMode = ($gameMode === 0);
|
|
|
|
}
|
|
|
|
return $this->isScriptMode;
|
|
|
|
}
|
2014-05-06 02:17:11 +02:00
|
|
|
}
|