diff --git a/application/core/Chat.php b/application/core/Chat.php index 3dd1249f..084acc67 100644 --- a/application/core/Chat.php +++ b/application/core/Chat.php @@ -208,8 +208,7 @@ class Chat { * @param int $minLevel * @param bool|string $prefix */ - public function sendExceptionToAdmins(\Exception $exception, $minLevel = AuthenticationManager::AUTH_LEVEL_MODERATOR, - $prefix = true) { + public function sendExceptionToAdmins(\Exception $exception, $minLevel = AuthenticationManager::AUTH_LEVEL_MODERATOR, $prefix = true) { $format = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_FORMAT_ERROR); $message = $format . "Exception: '{$exception->getMessage()}' ({$exception->getCode()})"; $this->sendMessageToAdmins($message, $minLevel, $prefix); diff --git a/application/core/Commands/CommandManager.php b/application/core/Commands/CommandManager.php index 7124504f..b62b6b34 100644 --- a/application/core/Commands/CommandManager.php +++ b/application/core/Commands/CommandManager.php @@ -61,8 +61,7 @@ class CommandManager implements CallbackListener { * @param string $description * @return bool */ - public function registerCommandListener($commandName, CommandListener $listener, $method, $adminCommand = false, - $description = null) { + public function registerCommandListener($commandName, CommandListener $listener, $method, $adminCommand = false, $description = null) { if (is_array($commandName)) { $success = false; foreach ($commandName as $command) { diff --git a/application/core/Files/AsynchronousFileReader.php b/application/core/Files/AsynchronousFileReader.php index ae416fe4..15b5390e 100644 --- a/application/core/Files/AsynchronousFileReader.php +++ b/application/core/Files/AsynchronousFileReader.php @@ -120,8 +120,7 @@ class AsynchronousFileReader { array_push($this->requests, $request); } - public function postDataTest(Request $request, $url, callable $function, $content, $compression = false, - $contentType = 'text/xml; charset=UTF-8;') { + public function postDataTest(Request $request, $url, callable $function, $content, $compression = false, $contentType = 'text/xml; charset=UTF-8;') { $headers = array(); array_push($headers, 'Content-Type: ' . $contentType); @@ -163,8 +162,7 @@ class AsynchronousFileReader { * @param bool $compression * @param string $contentType */ - public function postData($url, callable $function, $content, $compression = false, - $contentType = 'text/xml; charset=UTF-8;') { + public function postData($url, callable $function, $content, $compression = false, $contentType = 'text/xml; charset=UTF-8;') { $headers = array(); array_push($headers, 'Content-Type: ' . $contentType); diff --git a/application/core/Files/BackupUtil.php b/application/core/Files/BackupUtil.php index 4a93ddc7..ef4f82bf 100644 --- a/application/core/Files/BackupUtil.php +++ b/application/core/Files/BackupUtil.php @@ -68,8 +68,7 @@ abstract class BackupUtil { * @param array $baseFileNames * @return bool */ - private static function zipDirectory(\ZipArchive &$zipArchive, $folderName, $prefixLength, array $excludes = array(), - array $baseFileNames = array()) { + private static function zipDirectory(\ZipArchive &$zipArchive, $folderName, $prefixLength, array $excludes = array(), array $baseFileNames = array()) { $folderHandle = opendir($folderName); if (!is_resource($folderHandle)) { Logger::logError("Couldn't open folder '{$folderName}' for backup!"); diff --git a/application/core/ManiaExchange/ManiaExchangeList.php b/application/core/ManiaExchange/ManiaExchangeList.php index 77059efe..29d33246 100644 --- a/application/core/ManiaExchange/ManiaExchangeList.php +++ b/application/core/ManiaExchange/ManiaExchangeList.php @@ -132,12 +132,12 @@ class ManiaExchangeList implements CallbackListener, ManialinkPageAnswerListener // search for matching maps $this->maniaControl->getMapManager()->getMXManager()->fetchMapsAsync(function (array $maps) use (&$player) { - if (!$maps) { - $this->maniaControl->getChat()->sendError('No maps found, or MX is down!', $player->login); - return; - } - $this->showManiaExchangeList($maps, $player); - }, $searchString, $author, $environment); + if (!$maps) { + $this->maniaControl->getChat()->sendError('No maps found, or MX is down!', $player->login); + return; + } + $this->showManiaExchangeList($maps, $player); + }, $searchString, $author, $environment); } /** diff --git a/application/core/ManiaExchange/ManiaExchangeManager.php b/application/core/ManiaExchange/ManiaExchangeManager.php index 7135d9a6..b69d77ac 100644 --- a/application/core/ManiaExchange/ManiaExchangeManager.php +++ b/application/core/ManiaExchange/ManiaExchangeManager.php @@ -159,32 +159,32 @@ class ManiaExchangeManager { $url = "http://api.mania-exchange.com/{$titlePrefix}/maps/?ids={$string}"; $this->maniaControl->getFileReader()->loadFile($url, function ($mapInfo, $error) use ($titlePrefix, $url) { - if ($error) { - trigger_error("Error: '{$error}' for Url '{$url}'"); - return; - } - if (!$mapInfo) { - return; - } + if ($error) { + trigger_error("Error: '{$error}' for Url '{$url}'"); + return; + } + if (!$mapInfo) { + return; + } - $mxMapList = json_decode($mapInfo); - if ($mxMapList === null) { - trigger_error("Can't decode searched JSON Data from Url '{$url}'"); - return; - } + $mxMapList = json_decode($mapInfo); + if ($mxMapList === null) { + trigger_error("Can't decode searched JSON Data from Url '{$url}'"); + return; + } - $maps = array(); - foreach ($mxMapList as $map) { - if ($map) { - $mxMapObject = new MXMapInfo($titlePrefix, $map); - if ($mxMapObject) { - array_push($maps, $mxMapObject); - } - } - } + $maps = array(); + foreach ($mxMapList as $map) { + if ($map) { + $mxMapObject = new MXMapInfo($titlePrefix, $map); + if ($mxMapObject) { + array_push($maps, $mxMapObject); + } + } + } - $this->updateMapObjectsWithManiaExchangeIds($maps); - }, AsynchronousFileReader::CONTENT_TYPE_JSON); + $this->updateMapObjectsWithManiaExchangeIds($maps); + }, AsynchronousFileReader::CONTENT_TYPE_JSON); } /** @@ -252,27 +252,26 @@ class ManiaExchangeManager { $url = 'http://api.mania-exchange.com/' . $titlePrefix . '/maps/?ids=' . $mapId; $this->maniaControl->getFileReader()->loadFile($url, function ($mapInfo, $error) use (&$function, $titlePrefix, $url) { - $mxMapInfo = null; - if ($error) { - trigger_error($error); - } else { - $mxMapList = json_decode($mapInfo); - if (!is_array($mxMapList)) { - trigger_error('Cannot decode searched JSON data from ' . $url); - } else if (!empty($mxMapList)) { - $mxMapInfo = new MXMapInfo($titlePrefix, $mxMapList[0]); - } - } - call_user_func($function, $mxMapInfo); - }, AsynchronousFileReader::CONTENT_TYPE_JSON); + $mxMapInfo = null; + if ($error) { + trigger_error($error); + } else { + $mxMapList = json_decode($mapInfo); + if (!is_array($mxMapList)) { + trigger_error('Cannot decode searched JSON data from ' . $url); + } else if (!empty($mxMapList)) { + $mxMapInfo = new MXMapInfo($titlePrefix, $mxMapList[0]); + } + } + call_user_func($function, $mxMapInfo); + }, AsynchronousFileReader::CONTENT_TYPE_JSON); } /** * @deprecated * @see \ManiaControl\ManiaExchange\ManiaExchangeManager::fetchMapsAsync() */ - public function getMapsAsync(callable $function, $name = '', $author = '', $env = '', $maxMapsReturned = 100, - $searchOrder = self::SEARCH_ORDER_UPDATED_NEWEST) { + public function getMapsAsync(callable $function, $name = '', $author = '', $env = '', $maxMapsReturned = 100, $searchOrder = self::SEARCH_ORDER_UPDATED_NEWEST) { $this->fetchMapsAsync($function, $name, $author, $env, $maxMapsReturned, $searchOrder); return true; } @@ -287,8 +286,7 @@ class ManiaExchangeManager { * @param int $maxMapsReturned * @param int $searchOrder */ - public function fetchMapsAsync(callable $function, $name = '', $author = '', $env = '', $maxMapsReturned = 100, - $searchOrder = self::SEARCH_ORDER_UPDATED_NEWEST) { + public function fetchMapsAsync(callable $function, $name = '', $author = '', $env = '', $maxMapsReturned = 100, $searchOrder = self::SEARCH_ORDER_UPDATED_NEWEST) { // TODO: remove $env because it's not really used? // Get Title Id @@ -326,34 +324,34 @@ class ManiaExchangeManager { } $this->maniaControl->getFileReader()->loadFile($url, function ($mapInfo, $error) use (&$function, $titlePrefix) { - if ($error) { - trigger_error($error); - return; - } + if ($error) { + trigger_error($error); + return; + } - $mxMapList = json_decode($mapInfo); + $mxMapList = json_decode($mapInfo); - if (!isset($mxMapList->results)) { - trigger_error('Cannot decode searched JSON data'); - return; - } + if (!isset($mxMapList->results)) { + trigger_error('Cannot decode searched JSON data'); + return; + } - $mxMapList = $mxMapList->results; + $mxMapList = $mxMapList->results; - if ($mxMapList === null) { - trigger_error('Cannot decode searched JSON data'); - return; - } + if ($mxMapList === null) { + trigger_error('Cannot decode searched JSON data'); + return; + } - $maps = array(); - foreach ($mxMapList as $map) { - if (!empty($map)) { - array_push($maps, new MXMapInfo($titlePrefix, $map)); - } - } + $maps = array(); + foreach ($mxMapList as $map) { + if (!empty($map)) { + array_push($maps, new MXMapInfo($titlePrefix, $map)); + } + } - call_user_func($function, $maps); - }, AsynchronousFileReader::CONTENT_TYPE_JSON); + call_user_func($function, $maps); + }, AsynchronousFileReader::CONTENT_TYPE_JSON); } /** diff --git a/application/core/Manialinks/CustomUIManager.php b/application/core/Manialinks/CustomUIManager.php index 8373fa51..afefa314 100644 --- a/application/core/Manialinks/CustomUIManager.php +++ b/application/core/Manialinks/CustomUIManager.php @@ -87,8 +87,8 @@ class CustomUIManager implements CallbackListener, TimerListener { //TODO: validate necessity //send it again after 500ms $this->maniaControl->getTimerManager()->registerOneTimeListening($this, function () use (&$player) { - $this->updateManialink($player); - }, 500); + $this->updateManialink($player); + }, 500); } /** diff --git a/application/core/Players/PlayerActions.php b/application/core/Players/PlayerActions.php index 00a78b95..de78ba16 100644 --- a/application/core/Players/PlayerActions.php +++ b/application/core/Players/PlayerActions.php @@ -179,8 +179,7 @@ class PlayerActions { * @param int $spectatorState * @param bool $releaseSlot */ - public function forcePlayerToSpectator($adminLogin, $targetLogin, $spectatorState = self::SPECTATOR_BUT_KEEP_SELECTABLE, - $releaseSlot = true) { + public function forcePlayerToSpectator($adminLogin, $targetLogin, $spectatorState = self::SPECTATOR_BUT_KEEP_SELECTABLE, $releaseSlot = true) { $admin = $this->maniaControl->getPlayerManager()->getPlayer($adminLogin); if (!$this->maniaControl->getAuthenticationManager()->checkPermission($admin, self::SETTING_PERMISSION_FORCE_PLAYER_SPEC) ) { diff --git a/application/core/Plugins/PluginManager.php b/application/core/Plugins/PluginManager.php index 6f6779c8..db9d1ff6 100644 --- a/application/core/Plugins/PluginManager.php +++ b/application/core/Plugins/PluginManager.php @@ -475,8 +475,8 @@ class PluginManager { public function fetchPluginList(callable $function) { $url = ManiaControl::URL_WEBSERVICE . 'plugins'; $this->maniaControl->getFileReader()->loadFile($url, function ($dataJson, $error) use (&$function) { - $data = json_decode($dataJson); - call_user_func($function, $data, $error); - }); + $data = json_decode($dataJson); + call_user_func($function, $data, $error); + }); } } diff --git a/application/core/Server/UsageReporter.php b/application/core/Server/UsageReporter.php index cf20d02a..89028f25 100644 --- a/application/core/Server/UsageReporter.php +++ b/application/core/Server/UsageReporter.php @@ -81,10 +81,10 @@ class UsageReporter implements TimerListener { $url = ManiaControl::URL_WEBSERVICE . '/usagereport?info=' . urlencode($info); $this->maniaControl->getFileReader()->loadFile($url, function ($response, $error) { - $response = json_decode($response); - if ($error || !$response) { - Logger::logError('Error while Sending data: ' . print_r($error, true)); - } - }); + $response = json_decode($response); + if ($error || !$response) { + Logger::logError('Error while Sending data: ' . print_r($error, true)); + } + }); } } diff --git a/application/core/Update/PluginUpdateManager.php b/application/core/Update/PluginUpdateManager.php index 6916e3fe..45f85321 100644 --- a/application/core/Update/PluginUpdateManager.php +++ b/application/core/Update/PluginUpdateManager.php @@ -76,53 +76,53 @@ class PluginUpdateManager implements CallbackListener, CommandListener, TimerLis Logger::log($message); $this->maniaControl->getPluginManager()->fetchPluginList(function ($data, $error) use (&$player) { - if (!$data || $error) { - $message = 'Error while checking Plugins for newer Versions!'; - if ($player) { - $this->maniaControl->getChat()->sendError($message, $player); - } - Logger::logError($message); - return; - } + if (!$data || $error) { + $message = 'Error while checking Plugins for newer Versions!'; + if ($player) { + $this->maniaControl->getChat()->sendError($message, $player); + } + Logger::logError($message); + return; + } - $pluginsData = $this->parsePluginsData($data); - $pluginClasses = $this->maniaControl->getPluginManager()->getPluginClasses(); - $pluginUpdates = array(); + $pluginsData = $this->parsePluginsData($data); + $pluginClasses = $this->maniaControl->getPluginManager()->getPluginClasses(); + $pluginUpdates = array(); - foreach ($pluginClasses as $pluginClass) { - /** @var Plugin $pluginClass */ - $pluginId = $pluginClass::getId(); - if (!isset($pluginsData[$pluginId])) { - continue; - } - /** @var PluginUpdateData $pluginData */ - $pluginData = $pluginsData[$pluginId]; - $pluginVersion = $pluginClass::getVersion(); - if ($pluginData->isNewerThan($pluginVersion)) { - $pluginUpdates[$pluginId] = $pluginData; - $message = "There is an Update of '{$pluginData->pluginName}' available! ('{$pluginClass}' - Version {$pluginData->version})"; - if ($player) { - $this->maniaControl->getChat()->sendSuccess($message, $player); - } - Logger::log($message); - } - } + foreach ($pluginClasses as $pluginClass) { + /** @var Plugin $pluginClass */ + $pluginId = $pluginClass::getId(); + if (!isset($pluginsData[$pluginId])) { + continue; + } + /** @var PluginUpdateData $pluginData */ + $pluginData = $pluginsData[$pluginId]; + $pluginVersion = $pluginClass::getVersion(); + if ($pluginData->isNewerThan($pluginVersion)) { + $pluginUpdates[$pluginId] = $pluginData; + $message = "There is an Update of '{$pluginData->pluginName}' available! ('{$pluginClass}' - Version {$pluginData->version})"; + if ($player) { + $this->maniaControl->getChat()->sendSuccess($message, $player); + } + Logger::log($message); + } + } - if (empty($pluginUpdates)) { - $message = 'Plugins Update Check completed: All Plugins are up-to-date!'; - if ($player) { - $this->maniaControl->getChat()->sendSuccess($message, $player); - } - Logger::log($message); - } else { - $updatesCount = count($pluginUpdates); - $message = "Plugins Update Check completed: There are {$updatesCount} Updates available!"; - if ($player) { - $this->maniaControl->getChat()->sendSuccess($message, $player); - } - Logger::log($message); - } - }); + if (empty($pluginUpdates)) { + $message = 'Plugins Update Check completed: All Plugins are up-to-date!'; + if ($player) { + $this->maniaControl->getChat()->sendSuccess($message, $player); + } + Logger::log($message); + } else { + $updatesCount = count($pluginUpdates); + $message = "Plugins Update Check completed: There are {$updatesCount} Updates available!"; + if ($player) { + $this->maniaControl->getChat()->sendSuccess($message, $player); + } + Logger::log($message); + } + }); } /** @@ -241,85 +241,85 @@ class PluginUpdateManager implements CallbackListener, CommandListener, TimerLis */ private function installPlugin(PluginUpdateData $pluginUpdateData, Player $player = null, $update = false) { $this->maniaControl->getFileReader()->loadFile($pluginUpdateData->url, function ($updateFileContent, $error) use ( - &$pluginUpdateData, &$player, &$update - ) { - if (!$updateFileContent || $error) { - $message = "Error loading Update Data for '{$pluginUpdateData->pluginName}': {$error}!"; - if ($player) { - $this->maniaControl->getChat()->sendInformation($message, $player); - } - Logger::logError($message); - return; - } + &$pluginUpdateData, &$player, &$update + ) { + if (!$updateFileContent || $error) { + $message = "Error loading Update Data for '{$pluginUpdateData->pluginName}': {$error}!"; + if ($player) { + $this->maniaControl->getChat()->sendInformation($message, $player); + } + Logger::logError($message); + return; + } - $actionNoun = ($update ? 'Update' : 'Install'); - $actionVerb = ($update ? 'Updating' : 'Installing'); - $actionVerbDone = ($update ? 'updated' : 'installed'); + $actionNoun = ($update ? 'Update' : 'Install'); + $actionVerb = ($update ? 'Updating' : 'Installing'); + $actionVerbDone = ($update ? 'updated' : 'installed'); - $message = "Now {$actionVerb} '{$pluginUpdateData->pluginName}'..."; - if ($player) { - $this->maniaControl->getChat()->sendInformation($message, $player); - } - Logger::log($message); + $message = "Now {$actionVerb} '{$pluginUpdateData->pluginName}'..."; + if ($player) { + $this->maniaControl->getChat()->sendInformation($message, $player); + } + Logger::log($message); - $tempDir = FileUtil::getTempFolder(); - $updateFileName = $tempDir . $pluginUpdateData->zipfile; + $tempDir = FileUtil::getTempFolder(); + $updateFileName = $tempDir . $pluginUpdateData->zipfile; - $bytes = file_put_contents($updateFileName, $updateFileContent); - if (!$bytes || $bytes <= 0) { - $message = "Plugin {$actionNoun} failed: Couldn't save {$actionNoun} Zip!"; - if ($player) { - $this->maniaControl->getChat()->sendError($message, $player); - } - Logger::logError($message); - return; - } + $bytes = file_put_contents($updateFileName, $updateFileContent); + if (!$bytes || $bytes <= 0) { + $message = "Plugin {$actionNoun} failed: Couldn't save {$actionNoun} Zip!"; + if ($player) { + $this->maniaControl->getChat()->sendError($message, $player); + } + Logger::logError($message); + return; + } - $zip = new \ZipArchive(); - $result = $zip->open($updateFileName); - if ($result !== true) { - $message = "Plugin {$actionNoun} failed: Couldn't open {$actionNoun} Zip! ({$result})"; - if ($player) { - $this->maniaControl->getChat()->sendError($message, $player); - } - Logger::logError($message); - return; - } + $zip = new \ZipArchive(); + $result = $zip->open($updateFileName); + if ($result !== true) { + $message = "Plugin {$actionNoun} failed: Couldn't open {$actionNoun} Zip! ({$result})"; + if ($player) { + $this->maniaControl->getChat()->sendError($message, $player); + } + Logger::logError($message); + return; + } - $zip->extractTo(MANIACONTROL_PATH . 'plugins' . DIRECTORY_SEPARATOR); - $zip->close(); - unlink($updateFileName); - FileUtil::deleteTempFolder(); + $zip->extractTo(MANIACONTROL_PATH . 'plugins' . DIRECTORY_SEPARATOR); + $zip->close(); + unlink($updateFileName); + FileUtil::deleteTempFolder(); - $messageExtra = ''; - if ($update) { - $messageExtra = ' (Restart ManiaControl to load the new Version!)'; - } - $message = "Successfully {$actionVerbDone} '{$pluginUpdateData->pluginName}'!{$messageExtra}"; - if ($player) { - $this->maniaControl->getChat()->sendSuccess($message, $player); - } - Logger::log($message); + $messageExtra = ''; + if ($update) { + $messageExtra = ' (Restart ManiaControl to load the new Version!)'; + } + $message = "Successfully {$actionVerbDone} '{$pluginUpdateData->pluginName}'!{$messageExtra}"; + if ($player) { + $this->maniaControl->getChat()->sendSuccess($message, $player); + } + Logger::log($message); - if (!$update) { - $newPluginClasses = $this->maniaControl->getPluginManager()->loadPlugins(); - if (empty($newPluginClasses)) { - $message = "Loading fresh installed Plugin '{$pluginUpdateData->pluginName}' failed!"; - if ($player) { - $this->maniaControl->getChat()->sendError($message, $player); - } - Logger::log($message); - } else { - $message = "Successfully loaded fresh installed Plugin '{$pluginUpdateData->pluginName}'!"; - if ($player) { - $this->maniaControl->getChat()->sendSuccess($message, $player); - } - Logger::log($message); + if (!$update) { + $newPluginClasses = $this->maniaControl->getPluginManager()->loadPlugins(); + if (empty($newPluginClasses)) { + $message = "Loading fresh installed Plugin '{$pluginUpdateData->pluginName}' failed!"; + if ($player) { + $this->maniaControl->getChat()->sendError($message, $player); + } + Logger::log($message); + } else { + $message = "Successfully loaded fresh installed Plugin '{$pluginUpdateData->pluginName}'!"; + if ($player) { + $this->maniaControl->getChat()->sendSuccess($message, $player); + } + Logger::log($message); - $this->maniaControl->getConfigurator()->showMenu($player, InstallMenu::getTitle()); - } - } - }); + $this->maniaControl->getConfigurator()->showMenu($player, InstallMenu::getTitle()); + } + } + }); } /** @@ -356,22 +356,22 @@ class PluginUpdateManager implements CallbackListener, CommandListener, TimerLis $url = ManiaControl::URL_WEBSERVICE . 'plugins/' . $pluginId; $this->maniaControl->getFileReader()->loadFile($url, function ($data, $error) use (&$player) { - if ($error || !$data) { - $message = "Error loading Plugin Install Data! {$error}"; - $this->maniaControl->getChat()->sendError($message, $player); - return; - } + if ($error || !$data) { + $message = "Error loading Plugin Install Data! {$error}"; + $this->maniaControl->getChat()->sendError($message, $player); + return; + } - $data = json_decode($data); - if (!$data) { - $message = "Error loading Plugin Install Data! {$error}"; - $this->maniaControl->getChat()->sendError($message, $player); - return; - } + $data = json_decode($data); + if (!$data) { + $message = "Error loading Plugin Install Data! {$error}"; + $this->maniaControl->getChat()->sendError($message, $player); + return; + } - $pluginUpdateData = new PluginUpdateData($data); - $this->installPlugin($pluginUpdateData, $player); - }); + $pluginUpdateData = new PluginUpdateData($data); + $this->installPlugin($pluginUpdateData, $player); + }); } } diff --git a/application/core/Update/UpdateManager.php b/application/core/Update/UpdateManager.php index 0d689879..7bc12b1a 100644 --- a/application/core/Update/UpdateManager.php +++ b/application/core/Update/UpdateManager.php @@ -141,18 +141,18 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener $url = ManiaControl::URL_WEBSERVICE . 'versions?current=1&channel=' . $updateChannel; $this->maniaControl->getFileReader()->loadFile($url, function ($dataJson, $error) use (&$function) { - if ($error) { - Logger::logError('Error on UpdateCheck: ' . $error); - return; - } - $versions = json_decode($dataJson); - if (!$versions || !isset($versions[0])) { - call_user_func($function); - } else { - $updateData = new UpdateData($versions[0]); - call_user_func($function, $updateData); - } - }); + if ($error) { + Logger::logError('Error on UpdateCheck: ' . $error); + return; + } + $versions = json_decode($dataJson); + if (!$versions || !isset($versions[0])) { + call_user_func($function); + } else { + $updateData = new UpdateData($versions[0]); + call_user_func($function, $updateData); + } + }); } /** @@ -329,66 +329,66 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener $updateData = $this->coreUpdateData; $this->maniaControl->getFileReader()->loadFile($updateData->url, function ($updateFileContent, $error) use ( - $updateData, &$player - ) { - if (!$updateFileContent || $error) { - $message = "Update failed: Couldn't load Update zip! {$error}"; - if ($player) { - $this->maniaControl->getChat()->sendError($message, $player); - } - Logger::logError($message); - return; - } + $updateData, &$player + ) { + if (!$updateFileContent || $error) { + $message = "Update failed: Couldn't load Update zip! {$error}"; + if ($player) { + $this->maniaControl->getChat()->sendError($message, $player); + } + Logger::logError($message); + return; + } - $tempDir = FileUtil::getTempFolder(); - if (!$tempDir) { - $message = "Update failed: Can't save Update zip!"; - if ($player) { - $this->maniaControl->getChat()->sendError($message, $player); - } - Logger::logError($message); - return; - } - $updateFileName = $tempDir . basename($updateData->url); + $tempDir = FileUtil::getTempFolder(); + if (!$tempDir) { + $message = "Update failed: Can't save Update zip!"; + if ($player) { + $this->maniaControl->getChat()->sendError($message, $player); + } + Logger::logError($message); + return; + } + $updateFileName = $tempDir . basename($updateData->url); - $bytes = file_put_contents($updateFileName, $updateFileContent); - if (!$bytes || $bytes <= 0) { - $message = "Update failed: Couldn't save Update zip!"; - if ($player) { - $this->maniaControl->getChat()->sendError($message, $player); - } - Logger::logError($message); - return; - } + $bytes = file_put_contents($updateFileName, $updateFileContent); + if (!$bytes || $bytes <= 0) { + $message = "Update failed: Couldn't save Update zip!"; + if ($player) { + $this->maniaControl->getChat()->sendError($message, $player); + } + Logger::logError($message); + return; + } - $zip = new \ZipArchive(); - $result = $zip->open($updateFileName); - if ($result !== true) { - $message = "Update failed: Couldn't open Update Zip. ({$result})"; - if ($player) { - $this->maniaControl->getChat()->sendError($message, $player); - } - Logger::logError($message); - unlink($updateFileName); - return; - } + $zip = new \ZipArchive(); + $result = $zip->open($updateFileName); + if ($result !== true) { + $message = "Update failed: Couldn't open Update Zip. ({$result})"; + if ($player) { + $this->maniaControl->getChat()->sendError($message, $player); + } + Logger::logError($message); + unlink($updateFileName); + return; + } - $zip->extractTo(MANIACONTROL_PATH); - $zip->close(); - unlink($updateFileName); - FileUtil::deleteTempFolder(); + $zip->extractTo(MANIACONTROL_PATH); + $zip->close(); + unlink($updateFileName); + FileUtil::deleteTempFolder(); - // Set the Nightly Build Date - $this->setNightlyBuildDate($updateData->releaseDate); + // Set the Nightly Build Date + $this->setNightlyBuildDate($updateData->releaseDate); - $message = 'Update finished!'; - if ($player) { - $this->maniaControl->getChat()->sendSuccess($message, $player); - } - Logger::log($message); + $message = 'Update finished!'; + if ($player) { + $this->maniaControl->getChat()->sendSuccess($message, $player); + } + Logger::log($message); - $this->maniaControl->restart(); - }); + $this->maniaControl->restart(); + }); return true; }