dedimania try fixes
This commit is contained in:
		| @@ -131,7 +131,7 @@ class AsynchronousFileReader { | |||||||
| 	                         $contentType = 'text/xml; charset=UTF-8;') { | 	                         $contentType = 'text/xml; charset=UTF-8;') { | ||||||
| 		$headers = array(); | 		$headers = array(); | ||||||
| 		array_push($headers, 'Content-Type: ' . $contentType); | 		array_push($headers, 'Content-Type: ' . $contentType); | ||||||
| 		array_push($headers, 'Keep-Alive: 300'); | 		array_push($headers, 'Keep-Alive: 600'); | ||||||
| 		array_push($headers, 'Connection: Keep-Alive'); | 		array_push($headers, 'Connection: Keep-Alive'); | ||||||
|  |  | ||||||
| 		$content = str_replace(array("\r", "\n"), '', $content); | 		$content = str_replace(array("\r", "\n"), '', $content); | ||||||
|   | |||||||
| @@ -58,6 +58,7 @@ class DedimaniaPlugin implements CallbackListener, CommandListener, TimerListene | |||||||
| 	const CB_DEDIMANIA_CHANGED            = 'Dedimania.Changed'; | 	const CB_DEDIMANIA_CHANGED            = 'Dedimania.Changed'; | ||||||
| 	const CB_DEDIMANIA_UPDATED            = 'Dedimania.Updated'; | 	const CB_DEDIMANIA_UPDATED            = 'Dedimania.Updated'; | ||||||
| 	const ACTION_SHOW_DEDIRECORDSLIST     = 'Dedimania.ShowDediRecordsList'; | 	const ACTION_SHOW_DEDIRECORDSLIST     = 'Dedimania.ShowDediRecordsList'; | ||||||
|  | 	const DEDIMANIA_DEBUG                 = false; | ||||||
|  |  | ||||||
| 	/* | 	/* | ||||||
| 	 * Private Properties | 	 * Private Properties | ||||||
| @@ -170,8 +171,18 @@ class DedimaniaPlugin implements CallbackListener, CommandListener, TimerListene | |||||||
| 	 * Opens the Dedimania Session | 	 * Opens the Dedimania Session | ||||||
| 	 */ | 	 */ | ||||||
| 	private function openDedimaniaSession() { | 	private function openDedimaniaSession() { | ||||||
|  | 		if (self::DEDIMANIA_DEBUG) { | ||||||
|  | 			var_dump("Dedi Debug: DedimaniaData before Connecting"); | ||||||
|  | 			var_dump($this->dedimaniaData); | ||||||
|  | 		} | ||||||
|  |  | ||||||
| 		$content = $this->encode_request(self::DEDIMANIA_OPEN_SESSION, array($this->dedimaniaData->toArray())); | 		$content = $this->encode_request(self::DEDIMANIA_OPEN_SESSION, array($this->dedimaniaData->toArray())); | ||||||
|  |  | ||||||
|  | 		if (self::DEDIMANIA_DEBUG) { | ||||||
|  | 			var_dump("Dedi Debug: XML-RPC Content on Connecting"); | ||||||
|  | 			var_dump($content); | ||||||
|  | 		} | ||||||
|  |  | ||||||
| 		$this->maniaControl->fileReader->postData(self::DEDIMANIA_URL, function ($data, $error) { | 		$this->maniaControl->fileReader->postData(self::DEDIMANIA_URL, function ($data, $error) { | ||||||
| 			$this->maniaControl->log("Try to connect on Dedimania"); | 			$this->maniaControl->log("Try to connect on Dedimania"); | ||||||
|  |  | ||||||
| @@ -199,6 +210,14 @@ class DedimaniaPlugin implements CallbackListener, CommandListener, TimerListene | |||||||
| 			} else { | 			} else { | ||||||
| 				$this->maniaControl->log("Error while opening Dedimania Connection"); | 				$this->maniaControl->log("Error while opening Dedimania Connection"); | ||||||
| 			} | 			} | ||||||
|  |  | ||||||
|  | 			if (self::DEDIMANIA_DEBUG) { | ||||||
|  | 				var_dump("Dedi Debug: Connect Method Response"); | ||||||
|  | 				var_dump($methodResponse); | ||||||
|  |  | ||||||
|  | 				var_dump("Dedi Debug: DedimaniaData after Startup"); | ||||||
|  | 				var_dump($this->dedimaniaData); | ||||||
|  | 			} | ||||||
| 		}, $content, true); | 		}, $content, true); | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| @@ -278,7 +297,7 @@ class DedimaniaPlugin implements CallbackListener, CommandListener, TimerListene | |||||||
| 				return; | 				return; | ||||||
| 			} | 			} | ||||||
|  |  | ||||||
| 			$responseData                       = $methodResponse[0]; | 			$responseData = $methodResponse[0]; | ||||||
| 			if (!isset($responseData['Players']) || !isset($responseData['Records'])) { | 			if (!isset($responseData['Players']) || !isset($responseData['Records'])) { | ||||||
| 				$this->maniaControl->errorHandler->triggerDebugNotice('Invalid Dedimania response!', $responseData); | 				$this->maniaControl->errorHandler->triggerDebugNotice('Invalid Dedimania response!', $responseData); | ||||||
| 				return; | 				return; | ||||||
| @@ -294,6 +313,10 @@ class DedimaniaPlugin implements CallbackListener, CommandListener, TimerListene | |||||||
| 				$this->dedimaniaData->records[$key] = new RecordData($record); | 				$this->dedimaniaData->records[$key] = new RecordData($record); | ||||||
| 			} | 			} | ||||||
|  |  | ||||||
|  | 			if (self::DEDIMANIA_DEBUG) { | ||||||
|  | 				var_dump("Dedimania Records Fetched"); | ||||||
|  | 			} | ||||||
|  |  | ||||||
| 			$this->updateManialink = true; | 			$this->updateManialink = true; | ||||||
| 			$this->maniaControl->callbackManager->triggerCallback(self::CB_DEDIMANIA_UPDATED, $this->dedimaniaData->records); | 			$this->maniaControl->callbackManager->triggerCallback(self::CB_DEDIMANIA_UPDATED, $this->dedimaniaData->records); | ||||||
| 		}, $content, true); | 		}, $content, true); | ||||||
| @@ -404,11 +427,16 @@ class DedimaniaPlugin implements CallbackListener, CommandListener, TimerListene | |||||||
| 	 * Handle 1 Second Callback | 	 * Handle 1 Second Callback | ||||||
| 	 */ | 	 */ | ||||||
| 	public function updateEverySecond() { | 	public function updateEverySecond() { | ||||||
| 		if (!$this->updateManialink || !$this->dedimaniaData->records) { | 		if (!$this->updateManialink) { | ||||||
| 			return; | 			return; | ||||||
| 		} | 		} | ||||||
| 		$this->updateManialink = false; | 		$this->updateManialink = false; | ||||||
|  |  | ||||||
|  | 		if (self::DEDIMANIA_DEBUG) { | ||||||
|  | 			var_dump($this->dedimaniaData); | ||||||
|  | 			var_dump("Dedimania Debug: Update Manialink"); | ||||||
|  | 		} | ||||||
|  |  | ||||||
| 		if ($this->maniaControl->settingManager->getSettingValue($this, self::SETTING_WIDGET_ENABLE)) { | 		if ($this->maniaControl->settingManager->getSettingValue($this, self::SETTING_WIDGET_ENABLE)) { | ||||||
| 			$manialink = $this->buildManialink(); | 			$manialink = $this->buildManialink(); | ||||||
| 			$this->maniaControl->manialinkManager->sendManialink($manialink); | 			$this->maniaControl->manialinkManager->sendManialink($manialink); | ||||||
| @@ -421,9 +449,6 @@ class DedimaniaPlugin implements CallbackListener, CommandListener, TimerListene | |||||||
| 	 * @return \FML\ManiaLink | 	 * @return \FML\ManiaLink | ||||||
| 	 */ | 	 */ | ||||||
| 	private function buildManialink() { | 	private function buildManialink() { | ||||||
| 		if (!$this->dedimaniaData->records) { |  | ||||||
| 			return null; |  | ||||||
| 		} |  | ||||||
| 		$records = $this->dedimaniaData->records; | 		$records = $this->dedimaniaData->records; | ||||||
|  |  | ||||||
| 		$title        = $this->maniaControl->settingManager->getSettingValue($this, self::SETTING_WIDGET_TITLE); | 		$title        = $this->maniaControl->settingManager->getSettingValue($this, self::SETTING_WIDGET_TITLE); | ||||||
| @@ -553,6 +578,11 @@ class DedimaniaPlugin implements CallbackListener, CommandListener, TimerListene | |||||||
| 					$this->openDedimaniaSession(); | 					$this->openDedimaniaSession(); | ||||||
| 				} | 				} | ||||||
| 			} | 			} | ||||||
|  |  | ||||||
|  | 			if (self::DEDIMANIA_DEBUG) { | ||||||
|  | 				var_dump("Dedi Debug: Session Check ResponseData "); | ||||||
|  | 				var_dump($responseData); | ||||||
|  | 			} | ||||||
| 		}, $content, true); | 		}, $content, true); | ||||||
| 		return; | 		return; | ||||||
| 	} | 	} | ||||||
| @@ -685,11 +715,20 @@ class DedimaniaPlugin implements CallbackListener, CommandListener, TimerListene | |||||||
| 		//var_dump($data); | 		//var_dump($data); | ||||||
| 		$content = $this->encode_request(self::DEDIMANIA_SET_CHALLENGE_TIMES, $data); | 		$content = $this->encode_request(self::DEDIMANIA_SET_CHALLENGE_TIMES, $data); | ||||||
|  |  | ||||||
|  | 		if (self::DEDIMANIA_DEBUG) { | ||||||
|  | 			var_dump("Dedimania Debug: Submitting Times at End-Map", $content); | ||||||
|  | 		} | ||||||
|  |  | ||||||
| 		$this->maniaControl->fileReader->postData(self::DEDIMANIA_URL, function ($data, $error) { | 		$this->maniaControl->fileReader->postData(self::DEDIMANIA_URL, function ($data, $error) { | ||||||
| 			if ($error) { | 			if ($error) { | ||||||
| 				$this->maniaControl->log("Dedimania Error: " . $error); | 				$this->maniaControl->log("Dedimania Error: " . $error); | ||||||
| 			} | 			} | ||||||
|  |  | ||||||
|  | 			if (self::DEDIMANIA_DEBUG) { | ||||||
|  | 				var_dump("Dedimania Debug: Submit Data Response"); | ||||||
|  | 				var_dump($data); | ||||||
|  | 			} | ||||||
|  |  | ||||||
| 			$data = $this->decode($data); | 			$data = $this->decode($data); | ||||||
| 			if (!is_array($data) || empty($data)) { | 			if (!is_array($data) || empty($data)) { | ||||||
| 				return; | 				return; | ||||||
| @@ -705,6 +744,13 @@ class DedimaniaPlugin implements CallbackListener, CommandListener, TimerListene | |||||||
| 			if (!$methodResponse[0]) { | 			if (!$methodResponse[0]) { | ||||||
| 				trigger_error("Records Plugin: Submitting dedimania records failed."); | 				trigger_error("Records Plugin: Submitting dedimania records failed."); | ||||||
| 			} | 			} | ||||||
|  |  | ||||||
|  | 			if (self::DEDIMANIA_DEBUG) { | ||||||
|  | 				var_dump("Dedimania Debug: endMap response"); | ||||||
|  | 				var_dump($methodResponse); | ||||||
|  | 				var_dump("Dedimania Data"); | ||||||
|  | 				var_dump($this->dedimaniaData); | ||||||
|  | 			} | ||||||
| 		}, $content, false); | 		}, $content, false); | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| @@ -761,7 +807,9 @@ class DedimaniaPlugin implements CallbackListener, CommandListener, TimerListene | |||||||
| 	 * @param RecordCallback $callback | 	 * @param RecordCallback $callback | ||||||
| 	 */ | 	 */ | ||||||
| 	public function handleCheckpointCallback(RecordCallback $callback) { | 	public function handleCheckpointCallback(RecordCallback $callback) { | ||||||
| 		if ($callback->isLegacyCallback) { | 		//var_dump($callback->lapTime); //FIXME, dedimania needs Finish as LastCp, or NbOfCheckpoints wrong? | ||||||
|  |  | ||||||
|  | 		if ($callback->isLegacyCallback || !$callback->lapTime) { | ||||||
| 			return; | 			return; | ||||||
| 		} | 		} | ||||||
| 		if (!isset($this->checkpoints[$callback->login])) { | 		if (!isset($this->checkpoints[$callback->login])) { | ||||||
| @@ -890,6 +938,7 @@ class DedimaniaPlugin implements CallbackListener, CommandListener, TimerListene | |||||||
|  |  | ||||||
| 		$insert = false; | 		$insert = false; | ||||||
|  |  | ||||||
|  | 		var_dump($newRecord); | ||||||
| 		// Get max possible rank | 		// Get max possible rank | ||||||
| 		$maxRank = $this->dedimaniaData->getPlayerMaxRank($newRecord->login); | 		$maxRank = $this->dedimaniaData->getPlayerMaxRank($newRecord->login); | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user