Remove WebReader & and add a sec delay before sending EndMatch update
This commit is contained in:
		| @@ -11,10 +11,10 @@ use ManiaControl\Players\Player; | |||||||
| use ManiaControl\Plugins\Plugin; | use ManiaControl\Plugins\Plugin; | ||||||
| use ManiaControl\Settings\Setting; | use ManiaControl\Settings\Setting; | ||||||
| use ManiaControl\Settings\SettingManager; | use ManiaControl\Settings\SettingManager; | ||||||
| use ManiaControl\Utils\WebReader; |  | ||||||
| use ManiaControl\Files\AsyncHttpRequest; | use ManiaControl\Files\AsyncHttpRequest; | ||||||
| use ManiaControl\Commands\CommandListener; | use ManiaControl\Commands\CommandListener; | ||||||
| use ManiaControl\Admin\AuthenticationManager; | use ManiaControl\Admin\AuthenticationManager; | ||||||
|  | use ManiaControl\Callbacks\TimerListener; | ||||||
|  |  | ||||||
| if (! class_exists('MatchManagerSuite\MatchManagerCore')) { | if (! class_exists('MatchManagerSuite\MatchManagerCore')) { | ||||||
| 	$this->maniaControl->getChat()->sendErrorToAdmins('MatchManager Core is needed to use MatchManagerGSheet plugin. Install it and restart Maniacontrol'); | 	$this->maniaControl->getChat()->sendErrorToAdmins('MatchManager Core is needed to use MatchManagerGSheet plugin. Install it and restart Maniacontrol'); | ||||||
| @@ -30,12 +30,12 @@ use MatchManagerSuite\MatchManagerCore; | |||||||
|  * @author		Beu |  * @author		Beu | ||||||
|  * @license		http://www.gnu.org/licenses/ GNU General Public License, Version 3 |  * @license		http://www.gnu.org/licenses/ GNU General Public License, Version 3 | ||||||
|  */ |  */ | ||||||
| class MatchManagerGSheet implements  CallbackListener, CommandListener, Plugin { | class MatchManagerGSheet implements  CallbackListener, TimerListener, CommandListener, Plugin { | ||||||
| 	/* | 	/* | ||||||
| 	 * Constants | 	 * Constants | ||||||
| 	 */ | 	 */ | ||||||
| 	const PLUGIN_ID											= 156; | 	const PLUGIN_ID											= 156; | ||||||
| 	const PLUGIN_VERSION									= 0.8; | 	const PLUGIN_VERSION									= 0.9; | ||||||
| 	const PLUGIN_NAME										= 'MatchManager GSheet'; | 	const PLUGIN_NAME										= 'MatchManager GSheet'; | ||||||
| 	const PLUGIN_AUTHOR										= 'Beu'; | 	const PLUGIN_AUTHOR										= 'Beu'; | ||||||
|  |  | ||||||
| @@ -246,28 +246,33 @@ class MatchManagerGSheet implements  CallbackListener, CommandListener, Plugin { | |||||||
| 			$this->maniaControl->getChat()->sendError('Client ID empty', $player); | 			$this->maniaControl->getChat()->sendError('Client ID empty', $player); | ||||||
| 			return; | 			return; | ||||||
| 		} | 		} | ||||||
| 		$response = WebReader::postUrl('https://oauth2.googleapis.com/device/code?scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fspreadsheets&client_id=' . $clientid); |  | ||||||
| 		$json = $response->getContent(); | 		$asyncHttpRequest = new AsyncHttpRequest($this->maniaControl, 'https://oauth2.googleapis.com/device/code?scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fspreadsheets&client_id=' . $clientid); | ||||||
| 		if (!$json) { | 		$asyncHttpRequest->setContentType("application/x-www-form-urlencoded"); | ||||||
| 			Logger::logError('Impossible to Google API: ' . $json); | 		$asyncHttpRequest->setCallable(function ($json, $error) use ($player) { | ||||||
| 			$this->maniaControl->getChat()->sendError('Impossible to Google API: ' . $json, $player); | 			if (!$json) { | ||||||
| 			return; | 				Logger::logError('Impossible to Google API: ' . $json); | ||||||
| 		} | 				$this->maniaControl->getChat()->sendError('Impossible to Google API: ' . $json, $player); | ||||||
| 		$data = json_decode($json); | 				return; | ||||||
| 		if (!$data) { | 			} | ||||||
| 			Logger::logError('Json parse error: ' . $json); | 			$data = json_decode($json); | ||||||
| 			$this->maniaControl->getChat()->sendError('Json parse error: ' . $json, $player); | 			if (!$data) { | ||||||
| 			return; | 				Logger::logError('Json parse error: ' . $json); | ||||||
| 		} | 				$this->maniaControl->getChat()->sendError('Json parse error: ' . $json, $player); | ||||||
| 		if (isset($data->device_code)) { | 				return; | ||||||
| 			$this->device_code = $data->device_code; | 			} | ||||||
| 			$this->maniaControl->getChat()->sendSuccess('Open $<$l['. $data->verification_url . ']this link$> and type this code: "' . $data->user_code .'"' , $player); | 			if (isset($data->device_code)) { | ||||||
| 			$this->maniaControl->getChat()->sendSuccess('After have validate the App, type the commande "//matchgsheet step2"' , $player); | 				$this->device_code = $data->device_code; | ||||||
| 		} elseif (isset($data->error_code)) { | 				$this->maniaControl->getChat()->sendSuccess('Open $<$l['. $data->verification_url . ']this link$> and type this code: "' . $data->user_code .'"' , $player); | ||||||
| 			$this->maniaControl->getChat()->sendError('Google refused the request: ' . $data->error_code, $player); | 				$this->maniaControl->getChat()->sendSuccess('After have validate the App, type the commande "//matchgsheet step2"' , $player); | ||||||
| 		} else { | 			} elseif (isset($data->error_code)) { | ||||||
| 			$this->maniaControl->getChat()->sendError('Unkown error' , $player); | 				$this->maniaControl->getChat()->sendError('Google refused the request: ' . $data->error_code, $player); | ||||||
| 		} | 			} else { | ||||||
|  | 				$this->maniaControl->getChat()->sendError('Unkown error' , $player); | ||||||
|  | 			} | ||||||
|  | 		}); | ||||||
|  |  | ||||||
|  | 		$asyncHttpRequest->postData(1000); | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	private function OAuth2Step2(Player $player) { | 	private function OAuth2Step2(Player $player) { | ||||||
| @@ -291,32 +296,37 @@ class MatchManagerGSheet implements  CallbackListener, CommandListener, Plugin { | |||||||
| 			return; | 			return; | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
| 		$response = WebReader::postUrl('https://oauth2.googleapis.com/token?grant_type=urn%3Aietf%3Aparams%3Aoauth%3Agrant-type%3Adevice_code&client_id=' . $clientid . '&client_secret=' . $clientsecret . '&device_code=' . $this->device_code); | 		$asyncHttpRequest = new AsyncHttpRequest($this->maniaControl, 'https://oauth2.googleapis.com/token?grant_type=urn%3Aietf%3Aparams%3Aoauth%3Agrant-type%3Adevice_code&client_id=' . $clientid . '&client_secret=' . $clientsecret . '&device_code=' . $this->device_code); | ||||||
| 		$json = $response->getContent(); | 		$asyncHttpRequest->setContentType("application/x-www-form-urlencoded"); | ||||||
| 		if (!$json) { | 		$asyncHttpRequest->setHeaders(array("Content-Length: 0")); | ||||||
| 			Logger::logError('Impossible to Google API: ' . $json); | 		$asyncHttpRequest->setCallable(function ($json, $error) use ($player) { | ||||||
| 			$this->maniaControl->getChat()->sendError('Impossible to Google API: ' . $json, $player); | 			if (!$json) { | ||||||
| 			return; | 				Logger::logError('Impossible to Google API: ' . $json); | ||||||
| 		} | 				$this->maniaControl->getChat()->sendError('Impossible to Google API: ' . $json, $player); | ||||||
| 		$data = json_decode($json); | 				return; | ||||||
| 		if (!$data) { | 			} | ||||||
| 			Logger::logError('Json parse error: ' . $json); | 			$data = json_decode($json); | ||||||
| 			$this->maniaControl->getChat()->sendError('Json parse error: ' . $json, $player); | 			if (!$data) { | ||||||
| 			return; | 				Logger::logError('Json parse error: ' . $json); | ||||||
| 		} | 				$this->maniaControl->getChat()->sendError('Json parse error: ' . $json, $player); | ||||||
| 		if (isset($data->access_token)) { | 				return; | ||||||
| 			$this->access_token = $data->access_token; | 			} | ||||||
| 			$this->saveSecretSetting("access_token", $data->access_token); | 			if (isset($data->access_token)) { | ||||||
| 			$this->saveSecretSetting("expire", time() + $data->expires_in); | 				$this->access_token = $data->access_token; | ||||||
| 			$this->saveSecretSetting("refresh_token", $data->refresh_token); | 				$this->saveSecretSetting("access_token", $data->access_token); | ||||||
| 			$this->maniaControl->getChat()->sendSuccess('Maniacontrol is registered' , $player); | 				$this->saveSecretSetting("expire", time() + $data->expires_in); | ||||||
| 		} elseif (isset($data->error_description)) { | 				$this->saveSecretSetting("refresh_token", $data->refresh_token); | ||||||
| 			Logger::logError('Google refused the request: ' . $data->error_description); | 				$this->maniaControl->getChat()->sendSuccess('Maniacontrol is registered' , $player); | ||||||
| 			$this->maniaControl->getChat()->sendError('Google refused the request: ' . $data->error_description , $player); | 			} elseif (isset($data->error_description)) { | ||||||
| 		} else { | 				Logger::logError('Google refused the request: ' . $data->error_description); | ||||||
| 			Logger::logError('Unkown error' . $data->error_description); | 				$this->maniaControl->getChat()->sendError('Google refused the request: ' . $data->error_description , $player); | ||||||
| 			$this->maniaControl->getChat()->sendError('Unkown error' , $player); | 			} else { | ||||||
| 		} | 				Logger::logError('Unkown error' . $data->error_description); | ||||||
|  | 				$this->maniaControl->getChat()->sendError('Unkown error' , $player); | ||||||
|  | 			} | ||||||
|  | 		}); | ||||||
|  |  | ||||||
|  | 		$asyncHttpRequest->postData(1000); | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	private function refreshTokenIfNeeded() { | 	private function refreshTokenIfNeeded() { | ||||||
| @@ -326,29 +336,33 @@ class MatchManagerGSheet implements  CallbackListener, CommandListener, Plugin { | |||||||
| 		$refreshtoken = $this->getSecretSetting("refresh_token"); | 		$refreshtoken = $this->getSecretSetting("refresh_token"); | ||||||
| 		$clientid = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MATCHMANAGERGSHEET_CLIENT_ID); | 		$clientid = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MATCHMANAGERGSHEET_CLIENT_ID); | ||||||
| 		$clientsecret = $this->getSecretSetting("client_secret"); | 		$clientsecret = $this->getSecretSetting("client_secret"); | ||||||
| 		 |  | ||||||
| 		if (!empty($refreshtoken) && !empty($expire) && !empty($clientid) && !empty($clientsecret)) { | 		if (!empty($refreshtoken) && !empty($expire) && !empty($clientid) && !empty($clientsecret)) { | ||||||
| 			if (time() >= $expire) { | 			if (time() >= $expire) { | ||||||
| 				$response = WebReader::postUrl('https://oauth2.googleapis.com/token?grant_type=refresh_token&client_id=' . $clientid . '&client_secret=' . $clientsecret . '&refresh_token=' . $refreshtoken); | 				$asyncHttpRequest = new AsyncHttpRequest($this->maniaControl, 'https://oauth2.googleapis.com/token?grant_type=refresh_token&client_id=' . $clientid . '&client_secret=' . $clientsecret . '&refresh_token=' . $refreshtoken); | ||||||
| 				$json = $response->getContent(); | 				$asyncHttpRequest->setContentType("application/x-www-form-urlencoded"); | ||||||
| 				if (!$json) { | 				$asyncHttpRequest->setCallable(function ($json, $error) use ($player) { | ||||||
| 					Logger::logError('Impossible to Google API: ' . $json); | 					if (!$json) { | ||||||
| 					return; | 						Logger::logError('Impossible to Google API: ' . $json); | ||||||
| 				} | 						return; | ||||||
| 				$data = json_decode($json); | 					} | ||||||
| 				if (!$data) { | 					$data = json_decode($json); | ||||||
| 					Logger::logError('Json parse error: ' . $json); | 					if (!$data) { | ||||||
| 					return; | 						Logger::logError('Json parse error: ' . $json); | ||||||
| 				} | 						return; | ||||||
| 				if (isset($data->access_token)) { | 					} | ||||||
| 					$this->access_token = $data->access_token; | 					if (isset($data->access_token)) { | ||||||
| 					$this->saveSecretSetting("access_token", $data->access_token); | 						$this->access_token = $data->access_token; | ||||||
| 					$this->saveSecretSetting("expire", time() + $data->expires_in); | 						$this->saveSecretSetting("access_token", $data->access_token); | ||||||
| 				} elseif (isset($data->error_description)) { | 						$this->saveSecretSetting("expire", time() + $data->expires_in); | ||||||
| 					$this->maniaControl->getChat()->sendError('Google refused the request: ' . $data->error_description , $player); | 					} elseif (isset($data->error_description)) { | ||||||
| 				} else { | 						$this->maniaControl->getChat()->sendError('Google refused the request: ' . $data->error_description , $player); | ||||||
| 					$this->maniaControl->getChat()->sendError('Unkown error' , $player); | 					} else { | ||||||
| 				} | 						$this->maniaControl->getChat()->sendError('Unkown error' , $player); | ||||||
|  | 					} | ||||||
|  | 				}); | ||||||
|  |  | ||||||
|  | 				$asyncHttpRequest->postData(1000); | ||||||
| 			} | 			} | ||||||
| 			return true; | 			return true; | ||||||
| 		} | 		} | ||||||
| @@ -410,7 +424,7 @@ class MatchManagerGSheet implements  CallbackListener, CommandListener, Plugin { | |||||||
| 					$this->maniaControl->getChat()->sendError("Can't access to the Spreadsheet: " . $data->error->message, $player); | 					$this->maniaControl->getChat()->sendError("Can't access to the Spreadsheet: " . $data->error->message, $player); | ||||||
| 				} | 				} | ||||||
| 			}); | 			}); | ||||||
| 	 |  | ||||||
| 			$asyncHttpRequest->getData(1000); | 			$asyncHttpRequest->getData(1000); | ||||||
| 		} else { | 		} else { | ||||||
| 			$this->maniaControl->getChat()->sendError("Can't have access to Google API service", $player); | 			$this->maniaControl->getChat()->sendError("Can't have access to Google API service", $player); | ||||||
| @@ -445,7 +459,6 @@ class MatchManagerGSheet implements  CallbackListener, CommandListener, Plugin { | |||||||
| 			$data->data[1] = new \stdClass; | 			$data->data[1] = new \stdClass; | ||||||
| 			$data->data[1]->range = "'" . $sheetname . "'!A9"; | 			$data->data[1]->range = "'" . $sheetname . "'!A9"; | ||||||
|  |  | ||||||
| 			 |  | ||||||
| 			foreach ($this->maniaControl->getPlayerManager()->getPlayers() as $player) { | 			foreach ($this->maniaControl->getPlayerManager()->getPlayers() as $player) { | ||||||
| 				$this->playerlist[$player->login] = $player->nickname; | 				$this->playerlist[$player->login] = $player->nickname; | ||||||
| 			} | 			} | ||||||
| @@ -460,7 +473,7 @@ class MatchManagerGSheet implements  CallbackListener, CommandListener, Plugin { | |||||||
| 				$data->data[2] = new \stdClass; | 				$data->data[2] = new \stdClass; | ||||||
| 				$data->data[2]->range = "'" . $sheetname . "'!" . self::MODE_SPECIFICS_SETTINGS[$this->currentdatamode]["ScoreTable_BeginLetter"] . "2"; | 				$data->data[2]->range = "'" . $sheetname . "'!" . self::MODE_SPECIFICS_SETTINGS[$this->currentdatamode]["ScoreTable_BeginLetter"] . "2"; | ||||||
| 				$data->data[2]->values = $currentscore; | 				$data->data[2]->values = $currentscore; | ||||||
| 	 |  | ||||||
| 				$data->data[3] = new \stdClass; | 				$data->data[3] = new \stdClass; | ||||||
| 				$data->data[3]->range = "'" . $sheetname . "'!" . self::MODE_SPECIFICS_SETTINGS[$this->currentdatamode]["TeamsScoreTable_BeginLetter"] . "2"; | 				$data->data[3]->range = "'" . $sheetname . "'!" . self::MODE_SPECIFICS_SETTINGS[$this->currentdatamode]["TeamsScoreTable_BeginLetter"] . "2"; | ||||||
| 				$data->data[3]->values = $currentteamsscore; | 				$data->data[3]->values = $currentteamsscore; | ||||||
| @@ -486,12 +499,12 @@ class MatchManagerGSheet implements  CallbackListener, CommandListener, Plugin { | |||||||
| 					foreach ($currentscore as $score) { | 					foreach ($currentscore as $score) { | ||||||
| 						array_push($newcurrentscore,array_merge([$this->MatchManagerCore->getMapNumber() , $this->MatchManagerCore->getRoundNumber()], $score)); | 						array_push($newcurrentscore,array_merge([$this->MatchManagerCore->getMapNumber() , $this->MatchManagerCore->getRoundNumber()], $score)); | ||||||
| 					} | 					} | ||||||
| 	 |  | ||||||
| 					$data = new \stdClass; | 					$data = new \stdClass; | ||||||
| 					$data->range = "'" . $sheetname . "'!" . self::MODE_SPECIFICS_SETTINGS[$this->currentdatamode]["ScoreTable_BeginLetter"] . "1:" . self::MODE_SPECIFICS_SETTINGS[$this->currentdatamode]["ScoreTable_EndLetter"] . "1" ; | 					$data->range = "'" . $sheetname . "'!" . self::MODE_SPECIFICS_SETTINGS[$this->currentdatamode]["ScoreTable_BeginLetter"] . "1:" . self::MODE_SPECIFICS_SETTINGS[$this->currentdatamode]["ScoreTable_EndLetter"] . "1" ; | ||||||
| 					$data->majorDimension = "ROWS"; | 					$data->majorDimension = "ROWS"; | ||||||
| 					$data->values = $newcurrentscore; | 					$data->values = $newcurrentscore; | ||||||
| 	 |  | ||||||
| 					$asyncHttpRequest = new AsyncHttpRequest($this->maniaControl, 'https://sheets.googleapis.com/v4/spreadsheets/' . $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MATCHMANAGERGSHEET_SPREADSHEET) . '/values/' . urlencode("'". $sheetname . "'") . "!" . self::MODE_SPECIFICS_SETTINGS[$this->currentdatamode]["ScoreTable_BeginLetter"] . "1:" . self::MODE_SPECIFICS_SETTINGS[$this->currentdatamode]["ScoreTable_EndLetter"] . "1:append?valueInputOption=RAW"); | 					$asyncHttpRequest = new AsyncHttpRequest($this->maniaControl, 'https://sheets.googleapis.com/v4/spreadsheets/' . $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MATCHMANAGERGSHEET_SPREADSHEET) . '/values/' . urlencode("'". $sheetname . "'") . "!" . self::MODE_SPECIFICS_SETTINGS[$this->currentdatamode]["ScoreTable_BeginLetter"] . "1:" . self::MODE_SPECIFICS_SETTINGS[$this->currentdatamode]["ScoreTable_EndLetter"] . "1:append?valueInputOption=RAW"); | ||||||
| 					$asyncHttpRequest->setContentType(AsyncHttpRequest::CONTENT_TYPE_JSON); | 					$asyncHttpRequest->setContentType(AsyncHttpRequest::CONTENT_TYPE_JSON); | ||||||
| 					$asyncHttpRequest->setHeaders(array("Authorization: Bearer " . $this->access_token)); | 					$asyncHttpRequest->setHeaders(array("Authorization: Bearer " . $this->access_token)); | ||||||
| @@ -512,12 +525,12 @@ class MatchManagerGSheet implements  CallbackListener, CommandListener, Plugin { | |||||||
| 							foreach ($currentteamsscore as $score) { | 							foreach ($currentteamsscore as $score) { | ||||||
| 								array_push($newcurrentteamsscore,array_merge([$this->MatchManagerCore->getMapNumber() , $this->MatchManagerCore->getRoundNumber()], $score)); | 								array_push($newcurrentteamsscore,array_merge([$this->MatchManagerCore->getMapNumber() , $this->MatchManagerCore->getRoundNumber()], $score)); | ||||||
| 							} | 							} | ||||||
| 			 |  | ||||||
| 							$data = new \stdClass; | 							$data = new \stdClass; | ||||||
| 							$data->range = "'" . $sheetname . "'!" . self::MODE_SPECIFICS_SETTINGS[$this->currentdatamode]["TeamsScoreTable_BeginLetter"] . "1:" . self::MODE_SPECIFICS_SETTINGS[$this->currentdatamode]["TeamsScoreTable_EndLetter"] . "1" ; | 							$data->range = "'" . $sheetname . "'!" . self::MODE_SPECIFICS_SETTINGS[$this->currentdatamode]["TeamsScoreTable_BeginLetter"] . "1:" . self::MODE_SPECIFICS_SETTINGS[$this->currentdatamode]["TeamsScoreTable_EndLetter"] . "1" ; | ||||||
| 							$data->majorDimension = "ROWS"; | 							$data->majorDimension = "ROWS"; | ||||||
| 							$data->values = $newcurrentteamsscore; | 							$data->values = $newcurrentteamsscore; | ||||||
| 			 |  | ||||||
| 							$asyncHttpRequest = new AsyncHttpRequest($this->maniaControl, 'https://sheets.googleapis.com/v4/spreadsheets/' . $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MATCHMANAGERGSHEET_SPREADSHEET) . '/values/' . urlencode("'". $sheetname . "'") . "!" . self::MODE_SPECIFICS_SETTINGS[$this->currentdatamode]["TeamsScoreTable_BeginLetter"] . "1:" . self::MODE_SPECIFICS_SETTINGS[$this->currentdatamode]["TeamsScoreTable_EndLetter"] . "1:append?valueInputOption=RAW"); | 							$asyncHttpRequest = new AsyncHttpRequest($this->maniaControl, 'https://sheets.googleapis.com/v4/spreadsheets/' . $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MATCHMANAGERGSHEET_SPREADSHEET) . '/values/' . urlencode("'". $sheetname . "'") . "!" . self::MODE_SPECIFICS_SETTINGS[$this->currentdatamode]["TeamsScoreTable_BeginLetter"] . "1:" . self::MODE_SPECIFICS_SETTINGS[$this->currentdatamode]["TeamsScoreTable_EndLetter"] . "1:append?valueInputOption=RAW"); | ||||||
| 							$asyncHttpRequest->setContentType(AsyncHttpRequest::CONTENT_TYPE_JSON); | 							$asyncHttpRequest->setContentType(AsyncHttpRequest::CONTENT_TYPE_JSON); | ||||||
| 							$asyncHttpRequest->setHeaders(array("Authorization: Bearer " . $this->access_token)); | 							$asyncHttpRequest->setHeaders(array("Authorization: Bearer " . $this->access_token)); | ||||||
| @@ -548,7 +561,10 @@ class MatchManagerGSheet implements  CallbackListener, CommandListener, Plugin { | |||||||
| 	function onCallbackEndMatch(String $matchid, Array $currentscore, Array $currentteamsscore) { | 	function onCallbackEndMatch(String $matchid, Array $currentscore, Array $currentteamsscore) { | ||||||
| 		Logger::Log('onCallbackEndMatch'); | 		Logger::Log('onCallbackEndMatch'); | ||||||
| 		$this->matchstatus = "ended"; | 		$this->matchstatus = "ended"; | ||||||
| 		$this->UpdateGSheetData($matchid, $currentscore, $currentteamsscore); |  | ||||||
|  | 		$this->maniaControl->getTimerManager()->registerOneTimeListening($this, function () use ($matchid, $currentscore, $currentteamsscore) { | ||||||
|  | 			$this->UpdateGSheetData($matchid, $currentscore, $currentteamsscore); | ||||||
|  | 		}, 1000); // Wait a sec before sending last data to avoid collision | ||||||
| 	} | 	} | ||||||
| 	function onCallbackStopMatch(String $matchid, Array $currentscore, Array $currentteamsscore) { | 	function onCallbackStopMatch(String $matchid, Array $currentscore, Array $currentteamsscore) { | ||||||
| 		Logger::Log('onCallbackStopMatch'); | 		Logger::Log('onCallbackStopMatch'); | ||||||
| @@ -594,7 +610,7 @@ class MatchManagerGSheet implements  CallbackListener, CommandListener, Plugin { | |||||||
|  |  | ||||||
| 				} | 				} | ||||||
| 			}); | 			}); | ||||||
| 	 |  | ||||||
| 			$asyncHttpRequest->getData(1000); | 			$asyncHttpRequest->getData(1000); | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| @@ -771,4 +787,4 @@ class MatchManagerGSheet implements  CallbackListener, CommandListener, Plugin { | |||||||
| 			$asyncHttpRequest->postData(1000); | 			$asyncHttpRequest->postData(1000); | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
		Reference in New Issue
	
	Block a user