TrackManiaControl/core/Server/ScriptManager.php

75 lines
1.8 KiB
PHP
Raw Normal View History

<?php
namespace ManiaControl\Server;
use ManiaControl\Logger;
use ManiaControl\ManiaControl;
2015-06-18 16:18:19 +02:00
use Maniaplanet\DedicatedServer\Xmlrpc\GameModeException;
/**
* Manager for Game Mode Script related Stuff
*
* @author ManiaControl Team <mail@maniacontrol.com>
2017-02-04 11:49:23 +01:00
* @copyright 2014-2017 ManiaControl Team
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
*/
class ScriptManager {
/*
* Private properties
*/
/** @var ManiaControl $maniaControl */
private $maniaControl = null;
2014-05-11 14:41:14 +02:00
private $isScriptMode = null;
/**
* Construct a new script manager instance
*
* @param ManiaControl $maniaControl
*/
public function __construct(ManiaControl $maniaControl) {
$this->maniaControl = $maniaControl;
}
/**
* Enable script callbacks
*
* @param bool $enable
* @return bool
*/
public function enableScriptCallbacks() {
2014-05-11 14:41:14 +02:00
if (!$this->isScriptMode()) {
return false;
}
2015-06-18 16:18:19 +02:00
try {
$scriptSettings = $this->maniaControl->getClient()->getModeScriptSettings();
} catch (GameModeException $e) {
2017-03-23 20:39:32 +01:00
var_dump("test");
2015-06-18 16:18:19 +02:00
return false;
}
//TODO remove later, than only the last 2 lines are needed in future
2017-03-23 20:39:32 +01:00
if (array_key_exists('S_UseScriptCallbacks', $scriptSettings)) {
$scriptSettings['S_UseScriptCallbacks'] = true;
$this->maniaControl->getClient()->setModeScriptSettings($scriptSettings);
}
2017-03-22 17:57:21 +01:00
$this->maniaControl->getModeScriptEventManager()->enableCallbacks();
Logger::logInfo("Script Callbacks successfully enabled!");
2014-05-09 17:30:31 +02:00
return true;
}
2014-05-11 14:41:14 +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;
}
}