fix php 8.4 compatibility + improve logging / chat messages
This commit is contained in:
		| @@ -12,8 +12,8 @@ use ManiaControl\Settings\SettingManager; | |||||||
| use ManiaControl\Callbacks\TimerListener; | use ManiaControl\Callbacks\TimerListener; | ||||||
|  |  | ||||||
| if (!class_exists('MatchManagerSuite\MatchManagerCore')) { | if (!class_exists('MatchManagerSuite\MatchManagerCore')) { | ||||||
| 	$this->maniaControl->getChat()->sendErrorToAdmins('MatchManager Core is required to use one of MatchManager plugin. Install it and restart Maniacontrol'); | 	$this->maniaControl->getChat()->sendErrorToAdmins('MatchManager Core is required to use MatchManagerAutomaticLauncher plugin. Install it and restart Maniacontrol'); | ||||||
| 	Logger::logError('MatchManager Core is required to use one of MatchManager plugin. Install it and restart Maniacontrol'); | 	Logger::logError('MatchManager Core is required to use MatchManagerAutomaticLauncher plugin. Install it and restart Maniacontrol'); | ||||||
| 	return false; | 	return false; | ||||||
| } | } | ||||||
|  |  | ||||||
| @@ -42,6 +42,7 @@ class MatchManagerAutomaticLauncher implements CallbackListener, TimerListener, | |||||||
| 	 */ | 	 */ | ||||||
| 	/** @var ManiaControl $maniaControl */ | 	/** @var ManiaControl $maniaControl */ | ||||||
| 	private $maniaControl 			= null; | 	private $maniaControl 			= null; | ||||||
|  | 	/** @var MatchManagerCore $MatchManagerCore */ | ||||||
| 	private $MatchManagerCore		= null; | 	private $MatchManagerCore		= null; | ||||||
|  |  | ||||||
|  |  | ||||||
| @@ -101,7 +102,7 @@ class MatchManagerAutomaticLauncher implements CallbackListener, TimerListener, | |||||||
| 				$this->MatchManagerCore = $this->maniaControl->getPluginManager()->getPlugin(self::MATCHMANAGERCORE_PLUGIN); | 				$this->MatchManagerCore = $this->maniaControl->getPluginManager()->getPlugin(self::MATCHMANAGERCORE_PLUGIN); | ||||||
| 				if ($this->MatchManagerCore == null) { | 				if ($this->MatchManagerCore == null) { | ||||||
| 					$this->maniaControl->getChat()->sendErrorToAdmins('MatchManager Core is needed to use ' . self::PLUGIN_NAME . ' plugin.'); | 					$this->maniaControl->getChat()->sendErrorToAdmins('MatchManager Core is needed to use ' . self::PLUGIN_NAME . ' plugin.'); | ||||||
| 					$this->maniaControl->getPluginManager()->deactivatePlugin((get_class())); | 					$this->maniaControl->getPluginManager()->deactivatePlugin((get_class($this))); | ||||||
| 				} else { | 				} else { | ||||||
| 					$this->createTimers(); | 					$this->createTimers(); | ||||||
| 				} | 				} | ||||||
| @@ -146,7 +147,7 @@ class MatchManagerAutomaticLauncher implements CallbackListener, TimerListener, | |||||||
| 	public function handlePluginUnloaded(string $pluginClass, Plugin $plugin) { | 	public function handlePluginUnloaded(string $pluginClass, Plugin $plugin) { | ||||||
| 		if ($pluginClass == self::MATCHMANAGERCORE_PLUGIN) { | 		if ($pluginClass == self::MATCHMANAGERCORE_PLUGIN) { | ||||||
| 			$this->maniaControl->getChat()->sendErrorToAdmins(self::PLUGIN_NAME . " disabled because MatchManager Core is now disabled"); | 			$this->maniaControl->getChat()->sendErrorToAdmins(self::PLUGIN_NAME . " disabled because MatchManager Core is now disabled"); | ||||||
| 			$this->maniaControl->getPluginManager()->deactivatePlugin((get_class())); | 			$this->maniaControl->getPluginManager()->deactivatePlugin((get_class($this))); | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| 	 | 	 | ||||||
| @@ -170,6 +171,6 @@ class MatchManagerAutomaticLauncher implements CallbackListener, TimerListener, | |||||||
| 				$newtimers++; | 				$newtimers++; | ||||||
| 			} | 			} | ||||||
| 		} | 		} | ||||||
| 		$this->maniaControl->getChat()->sendSuccessToAdmins($newtimers . " matches are planned"); | 		$this->maniaControl->getChat()->sendSuccessToAdmins($this->MatchManagerCore->getChatPrefix() . $newtimers . " matches are planned"); | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
| @@ -37,6 +37,8 @@ class MatchManagerECircuitMania implements CallbackListener, ManialinkPageAnswer | |||||||
| 	const PLUGIN_NAME		= 'MatchManager eCircuitMania'; | 	const PLUGIN_NAME		= 'MatchManager eCircuitMania'; | ||||||
| 	const PLUGIN_AUTHOR		= 'Beu'; | 	const PLUGIN_AUTHOR		= 'Beu'; | ||||||
|  |  | ||||||
|  | 	const LOG_PREFIX					= '[MatchManagerECircuitMania] '; | ||||||
|  |  | ||||||
| 	const MATCHMANAGERCORE_PLUGIN		= 'MatchManagerSuite\MatchManagerCore'; | 	const MATCHMANAGERCORE_PLUGIN		= 'MatchManagerSuite\MatchManagerCore'; | ||||||
| 	const MATCHMANAGERADMINUI_PLUGIN	= 'MatchManagerSuite\MatchManagerAdminUI'; | 	const MATCHMANAGERADMINUI_PLUGIN	= 'MatchManagerSuite\MatchManagerAdminUI'; | ||||||
|  |  | ||||||
| @@ -108,7 +110,7 @@ class MatchManagerECircuitMania implements CallbackListener, ManialinkPageAnswer | |||||||
| 				$this->MatchManagerCore = $this->maniaControl->getPluginManager()->getPlugin(self::MATCHMANAGERCORE_PLUGIN); | 				$this->MatchManagerCore = $this->maniaControl->getPluginManager()->getPlugin(self::MATCHMANAGERCORE_PLUGIN); | ||||||
| 				if ($this->MatchManagerCore === null) { | 				if ($this->MatchManagerCore === null) { | ||||||
| 					$this->maniaControl->getChat()->sendErrorToAdmins('MatchManager Core is needed to use ' . self::PLUGIN_NAME . ' plugin.'); | 					$this->maniaControl->getChat()->sendErrorToAdmins('MatchManager Core is needed to use ' . self::PLUGIN_NAME . ' plugin.'); | ||||||
| 					$this->maniaControl->getPluginManager()->deactivatePlugin((get_class())); | 					$this->maniaControl->getPluginManager()->deactivatePlugin((get_class($this))); | ||||||
| 					return; | 					return; | ||||||
| 				} | 				} | ||||||
|  |  | ||||||
| @@ -130,6 +132,24 @@ class MatchManagerECircuitMania implements CallbackListener, ManialinkPageAnswer | |||||||
| 		$this->maniaControl->getManialinkManager()->registerManialinkPageAnswerListener(self::ML_ACTION_OPENSETTINGS, $this, 'handleActionOpenSettings'); | 		$this->maniaControl->getManialinkManager()->registerManialinkPageAnswerListener(self::ML_ACTION_OPENSETTINGS, $this, 'handleActionOpenSettings'); | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
|  | 	/** | ||||||
|  | 	 * Custom log function to add prefix | ||||||
|  | 	 *  | ||||||
|  | 	 * @param mixed $message | ||||||
|  | 	 */ | ||||||
|  | 	private function log(mixed $message) { | ||||||
|  | 		Logger::log(self::LOG_PREFIX . $message); | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	/** | ||||||
|  | 	 * Custom logError function to add prefix | ||||||
|  | 	 *  | ||||||
|  | 	 * @param mixed $message | ||||||
|  | 	 */ | ||||||
|  | 	private function logError(mixed $message) { | ||||||
|  | 		Logger::logError(self::LOG_PREFIX . $message); | ||||||
|  | 	} | ||||||
|  |  | ||||||
| 	/** | 	/** | ||||||
| 	 * handle Plugin Loaded | 	 * handle Plugin Loaded | ||||||
| 	 *  | 	 *  | ||||||
| @@ -214,7 +234,7 @@ class MatchManagerECircuitMania implements CallbackListener, ManialinkPageAnswer | |||||||
| 		if ($request !== null) { | 		if ($request !== null) { | ||||||
| 			$request->setContent($payload)->setCallable(function ($content, $error, $headers) use ($payload) { | 			$request->setContent($payload)->setCallable(function ($content, $error, $headers) use ($payload) { | ||||||
| 				if ($content !== "Created" || $error !== null) { | 				if ($content !== "Created" || $error !== null) { | ||||||
| 					Logger::logWarning("Error on the 'addRoundTime' request. answer: " . $content . " / error: " . $error . " / payload: " . $payload); | 					$this->logError("Error on the 'addRoundTime' request. answer: " . $content . " / error: " . $error . " / payload: " . $payload); | ||||||
| 				} | 				} | ||||||
| 			})->postData(); | 			})->postData(); | ||||||
| 		} | 		} | ||||||
| @@ -226,7 +246,6 @@ class MatchManagerECircuitMania implements CallbackListener, ManialinkPageAnswer | |||||||
|  |  | ||||||
| 		$scores = []; | 		$scores = []; | ||||||
| 		foreach ($structure->getPlayerScores() as $playerscore) { | 		foreach ($structure->getPlayerScores() as $playerscore) { | ||||||
| 			if ($playerscore->getMatchPoints() <= -2000) continue; |  | ||||||
| 			$scores[] = $playerscore; | 			$scores[] = $playerscore; | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
| @@ -284,7 +303,7 @@ class MatchManagerECircuitMania implements CallbackListener, ManialinkPageAnswer | |||||||
| 		if ($request !== null) { | 		if ($request !== null) { | ||||||
| 			$request->setContent($payload)->setCallable(function ($content, $error, $headers) use ($payload) { | 			$request->setContent($payload)->setCallable(function ($content, $error, $headers) use ($payload) { | ||||||
| 				if ($content !== "Created" || $error !== null) { | 				if ($content !== "Created" || $error !== null) { | ||||||
| 					Logger::logWarning("Error on the 'addRound' request. answer: " . $content . " / error: " . $error . " / payload: " . $payload); | 					$this->logError("Error on the 'addRound' request. answer: " . $content . " / error: " . $error . " / payload: " . $payload); | ||||||
| 				} | 				} | ||||||
| 			})->postData(); | 			})->postData(); | ||||||
| 		} | 		} | ||||||
| @@ -304,7 +323,7 @@ class MatchManagerECircuitMania implements CallbackListener, ManialinkPageAnswer | |||||||
| 		if ($request !== null) { | 		if ($request !== null) { | ||||||
| 			$request->setContent($payload)->setCallable(function ($content, $error, $headers) use ($payload) { | 			$request->setContent($payload)->setCallable(function ($content, $error, $headers) use ($payload) { | ||||||
| 				if ($content !== "Created" || $error !== null) { | 				if ($content !== "Created" || $error !== null) { | ||||||
| 					Logger::logWarning("Error on the 'removeRound' request. answer: " . $content . " / error: " . $error . " / payload: " . $payload); | 					$this->logError("Error on the 'removeRound' request. answer: " . $content . " / error: " . $error . " / payload: " . $payload); | ||||||
| 				} | 				} | ||||||
| 			})->postData(); | 			})->postData(); | ||||||
| 		} | 		} | ||||||
|   | |||||||
| @@ -21,8 +21,8 @@ use ManiaControl\Plugins\PluginMenu; | |||||||
| use ManiaControl\Utils\WebReader; | use ManiaControl\Utils\WebReader; | ||||||
|  |  | ||||||
| if (!class_exists('MatchManagerSuite\MatchManagerCore')) { | if (!class_exists('MatchManagerSuite\MatchManagerCore')) { | ||||||
| 	$this->maniaControl->getChat()->sendErrorToAdmins('MatchManager Core is required to use one of MatchManager plugin. Install it and restart Maniacontrol'); | 	$this->maniaControl->getChat()->sendErrorToAdmins('MatchManager Core is required to use MatchManagerGSheet plugin. Install it and restart Maniacontrol'); | ||||||
| 	Logger::logError('MatchManager Core is required to use one of MatchManager plugin. Install it and restart Maniacontrol'); | 	Logger::logError('MatchManager Core is required to use MatchManagerGSheet plugin. Install it and restart Maniacontrol'); | ||||||
| 	return false; | 	return false; | ||||||
| } | } | ||||||
| use MatchManagerSuite\MatchManagerCore; | use MatchManagerSuite\MatchManagerCore; | ||||||
| @@ -43,6 +43,8 @@ class MatchManagerGSheet implements  CallbackListener, TimerListener, CommandLis | |||||||
| 	const PLUGIN_NAME										= 'MatchManager GSheet'; | 	const PLUGIN_NAME										= 'MatchManager GSheet'; | ||||||
| 	const PLUGIN_AUTHOR										= 'Beu'; | 	const PLUGIN_AUTHOR										= 'Beu'; | ||||||
|  |  | ||||||
|  | 	const LOG_PREFIX										= '[MatchManagerGSheet] '; | ||||||
|  |  | ||||||
| 	// Other MatchManager plugin | 	// Other MatchManager plugin | ||||||
| 	const MATCHMANAGERADMINUI_PLUGIN						= 'MatchManagerSuite\MatchManagerAdminUI'; | 	const MATCHMANAGERADMINUI_PLUGIN						= 'MatchManagerSuite\MatchManagerAdminUI'; | ||||||
|  |  | ||||||
| @@ -213,6 +215,24 @@ class MatchManagerGSheet implements  CallbackListener, TimerListener, CommandLis | |||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
|  | 	/** | ||||||
|  | 	 * Custom log function to add prefix | ||||||
|  | 	 *  | ||||||
|  | 	 * @param mixed $message | ||||||
|  | 	 */ | ||||||
|  | 	private function log(mixed $message) { | ||||||
|  | 		Logger::log(self::LOG_PREFIX . $message); | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	/** | ||||||
|  | 	 * Custom logError function to add prefix | ||||||
|  | 	 *  | ||||||
|  | 	 * @param mixed $message | ||||||
|  | 	 */ | ||||||
|  | 	private function logError(mixed $message) { | ||||||
|  | 		Logger::logError(self::LOG_PREFIX . $message); | ||||||
|  | 	} | ||||||
|  |  | ||||||
| 	/** | 	/** | ||||||
| 	 * handle Plugin Loaded | 	 * handle Plugin Loaded | ||||||
| 	 *  | 	 *  | ||||||
| @@ -243,7 +263,8 @@ class MatchManagerGSheet implements  CallbackListener, TimerListener, CommandLis | |||||||
| 	public function handlePluginUnloaded(string $pluginClass, Plugin $plugin) { | 	public function handlePluginUnloaded(string $pluginClass, Plugin $plugin) { | ||||||
| 		if ($pluginClass == self::MATCHMANAGERCORE_PLUGIN) { | 		if ($pluginClass == self::MATCHMANAGERCORE_PLUGIN) { | ||||||
| 			$this->maniaControl->getChat()->sendErrorToAdmins(self::PLUGIN_NAME . " disabled because MatchManager Core is now disabled"); | 			$this->maniaControl->getChat()->sendErrorToAdmins(self::PLUGIN_NAME . " disabled because MatchManager Core is now disabled"); | ||||||
| 			$this->maniaControl->getPluginManager()->deactivatePlugin((get_class())); | 			$this->log(self::PLUGIN_NAME . " disabled because MatchManager Core is now disabled"); | ||||||
|  | 			$this->maniaControl->getPluginManager()->deactivatePlugin((get_class($this))); | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| @@ -272,7 +293,7 @@ class MatchManagerGSheet implements  CallbackListener, TimerListener, CommandLis | |||||||
| 		if ($setting->belongsToClass($this)) { | 		if ($setting->belongsToClass($this)) { | ||||||
| 			if (($setting->setting == self::SETTING_MATCHMANAGERGSHEET_CLIENT_SECRET && $setting->value == "hidden") || $setting->setting == self::SETTING_MATCHMANAGERGSHEET_CLIENT_ID) { | 			if (($setting->setting == self::SETTING_MATCHMANAGERGSHEET_CLIENT_SECRET && $setting->value == "hidden") || $setting->setting == self::SETTING_MATCHMANAGERGSHEET_CLIENT_ID) { | ||||||
| 				// (Check when hidden = true to avoid double message) | 				// (Check when hidden = true to avoid double message) | ||||||
| 				$this->maniaControl->getChat()->sendErrorToAdmins('Google API Session cleared. You must revalidate a session with //matchgsheet step1'); | 				$this->maniaControl->getChat()->sendErrorToAdmins($this->MatchManagerCore->getChatPrefix() .'Google API Session cleared. You must revalidate a session with //matchgsheet step1'); | ||||||
|  |  | ||||||
| 				$this->saveSecretSetting("access_token"); | 				$this->saveSecretSetting("access_token"); | ||||||
| 				$this->saveSecretSetting("expire"); | 				$this->saveSecretSetting("expire"); | ||||||
| @@ -292,7 +313,7 @@ class MatchManagerGSheet implements  CallbackListener, TimerListener, CommandLis | |||||||
|  |  | ||||||
| 	public function handlePlayerConnect(Player $player) { | 	public function handlePlayerConnect(Player $player) { | ||||||
| 		if ($this->maniaControl->getAuthenticationManager()->checkRight($player, AuthenticationManager::AUTH_LEVEL_ADMIN)) { | 		if ($this->maniaControl->getAuthenticationManager()->checkRight($player, AuthenticationManager::AUTH_LEVEL_ADMIN)) { | ||||||
| 			$this->maniaControl->getChat()->sendError('Since MatchManagerGSheet 2.0, Player names are in the results and no more in a separated list', $player->login); | 			$this->maniaControl->getChat()->sendError($this->MatchManagerCore->getChatPrefix() .'Since MatchManagerGSheet 2.0, Player names are in the results and no more in a separated list', $player->login); | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| @@ -346,15 +367,15 @@ class MatchManagerGSheet implements  CallbackListener, TimerListener, CommandLis | |||||||
| 		} elseif (isset($text[1]) && $text[1] == 'check') {  | 		} elseif (isset($text[1]) && $text[1] == 'check') {  | ||||||
| 			$this->CheckSpeadsheetAccess($player); | 			$this->CheckSpeadsheetAccess($player); | ||||||
| 		} else { | 		} else { | ||||||
| 			$this->maniaControl->getChat()->sendError('use argument "step1", "step2" or "check"', $player); | 			$this->maniaControl->getChat()->sendError($this->MatchManagerCore->getChatPrefix() .'use argument "step1", "step2" or "check"', $player); | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	private function OAuth2Step1(Player $player) { | 	private function OAuth2Step1(Player $player) { | ||||||
| 		$clientid = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MATCHMANAGERGSHEET_CLIENT_ID); | 		$clientid = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MATCHMANAGERGSHEET_CLIENT_ID); | ||||||
| 		if (empty($clientid)) { | 		if (empty($clientid)) { | ||||||
| 			Logger::logError('Client ID empty'); | 			$this->logError('Client ID empty'); | ||||||
| 			$this->maniaControl->getChat()->sendError('Client ID empty', $player); | 			$this->maniaControl->getChat()->sendError($this->MatchManagerCore->getChatPrefix() .'Client ID empty', $player); | ||||||
| 			return; | 			return; | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
| @@ -362,29 +383,29 @@ class MatchManagerGSheet implements  CallbackListener, TimerListener, CommandLis | |||||||
| 		$asyncHttpRequest->setContentType("application/x-www-form-urlencoded"); | 		$asyncHttpRequest->setContentType("application/x-www-form-urlencoded"); | ||||||
| 		$asyncHttpRequest->setCallable(function ($json, $error) use ($player) { | 		$asyncHttpRequest->setCallable(function ($json, $error) use ($player) { | ||||||
| 			if (!$json || $error) { | 			if (!$json || $error) { | ||||||
| 				Logger::logError('Error from Google API: ' . $error); | 				$this->logError('Error from Google API: ' . $error); | ||||||
| 				$this->maniaControl->getChat()->sendError('Error from Google API: ' . $error, $player); | 				$this->maniaControl->getChat()->sendError($this->MatchManagerCore->getChatPrefix() .'Error from Google API: ' . $error, $player); | ||||||
| 				return; | 				return; | ||||||
| 			} | 			} | ||||||
| 			$data = json_decode($json); | 			$data = json_decode($json); | ||||||
| 			if (!$data) { | 			if (!$data) { | ||||||
| 				Logger::logError('Json parse error: ' . $json); | 				$this->logError('Json parse error: ' . $json); | ||||||
| 				$this->maniaControl->getChat()->sendError('Json parse error: ' . $json, $player); | 				$this->maniaControl->getChat()->sendError($this->MatchManagerCore->getChatPrefix() .'Json parse error: ' . $json, $player); | ||||||
| 				return; | 				return; | ||||||
| 			} | 			} | ||||||
| 			if (property_exists($data, "error")) { | 			if (property_exists($data, "error")) { | ||||||
| 				Logger::logError('Request error: ' . $data->error->code . " ". $data->error->message); | 				$this->logError('Request error: ' . $data->error->code . " ". $data->error->message); | ||||||
| 				$this->maniaControl->getChat()->sendErrorToAdmins('Request error: ' . $data->error->code . " ". $data->error->message); | 				$this->maniaControl->getChat()->sendErrorToAdmins($this->MatchManagerCore->getChatPrefix() .'Request error: ' . $data->error->code . " ". $data->error->message); | ||||||
| 				return; | 				return; | ||||||
| 			} | 			} | ||||||
| 			if (isset($data->device_code)) { | 			if (isset($data->device_code)) { | ||||||
| 				$this->device_code = $data->device_code; | 				$this->device_code = $data->device_code; | ||||||
| 				$this->maniaControl->getChat()->sendSuccess('Open $<$l['. $data->verification_url .'?user_code=' . $data->user_code . ']this link$> and type this code: "' . $data->user_code .'"' , $player); | 				$this->maniaControl->getChat()->sendSuccess($this->MatchManagerCore->getChatPrefix() .'Open $<$l['. $data->verification_url .'?user_code=' . $data->user_code . ']this link$> and type this code: "' . $data->user_code .'"' , $player); | ||||||
| 				$this->maniaControl->getChat()->sendSuccess('After have validate the App, type the commande "//matchgsheet step2"' , $player); | 				$this->maniaControl->getChat()->sendSuccess($this->MatchManagerCore->getChatPrefix() .'After have validate the App, type the commande "//matchgsheet step2"' , $player); | ||||||
| 			} elseif (isset($data->error_code)) { | 			} elseif (isset($data->error_code)) { | ||||||
| 				$this->maniaControl->getChat()->sendError('Google refused the request: ' . $data->error_code, $player); | 				$this->maniaControl->getChat()->sendError($this->MatchManagerCore->getChatPrefix() .'Google refused the request: ' . $data->error_code, $player); | ||||||
| 			} else { | 			} else { | ||||||
| 				$this->maniaControl->getChat()->sendError('Unkown error' , $player); | 				$this->maniaControl->getChat()->sendError($this->MatchManagerCore->getChatPrefix() .'Unkown error' , $player); | ||||||
| 			} | 			} | ||||||
| 		}); | 		}); | ||||||
|  |  | ||||||
| @@ -394,21 +415,21 @@ class MatchManagerGSheet implements  CallbackListener, TimerListener, CommandLis | |||||||
| 	private function OAuth2Step2(Player $player) { | 	private function OAuth2Step2(Player $player) { | ||||||
| 		$clientid = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MATCHMANAGERGSHEET_CLIENT_ID); | 		$clientid = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MATCHMANAGERGSHEET_CLIENT_ID); | ||||||
| 		if (empty($clientid)) { | 		if (empty($clientid)) { | ||||||
| 			Logger::logError('Client ID empty'); | 			$this->logError('Client ID empty'); | ||||||
| 			$this->maniaControl->getChat()->sendError('Client ID empty', $player); | 			$this->maniaControl->getChat()->sendError($this->MatchManagerCore->getChatPrefix() .'Client ID empty', $player); | ||||||
| 			return; | 			return; | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
| 		$clientsecret = $this->getSecretSetting("client_secret"); | 		$clientsecret = $this->getSecretSetting("client_secret"); | ||||||
| 		if (empty($clientsecret)) { | 		if (empty($clientsecret)) { | ||||||
| 			Logger::logError('Client Secret empty'); | 			$this->logError('Client Secret empty'); | ||||||
| 			$this->maniaControl->getChat()->sendError('Client Secret empty', $player); | 			$this->maniaControl->getChat()->sendError($this->MatchManagerCore->getChatPrefix() .'Client Secret empty', $player); | ||||||
| 			return; | 			return; | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
| 		if (empty($this->device_code)) { | 		if (empty($this->device_code)) { | ||||||
| 			Logger::logError('No device_code. Have you run the step 1?'); | 			$this->logError('No device_code. Have you run the step 1?'); | ||||||
| 			$this->maniaControl->getChat()->sendError('No device_code. Have you run the step 1?', $player); | 			$this->maniaControl->getChat()->sendError($this->MatchManagerCore->getChatPrefix() .'No device_code. Have you run the step 1?', $player); | ||||||
| 			return; | 			return; | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
| @@ -417,19 +438,19 @@ class MatchManagerGSheet implements  CallbackListener, TimerListener, CommandLis | |||||||
| 		$asyncHttpRequest->setHeaders(array("Content-Length: 0")); | 		$asyncHttpRequest->setHeaders(array("Content-Length: 0")); | ||||||
| 		$asyncHttpRequest->setCallable(function ($json, $error) use ($player) { | 		$asyncHttpRequest->setCallable(function ($json, $error) use ($player) { | ||||||
| 			if (!$json || $error) { | 			if (!$json || $error) { | ||||||
| 				Logger::logError('Error from Google API: ' . $error); | 				$this->logError('Error from Google API: ' . $error); | ||||||
| 				$this->maniaControl->getChat()->sendError('Error from Google API: ' . $error, $player); | 				$this->maniaControl->getChat()->sendError($this->MatchManagerCore->getChatPrefix() .'Error from Google API: ' . $error, $player); | ||||||
| 				return; | 				return; | ||||||
| 			} | 			} | ||||||
| 			$data = json_decode($json); | 			$data = json_decode($json); | ||||||
| 			if (!$data) { | 			if (!$data) { | ||||||
| 				Logger::logError('Json parse error: ' . $json); | 				$this->logError('Json parse error: ' . $json); | ||||||
| 				$this->maniaControl->getChat()->sendError('Json parse error: ' . $json, $player); | 				$this->maniaControl->getChat()->sendError($this->MatchManagerCore->getChatPrefix() .'Json parse error: ' . $json, $player); | ||||||
| 				return; | 				return; | ||||||
| 			} | 			} | ||||||
| 			if (property_exists($data, "error")) { | 			if (property_exists($data, "error")) { | ||||||
| 				Logger::logError('Request error: ' . $data->error->code . " ". $data->error->message); | 				$this->logError('Request error: ' . $data->error->code . " ". $data->error->message); | ||||||
| 				$this->maniaControl->getChat()->sendErrorToAdmins('Request error: ' . $data->error->code . " ". $data->error->message); | 				$this->maniaControl->getChat()->sendErrorToAdmins($this->MatchManagerCore->getChatPrefix() .'Request error: ' . $data->error->code . " ". $data->error->message); | ||||||
| 				return; | 				return; | ||||||
| 			} | 			} | ||||||
|  |  | ||||||
| @@ -438,13 +459,13 @@ class MatchManagerGSheet implements  CallbackListener, TimerListener, CommandLis | |||||||
| 				$this->saveSecretSetting("access_token", $data->access_token); | 				$this->saveSecretSetting("access_token", $data->access_token); | ||||||
| 				$this->saveSecretSetting("expire", time() + $data->expires_in); | 				$this->saveSecretSetting("expire", time() + $data->expires_in); | ||||||
| 				$this->saveSecretSetting("refresh_token", $data->refresh_token); | 				$this->saveSecretSetting("refresh_token", $data->refresh_token); | ||||||
| 				$this->maniaControl->getChat()->sendSuccess('Maniacontrol is registered' , $player); | 				$this->maniaControl->getChat()->sendSuccess($this->MatchManagerCore->getChatPrefix() .'Maniacontrol is registered' , $player); | ||||||
| 			} elseif (isset($data->error_description)) { | 			} elseif (isset($data->error_description)) { | ||||||
| 				Logger::logError('Google refused the request: ' . $data->error_description); | 				$this->logError('Google refused the request: ' . $data->error_description); | ||||||
| 				$this->maniaControl->getChat()->sendError('Google refused the request: ' . $data->error_description , $player); | 				$this->maniaControl->getChat()->sendError($this->MatchManagerCore->getChatPrefix() .'Google refused the request: ' . $data->error_description , $player); | ||||||
| 			} else { | 			} else { | ||||||
| 				Logger::logError('Unkown error' . $data->error_description); | 				$this->logError('Unkown error' . $data->error_description); | ||||||
| 				$this->maniaControl->getChat()->sendError('Unkown error' , $player); | 				$this->maniaControl->getChat()->sendError($this->MatchManagerCore->getChatPrefix() .'Unkown error' , $player); | ||||||
| 			} | 			} | ||||||
| 		}); | 		}); | ||||||
|  |  | ||||||
| @@ -452,7 +473,7 @@ class MatchManagerGSheet implements  CallbackListener, TimerListener, CommandLis | |||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	private function refreshTokenIfNeeded() { | 	private function refreshTokenIfNeeded() { | ||||||
| 		Logger::Log('refreshTokenIfNeeded'); | 		$this->Log('refreshTokenIfNeeded'); | ||||||
| 		$this->access_token = $this->getSecretSetting("access_token"); | 		$this->access_token = $this->getSecretSetting("access_token"); | ||||||
| 		$expire = $this->getSecretSetting("expire"); | 		$expire = $this->getSecretSetting("expire"); | ||||||
| 		$refreshtoken = $this->getSecretSetting("refresh_token"); | 		$refreshtoken = $this->getSecretSetting("refresh_token"); | ||||||
| @@ -465,18 +486,18 @@ class MatchManagerGSheet implements  CallbackListener, TimerListener, CommandLis | |||||||
| 				$json = $response->getContent(); | 				$json = $response->getContent(); | ||||||
| 				$error = $response->getError(); | 				$error = $response->getError(); | ||||||
| 				if (!$json || $error) { | 				if (!$json || $error) { | ||||||
| 					Logger::logError('Error during token refresh: ' . $error); | 					$this->logError('Error during token refresh: ' . $error); | ||||||
| 					$this->maniaControl->getChat()->sendErrorToAdmins('Error during token refresh: ' . $error); | 					$this->maniaControl->getChat()->sendErrorToAdmins($this->MatchManagerCore->getChatPrefix() .'Error during token refresh: ' . $error); | ||||||
| 					return; | 					return; | ||||||
| 				} | 				} | ||||||
| 				$data = json_decode($json); | 				$data = json_decode($json); | ||||||
| 				if (!$data) { | 				if (!$data) { | ||||||
| 					Logger::logError('Json parse error: ' . $json); | 					$this->logError('Json parse error: ' . $json); | ||||||
| 					return; | 					return; | ||||||
| 				} | 				} | ||||||
| 				if (property_exists($data, "error")) { | 				if (property_exists($data, "error")) { | ||||||
| 					Logger::logError('Request error: ' . $data->error->code . " ". $data->error->message); | 					$this->logError('Request error: ' . $data->error->code . " ". $data->error->message); | ||||||
| 					$this->maniaControl->getChat()->sendErrorToAdmins('Request error: ' . $data->error->code . " ". $data->error->message); | 					$this->maniaControl->getChat()->sendErrorToAdmins($this->MatchManagerCore->getChatPrefix() .'Request error: ' . $data->error->code . " ". $data->error->message); | ||||||
| 					return; | 					return; | ||||||
| 				} | 				} | ||||||
|  |  | ||||||
| @@ -485,9 +506,9 @@ class MatchManagerGSheet implements  CallbackListener, TimerListener, CommandLis | |||||||
| 					$this->saveSecretSetting("access_token", $data->access_token); | 					$this->saveSecretSetting("access_token", $data->access_token); | ||||||
| 					$this->saveSecretSetting("expire", time() + $data->expires_in); | 					$this->saveSecretSetting("expire", time() + $data->expires_in); | ||||||
| 				} elseif (isset($data->error_description)) { | 				} elseif (isset($data->error_description)) { | ||||||
| 					$this->maniaControl->getChat()->sendErrorToAdmins('Google refused the request: ' . $data->error_description); | 					$this->maniaControl->getChat()->sendErrorToAdmins($this->MatchManagerCore->getChatPrefix() .'Google refused the request: ' . $data->error_description); | ||||||
| 				} else { | 				} else { | ||||||
| 					$this->maniaControl->getChat()->sendErrorToAdmins('Unkown error'); | 					$this->maniaControl->getChat()->sendErrorToAdmins($this->MatchManagerCore->getChatPrefix() .'Unkown error'); | ||||||
| 				} | 				} | ||||||
| 			} | 			} | ||||||
| 			return true; | 			return true; | ||||||
| @@ -530,7 +551,7 @@ class MatchManagerGSheet implements  CallbackListener, TimerListener, CommandLis | |||||||
| 	private function CheckSpeadsheetAccess(Player $player) { | 	private function CheckSpeadsheetAccess(Player $player) { | ||||||
| 		$spreadsheetid = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MATCHMANAGERGSHEET_SPREADSHEET); | 		$spreadsheetid = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MATCHMANAGERGSHEET_SPREADSHEET); | ||||||
| 		if ($spreadsheetid === "") { | 		if ($spreadsheetid === "") { | ||||||
| 			$this->maniaControl->getChat()->sendError('Empty Spreadsheet Id', $player); | 			$this->maniaControl->getChat()->sendError($this->MatchManagerCore->getChatPrefix() .'Empty Spreadsheet Id', $player); | ||||||
| 			return; | 			return; | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
| @@ -540,32 +561,32 @@ class MatchManagerGSheet implements  CallbackListener, TimerListener, CommandLis | |||||||
| 			$asyncHttpRequest->setHeaders(array("Authorization: Bearer " . $this->access_token)); | 			$asyncHttpRequest->setHeaders(array("Authorization: Bearer " . $this->access_token)); | ||||||
| 			$asyncHttpRequest->setCallable(function ($json, $error) use ($player) { | 			$asyncHttpRequest->setCallable(function ($json, $error) use ($player) { | ||||||
| 				if (!$json || $error) { | 				if (!$json || $error) { | ||||||
| 					Logger::logError('Error: ' . $error); | 					$this->logError('Error: ' . $error); | ||||||
| 					$this->maniaControl->getChat()->sendError('Error: ' . $error, $player); | 					$this->maniaControl->getChat()->sendError($this->MatchManagerCore->getChatPrefix() .'Error: ' . $error, $player); | ||||||
| 					return; | 					return; | ||||||
| 				} | 				} | ||||||
| 				$data = json_decode($json); | 				$data = json_decode($json); | ||||||
| 				if (!$data) { | 				if (!$data) { | ||||||
| 					Logger::logError('Json parse error: ' . $json); | 					$this->logError('Json parse error: ' . $json); | ||||||
| 					$this->maniaControl->getChat()->sendError('Json parse error: ' . $json, $player); | 					$this->maniaControl->getChat()->sendError($this->MatchManagerCore->getChatPrefix() .'Json parse error: ' . $json, $player); | ||||||
| 					return; | 					return; | ||||||
| 				} | 				} | ||||||
| 				if (property_exists($data, "error")) { | 				if (property_exists($data, "error")) { | ||||||
| 					Logger::logError('Request error: ' . $data->error->code . " ". $data->error->message); | 					$this->logError('Request error: ' . $data->error->code . " ". $data->error->message); | ||||||
| 					$this->maniaControl->getChat()->sendErrorToAdmins('Request error: ' . $data->error->code . " ". $data->error->message); | 					$this->maniaControl->getChat()->sendErrorToAdmins($this->MatchManagerCore->getChatPrefix() .'Request error: ' . $data->error->code . " ". $data->error->message); | ||||||
| 					return; | 					return; | ||||||
| 				} | 				} | ||||||
|  |  | ||||||
| 				if (isset($data->properties->title)) { | 				if (isset($data->properties->title)) { | ||||||
| 					$this->maniaControl->getChat()->sendSuccess('Speadsheet name: ' . $data->properties->title, $player); | 					$this->maniaControl->getChat()->sendSuccess($this->MatchManagerCore->getChatPrefix() .'Speadsheet name: ' . $data->properties->title, $player); | ||||||
| 				} else { | 				} else { | ||||||
| 					$this->maniaControl->getChat()->sendError("Can't access to the Spreadsheet: " . $data->error->message, $player); | 					$this->maniaControl->getChat()->sendError($this->MatchManagerCore->getChatPrefix() ."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($this->MatchManagerCore->getChatPrefix() ."Can't have access to Google API service", $player); | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| @@ -632,19 +653,19 @@ class MatchManagerGSheet implements  CallbackListener, TimerListener, CommandLis | |||||||
| 			$asyncHttpRequest->setContent(json_encode($data)); | 			$asyncHttpRequest->setContent(json_encode($data)); | ||||||
| 			$asyncHttpRequest->setCallable(function ($json, $error) use ($sheetname, $spreadsheetid, $currentscore, $currentteamsscore, $matchstatus, $nbmaps, $nbrounds) { | 			$asyncHttpRequest->setCallable(function ($json, $error) use ($sheetname, $spreadsheetid, $currentscore, $currentteamsscore, $matchstatus, $nbmaps, $nbrounds) { | ||||||
| 				if (!$json || $error) { | 				if (!$json || $error) { | ||||||
| 					Logger::logError('Error from Google API: ' . $error); | 					$this->logError('Error from Google API: ' . $error); | ||||||
| 					$this->maniaControl->getChat()->sendErrorToAdmins('Error from Google API: ' . $error); | 					$this->maniaControl->getChat()->sendErrorToAdmins($this->MatchManagerCore->getChatPrefix() .'Error from Google API: ' . $error); | ||||||
| 					return; | 					return; | ||||||
| 				} | 				} | ||||||
| 				$data = json_decode($json); | 				$data = json_decode($json); | ||||||
| 				if (!$data) { | 				if (!$data) { | ||||||
| 					Logger::logError('Json parse error: ' . $json); | 					$this->logError('Json parse error: ' . $json); | ||||||
| 					$this->maniaControl->getChat()->sendErrorToAdmins('Json parse error: ' . $json); | 					$this->maniaControl->getChat()->sendErrorToAdmins($this->MatchManagerCore->getChatPrefix() .'Json parse error: ' . $json); | ||||||
| 					return; | 					return; | ||||||
| 				} | 				} | ||||||
| 				if (property_exists($data, "error")) { | 				if (property_exists($data, "error")) { | ||||||
| 					Logger::logError('Request error: ' . $data->error->code . " ". $data->error->message); | 					$this->logError('Request error: ' . $data->error->code . " ". $data->error->message); | ||||||
| 					$this->maniaControl->getChat()->sendErrorToAdmins('Request error: ' . $data->error->code . " ". $data->error->message); | 					$this->maniaControl->getChat()->sendErrorToAdmins($this->MatchManagerCore->getChatPrefix() .'Request error: ' . $data->error->code . " ". $data->error->message); | ||||||
| 					return; | 					return; | ||||||
| 				} | 				} | ||||||
|  |  | ||||||
| @@ -665,19 +686,19 @@ class MatchManagerGSheet implements  CallbackListener, TimerListener, CommandLis | |||||||
| 					$asyncHttpRequest->setContent(json_encode($data)); | 					$asyncHttpRequest->setContent(json_encode($data)); | ||||||
| 					$asyncHttpRequest->setCallable(function ($json, $error) use ($sheetname, $spreadsheetid, $currentteamsscore, $nbmaps, $nbrounds) { | 					$asyncHttpRequest->setCallable(function ($json, $error) use ($sheetname, $spreadsheetid, $currentteamsscore, $nbmaps, $nbrounds) { | ||||||
| 						if (!$json || $error) { | 						if (!$json || $error) { | ||||||
| 							Logger::logError('Error from Google API: ' . $error); | 							$this->logError('Error from Google API: ' . $error); | ||||||
| 							$this->maniaControl->getChat()->sendErrorToAdmins('Error from Google API: ' . $error); | 							$this->maniaControl->getChat()->sendErrorToAdmins($this->MatchManagerCore->getChatPrefix() .'Error from Google API: ' . $error); | ||||||
| 							return; | 							return; | ||||||
| 						} | 						} | ||||||
| 						$data = json_decode($json); | 						$data = json_decode($json); | ||||||
| 						if (!$data) { | 						if (!$data) { | ||||||
| 							Logger::logError('Json parse error: ' . $json); | 							$this->logError('Json parse error: ' . $json); | ||||||
| 							$this->maniaControl->getChat()->sendErrorToAdmins('Json parse error: ' . $json); | 							$this->maniaControl->getChat()->sendErrorToAdmins($this->MatchManagerCore->getChatPrefix() .'Json parse error: ' . $json); | ||||||
| 							return; | 							return; | ||||||
| 						} | 						} | ||||||
| 						if (property_exists($data, "error")) { | 						if (property_exists($data, "error")) { | ||||||
| 							Logger::logError('Request error: ' . $data->error->code . " ". $data->error->message); | 							$this->logError('Request error: ' . $data->error->code . " ". $data->error->message); | ||||||
| 							$this->maniaControl->getChat()->sendErrorToAdmins('Request error: ' . $data->error->code . " ". $data->error->message); | 							$this->maniaControl->getChat()->sendErrorToAdmins($this->MatchManagerCore->getChatPrefix() .'Request error: ' . $data->error->code . " ". $data->error->message); | ||||||
| 							return; | 							return; | ||||||
| 						} | 						} | ||||||
|  |  | ||||||
| @@ -698,19 +719,19 @@ class MatchManagerGSheet implements  CallbackListener, TimerListener, CommandLis | |||||||
| 							$asyncHttpRequest->setContent(json_encode($data)); | 							$asyncHttpRequest->setContent(json_encode($data)); | ||||||
| 							$asyncHttpRequest->setCallable(function ($json, $error) { | 							$asyncHttpRequest->setCallable(function ($json, $error) { | ||||||
| 								if (!$json || $error) { | 								if (!$json || $error) { | ||||||
| 									Logger::logError('Error from Google API: ' . $error); | 									$this->logError('Error from Google API: ' . $error); | ||||||
| 									$this->maniaControl->getChat()->sendErrorToAdmins('Error from Google API: ' . $error); | 									$this->maniaControl->getChat()->sendErrorToAdmins($this->MatchManagerCore->getChatPrefix() .'Error from Google API: ' . $error); | ||||||
| 									return; | 									return; | ||||||
| 								} | 								} | ||||||
| 								$data = json_decode($json); | 								$data = json_decode($json); | ||||||
| 								if (!$data) { | 								if (!$data) { | ||||||
| 									Logger::logError('Json parse error: ' . $json); | 									$this->logError('Json parse error: ' . $json); | ||||||
| 									$this->maniaControl->getChat()->sendErrorToAdmins('Json parse error: ' . $json); | 									$this->maniaControl->getChat()->sendErrorToAdmins($this->MatchManagerCore->getChatPrefix() .'Json parse error: ' . $json); | ||||||
| 									return; | 									return; | ||||||
| 								} | 								} | ||||||
| 								if (property_exists($data, "error")) { | 								if (property_exists($data, "error")) { | ||||||
| 									Logger::logError('Request error: ' . $data->error->code . " ". $data->error->message); | 									$this->logError('Request error: ' . $data->error->code . " ". $data->error->message); | ||||||
| 									$this->maniaControl->getChat()->sendErrorToAdmins('Request error: ' . $data->error->code . " ". $data->error->message); | 									$this->maniaControl->getChat()->sendErrorToAdmins($this->MatchManagerCore->getChatPrefix() .'Request error: ' . $data->error->code . " ". $data->error->message); | ||||||
| 									return; | 									return; | ||||||
| 								} | 								} | ||||||
| 							}); | 							}); | ||||||
| @@ -722,17 +743,17 @@ class MatchManagerGSheet implements  CallbackListener, TimerListener, CommandLis | |||||||
| 			});	 | 			});	 | ||||||
| 			$asyncHttpRequest->postData(1000); | 			$asyncHttpRequest->postData(1000); | ||||||
| 		} else { | 		} else { | ||||||
| 			$this->maniaControl->getChat()->sendErrorToAdmins('Impossible to update the Google Sheet'); | 			$this->maniaControl->getChat()->sendErrorToAdmins($this->MatchManagerCore->getChatPrefix() .'Impossible to update the Google Sheet'); | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	function onCallbackEndRound(String $matchid, Array $currentscore, Array $currentteamsscore) { | 	function onCallbackEndRound(String $matchid, Array $currentscore, Array $currentteamsscore) { | ||||||
| 		Logger::Log('onCallbackEndRound'); | 		$this->Log('onCallbackEndRound'); | ||||||
| 		$this->matchstatus = "running"; | 		$this->matchstatus = "running"; | ||||||
| 		$this->UpdateGSheetData($matchid, $currentscore, $currentteamsscore); | 		$this->UpdateGSheetData($matchid, $currentscore, $currentteamsscore); | ||||||
| 	} | 	} | ||||||
| 	function onCallbackEndMatch(String $matchid, Array $currentscore, Array $currentteamsscore) { | 	function onCallbackEndMatch(String $matchid, Array $currentscore, Array $currentteamsscore) { | ||||||
| 		Logger::Log('onCallbackEndMatch'); | 		$this->Log('onCallbackEndMatch'); | ||||||
| 		$this->matchstatus = "ended"; | 		$this->matchstatus = "ended"; | ||||||
|  |  | ||||||
| 		$this->maniaControl->getTimerManager()->registerOneTimeListening($this, function () use ($matchid, $currentscore, $currentteamsscore) { | 		$this->maniaControl->getTimerManager()->registerOneTimeListening($this, function () use ($matchid, $currentscore, $currentteamsscore) { | ||||||
| @@ -740,7 +761,7 @@ class MatchManagerGSheet implements  CallbackListener, TimerListener, CommandLis | |||||||
| 		}, 1000); // Wait a sec before sending last data to avoid collision | 		}, 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'); | 		$this->Log('onCallbackStopMatch'); | ||||||
| 		$this->matchstatus = "stopped"; | 		$this->matchstatus = "stopped"; | ||||||
| 		$this->UpdateGSheetData($matchid, $currentscore, $currentteamsscore); | 		$this->UpdateGSheetData($matchid, $currentscore, $currentteamsscore); | ||||||
| 	} | 	} | ||||||
| @@ -759,19 +780,19 @@ class MatchManagerGSheet implements  CallbackListener, TimerListener, CommandLis | |||||||
| 			$asyncHttpRequest->setHeaders(array("Authorization: Bearer " . $this->access_token)); | 			$asyncHttpRequest->setHeaders(array("Authorization: Bearer " . $this->access_token)); | ||||||
| 			$asyncHttpRequest->setCallable(function ($json, $error) use ($sheetname) { | 			$asyncHttpRequest->setCallable(function ($json, $error) use ($sheetname) { | ||||||
| 				if (!$json || $error) { | 				if (!$json || $error) { | ||||||
| 					Logger::logError('Error from Google API: ' . $error); | 					$this->logError('Error from Google API: ' . $error); | ||||||
| 					$this->maniaControl->getChat()->sendErrorToAdmins('Error from Google API: ' . $error); | 					$this->maniaControl->getChat()->sendErrorToAdmins($this->MatchManagerCore->getChatPrefix() .'Error from Google API: ' . $error); | ||||||
| 					return; | 					return; | ||||||
| 				} | 				} | ||||||
| 				$data = json_decode($json); | 				$data = json_decode($json); | ||||||
| 				if (!$data) { | 				if (!$data) { | ||||||
| 					Logger::logError('Json parse error: ' . $json); | 					$this->logError('Json parse error: ' . $json); | ||||||
| 					$this->maniaControl->getChat()->sendErrorToAdmins('Json parse error: ' . $json); | 					$this->maniaControl->getChat()->sendErrorToAdmins($this->MatchManagerCore->getChatPrefix() .'Json parse error: ' . $json); | ||||||
| 					return; | 					return; | ||||||
| 				} | 				} | ||||||
| 				if (property_exists($data, "error")) { | 				if (property_exists($data, "error")) { | ||||||
| 					Logger::logError('Request error: ' . $data->error->code . " ". $data->error->message); | 					$this->logError('Request error: ' . $data->error->code . " ". $data->error->message); | ||||||
| 					$this->maniaControl->getChat()->sendErrorToAdmins('Request error: ' . $data->error->code . " ". $data->error->message); | 					$this->maniaControl->getChat()->sendErrorToAdmins($this->MatchManagerCore->getChatPrefix() .'Request error: ' . $data->error->code . " ". $data->error->message); | ||||||
| 					return; | 					return; | ||||||
| 				} | 				} | ||||||
|  |  | ||||||
| @@ -812,7 +833,7 @@ class MatchManagerGSheet implements  CallbackListener, TimerListener, CommandLis | |||||||
| 			$i = 0; | 			$i = 0; | ||||||
|  |  | ||||||
| 			if (!$sheetexists) { | 			if (!$sheetexists) { | ||||||
| 				Logger::Log("Creating new Sheet: " . $sheetname); | 				$this->Log("Creating new Sheet: " . $sheetname); | ||||||
| 				$sheetid = rand(1000,2147483646); | 				$sheetid = rand(1000,2147483646); | ||||||
| 				while (in_array($sheetid, $sheetsid)) { | 				while (in_array($sheetid, $sheetsid)) { | ||||||
| 					$sheetid = rand(1000,2147483646); | 					$sheetid = rand(1000,2147483646); | ||||||
| @@ -907,19 +928,19 @@ class MatchManagerGSheet implements  CallbackListener, TimerListener, CommandLis | |||||||
| 			$asyncHttpRequest->setContent(json_encode($data)); | 			$asyncHttpRequest->setContent(json_encode($data)); | ||||||
| 			$asyncHttpRequest->setCallable(function ($json, $error) use ($sheetname, $spreadsheetid) { | 			$asyncHttpRequest->setCallable(function ($json, $error) use ($sheetname, $spreadsheetid) { | ||||||
| 				if (!$json || $error) { | 				if (!$json || $error) { | ||||||
| 					Logger::logError('Error from Google API: ' . $error); | 					$this->logError('Error from Google API: ' . $error); | ||||||
| 					$this->maniaControl->getChat()->sendErrorToAdmins('Error from Google API: ' . $error); | 					$this->maniaControl->getChat()->sendErrorToAdmins($this->MatchManagerCore->getChatPrefix() .'Error from Google API: ' . $error); | ||||||
| 					return; | 					return; | ||||||
| 				} | 				} | ||||||
| 				$data = json_decode($json); | 				$data = json_decode($json); | ||||||
| 				if (!$data) { | 				if (!$data) { | ||||||
| 					Logger::logError('Json parse error: ' . $json); | 					$this->logError('Json parse error: ' . $json); | ||||||
| 					$this->maniaControl->getChat()->sendErrorToAdmins('Json parse error: ' . $json); | 					$this->maniaControl->getChat()->sendErrorToAdmins($this->MatchManagerCore->getChatPrefix() .'Json parse error: ' . $json); | ||||||
| 					return; | 					return; | ||||||
| 				} | 				} | ||||||
| 				if (property_exists($data, "error")) { | 				if (property_exists($data, "error")) { | ||||||
| 					Logger::logError('Request error: ' . $data->error->code . " ". $data->error->message); | 					$this->logError('Request error: ' . $data->error->code . " ". $data->error->message); | ||||||
| 					$this->maniaControl->getChat()->sendErrorToAdmins('Request error: ' . $data->error->code . " ". $data->error->message); | 					$this->maniaControl->getChat()->sendErrorToAdmins($this->MatchManagerCore->getChatPrefix() .'Request error: ' . $data->error->code . " ". $data->error->message); | ||||||
| 					return; | 					return; | ||||||
| 				} | 				} | ||||||
|  |  | ||||||
| @@ -928,19 +949,19 @@ class MatchManagerGSheet implements  CallbackListener, TimerListener, CommandLis | |||||||
| 				$asyncHttpRequest->setHeaders(array("Authorization: Bearer " . $this->access_token)); | 				$asyncHttpRequest->setHeaders(array("Authorization: Bearer " . $this->access_token)); | ||||||
| 				$asyncHttpRequest->setCallable(function ($json, $error) use ($sheetname, $spreadsheetid) { | 				$asyncHttpRequest->setCallable(function ($json, $error) use ($sheetname, $spreadsheetid) { | ||||||
| 					if (!$json || $error) { | 					if (!$json || $error) { | ||||||
| 						Logger::logError('Error from Google API: ' . $error); | 						$this->logError('Error from Google API: ' . $error); | ||||||
| 						$this->maniaControl->getChat()->sendErrorToAdmins('Error from Google API: ' . $error); | 						$this->maniaControl->getChat()->sendErrorToAdmins($this->MatchManagerCore->getChatPrefix() .'Error from Google API: ' . $error); | ||||||
| 						return; | 						return; | ||||||
| 					} | 					} | ||||||
| 					$data = json_decode($json); | 					$data = json_decode($json); | ||||||
| 					if (!$data) { | 					if (!$data) { | ||||||
| 						Logger::logError('Json parse error: ' . $json); | 						$this->logError('Json parse error: ' . $json); | ||||||
| 						$this->maniaControl->getChat()->sendErrorToAdmins('Json parse error: ' . $json); | 						$this->maniaControl->getChat()->sendErrorToAdmins($this->MatchManagerCore->getChatPrefix() .'Json parse error: ' . $json); | ||||||
| 						return; | 						return; | ||||||
| 					} | 					} | ||||||
| 					if (property_exists($data, "error")) { | 					if (property_exists($data, "error")) { | ||||||
| 						Logger::logError('Request error: ' . $data->error->code . " ". $data->error->message); | 						$this->logError('Request error: ' . $data->error->code . " ". $data->error->message); | ||||||
| 						$this->maniaControl->getChat()->sendErrorToAdmins('Request error: ' . $data->error->code . " ". $data->error->message); | 						$this->maniaControl->getChat()->sendErrorToAdmins($this->MatchManagerCore->getChatPrefix() .'Request error: ' . $data->error->code . " ". $data->error->message); | ||||||
| 						return; | 						return; | ||||||
| 					} | 					} | ||||||
|  |  | ||||||
| @@ -966,19 +987,19 @@ class MatchManagerGSheet implements  CallbackListener, TimerListener, CommandLis | |||||||
| 					$asyncHttpRequest->setContent(json_encode($data)); | 					$asyncHttpRequest->setContent(json_encode($data)); | ||||||
| 					$asyncHttpRequest->setCallable(function ($json, $error) { | 					$asyncHttpRequest->setCallable(function ($json, $error) { | ||||||
| 						if (!$json || $error) { | 						if (!$json || $error) { | ||||||
| 							Logger::logError('Error from Google API: ' . $error); | 							$this->logError('Error from Google API: ' . $error); | ||||||
| 							$this->maniaControl->getChat()->sendErrorToAdmins('Error from Google API: ' . $error); | 							$this->maniaControl->getChat()->sendErrorToAdmins($this->MatchManagerCore->getChatPrefix() .'Error from Google API: ' . $error); | ||||||
| 							return; | 							return; | ||||||
| 						} | 						} | ||||||
| 						$data = json_decode($json); | 						$data = json_decode($json); | ||||||
| 						if (!$data) { | 						if (!$data) { | ||||||
| 							Logger::logError('Json parse error: ' . $json); | 							$this->logError('Json parse error: ' . $json); | ||||||
| 							$this->maniaControl->getChat()->sendErrorToAdmins('Json parse error: ' . $json); | 							$this->maniaControl->getChat()->sendErrorToAdmins($this->MatchManagerCore->getChatPrefix() .'Json parse error: ' . $json); | ||||||
| 							return; | 							return; | ||||||
| 						} | 						} | ||||||
| 						if (property_exists($data, "error")) { | 						if (property_exists($data, "error")) { | ||||||
| 							Logger::logError('Request error: ' . $data->error->code . " ". $data->error->message); | 							$this->logError('Request error: ' . $data->error->code . " ". $data->error->message); | ||||||
| 							$this->maniaControl->getChat()->sendErrorToAdmins('Request error: ' . $data->error->code . " ". $data->error->message); | 							$this->maniaControl->getChat()->sendErrorToAdmins('$this->MatchManagerCore->getChatPrefix() .Request error: ' . $data->error->code . " ". $data->error->message); | ||||||
| 							return; | 							return; | ||||||
| 						} | 						} | ||||||
| 					}); | 					}); | ||||||
|   | |||||||
| @@ -27,8 +27,8 @@ use ManiaControl\Commands\CommandListener; | |||||||
| use ManiaControl\Plugins\PluginMenu; | use ManiaControl\Plugins\PluginMenu; | ||||||
|  |  | ||||||
| if (!class_exists('MatchManagerSuite\MatchManagerCore')) { | if (!class_exists('MatchManagerSuite\MatchManagerCore')) { | ||||||
| 	$this->maniaControl->getChat()->sendErrorToAdmins('MatchManager Core is required to use one of MatchManager plugin. Install it and restart Maniacontrol'); | 	$this->maniaControl->getChat()->sendErrorToAdmins('MatchManager Core is required to use MatchManagerMultipleConfigManager plugin. Install it and restart Maniacontrol'); | ||||||
| 	Logger::logError('MatchManager Core is required to use one of MatchManager plugin. Install it and restart Maniacontrol'); | 	Logger::logError('MatchManager Core is required to use MatchManagerMultipleConfigManager plugin. Install it and restart Maniacontrol'); | ||||||
| 	return false; | 	return false; | ||||||
| } | } | ||||||
| use MatchManagerSuite\MatchManagerCore; | use MatchManagerSuite\MatchManagerCore; | ||||||
| @@ -48,6 +48,9 @@ class MatchManagerMultipleConfigManager implements ManialinkPageAnswerListener, | |||||||
| 	const PLUGIN_NAME										= 'MatchManager Multiple Config Manager'; | 	const PLUGIN_NAME										= 'MatchManager Multiple Config Manager'; | ||||||
| 	const PLUGIN_AUTHOR										= 'Beu'; | 	const PLUGIN_AUTHOR										= 'Beu'; | ||||||
|  |  | ||||||
|  | 	const LOG_PREFIX										= '[MatchManagerMultipleConfigManager] '; | ||||||
|  |  | ||||||
|  |  | ||||||
| 	// MatchManagerWidget Properties | 	// MatchManagerWidget Properties | ||||||
| 	const MATCHMANAGERCORE_PLUGIN							= 'MatchManagerSuite\MatchManagerCore'; | 	const MATCHMANAGERCORE_PLUGIN							= 'MatchManagerSuite\MatchManagerCore'; | ||||||
| 	const MATCHMANAGERADMINUI_PLUGIN						= 'MatchManagerSuite\MatchManagerAdminUI'; | 	const MATCHMANAGERADMINUI_PLUGIN						= 'MatchManagerSuite\MatchManagerAdminUI'; | ||||||
| @@ -71,6 +74,7 @@ class MatchManagerMultipleConfigManager implements ManialinkPageAnswerListener, | |||||||
| 	 */ | 	 */ | ||||||
| 	/** @var ManiaControl $maniaControl */ | 	/** @var ManiaControl $maniaControl */ | ||||||
| 	private $maniaControl 			= null; | 	private $maniaControl 			= null; | ||||||
|  | 	/** @var MatchManagerCore $MatchManagerCore */ | ||||||
| 	private $MatchManagerCore		= null; | 	private $MatchManagerCore		= null; | ||||||
|  |  | ||||||
| 	/** | 	/** | ||||||
| @@ -152,6 +156,24 @@ class MatchManagerMultipleConfigManager implements ManialinkPageAnswerListener, | |||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
|  | 	/** | ||||||
|  | 	 * Custom log function to add prefix | ||||||
|  | 	 *  | ||||||
|  | 	 * @param mixed $message | ||||||
|  | 	 */ | ||||||
|  | 	private function log(mixed $message) { | ||||||
|  | 		Logger::log(self::LOG_PREFIX . $message); | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	/** | ||||||
|  | 	 * Custom logError function to add prefix | ||||||
|  | 	 *  | ||||||
|  | 	 * @param mixed $message | ||||||
|  | 	 */ | ||||||
|  | 	private function logError(mixed $message) { | ||||||
|  | 		Logger::logError(self::LOG_PREFIX . $message); | ||||||
|  | 	} | ||||||
|  |  | ||||||
| 	/** | 	/** | ||||||
| 	 * handle Plugin Loaded | 	 * handle Plugin Loaded | ||||||
| 	 *  | 	 *  | ||||||
| @@ -182,7 +204,8 @@ class MatchManagerMultipleConfigManager implements ManialinkPageAnswerListener, | |||||||
| 	public function handlePluginUnloaded(string $pluginClass, Plugin $plugin) { | 	public function handlePluginUnloaded(string $pluginClass, Plugin $plugin) { | ||||||
| 		if ($pluginClass == self::MATCHMANAGERCORE_PLUGIN) { | 		if ($pluginClass == self::MATCHMANAGERCORE_PLUGIN) { | ||||||
| 			$this->maniaControl->getChat()->sendErrorToAdmins(self::PLUGIN_NAME . " disabled because MatchManager Core is now disabled"); | 			$this->maniaControl->getChat()->sendErrorToAdmins(self::PLUGIN_NAME . " disabled because MatchManager Core is now disabled"); | ||||||
| 			$this->maniaControl->getPluginManager()->deactivatePlugin((get_class())); | 			$this->log(self::PLUGIN_NAME . " disabled because MatchManager Core is now disabled"); | ||||||
|  | 			$this->maniaControl->getPluginManager()->deactivatePlugin((get_class($this))); | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| @@ -248,7 +271,7 @@ class MatchManagerMultipleConfigManager implements ManialinkPageAnswerListener, | |||||||
| 				break; | 				break; | ||||||
| 			case self::ML_ACTION_REMOVE_CONFIG: | 			case self::ML_ACTION_REMOVE_CONFIG: | ||||||
| 				$id = intval($actionArray[2]); | 				$id = intval($actionArray[2]); | ||||||
| 				Logger::log("[MatchManagerMultipleConfigManager] Removing config: " . $id); | 				$this->log("Removing config: " . $id); | ||||||
| 				$mysqli = $this->maniaControl->getDatabase()->getMysqli(); | 				$mysqli = $this->maniaControl->getDatabase()->getMysqli(); | ||||||
|  |  | ||||||
| 				$query = $mysqli->prepare('DELETE FROM  `'. self::DB_MATCHCONFIG .'` WHERE id = ?;'); | 				$query = $mysqli->prepare('DELETE FROM  `'. self::DB_MATCHCONFIG .'` WHERE id = ?;'); | ||||||
| @@ -288,8 +311,8 @@ class MatchManagerMultipleConfigManager implements ManialinkPageAnswerListener, | |||||||
| 	 */ | 	 */ | ||||||
| 	public function loadConfig(int $id) { | 	public function loadConfig(int $id) { | ||||||
| 		if ($this->MatchManagerCore->getMatchStatus()) { | 		if ($this->MatchManagerCore->getMatchStatus()) { | ||||||
| 			Logger::logError("Impossible to load config during a match"); | 			$this->logError("Impossible to load config during a match"); | ||||||
| 			$this->maniaControl->getChat()->sendErrorToAdmins('Impossible to load config during a match'); | 			$this->maniaControl->getChat()->sendErrorToAdmins($this->MatchManagerCore->getChatPrefix() .'Impossible to load config during a match'); | ||||||
| 			return; | 			return; | ||||||
| 		} | 		} | ||||||
| 		$mysqli = $this->maniaControl->getDatabase()->getMysqli(); | 		$mysqli = $this->maniaControl->getDatabase()->getMysqli(); | ||||||
| @@ -310,7 +333,7 @@ class MatchManagerMultipleConfigManager implements ManialinkPageAnswerListener, | |||||||
| 		if ($result[0] && $result[0]["config"]) { | 		if ($result[0] && $result[0]["config"]) { | ||||||
| 			$allconfigs = json_decode($result[0]["config"],true); | 			$allconfigs = json_decode($result[0]["config"],true); | ||||||
| 			if ($allconfigs != null) { | 			if ($allconfigs != null) { | ||||||
| 				Logger::log("[MatchManagerMultipleConfigManager] Loading config: " . $id); | 				$this->log("Loading config: " . $id); | ||||||
| 				$someconfignotloaded = false; | 				$someconfignotloaded = false; | ||||||
| 				foreach ($allconfigs as $plugin => $configs) { | 				foreach ($allconfigs as $plugin => $configs) { | ||||||
| 					$pluginclass = $this->maniaControl->getPluginManager()->getPlugin($plugin); | 					$pluginclass = $this->maniaControl->getPluginManager()->getPlugin($plugin); | ||||||
| @@ -321,22 +344,22 @@ class MatchManagerMultipleConfigManager implements ManialinkPageAnswerListener, | |||||||
| 							$setting = $this->maniaControl->getSettingManager()->getSettingObject($pluginclass, $name); | 							$setting = $this->maniaControl->getSettingManager()->getSettingObject($pluginclass, $name); | ||||||
| 							if ($setting != null) { | 							if ($setting != null) { | ||||||
| 								if ($setting->value != $value) { | 								if ($setting->value != $value) { | ||||||
| 									Logger::log("Saving new setting " . $name); | 									$this->log("Saving new setting " . $name); | ||||||
| 									$setting->value = $value; | 									$setting->value = $value; | ||||||
| 									$this->maniaControl->getSettingManager()->saveSetting($setting); | 									$this->maniaControl->getSettingManager()->saveSetting($setting); | ||||||
| 								} | 								} | ||||||
| 							} else { | 							} else { | ||||||
| 								$someconfignotloaded = true; | 								$someconfignotloaded = true; | ||||||
| 								Logger::log("Unable to load setting: " . $name); | 								$this->log("Unable to load setting: " . $name); | ||||||
| 							} | 							} | ||||||
| 						} | 						} | ||||||
| 					} | 					} | ||||||
| 				} | 				} | ||||||
| 				if ($someconfignotloaded) { | 				if ($someconfignotloaded) { | ||||||
| 					$this->maniaControl->getChat()->sendErrorToAdmins('One or more settings could not be imported'); | 					$this->maniaControl->getChat()->sendErrorToAdmins($this->MatchManagerCore->getChatPrefix() .'One or more settings could not be imported'); | ||||||
| 				} | 				} | ||||||
| 				$this->maniaControl->getSettingManager()->clearStorage(); | 				$this->maniaControl->getSettingManager()->clearStorage(); | ||||||
| 				$this->maniaControl->getChat()->sendSuccessToAdmins('MatchManager Config "' . $result[0]["name"] . '" loaded'); | 				$this->maniaControl->getChat()->sendSuccessToAdmins($this->MatchManagerCore->getChatPrefix() .'MatchManager Config "' . $result[0]["name"] . '" loaded'); | ||||||
| 			} | 			} | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
| @@ -350,7 +373,7 @@ class MatchManagerMultipleConfigManager implements ManialinkPageAnswerListener, | |||||||
| 	 * @return void | 	 * @return void | ||||||
| 	 */ | 	 */ | ||||||
| 	public function saveCurrentConfig(array $fields) { | 	public function saveCurrentConfig(array $fields) { | ||||||
| 		Logger::log("[MatchManagerMultipleConfigManager] Saving current config"); | 		$this->log("Saving current config"); | ||||||
| 		$result = array(); | 		$result = array(); | ||||||
| 		$configname = ""; | 		$configname = ""; | ||||||
| 		$gamemodebase = ""; | 		$gamemodebase = ""; | ||||||
|   | |||||||
| @@ -21,8 +21,8 @@ use ManiaControl\Commands\CommandListener; | |||||||
|  |  | ||||||
|  |  | ||||||
| if (!class_exists('MatchManagerSuite\MatchManagerCore')) { | if (!class_exists('MatchManagerSuite\MatchManagerCore')) { | ||||||
| 	$this->maniaControl->getChat()->sendErrorToAdmins('MatchManager Core is required to use one of MatchManager plugin. Install it and restart Maniacontrol'); | 	$this->maniaControl->getChat()->sendErrorToAdmins('MatchManager Core is required to use MatchManagerPlayersPause plugin. Install it and restart Maniacontrol'); | ||||||
| 	Logger::logError('MatchManager Core is required to use one of MatchManager plugin. Install it and restart Maniacontrol'); | 	Logger::logError('MatchManager Core is required to use MatchManagerPlayersPause plugin. Install it and restart Maniacontrol'); | ||||||
| 	return false; | 	return false; | ||||||
| } | } | ||||||
|  |  | ||||||
| @@ -42,6 +42,8 @@ class MatchManagerPlayersPause implements ManialinkPageAnswerListener, CommandLi | |||||||
| 	const PLUGIN_NAME										= 'MatchManager Players Pause'; | 	const PLUGIN_NAME										= 'MatchManager Players Pause'; | ||||||
| 	const PLUGIN_AUTHOR										= 'Beu'; | 	const PLUGIN_AUTHOR										= 'Beu'; | ||||||
|  |  | ||||||
|  | 	const LOG_PREFIX										= '[MatchManagerPlayersPause] '; | ||||||
|  |  | ||||||
| 	// MatchManagerWidget Properties | 	// MatchManagerWidget Properties | ||||||
| 	const MATCHMANAGERCORE_PLUGIN							= 'MatchManagerSuite\MatchManagerCore'; | 	const MATCHMANAGERCORE_PLUGIN							= 'MatchManagerSuite\MatchManagerCore'; | ||||||
|  |  | ||||||
| @@ -58,6 +60,7 @@ class MatchManagerPlayersPause implements ManialinkPageAnswerListener, CommandLi | |||||||
| 	 */ | 	 */ | ||||||
| 	/** @var ManiaControl $maniaControl */ | 	/** @var ManiaControl $maniaControl */ | ||||||
| 	private $maniaControl 			= null; | 	private $maniaControl 			= null; | ||||||
|  | 	/** @var MatchManagerCore $MatchManagerCore */ | ||||||
| 	private $MatchManagerCore		= null; | 	private $MatchManagerCore		= null; | ||||||
|  |  | ||||||
| 	private $playerspausestate		= array(); | 	private $playerspausestate		= array(); | ||||||
| @@ -160,6 +163,24 @@ class MatchManagerPlayersPause implements ManialinkPageAnswerListener, CommandLi | |||||||
| 		$this->closePauseWidget(); | 		$this->closePauseWidget(); | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
|  | 	/** | ||||||
|  | 	 * Custom log function to add prefix | ||||||
|  | 	 *  | ||||||
|  | 	 * @param mixed $message | ||||||
|  | 	 */ | ||||||
|  | 	private function log(mixed $message) { | ||||||
|  | 		Logger::log(self::LOG_PREFIX . $message); | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	/** | ||||||
|  | 	 * Custom logError function to add prefix | ||||||
|  | 	 *  | ||||||
|  | 	 * @param mixed $message | ||||||
|  | 	 */ | ||||||
|  | 	private function logError(mixed $message) { | ||||||
|  | 		Logger::logError(self::LOG_PREFIX . $message); | ||||||
|  | 	} | ||||||
|  |  | ||||||
| 	/** | 	/** | ||||||
| 	 * handlePluginUnloaded | 	 * handlePluginUnloaded | ||||||
| 	 * | 	 * | ||||||
| @@ -170,7 +191,8 @@ class MatchManagerPlayersPause implements ManialinkPageAnswerListener, CommandLi | |||||||
| 	public function handlePluginUnloaded(string $pluginClass, Plugin $plugin) { | 	public function handlePluginUnloaded(string $pluginClass, Plugin $plugin) { | ||||||
| 		if ($pluginClass == self::MATCHMANAGERCORE_PLUGIN) { | 		if ($pluginClass == self::MATCHMANAGERCORE_PLUGIN) { | ||||||
| 			$this->maniaControl->getChat()->sendErrorToAdmins(self::PLUGIN_NAME . " disabled because MatchManager Core is now disabled"); | 			$this->maniaControl->getChat()->sendErrorToAdmins(self::PLUGIN_NAME . " disabled because MatchManager Core is now disabled"); | ||||||
| 			$this->maniaControl->getPluginManager()->deactivatePlugin((get_class())); | 			$this->log(self::PLUGIN_NAME . " disabled because MatchManager Core is now disabled"); | ||||||
|  | 			$this->maniaControl->getPluginManager()->deactivatePlugin((get_class($this))); | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| @@ -211,7 +233,7 @@ class MatchManagerPlayersPause implements ManialinkPageAnswerListener, CommandLi | |||||||
| 				if ($nbpause >= $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MATCH_PAUSE_NBPLAYERS)) { | 				if ($nbpause >= $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MATCH_PAUSE_NBPLAYERS)) { | ||||||
| 					$this->playerspausestate = array(); | 					$this->playerspausestate = array(); | ||||||
| 					$this->closePauseWidget(); | 					$this->closePauseWidget(); | ||||||
| 					Logger::log('Pause requested by players'); | 					$this->log('Pause requested by players'); | ||||||
| 					if (!$this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MATCH_PAUSE_WAIT_END_ROUND)) { | 					if (!$this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MATCH_PAUSE_WAIT_END_ROUND)) { | ||||||
| 						if ($this->maniaControl->getSettingManager()->getSettingValue($this->maniaControl, MatchManagerCore::SETTING_MATCH_PAUSE_DURATION) <= 0) { | 						if ($this->maniaControl->getSettingManager()->getSettingValue($this->maniaControl, MatchManagerCore::SETTING_MATCH_PAUSE_DURATION) <= 0) { | ||||||
| 							$this->maniaControl->getChat()->sendInformation($this->MatchManagerCore->getChatPrefix() . 'Ask the admins to resume the match'); | 							$this->maniaControl->getChat()->sendInformation($this->MatchManagerCore->getChatPrefix() . 'Ask the admins to resume the match'); | ||||||
|   | |||||||
| @@ -20,8 +20,8 @@ use ManiaControl\Commands\CommandListener; | |||||||
| use Maniaplanet\DedicatedServer\InvalidArgumentException; | use Maniaplanet\DedicatedServer\InvalidArgumentException; | ||||||
|  |  | ||||||
| if (!class_exists('MatchManagerSuite\MatchManagerCore')) { | if (!class_exists('MatchManagerSuite\MatchManagerCore')) { | ||||||
| 	$this->maniaControl->getChat()->sendErrorToAdmins('MatchManager Core is required to use one of MatchManager plugin. Install it and restart Maniacontrol'); | 	$this->maniaControl->getChat()->sendErrorToAdmins('MatchManager Core is required to use MatchManagerReadyButton plugin. Install it and restart Maniacontrol'); | ||||||
| 	Logger::logError('MatchManager Core is required to use one of MatchManager plugin. Install it and restart Maniacontrol'); | 	Logger::logError('MatchManager Core is required to use MatchManagerReadyButton plugin. Install it and restart Maniacontrol'); | ||||||
| 	return false; | 	return false; | ||||||
| } | } | ||||||
|  |  | ||||||
| @@ -41,6 +41,8 @@ class MatchManagerReadyButton implements ManialinkPageAnswerListener, CommandLis | |||||||
| 	const PLUGIN_NAME										= 'MatchManager Ready Button'; | 	const PLUGIN_NAME										= 'MatchManager Ready Button'; | ||||||
| 	const PLUGIN_AUTHOR										= 'Beu'; | 	const PLUGIN_AUTHOR										= 'Beu'; | ||||||
|  |  | ||||||
|  | 	const LOG_PREFIX										= '[MatchManagerReadyButton] '; | ||||||
|  |  | ||||||
| 	// MatchManagerWidget Properties | 	// MatchManagerWidget Properties | ||||||
| 	const MATCHMANAGERCORE_PLUGIN							= 'MatchManagerSuite\MatchManagerCore'; | 	const MATCHMANAGERCORE_PLUGIN							= 'MatchManagerSuite\MatchManagerCore'; | ||||||
|  |  | ||||||
| @@ -57,6 +59,7 @@ class MatchManagerReadyButton implements ManialinkPageAnswerListener, CommandLis | |||||||
| 	 */ | 	 */ | ||||||
| 	/** @var ManiaControl $maniaControl */ | 	/** @var ManiaControl $maniaControl */ | ||||||
| 	private $maniaControl 			= null; | 	private $maniaControl 			= null; | ||||||
|  | 	/** @var MatchManagerCore $MatchManagerCore */ | ||||||
| 	private $MatchManagerCore		= null; | 	private $MatchManagerCore		= null; | ||||||
|  |  | ||||||
| 	private $playersreadystate		= array(); | 	private $playersreadystate		= array(); | ||||||
| @@ -154,6 +157,24 @@ class MatchManagerReadyButton implements ManialinkPageAnswerListener, CommandLis | |||||||
| 		$this->closeReadyWidget(); | 		$this->closeReadyWidget(); | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
|  | 	/** | ||||||
|  | 	 * Custom log function to add prefix | ||||||
|  | 	 *  | ||||||
|  | 	 * @param mixed $message | ||||||
|  | 	 */ | ||||||
|  | 	private function log(mixed $message) { | ||||||
|  | 		Logger::log(self::LOG_PREFIX . $message); | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	/** | ||||||
|  | 	 * Custom logError function to add prefix | ||||||
|  | 	 *  | ||||||
|  | 	 * @param mixed $message | ||||||
|  | 	 */ | ||||||
|  | 	private function logError(mixed $message) { | ||||||
|  | 		Logger::logError(self::LOG_PREFIX . $message); | ||||||
|  | 	} | ||||||
|  |  | ||||||
| 	/** | 	/** | ||||||
| 	 * handlePluginUnloaded | 	 * handlePluginUnloaded | ||||||
| 	 * | 	 * | ||||||
| @@ -164,7 +185,7 @@ class MatchManagerReadyButton implements ManialinkPageAnswerListener, CommandLis | |||||||
| 	public function handlePluginUnloaded(string $pluginClass, Plugin $plugin) { | 	public function handlePluginUnloaded(string $pluginClass, Plugin $plugin) { | ||||||
| 		if ($pluginClass == self::MATCHMANAGERCORE_PLUGIN) { | 		if ($pluginClass == self::MATCHMANAGERCORE_PLUGIN) { | ||||||
| 			$this->maniaControl->getChat()->sendErrorToAdmins(self::PLUGIN_NAME . " disabled because MatchManager Core is now disabled"); | 			$this->maniaControl->getChat()->sendErrorToAdmins(self::PLUGIN_NAME . " disabled because MatchManager Core is now disabled"); | ||||||
| 			$this->maniaControl->getPluginManager()->deactivatePlugin((get_class())); | 			$this->maniaControl->getPluginManager()->deactivatePlugin((get_class($this))); | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| @@ -205,7 +226,7 @@ class MatchManagerReadyButton implements ManialinkPageAnswerListener, CommandLis | |||||||
| 				if ($nbready >= $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MATCH_READY_NBPLAYERS)) { | 				if ($nbready >= $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MATCH_READY_NBPLAYERS)) { | ||||||
| 					$this->playersreadystate = array(); | 					$this->playersreadystate = array(); | ||||||
| 					$this->closeReadyWidget(); | 					$this->closeReadyWidget(); | ||||||
| 					Logger::log('Start Match via Ready Button'); | 					$this->log('Start Match via Ready Button'); | ||||||
| 					$this->MatchManagerCore->MatchStart(); | 					$this->MatchManagerCore->MatchStart(); | ||||||
| 					return; | 					return; | ||||||
| 				} | 				} | ||||||
|   | |||||||
| @@ -19,8 +19,8 @@ use ManiaControl\Utils\WebReader; | |||||||
|  |  | ||||||
|  |  | ||||||
| if (!class_exists('MatchManagerSuite\MatchManagerCore')) { | if (!class_exists('MatchManagerSuite\MatchManagerCore')) { | ||||||
| 	$this->maniaControl->getChat()->sendErrorToAdmins('MatchManager Core is required to use one of MatchManager plugin. Install it and restart Maniacontrol'); | 	$this->maniaControl->getChat()->sendErrorToAdmins('MatchManager Core is required to use MatchManagerTMWTDuoIntegration plugin. Install it and restart Maniacontrol'); | ||||||
| 	Logger::logError('MatchManager Core is required to use one of MatchManager plugin. Install it and restart Maniacontrol'); | 	Logger::logError('MatchManager Core is required to use MatchManagerTMWTDuoIntegration plugin. Install it and restart Maniacontrol'); | ||||||
| 	return false; | 	return false; | ||||||
| } | } | ||||||
| use MatchManagerSuite\MatchManagerCore; | use MatchManagerSuite\MatchManagerCore; | ||||||
| @@ -37,10 +37,12 @@ class MatchManagerTMWTDuoIntegration implements CallbackListener, ManialinkPageA | |||||||
| 	 * Constants | 	 * Constants | ||||||
| 	 */ | 	 */ | ||||||
| 	const PLUGIN_ID											= 211; | 	const PLUGIN_ID											= 211; | ||||||
| 	const PLUGIN_VERSION									= 1.0; | 	const PLUGIN_VERSION									= 1.1; | ||||||
| 	const PLUGIN_NAME										= 'MatchManager TMWT Duo Integration'; | 	const PLUGIN_NAME										= 'MatchManager TMWT Duo Integration'; | ||||||
| 	const PLUGIN_AUTHOR										= 'Beu'; | 	const PLUGIN_AUTHOR										= 'Beu'; | ||||||
|  |  | ||||||
|  | 	const LOG_PREFIX										= '[MatchManagerTMWTDuoIntegration] '; | ||||||
|  |  | ||||||
| 	// Other MatchManager plugin | 	// Other MatchManager plugin | ||||||
| 	const MATCHMANAGERCORE_PLUGIN							= 'MatchManagerSuite\MatchManagerCore'; | 	const MATCHMANAGERCORE_PLUGIN							= 'MatchManagerSuite\MatchManagerCore'; | ||||||
| 	const MATCHMANAGERADMINUI_PLUGIN						= 'MatchManagerSuite\MatchManagerAdminUI'; | 	const MATCHMANAGERADMINUI_PLUGIN						= 'MatchManagerSuite\MatchManagerAdminUI'; | ||||||
| @@ -62,6 +64,7 @@ class MatchManagerTMWTDuoIntegration implements CallbackListener, ManialinkPageA | |||||||
| 	const SETTING_PICKANDBAN_ENABLE 						= 'Enable Pick & Ban'; | 	const SETTING_PICKANDBAN_ENABLE 						= 'Enable Pick & Ban'; | ||||||
| 	const SETTING_PICKANDBAN_STEPCONFIG 					= 'Pick & Ban: Step config'; | 	const SETTING_PICKANDBAN_STEPCONFIG 					= 'Pick & Ban: Step config'; | ||||||
| 	const SETTING_PICKANDBAN_STEPDURATION 					= 'Pick & Ban: Step duration'; | 	const SETTING_PICKANDBAN_STEPDURATION 					= 'Pick & Ban: Step duration'; | ||||||
|  | 	const SETTING_PICKANDBAN_OVERRIDEMAPORDER	 			= 'Pick & Ban: Override Map Order'; | ||||||
| 	const SETTING_PICKANDBAN_RESULTDURATION 				= 'Pick & Ban: Result duration'; | 	const SETTING_PICKANDBAN_RESULTDURATION 				= 'Pick & Ban: Result duration'; | ||||||
|  |  | ||||||
| 	const STATE_NOTHING = 0; | 	const STATE_NOTHING = 0; | ||||||
| @@ -74,6 +77,7 @@ class MatchManagerTMWTDuoIntegration implements CallbackListener, ManialinkPageA | |||||||
| 	 */ | 	 */ | ||||||
| 	/** @var ManiaControl $maniaControl */ | 	/** @var ManiaControl $maniaControl */ | ||||||
| 	private $maniaControl 			= null; | 	private $maniaControl 			= null; | ||||||
|  | 	/** @var MatchManagerCore $MatchManagerCore */ | ||||||
| 	private $MatchManagerCore		= null; | 	private $MatchManagerCore		= null; | ||||||
| 	private $state = 0; | 	private $state = 0; | ||||||
|  |  | ||||||
| @@ -139,7 +143,8 @@ class MatchManagerTMWTDuoIntegration implements CallbackListener, ManialinkPageA | |||||||
| 		$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_PICKANDBAN_ENABLE, false, '', 20); | 		$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_PICKANDBAN_ENABLE, false, '', 20); | ||||||
| 		$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_PICKANDBAN_STEPCONFIG, '', 'Similar syntax as the ofiicial Competition Tool. e.g: b:1,b:0,p:0,p:1,p:1,p:0,b:0,b:1,p:r'); | 		$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_PICKANDBAN_STEPCONFIG, '', 'Similar syntax as the ofiicial Competition Tool. e.g: b:1,b:0,p:0,p:1,p:1,p:0,b:0,b:1,p:r'); | ||||||
| 		$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_PICKANDBAN_STEPDURATION, 60000, 'Each step duration in ms', 110); | 		$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_PICKANDBAN_STEPDURATION, 60000, 'Each step duration in ms', 110); | ||||||
| 		$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_PICKANDBAN_RESULTDURATION, 10000, 'result duration in ms', 120); | 		$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_PICKANDBAN_OVERRIDEMAPORDER, '', 'Override map order received by the server. e.g: 1,2,4,3,5', 120); | ||||||
|  | 		$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_PICKANDBAN_RESULTDURATION, 10000, 'result duration in ms', 130); | ||||||
|  |  | ||||||
| 		// Callbacks | 		// Callbacks | ||||||
| 		$this->maniaControl->getManialinkManager()->registerManialinkPageAnswerListener(self::ML_ACTION_OPENSETTINGS, $this, 'handleActionOpenSettings'); | 		$this->maniaControl->getManialinkManager()->registerManialinkPageAnswerListener(self::ML_ACTION_OPENSETTINGS, $this, 'handleActionOpenSettings'); | ||||||
| @@ -157,6 +162,24 @@ class MatchManagerTMWTDuoIntegration implements CallbackListener, ManialinkPageA | |||||||
| 		$this->updateAdminUIMenuItems(); | 		$this->updateAdminUIMenuItems(); | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
|  | 	/** | ||||||
|  | 	 * Custom log function to add prefix | ||||||
|  | 	 *  | ||||||
|  | 	 * @param mixed $message | ||||||
|  | 	 */ | ||||||
|  | 	private function log(mixed $message) { | ||||||
|  | 		Logger::log(self::LOG_PREFIX . $message); | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	/** | ||||||
|  | 	 * Custom logError function to add prefix | ||||||
|  | 	 *  | ||||||
|  | 	 * @param mixed $message | ||||||
|  | 	 */ | ||||||
|  | 	private function logError(mixed $message) { | ||||||
|  | 		Logger::logError(self::LOG_PREFIX . $message); | ||||||
|  | 	} | ||||||
|  |  | ||||||
| 	/** | 	/** | ||||||
| 	 * handle Plugin Loaded | 	 * handle Plugin Loaded | ||||||
| 	 *  | 	 *  | ||||||
| @@ -234,7 +257,7 @@ class MatchManagerTMWTDuoIntegration implements CallbackListener, ManialinkPageA | |||||||
|  |  | ||||||
| 		if ($this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_PICKANDBAN_ENABLE)) { | 		if ($this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_PICKANDBAN_ENABLE)) { | ||||||
| 			if ($this->maniaControl->getSettingManager()->getSettingValue($this->MatchManagerCore, $this->MatchManagerCore::SETTING_MATCH_SETTINGS_MODE) !== "All from the plugin") { | 			if ($this->maniaControl->getSettingManager()->getSettingValue($this->MatchManagerCore, $this->MatchManagerCore::SETTING_MATCH_SETTINGS_MODE) !== "All from the plugin") { | ||||||
| 				$this->maniaControl->getChat()->sendErrorToAdmins('TMWT Pick and bans are only supported in Match Manager Core "All from the plugin" mode'); | 				$this->maniaControl->getChat()->sendErrorToAdmins($this->MatchManagerCore->getChatPrefix() .'TMWT Pick and bans are only supported in MatchManagerCore "All from the plugin" mode'); | ||||||
| 				return false; | 				return false; | ||||||
| 			} | 			} | ||||||
| 		} | 		} | ||||||
| @@ -254,8 +277,8 @@ class MatchManagerTMWTDuoIntegration implements CallbackListener, ManialinkPageA | |||||||
| 		if ($setting !== null && !$setting->value) { | 		if ($setting !== null && !$setting->value) { | ||||||
| 			$setting->value = true; | 			$setting->value = true; | ||||||
| 			$this->maniaControl->getSettingManager()->saveSetting($setting); | 			$this->maniaControl->getSettingManager()->saveSetting($setting); | ||||||
| 			Logger::logWarning('Remplacing S_IsMatchmaking setting value in MatchManagerCore for TMWT integration'); | 			$this->logError('Remplacing S_IsMatchmaking setting value in MatchManagerCore for TMWT integration'); | ||||||
| 			$this->maniaControl->getChat()->sendErrorToAdmins('Remplacing S_IsMatchmaking setting value in MatchManagerCore for TMWT integration'); | 			$this->maniaControl->getChat()->sendErrorToAdmins($this->MatchManagerCore->getChatPrefix() .'Remplacing S_IsMatchmaking setting value in MatchManagerCore for TMWT integration'); | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
| 		if ($this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_PICKANDBAN_ENABLE)) { | 		if ($this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_PICKANDBAN_ENABLE)) { | ||||||
| @@ -263,8 +286,8 @@ class MatchManagerTMWTDuoIntegration implements CallbackListener, ManialinkPageA | |||||||
| 			if ($setting !== null && !$setting->value) { | 			if ($setting !== null && !$setting->value) { | ||||||
| 				$setting->value = true; | 				$setting->value = true; | ||||||
| 				$this->maniaControl->getSettingManager()->saveSetting($setting); | 				$this->maniaControl->getSettingManager()->saveSetting($setting); | ||||||
| 				Logger::logWarning('Remplacing S_PickAndBan_Enable setting value in MatchManagerCore for TMWT integration'); | 				$this->logError('Remplacing S_PickAndBan_Enable setting value in MatchManagerCore for TMWT integration'); | ||||||
| 				$this->maniaControl->getChat()->sendErrorToAdmins('Remplacing S_PickAndBan_Enable setting value in MatchManagerCore for TMWT integration'); | 				$this->maniaControl->getChat()->sendErrorToAdmins($this->MatchManagerCore->getChatPrefix() .'Remplacing S_PickAndBan_Enable setting value in MatchManagerCore for TMWT integration'); | ||||||
| 			} | 			} | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| @@ -317,14 +340,14 @@ class MatchManagerTMWTDuoIntegration implements CallbackListener, ManialinkPageA | |||||||
| 						if ($team->Id === $team1) { | 						if ($team->Id === $team1) { | ||||||
| 							$team1 = null; | 							$team1 = null; | ||||||
| 							foreach ($team->Players as $player) { | 							foreach ($team->Players as $player) { | ||||||
| 								Logger::log($player->AccountId ." added to team 1"); | 								$this->log($player->AccountId ." added to team 1"); | ||||||
| 								$this->maniaControl->getClient()->triggerModeScriptEvent(self::XMLRPC_METHOD_ADDPLAYER, [$player->AccountId, "1"], true); | 								$this->maniaControl->getClient()->triggerModeScriptEvent(self::XMLRPC_METHOD_ADDPLAYER, [$player->AccountId, "1"], true); | ||||||
| 							} | 							} | ||||||
| 						} | 						} | ||||||
| 						if ($team->Id === $team2) { | 						if ($team->Id === $team2) { | ||||||
| 							$team2 = null; | 							$team2 = null; | ||||||
| 							foreach ($team->Players as $player) { | 							foreach ($team->Players as $player) { | ||||||
| 								Logger::log($player->AccountId ." added to team 2"); | 								$this->log($player->AccountId ." added to team 2"); | ||||||
| 								$this->maniaControl->getClient()->triggerModeScriptEvent(self::XMLRPC_METHOD_ADDPLAYER, [$player->AccountId, "2"], true); | 								$this->maniaControl->getClient()->triggerModeScriptEvent(self::XMLRPC_METHOD_ADDPLAYER, [$player->AccountId, "2"], true); | ||||||
| 							} | 							} | ||||||
| 						} | 						} | ||||||
| @@ -333,8 +356,8 @@ class MatchManagerTMWTDuoIntegration implements CallbackListener, ManialinkPageA | |||||||
| 					} | 					} | ||||||
|  |  | ||||||
| 					if ($this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_PICKANDBAN_ENABLE)) { | 					if ($this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_PICKANDBAN_ENABLE)) { | ||||||
| 						Logger::log('Starting Pick & ban in 10 seconds'); | 						$this->log('Starting Pick & ban in 10 seconds'); | ||||||
| 						$this->maniaControl->getChat()->sendSuccess('Starting pick & ban in 10 seconds'); | 						$this->maniaControl->getChat()->sendSuccess($this->MatchManagerCore->getChatPrefix() .'Starting pick & ban in 10 seconds'); | ||||||
| 						$this->maniaControl->getTimerManager()->registerOneTimeListening($this, function () { | 						$this->maniaControl->getTimerManager()->registerOneTimeListening($this, function () { | ||||||
| 						$payload = [ | 						$payload = [ | ||||||
| 							'stepDuration' => $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_PICKANDBAN_STEPDURATION), | 							'stepDuration' => $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_PICKANDBAN_STEPDURATION), | ||||||
| @@ -364,12 +387,12 @@ class MatchManagerTMWTDuoIntegration implements CallbackListener, ManialinkPageA | |||||||
|  |  | ||||||
| 						$json = json_encode($payload); | 						$json = json_encode($payload); | ||||||
|  |  | ||||||
| 						Logger::log('Starting Pick & ban: '. $json); | 						$this->log('Starting Pick & ban: '. $json); | ||||||
| 						$this->maniaControl->getClient()->triggerModeScriptEvent(self::XMLRPC_METHOD_STARTPICKANDBAN, [$json], true); | 						$this->maniaControl->getClient()->triggerModeScriptEvent(self::XMLRPC_METHOD_STARTPICKANDBAN, [$json], true); | ||||||
| 						}, 5000); | 						}, 5000); | ||||||
| 					} else { | 					} else { | ||||||
| 						$this->state = self::STATE_MATCH; | 						$this->state = self::STATE_MATCH; | ||||||
| 						Logger::log('Sending match start callback'); | 						$this->log('Sending match start callback'); | ||||||
| 						$this->maniaControl->getClient()->triggerModeScriptEvent(self::XMLRPC_METHOD_MATCHSTARTED, [], true); | 						$this->maniaControl->getClient()->triggerModeScriptEvent(self::XMLRPC_METHOD_MATCHSTARTED, [], true); | ||||||
| 					} | 					} | ||||||
| 				} | 				} | ||||||
| @@ -385,13 +408,30 @@ class MatchManagerTMWTDuoIntegration implements CallbackListener, ManialinkPageA | |||||||
| 	 */ | 	 */ | ||||||
| 	public function handlePickAndBanComplete(array $structure) { | 	public function handlePickAndBanComplete(array $structure) { | ||||||
| 		if (!$this->MatchManagerCore->getMatchStatus()) return; | 		if (!$this->MatchManagerCore->getMatchStatus()) return; | ||||||
| 		Logger::log('Received picks: '. $structure[1][0]); | 		$this->log('Received picks: '. $structure[1][0]); | ||||||
|  |  | ||||||
| 		$this->maniaControl->getTimerManager()->registerOneTimeListening($this, function () use ($structure) { | 		$this->maniaControl->getTimerManager()->registerOneTimeListening($this, function () use ($structure) { | ||||||
| 			try { | 			try { | ||||||
| 				$json = json_decode($structure[1][0]); | 				$json = json_decode($structure[1][0]); | ||||||
| 	 | 	 | ||||||
| 				$mapUids = array_column($json->playlist, 'uid'); | 				$mapUids = array_column($json->playlist, 'uid'); | ||||||
|  |  | ||||||
|  | 				$order = explode(',', $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_PICKANDBAN_OVERRIDEMAPORDER)); | ||||||
|  |  | ||||||
|  | 				if (count($order) === count($mapUids)) { | ||||||
|  | 					$this->log("Re-ordering maps"); | ||||||
|  | 					try { | ||||||
|  | 						$orderedMapUid = []; | ||||||
|  | 						foreach ($order as $number) { | ||||||
|  | 							$orderedMapUid[] = $mapUids[$number - 1]; | ||||||
|  | 						} | ||||||
|  | 						$mapUids = $orderedMapUid; | ||||||
|  | 					} catch (\Throwable $th) { | ||||||
|  | 						$this->logError("Invalid Map order setting"); | ||||||
|  | 						$this->maniaControl->getChat()->sendErrorToAdmins($this->MatchManagerCore->getChatPrefix() ."Invalid Map order setting"); | ||||||
|  | 					} | ||||||
|  | 				} | ||||||
|  |  | ||||||
| 				$mapList = []; | 				$mapList = []; | ||||||
| 				foreach ($this->maniaControl->getMapManager()->getMaps() as $map) { | 				foreach ($this->maniaControl->getMapManager()->getMaps() as $map) { | ||||||
| 					$index = array_search($map->uid, $mapUids); | 					$index = array_search($map->uid, $mapUids); | ||||||
| @@ -404,19 +444,19 @@ class MatchManagerTMWTDuoIntegration implements CallbackListener, ManialinkPageA | |||||||
| 				} | 				} | ||||||
| 	 | 	 | ||||||
| 				if (count($mapUids) !== count($mapList)) { | 				if (count($mapUids) !== count($mapList)) { | ||||||
| 					Logger::logError("Missing maps: ". implode(' ', array_diff($mapUids, $mapList))); | 					$this->logError("Missing maps: ". implode(' ', array_diff($mapUids, $mapList))); | ||||||
| 				} | 				} | ||||||
| 	 | 	 | ||||||
| 				ksort($mapList); | 				ksort($mapList); | ||||||
|  |  | ||||||
| 				$this->maniaControl->getClient()->chooseNextMapList(array_values($mapList)); | 				$this->maniaControl->getClient()->chooseNextMapList(array_values($mapList)); | ||||||
| 			} catch (\Throwable $th) { | 			} catch (\Throwable $th) { | ||||||
| 				Logger::logError("Can't apply map list: ". $th->getMessage()); | 				$this->logError("Can't apply map list: ". $th->getMessage()); | ||||||
| 				$this->maniaControl->getChat()->sendError("Can't apply map list: ". $th->getMessage()); | 				$this->maniaControl->getChat()->sendError($this->MatchManagerCore->getChatPrefix() ."Can't apply map list: ". $th->getMessage()); | ||||||
| 			} | 			} | ||||||
|  |  | ||||||
| 			$this->state = self::STATE_MATCH; | 			$this->state = self::STATE_MATCH; | ||||||
| 			Logger::log('Sending match start callback'); | 			$this->log('Sending match start callback'); | ||||||
| 			$this->maniaControl->getClient()->triggerModeScriptEvent(self::XMLRPC_METHOD_MATCHSTARTED, [], true); | 			$this->maniaControl->getClient()->triggerModeScriptEvent(self::XMLRPC_METHOD_MATCHSTARTED, [], true); | ||||||
| 			$this->maniaControl->getMapManager()->getMapActions()->skipMap(); | 			$this->maniaControl->getMapManager()->getMapActions()->skipMap(); | ||||||
| 		}, $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_PICKANDBAN_RESULTDURATION)); | 		}, $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_PICKANDBAN_RESULTDURATION)); | ||||||
| @@ -431,8 +471,8 @@ class MatchManagerTMWTDuoIntegration implements CallbackListener, ManialinkPageA | |||||||
| 	 */ | 	 */ | ||||||
| 	public function handlePluginUnloaded(string $pluginClass, Plugin $plugin) { | 	public function handlePluginUnloaded(string $pluginClass, Plugin $plugin) { | ||||||
| 		if ($pluginClass == self::MATCHMANAGERCORE_PLUGIN) { | 		if ($pluginClass == self::MATCHMANAGERCORE_PLUGIN) { | ||||||
| 			$this->maniaControl->getChat()->sendErrorToAdmins(self::PLUGIN_NAME . " disabled because MatchManager Core is now disabled"); | 			$this->maniaControl->getChat()->sendErrorToAdmins($this->MatchManagerCore->getChatPrefix() .self::PLUGIN_NAME . " disabled because MatchManager Core is now disabled"); | ||||||
| 			$this->maniaControl->getPluginManager()->deactivatePlugin((get_class())); | 			$this->maniaControl->getPluginManager()->deactivatePlugin((get_class($this))); | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| @@ -446,7 +486,7 @@ class MatchManagerTMWTDuoIntegration implements CallbackListener, ManialinkPageA | |||||||
| 		if ($setting->setting === self::SETTING_PICKANDBAN_ENABLE || $setting->setting === $this->MatchManagerCore::SETTING_MATCH_SETTINGS_MODE) { | 		if ($setting->setting === self::SETTING_PICKANDBAN_ENABLE || $setting->setting === $this->MatchManagerCore::SETTING_MATCH_SETTINGS_MODE) { | ||||||
| 			if ($this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_PICKANDBAN_ENABLE)) { | 			if ($this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_PICKANDBAN_ENABLE)) { | ||||||
| 				if ($this->maniaControl->getSettingManager()->getSettingValue($this->MatchManagerCore, $this->MatchManagerCore::SETTING_MATCH_SETTINGS_MODE) !== "All from the plugin") { | 				if ($this->maniaControl->getSettingManager()->getSettingValue($this->MatchManagerCore, $this->MatchManagerCore::SETTING_MATCH_SETTINGS_MODE) !== "All from the plugin") { | ||||||
| 					$this->maniaControl->getChat()->sendErrorToAdmins('TMWT Pick and bans are only supported in Match Manager Core "All from the plugin" mode'); | 					$this->maniaControl->getChat()->sendErrorToAdmins($this->MatchManagerCore->getChatPrefix() .'TMWT Pick and bans are only supported in Match Manager Core "All from the plugin" mode'); | ||||||
| 				} | 				} | ||||||
| 			} | 			} | ||||||
| 		} | 		} | ||||||
| @@ -456,7 +496,7 @@ class MatchManagerTMWTDuoIntegration implements CallbackListener, ManialinkPageA | |||||||
| 	 * @see \ManiaControl\Plugins\Plugin::unload() | 	 * @see \ManiaControl\Plugins\Plugin::unload() | ||||||
| 	 */ | 	 */ | ||||||
| 	public function unload() { | 	public function unload() { | ||||||
| 		$this->MatchManagerCore->removeCanStartFunction($this, 'canStartMatch');  | 		if ($this->MatchManagerCore !== null) $this->MatchManagerCore->removeCanStartFunction($this, 'canStartMatch');  | ||||||
| 		/** @var \MatchManagerSuite\MatchManagerAdminUI|null */ | 		/** @var \MatchManagerSuite\MatchManagerAdminUI|null */ | ||||||
| 		$adminUIPlugin = $this->maniaControl->getPluginManager()->getPlugin(self::MATCHMANAGERADMINUI_PLUGIN); | 		$adminUIPlugin = $this->maniaControl->getPluginManager()->getPlugin(self::MATCHMANAGERADMINUI_PLUGIN); | ||||||
| 		if ($adminUIPlugin !== null) { | 		if ($adminUIPlugin !== null) { | ||||||
|   | |||||||
| @@ -20,8 +20,8 @@ use ManiaControl\Settings\Setting; | |||||||
| use ManiaControl\Settings\SettingManager; | use ManiaControl\Settings\SettingManager; | ||||||
|  |  | ||||||
| if (!class_exists('MatchManagerSuite\MatchManagerCore')) { | if (!class_exists('MatchManagerSuite\MatchManagerCore')) { | ||||||
| 	$this->maniaControl->getChat()->sendErrorToAdmins('MatchManager Core is required to use one of MatchManager plugin. Install it and restart Maniacontrol'); | 	$this->maniaControl->getChat()->sendErrorToAdmins('MatchManager Core is required to use MatchManagerWidget plugin. Install it and restart Maniacontrol'); | ||||||
| 	Logger::logError('MatchManager Core is required to use one of MatchManager plugin. Install it and restart Maniacontrol'); | 	$this->logError('MatchManager Core is required to use MatchManagerWidget plugin. Install it and restart Maniacontrol'); | ||||||
| 	return false; | 	return false; | ||||||
| } | } | ||||||
| use MatchManagerSuite\MatchManagerCore; | use MatchManagerSuite\MatchManagerCore; | ||||||
| @@ -42,6 +42,8 @@ class MatchManagerWidget implements ManialinkPageAnswerListener, CallbackListene | |||||||
| 	const PLUGIN_NAME										= 'MatchManager Widget'; | 	const PLUGIN_NAME										= 'MatchManager Widget'; | ||||||
| 	const PLUGIN_AUTHOR										= 'Beu'; | 	const PLUGIN_AUTHOR										= 'Beu'; | ||||||
|  |  | ||||||
|  | 	const LOG_PREFIX										= '[MatchManagerWidget] '; | ||||||
|  |  | ||||||
| 	// MatchManagerWidget Properties | 	// MatchManagerWidget Properties | ||||||
| 	const MATCHMANAGERWIDGET_COMPATIBLE_GM					= ["Cup", "Teams", "Rounds"]; | 	const MATCHMANAGERWIDGET_COMPATIBLE_GM					= ["Cup", "Teams", "Rounds"]; | ||||||
| 	const MATCHMANAGERCORE_PLUGIN							= 'MatchManagerSuite\MatchManagerCore'; | 	const MATCHMANAGERCORE_PLUGIN							= 'MatchManagerSuite\MatchManagerCore'; | ||||||
| @@ -64,6 +66,7 @@ class MatchManagerWidget implements ManialinkPageAnswerListener, CallbackListene | |||||||
| 	 */ | 	 */ | ||||||
| 	/** @var ManiaControl $maniaControl */ | 	/** @var ManiaControl $maniaControl */ | ||||||
| 	private $maniaControl 			= null; | 	private $maniaControl 			= null; | ||||||
|  | 	/** @var MatchManagerCore $MatchManagerCore */ | ||||||
| 	private $MatchManagerCore		= null; | 	private $MatchManagerCore		= null; | ||||||
| 	private $gmbase					= ""; | 	private $gmbase					= ""; | ||||||
| 	private $manialinkData			= null; | 	private $manialinkData			= null; | ||||||
| @@ -171,6 +174,24 @@ class MatchManagerWidget implements ManialinkPageAnswerListener, CallbackListene | |||||||
| 		$this->closeWidgets(); | 		$this->closeWidgets(); | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
|  | 	/** | ||||||
|  | 	 * Custom log function to add prefix | ||||||
|  | 	 *  | ||||||
|  | 	 * @param mixed $message | ||||||
|  | 	 */ | ||||||
|  | 	private function log(mixed $message) { | ||||||
|  | 		Logger::log(self::LOG_PREFIX . $message); | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	/** | ||||||
|  | 	 * Custom logError function to add prefix | ||||||
|  | 	 *  | ||||||
|  | 	 * @param mixed $message | ||||||
|  | 	 */ | ||||||
|  | 	private function logError(mixed $message) { | ||||||
|  | 		Logger::logError(self::LOG_PREFIX . $message); | ||||||
|  | 	} | ||||||
|  |  | ||||||
| 	/** | 	/** | ||||||
| 	 * handlePluginUnloaded | 	 * handlePluginUnloaded | ||||||
| 	 * | 	 * | ||||||
| @@ -181,7 +202,7 @@ class MatchManagerWidget implements ManialinkPageAnswerListener, CallbackListene | |||||||
| 	public function handlePluginUnloaded(string $pluginClass, Plugin $plugin) { | 	public function handlePluginUnloaded(string $pluginClass, Plugin $plugin) { | ||||||
| 		if ($pluginClass == self::MATCHMANAGERCORE_PLUGIN) { | 		if ($pluginClass == self::MATCHMANAGERCORE_PLUGIN) { | ||||||
| 			$this->maniaControl->getChat()->sendErrorToAdmins(self::PLUGIN_NAME . " disabled because MatchManager Core is now disabled"); | 			$this->maniaControl->getChat()->sendErrorToAdmins(self::PLUGIN_NAME . " disabled because MatchManager Core is now disabled"); | ||||||
| 			$this->maniaControl->getPluginManager()->deactivatePlugin((get_class())); | 			$this->maniaControl->getPluginManager()->deactivatePlugin((get_class($this))); | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| @@ -215,7 +236,7 @@ class MatchManagerWidget implements ManialinkPageAnswerListener, CallbackListene | |||||||
| 	 * @param array $settings | 	 * @param array $settings | ||||||
| 	 */ | 	 */ | ||||||
| 	public function InitMatch(string $matchid, array $settings) { | 	public function InitMatch(string $matchid, array $settings) { | ||||||
| 		Logger::Log("InitMatch"); | 		$this->log("InitMatch"); | ||||||
| 		$this->gmbase = $settings['currentgmbase']; | 		$this->gmbase = $settings['currentgmbase']; | ||||||
| 		$this->displayManialinks(false); | 		$this->displayManialinks(false); | ||||||
| 	} | 	} | ||||||
| @@ -224,7 +245,7 @@ class MatchManagerWidget implements ManialinkPageAnswerListener, CallbackListene | |||||||
| 	 * Clear variables and hide widget | 	 * Clear variables and hide widget | ||||||
| 	 */ | 	 */ | ||||||
| 	public function ClearMatch() { | 	public function ClearMatch() { | ||||||
| 		Logger::Log("ClearMatch"); | 		$this->log("ClearMatch"); | ||||||
| 		$this->gmbase = ""; | 		$this->gmbase = ""; | ||||||
| 		$this->manialinkData = ""; | 		$this->manialinkData = ""; | ||||||
| 		$this->closeWidgets(); | 		$this->closeWidgets(); | ||||||
| @@ -295,7 +316,7 @@ class MatchManagerWidget implements ManialinkPageAnswerListener, CallbackListene | |||||||
| 	 * @param Player $player | 	 * @param Player $player | ||||||
| 	 */ | 	 */ | ||||||
| 	public function handlePlayerConnect(Player $player) { | 	public function handlePlayerConnect(Player $player) { | ||||||
| 		Logger::Log("handlePlayerConnect"); | 		$this->log("handlePlayerConnect"); | ||||||
|  |  | ||||||
| 		if (strlen($this->gmbase) > 0) { | 		if (strlen($this->gmbase) > 0) { | ||||||
| 			$this->displayManialinks($player->login); | 			$this->displayManialinks($player->login); | ||||||
| @@ -405,7 +426,7 @@ class MatchManagerWidget implements ManialinkPageAnswerListener, CallbackListene | |||||||
| 	 * Generate the manilink of the background of the widget | 	 * Generate the manilink of the background of the widget | ||||||
| 	 */ | 	 */ | ||||||
| 	public function generateMatchLiveWidgetBackground() { | 	public function generateMatchLiveWidgetBackground() { | ||||||
| 		Logger::Log("generateMatchLiveWidgetBackground"); | 		$this->log("generateMatchLiveWidgetBackground"); | ||||||
|  |  | ||||||
| 		$posX       = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MATCHMANAGERWIDGET_LIVE_POSX); | 		$posX       = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MATCHMANAGERWIDGET_LIVE_POSX); | ||||||
| 		$posY       = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MATCHMANAGERWIDGET_LIVE_POSY); | 		$posY       = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MATCHMANAGERWIDGET_LIVE_POSY); | ||||||
| @@ -448,7 +469,7 @@ class MatchManagerWidget implements ManialinkPageAnswerListener, CallbackListene | |||||||
| 	 * @param array $currentscore | 	 * @param array $currentscore | ||||||
| 	 */ | 	 */ | ||||||
| 	public function generateMatchLiveWidgetData(array $currentscore) { | 	public function generateMatchLiveWidgetData(array $currentscore) { | ||||||
| 		Logger::Log("generateMatchLiveWidgetData"); | 		$this->log("generateMatchLiveWidgetData"); | ||||||
|  |  | ||||||
| 		if ($this->gmbase == "Cup") { | 		if ($this->gmbase == "Cup") { | ||||||
| 			$pointlimit = $this->MatchManagerCore->getMatchPointsLimit(); | 			$pointlimit = $this->MatchManagerCore->getMatchPointsLimit(); | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user