improved script mode check

This commit is contained in:
Steffen Schröder 2014-05-11 14:41:14 +02:00
parent 899d14c5c3
commit 52be0fab10

View File

@ -4,7 +4,6 @@ namespace ManiaControl\Server;
use ManiaControl\ManiaControl; use ManiaControl\ManiaControl;
use Maniaplanet\DedicatedServer\Xmlrpc\Exception; use Maniaplanet\DedicatedServer\Xmlrpc\Exception;
use Maniaplanet\DedicatedServer\Xmlrpc\NotInScriptModeException;
/** /**
* Manager for Game Mode Script related Stuff * Manager for Game Mode Script related Stuff
@ -19,6 +18,11 @@ class ScriptManager {
*/ */
public $maniaControl = null; public $maniaControl = null;
/*
* Private Properties
*/
private $isScriptMode = null;
/** /**
* Construct a new Script Manager * Construct a new Script Manager
* *
@ -35,11 +39,10 @@ class ScriptManager {
* @return bool * @return bool
*/ */
public function enableScriptCallbacks($enable = true) { public function enableScriptCallbacks($enable = true) {
try { if (!$this->isScriptMode()) {
$scriptSettings = $this->maniaControl->client->getModeScriptSettings();
} catch (NotInScriptModeException $e) {
return false; return false;
} }
$scriptSettings = $this->maniaControl->client->getModeScriptSettings();
if (!array_key_exists('S_UseScriptCallbacks', $scriptSettings)) { if (!array_key_exists('S_UseScriptCallbacks', $scriptSettings)) {
return false; return false;
@ -59,4 +62,17 @@ class ScriptManager {
$this->maniaControl->log("Script Callbacks successfully {$actionName}abled!"); $this->maniaControl->log("Script Callbacks successfully {$actionName}abled!");
return true; return true;
} }
/**
* 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;
}
} }