improvements on mapadd
This commit is contained in:
		
				
					committed by
					
						 Steffen Schröder
						Steffen Schröder
					
				
			
			
				
	
			
			
			
						parent
						
							8593f10ecc
						
					
				
				
					commit
					7a9627f41d
				
			| @@ -52,7 +52,7 @@ class ManiaExchangeInfoSearcher { //TODO rename to ManiaExchangeManager | |||||||
| 	 * | 	 * | ||||||
| 	 * @param $mxMapInfos | 	 * @param $mxMapInfos | ||||||
| 	 */ | 	 */ | ||||||
| 	private function updateMapObjectWithManiaExchangeIds($mxMapInfos) { | 	public function updateMapObjectsWithManiaExchangeIds($mxMapInfos) { | ||||||
| 		$mysqli = $this->maniaControl->database->mysqli; | 		$mysqli = $this->maniaControl->database->mysqli; | ||||||
| 		// Save map data | 		// Save map data | ||||||
| 		$saveMapQuery     = "UPDATE `" . MapManager::TABLE_MAPS . "` | 		$saveMapQuery     = "UPDATE `" . MapManager::TABLE_MAPS . "` | ||||||
| @@ -132,14 +132,14 @@ class ManiaExchangeInfoSearcher { //TODO rename to ManiaExchangeManager | |||||||
| 			//if($id % self::MAPS_PER_MX_FETCH == 0) { | 			//if($id % self::MAPS_PER_MX_FETCH == 0) { | ||||||
| 			if($id % 6 == 0) { //TODO 6 is temporary | 			if($id % 6 == 0) { //TODO 6 is temporary | ||||||
| 				$maps = $this->getMaplistByMixedUidIdString($mapIdString); | 				$maps = $this->getMaplistByMixedUidIdString($mapIdString); | ||||||
| 				$this->updateMapObjectWithManiaExchangeIds($maps); | 				$this->updateMapObjectsWithManiaExchangeIds($maps); | ||||||
| 				$mapIdString = ''; | 				$mapIdString = ''; | ||||||
| 			} | 			} | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
| 		if($mapIdString != '') { | 		if($mapIdString != '') { | ||||||
| 			$maps = $this->getMaplistByMixedUidIdString($mapIdString); | 			$maps = $this->getMaplistByMixedUidIdString($mapIdString); | ||||||
| 			$this->updateMapObjectWithManiaExchangeIds($maps); | 			$this->updateMapObjectsWithManiaExchangeIds($maps); | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
| 		$fetchMapStatement->close(); | 		$fetchMapStatement->close(); | ||||||
|   | |||||||
| @@ -340,19 +340,16 @@ class MapManager implements CallbackListener { | |||||||
| 			$title      = strtolower(substr($serverInfo['TitleId'], 0, 2)); | 			$title      = strtolower(substr($serverInfo['TitleId'], 0, 2)); | ||||||
|  |  | ||||||
| 			// Check if map exists | 			// Check if map exists | ||||||
| 			$url = "http://api.mania-exchange.com/{$title}/maps/{$mapId}?format=json"; | 			$mxMapInfos = $this->maniaControl->mapManager->mxInfoSearcher->getMaplistByMixedUidIdString($mapId); | ||||||
|  | 			$mapInfo    = $mxMapInfos[0]; | ||||||
|  | 			/** @var MXMapInfo $mapInfo */ | ||||||
|  |  | ||||||
| 			$mapInfo = FileUtil::loadFile($url, "application/json"); | 			if(!$mapInfo || !isset($mapInfo->uploaded)) { | ||||||
|  |  | ||||||
| 			if(!$mapInfo || strlen($mapInfo) <= 0) { |  | ||||||
| 				// Invalid id | 				// Invalid id | ||||||
| 				$this->maniaControl->chat->sendError('Invalid MX-Id!', $login); | 				$this->maniaControl->chat->sendError('Invalid MX-Id!', $login); | ||||||
| 				return; | 				return; | ||||||
| 			} | 			} | ||||||
|  |  | ||||||
| 			$mapInfo = json_decode($mapInfo, true); |  | ||||||
| 			$mapInfo = $mapInfo[0]; |  | ||||||
|  |  | ||||||
| 			$url  = "http://{$title}.mania-exchange.com/tracks/download/{$mapId}"; | 			$url  = "http://{$title}.mania-exchange.com/tracks/download/{$mapId}"; | ||||||
| 			$file = FileUtil::loadFile($url); | 			$file = FileUtil::loadFile($url); | ||||||
| 			if(!$file) { | 			if(!$file) { | ||||||
| @@ -361,7 +358,7 @@ class MapManager implements CallbackListener { | |||||||
| 				return; | 				return; | ||||||
| 			} | 			} | ||||||
| 			// Save map | 			// Save map | ||||||
| 			$fileName = $mapId . '_' . $mapInfo['Name'] . '.Map.Gbx'; | 			$fileName = $mapId . '_' . $mapInfo->name . '.Map.Gbx'; | ||||||
| 			$fileName = FileUtil::getClearedFileName($fileName); | 			$fileName = FileUtil::getClearedFileName($fileName); | ||||||
| 			if(!file_put_contents($mapDir . $fileName, $file)) { | 			if(!file_put_contents($mapDir . $fileName, $file)) { | ||||||
| 				// Save error | 				// Save error | ||||||
| @@ -387,12 +384,15 @@ class MapManager implements CallbackListener { | |||||||
| 				$this->maniaControl->chat->sendError("Couldn't add map to match settings!", $login); | 				$this->maniaControl->chat->sendError("Couldn't add map to match settings!", $login); | ||||||
| 				return; | 				return; | ||||||
| 			} | 			} | ||||||
| 			$this->maniaControl->chat->sendSuccess('Map $<' . $mapInfo['Name'] . '$> added!'); | 			$this->maniaControl->chat->sendSuccess('Map $<' . $mapInfo->name . '$> added!'); | ||||||
|  |  | ||||||
| 			$this->updateFullMapList(); | 			$this->updateFullMapList(); | ||||||
|  |  | ||||||
|  | 			//Update Mx MapInfo | ||||||
|  | 			$this->maniaControl->mapManager->mxInfoSearcher->updateMapObjectsWithManiaExchangeIds($mxMapInfos); | ||||||
|  |  | ||||||
| 			// Queue requested Map | 			// Queue requested Map | ||||||
| 			$this->maniaControl->mapManager->mapQueue->addMapToMapQueue($login, $mapInfo['MapUID']); | 			$this->maniaControl->mapManager->mapQueue->addMapToMapQueue($login, $mapInfo->uid); | ||||||
| 		} | 		} | ||||||
| 		// TODO: add local map by filename | 		// TODO: add local map by filename | ||||||
| 	} | 	} | ||||||
|   | |||||||
| @@ -486,7 +486,7 @@ class CustomVotesPlugin implements CommandListener, CallbackListener, ManialinkP | |||||||
| 		$quad->setSubStyle($quad::SUBSTYLE_BgPlayerCardBig); | 		$quad->setSubStyle($quad::SUBSTYLE_BgPlayerCardBig); | ||||||
| 		$quad->setSize(5, 5); | 		$quad->setSize(5, 5); | ||||||
| 		$quad->setAction(self::ACTION_NEGATIVE_VOTE); | 		$quad->setAction(self::ACTION_NEGATIVE_VOTE); | ||||||
| 		$quad->setActionKey($quad::ACTIONKEY_F5); | 		$quad->setActionKey($quad::ACTIONKEY_F7); | ||||||
|  |  | ||||||
| 		$label = new Label_Button(); | 		$label = new Label_Button(); | ||||||
| 		$frame->add($label); | 		$frame->add($label); | ||||||
| @@ -497,19 +497,19 @@ class CustomVotesPlugin implements CommandListener, CallbackListener, ManialinkP | |||||||
| 		$label->setTextSize(1); | 		$label->setTextSize(1); | ||||||
| 		$label->setSize(3, 3); | 		$label->setSize(3, 3); | ||||||
| 		$label->setTextColor("F00"); | 		$label->setTextColor("F00"); | ||||||
| 		$label->setText("F5"); | 		$label->setText("F7"); | ||||||
|  |  | ||||||
| 		$quad = clone $quad; | 		$quad = clone $quad; | ||||||
| 		$frame->add($quad); | 		$frame->add($quad); | ||||||
| 		$quad->setX($width / 2 - 4); | 		$quad->setX($width / 2 - 4); | ||||||
| 		$quad->setAction(self::ACTION_POSITIVE_VOTE); | 		$quad->setAction(self::ACTION_POSITIVE_VOTE); | ||||||
| 		$quad->setActionKey($quad::ACTIONKEY_F6); | 		$quad->setActionKey($quad::ACTIONKEY_F8); | ||||||
|  |  | ||||||
| 		$label = clone $label; | 		$label = clone $label; | ||||||
| 		$frame->add($label); | 		$frame->add($label); | ||||||
| 		$label->setX($width / 2 - 4); | 		$label->setX($width / 2 - 4); | ||||||
| 		$label->setTextColor("0F0"); | 		$label->setTextColor("0F0"); | ||||||
| 		$label->setText("F6"); | 		$label->setText("F8"); | ||||||
|  |  | ||||||
| 		// Send manialink | 		// Send manialink | ||||||
| 		$manialinkText = $maniaLink->render()->saveXML(); | 		$manialinkText = $maniaLink->render()->saveXML(); | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user