rework score storage
This commit is contained in:
		@@ -341,6 +341,7 @@ class MatchManagerCore implements CallbackListener, CommandListener, TimerListen
 | 
				
			|||||||
	private $scriptSettings			= array();
 | 
						private $scriptSettings			= array();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	private $currentscore			= array();
 | 
						private $currentscore			= array();
 | 
				
			||||||
 | 
						private $preendroundscore		= array();
 | 
				
			||||||
	private $currentteamsscore		= array();
 | 
						private $currentteamsscore		= array();
 | 
				
			||||||
	private $playerpause			= array();
 | 
						private $playerpause			= array();
 | 
				
			||||||
	private $pausetimer				= 0;
 | 
						private $pausetimer				= 0;
 | 
				
			||||||
@@ -407,6 +408,8 @@ class MatchManagerCore implements CallbackListener, CommandListener, TimerListen
 | 
				
			|||||||
		$this->initTables();
 | 
							$this->initTables();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		$this->maniaControl->getChat()->sendErrorToAdmins($this->chatprefix . "This new version has a lot of code refactoring, please contact me if you encounter any bug via discord @Beu#1337 or Twitter @AmazingBeu");
 | 
							$this->maniaControl->getChat()->sendErrorToAdmins($this->chatprefix . "This new version has a lot of code refactoring, please contact me if you encounter any bug via discord @Beu#1337 or Twitter @AmazingBeu");
 | 
				
			||||||
 | 
							$this->maniaControl->getChat()->sendErrorToAdmins($this->chatprefix . "If you retrieve data from this plugin (via gsheet or others), be careful, the data format has changed");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		//Settings
 | 
							//Settings
 | 
				
			||||||
		$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_MATCH_AUTHLEVEL, AuthenticationManager::getPermissionLevelNameArray(AuthenticationManager::AUTH_LEVEL_ADMIN), "Admin level needed to use the plugin");
 | 
							$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_MATCH_AUTHLEVEL, AuthenticationManager::getPermissionLevelNameArray(AuthenticationManager::AUTH_LEVEL_ADMIN), "Admin level needed to use the plugin");
 | 
				
			||||||
@@ -438,6 +441,8 @@ class MatchManagerCore implements CallbackListener, CommandListener, TimerListen
 | 
				
			|||||||
		$this->maniaControl->getCallbackManager()->registerCallbackListener(Callbacks::TM_SCORES, $this, 'handleEndRoundCallback');
 | 
							$this->maniaControl->getCallbackManager()->registerCallbackListener(Callbacks::TM_SCORES, $this, 'handleEndRoundCallback');
 | 
				
			||||||
		$this->maniaControl->getCallbackManager()->registerCallbackListener(Callbacks::MP_STARTROUNDSTART, $this, 'handleBeginRoundCallback');
 | 
							$this->maniaControl->getCallbackManager()->registerCallbackListener(Callbacks::MP_STARTROUNDSTART, $this, 'handleBeginRoundCallback');
 | 
				
			||||||
		$this->maniaControl->getCallbackManager()->registerCallbackListener(Callbacks::TM_WARMUPSTARTROUND, $this, 'handleStartWarmUpCallback');
 | 
							$this->maniaControl->getCallbackManager()->registerCallbackListener(Callbacks::TM_WARMUPSTARTROUND, $this, 'handleStartWarmUpCallback');
 | 
				
			||||||
 | 
							$this->maniaControl->getCallbackManager()->registerCallbackListener(Callbacks::MP_STARTMATCHSTART, $this, 'handleStartMatchStartCallback');
 | 
				
			||||||
 | 
							$this->maniaControl->getCallbackManager()->registerCallbackListener(CallbackManager::CB_MP_BEGINMAP, $this, 'handleBeginMapCallback');
 | 
				
			||||||
		$this->maniaControl->getCallbackManager()->registerCallbackListener(CallbackManager::CB_MP_BEGINMATCH, $this, 'handleBeginMatchCallback');
 | 
							$this->maniaControl->getCallbackManager()->registerCallbackListener(CallbackManager::CB_MP_BEGINMATCH, $this, 'handleBeginMatchCallback');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// Register Socket commands
 | 
							// Register Socket commands
 | 
				
			||||||
