improved map restart param parsing

This commit is contained in:
Steffen Schröder 2014-06-23 15:45:40 +02:00
parent e25b352a7a
commit 6aeea15621
3 changed files with 13 additions and 6 deletions

View File

@ -45,6 +45,9 @@ class LibXmlRpcCallbacks implements CallbackListener {
break; break;
case 'BeginMap': case 'BeginMap':
case 'LibXmlRpc_BeginMap': case 'LibXmlRpc_BeginMap':
if (!isset($data[2])) {
$data[2] = 'False';
}
$this->maniaControl->mapManager->handleScriptBeginMap($data[1], $data[2]); $this->maniaControl->mapManager->handleScriptBeginMap($data[1], $data[2]);
break; break;
case 'LibXmlRpc_BeginSubmatch': case 'LibXmlRpc_BeginSubmatch':

View File

@ -12,6 +12,7 @@ use ManiaControl\ManiaExchange\ManiaExchangeList;
use ManiaControl\ManiaExchange\ManiaExchangeManager; use ManiaControl\ManiaExchange\ManiaExchangeManager;
use ManiaControl\ManiaExchange\MXMapInfo; use ManiaControl\ManiaExchange\MXMapInfo;
use ManiaControl\Players\Player; use ManiaControl\Players\Player;
use ManiaControl\Utils\Formatter;
use Maniaplanet\DedicatedServer\InvalidArgumentException; use Maniaplanet\DedicatedServer\InvalidArgumentException;
use Maniaplanet\DedicatedServer\Xmlrpc\Exception; use Maniaplanet\DedicatedServer\Xmlrpc\Exception;
use Maniaplanet\DedicatedServer\Xmlrpc\FileException; use Maniaplanet\DedicatedServer\Xmlrpc\FileException;
@ -245,7 +246,9 @@ class MapManager implements CallbackListener {
public function addMapFromMx($mapId, $login, $update = false) { public function addMapFromMx($mapId, $login, $update = false) {
if (is_numeric($mapId)) { if (is_numeric($mapId)) {
// Check if map exists // 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)) { if (!$mapInfo || !isset($mapInfo->uploaded)) {
// Invalid id // Invalid id
$this->maniaControl->chat->sendError('Invalid MX-Id!', $login); $this->maniaControl->chat->sendError('Invalid MX-Id!', $login);
@ -253,7 +256,9 @@ class MapManager implements CallbackListener {
} }
// Download the file // 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) { if (!$file || $error) {
// Download error // Download error
$this->maniaControl->chat->sendError("Download failed: '{$error}'!", $login); $this->maniaControl->chat->sendError("Download failed: '{$error}'!", $login);
@ -643,10 +648,10 @@ class MapManager implements CallbackListener {
* Handle Script BeginMap callback * Handle Script BeginMap callback
* *
* @param string $mapUid * @param string $mapUid
* @param bool $restart * @param string $restart
*/ */
public function handleScriptBeginMap($mapUid, $restart) { public function handleScriptBeginMap($mapUid, $restart) {
$this->beginMap($mapUid, strtolower($restart) === 'true' ? true : false); $this->beginMap($mapUid, Formatter::parseBoolean($restart));
} }
/** /**

View File

@ -168,8 +168,7 @@ abstract class Formatter {
if (is_string($value)) { if (is_string($value)) {
$value = strtolower($value); $value = strtolower($value);
} }
$bool = filter_var($value, FILTER_VALIDATE_BOOLEAN); return filter_var($value, FILTER_VALIDATE_BOOLEAN);
return $bool;
} }
/** /**