From 5b87873aba3a3c5cca3e1d39931606851ee61afa Mon Sep 17 00:00:00 2001 From: kremsy Date: Tue, 11 Apr 2017 14:58:17 +0200 Subject: [PATCH] improved directory browser and map update check --- core/ManiaExchange/ManiaExchangeManager.php | 4 +-- core/Maps/DirectoryBrowser.php | 5 ++++ core/Maps/Map.php | 27 +++++++++++++++++++-- 3 files changed, 32 insertions(+), 4 deletions(-) diff --git a/core/ManiaExchange/ManiaExchangeManager.php b/core/ManiaExchange/ManiaExchangeManager.php index 55bf4c5f..ef9304d7 100644 --- a/core/ManiaExchange/ManiaExchangeManager.php +++ b/core/ManiaExchange/ManiaExchangeManager.php @@ -105,10 +105,10 @@ class ManiaExchangeManager implements UsageInformationAble { } $index = 0; - foreach ($maps as $map) { + foreach ($maps as &$map) { if (!$map) { // TODO: remove after resolving of error report about "non-object" - $this->maniaControl->getErrorHandler()->triggerDebugNotice('Non-Object-Map', $map, $maps); + $this->maniaControl->getErrorHandler()->triggerDebugNotice('Non-Object-Map ' . $map->name); continue; } /** @var Map $map */ diff --git a/core/Maps/DirectoryBrowser.php b/core/Maps/DirectoryBrowser.php index 4fed78f8..95224fa5 100644 --- a/core/Maps/DirectoryBrowser.php +++ b/core/Maps/DirectoryBrowser.php @@ -362,6 +362,11 @@ class DirectoryBrowser implements ManialinkPageAnswerListener { return; } + //Update MX Data and ID + $this->maniaControl->getMapManager()->getMXManager()->fetchManiaExchangeMapInformation($map); + + $map->lastUpdate = time(); + // Message $message = $player->getEscapedNickname() . ' added ' . $map->getEscapedName() . '!'; $this->maniaControl->getChat()->sendSuccess($message); diff --git a/core/Maps/Map.php b/core/Maps/Map.php index 28c6a8b8..47b58c72 100644 --- a/core/Maps/Map.php +++ b/core/Maps/Map.php @@ -18,7 +18,10 @@ use ManiaControl\Utils\Formatter; */ class Map implements Dumpable, UsageInformationAble { use DumpTrait, UsageInformationTrait; - + + //Minimum Lightmap Version for the Update Check + const MIN_LIGHTMAP_VERSION = 7; + /* * Public properties */ @@ -107,7 +110,27 @@ class Map implements Dumpable, UsageInformationAble { * @return bool */ public function updateAvailable() { - return ($this->mx && ($this->lastUpdate < strtotime($this->mx->updated) || $this->uid !== $this->mx->uid)); + //Check if MX Object is existing + if (!$this->mx) { + return false; + } + + //Check if the Lightmap verison on MX surpasses the min Lightmap version + if ($this->mx->lightmap < self::MIN_LIGHTMAP_VERSION) { + return false; + } + + //Check if last Map update is older than the MX Maptime + if ($this->lastUpdate < strtotime($this->mx->updated)) { + return true; + } + + //Check if UIDs are different + if ($this->uid !== $this->mx->uid) { + return true; + } + + return false; } }