From 6aeea1562170d5d1542a0ee2b361b886248946e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Steffen=20Schro=CC=88der?= Date: Mon, 23 Jun 2014 15:45:40 +0200 Subject: [PATCH] improved map restart param parsing --- application/core/Callbacks/LibXmlRpcCallbacks.php | 3 +++ application/core/Maps/MapManager.php | 13 +++++++++---- application/core/Utils/Formatter.php | 3 +-- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/application/core/Callbacks/LibXmlRpcCallbacks.php b/application/core/Callbacks/LibXmlRpcCallbacks.php index fe7bae3f..24984921 100644 --- a/application/core/Callbacks/LibXmlRpcCallbacks.php +++ b/application/core/Callbacks/LibXmlRpcCallbacks.php @@ -45,6 +45,9 @@ class LibXmlRpcCallbacks implements CallbackListener { break; case 'BeginMap': case 'LibXmlRpc_BeginMap': + if (!isset($data[2])) { + $data[2] = 'False'; + } $this->maniaControl->mapManager->handleScriptBeginMap($data[1], $data[2]); break; case 'LibXmlRpc_BeginSubmatch': diff --git a/application/core/Maps/MapManager.php b/application/core/Maps/MapManager.php index c50d0f7e..2001a5e4 100644 --- a/application/core/Maps/MapManager.php +++ b/application/core/Maps/MapManager.php @@ -12,6 +12,7 @@ use ManiaControl\ManiaExchange\ManiaExchangeList; use ManiaControl\ManiaExchange\ManiaExchangeManager; use ManiaControl\ManiaExchange\MXMapInfo; use ManiaControl\Players\Player; +use ManiaControl\Utils\Formatter; use Maniaplanet\DedicatedServer\InvalidArgumentException; use Maniaplanet\DedicatedServer\Xmlrpc\Exception; use Maniaplanet\DedicatedServer\Xmlrpc\FileException; @@ -245,7 +246,9 @@ class MapManager implements CallbackListener { public function addMapFromMx($mapId, $login, $update = false) { if (is_numeric($mapId)) { // Check if map exists - $this->maniaControl->mapManager->mxManager->fetchMapInfo($mapId, function (MXMapInfo $mapInfo = null) use (&$login, &$update) { + $this->maniaControl->mapManager->mxManager->fetchMapInfo($mapId, function (MXMapInfo $mapInfo = null) use ( + &$login, &$update + ) { if (!$mapInfo || !isset($mapInfo->uploaded)) { // Invalid id $this->maniaControl->chat->sendError('Invalid MX-Id!', $login); @@ -253,7 +256,9 @@ class MapManager implements CallbackListener { } // Download the file - $this->maniaControl->fileReader->loadFile($mapInfo->downloadurl, function ($file, $error) use (&$login, &$mapInfo, &$update) { + $this->maniaControl->fileReader->loadFile($mapInfo->downloadurl, function ($file, $error) use ( + &$login, &$mapInfo, &$update + ) { if (!$file || $error) { // Download error $this->maniaControl->chat->sendError("Download failed: '{$error}'!", $login); @@ -643,10 +648,10 @@ class MapManager implements CallbackListener { * Handle Script BeginMap callback * * @param string $mapUid - * @param bool $restart + * @param string $restart */ public function handleScriptBeginMap($mapUid, $restart) { - $this->beginMap($mapUid, strtolower($restart) === 'true' ? true : false); + $this->beginMap($mapUid, Formatter::parseBoolean($restart)); } /** diff --git a/application/core/Utils/Formatter.php b/application/core/Utils/Formatter.php index 6b0a4963..4977c0ef 100644 --- a/application/core/Utils/Formatter.php +++ b/application/core/Utils/Formatter.php @@ -168,8 +168,7 @@ abstract class Formatter { if (is_string($value)) { $value = strtolower($value); } - $bool = filter_var($value, FILTER_VALIDATE_BOOLEAN); - return $bool; + return filter_var($value, FILTER_VALIDATE_BOOLEAN); } /**