diff --git a/core/Maps/MapManager.php b/core/Maps/MapManager.php index 2b36daa2..41e53be8 100644 --- a/core/Maps/MapManager.php +++ b/core/Maps/MapManager.php @@ -469,6 +469,7 @@ class MapManager implements CallbackListener, CommunicationListener, UsageInform // Update last updated time $map = $this->getMapByUid($mapInfo->uid); + if (!$map) { // TODO: improve this - error reports about not existing maps $this->maniaControl->getErrorHandler()->triggerDebugNotice('Map not in List after Insert!'); diff --git a/core/Server/UsageReporter.php b/core/Server/UsageReporter.php index 88cb21aa..3c310370 100644 --- a/core/Server/UsageReporter.php +++ b/core/Server/UsageReporter.php @@ -3,6 +3,7 @@ namespace ManiaControl\Server; use ManiaControl\Callbacks\TimerListener; +use ManiaControl\Files\AsyncHttpRequest; use ManiaControl\Logger; use ManiaControl\ManiaControl; use ManiaControl\Utils\Formatter; @@ -81,11 +82,16 @@ class UsageReporter implements TimerListener { $usageReport = json_encode($properties); $url = ManiaControl::URL_WEBSERVICE . 'usagereport'; - $this->maniaControl->getFileReader()->postData($url, function ($response, $error) { + + $asyncRequest = new AsyncHttpRequest($this->maniaControl, $url); + $asyncRequest->setContent($usageReport); + $asyncRequest->setCallable(function ($response, $error) { $response = json_decode($response); if ($error || !$response) { Logger::logError('Error while Sending data: ' . print_r($error, true)); } - }, $usageReport); + }); + + $asyncRequest->postData(); } } diff --git a/plugins/MCTeam/KarmaPlugin.php b/plugins/MCTeam/KarmaPlugin.php index 1796a32f..309bf1dc 100644 --- a/plugins/MCTeam/KarmaPlugin.php +++ b/plugins/MCTeam/KarmaPlugin.php @@ -12,6 +12,7 @@ use ManiaControl\Callbacks\CallbackManager; use ManiaControl\Callbacks\Callbacks; use ManiaControl\Callbacks\TimerListener; use ManiaControl\Files\AsynchronousFileReader; +use ManiaControl\Files\AsyncHttpRequest; use ManiaControl\Logger; use ManiaControl\ManiaControl; use ManiaControl\Maps\Map; @@ -368,16 +369,23 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin { } $content = json_encode($properties); - $this->maniaControl->getFileReader()->postData(self::MX_KARMA_URL . self::MX_KARMA_GET_MAP_RATING . '?sessionKey=' . urlencode($this->mxKarma['session']->sessionKey), function ($json, $error) use ( + + $url = self::MX_KARMA_URL . self::MX_KARMA_GET_MAP_RATING . '?sessionKey=' . urlencode($this->mxKarma['session']->sessionKey); + + $asyncHttpRequest = new AsyncHttpRequest($this->maniaControl, $url); + $asyncHttpRequest->setContent($content); + $asyncHttpRequest->setContentType($asyncHttpRequest::CONTENT_TYPE_JSON); + + $asyncHttpRequest->setCallable(function ($json, $error) use ( &$player ) { if ($error) { - $this->maniaControl->getErrorHandler()->triggerDebugNotice('mx karma error', $error); + $this->maniaControl->getErrorHandler()->triggerDebugNotice('mx karma error' . $error); return; } $data = json_decode($json); if (!$data) { - $this->maniaControl->getErrorHandler()->triggerDebugNotice('parse error', $json, $data); + $this->maniaControl->getErrorHandler()->triggerDebugNotice('parse error' . $json); return; } @@ -403,10 +411,12 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin { if ($data->data->message === 'invalid session') { unset($this->mxKarma['session']); } else { - $this->maniaControl->getErrorHandler()->triggerDebugNotice('fetch error', $data->data->message, self::MX_KARMA_GET_MAP_RATING, $this->mxKarma['session']); + $this->maniaControl->getErrorHandler()->triggerDebugNotice('fetch error ' . $data->data->message . self::MX_KARMA_GET_MAP_RATING . $this->mxKarma['session']); } } - }, $content, false, AsynchronousFileReader::CONTENT_TYPE_JSON); + }); + + $asyncHttpRequest->postData(); } /** @@ -483,14 +493,19 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin { $content = json_encode($properties); - $this->maniaControl->getFileReader()->postData(self::MX_KARMA_URL . self::MX_KARMA_SAVE_VOTES . "?sessionKey=" . urlencode($this->mxKarma['session']->sessionKey), function ($json, $error) { + $url = self::MX_KARMA_URL . self::MX_KARMA_SAVE_VOTES . "?sessionKey=" . urlencode($this->mxKarma['session']->sessionKey); + + $asyncRequest = new AsyncHttpRequest($this->maniaControl, $url); + $asyncRequest->setContent($content); + $asyncRequest->setContentType($asyncRequest::CONTENT_TYPE_JSON); + $asyncRequest->setCallable(function ($json, $error) { if ($error) { - $this->maniaControl->getErrorHandler()->triggerDebugNotice('mx karma error', $error); + $this->maniaControl->getErrorHandler()->triggerDebugNotice('mx karma error ' . $error); return; } $data = json_decode($json); if (!$data) { - $this->maniaControl->getErrorHandler()->triggerDebugNotice('parse error', $json, $data); + $this->maniaControl->getErrorHandler()->triggerDebugNotice('parse error ' . $json); return; } if ($data->success) { @@ -501,10 +516,12 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin { if ($data->data->message === "invalid session") { unset($this->mxKarma['session']); } else { - $this->maniaControl->getErrorHandler()->triggerDebugNotice('saving error', $data->data->message, self::MX_KARMA_SAVE_VOTES, $this->mxKarma['session']); + $this->maniaControl->getErrorHandler()->triggerDebugNotice('saving error ' . $data->data->message . self::MX_KARMA_SAVE_VOTES . $this->mxKarma['session']); } } - }, $content, false, AsynchronousFileReader::CONTENT_TYPE_JSON); + }); + + $asyncRequest->postData(); } /**