Compare commits
	
		
			2 Commits
		
	
	
		
			f8c8ff6269
			...
			8d01340d22
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 
						
						
							
						
						8d01340d22
	
				 | 
					
					
						|||
| 
						
						
							
						
						6887384578
	
				 | 
					
					
						
@@ -12,8 +12,8 @@ use ManiaControl\Settings\SettingManager;
 | 
			
		||||
use ManiaControl\Callbacks\TimerListener;
 | 
			
		||||
 | 
			
		||||
if (!class_exists('MatchManagerSuite\MatchManagerCore')) {
 | 
			
		||||
	$this->maniaControl->getChat()->sendErrorToAdmins('MatchManager Core is required to use one of MatchManager plugin. Install it and restart Maniacontrol');
 | 
			
		||||
	Logger::logError('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 MatchManagerAutomaticLauncher plugin. Install it and restart Maniacontrol');
 | 
			
		||||
	return false;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -42,6 +42,7 @@ class MatchManagerAutomaticLauncher implements CallbackListener, TimerListener,
 | 
			
		||||
	 */
 | 
			
		||||
	/** @var ManiaControl $maniaControl */
 | 
			
		||||
	private $maniaControl 			= null;
 | 
			
		||||
	/** @var MatchManagerCore $MatchManagerCore */
 | 
			
		||||
	private $MatchManagerCore		= null;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@@ -101,7 +102,7 @@ class MatchManagerAutomaticLauncher implements CallbackListener, TimerListener,
 | 
			
		||||
				$this->MatchManagerCore = $this->maniaControl->getPluginManager()->getPlugin(self::MATCHMANAGERCORE_PLUGIN);
 | 
			
		||||
				if ($this->MatchManagerCore == null) {
 | 
			
		||||
					$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 {
 | 
			
		||||
					$this->createTimers();
 | 
			
		||||
				}
 | 
			
		||||
@@ -146,7 +147,7 @@ class MatchManagerAutomaticLauncher implements CallbackListener, TimerListener,
 | 
			
		||||
	public function handlePluginUnloaded(string $pluginClass, Plugin $plugin) {
 | 
			
		||||
		if ($pluginClass == self::MATCHMANAGERCORE_PLUGIN) {
 | 
			
		||||
			$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++;
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
		$this->maniaControl->getChat()->sendSuccessToAdmins($newtimers . " matches are planned");
 | 
			
		||||
		$this->maniaControl->getChat()->sendSuccessToAdmins($this->MatchManagerCore->getChatPrefix() . $newtimers . " matches are planned");
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
@@ -14,6 +14,7 @@ use ManiaControl\Callbacks\Structures\TrackMania\OnWayPointEventStructure;
 | 
			
		||||
use ManiaControl\Callbacks\TimerListener;
 | 
			
		||||
use ManiaControl\Manialinks\ManialinkPageAnswerListener;
 | 
			
		||||
use ManiaControl\Players\Player;
 | 
			
		||||
use ManiaControl\Plugins\PluginManager;
 | 
			
		||||
use ManiaControl\Plugins\PluginMenu;
 | 
			
		||||
 | 
			
		||||
if (!class_exists('MatchManagerSuite\MatchManagerCore')) {
 | 
			
		||||
@@ -37,6 +38,8 @@ class MatchManagerECircuitMania implements CallbackListener, ManialinkPageAnswer
 | 
			
		||||
	const PLUGIN_NAME		= 'MatchManager eCircuitMania';
 | 
			
		||||
	const PLUGIN_AUTHOR		= 'Beu';
 | 
			
		||||
 | 
			
		||||
	const LOG_PREFIX					= '[MatchManagerECircuitMania] ';
 | 
			
		||||
 | 
			
		||||
	const MATCHMANAGERCORE_PLUGIN		= 'MatchManagerSuite\MatchManagerCore';
 | 
			
		||||
	const MATCHMANAGERADMINUI_PLUGIN	= 'MatchManagerSuite\MatchManagerAdminUI';
 | 
			
		||||
 | 
			
		||||
@@ -108,10 +111,12 @@ class MatchManagerECircuitMania implements CallbackListener, ManialinkPageAnswer
 | 
			
		||||
				$this->MatchManagerCore = $this->maniaControl->getPluginManager()->getPlugin(self::MATCHMANAGERCORE_PLUGIN);
 | 
			
		||||
				if ($this->MatchManagerCore === null) {
 | 
			
		||||
					$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;
 | 
			
		||||
				}
 | 
			
		||||
 | 
			
		||||
				$this->maniaControl->getCallbackManager()->registerCallbackListener(PluginManager::CB_PLUGIN_LOADED, $this, 'handlePluginLoaded');
 | 
			
		||||
				$this->maniaControl->getCallbackManager()->registerCallbackListener(PluginManager::CB_PLUGIN_UNLOADED, $this, 'handlePluginUnloaded');
 | 
			
		||||
				$this->maniaControl->getCallbackManager()->registerScriptCallbackListener(self::CB_STARTMAP, $this, 'handleStartMap');
 | 
			
		||||
				$this->maniaControl->getCallbackManager()->registerCallbackListener(Callbacks::MP_STARTROUNDSTART, $this, 'handleStartRound');
 | 
			
		||||
				$this->maniaControl->getCallbackManager()->registerCallbackListener(Callbacks::TM_ONWAYPOINT, $this, 'handleOnWaypoint');
 | 
			
		||||
@@ -130,6 +135,24 @@ class MatchManagerECircuitMania implements CallbackListener, ManialinkPageAnswer
 | 
			
		||||
		$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
 | 
			
		||||
	 * 
 | 
			
		||||
@@ -141,6 +164,22 @@ class MatchManagerECircuitMania implements CallbackListener, ManialinkPageAnswer
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * handlePluginUnloaded
 | 
			
		||||
	 *
 | 
			
		||||
	 * @param  string $pluginClass
 | 
			
		||||
	 * @param  Plugin $plugin
 | 
			
		||||
	 * @return void
 | 
			
		||||
	 */
 | 
			
		||||
	public function handlePluginUnloaded(string $pluginClass, Plugin $plugin) {
 | 
			
		||||
		if ($pluginClass == self::MATCHMANAGERCORE_PLUGIN) {
 | 
			
		||||
			$this->maniaControl->getChat()->sendErrorToAdmins(self::PLUGIN_NAME . " disabled because MatchManager Core is now disabled");
 | 
			
		||||
			$this->log(self::PLUGIN_NAME . " disabled because MatchManager Core is now disabled");
 | 
			
		||||
			$this->maniaControl->getPluginManager()->deactivatePlugin((get_class($this)));
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Add items in AdminUI plugin
 | 
			
		||||
	 */
 | 
			
		||||
@@ -214,7 +253,7 @@ class MatchManagerECircuitMania implements CallbackListener, ManialinkPageAnswer
 | 
			
		||||
		if ($request !== null) {
 | 
			
		||||
			$request->setContent($payload)->setCallable(function ($content, $error, $headers) use ($payload) {
 | 
			
		||||
				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();
 | 
			
		||||
		}
 | 
			
		||||
@@ -226,7 +265,6 @@ class MatchManagerECircuitMania implements CallbackListener, ManialinkPageAnswer
 | 
			
		||||
 | 
			
		||||
		$scores = [];
 | 
			
		||||
		foreach ($structure->getPlayerScores() as $playerscore) {
 | 
			
		||||
			if ($playerscore->getMatchPoints() <= -2000) continue;
 | 
			
		||||
			$scores[] = $playerscore;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
@@ -284,7 +322,7 @@ class MatchManagerECircuitMania implements CallbackListener, ManialinkPageAnswer
 | 
			
		||||
		if ($request !== null) {
 | 
			
		||||
			$request->setContent($payload)->setCallable(function ($content, $error, $headers) use ($payload) {
 | 
			
		||||
				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();
 | 
			
		||||
		}
 | 
			
		||||
@@ -304,7 +342,7 @@ class MatchManagerECircuitMania implements CallbackListener, ManialinkPageAnswer
 | 
			
		||||
		if ($request !== null) {
 | 
			
		||||
			$request->setContent($payload)->setCallable(function ($content, $error, $headers) use ($payload) {
 | 
			
		||||
				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();
 | 
			
		||||
		}
 | 
			
		||||
@@ -334,5 +372,11 @@ class MatchManagerECircuitMania implements CallbackListener, ManialinkPageAnswer
 | 
			
		||||
	/**
 | 
			
		||||
	 * Unload the plugin and its Resources
 | 
			
		||||
	 */
 | 
			
		||||
	public function unload() {}
 | 
			
		||||
	public function unload() {
 | 
			
		||||
		/** @var \MatchManagerSuite\MatchManagerAdminUI|null */
 | 
			
		||||
		$adminUIPlugin = $this->maniaControl->getPluginManager()->getPlugin(self::MATCHMANAGERADMINUI_PLUGIN);
 | 
			
		||||
		if ($adminUIPlugin !== null) {
 | 
			
		||||
			$adminUIPlugin->removeMenuItem(self::ML_ACTION_OPENSETTINGS);
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
@@ -21,8 +21,8 @@ use ManiaControl\Plugins\PluginMenu;
 | 
			
		||||
use ManiaControl\Utils\WebReader;
 | 
			
		||||
 | 
			
		||||
if (!class_exists('MatchManagerSuite\MatchManagerCore')) {
 | 
			
		||||
	$this->maniaControl->getChat()->sendErrorToAdmins('MatchManager Core is required to use one of MatchManager plugin. Install it and restart Maniacontrol');
 | 
			
		||||
	Logger::logError('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 MatchManagerGSheet plugin. Install it and restart Maniacontrol');
 | 
			
		||||
	return false;
 | 
			
		||||
}
 | 
			
		||||
use MatchManagerSuite\MatchManagerCore;
 | 
			
		||||
@@ -43,6 +43,8 @@ class MatchManagerGSheet implements  CallbackListener, TimerListener, CommandLis
 | 
			
		||||
	const PLUGIN_NAME										= 'MatchManager GSheet';
 | 
			
		||||
	const PLUGIN_AUTHOR										= 'Beu';
 | 
			
		||||
 | 
			
		||||
	const LOG_PREFIX										= '[MatchManagerGSheet] ';
 | 
			
		||||
 | 
			
		||||
	// Other MatchManager plugin
 | 
			
		||||
	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
 | 
			
		||||
	 * 
 | 
			
		||||
@@ -243,7 +263,8 @@ class MatchManagerGSheet implements  CallbackListener, TimerListener, CommandLis
 | 
			
		||||
	public function handlePluginUnloaded(string $pluginClass, Plugin $plugin) {
 | 
			
		||||
		if ($pluginClass == self::MATCHMANAGERCORE_PLUGIN) {
 | 
			
		||||
			$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->setting == self::SETTING_MATCHMANAGERGSHEET_CLIENT_SECRET && $setting->value == "hidden") || $setting->setting == self::SETTING_MATCHMANAGERGSHEET_CLIENT_ID) {
 | 
			
		||||
				// (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("expire");
 | 
			
		||||
@@ -292,7 +313,7 @@ class MatchManagerGSheet implements  CallbackListener, TimerListener, CommandLis
 | 
			
		||||
 | 
			
		||||
	public function handlePlayerConnect(Player $player) {
 | 
			
		||||
		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') { 
 | 
			
		||||
			$this->CheckSpeadsheetAccess($player);
 | 
			
		||||
		} 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) {
 | 
			
		||||
		$clientid = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MATCHMANAGERGSHEET_CLIENT_ID);
 | 
			
		||||
		if (empty($clientid)) {
 | 
			
		||||
			Logger::logError('Client ID empty');
 | 
			
		||||
			$this->maniaControl->getChat()->sendError('Client ID empty', $player);
 | 
			
		||||
			$this->logError('Client ID empty');
 | 
			
		||||
			$this->maniaControl->getChat()->sendError($this->MatchManagerCore->getChatPrefix() .'Client ID empty', $player);
 | 
			
		||||
			return;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
@@ -362,29 +383,29 @@ class MatchManagerGSheet implements  CallbackListener, TimerListener, CommandLis
 | 
			
		||||
		$asyncHttpRequest->setContentType("application/x-www-form-urlencoded");
 | 
			
		||||
		$asyncHttpRequest->setCallable(function ($json, $error) use ($player) {
 | 
			
		||||
			if (!$json || $error) {
 | 
			
		||||
				Logger::logError('Error from Google API: ' . $error);
 | 
			
		||||
				$this->maniaControl->getChat()->sendError('Error from Google API: ' . $error, $player);
 | 
			
		||||
				$this->logError('Error from Google API: ' . $error);
 | 
			
		||||
				$this->maniaControl->getChat()->sendError($this->MatchManagerCore->getChatPrefix() .'Error from Google API: ' . $error, $player);
 | 
			
		||||
				return;
 | 
			
		||||
			}
 | 
			
		||||
			$data = json_decode($json);
 | 
			
		||||
			if (!$data) {
 | 
			
		||||
				Logger::logError('Json parse error: ' . $json);
 | 
			
		||||
				$this->maniaControl->getChat()->sendError('Json parse error: ' . $json, $player);
 | 
			
		||||
				$this->logError('Json parse error: ' . $json);
 | 
			
		||||
				$this->maniaControl->getChat()->sendError($this->MatchManagerCore->getChatPrefix() .'Json parse error: ' . $json, $player);
 | 
			
		||||
				return;
 | 
			
		||||
			}
 | 
			
		||||
			if (property_exists($data, "error")) {
 | 
			
		||||
				Logger::logError('Request error: ' . $data->error->code . " ". $data->error->message);
 | 
			
		||||
				$this->maniaControl->getChat()->sendErrorToAdmins('Request error: ' . $data->error->code . " ". $data->error->message);
 | 
			
		||||
				$this->logError('Request error: ' . $data->error->code . " ". $data->error->message);
 | 
			
		||||
				$this->maniaControl->getChat()->sendErrorToAdmins($this->MatchManagerCore->getChatPrefix() .'Request error: ' . $data->error->code . " ". $data->error->message);
 | 
			
		||||
				return;
 | 
			
		||||
			}
 | 
			
		||||
			if (isset($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('After have validate the App, type the commande "//matchgsheet step2"' , $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($this->MatchManagerCore->getChatPrefix() .'After have validate the App, type the commande "//matchgsheet step2"' , $player);
 | 
			
		||||
			} 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 {
 | 
			
		||||
				$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) {
 | 
			
		||||
		$clientid = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MATCHMANAGERGSHEET_CLIENT_ID);
 | 
			
		||||
		if (empty($clientid)) {
 | 
			
		||||
			Logger::logError('Client ID empty');
 | 
			
		||||
			$this->maniaControl->getChat()->sendError('Client ID empty', $player);
 | 
			
		||||
			$this->logError('Client ID empty');
 | 
			
		||||
			$this->maniaControl->getChat()->sendError($this->MatchManagerCore->getChatPrefix() .'Client ID empty', $player);
 | 
			
		||||
			return;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		$clientsecret = $this->getSecretSetting("client_secret");
 | 
			
		||||
		if (empty($clientsecret)) {
 | 
			
		||||
			Logger::logError('Client Secret empty');
 | 
			
		||||
			$this->maniaControl->getChat()->sendError('Client Secret empty', $player);
 | 
			
		||||
			$this->logError('Client Secret empty');
 | 
			
		||||
			$this->maniaControl->getChat()->sendError($this->MatchManagerCore->getChatPrefix() .'Client Secret empty', $player);
 | 
			
		||||
			return;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		if (empty($this->device_code)) {
 | 
			
		||||
			Logger::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->logError('No device_code. Have you run the step 1?');
 | 
			
		||||
			$this->maniaControl->getChat()->sendError($this->MatchManagerCore->getChatPrefix() .'No device_code. Have you run the step 1?', $player);
 | 
			
		||||
			return;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
@@ -417,19 +438,19 @@ class MatchManagerGSheet implements  CallbackListener, TimerListener, CommandLis
 | 
			
		||||
		$asyncHttpRequest->setHeaders(array("Content-Length: 0"));
 | 
			
		||||
		$asyncHttpRequest->setCallable(function ($json, $error) use ($player) {
 | 
			
		||||
			if (!$json || $error) {
 | 
			
		||||
				Logger::logError('Error from Google API: ' . $error);
 | 
			
		||||
				$this->maniaControl->getChat()->sendError('Error from Google API: ' . $error, $player);
 | 
			
		||||
				$this->logError('Error from Google API: ' . $error);
 | 
			
		||||
				$this->maniaControl->getChat()->sendError($this->MatchManagerCore->getChatPrefix() .'Error from Google API: ' . $error, $player);
 | 
			
		||||
				return;
 | 
			
		||||
			}
 | 
			
		||||
			$data = json_decode($json);
 | 
			
		||||
			if (!$data) {
 | 
			
		||||
				Logger::logError('Json parse error: ' . $json);
 | 
			
		||||
				$this->maniaControl->getChat()->sendError('Json parse error: ' . $json, $player);
 | 
			
		||||
				$this->logError('Json parse error: ' . $json);
 | 
			
		||||
				$this->maniaControl->getChat()->sendError($this->MatchManagerCore->getChatPrefix() .'Json parse error: ' . $json, $player);
 | 
			
		||||
				return;
 | 
			
		||||
			}
 | 
			
		||||
			if (property_exists($data, "error")) {
 | 
			
		||||
				Logger::logError('Request error: ' . $data->error->code . " ". $data->error->message);
 | 
			
		||||
				$this->maniaControl->getChat()->sendErrorToAdmins('Request error: ' . $data->error->code . " ". $data->error->message);
 | 
			
		||||
				$this->logError('Request error: ' . $data->error->code . " ". $data->error->message);
 | 
			
		||||
				$this->maniaControl->getChat()->sendErrorToAdmins($this->MatchManagerCore->getChatPrefix() .'Request error: ' . $data->error->code . " ". $data->error->message);
 | 
			
		||||
				return;
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
@@ -438,13 +459,13 @@ class MatchManagerGSheet implements  CallbackListener, TimerListener, CommandLis
 | 
			
		||||
				$this->saveSecretSetting("access_token", $data->access_token);
 | 
			
		||||
				$this->saveSecretSetting("expire", time() + $data->expires_in);
 | 
			
		||||
				$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)) {
 | 
			
		||||
				Logger::logError('Google refused the request: ' . $data->error_description);
 | 
			
		||||
				$this->maniaControl->getChat()->sendError('Google refused the request: ' . $data->error_description , $player);
 | 
			
		||||
				$this->logError('Google refused the request: ' . $data->error_description);
 | 
			
		||||
				$this->maniaControl->getChat()->sendError($this->MatchManagerCore->getChatPrefix() .'Google refused the request: ' . $data->error_description , $player);
 | 
			
		||||
			} else {
 | 
			
		||||
				Logger::logError('Unkown error' . $data->error_description);
 | 
			
		||||
				$this->maniaControl->getChat()->sendError('Unkown error' , $player);
 | 
			
		||||
				$this->logError('Unkown error' . $data->error_description);
 | 
			
		||||
				$this->maniaControl->getChat()->sendError($this->MatchManagerCore->getChatPrefix() .'Unkown error' , $player);
 | 
			
		||||
			}
 | 
			
		||||
		});
 | 
			
		||||
 | 
			
		||||
@@ -452,7 +473,7 @@ class MatchManagerGSheet implements  CallbackListener, TimerListener, CommandLis
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	private function refreshTokenIfNeeded() {
 | 
			
		||||
		Logger::Log('refreshTokenIfNeeded');
 | 
			
		||||
		$this->Log('refreshTokenIfNeeded');
 | 
			
		||||
		$this->access_token = $this->getSecretSetting("access_token");
 | 
			
		||||
		$expire = $this->getSecretSetting("expire");
 | 
			
		||||
		$refreshtoken = $this->getSecretSetting("refresh_token");
 | 
			
		||||
@@ -465,18 +486,18 @@ class MatchManagerGSheet implements  CallbackListener, TimerListener, CommandLis
 | 
			
		||||
				$json = $response->getContent();
 | 
			
		||||
				$error = $response->getError();
 | 
			
		||||
				if (!$json || $error) {
 | 
			
		||||
					Logger::logError('Error during token refresh: ' . $error);
 | 
			
		||||
					$this->maniaControl->getChat()->sendErrorToAdmins('Error during token refresh: ' . $error);
 | 
			
		||||
					$this->logError('Error during token refresh: ' . $error);
 | 
			
		||||
					$this->maniaControl->getChat()->sendErrorToAdmins($this->MatchManagerCore->getChatPrefix() .'Error during token refresh: ' . $error);
 | 
			
		||||
					return;
 | 
			
		||||
				}
 | 
			
		||||
				$data = json_decode($json);
 | 
			
		||||
				if (!$data) {
 | 
			
		||||
					Logger::logError('Json parse error: ' . $json);
 | 
			
		||||
					$this->logError('Json parse error: ' . $json);
 | 
			
		||||
					return;
 | 
			
		||||
				}
 | 
			
		||||
				if (property_exists($data, "error")) {
 | 
			
		||||
					Logger::logError('Request error: ' . $data->error->code . " ". $data->error->message);
 | 
			
		||||
					$this->maniaControl->getChat()->sendErrorToAdmins('Request error: ' . $data->error->code . " ". $data->error->message);
 | 
			
		||||
					$this->logError('Request error: ' . $data->error->code . " ". $data->error->message);
 | 
			
		||||
					$this->maniaControl->getChat()->sendErrorToAdmins($this->MatchManagerCore->getChatPrefix() .'Request error: ' . $data->error->code . " ". $data->error->message);
 | 
			
		||||
					return;
 | 
			
		||||
				}
 | 
			
		||||
 | 
			
		||||
@@ -485,9 +506,9 @@ class MatchManagerGSheet implements  CallbackListener, TimerListener, CommandLis
 | 
			
		||||
					$this->saveSecretSetting("access_token", $data->access_token);
 | 
			
		||||
					$this->saveSecretSetting("expire", time() + $data->expires_in);
 | 
			
		||||
				} 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 {
 | 
			
		||||
					$this->maniaControl->getChat()->sendErrorToAdmins('Unkown error');
 | 
			
		||||
					$this->maniaControl->getChat()->sendErrorToAdmins($this->MatchManagerCore->getChatPrefix() .'Unkown error');
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
			return true;
 | 
			
		||||
@@ -530,7 +551,7 @@ class MatchManagerGSheet implements  CallbackListener, TimerListener, CommandLis
 | 
			
		||||
	private function CheckSpeadsheetAccess(Player $player) {
 | 
			
		||||
		$spreadsheetid = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MATCHMANAGERGSHEET_SPREADSHEET);
 | 
			
		||||
		if ($spreadsheetid === "") {
 | 
			
		||||
			$this->maniaControl->getChat()->sendError('Empty Spreadsheet Id', $player);
 | 
			
		||||
			$this->maniaControl->getChat()->sendError($this->MatchManagerCore->getChatPrefix() .'Empty Spreadsheet Id', $player);
 | 
			
		||||
			return;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
@@ -540,32 +561,32 @@ class MatchManagerGSheet implements  CallbackListener, TimerListener, CommandLis
 | 
			
		||||
			$asyncHttpRequest->setHeaders(array("Authorization: Bearer " . $this->access_token));
 | 
			
		||||
			$asyncHttpRequest->setCallable(function ($json, $error) use ($player) {
 | 
			
		||||
				if (!$json || $error) {
 | 
			
		||||
					Logger::logError('Error: ' . $error);
 | 
			
		||||
					$this->maniaControl->getChat()->sendError('Error: ' . $error, $player);
 | 
			
		||||
					$this->logError('Error: ' . $error);
 | 
			
		||||
					$this->maniaControl->getChat()->sendError($this->MatchManagerCore->getChatPrefix() .'Error: ' . $error, $player);
 | 
			
		||||
					return;
 | 
			
		||||
				}
 | 
			
		||||
				$data = json_decode($json);
 | 
			
		||||
				if (!$data) {
 | 
			
		||||
					Logger::logError('Json parse error: ' . $json);
 | 
			
		||||
					$this->maniaControl->getChat()->sendError('Json parse error: ' . $json, $player);
 | 
			
		||||
					$this->logError('Json parse error: ' . $json);
 | 
			
		||||
					$this->maniaControl->getChat()->sendError($this->MatchManagerCore->getChatPrefix() .'Json parse error: ' . $json, $player);
 | 
			
		||||
					return;
 | 
			
		||||
				}
 | 
			
		||||
				if (property_exists($data, "error")) {
 | 
			
		||||
					Logger::logError('Request error: ' . $data->error->code . " ". $data->error->message);
 | 
			
		||||
					$this->maniaControl->getChat()->sendErrorToAdmins('Request error: ' . $data->error->code . " ". $data->error->message);
 | 
			
		||||
					$this->logError('Request error: ' . $data->error->code . " ". $data->error->message);
 | 
			
		||||
					$this->maniaControl->getChat()->sendErrorToAdmins($this->MatchManagerCore->getChatPrefix() .'Request error: ' . $data->error->code . " ". $data->error->message);
 | 
			
		||||
					return;
 | 
			
		||||
				}
 | 
			
		||||
 | 
			
		||||
				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 {
 | 
			
		||||
					$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);
 | 
			
		||||
		} 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->setCallable(function ($json, $error) use ($sheetname, $spreadsheetid, $currentscore, $currentteamsscore, $matchstatus, $nbmaps, $nbrounds) {
 | 
			
		||||
				if (!$json || $error) {
 | 
			
		||||
					Logger::logError('Error from Google API: ' . $error);
 | 
			
		||||
					$this->maniaControl->getChat()->sendErrorToAdmins('Error from Google API: ' . $error);
 | 
			
		||||
					$this->logError('Error from Google API: ' . $error);
 | 
			
		||||
					$this->maniaControl->getChat()->sendErrorToAdmins($this->MatchManagerCore->getChatPrefix() .'Error from Google API: ' . $error);
 | 
			
		||||
					return;
 | 
			
		||||
				}
 | 
			
		||||
				$data = json_decode($json);
 | 
			
		||||
				if (!$data) {
 | 
			
		||||
					Logger::logError('Json parse error: ' . $json);
 | 
			
		||||
					$this->maniaControl->getChat()->sendErrorToAdmins('Json parse error: ' . $json);
 | 
			
		||||
					$this->logError('Json parse error: ' . $json);
 | 
			
		||||
					$this->maniaControl->getChat()->sendErrorToAdmins($this->MatchManagerCore->getChatPrefix() .'Json parse error: ' . $json);
 | 
			
		||||
					return;
 | 
			
		||||
				}
 | 
			
		||||
				if (property_exists($data, "error")) {
 | 
			
		||||
					Logger::logError('Request error: ' . $data->error->code . " ". $data->error->message);
 | 
			
		||||
					$this->maniaControl->getChat()->sendErrorToAdmins('Request error: ' . $data->error->code . " ". $data->error->message);
 | 
			
		||||
					$this->logError('Request error: ' . $data->error->code . " ". $data->error->message);
 | 
			
		||||
					$this->maniaControl->getChat()->sendErrorToAdmins($this->MatchManagerCore->getChatPrefix() .'Request error: ' . $data->error->code . " ". $data->error->message);
 | 
			
		||||
					return;
 | 
			
		||||
				}
 | 
			
		||||
 | 
			
		||||
@@ -665,19 +686,19 @@ class MatchManagerGSheet implements  CallbackListener, TimerListener, CommandLis
 | 
			
		||||
					$asyncHttpRequest->setContent(json_encode($data));
 | 
			
		||||
					$asyncHttpRequest->setCallable(function ($json, $error) use ($sheetname, $spreadsheetid, $currentteamsscore, $nbmaps, $nbrounds) {
 | 
			
		||||
						if (!$json || $error) {
 | 
			
		||||
							Logger::logError('Error from Google API: ' . $error);
 | 
			
		||||
							$this->maniaControl->getChat()->sendErrorToAdmins('Error from Google API: ' . $error);
 | 
			
		||||
							$this->logError('Error from Google API: ' . $error);
 | 
			
		||||
							$this->maniaControl->getChat()->sendErrorToAdmins($this->MatchManagerCore->getChatPrefix() .'Error from Google API: ' . $error);
 | 
			
		||||
							return;
 | 
			
		||||
						}
 | 
			
		||||
						$data = json_decode($json);
 | 
			
		||||
						if (!$data) {
 | 
			
		||||
							Logger::logError('Json parse error: ' . $json);
 | 
			
		||||
							$this->maniaControl->getChat()->sendErrorToAdmins('Json parse error: ' . $json);
 | 
			
		||||
							$this->logError('Json parse error: ' . $json);
 | 
			
		||||
							$this->maniaControl->getChat()->sendErrorToAdmins($this->MatchManagerCore->getChatPrefix() .'Json parse error: ' . $json);
 | 
			
		||||
							return;
 | 
			
		||||
						}
 | 
			
		||||
						if (property_exists($data, "error")) {
 | 
			
		||||
							Logger::logError('Request error: ' . $data->error->code . " ". $data->error->message);
 | 
			
		||||
							$this->maniaControl->getChat()->sendErrorToAdmins('Request error: ' . $data->error->code . " ". $data->error->message);
 | 
			
		||||
							$this->logError('Request error: ' . $data->error->code . " ". $data->error->message);
 | 
			
		||||
							$this->maniaControl->getChat()->sendErrorToAdmins($this->MatchManagerCore->getChatPrefix() .'Request error: ' . $data->error->code . " ". $data->error->message);
 | 
			
		||||
							return;
 | 
			
		||||
						}
 | 
			
		||||
 | 
			
		||||
@@ -698,19 +719,19 @@ class MatchManagerGSheet implements  CallbackListener, TimerListener, CommandLis
 | 
			
		||||
							$asyncHttpRequest->setContent(json_encode($data));
 | 
			
		||||
							$asyncHttpRequest->setCallable(function ($json, $error) {
 | 
			
		||||
								if (!$json || $error) {
 | 
			
		||||
									Logger::logError('Error from Google API: ' . $error);
 | 
			
		||||
									$this->maniaControl->getChat()->sendErrorToAdmins('Error from Google API: ' . $error);
 | 
			
		||||
									$this->logError('Error from Google API: ' . $error);
 | 
			
		||||
									$this->maniaControl->getChat()->sendErrorToAdmins($this->MatchManagerCore->getChatPrefix() .'Error from Google API: ' . $error);
 | 
			
		||||
									return;
 | 
			
		||||
								}
 | 
			
		||||
								$data = json_decode($json);
 | 
			
		||||
								if (!$data) {
 | 
			
		||||
									Logger::logError('Json parse error: ' . $json);
 | 
			
		||||
									$this->maniaControl->getChat()->sendErrorToAdmins('Json parse error: ' . $json);
 | 
			
		||||
									$this->logError('Json parse error: ' . $json);
 | 
			
		||||
									$this->maniaControl->getChat()->sendErrorToAdmins($this->MatchManagerCore->getChatPrefix() .'Json parse error: ' . $json);
 | 
			
		||||
									return;
 | 
			
		||||
								}
 | 
			
		||||
								if (property_exists($data, "error")) {
 | 
			
		||||
									Logger::logError('Request error: ' . $data->error->code . " ". $data->error->message);
 | 
			
		||||
									$this->maniaControl->getChat()->sendErrorToAdmins('Request error: ' . $data->error->code . " ". $data->error->message);
 | 
			
		||||
									$this->logError('Request error: ' . $data->error->code . " ". $data->error->message);
 | 
			
		||||
									$this->maniaControl->getChat()->sendErrorToAdmins($this->MatchManagerCore->getChatPrefix() .'Request error: ' . $data->error->code . " ". $data->error->message);
 | 
			
		||||
									return;
 | 
			
		||||
								}
 | 
			
		||||
							});
 | 
			
		||||
@@ -722,17 +743,17 @@ class MatchManagerGSheet implements  CallbackListener, TimerListener, CommandLis
 | 
			
		||||
			});	
 | 
			
		||||
			$asyncHttpRequest->postData(1000);
 | 
			
		||||
		} 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) {
 | 
			
		||||
		Logger::Log('onCallbackEndRound');
 | 
			
		||||
		$this->Log('onCallbackEndRound');
 | 
			
		||||
		$this->matchstatus = "running";
 | 
			
		||||
		$this->UpdateGSheetData($matchid, $currentscore, $currentteamsscore);
 | 
			
		||||
	}
 | 
			
		||||
	function onCallbackEndMatch(String $matchid, Array $currentscore, Array $currentteamsscore) {
 | 
			
		||||
		Logger::Log('onCallbackEndMatch');
 | 
			
		||||
		$this->Log('onCallbackEndMatch');
 | 
			
		||||
		$this->matchstatus = "ended";
 | 
			
		||||
 | 
			
		||||
		$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
 | 
			
		||||
	}
 | 
			
		||||
	function onCallbackStopMatch(String $matchid, Array $currentscore, Array $currentteamsscore) {
 | 
			
		||||
		Logger::Log('onCallbackStopMatch');
 | 
			
		||||
		$this->Log('onCallbackStopMatch');
 | 
			
		||||
		$this->matchstatus = "stopped";
 | 
			
		||||
		$this->UpdateGSheetData($matchid, $currentscore, $currentteamsscore);
 | 
			
		||||
	}
 | 
			
		||||
@@ -759,19 +780,19 @@ class MatchManagerGSheet implements  CallbackListener, TimerListener, CommandLis
 | 
			
		||||
			$asyncHttpRequest->setHeaders(array("Authorization: Bearer " . $this->access_token));
 | 
			
		||||
			$asyncHttpRequest->setCallable(function ($json, $error) use ($sheetname) {
 | 
			
		||||
				if (!$json || $error) {
 | 
			
		||||
					Logger::logError('Error from Google API: ' . $error);
 | 
			
		||||
					$this->maniaControl->getChat()->sendErrorToAdmins('Error from Google API: ' . $error);
 | 
			
		||||
					$this->logError('Error from Google API: ' . $error);
 | 
			
		||||
					$this->maniaControl->getChat()->sendErrorToAdmins($this->MatchManagerCore->getChatPrefix() .'Error from Google API: ' . $error);
 | 
			
		||||
					return;
 | 
			
		||||
				}
 | 
			
		||||
				$data = json_decode($json);
 | 
			
		||||
				if (!$data) {
 | 
			
		||||
					Logger::logError('Json parse error: ' . $json);
 | 
			
		||||
					$this->maniaControl->getChat()->sendErrorToAdmins('Json parse error: ' . $json);
 | 
			
		||||
					$this->logError('Json parse error: ' . $json);
 | 
			
		||||
					$this->maniaControl->getChat()->sendErrorToAdmins($this->MatchManagerCore->getChatPrefix() .'Json parse error: ' . $json);
 | 
			
		||||
					return;
 | 
			
		||||
				}
 | 
			
		||||
				if (property_exists($data, "error")) {
 | 
			
		||||
					Logger::logError('Request error: ' . $data->error->code . " ". $data->error->message);
 | 
			
		||||
					$this->maniaControl->getChat()->sendErrorToAdmins('Request error: ' . $data->error->code . " ". $data->error->message);
 | 
			
		||||
					$this->logError('Request error: ' . $data->error->code . " ". $data->error->message);
 | 
			
		||||
					$this->maniaControl->getChat()->sendErrorToAdmins($this->MatchManagerCore->getChatPrefix() .'Request error: ' . $data->error->code . " ". $data->error->message);
 | 
			
		||||
					return;
 | 
			
		||||
				}
 | 
			
		||||
 | 
			
		||||
@@ -812,7 +833,7 @@ class MatchManagerGSheet implements  CallbackListener, TimerListener, CommandLis
 | 
			
		||||
			$i = 0;
 | 
			
		||||
 | 
			
		||||
			if (!$sheetexists) {
 | 
			
		||||
				Logger::Log("Creating new Sheet: " . $sheetname);
 | 
			
		||||
				$this->Log("Creating new Sheet: " . $sheetname);
 | 
			
		||||
				$sheetid = rand(1000,2147483646);
 | 
			
		||||
				while (in_array($sheetid, $sheetsid)) {
 | 
			
		||||
					$sheetid = rand(1000,2147483646);
 | 
			
		||||
@@ -907,19 +928,19 @@ class MatchManagerGSheet implements  CallbackListener, TimerListener, CommandLis
 | 
			
		||||
			$asyncHttpRequest->setContent(json_encode($data));
 | 
			
		||||
			$asyncHttpRequest->setCallable(function ($json, $error) use ($sheetname, $spreadsheetid) {
 | 
			
		||||
				if (!$json || $error) {
 | 
			
		||||
					Logger::logError('Error from Google API: ' . $error);
 | 
			
		||||
					$this->maniaControl->getChat()->sendErrorToAdmins('Error from Google API: ' . $error);
 | 
			
		||||
					$this->logError('Error from Google API: ' . $error);
 | 
			
		||||
					$this->maniaControl->getChat()->sendErrorToAdmins($this->MatchManagerCore->getChatPrefix() .'Error from Google API: ' . $error);
 | 
			
		||||
					return;
 | 
			
		||||
				}
 | 
			
		||||
				$data = json_decode($json);
 | 
			
		||||
				if (!$data) {
 | 
			
		||||
					Logger::logError('Json parse error: ' . $json);
 | 
			
		||||
					$this->maniaControl->getChat()->sendErrorToAdmins('Json parse error: ' . $json);
 | 
			
		||||
					$this->logError('Json parse error: ' . $json);
 | 
			
		||||
					$this->maniaControl->getChat()->sendErrorToAdmins($this->MatchManagerCore->getChatPrefix() .'Json parse error: ' . $json);
 | 
			
		||||
					return;
 | 
			
		||||
				}
 | 
			
		||||
				if (property_exists($data, "error")) {
 | 
			
		||||
					Logger::logError('Request error: ' . $data->error->code . " ". $data->error->message);
 | 
			
		||||
					$this->maniaControl->getChat()->sendErrorToAdmins('Request error: ' . $data->error->code . " ". $data->error->message);
 | 
			
		||||
					$this->logError('Request error: ' . $data->error->code . " ". $data->error->message);
 | 
			
		||||
					$this->maniaControl->getChat()->sendErrorToAdmins($this->MatchManagerCore->getChatPrefix() .'Request error: ' . $data->error->code . " ". $data->error->message);
 | 
			
		||||
					return;
 | 
			
		||||
				}
 | 
			
		||||
 | 
			
		||||
@@ -928,19 +949,19 @@ class MatchManagerGSheet implements  CallbackListener, TimerListener, CommandLis
 | 
			
		||||
				$asyncHttpRequest->setHeaders(array("Authorization: Bearer " . $this->access_token));
 | 
			
		||||
				$asyncHttpRequest->setCallable(function ($json, $error) use ($sheetname, $spreadsheetid) {
 | 
			
		||||
					if (!$json || $error) {
 | 
			
		||||
						Logger::logError('Error from Google API: ' . $error);
 | 
			
		||||
						$this->maniaControl->getChat()->sendErrorToAdmins('Error from Google API: ' . $error);
 | 
			
		||||
						$this->logError('Error from Google API: ' . $error);
 | 
			
		||||
						$this->maniaControl->getChat()->sendErrorToAdmins($this->MatchManagerCore->getChatPrefix() .'Error from Google API: ' . $error);
 | 
			
		||||
						return;
 | 
			
		||||
					}
 | 
			
		||||
					$data = json_decode($json);
 | 
			
		||||
					if (!$data) {
 | 
			
		||||
						Logger::logError('Json parse error: ' . $json);
 | 
			
		||||
						$this->maniaControl->getChat()->sendErrorToAdmins('Json parse error: ' . $json);
 | 
			
		||||
						$this->logError('Json parse error: ' . $json);
 | 
			
		||||
						$this->maniaControl->getChat()->sendErrorToAdmins($this->MatchManagerCore->getChatPrefix() .'Json parse error: ' . $json);
 | 
			
		||||
						return;
 | 
			
		||||
					}
 | 
			
		||||
					if (property_exists($data, "error")) {
 | 
			
		||||
						Logger::logError('Request error: ' . $data->error->code . " ". $data->error->message);
 | 
			
		||||
						$this->maniaControl->getChat()->sendErrorToAdmins('Request error: ' . $data->error->code . " ". $data->error->message);
 | 
			
		||||
						$this->logError('Request error: ' . $data->error->code . " ". $data->error->message);
 | 
			
		||||
						$this->maniaControl->getChat()->sendErrorToAdmins($this->MatchManagerCore->getChatPrefix() .'Request error: ' . $data->error->code . " ". $data->error->message);
 | 
			
		||||
						return;
 | 
			
		||||
					}
 | 
			
		||||
 | 
			
		||||
@@ -966,19 +987,19 @@ class MatchManagerGSheet implements  CallbackListener, TimerListener, CommandLis
 | 
			
		||||
					$asyncHttpRequest->setContent(json_encode($data));
 | 
			
		||||
					$asyncHttpRequest->setCallable(function ($json, $error) {
 | 
			
		||||
						if (!$json || $error) {
 | 
			
		||||
							Logger::logError('Error from Google API: ' . $error);
 | 
			
		||||
							$this->maniaControl->getChat()->sendErrorToAdmins('Error from Google API: ' . $error);
 | 
			
		||||
							$this->logError('Error from Google API: ' . $error);
 | 
			
		||||
							$this->maniaControl->getChat()->sendErrorToAdmins($this->MatchManagerCore->getChatPrefix() .'Error from Google API: ' . $error);
 | 
			
		||||
							return;
 | 
			
		||||
						}
 | 
			
		||||
						$data = json_decode($json);
 | 
			
		||||
						if (!$data) {
 | 
			
		||||
							Logger::logError('Json parse error: ' . $json);
 | 
			
		||||
							$this->maniaControl->getChat()->sendErrorToAdmins('Json parse error: ' . $json);
 | 
			
		||||
							$this->logError('Json parse error: ' . $json);
 | 
			
		||||
							$this->maniaControl->getChat()->sendErrorToAdmins($this->MatchManagerCore->getChatPrefix() .'Json parse error: ' . $json);
 | 
			
		||||
							return;
 | 
			
		||||
						}
 | 
			
		||||
						if (property_exists($data, "error")) {
 | 
			
		||||
							Logger::logError('Request error: ' . $data->error->code . " ". $data->error->message);
 | 
			
		||||
							$this->maniaControl->getChat()->sendErrorToAdmins('Request error: ' . $data->error->code . " ". $data->error->message);
 | 
			
		||||
							$this->logError('Request error: ' . $data->error->code . " ". $data->error->message);
 | 
			
		||||
							$this->maniaControl->getChat()->sendErrorToAdmins('$this->MatchManagerCore->getChatPrefix() .Request error: ' . $data->error->code . " ". $data->error->message);
 | 
			
		||||
							return;
 | 
			
		||||
						}
 | 
			
		||||
					});
 | 
			
		||||
 
 | 
			
		||||
@@ -27,8 +27,8 @@ use ManiaControl\Commands\CommandListener;
 | 
			
		||||
use ManiaControl\Plugins\PluginMenu;
 | 
			
		||||
 | 
			
		||||
if (!class_exists('MatchManagerSuite\MatchManagerCore')) {
 | 
			
		||||
	$this->maniaControl->getChat()->sendErrorToAdmins('MatchManager Core is required to use one of MatchManager plugin. Install it and restart Maniacontrol');
 | 
			
		||||
	Logger::logError('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 MatchManagerMultipleConfigManager plugin. Install it and restart Maniacontrol');
 | 
			
		||||
	return false;
 | 
			
		||||
}
 | 
			
		||||
use MatchManagerSuite\MatchManagerCore;
 | 
			
		||||
@@ -48,6 +48,9 @@ class MatchManagerMultipleConfigManager implements ManialinkPageAnswerListener,
 | 
			
		||||
	const PLUGIN_NAME										= 'MatchManager Multiple Config Manager';
 | 
			
		||||
	const PLUGIN_AUTHOR										= 'Beu';
 | 
			
		||||
 | 
			
		||||
	const LOG_PREFIX										= '[MatchManagerMultipleConfigManager] ';
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
	// MatchManagerWidget Properties
 | 
			
		||||
	const MATCHMANAGERCORE_PLUGIN							= 'MatchManagerSuite\MatchManagerCore';
 | 
			
		||||
	const MATCHMANAGERADMINUI_PLUGIN						= 'MatchManagerSuite\MatchManagerAdminUI';
 | 
			
		||||
@@ -71,6 +74,7 @@ class MatchManagerMultipleConfigManager implements ManialinkPageAnswerListener,
 | 
			
		||||
	 */
 | 
			
		||||
	/** @var ManiaControl $maniaControl */
 | 
			
		||||
	private $maniaControl 			= null;
 | 
			
		||||
	/** @var MatchManagerCore $MatchManagerCore */
 | 
			
		||||
	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
 | 
			
		||||
	 * 
 | 
			
		||||
@@ -182,7 +204,8 @@ class MatchManagerMultipleConfigManager implements ManialinkPageAnswerListener,
 | 
			
		||||
	public function handlePluginUnloaded(string $pluginClass, Plugin $plugin) {
 | 
			
		||||
		if ($pluginClass == self::MATCHMANAGERCORE_PLUGIN) {
 | 
			
		||||
			$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;
 | 
			
		||||
			case self::ML_ACTION_REMOVE_CONFIG:
 | 
			
		||||
				$id = intval($actionArray[2]);
 | 
			
		||||
				Logger::log("[MatchManagerMultipleConfigManager] Removing config: " . $id);
 | 
			
		||||
				$this->log("Removing config: " . $id);
 | 
			
		||||
				$mysqli = $this->maniaControl->getDatabase()->getMysqli();
 | 
			
		||||
 | 
			
		||||
				$query = $mysqli->prepare('DELETE FROM  `'. self::DB_MATCHCONFIG .'` WHERE id = ?;');
 | 
			
		||||
@@ -288,8 +311,8 @@ class MatchManagerMultipleConfigManager implements ManialinkPageAnswerListener,
 | 
			
		||||
	 */
 | 
			
		||||
	public function loadConfig(int $id) {
 | 
			
		||||
		if ($this->MatchManagerCore->getMatchStatus()) {
 | 
			
		||||
			Logger::logError("Impossible to load config during a match");
 | 
			
		||||
			$this->maniaControl->getChat()->sendErrorToAdmins('Impossible to load config during a match');
 | 
			
		||||
			$this->logError("Impossible to load config during a match");
 | 
			
		||||
			$this->maniaControl->getChat()->sendErrorToAdmins($this->MatchManagerCore->getChatPrefix() .'Impossible to load config during a match');
 | 
			
		||||
			return;
 | 
			
		||||
		}
 | 
			
		||||
		$mysqli = $this->maniaControl->getDatabase()->getMysqli();
 | 
			
		||||
@@ -310,7 +333,7 @@ class MatchManagerMultipleConfigManager implements ManialinkPageAnswerListener,
 | 
			
		||||
		if ($result[0] && $result[0]["config"]) {
 | 
			
		||||
			$allconfigs = json_decode($result[0]["config"],true);
 | 
			
		||||
			if ($allconfigs != null) {
 | 
			
		||||
				Logger::log("[MatchManagerMultipleConfigManager] Loading config: " . $id);
 | 
			
		||||
				$this->log("Loading config: " . $id);
 | 
			
		||||
				$someconfignotloaded = false;
 | 
			
		||||
				foreach ($allconfigs as $plugin => $configs) {
 | 
			
		||||
					$pluginclass = $this->maniaControl->getPluginManager()->getPlugin($plugin);
 | 
			
		||||
@@ -321,22 +344,22 @@ class MatchManagerMultipleConfigManager implements ManialinkPageAnswerListener,
 | 
			
		||||
							$setting = $this->maniaControl->getSettingManager()->getSettingObject($pluginclass, $name);
 | 
			
		||||
							if ($setting != null) {
 | 
			
		||||
								if ($setting->value != $value) {
 | 
			
		||||
									Logger::log("Saving new setting " . $name);
 | 
			
		||||
									$this->log("Saving new setting " . $name);
 | 
			
		||||
									$setting->value = $value;
 | 
			
		||||
									$this->maniaControl->getSettingManager()->saveSetting($setting);
 | 
			
		||||
								}
 | 
			
		||||
							} else {
 | 
			
		||||
								$someconfignotloaded = true;
 | 
			
		||||
								Logger::log("Unable to load setting: " . $name);
 | 
			
		||||
								$this->log("Unable to load setting: " . $name);
 | 
			
		||||
							}
 | 
			
		||||
						}
 | 
			
		||||
					}
 | 
			
		||||
				}
 | 
			
		||||
				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->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
 | 
			
		||||
	 */
 | 
			
		||||
	public function saveCurrentConfig(array $fields) {
 | 
			
		||||
		Logger::log("[MatchManagerMultipleConfigManager] Saving current config");
 | 
			
		||||
		$this->log("Saving current config");
 | 
			
		||||
		$result = array();
 | 
			
		||||
		$configname = "";
 | 
			
		||||
		$gamemodebase = "";
 | 
			
		||||
 
 | 
			
		||||
@@ -21,8 +21,8 @@ use ManiaControl\Commands\CommandListener;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
if (!class_exists('MatchManagerSuite\MatchManagerCore')) {
 | 
			
		||||
	$this->maniaControl->getChat()->sendErrorToAdmins('MatchManager Core is required to use one of MatchManager plugin. Install it and restart Maniacontrol');
 | 
			
		||||
	Logger::logError('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 MatchManagerPlayersPause plugin. Install it and restart Maniacontrol');
 | 
			
		||||
	return false;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -42,6 +42,8 @@ class MatchManagerPlayersPause implements ManialinkPageAnswerListener, CommandLi
 | 
			
		||||
	const PLUGIN_NAME										= 'MatchManager Players Pause';
 | 
			
		||||
	const PLUGIN_AUTHOR										= 'Beu';
 | 
			
		||||
 | 
			
		||||
	const LOG_PREFIX										= '[MatchManagerPlayersPause] ';
 | 
			
		||||
 | 
			
		||||
	// MatchManagerWidget Properties
 | 
			
		||||
	const MATCHMANAGERCORE_PLUGIN							= 'MatchManagerSuite\MatchManagerCore';
 | 
			
		||||
 | 
			
		||||
@@ -58,6 +60,7 @@ class MatchManagerPlayersPause implements ManialinkPageAnswerListener, CommandLi
 | 
			
		||||
	 */
 | 
			
		||||
	/** @var ManiaControl $maniaControl */
 | 
			
		||||
	private $maniaControl 			= null;
 | 
			
		||||
	/** @var MatchManagerCore $MatchManagerCore */
 | 
			
		||||
	private $MatchManagerCore		= null;
 | 
			
		||||
 | 
			
		||||
	private $playerspausestate		= array();
 | 
			
		||||
@@ -160,6 +163,24 @@ class MatchManagerPlayersPause implements ManialinkPageAnswerListener, CommandLi
 | 
			
		||||
		$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
 | 
			
		||||
	 *
 | 
			
		||||
@@ -170,7 +191,8 @@ class MatchManagerPlayersPause implements ManialinkPageAnswerListener, CommandLi
 | 
			
		||||
	public function handlePluginUnloaded(string $pluginClass, Plugin $plugin) {
 | 
			
		||||
		if ($pluginClass == self::MATCHMANAGERCORE_PLUGIN) {
 | 
			
		||||
			$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)) {
 | 
			
		||||
					$this->playerspausestate = array();
 | 
			
		||||
					$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->maniaControl, MatchManagerCore::SETTING_MATCH_PAUSE_DURATION) <= 0) {
 | 
			
		||||
							$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;
 | 
			
		||||
 | 
			
		||||
if (!class_exists('MatchManagerSuite\MatchManagerCore')) {
 | 
			
		||||
	$this->maniaControl->getChat()->sendErrorToAdmins('MatchManager Core is required to use one of MatchManager plugin. Install it and restart Maniacontrol');
 | 
			
		||||
	Logger::logError('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 MatchManagerReadyButton plugin. Install it and restart Maniacontrol');
 | 
			
		||||
	return false;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -41,6 +41,8 @@ class MatchManagerReadyButton implements ManialinkPageAnswerListener, CommandLis
 | 
			
		||||
	const PLUGIN_NAME										= 'MatchManager Ready Button';
 | 
			
		||||
	const PLUGIN_AUTHOR										= 'Beu';
 | 
			
		||||
 | 
			
		||||
	const LOG_PREFIX										= '[MatchManagerReadyButton] ';
 | 
			
		||||
 | 
			
		||||
	// MatchManagerWidget Properties
 | 
			
		||||
	const MATCHMANAGERCORE_PLUGIN							= 'MatchManagerSuite\MatchManagerCore';
 | 
			
		||||
 | 
			
		||||
@@ -57,6 +59,7 @@ class MatchManagerReadyButton implements ManialinkPageAnswerListener, CommandLis
 | 
			
		||||
	 */
 | 
			
		||||
	/** @var ManiaControl $maniaControl */
 | 
			
		||||
	private $maniaControl 			= null;
 | 
			
		||||
	/** @var MatchManagerCore $MatchManagerCore */
 | 
			
		||||
	private $MatchManagerCore		= null;
 | 
			
		||||
 | 
			
		||||
	private $playersreadystate		= array();
 | 
			
		||||
@@ -154,6 +157,24 @@ class MatchManagerReadyButton implements ManialinkPageAnswerListener, CommandLis
 | 
			
		||||
		$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
 | 
			
		||||
	 *
 | 
			
		||||
@@ -164,7 +185,7 @@ class MatchManagerReadyButton implements ManialinkPageAnswerListener, CommandLis
 | 
			
		||||
	public function handlePluginUnloaded(string $pluginClass, Plugin $plugin) {
 | 
			
		||||
		if ($pluginClass == self::MATCHMANAGERCORE_PLUGIN) {
 | 
			
		||||
			$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)) {
 | 
			
		||||
					$this->playersreadystate = array();
 | 
			
		||||
					$this->closeReadyWidget();
 | 
			
		||||
					Logger::log('Start Match via Ready Button');
 | 
			
		||||
					$this->log('Start Match via Ready Button');
 | 
			
		||||
					$this->MatchManagerCore->MatchStart();
 | 
			
		||||
					return;
 | 
			
		||||
				}
 | 
			
		||||
 
 | 
			
		||||
@@ -19,8 +19,8 @@ use ManiaControl\Utils\WebReader;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
if (!class_exists('MatchManagerSuite\MatchManagerCore')) {
 | 
			
		||||
	$this->maniaControl->getChat()->sendErrorToAdmins('MatchManager Core is required to use one of MatchManager plugin. Install it and restart Maniacontrol');
 | 
			
		||||
	Logger::logError('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 MatchManagerTMWTDuoIntegration plugin. Install it and restart Maniacontrol');
 | 
			
		||||
	return false;
 | 
			
		||||
}
 | 
			
		||||
use MatchManagerSuite\MatchManagerCore;
 | 
			
		||||
@@ -37,10 +37,12 @@ class MatchManagerTMWTDuoIntegration implements CallbackListener, ManialinkPageA
 | 
			
		||||
	 * Constants
 | 
			
		||||
	 */
 | 
			
		||||
	const PLUGIN_ID											= 211;
 | 
			
		||||
	const PLUGIN_VERSION									= 1.0;
 | 
			
		||||
	const PLUGIN_VERSION									= 1.1;
 | 
			
		||||
	const PLUGIN_NAME										= 'MatchManager TMWT Duo Integration';
 | 
			
		||||
	const PLUGIN_AUTHOR										= 'Beu';
 | 
			
		||||
 | 
			
		||||
	const LOG_PREFIX										= '[MatchManagerTMWTDuoIntegration] ';
 | 
			
		||||
 | 
			
		||||
	// Other MatchManager plugin
 | 
			
		||||
	const MATCHMANAGERCORE_PLUGIN							= 'MatchManagerSuite\MatchManagerCore';
 | 
			
		||||
	const MATCHMANAGERADMINUI_PLUGIN						= 'MatchManagerSuite\MatchManagerAdminUI';
 | 
			
		||||
@@ -62,6 +64,7 @@ class MatchManagerTMWTDuoIntegration implements CallbackListener, ManialinkPageA
 | 
			
		||||
	const SETTING_PICKANDBAN_ENABLE 						= 'Enable Pick & Ban';
 | 
			
		||||
	const SETTING_PICKANDBAN_STEPCONFIG 					= 'Pick & Ban: Step config';
 | 
			
		||||
	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 STATE_NOTHING = 0;
 | 
			
		||||
@@ -74,6 +77,7 @@ class MatchManagerTMWTDuoIntegration implements CallbackListener, ManialinkPageA
 | 
			
		||||
	 */
 | 
			
		||||
	/** @var ManiaControl $maniaControl */
 | 
			
		||||
	private $maniaControl 			= null;
 | 
			
		||||
	/** @var MatchManagerCore $MatchManagerCore */
 | 
			
		||||
	private $MatchManagerCore		= null;
 | 
			
		||||
	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_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_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
 | 
			
		||||
		$this->maniaControl->getManialinkManager()->registerManialinkPageAnswerListener(self::ML_ACTION_OPENSETTINGS, $this, 'handleActionOpenSettings');
 | 
			
		||||
@@ -157,6 +162,24 @@ class MatchManagerTMWTDuoIntegration implements CallbackListener, ManialinkPageA
 | 
			
		||||
		$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
 | 
			
		||||
	 * 
 | 
			
		||||
@@ -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->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;
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
@@ -254,8 +277,8 @@ class MatchManagerTMWTDuoIntegration implements CallbackListener, ManialinkPageA
 | 
			
		||||
		if ($setting !== null && !$setting->value) {
 | 
			
		||||
			$setting->value = true;
 | 
			
		||||
			$this->maniaControl->getSettingManager()->saveSetting($setting);
 | 
			
		||||
			Logger::logWarning('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->logError('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)) {
 | 
			
		||||
@@ -263,8 +286,8 @@ class MatchManagerTMWTDuoIntegration implements CallbackListener, ManialinkPageA
 | 
			
		||||
			if ($setting !== null && !$setting->value) {
 | 
			
		||||
				$setting->value = true;
 | 
			
		||||
				$this->maniaControl->getSettingManager()->saveSetting($setting);
 | 
			
		||||
				Logger::logWarning('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->logError('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) {
 | 
			
		||||
							$team1 = null;
 | 
			
		||||
							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);
 | 
			
		||||
							}
 | 
			
		||||
						}
 | 
			
		||||
						if ($team->Id === $team2) {
 | 
			
		||||
							$team2 = null;
 | 
			
		||||
							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);
 | 
			
		||||
							}
 | 
			
		||||
						}
 | 
			
		||||
@@ -333,8 +356,8 @@ class MatchManagerTMWTDuoIntegration implements CallbackListener, ManialinkPageA
 | 
			
		||||
					}
 | 
			
		||||
 | 
			
		||||
					if ($this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_PICKANDBAN_ENABLE)) {
 | 
			
		||||
						Logger::log('Starting Pick & ban in 10 seconds');
 | 
			
		||||
						$this->maniaControl->getChat()->sendSuccess('Starting pick & ban in 10 seconds');
 | 
			
		||||
						$this->log('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 () {
 | 
			
		||||
						$payload = [
 | 
			
		||||
							'stepDuration' => $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_PICKANDBAN_STEPDURATION),
 | 
			
		||||
@@ -364,12 +387,12 @@ class MatchManagerTMWTDuoIntegration implements CallbackListener, ManialinkPageA
 | 
			
		||||
 | 
			
		||||
						$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);
 | 
			
		||||
						}, 5000);
 | 
			
		||||
					} else {
 | 
			
		||||
						$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);
 | 
			
		||||
					}
 | 
			
		||||
				}
 | 
			
		||||
@@ -385,13 +408,30 @@ class MatchManagerTMWTDuoIntegration implements CallbackListener, ManialinkPageA
 | 
			
		||||
	 */
 | 
			
		||||
	public function handlePickAndBanComplete(array $structure) {
 | 
			
		||||
		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) {
 | 
			
		||||
			try {
 | 
			
		||||
				$json = json_decode($structure[1][0]);
 | 
			
		||||
	
 | 
			
		||||
				$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 = [];
 | 
			
		||||
				foreach ($this->maniaControl->getMapManager()->getMaps() as $map) {
 | 
			
		||||
					$index = array_search($map->uid, $mapUids);
 | 
			
		||||
@@ -404,19 +444,19 @@ class MatchManagerTMWTDuoIntegration implements CallbackListener, ManialinkPageA
 | 
			
		||||
				}
 | 
			
		||||
	
 | 
			
		||||
				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);
 | 
			
		||||
 | 
			
		||||
				$this->maniaControl->getClient()->chooseNextMapList(array_values($mapList));
 | 
			
		||||
			} catch (\Throwable $th) {
 | 
			
		||||
				Logger::logError("Can't apply map list: ". $th->getMessage());
 | 
			
		||||
				$this->maniaControl->getChat()->sendError("Can't apply map list: ". $th->getMessage());
 | 
			
		||||
				$this->logError("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;
 | 
			
		||||
			Logger::log('Sending match start callback');
 | 
			
		||||
			$this->log('Sending match start callback');
 | 
			
		||||
			$this->maniaControl->getClient()->triggerModeScriptEvent(self::XMLRPC_METHOD_MATCHSTARTED, [], true);
 | 
			
		||||
			$this->maniaControl->getMapManager()->getMapActions()->skipMap();
 | 
			
		||||
		}, $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) {
 | 
			
		||||
		if ($pluginClass == self::MATCHMANAGERCORE_PLUGIN) {
 | 
			
		||||
			$this->maniaControl->getChat()->sendErrorToAdmins(self::PLUGIN_NAME . " disabled because MatchManager Core is now disabled");
 | 
			
		||||
			$this->maniaControl->getPluginManager()->deactivatePlugin((get_class()));
 | 
			
		||||
			$this->maniaControl->getChat()->sendErrorToAdmins($this->MatchManagerCore->getChatPrefix() .self::PLUGIN_NAME . " disabled because MatchManager Core is now disabled");
 | 
			
		||||
			$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 ($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") {
 | 
			
		||||
					$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()
 | 
			
		||||
	 */
 | 
			
		||||
	public function unload() {
 | 
			
		||||
		$this->MatchManagerCore->removeCanStartFunction($this, 'canStartMatch'); 
 | 
			
		||||
		if ($this->MatchManagerCore !== null) $this->MatchManagerCore->removeCanStartFunction($this, 'canStartMatch'); 
 | 
			
		||||
		/** @var \MatchManagerSuite\MatchManagerAdminUI|null */
 | 
			
		||||
		$adminUIPlugin = $this->maniaControl->getPluginManager()->getPlugin(self::MATCHMANAGERADMINUI_PLUGIN);
 | 
			
		||||
		if ($adminUIPlugin !== null) {
 | 
			
		||||
 
 | 
			
		||||
@@ -20,8 +20,8 @@ use ManiaControl\Settings\Setting;
 | 
			
		||||
use ManiaControl\Settings\SettingManager;
 | 
			
		||||
 | 
			
		||||
if (!class_exists('MatchManagerSuite\MatchManagerCore')) {
 | 
			
		||||
	$this->maniaControl->getChat()->sendErrorToAdmins('MatchManager Core is required to use one of MatchManager plugin. Install it and restart Maniacontrol');
 | 
			
		||||
	Logger::logError('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');
 | 
			
		||||
	$this->logError('MatchManager Core is required to use MatchManagerWidget plugin. Install it and restart Maniacontrol');
 | 
			
		||||
	return false;
 | 
			
		||||
}
 | 
			
		||||
use MatchManagerSuite\MatchManagerCore;
 | 
			
		||||
@@ -42,6 +42,8 @@ class MatchManagerWidget implements ManialinkPageAnswerListener, CallbackListene
 | 
			
		||||
	const PLUGIN_NAME										= 'MatchManager Widget';
 | 
			
		||||
	const PLUGIN_AUTHOR										= 'Beu';
 | 
			
		||||
 | 
			
		||||
	const LOG_PREFIX										= '[MatchManagerWidget] ';
 | 
			
		||||
 | 
			
		||||
	// MatchManagerWidget Properties
 | 
			
		||||
	const MATCHMANAGERWIDGET_COMPATIBLE_GM					= ["Cup", "Teams", "Rounds"];
 | 
			
		||||
	const MATCHMANAGERCORE_PLUGIN							= 'MatchManagerSuite\MatchManagerCore';
 | 
			
		||||
@@ -64,6 +66,7 @@ class MatchManagerWidget implements ManialinkPageAnswerListener, CallbackListene
 | 
			
		||||
	 */
 | 
			
		||||
	/** @var ManiaControl $maniaControl */
 | 
			
		||||
	private $maniaControl 			= null;
 | 
			
		||||
	/** @var MatchManagerCore $MatchManagerCore */
 | 
			
		||||
	private $MatchManagerCore		= null;
 | 
			
		||||
	private $gmbase					= "";
 | 
			
		||||
	private $manialinkData			= null;
 | 
			
		||||
@@ -171,6 +174,24 @@ class MatchManagerWidget implements ManialinkPageAnswerListener, CallbackListene
 | 
			
		||||
		$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
 | 
			
		||||
	 *
 | 
			
		||||
@@ -181,7 +202,7 @@ class MatchManagerWidget implements ManialinkPageAnswerListener, CallbackListene
 | 
			
		||||
	public function handlePluginUnloaded(string $pluginClass, Plugin $plugin) {
 | 
			
		||||
		if ($pluginClass == self::MATCHMANAGERCORE_PLUGIN) {
 | 
			
		||||
			$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
 | 
			
		||||
	 */
 | 
			
		||||
	public function InitMatch(string $matchid, array $settings) {
 | 
			
		||||
		Logger::Log("InitMatch");
 | 
			
		||||
		$this->log("InitMatch");
 | 
			
		||||
		$this->gmbase = $settings['currentgmbase'];
 | 
			
		||||
		$this->displayManialinks(false);
 | 
			
		||||
	}
 | 
			
		||||
@@ -224,7 +245,7 @@ class MatchManagerWidget implements ManialinkPageAnswerListener, CallbackListene
 | 
			
		||||
	 * Clear variables and hide widget
 | 
			
		||||
	 */
 | 
			
		||||
	public function ClearMatch() {
 | 
			
		||||
		Logger::Log("ClearMatch");
 | 
			
		||||
		$this->log("ClearMatch");
 | 
			
		||||
		$this->gmbase = "";
 | 
			
		||||
		$this->manialinkData = "";
 | 
			
		||||
		$this->closeWidgets();
 | 
			
		||||
@@ -295,7 +316,7 @@ class MatchManagerWidget implements ManialinkPageAnswerListener, CallbackListene
 | 
			
		||||
	 * @param Player $player
 | 
			
		||||
	 */
 | 
			
		||||
	public function handlePlayerConnect(Player $player) {
 | 
			
		||||
		Logger::Log("handlePlayerConnect");
 | 
			
		||||
		$this->log("handlePlayerConnect");
 | 
			
		||||
 | 
			
		||||
		if (strlen($this->gmbase) > 0) {
 | 
			
		||||
			$this->displayManialinks($player->login);
 | 
			
		||||
@@ -405,7 +426,7 @@ class MatchManagerWidget implements ManialinkPageAnswerListener, CallbackListene
 | 
			
		||||
	 * Generate the manilink of the background of the widget
 | 
			
		||||
	 */
 | 
			
		||||
	public function generateMatchLiveWidgetBackground() {
 | 
			
		||||
		Logger::Log("generateMatchLiveWidgetBackground");
 | 
			
		||||
		$this->log("generateMatchLiveWidgetBackground");
 | 
			
		||||
 | 
			
		||||
		$posX       = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MATCHMANAGERWIDGET_LIVE_POSX);
 | 
			
		||||
		$posY       = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MATCHMANAGERWIDGET_LIVE_POSY);
 | 
			
		||||
@@ -448,7 +469,7 @@ class MatchManagerWidget implements ManialinkPageAnswerListener, CallbackListene
 | 
			
		||||
	 * @param array $currentscore
 | 
			
		||||
	 */
 | 
			
		||||
	public function generateMatchLiveWidgetData(array $currentscore) {
 | 
			
		||||
		Logger::Log("generateMatchLiveWidgetData");
 | 
			
		||||
		$this->log("generateMatchLiveWidgetData");
 | 
			
		||||
 | 
			
		||||
		if ($this->gmbase == "Cup") {
 | 
			
		||||
			$pointlimit = $this->MatchManagerCore->getMatchPointsLimit();
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user