@@ -493,9 +498,15 @@ class MatchManagerCore implements CallbackListener, CommandListener, TimerListen
 | 
				
			|||||||
			`rank` INT(4) NOT NULL,
 | 
								`rank` INT(4) NOT NULL,
 | 
				
			||||||
			`login` VARCHAR(30) NOT NULL,
 | 
								`login` VARCHAR(30) NOT NULL,
 | 
				
			||||||
			`matchpoints` INT(10) NOT NULL,
 | 
								`matchpoints` INT(10) NOT NULL,
 | 
				
			||||||
 | 
								`mappoints` INT(10) NOT NULL,
 | 
				
			||||||
			`roundpoints` INT(10) NOT NULL,
 | 
								`roundpoints` INT(10) NOT NULL,
 | 
				
			||||||
			`time` INT(10) NOT NULL,
 | 
								`bestracetime` INT(10) NOT NULL,
 | 
				
			||||||
			`teamid` VARCHAR(30) NOT NULL
 | 
								`bestracecheckpoints` VARCHAR(1000) NOT NULL,
 | 
				
			||||||
 | 
								`bestlaptime` INT(10) NOT NULL,
 | 
				
			||||||
 | 
								`bestlapcheckpoints` VARCHAR(1000) NOT NULL,
 | 
				
			||||||
 | 
								`prevracetime` INT(10) NOT NULL,
 | 
				
			||||||
 | 
								`prevracecheckpoints` VARCHAR(1000) NOT NULL,
 | 
				
			||||||
 | 
								`teamid` INT(3) NOT NULL
 | 
				
			||||||
			) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;';
 | 
								) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;';
 | 
				
			||||||
		$mysqli->query($query);
 | 
							$mysqli->query($query);
 | 
				
			||||||
		if ($mysqli->error) {
 | 
							if ($mysqli->error) {
 | 
				
			||||||
@@ -504,14 +515,46 @@ class MatchManagerCore implements CallbackListener, CommandListener, TimerListen
 | 
				
			|||||||
		$query = 'CREATE TABLE IF NOT EXISTS `' . self::DB_TEAMSDATA . '` (
 | 
							$query = 'CREATE TABLE IF NOT EXISTS `' . self::DB_TEAMSDATA . '` (
 | 
				
			||||||
			`matchid` VARCHAR(100) NOT NULL,
 | 
								`matchid` VARCHAR(100) NOT NULL,
 | 
				
			||||||
			`timestamp` INT(10) NOT NULL,
 | 
								`timestamp` INT(10) NOT NULL,
 | 
				
			||||||
			`id` VARCHAR(30) NOT NULL,
 | 
								`rank` INT(3) NOT NULL,
 | 
				
			||||||
 | 
								`id` INT(3) NOT NULL,
 | 
				
			||||||
			`team` VARCHAR(30) NOT NULL,
 | 
								`team` VARCHAR(30) NOT NULL,
 | 
				
			||||||
			`points` INT(10) NOT NULL
 | 
								`matchpoints` INT(10) NOT NULL,
 | 
				
			||||||
 | 
								`mappoints` INT(10) NOT NULL,
 | 
				
			||||||
 | 
								`roundpoints` INT(10) NOT NULL
 | 
				
			||||||
			) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;';
 | 
								) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;';
 | 
				
			||||||
		$mysqli->query($query);
 | 
							$mysqli->query($query);
 | 
				
			||||||
		if ($mysqli->error) {
 | 
							if ($mysqli->error) {
 | 
				
			||||||
			trigger_error($mysqli->error, E_USER_ERROR);
 | 
								trigger_error($mysqli->error, E_USER_ERROR);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							// Update table data
 | 
				
			||||||
 | 
							$mysqliconfig = $this->maniaControl->getDatabase()->getConfig();
 | 
				
			||||||
 | 
							$query = 'IF NOT EXISTS( SELECT NULL
 | 
				
			||||||
 | 
											FROM INFORMATION_SCHEMA.COLUMNS
 | 
				
			||||||
 | 
										WHERE `table_name` = "' . self::DB_ROUNDSDATA . '"
 | 
				
			||||||
 | 
											AND `table_schema` = "' . $mysqliconfig->name . '"
 | 
				
			||||||
 | 
											AND `column_name` = "mappoints")  THEN
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
										ALTER TABLE `' . self::DB_ROUNDSDATA . '`
 | 
				
			||||||
 | 
											ADD COLUMN `mappoints` INT(10) NOT NULL AFTER `matchpoints`,
 | 
				
			||||||
 | 
											CHANGE `time` `bestracetime` INT(10) NOT NULL,
 | 
				
			||||||
 | 
											ADD COLUMN `bestracecheckpoints` VARCHAR(1000) NOT NULL AFTER `bestracetime`,
 | 
				
			||||||
 | 
											ADD COLUMN `bestlaptime` INT(10) NOT NULL AFTER `bestracecheckpoints`,
 | 
				
			||||||
 | 
											ADD COLUMN `bestlapcheckpoints` VARCHAR(1000) NOT NULL AFTER `bestlaptime`,
 | 
				
			||||||
 | 
											ADD COLUMN `prevracetime` INT(10) NOT NULL AFTER `bestlapcheckpoints`,
 | 
				
			||||||
 | 
											ADD COLUMN `prevracecheckpoints` VARCHAR(1000) NOT NULL AFTER `prevracetime`,
 | 
				
			||||||
 | 
											MODIFY `teamid` INT(3) NOT NULL;
 | 
				
			||||||
 | 
										ALTER TABLE `' . self::DB_TEAMSDATA . '`
 | 
				
			||||||
 | 
											ADD COLUMN `rank` INT(3) NOT NULL,
 | 
				
			||||||
 | 
											MODIFY `id` INT(3) NOT NULL,
 | 
				
			||||||
 | 
											CHANGE `points` `matchpoints` INT(10) NOT NULL,
 | 
				
			||||||
 | 
											ADD COLUMN `mappoints` INT(10) NOT NULL AFTER `matchpoints`,
 | 
				
			||||||
 | 
											ADD COLUMN `roundpoints` INT(10) NOT NULL AFTER `mappoints`;
 | 
				
			||||||
 | 
									END IF;';
 | 
				
			||||||
 | 
							$mysqli->query($query);
 | 
				
			||||||
 | 
							if ($mysqli->error) {
 | 
				
			||||||
 | 
								trigger_error($mysqli->error, E_USER_ERROR);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	public function getMatchStatus() {
 | 
						public function getMatchStatus() {
 | 
				
			||||||
@@ -611,7 +654,6 @@ class MatchManagerCore implements CallbackListener, CommandListener, TimerListen
 | 
				
			|||||||
			$this->maniaControl->getSettingManager()->initSetting($this, $key, self::SETTINGS_MODE_LIST[$key]['default'], self::SETTINGS_MODE_LIST[$key]['description']);
 | 
								$this->maniaControl->getSettingManager()->initSetting($this, $key, self::SETTINGS_MODE_LIST[$key]['default'], self::SETTINGS_MODE_LIST[$key]['description']);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		
 | 
					 | 
				
			||||||
		if ($settingsmode == 'Maps from file & Settings from plugin' || $settingsmode == 'All from the plugin') {
 | 
							if ($settingsmode == 'Maps from file & Settings from plugin' || $settingsmode == 'All from the plugin') {
 | 
				
			||||||
			$gmsettings = $this->getGMSettings($this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MATCH_GAMEMODE_BASE), $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MATCH_CUSTOM_GAMEMODE));
 | 
								$gmsettings = $this->getGMSettings($this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MATCH_GAMEMODE_BASE), $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MATCH_CUSTOM_GAMEMODE));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -645,6 +687,7 @@ class MatchManagerCore implements CallbackListener, CommandListener, TimerListen
 | 
				
			|||||||
		$this->matchrecover		= false;
 | 
							$this->matchrecover		= false;
 | 
				
			||||||
		$this->pointstorecover	= array();
 | 
							$this->pointstorecover	= array();
 | 
				
			||||||
		$this->currentscore		= array();
 | 
							$this->currentscore		= array();
 | 
				
			||||||
 | 
							$this->preendroundscore	= array();
 | 
				
			||||||
		$this->settingsloaded	= false;
 | 
							$this->settingsloaded	= false;
 | 
				
			||||||
		$this->mapsshuffled		= false;
 | 
							$this->mapsshuffled		= false;
 | 
				
			||||||
		$this->mapshidden		= false;
 | 
							$this->mapshidden		= false;
 | 
				
			||||||
@@ -659,6 +702,10 @@ class MatchManagerCore implements CallbackListener, CommandListener, TimerListen
 | 
				
			|||||||
		$this->settings_nbwinner		= 2;
 | 
							$this->settings_nbwinner		= 2;
 | 
				
			||||||
		$this->settings_nbmapsbymatch	= 0;
 | 
							$this->settings_nbmapsbymatch	= 0;
 | 
				
			||||||
		$this->settings_pointlimit		= 100;
 | 
							$this->settings_pointlimit		= 100;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							$this->currentgmbase		= "";
 | 
				
			||||||
 | 
							$this->currentcustomgm		= "";
 | 
				
			||||||
 | 
							$this->currentsettingmode	= "";
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/**
 | 
						/**
 | 
				
			||||||
@@ -673,7 +720,6 @@ class MatchManagerCore implements CallbackListener, CommandListener, TimerListen
 | 
				
			|||||||
				$gmsettings[$gamemodename] = $info['value'];
 | 
									$gmsettings[$gamemodename] = $info['value'];
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		var_dump($gmsettings);
 | 
					 | 
				
			||||||
		$this->maniaControl->getClient()->setModeScriptSettings($gmsettings);
 | 
							$this->maniaControl->getClient()->setModeScriptSettings($gmsettings);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -699,7 +745,7 @@ class MatchManagerCore implements CallbackListener, CommandListener, TimerListen
 | 
				
			|||||||
						if (preg_match('/^(\s*)\#Setting\s+(S_\S+)\s+(\S+)\s*(as\s|)(_\(|)("|\'|)([^\'"]*)("\)|\'\)|"|\'| |)/', $line, $matches)) {
 | 
											if (preg_match('/^(\s*)\#Setting\s+(S_\S+)\s+(\S+)\s*(as\s|)(_\(|)("|\'|)([^\'"]*)("\)|\'\)|"|\'| |)/', $line, $matches)) {
 | 
				
			||||||
							$gamesettingname = $matches[2];
 | 
												$gamesettingname = $matches[2];
 | 
				
			||||||
							$defaultvalue = $matches[3];
 | 
												$defaultvalue = $matches[3];
 | 
				
			||||||
							if (is_float($matches[3]+0)) {
 | 
												if (is_numeric($matches[3]) && is_float($matches[3]+0)) {
 | 
				
			||||||
								$type = "float";
 | 
													$type = "float";
 | 
				
			||||||
							} else if (is_numeric($matches[3])) {
 | 
												} else if (is_numeric($matches[3])) {
 | 
				
			||||||
								$type = "integer";
 | 
													$type = "integer";
 | 
				
			||||||
@@ -817,7 +863,6 @@ class MatchManagerCore implements CallbackListener, CommandListener, TimerListen
 | 
				
			|||||||
			// Prepare maps in case of "All from the plugin" mode
 | 
								// Prepare maps in case of "All from the plugin" mode
 | 
				
			||||||
			if ($this->currentsettingmode == 'All from the plugin' && strlen($this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MODE_MAPS)) >= 1) {
 | 
								if ($this->currentsettingmode == 'All from the plugin' && strlen($this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MODE_MAPS)) >= 1) {
 | 
				
			||||||
				$maps = explode(',', $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MODE_MAPS));
 | 
									$maps = explode(',', $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MODE_MAPS));
 | 
				
			||||||
 | 
					 | 
				
			||||||
				foreach ($maps as $map) {
 | 
									foreach ($maps as $map) {
 | 
				
			||||||
					try {
 | 
										try {
 | 
				
			||||||
						$mapInfo = new Map($this->maniaControl->getClient()->getMapInfo($map));
 | 
											$mapInfo = new Map($this->maniaControl->getClient()->getMapInfo($map));
 | 
				
			||||||
@@ -827,7 +872,6 @@ class MatchManagerCore implements CallbackListener, CommandListener, TimerListen
 | 
				
			|||||||
				}
 | 
									}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
				if ($this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MODE_SHUFFLE)) {
 | 
									if ($this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MODE_SHUFFLE)) {
 | 
				
			||||||
					//shuffle
 | 
					 | 
				
			||||||
					$this->mapsshuffled = true;
 | 
										$this->mapsshuffled = true;
 | 
				
			||||||
					shuffle($maps);
 | 
										shuffle($maps);
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
@@ -877,7 +921,7 @@ class MatchManagerCore implements CallbackListener, CommandListener, TimerListen
 | 
				
			|||||||
					$this->maniaControl->getClient()->removeMap($map->fileName);
 | 
										$this->maniaControl->getClient()->removeMap($map->fileName);
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
				$this->maniaControl->getClient()->InsertPlaylistFromMatchSettings($maplist); // TODO check if "All from file" if settings are loaded or not
 | 
									$this->maniaControl->getClient()->InsertPlaylistFromMatchSettings($maplist);
 | 
				
			||||||
			} elseif ($this->currentsettingmode == 'All from the plugin') {
 | 
								} elseif ($this->currentsettingmode == 'All from the plugin') {
 | 
				
			||||||
				if ($this->hidenextmaps) {
 | 
									if ($this->hidenextmaps) {
 | 
				
			||||||
					$this->maniaControl->getClient()->addMap($this->maps[0]);
 | 
										$this->maniaControl->getClient()->addMap($this->maps[0]);
 | 
				
			||||||
@@ -937,16 +981,17 @@ class MatchManagerCore implements CallbackListener, CommandListener, TimerListen
 | 
				
			|||||||
	 * Function called to end the match
 | 
						 * Function called to end the match
 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
	public function MatchEnd() {
 | 
						public function MatchEnd() {
 | 
				
			||||||
 | 
					 | 
				
			||||||
		if ($this->currentmap->mapType == "TrackMania\TM_Royal") {
 | 
					 | 
				
			||||||
			$scriptName = "Trackmania/TM_RoyalTimeAttack_Online.Script.txt" ;
 | 
					 | 
				
			||||||
		} else {
 | 
					 | 
				
			||||||
			$scriptName = "Trackmania/TM_TimeAttack_Online.Script.txt" ;
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		try {
 | 
							try {
 | 
				
			||||||
			$this->maniaControl->getClient()->setScriptName($scriptName);
 | 
								// Load TimeAttack gamemode if possible
 | 
				
			||||||
 | 
								if ($this->currentmap->mapType == "TrackMania\TM_Race") {
 | 
				
			||||||
 | 
									$scriptname = "Trackmania/TM_TimeAttack_Online.Script.txt" ;
 | 
				
			||||||
 | 
								} else if ($this->currentmap->mapType == "TrackMania\TM_Royal") {
 | 
				
			||||||
 | 
									$scriptname = "Trackmania/TM_RoyalTimeAttack_Online.Script.txt" ;
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								if (isset($scriptname)) {
 | 
				
			||||||
 | 
									Logger::log("Loading script: " . $scriptname);
 | 
				
			||||||
 | 
									$this->maniaControl->getClient()->setScriptName($scriptname);
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
			// MYSQL DATA INSERT
 | 
								// MYSQL DATA INSERT
 | 
				
			||||||
			$settings = json_encode($this->maniaControl->getClient()->getModeScriptSettings());
 | 
								$settings = json_encode($this->maniaControl->getClient()->getModeScriptSettings());
 | 
				
			||||||
			$mysqli = $this->maniaControl->getDatabase()->getMysqli();
 | 
								$mysqli = $this->maniaControl->getDatabase()->getMysqli();
 | 
				
			||||||
@@ -961,7 +1006,6 @@ class MatchManagerCore implements CallbackListener, CommandListener, TimerListen
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
			// End notifications
 | 
								// End notifications
 | 
				
			||||||
			$this->maniaControl->getChat()->sendSuccess($this->chatprefix . "Match finished");
 | 
								$this->maniaControl->getChat()->sendSuccess($this->chatprefix . "Match finished");
 | 
				
			||||||
			Logger::log("Loading script: $scriptName");
 | 
					 | 
				
			||||||
			Logger::log("Match finished");
 | 
								Logger::log("Match finished");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			$this->resetMatchVariables();
 | 
								$this->resetMatchVariables();
 | 
				
			||||||
@@ -979,22 +1023,26 @@ class MatchManagerCore implements CallbackListener, CommandListener, TimerListen
 | 
				
			|||||||
	 */
 | 
						 */
 | 
				
			||||||
	public function MatchStop() {
 | 
						public function MatchStop() {
 | 
				
			||||||
		Logger::log("Match stop");
 | 
							Logger::log("Match stop");
 | 
				
			||||||
		if ($this->currentmap->mapType == "TrackMania\TM_Royal") {
 | 
					
 | 
				
			||||||
			$scriptName = "Trackmania/TM_RoyalTimeAttack_Online.Script.txt" ;
 | 
					 | 
				
			||||||
		} else {
 | 
					 | 
				
			||||||
			$scriptName = "Trackmania/TM_TimeAttack_Online.Script.txt" ;
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
		try {
 | 
							try {
 | 
				
			||||||
			// Trigger Callback
 | 
								// Trigger Callback
 | 
				
			||||||
			$this->maniaControl->getCallbackManager()->triggerCallback(self::CB_MATCHMANAGER_STOPMATCH, $this->matchid, $this->currentscore, $this->currentteamsscore);
 | 
								$this->maniaControl->getCallbackManager()->triggerCallback(self::CB_MATCHMANAGER_STOPMATCH, $this->matchid, $this->currentscore, $this->currentteamsscore);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			$this->maniaControl->getChat()->sendError($this->chatprefix . 'Match stopped by an Admin!');
 | 
								$this->maniaControl->getChat()->sendError($this->chatprefix . 'Match stopped by an Admin!');
 | 
				
			||||||
			$this->maniaControl->getClient()->setScriptName($scriptName);
 | 
					
 | 
				
			||||||
			Logger::log("Loading script: $scriptName");
 | 
								// Load TimeAttack gamemode if possible
 | 
				
			||||||
 | 
								if ($this->currentmap->mapType == "TrackMania\TM_Race") {
 | 
				
			||||||
 | 
									$scriptname = "Trackmania/TM_TimeAttack_Online.Script.txt" ;
 | 
				
			||||||
 | 
								} else if ($this->currentmap->mapType == "TrackMania\TM_Royal") {
 | 
				
			||||||
 | 
									$scriptname = "Trackmania/TM_RoyalTimeAttack_Online.Script.txt" ;
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								if (isset($scriptname)) {
 | 
				
			||||||
 | 
									Logger::log("Loading script: " . $scriptname);
 | 
				
			||||||
 | 
									$this->maniaControl->getClient()->setScriptName($scriptname);
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			$this->resetMatchVariables();
 | 
								$this->resetMatchVariables();
 | 
				
			||||||
 | 
					 | 
				
			||||||
		} catch (Exception $e) {
 | 
							} catch (Exception $e) {
 | 
				
			||||||
			$this->maniaControl->getChat()->sendErrorToAdmins($this->chatprefix . 'Can not stop match: ' . $e->getMessage());
 | 
								$this->maniaControl->getChat()->sendErrorToAdmins($this->chatprefix . 'Can not stop match: ' . $e->getMessage());
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
@@ -1223,128 +1271,135 @@ class MatchManagerCore implements CallbackListener, CommandListener, TimerListen
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/**
 | 
						/**
 | 
				
			||||||
	 * Handle callback "BeginMatch"
 | 
						 * Handle XMLRPC callback "Maniaplanet.StartMatch_Start"
 | 
				
			||||||
 | 
						 */
 | 
				
			||||||
 | 
						public function handleStartMatchStartCallback() {
 | 
				
			||||||
 | 
							Logger::log("handleStartMatchStartCallback");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							if ($this->matchStarted) {
 | 
				
			||||||
 | 
								Logger::log("Loading settings");
 | 
				
			||||||
 | 
								$this->settingsloaded = true;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								if ($this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MATCH_SETTINGS_MODE) != 'All from file') {
 | 
				
			||||||
 | 
									Logger::log("Load Script Settings");
 | 
				
			||||||
 | 
									$this->loadGMSettings($this->getGMSettings($this->currentgmbase, $this->currentcustomgm));
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								$this->updateGMvariables();
 | 
				
			||||||
 | 
							} else if ($this->postmatch) {
 | 
				
			||||||
 | 
								$this->postmatch = false;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								Logger::log("Load PostMatch Game mode Settings");
 | 
				
			||||||
 | 
								$postmatchsettings = [
 | 
				
			||||||
 | 
									self::SETTING_MATCH_S_FORCELAPSNB => 0,
 | 
				
			||||||
 | 
									self::SETTING_MATCH_S_RESPAWNBEHAVIOUR => 0,
 | 
				
			||||||
 | 
									self::SETTING_MATCH_S_WARMUPNB => 0,
 | 
				
			||||||
 | 
									self::SETTING_MATCH_S_TIMELIMIT => 600
 | 
				
			||||||
 | 
								];
 | 
				
			||||||
 | 
								$currentgmsettings = $this->maniaControl->getClient()->getModeScriptSettings();
 | 
				
			||||||
 | 
								foreach ($postmatchsettings as $gamesettingname => $value) {
 | 
				
			||||||
 | 
									if (!array_key_exists($gamesettingname,$currentgmsettings)) {
 | 
				
			||||||
 | 
										unset($postmatchsettings[$gamesettingname]);
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								$this->maniaControl->getClient()->setModeScriptSettings($postmatchsettings);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/**
 | 
				
			||||||
 | 
						 * Handle Maniacontrol callback "BeginMatch"
 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
	public function handleBeginMatchCallback() {
 | 
						public function handleBeginMatchCallback() {
 | 
				
			||||||
		Logger::log("handleBeginMatchCallback");
 | 
							Logger::log("handleStartMatchStartCallback");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if ($this->matchStarted === true) {
 | 
							if ($this->matchStarted && !$this->settingsloaded) {
 | 
				
			||||||
			if (!($this->settingsloaded)) {
 | 
								Logger::log("Restarting map to restart match data");
 | 
				
			||||||
				Logger::log("Loading settings");
 | 
								$this->maniaControl->getClient()->restartMap();
 | 
				
			||||||
				$this->settingsloaded = true;
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
				if ($this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MATCH_SETTINGS_MODE) != 'All from file') {
 | 
						/**
 | 
				
			||||||
					Logger::log("Load Script Settings");
 | 
						 * Handle Maniacontrol callback "BeginMap"
 | 
				
			||||||
					$this->loadGMSettings($this->getGMSettings($this->currentgmbase, $this->currentcustomgm));
 | 
						 */
 | 
				
			||||||
				}
 | 
						public function handleBeginMapCallback() {
 | 
				
			||||||
 | 
							Logger::log("handleBeginMapCallback");
 | 
				
			||||||
 | 
							if ($this->matchStarted) {
 | 
				
			||||||
 | 
								$this->nbmaps++;
 | 
				
			||||||
 | 
								$this->nbrounds = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
				$this->updateGMvariables();
 | 
								if ($this->nbmaps > 0) {
 | 
				
			||||||
 | 
									$maps = $this->maniaControl->getMapManager()->getMaps();
 | 
				
			||||||
 | 
									$totalnbmaps = $this->maniaControl->getMapManager()->getMapsCount();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
				Logger::log("Restarting Map for load settings");
 | 
									$this->currentmap = $this->maniaControl->getMapManager()->getCurrentMap();
 | 
				
			||||||
				$this->maniaControl->getClient()->restartMap();
 | 
									Logger::log("Current Map: " . Formatter::stripCodes($this->currentmap->name));
 | 
				
			||||||
			} else {
 | 
									$message = $this->chatprefix . '$<$o$iCurrent Map:$>' . "\n";
 | 
				
			||||||
				$this->nbmaps++;
 | 
									$message .= Formatter::stripCodes($this->currentmap->name);
 | 
				
			||||||
				$this->nbrounds = 0;
 | 
									$this->maniaControl->getChat()->sendInformation($message);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
				if ($this->nbmaps > 0) {
 | 
									if (!in_array($this->currentgmbase, ["Laps", "TimeAttack", "RoyalTimeAttack"])) {
 | 
				
			||||||
					$maps = $this->maniaControl->getMapManager()->getMaps();
 | 
										$message = "";
 | 
				
			||||||
					$totalnbmaps = $this->maniaControl->getMapManager()->getMapsCount();
 | 
										$i = 0;
 | 
				
			||||||
 | 
										foreach ($maps as $map) {
 | 
				
			||||||
 | 
											if ($this->currentmap->uid == $map->uid) {
 | 
				
			||||||
 | 
												break;
 | 
				
			||||||
 | 
											}
 | 
				
			||||||
 | 
											$i++;
 | 
				
			||||||
 | 
										}
 | 
				
			||||||
 | 
										if (($this->settings_nbmapsbymatch > 0 && $i < $this->settings_nbmapsbymatch - 1 && $this->nbmaps < $this->settings_nbmapsbymatch) || ($this->settings_nbmapsbymatch <= 0 && ($totalnbmaps >= 2 || count($this->maps) >= 2))) { // TODO manage maps in queue added by an admin
 | 
				
			||||||
 | 
											$message = $this->chatprefix . '$<$o$iNext Maps:$>';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
					$this->currentmap = $this->maniaControl->getMapManager()->getCurrentMap();
 | 
											$nbhiddenmaps = 0;
 | 
				
			||||||
					Logger::log("Current Map: " . Formatter::stripCodes($this->currentmap->name));
 | 
											if ($this->hidenextmaps) {
 | 
				
			||||||
					$message = $this->chatprefix . '$<$o$iCurrent Map:$>' . "\n";
 | 
												if ($totalnbmaps < count($this->maps)) {
 | 
				
			||||||
					$message .= Formatter::stripCodes($this->currentmap->name);
 | 
													if ($this->settings_nbmapsbymatch > 0) {
 | 
				
			||||||
					$this->maniaControl->getChat()->sendInformation($message);
 | 
														$nbhiddenmaps = min(count($this->maps) - $totalnbmaps, $this->settings_nbmapsbymatch - 1);
 | 
				
			||||||
 | 
													} else {
 | 
				
			||||||
 | 
														$nbhiddenmaps = count($this->maps) - $totalnbmaps;
 | 
				
			||||||
 | 
													}
 | 
				
			||||||
 | 
													$message .= "\nThen " . $nbhiddenmaps . " hidden maps";
 | 
				
			||||||
 | 
													Logger::log("Then " . $nbhiddenmaps . " hidden maps");
 | 
				
			||||||
 | 
												}
 | 
				
			||||||
 | 
											}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
					if (!in_array($this->currentgmbase, ["Laps", "TimeAttack", "RoyalTimeAttack"])) {
 | 
											for ($j = 1; $j + $nbhiddenmaps <= 4 && (($this->settings_nbmapsbymatch > 0 && $j + $nbhiddenmaps <= $this->settings_nbmapsbymatch - $this->nbmaps) || ($this->settings_nbmapsbymatch <= 0 && $j + $nbhiddenmaps <= $totalnbmaps))  ; $j++ ) {
 | 
				
			||||||
						$message = "";
 | 
												$index = $i + $j;
 | 
				
			||||||
						$i = 0;
 | 
					
 | 
				
			||||||
						foreach ($maps as $map) {
 | 
												while ($index >= $totalnbmaps) { // return to the start of the array if end of array
 | 
				
			||||||
							if ($this->currentmap->uid == $map->uid) {
 | 
													$index = $index - $totalnbmaps;
 | 
				
			||||||
 | 
												}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
												if ($index != $i) {
 | 
				
			||||||
 | 
													$message .= "\n" . $j . ": " . Formatter::stripCodes($maps[$index]->name);
 | 
				
			||||||
 | 
													Logger::log(Formatter::stripCodes($index . ": " . $maps[$index]->name));
 | 
				
			||||||
 | 
												} else {
 | 
				
			||||||
 | 
													$message .= "\nThen we will return to this map";
 | 
				
			||||||
 | 
													Logger::log("Then we will return to this map");
 | 
				
			||||||
 | 
													$j = 0;
 | 
				
			||||||
								break;
 | 
													break;
 | 
				
			||||||
							}
 | 
												}
 | 
				
			||||||
							$i++;
 | 
					 | 
				
			||||||
						}
 | 
											}
 | 
				
			||||||
	
 | 
											if ($j + $nbhiddenmaps >= 4) {
 | 
				
			||||||
						if (($this->settings_nbmapsbymatch > 0 && $i < $this->settings_nbmapsbymatch - 1 && $this->nbmaps < $this->settings_nbmapsbymatch) || ($this->settings_nbmapsbymatch <= 0 && ($totalnbmaps >= 2 || count($this->maps) >= 2))) { // TODO manage maps in queue added by an admin
 | 
												if ($this->settings_nbmapsbymatch > 0 && $this->settings_nbmapsbymatch - $j - $nbhiddenmaps - $this->nbmaps + 1 > 0) {
 | 
				
			||||||
							$message = $this->chatprefix . '$<$o$iNext Maps:$>';
 | 
													$message .= "\n" . "And " . ($this->settings_nbmapsbymatch - $j - $nbhiddenmaps - $this->nbmaps + 1) . " more maps";
 | 
				
			||||||
 | 
													Logger::log("And " . ($this->settings_nbmapsbymatch - $j - $nbhiddenmaps - $this->nbmaps + 1) . " more maps");
 | 
				
			||||||
							$nbhiddenmaps = 0;
 | 
												} elseif ($this->settings_nbmapsbymatch <= 0 && ($totalnbmaps - $j - $nbhiddenmaps > 0 || count($this->maps) - $j - $nbhiddenmaps > 0)) {
 | 
				
			||||||
							if ($this->hidenextmaps) {
 | 
													$n = max($totalnbmaps - $j - $nbhiddenmaps, count($this->maps) - $j - $nbhiddenmaps);
 | 
				
			||||||
								if ($totalnbmaps < count($this->maps)) {
 | 
													$message .= "\n" . "And " . $n . " more maps";
 | 
				
			||||||
									if ($this->settings_nbmapsbymatch > 0) {
 | 
													Logger::log("And " . $n . " more maps");
 | 
				
			||||||
										$nbhiddenmaps = min(count($this->maps) - $totalnbmaps, $this->settings_nbmapsbymatch - 1);
 | 
					 | 
				
			||||||
									} else {
 | 
					 | 
				
			||||||
										$nbhiddenmaps = count($this->maps) - $totalnbmaps;
 | 
					 | 
				
			||||||
									}
 | 
					 | 
				
			||||||
									$message .= "\nThen " . $nbhiddenmaps . " hidden maps";
 | 
					 | 
				
			||||||
									Logger::log("Then " . $nbhiddenmaps . " hidden maps");
 | 
					 | 
				
			||||||
								}
 | 
					 | 
				
			||||||
							}
 | 
												}
 | 
				
			||||||
 | 
					 | 
				
			||||||
							for ($j = 1; $j + $nbhiddenmaps <= 4 && (($this->settings_nbmapsbymatch > 0 && $j + $nbhiddenmaps <= $this->settings_nbmapsbymatch - $this->nbmaps) || ($this->settings_nbmapsbymatch <= 0 && $j + $nbhiddenmaps <= $totalnbmaps))  ; $j++ ) {
 | 
					 | 
				
			||||||
								$index = $i + $j;
 | 
					 | 
				
			||||||
	
 | 
					 | 
				
			||||||
								while ($index >= $totalnbmaps) { // return to the start of the array if end of array
 | 
					 | 
				
			||||||
									$index = $index - $totalnbmaps;
 | 
					 | 
				
			||||||
								}
 | 
					 | 
				
			||||||
	
 | 
					 | 
				
			||||||
								if ($index != $i) {
 | 
					 | 
				
			||||||
									$message .= "\n" . $j . ": " . Formatter::stripCodes($maps[$index]->name);
 | 
					 | 
				
			||||||
									Logger::log(Formatter::stripCodes($index . ": " . $maps[$index]->name));
 | 
					 | 
				
			||||||
								} else {
 | 
					 | 
				
			||||||
									$message .= "\nThen we will return to this map";
 | 
					 | 
				
			||||||
									Logger::log("Then we will return to this map");
 | 
					 | 
				
			||||||
									$j = 0;
 | 
					 | 
				
			||||||
									break;
 | 
					 | 
				
			||||||
								}
 | 
					 | 
				
			||||||
							}
 | 
					 | 
				
			||||||
							if ($j + $nbhiddenmaps >= 4) {
 | 
					 | 
				
			||||||
								if ($this->settings_nbmapsbymatch > 0 && $this->settings_nbmapsbymatch - $j - $nbhiddenmaps - $this->nbmaps + 1 > 0) {
 | 
					 | 
				
			||||||
									$message .= "\n" . "And " . ($this->settings_nbmapsbymatch - $j - $nbhiddenmaps - $this->nbmaps + 1) . " more maps";
 | 
					 | 
				
			||||||
									Logger::log("And " . ($this->settings_nbmapsbymatch - $j - $nbhiddenmaps - $this->nbmaps + 1) . " more maps");
 | 
					 | 
				
			||||||
								} elseif ($this->settings_nbmapsbymatch <= 0 && ($totalnbmaps - $j - $nbhiddenmaps > 0 || count($this->maps) - $j - $nbhiddenmaps > 0)) {
 | 
					 | 
				
			||||||
									$n = max($totalnbmaps - $j - $nbhiddenmaps, count($this->maps) - $j - $nbhiddenmaps);
 | 
					 | 
				
			||||||
									$message .= "\n" . "And " . $n . " more maps";
 | 
					 | 
				
			||||||
									Logger::log("And " . $n . " more maps");
 | 
					 | 
				
			||||||
								}
 | 
					 | 
				
			||||||
							}
 | 
					 | 
				
			||||||
							$this->maniaControl->getChat()->sendInformation($message);
 | 
					 | 
				
			||||||
						}
 | 
											}
 | 
				
			||||||
 | 
											$this->maniaControl->getChat()->sendInformation($message);
 | 
				
			||||||
					}
 | 
										}
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
 | 
					 | 
				
			||||||
				// Trigger Callback
 | 
					 | 
				
			||||||
				$currentstatus = [
 | 
					 | 
				
			||||||
					'nbmaps'			=> $this->nbmaps,
 | 
					 | 
				
			||||||
					'settings_nbmapsbymatch'	=> $this->settings_nbmapsbymatch];
 | 
					 | 
				
			||||||
				$this->maniaControl->getCallbackManager()->triggerCallback(self::CB_MATCHMANAGER_BEGINMAP,$this->matchid, $currentstatus, $this->currentmap);
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		if ($this->postmatch) {
 | 
					 | 
				
			||||||
			$scriptName = $this->maniaControl->getClient()->getScriptName()['CurrentValue'];
 | 
					 | 
				
			||||||
			Logger::log("scriptName: " . $scriptName);
 | 
					 | 
				
			||||||
			if ($scriptName == "Trackmania/TM_TimeAttack_Online.Script.txt" || $scriptName == "Trackmania/TM_RoyalTimeAttack_Online.Script.txt") {
 | 
					 | 
				
			||||||
				$this->postmatch = false;	
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
				Logger::log("Load Script Settings");
 | 
					 | 
				
			||||||
				$postmatchsettings = [
 | 
					 | 
				
			||||||
					self::SETTING_MATCH_S_FORCELAPSNB => 0,
 | 
					 | 
				
			||||||
					self::SETTING_MATCH_S_RESPAWNBEHAVIOUR => 0,
 | 
					 | 
				
			||||||
					self::SETTING_MATCH_S_TIMELIMIT => 600
 | 
					 | 
				
			||||||
				];
 | 
					 | 
				
			||||||
				if ($scriptName == "Trackmania/TM_TimeAttack_Online.Script.txt") {
 | 
					 | 
				
			||||||
					$postmatchsettings[self::SETTING_MATCH_S_WARMUPNB] = 0;
 | 
					 | 
				
			||||||
				}
 | 
					 | 
				
			||||||
				$this->maniaControl->getClient()->setModeScriptSettings($postmatchsettings);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
				Logger::log("Restarting Map for load settings");
 | 
					 | 
				
			||||||
				$this->maniaControl->getClient()->restartMap();
 | 
					 | 
				
			||||||
			} else {
 | 
					 | 
				
			||||||
				// Depending of the load of the server and the match gamemode, the script could be not loaded, this is a workaround to reload thhe script
 | 
					 | 
				
			||||||
				$this->maniaControl->getClient()->restartMap();
 | 
					 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								// Trigger Callback
 | 
				
			||||||
 | 
								$currentstatus = [
 | 
				
			||||||
 | 
									'nbmaps'			=> $this->nbmaps,
 | 
				
			||||||
 | 
									'settings_nbmapsbymatch'	=> $this->settings_nbmapsbymatch];
 | 
				
			||||||
 | 
								$this->maniaControl->getCallbackManager()->triggerCallback(self::CB_MATCHMANAGER_BEGINMAP,$this->matchid, $currentstatus, $this->currentmap);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -1396,157 +1451,147 @@ class MatchManagerCore implements CallbackListener, CommandListener, TimerListen
 | 
				
			|||||||
		Logger::log("handleEndRoundCallback-" . $structure->getSection());
 | 
							Logger::log("handleEndRoundCallback-" . $structure->getSection());
 | 
				
			||||||
		if ($this->matchStarted && $this->settingsloaded && !$this->postmatch) {
 | 
							if ($this->matchStarted && $this->settingsloaded && !$this->postmatch) {
 | 
				
			||||||
			Logger::log("Section: " . $structure->getSection());
 | 
								Logger::log("Section: " . $structure->getSection());
 | 
				
			||||||
			if ($structure->getSection() == "EndMatch") {
 | 
								if ($structure->getSection() == "EndMatchEarly") {
 | 
				
			||||||
				$this->MatchEnd();
 | 
									$this->MatchEnd();
 | 
				
			||||||
			} elseif ($structure->getSection() == "EndMap") {
 | 
								} elseif ($structure->getSection() == "EndMap" && $this->hidenextmaps && isset($this->maps[$this->nbmaps])) {
 | 
				
			||||||
				if ($this->hidenextmaps && isset($this->maps[$this->nbmaps])) {
 | 
									$this->maniaControl->getClient()->addMap($this->maps[$this->nbmaps]);
 | 
				
			||||||
					$this->maniaControl->getClient()->addMap($this->maps[$this->nbmaps]);
 | 
								} elseif ($structure->getSection() == "PreEndRound") {
 | 
				
			||||||
				}
 | 
									$this->preendroundscore = $structure->getPlayerScores();
 | 
				
			||||||
			} else {
 | 
								} elseif ($structure->getSection() == "EndRound") {
 | 
				
			||||||
				$timestamp = time();
 | 
									$timestamp = time();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
				if ($structure->getSection() == "PreEndRound" && in_array($this->currentgmbase, ["Cup", "Teams", "Rounds"])) {
 | 
									if ($this->nbmaps != 0 and ($this->nbrounds != $this->settings_nbroundsbymap || $this->nbrounds == 0 )) {
 | 
				
			||||||
					$realSection = true;
 | 
										//
 | 
				
			||||||
				} elseif ($structure->getSection() == "EndRound" && in_array($this->currentgmbase, ["Champion", "Knockout", "Laps", "TimeAttack", "RoyalTimeAttack"])) {
 | 
										// Players Scores
 | 
				
			||||||
					$realSection = true;
 | 
										//
 | 
				
			||||||
				} else {
 | 
										$this->currentscore = array();
 | 
				
			||||||
					$realSection = false;
 | 
										$results = $structure->getPlayerScores();
 | 
				
			||||||
				}
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
				if ($realSection) {
 | 
										if  ($this->currentgmbase == "RoyalTimeAttack") {
 | 
				
			||||||
					if ($this->nbmaps != 0 and ($this->nbrounds != $this->settings_nbroundsbymap || $this->nbrounds == 0 )) {
 | 
											$this->maniaControl->getChat()->sendErrorToAdmins($this->chatprefix . "No data are save in RoyalTimeAttack for the moment, it's not implemented on server side. Waiting a fix from NADEO");
 | 
				
			||||||
						$database		= "";
 | 
											Logger::Log("No data are save in RoyalTimeAttack for the moment, it's not implemented on server side. Waiting a fix from NADEO");
 | 
				
			||||||
						$this->currentscore = array();
 | 
										}
 | 
				
			||||||
						$results		= $structure->getPlayerScores();
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
						// Resort scores
 | 
										//$rank = 1;
 | 
				
			||||||
						if ($structure->getSection() == "PreEndRound") {
 | 
										foreach ($results as $result) {
 | 
				
			||||||
							usort($results, function ($a, $b) { return -($a->getMatchPoints() + $a->getRoundPoints() <=> $b->getMatchPoints() + $b->getRoundPoints()); });
 | 
											$rank 					= $result->getRank();
 | 
				
			||||||
						}
 | 
											$player					= $result->getPlayer();
 | 
				
			||||||
 | 
											$matchpoints			= $result->getMatchPoints();
 | 
				
			||||||
 | 
											$mappoints				= $result->getMapPoints();
 | 
				
			||||||
 | 
											$roundpoints			= $result->getRoundPoints();
 | 
				
			||||||
 | 
											$bestracetime			= $result->getBestRaceTime();
 | 
				
			||||||
 | 
											$bestracecheckpoints	= implode(",", $result->getBestRaceCheckpoints());
 | 
				
			||||||
 | 
											$bestlaptime			= $result->getBestLapTime();
 | 
				
			||||||
 | 
											$bestlapcheckpoints		= implode(",", $result->getBestLapCheckpoints());
 | 
				
			||||||
 | 
											$prevracetime			= $result->getPrevRaceTime();
 | 
				
			||||||
 | 
											$prevracecheckpoints	= implode(",", $result->getPrevRaceCheckpoints());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
						$pointsrepartition = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MATCH_S_POINTSREPARTITION);
 | 
											if (count($this->preendroundscore) > 0) {
 | 
				
			||||||
						$pointsrepartition = explode(',', $pointsrepartition);
 | 
												foreach ($this->preendroundscore as $k => $preendroundresult) {
 | 
				
			||||||
 | 
													if ($preendroundresult->getPlayer() === $player) {
 | 
				
			||||||
						$dbquery = 'INSERT INTO `' . self::DB_ROUNDSDATA . '` (`matchid`,`timestamp`,`rank`,`login`,`matchpoints`,`roundpoints`,`time`,`teamid`) VALUES ';
 | 
														if ($roundpoints == 0 && $preendroundresult->getRoundPoints() != 0) {
 | 
				
			||||||
						$rank = 1;
 | 
															$roundpoints = $preendroundresult->getRoundPoints();
 | 
				
			||||||
 | 
														}
 | 
				
			||||||
						foreach ($results as $result) {
 | 
														if ($mappoints == 0 && $preendroundresult->getMapPoints() != 0) {
 | 
				
			||||||
							$player		= $result->getPlayer();
 | 
															$mappoints = $preendroundresult->getMapPoints();
 | 
				
			||||||
							$time		= $result->getPrevRaceTime();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
							if (in_array($this->currentgmbase, ["Champion", "Cup", "Knockout", "Teams", "Rounds"]) && !($result->getMatchPoints() == 0 && ($player->isSpectator || $player->isFakePlayer()))) {
 | 
					 | 
				
			||||||
								$roundpoints	= $result->getRoundPoints();
 | 
					 | 
				
			||||||
								$points			= $result->getMatchPoints();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
								if ($this->currentgmbase == "Champion") {
 | 
					 | 
				
			||||||
									$this->currentscore = array_merge($this->currentscore, array(array($rank, $player->login, $points , $result->getMapPoints(), $time, "")));
 | 
					 | 
				
			||||||
								} elseif ($this->currentgmbase == "Cup") {
 | 
					 | 
				
			||||||
									// Bypass false winner because of the sum of points
 | 
					 | 
				
			||||||
									if ($points + $roundpoints > $this->settings_pointlimit && $roundpoints > 0) {
 | 
					 | 
				
			||||||
										if ($points == $this->settings_pointlimit) { // new winner
 | 
					 | 
				
			||||||
											var_dump("settings_pointlimit: " . $this->settings_pointlimit . " / settings_nbwinners: " . $this->settings_nbwinners . " / nbwinners: " . $this->nbwinners);
 | 
					 | 
				
			||||||
											$matchpoints = $this->settings_pointlimit + 1 + $this->settings_nbwinners - $this->nbwinners;
 | 
					 | 
				
			||||||
											$this->nbwinners++;
 | 
					 | 
				
			||||||
										} else {
 | 
					 | 
				
			||||||
											$matchpoints = $this->settings_pointlimit;
 | 
					 | 
				
			||||||
										}
 | 
					 | 
				
			||||||
										
 | 
					 | 
				
			||||||
									} else {
 | 
					 | 
				
			||||||
										$matchpoints = $points + $roundpoints;
 | 
					 | 
				
			||||||
									}
 | 
														}
 | 
				
			||||||
									$this->currentscore = array_merge($this->currentscore, array(array($rank, $player->login, $matchpoints, $roundpoints, $time, "-1")));
 | 
					 | 
				
			||||||
									if ($roundpoints > 0) $atleastonefinished = true; // Round is skipped if no one finishes only in cup mode
 | 
					 | 
				
			||||||
								} elseif ($this->currentgmbase == "Rounds" ) {
 | 
					 | 
				
			||||||
									$this->currentscore = array_merge($this->currentscore, array(array($rank, $player->login, ($points + $roundpoints), $roundpoints, $time, "-1")));
 | 
					 | 
				
			||||||
								} elseif ($this->currentgmbase == "Teams") {
 | 
					 | 
				
			||||||
									$this->currentscore = array_merge($this->currentscore, array(array($rank, $player->login, ($points + $roundpoints), $roundpoints, $time, $player->teamId)));
 | 
					 | 
				
			||||||
								} elseif ($this->currentgmbase == "Knockout") {
 | 
					 | 
				
			||||||
									$this->currentscore = array_merge($this->currentscore, array(array($rank, $player->login, $points, "-1", $time, "-1"))); //TODO check
 | 
					 | 
				
			||||||
								}
 | 
					 | 
				
			||||||
							} elseif (in_array($this->currentgmbase, ["Laps", "TimeAttack", "RoyalTimeAttack"]) && !(($time == 0 || $time == -1) && ($player->isSpectator || $player->isFakePlayer()))) {
 | 
					 | 
				
			||||||
								$besttime = $result->getBestRaceTime();
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
								if  ($this->currentgmbase == "RoyalTimeAttack") {
 | 
														unset($this->preendroundscore[$k]);
 | 
				
			||||||
									$this->maniaControl->getChat()->sendErrorToAdmins($this->chatprefix . "No data are save in RoyalTimeAttack for the moment, it's not implemented on server side. Waiting a fix from NADEO");
 | 
														break;
 | 
				
			||||||
									Logger::Log("No data are save in RoyalTimeAttack for the moment, it's not implemented on server side. Waiting a fix from NADEO");
 | 
					 | 
				
			||||||
								}
 | 
					 | 
				
			||||||
								if ($this->currentgmbase == "Laps" || $this->currentgmbase == "RoyalTimeAttack") {
 | 
					 | 
				
			||||||
									$nbcp = count($result->getBestRaceCheckpoints());
 | 
					 | 
				
			||||||
									$this->currentscore = array_merge($this->currentscore, array(array($rank, $player->login, $nbcp, "-1", $besttime, "-1")));
 | 
					 | 
				
			||||||
								} elseif ($this->currentgmbase == "TimeAttack") {
 | 
					 | 
				
			||||||
									$this->currentscore = array_merge($this->currentscore, array(array($rank, $player->login, "-1", "-1", $besttime, "-1")));
 | 
					 | 
				
			||||||
								}
 | 
													}
 | 
				
			||||||
							}
 | 
												}
 | 
				
			||||||
 | 
											}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
											$this->currentscore = array_merge($this->currentscore, array(
 | 
				
			||||||
 | 
												array($rank, $player->login, $matchpoints, $mappoints, $roundpoints, $bestracetime, $bestracecheckpoints, $bestlaptime, $bestlapcheckpoints, $prevracetime, $prevracecheckpoints, $player->teamId)
 | 
				
			||||||
 | 
											));
 | 
				
			||||||
 | 
										}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
										//
 | 
				
			||||||
 | 
										// Teams Scores
 | 
				
			||||||
 | 
										//
 | 
				
			||||||
 | 
										$this->currentteamsscore = array();
 | 
				
			||||||
 | 
										$teamresults = $structure->getTeamScores();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
										if (count($teamresults) > 1) {
 | 
				
			||||||
 | 
											// Resort scores
 | 
				
			||||||
 | 
											usort($teamresults, function ($a, $b) { return -($a->getMatchPoints() <=> $b->getMatchPoints()); });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
											$rank = 1;
 | 
				
			||||||
 | 
											foreach ($teamresults as $teamresult) {
 | 
				
			||||||
 | 
												$teamid					= $teamresult->getTeamId();
 | 
				
			||||||
 | 
												$teamname				= $teamresult->getName();
 | 
				
			||||||
 | 
												$matchpoints			= $teamresult->getMatchPoints();
 | 
				
			||||||
 | 
												$mappoints				= $teamresult->getMapPoints();
 | 
				
			||||||
 | 
												$roundpoints			= $teamresult->getRoundPoints();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
												$this->currentteamsscore = array_merge($this->currentteamsscore, array(
 | 
				
			||||||
 | 
													array($rank, $teamid, $teamname, $matchpoints, $mappoints, $roundpoints)
 | 
				
			||||||
 | 
												));
 | 
				
			||||||
							$rank++;
 | 
												$rank++;
 | 
				
			||||||
						}
 | 
											}
 | 
				
			||||||
 | 
					 | 
				
			||||||
						if (!$this->pauseon && !$this->skipround) {
 | 
					 | 
				
			||||||
							if ($this->currentgmbase != "Cup" || ($this->currentgmbase == "Cup" && isset($atleastonefinished) && $atleastonefinished)) { // Round is skipped if no one finishes only in cup mode
 | 
					 | 
				
			||||||
								$this->nbrounds++;
 | 
					 | 
				
			||||||
							}
 | 
					 | 
				
			||||||
						}
 | 
					 | 
				
			||||||
						if ($this->skipround) {
 | 
					 | 
				
			||||||
							$this->skipround = false;
 | 
					 | 
				
			||||||
						}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
						if ($this->currentgmbase == "Knockout" && $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MATCH_S_ROUNDSWITHOUTELIMINATION) <= $this->nbrounds && $this->nbmaps == 1) {
 | 
					 | 
				
			||||||
							Logger::log("Round without elimination");
 | 
					 | 
				
			||||||
						}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
						// MYSQL DATA INSERT
 | 
					 | 
				
			||||||
						$settings = json_encode($this->maniaControl->getClient()->getModeScriptSettings());
 | 
					 | 
				
			||||||
						$mysqli = $this->maniaControl->getDatabase()->getMysqli();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
						$query = 'INSERT INTO `' . self::DB_ROUNDSINDEX . '` 
 | 
					 | 
				
			||||||
							(`matchid`,`timestamp`,`nbmaps`,`nbrounds`,`settings`,`map`,`nbplayers`,`nbspectators`)
 | 
					 | 
				
			||||||
							VALUES
 | 
					 | 
				
			||||||
							("'. $this->matchid . '","' . $timestamp . '","' . $this->nbmaps . '","' . $this->nbrounds . '",' . "'" . $settings . "'" . ',"' . $this->currentmap->uid . '","' . $this->maniaControl->getPlayerManager()->getPlayerCount() . '","' . $this->maniaControl->getPlayerManager()->getSpectatorCount() . '")';
 | 
					 | 
				
			||||||
						$mysqli->query($query);
 | 
					 | 
				
			||||||
						if ($mysqli->error) {
 | 
					 | 
				
			||||||
							trigger_error($mysqli->error);
 | 
					 | 
				
			||||||
						}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
						// Round data
 | 
					 | 
				
			||||||
						foreach ($this->currentscore as $value) {
 | 
					 | 
				
			||||||
							$dbquery .= '("' . $this->matchid . '","' . $timestamp . '","' . implode('","',$value) . '"),';
 | 
					 | 
				
			||||||
						}
 | 
					 | 
				
			||||||
						$dbquery = substr($dbquery, 0, -1);
 | 
					 | 
				
			||||||
						$mysqli->query($dbquery);
 | 
					 | 
				
			||||||
						if ($mysqli->error) {
 | 
					 | 
				
			||||||
							trigger_error($mysqli->error);
 | 
					 | 
				
			||||||
						}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
						Logger::log("Rounds finished: " . $this->nbrounds);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
						// Trigger Callback
 | 
					 | 
				
			||||||
						$this->maniaControl->getCallbackManager()->triggerCallback(self::CB_MATCHMANAGER_ENDROUND, $this->matchid, $this->currentscore, []);
 | 
					 | 
				
			||||||
					}
 | 
										}
 | 
				
			||||||
				} elseif ($structure->getSection() == "EndRound" && $this->currentgmbase == "Teams") {
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
					// Teams Specific variables
 | 
										//
 | 
				
			||||||
					$teamresults = $structure->getTeamScores();
 | 
										// End Round Routines
 | 
				
			||||||
					$this->currentteamsscore = array();
 | 
										//
 | 
				
			||||||
 | 
										$this->preendroundscore = array();
 | 
				
			||||||
					// Resort scores
 | 
										if (!$this->pauseon && !$this->skipround) {
 | 
				
			||||||
					usort($results, function ($a, $b) { return -($a->getMatchPoints() <=> $b->getMatchPoints()); });
 | 
											if ($this->currentgmbase != "Cup" || ($this->currentgmbase == "Cup" && isset($atleastonefinished) && $atleastonefinished)) { // Round is skipped if no one finishes only in cup mode
 | 
				
			||||||
 | 
												$this->nbrounds++;
 | 
				
			||||||
					$teamdbquery = 'INSERT INTO `' . self::DB_TEAMSDATA . '` (`matchid`,`timestamp`,`id`,`team`,`points`) VALUES ';
 | 
											}
 | 
				
			||||||
					$this->currentteamsscore = [];
 | 
										}
 | 
				
			||||||
					$rank = 1;
 | 
										if ($this->skipround) {
 | 
				
			||||||
 | 
											$this->skipround = false;
 | 
				
			||||||
					foreach ($teamresults as $teamresult) {
 | 
					 | 
				
			||||||
						$this->currentteamsscore = array_merge($this->currentteamsscore, array(array($rank, $teamresult->getTeamId(), $teamresult->getName(), $teamresult->getMatchPoints())));
 | 
					 | 
				
			||||||
						$teamdbquery .= '("' . $this->matchid . '","' . $timestamp . '","' . $teamresult->getTeamId() . '","' . $teamresult->getName() . '","' . $teamresult->getMatchPoints() . '"),';
 | 
					 | 
				
			||||||
						$rank++;
 | 
					 | 
				
			||||||
					}
 | 
										}
 | 
				
			||||||
					$teamdbquery = substr($teamdbquery, 0, -1);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
										if ($this->currentgmbase == "Knockout" && $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MATCH_S_ROUNDSWITHOUTELIMINATION) <= $this->nbrounds && $this->nbmaps == 1) {
 | 
				
			||||||
 | 
											Logger::log("Round without elimination");
 | 
				
			||||||
 | 
										}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
										//
 | 
				
			||||||
 | 
										// MySQL queries
 | 
				
			||||||
 | 
										//
 | 
				
			||||||
 | 
										$settings = json_encode($this->maniaControl->getClient()->getModeScriptSettings());
 | 
				
			||||||
					$mysqli = $this->maniaControl->getDatabase()->getMysqli();
 | 
										$mysqli = $this->maniaControl->getDatabase()->getMysqli();
 | 
				
			||||||
					// Teams data
 | 
					
 | 
				
			||||||
					$mysqli->query($teamdbquery);
 | 
										$query = 'INSERT INTO `' . self::DB_ROUNDSINDEX . '`
 | 
				
			||||||
 | 
											(`matchid`,`timestamp`,`nbmaps`,`nbrounds`,`settings`,`map`,`nbplayers`,`nbspectators`)
 | 
				
			||||||
 | 
											VALUES
 | 
				
			||||||
 | 
											("'. $this->matchid . '","' . $timestamp . '","' . $this->nbmaps . '","' . $this->nbrounds . '",' . "'" . $settings . "'" . ',"' . $this->currentmap->uid . '","' . $this->maniaControl->getPlayerManager()->getPlayerCount() . '","' . $this->maniaControl->getPlayerManager()->getSpectatorCount() . '")';
 | 
				
			||||||
 | 
										$mysqli->query($query);
 | 
				
			||||||
					if ($mysqli->error) {
 | 
										if ($mysqli->error) {
 | 
				
			||||||
						trigger_error($mysqli->error);
 | 
											trigger_error($mysqli->error);
 | 
				
			||||||
					}
 | 
										}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
										// Round data
 | 
				
			||||||
 | 
										$dbquery = 'INSERT INTO `' . self::DB_ROUNDSDATA . '` (`matchid`,`timestamp`,`rank`,`login`,`matchpoints`,`mappoints`,`roundpoints`,`bestracetime`,`bestracecheckpoints`,`bestlaptime`,`bestlapcheckpoints`,`prevracetime`,`prevracecheckpoints`,`teamid`) VALUES ';
 | 
				
			||||||
 | 
										foreach ($this->currentscore as $value) {
 | 
				
			||||||
 | 
											$dbquery .= '("' . $this->matchid . '","' . $timestamp . '","' . implode('","',$value) . '"),';
 | 
				
			||||||
 | 
										}
 | 
				
			||||||
 | 
										$dbquery = substr($dbquery, 0, -1);
 | 
				
			||||||
 | 
										$mysqli->query($dbquery);
 | 
				
			||||||
 | 
										if ($mysqli->error) {
 | 
				
			||||||
 | 
											trigger_error($mysqli->error);
 | 
				
			||||||
 | 
										}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
										// Teams Rounds data
 | 
				
			||||||
 | 
										if (count($teamresults) > 1) {
 | 
				
			||||||
 | 
											$teamdbquery = 'INSERT INTO `' . self::DB_TEAMSDATA . '` (`matchid`,`timestamp`,`rank`,`id`,`team`,`matchpoints`,`mappoints`,`roundpoints`) VALUES ';
 | 
				
			||||||
 | 
											foreach ($this->currentteamsscore as $value) {
 | 
				
			||||||
 | 
												$teamdbquery .= '("' . $this->matchid . '","' . $timestamp . '","' . implode('","',$value) . '"),';
 | 
				
			||||||
 | 
											}
 | 
				
			||||||
 | 
											$teamdbquery = substr($teamdbquery, 0, -1);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
											$mysqli = $this->maniaControl->getDatabase()->getMysqli();
 | 
				
			||||||
 | 
											// Teams data
 | 
				
			||||||
 | 
											$mysqli->query($teamdbquery);
 | 
				
			||||||
 | 
											if ($mysqli->error) {
 | 
				
			||||||
 | 
												trigger_error($mysqli->error);
 | 
				
			||||||
 | 
											}
 | 
				
			||||||
 | 
										}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
										Logger::log("Rounds finished: " . $this->nbrounds);
 | 
				
			||||||
					$this->maniaControl->getCallbackManager()->triggerCallback(self::CB_MATCHMANAGER_ENDROUND, $this->matchid, $this->currentscore, $this->currentteamsscore);
 | 
										$this->maniaControl->getCallbackManager()->triggerCallback(self::CB_MATCHMANAGER_ENDROUND, $this->matchid, $this->currentscore, $this->currentteamsscore);
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -426,7 +426,7 @@ class MatchManagerGSheet implements  CallbackListener, CommandListener, Plugin {
 | 
				
			|||||||
			$data->data[2]->values = $currentscore;
 | 
								$data->data[2]->values = $currentscore;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			$data->data[3] = new \stdClass;
 | 
								$data->data[3] = new \stdClass;
 | 
				
			||||||
			$data->data[3]->range = "'" . $sheetname . "'!K2";
 | 
								$data->data[3]->range = "'" . $sheetname . "'!Q2";
 | 
				
			||||||
			$data->data[3]->values = $currentteamsscore;
 | 
								$data->data[3]->values = $currentteamsscore;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			$asyncHttpRequest = new AsyncHttpRequest($this->maniaControl, 'https://sheets.googleapis.com/v4/spreadsheets/' . $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MATCHMANAGERGSHEET_SPREADSHEET) . '/values:batchUpdate');
 | 
								$asyncHttpRequest = new AsyncHttpRequest($this->maniaControl, 'https://sheets.googleapis.com/v4/spreadsheets/' . $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MATCHMANAGERGSHEET_SPREADSHEET) . '/values:batchUpdate');
 | 
				
			||||||
@@ -589,7 +589,7 @@ class MatchManagerGSheet implements  CallbackListener, CommandListener, Plugin {
 | 
				
			|||||||
			$data->requests[$i]->repeatCell->range->startRowIndex = 0;
 | 
								$data->requests[$i]->repeatCell->range->startRowIndex = 0;
 | 
				
			||||||
			$data->requests[$i]->repeatCell->range->endRowIndex = 1;
 | 
								$data->requests[$i]->repeatCell->range->endRowIndex = 1;
 | 
				
			||||||
			$data->requests[$i]->repeatCell->range->startColumnIndex = 3;
 | 
								$data->requests[$i]->repeatCell->range->startColumnIndex = 3;
 | 
				
			||||||
			$data->requests[$i]->repeatCell->range->endColumnIndex = 9;
 | 
								$data->requests[$i]->repeatCell->range->endColumnIndex = 15;
 | 
				
			||||||
			$data->requests[$i]->repeatCell->cell = new \stdClass;
 | 
								$data->requests[$i]->repeatCell->cell = new \stdClass;
 | 
				
			||||||
			$data->requests[$i]->repeatCell->cell->userEnteredFormat = new \stdClass;
 | 
								$data->requests[$i]->repeatCell->cell->userEnteredFormat = new \stdClass;
 | 
				
			||||||
			$data->requests[$i]->repeatCell->cell->userEnteredFormat->backgroundColor = new \stdClass;
 | 
								$data->requests[$i]->repeatCell->cell->userEnteredFormat->backgroundColor = new \stdClass;
 | 
				
			||||||
@@ -609,8 +609,8 @@ class MatchManagerGSheet implements  CallbackListener, CommandListener, Plugin {
 | 
				
			|||||||
			$data->requests[$i]->repeatCell->range->sheetId = $sheetid;
 | 
								$data->requests[$i]->repeatCell->range->sheetId = $sheetid;
 | 
				
			||||||
			$data->requests[$i]->repeatCell->range->startRowIndex = 0;
 | 
								$data->requests[$i]->repeatCell->range->startRowIndex = 0;
 | 
				
			||||||
			$data->requests[$i]->repeatCell->range->endRowIndex = 1;
 | 
								$data->requests[$i]->repeatCell->range->endRowIndex = 1;
 | 
				
			||||||
			$data->requests[$i]->repeatCell->range->startColumnIndex = 10;
 | 
								$data->requests[$i]->repeatCell->range->startColumnIndex = 16;
 | 
				
			||||||
			$data->requests[$i]->repeatCell->range->endColumnIndex = 14;
 | 
								$data->requests[$i]->repeatCell->range->endColumnIndex = 22;
 | 
				
			||||||
			$data->requests[$i]->repeatCell->cell = new \stdClass;
 | 
								$data->requests[$i]->repeatCell->cell = new \stdClass;
 | 
				
			||||||
			$data->requests[$i]->repeatCell->cell->userEnteredFormat = new \stdClass;
 | 
								$data->requests[$i]->repeatCell->cell->userEnteredFormat = new \stdClass;
 | 
				
			||||||
			$data->requests[$i]->repeatCell->cell->userEnteredFormat->backgroundColor = new \stdClass;
 | 
								$data->requests[$i]->repeatCell->cell->userEnteredFormat->backgroundColor = new \stdClass;
 | 
				
			||||||
@@ -633,7 +633,7 @@ class MatchManagerGSheet implements  CallbackListener, CommandListener, Plugin {
 | 
				
			|||||||
					Logger::logError('Error while Sending data: ' . print_r($error, true));
 | 
										Logger::logError('Error while Sending data: ' . print_r($error, true));
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
				// Clear Scoreboards data
 | 
									// Clear Scoreboards data
 | 
				
			||||||
				$asyncHttpRequest = new AsyncHttpRequest($this->maniaControl, 'https://sheets.googleapis.com/v4/spreadsheets/' . $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MATCHMANAGERGSHEET_SPREADSHEET) . '/values/' . urlencode("'". $sheetname . "'") . '!A1:N300:clear');
 | 
									$asyncHttpRequest = new AsyncHttpRequest($this->maniaControl, 'https://sheets.googleapis.com/v4/spreadsheets/' . $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MATCHMANAGERGSHEET_SPREADSHEET) . '/values/' . urlencode("'". $sheetname . "'") . '!A1:V300:clear');
 | 
				
			||||||
				$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) {
 | 
				
			||||||
					$data = json_decode($json);
 | 
										$data = json_decode($json);
 | 
				
			||||||
@@ -650,11 +650,11 @@ class MatchManagerGSheet implements  CallbackListener, CommandListener, Plugin {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
					$data->data[1] = new \stdClass;
 | 
										$data->data[1] = new \stdClass;
 | 
				
			||||||
					$data->data[1]->range = "'" . $sheetname . "'!D1";
 | 
										$data->data[1]->range = "'" . $sheetname . "'!D1";
 | 
				
			||||||
					$data->data[1]->values = array(array("Rank","Login", "MatchPoints", "RoundPoints","Time","Team"));
 | 
										$data->data[1]->values = array(array("Rank","Login", "MatchPoints", "MapPoints", "RoundPoints","BestRaceTime","BestRaceCheckpoints","BestLaptime","BestLapCheckpoints","PrevRaceTime","PrevRaceCheckpoints","Team"));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
					$data->data[2] = new \stdClass;
 | 
										$data->data[2] = new \stdClass;
 | 
				
			||||||
					$data->data[2]->range = "'" . $sheetname . "'!K1";
 | 
										$data->data[2]->range = "'" . $sheetname . "'!Q1";
 | 
				
			||||||
					$data->data[2]->values = array(array("Rank","Team ID", "Name", "MatchPoints"));
 | 
										$data->data[2]->values = array(array("Rank","Team ID", "Name", "MatchPoints", "MapPoints", "RoundPoints"));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
					$asyncHttpRequest = new AsyncHttpRequest($this->maniaControl, 'https://sheets.googleapis.com/v4/spreadsheets/' . $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MATCHMANAGERGSHEET_SPREADSHEET) . '/values:batchUpdate');
 | 
										$asyncHttpRequest = new AsyncHttpRequest($this->maniaControl, 'https://sheets.googleapis.com/v4/spreadsheets/' . $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MATCHMANAGERGSHEET_SPREADSHEET) . '/values:batchUpdate');
 | 
				
			||||||
					$asyncHttpRequest->setContentType(AsyncHttpRequest::CONTENT_TYPE_JSON);
 | 
										$asyncHttpRequest->setContentType(AsyncHttpRequest::CONTENT_TYPE_JSON);
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -426,11 +426,20 @@ class MatchManagerWidget implements ManialinkPageAnswerListener, CallbackListene
 | 
				
			|||||||
			$pointlimit = $this->MatchManagerCore->getMatchPointsLimit();
 | 
								$pointlimit = $this->MatchManagerCore->getMatchPointsLimit();
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// Sort if possible
 | 
							if ($this->gmbase == "Teams") {
 | 
				
			||||||
		if (count($currentscore) > 1) {
 | 
								// Sort if possible
 | 
				
			||||||
			usort($currentscore, function($a, $b) {
 | 
								if (count($currentscore) > 1) {
 | 
				
			||||||
				return $b[2] - $a[2];
 | 
									usort($currentscore, function($a, $b) {
 | 
				
			||||||
			});
 | 
										return $b[3] - $a[3];
 | 
				
			||||||
 | 
									});
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							} else {
 | 
				
			||||||
 | 
								// Sort if possible
 | 
				
			||||||
 | 
								if (count($currentscore) > 1) {
 | 
				
			||||||
 | 
									usort($currentscore, function($a, $b) {
 | 
				
			||||||
 | 
										return $b[2] - $a[2];
 | 
				
			||||||
 | 
									});
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		$lines      = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MATCHMANAGERWIDGET_LIVE_LINESCOUNT);
 | 
							$lines      = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MATCHMANAGERWIDGET_LIVE_LINESCOUNT);
 | 
				
			||||||
@@ -451,11 +460,16 @@ class MatchManagerWidget implements ManialinkPageAnswerListener, CallbackListene
 | 
				
			|||||||
				break;
 | 
									break;
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			$points = $score[2];
 | 
								if ($this->gmbase == "Teams") {
 | 
				
			||||||
 | 
									$points = $score[3];
 | 
				
			||||||
 | 
								} else {
 | 
				
			||||||
 | 
									$points = $score[2];
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			if (isset($pointlimit)) {
 | 
								if (isset($pointlimit)) {
 | 
				
			||||||
				if ($score[2] > $pointlimit) {
 | 
									if ($points > $pointlimit) {
 | 
				
			||||||
					$points = '$0f0Winner';
 | 
										$points = '$0f0Winner';
 | 
				
			||||||
				} elseif ($score[2] == $pointlimit) {
 | 
									} elseif ($points == $pointlimit) {
 | 
				
			||||||
					$points = '$f00Finalist';
 | 
										$points = '$f00Finalist';
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user