2014-05-06 02:17:11 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace ManiaControl\Server;
|
|
|
|
|
|
|
|
use ManiaControl\ManiaControl;
|
2014-05-09 17:30:31 +02:00
|
|
|
use Maniaplanet\DedicatedServer\Xmlrpc\Exception;
|
2014-05-06 02:17:11 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Manager for Game Mode Script related Stuff
|
|
|
|
*
|
|
|
|
* @author ManiaControl Team <mail@maniacontrol.com>
|
|
|
|
* @copyright 2014 ManiaControl Team
|
|
|
|
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
|
|
|
*/
|
|
|
|
class ScriptManager {
|
|
|
|
/*
|
|
|
|
* Private Properties
|
|
|
|
*/
|
|
|
|
public $maniaControl = null;
|
|
|
|
|
2014-05-11 14:41:14 +02:00
|
|
|
/*
|
|
|
|
* Private Properties
|
|
|
|
*/
|
|
|
|
private $isScriptMode = null;
|
|
|
|
|
2014-05-06 02:17:11 +02:00
|
|
|
/**
|
|
|
|
* Construct a new Script Manager
|
|
|
|
*
|
|
|
|
* @param ManiaControl $maniaControl
|
|
|
|
*/
|
|
|
|
public function __construct(ManiaControl $maniaControl) {
|
|
|
|
$this->maniaControl = $maniaControl;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Enable Script Callbacks
|
|
|
|
*
|
|
|
|
* @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;
|
|
|
|
}
|
2014-05-11 14:41:14 +02:00
|
|
|
$scriptSettings = $this->maniaControl->client->getModeScriptSettings();
|
2014-05-06 02:17:11 +02:00
|
|
|
|
|
|
|
if (!array_key_exists('S_UseScriptCallbacks', $scriptSettings)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
$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
|
|
|
|
|
|
|
try {
|
|
|
|
$this->maniaControl->client->setModeScriptSettings($scriptSettings);
|
|
|
|
} catch (Exception $e) {
|
|
|
|
// TODO temp added 19.04.2014
|
|
|
|
$this->maniaControl->errorHandler->handleException($e, false);
|
2014-05-09 17:30:31 +02:00
|
|
|
trigger_error("Couldn't set Mode Script Settings to {$actionName}able Script Sallbacks. " . $e->getMessage());
|
2014-05-06 02:17:11 +02:00
|
|
|
return false;
|
|
|
|
}
|
2014-05-09 17:30:31 +02:00
|
|
|
$this->maniaControl->log("Script Callbacks successfully {$actionName}abled!");
|
|
|
|
return true;
|
2014-05-06 02:17:11 +02:00
|
|
|
}
|
2014-05-11 14:41:14 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if the Server is running in Script Mode
|
|
|
|
*
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function isScriptMode() {
|
|
|
|
if ($this->isScriptMode === null) {
|
|
|
|
$gameMode = $this->maniaControl->client->getGameMode();
|
|
|
|
$this->isScriptMode = ($gameMode === 0);
|
|
|
|
}
|
|
|
|
return $this->isScriptMode;
|
|
|
|
}
|
2014-05-06 02:17:11 +02:00
|
|
|
}
|