From 52be0fab1023765bbe8ec52bbc989c29b1d27f69 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Steffen=20Schro=CC=88der?= Date: Sun, 11 May 2014 14:41:14 +0200 Subject: [PATCH] improved script mode check --- application/core/Server/ScriptManager.php | 24 +++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/application/core/Server/ScriptManager.php b/application/core/Server/ScriptManager.php index 9b4b21ae..86d121e8 100644 --- a/application/core/Server/ScriptManager.php +++ b/application/core/Server/ScriptManager.php @@ -4,7 +4,6 @@ namespace ManiaControl\Server; use ManiaControl\ManiaControl; use Maniaplanet\DedicatedServer\Xmlrpc\Exception; -use Maniaplanet\DedicatedServer\Xmlrpc\NotInScriptModeException; /** * Manager for Game Mode Script related Stuff @@ -19,6 +18,11 @@ class ScriptManager { */ public $maniaControl = null; + /* + * Private Properties + */ + private $isScriptMode = null; + /** * Construct a new Script Manager * @@ -35,11 +39,10 @@ class ScriptManager { * @return bool */ public function enableScriptCallbacks($enable = true) { - try { - $scriptSettings = $this->maniaControl->client->getModeScriptSettings(); - } catch (NotInScriptModeException $e) { + if (!$this->isScriptMode()) { return false; } + $scriptSettings = $this->maniaControl->client->getModeScriptSettings(); if (!array_key_exists('S_UseScriptCallbacks', $scriptSettings)) { return false; @@ -59,4 +62,17 @@ class ScriptManager { $this->maniaControl->log("Script Callbacks successfully {$actionName}abled!"); 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; + } }