various tests to keep session alive
This commit is contained in:
		| @@ -118,6 +118,55 @@ class AsynchronousFileReader { | |||||||
| 		array_push($this->requests, $request); | 		array_push($this->requests, $request); | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
|  | 	//TODO remove, they are just for testing dedimania | ||||||
|  | 	public static function newRequestTest($url){ | ||||||
|  | 		$request = new Request($url); | ||||||
|  | 		$request->getOptions() | ||||||
|  | 		        ->set(CURLOPT_TIMEOUT, 60) | ||||||
|  | 		        ->set(CURLOPT_HEADER, false) // don't display response header | ||||||
|  | 		        ->set(CURLOPT_CRLF, true) // linux line feed | ||||||
|  | 		        ->set(CURLOPT_ENCODING, '') // accept encoding | ||||||
|  | 		        ->set(CURLOPT_USERAGENT, 'ManiaControl v' . ManiaControl::VERSION) // user-agent | ||||||
|  | 		        ->set(CURLOPT_RETURNTRANSFER, true); // return instead of output content | ||||||
|  | 		return $request; | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	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); | ||||||
|  | 		array_push($headers, 'Keep-Alive: timeout=600, max=2000'); | ||||||
|  | 		array_push($headers, 'Connection: Keep-Alive'); | ||||||
|  |  | ||||||
|  | 		$content = str_replace(array("\r", "\n"), '', $content); | ||||||
|  | 		if ($compression) { | ||||||
|  | 			$content = zlib_encode($content, 31); | ||||||
|  | 			array_push($headers, 'Content-Encoding: gzip'); | ||||||
|  | 		} | ||||||
|  |  | ||||||
|  | 		$request->getOptions() | ||||||
|  | 		        ->set(CURLOPT_POST, true) // post method | ||||||
|  | 		        ->set(CURLOPT_POSTFIELDS, $content) // post content field | ||||||
|  | 		        ->set(CURLOPT_HTTPHEADER, $headers) // headers | ||||||
|  | 		; | ||||||
|  | 		$request->addListener('complete', function (Event $event) use (&$function) { | ||||||
|  | 			$error   = null; | ||||||
|  | 			$content = null; | ||||||
|  | 			if ($event->response->hasError()) { | ||||||
|  | 				$error = $event->response->getError() | ||||||
|  | 				                         ->getMessage(); | ||||||
|  | 			} else { | ||||||
|  | 				$content = $event->response->getContent(); | ||||||
|  | 			} | ||||||
|  |  | ||||||
|  | 			call_user_func($function, $content, $error); | ||||||
|  | 		}); | ||||||
|  |  | ||||||
|  | 		$this->addRequest($request); | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  |  | ||||||
| 	/** | 	/** | ||||||
| 	 * Send Data via POST Method | 	 * Send Data via POST Method | ||||||
| 	 * | 	 * | ||||||
| @@ -129,6 +178,7 @@ class AsynchronousFileReader { | |||||||
| 	 */ | 	 */ | ||||||
| 	public function postData($url, callable $function, $content, $compression = false, | 	public function postData($url, callable $function, $content, $compression = false, | ||||||
| 	                         $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: timeout=600, max=2000'); | 		array_push($headers, 'Keep-Alive: timeout=600, max=2000'); | ||||||
| @@ -144,8 +194,8 @@ class AsynchronousFileReader { | |||||||
| 		$request->getOptions() | 		$request->getOptions() | ||||||
| 		        ->set(CURLOPT_POST, true) // post method | 		        ->set(CURLOPT_POST, true) // post method | ||||||
| 		        ->set(CURLOPT_POSTFIELDS, $content) // post content field | 		        ->set(CURLOPT_POSTFIELDS, $content) // post content field | ||||||
| 		        ->set(CURLOPT_HTTPHEADER, $headers); // headers | 		        ->set(CURLOPT_HTTPHEADER, $headers) // headers | ||||||
|  | 				; | ||||||
| 		$request->addListener('complete', function (Event $event) use (&$function) { | 		$request->addListener('complete', function (Event $event) use (&$function) { | ||||||
| 			$error   = null; | 			$error   = null; | ||||||
| 			$content = null; | 			$content = null; | ||||||
|   | |||||||
| @@ -14,6 +14,7 @@ use ManiaControl\Callbacks\Callbacks; | |||||||
| use ManiaControl\Callbacks\Models\RecordCallback; | use ManiaControl\Callbacks\Models\RecordCallback; | ||||||
| use ManiaControl\Callbacks\TimerListener; | use ManiaControl\Callbacks\TimerListener; | ||||||
| use ManiaControl\Commands\CommandListener; | use ManiaControl\Commands\CommandListener; | ||||||
|  | use ManiaControl\Files\AsynchronousFileReader; | ||||||
| use ManiaControl\ManiaControl; | use ManiaControl\ManiaControl; | ||||||
| use ManiaControl\Manialinks\ManialinkManager; | use ManiaControl\Manialinks\ManialinkManager; | ||||||
| use ManiaControl\Players\Player; | use ManiaControl\Players\Player; | ||||||
| @@ -71,6 +72,8 @@ class DedimaniaPlugin implements CallbackListener, CommandListener, TimerListene | |||||||
| 	private $checkpoints = array(); | 	private $checkpoints = array(); | ||||||
| 	private $init = false; | 	private $init = false; | ||||||
|  |  | ||||||
|  | 	private $request = null; | ||||||
|  |  | ||||||
| 	/** | 	/** | ||||||
| 	 * @see \ManiaControl\Plugins\Plugin::prepare() | 	 * @see \ManiaControl\Plugins\Plugin::prepare() | ||||||
| 	 */ | 	 */ | ||||||
| @@ -162,6 +165,9 @@ class DedimaniaPlugin implements CallbackListener, CommandListener, TimerListene | |||||||
| 			throw new \Exception("No Dedimania Code Specified, check the settings!"); | 			throw new \Exception("No Dedimania Code Specified, check the settings!"); | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
|  | 		$this->request = AsynchronousFileReader::newRequestTest(self::DEDIMANIA_URL); | ||||||
|  |  | ||||||
|  |  | ||||||
| 		$this->dedimaniaData = new DedimaniaData($serverInfo->login, $dedimaniaCode, $serverInfo->path, $packMask, $serverVersion); | 		$this->dedimaniaData = new DedimaniaData($serverInfo->login, $dedimaniaCode, $serverInfo->path, $packMask, $serverVersion); | ||||||
|  |  | ||||||
| 		$this->openDedimaniaSession(); | 		$this->openDedimaniaSession(); | ||||||
| @@ -183,6 +189,8 @@ class DedimaniaPlugin implements CallbackListener, CommandListener, TimerListene | |||||||
| 			var_dump($content); | 			var_dump($content); | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
|  |  | ||||||
|  | 		//$this->maniaControl->fileReader->postDataTest($this->request, self::DEDIMANIA_URL, function ($data, $error) { | ||||||
| 		$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"); | ||||||
|  |  | ||||||
| @@ -280,7 +288,8 @@ class DedimaniaPlugin implements CallbackListener, CommandListener, TimerListene | |||||||
|  |  | ||||||
| 		$data    = array($this->dedimaniaData->sessionId, $mapInfo, $gameMode, $serverInfo, $playerInfo); | 		$data    = array($this->dedimaniaData->sessionId, $mapInfo, $gameMode, $serverInfo, $playerInfo); | ||||||
| 		$content = $this->encode_request(self::DEDIMANIA_GET_RECORDS, $data); | 		$content = $this->encode_request(self::DEDIMANIA_GET_RECORDS, $data); | ||||||
|  | 		//var_dump("get recs"); | ||||||
|  | 		//$this->maniaControl->fileReader->postDataTest($this->request,self::DEDIMANIA_URL, function ($data, $error) { | ||||||
| 		$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); | ||||||
| @@ -555,7 +564,8 @@ class DedimaniaPlugin implements CallbackListener, CommandListener, TimerListene | |||||||
| 		} | 		} | ||||||
|  |  | ||||||
| 		$content = $this->encode_request(self::DEDIMANIA_CHECK_SESSION, array($this->dedimaniaData->sessionId)); | 		$content = $this->encode_request(self::DEDIMANIA_CHECK_SESSION, array($this->dedimaniaData->sessionId)); | ||||||
|  | 		//var_dump("check session"); //TODO remove | ||||||
|  | 		//$this->maniaControl->fileReader->postDataTest($this->request, self::DEDIMANIA_URL, function ($data, $error) { | ||||||
| 		$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); | ||||||
| @@ -938,7 +948,7 @@ class DedimaniaPlugin implements CallbackListener, CommandListener, TimerListene | |||||||
|  |  | ||||||
| 		$insert = false; | 		$insert = false; | ||||||
|  |  | ||||||
| 		//var_dump($newRecord); | 		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