2017-03-26 13:11:30 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace ManiaControl\Script;
|
|
|
|
|
2017-04-13 19:48:37 +02:00
|
|
|
use ManiaControl\Callbacks\Structures\ManiaPlanet\ModeUseTeamsStructure;
|
2017-03-26 19:44:55 +02:00
|
|
|
use ManiaControl\General\UsageInformationAble;
|
|
|
|
use ManiaControl\General\UsageInformationTrait;
|
2017-03-26 13:11:30 +02:00
|
|
|
use ManiaControl\Logger;
|
|
|
|
use ManiaControl\ManiaControl;
|
|
|
|
use Maniaplanet\DedicatedServer\Xmlrpc\GameModeException;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Manager for Game Mode Script related Stuff
|
|
|
|
*
|
|
|
|
* @author ManiaControl Team <mail@maniacontrol.com>
|
|
|
|
* @copyright 2014-2017 ManiaControl Team
|
|
|
|
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
|
|
|
*/
|
2017-03-26 19:44:55 +02:00
|
|
|
class ScriptManager implements UsageInformationAble {
|
|
|
|
use UsageInformationTrait;
|
|
|
|
|
2017-03-26 13:11:30 +02:00
|
|
|
/*
|
|
|
|
* Private properties
|
|
|
|
*/
|
|
|
|
/** @var ManiaControl $maniaControl */
|
|
|
|
private $maniaControl = null;
|
|
|
|
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() {
|
|
|
|
if (!$this->isScriptMode()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
$scriptSettings = $this->maniaControl->getClient()->getModeScriptSettings();
|
|
|
|
} catch (GameModeException $e) {
|
|
|
|
var_dump("test");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
//TODO remove later, than only the last 2 lines are needed in future
|
|
|
|
if (array_key_exists('S_UseScriptCallbacks', $scriptSettings)) {
|
|
|
|
$scriptSettings['S_UseScriptCallbacks'] = true;
|
|
|
|
$this->maniaControl->getClient()->setModeScriptSettings($scriptSettings);
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->maniaControl->getModeScriptEventManager()->enableCallbacks();
|
|
|
|
Logger::logInfo("Script Callbacks successfully enabled!");
|
2017-04-13 19:48:37 +02:00
|
|
|
|
|
|
|
//Checks if the Server is currently in TeamMode and sets it
|
|
|
|
$this->maniaControl->getModeScriptEventManager()->isTeamMode()->setCallable(function (ModeUseTeamsStructure $structure) {
|
|
|
|
if ($structure->modeIsUsingTeams()) {
|
|
|
|
$this->maniaControl->getServer()->setTeamMode(true);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2017-03-26 13:11:30 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-04-13 19:48:37 +02:00
|
|
|
|
2017-03-26 13:11:30 +02:00
|
|
|
/**
|
|
|
|
* Check whether the Server is running in Script Mode
|
|
|
|
*
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function isScriptMode() {
|
|
|
|
if (is_null($this->isScriptMode)) {
|
|
|
|
$gameMode = $this->maniaControl->getClient()->getGameMode();
|
|
|
|
$this->isScriptMode = ($gameMode === 0);
|
|
|
|
}
|
|
|
|
return $this->isScriptMode;
|
|
|
|
}
|
|
|
|
}
|