improve logging

This commit is contained in:
Beu
2025-06-22 11:52:48 +02:00
parent 0fe9dc3e14
commit 9efa66ac5d

View File

@ -47,6 +47,8 @@ class MatchManagerCore implements CallbackListener, CommandListener, TimerListen
const PLUGIN_NAME = 'MatchManager Core'; const PLUGIN_NAME = 'MatchManager Core';
const PLUGIN_AUTHOR = 'Beu'; const PLUGIN_AUTHOR = 'Beu';
const LOG_PREFIX = '[MatchManagerCore] ';
// Specific const // Specific const
const DB_MATCHESINDEX = 'MatchManager_MatchesIndex'; const DB_MATCHESINDEX = 'MatchManager_MatchesIndex';
const DB_ROUNDSINDEX = 'MatchManager_RoundsIndex'; const DB_ROUNDSINDEX = 'MatchManager_RoundsIndex';
@ -699,6 +701,12 @@ class MatchManagerCore implements CallbackListener, CommandListener, TimerListen
/* /*
* MARK: Internal Functions * MARK: Internal Functions
*/ */
private function log(mixed $message) {
Logger::log(self::LOG_PREFIX . $message);
}
private function logError(mixed $message) {
Logger::logError(self::LOG_PREFIX . $message);
}
/** /**
* Reset match variables * Reset match variables
@ -706,11 +714,12 @@ class MatchManagerCore implements CallbackListener, CommandListener, TimerListen
* @param Setting $setting * @param Setting $setting
*/ */
public function resetMatchVariables() { public function resetMatchVariables() {
$this->log("Reset match variables");
$this->matchStarted = false; $this->matchStarted = false;
$this->matchrecover = false; $this->matchrecover = false;
$this->pauseon = false; $this->pauseon = false;
$this->pointstorecover = array(); $this->pointstorecover = array();
$this->currentscore = array(); // TODO CHECK $this->currentscore = array();
$this->preendroundscore = null; $this->preendroundscore = null;
$this->settingsloaded = false; $this->settingsloaded = false;
$this->mapsshuffled = false; $this->mapsshuffled = false;
@ -775,7 +784,7 @@ class MatchManagerCore implements CallbackListener, CommandListener, TimerListen
$stmt->bind_param('i', $limit); $stmt->bind_param('i', $limit);
if (!$stmt->execute()) { if (!$stmt->execute()) {
Logger::logError('Error executing MySQL query: '. $stmt->error); $this->logError('Error executing MySQL query: '. $stmt->error);
} }
$result = $stmt->get_result(); $result = $stmt->get_result();
@ -813,13 +822,13 @@ class MatchManagerCore implements CallbackListener, CommandListener, TimerListen
$this->maniaControl->getChat()->sendErrorToAdmins($this->chatprefix . 'It\'s not possible to choose to hide or display the maps during a match'); $this->maniaControl->getChat()->sendErrorToAdmins($this->chatprefix . 'It\'s not possible to choose to hide or display the maps during a match');
} else { } else {
if ($this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MATCH_SETTINGS_MODE) != 'All from file') { if ($this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MATCH_SETTINGS_MODE) != 'All from file') {
Logger::log("Load Script Settings"); $this->log("Load Script Settings");
try { try {
$this->loadGMSettings($this->getGMSettings($this->currentgmbase,$this->currentcustomgm)); $this->loadGMSettings($this->getGMSettings($this->currentgmbase,$this->currentcustomgm));
Logger::log("Parameters updated"); $this->log("Parameters updated");
$this->maniaControl->getChat()->sendSuccessToAdmins($this->chatprefix . 'Parameters updated'); $this->maniaControl->getChat()->sendSuccessToAdmins($this->chatprefix . 'Parameters updated');
} catch (InvalidArgumentException $e) { } catch (InvalidArgumentException $e) {
Logger::log("Parameters not updated"); $this->log("Parameters not updated");
$this->maniaControl->getChat()->sendErrorToAdmins($this->chatprefix . 'Parameters not updated'); $this->maniaControl->getChat()->sendErrorToAdmins($this->chatprefix . 'Parameters not updated');
} }
$this->updateGMvariables(); $this->updateGMvariables();
@ -844,7 +853,7 @@ class MatchManagerCore implements CallbackListener, CommandListener, TimerListen
$this->maniaControl->getChat()->sendErrorToAdmins($this->chatprefix . 'Unable to find the Post match Maplist file: "' . $setting->value . '"'); $this->maniaControl->getChat()->sendErrorToAdmins($this->chatprefix . 'Unable to find the Post match Maplist file: "' . $setting->value . '"');
} }
} else if ($setting->setting == self::SETTING_MODE_MAPS && $setting->value != "") { } else if ($setting->setting == self::SETTING_MODE_MAPS && $setting->value != "") {
$maps = explode(',', $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MODE_MAPS)); $maps = explode(',', $setting->value);
foreach ($maps as $map) { foreach ($maps as $map) {
try { try {
$this->maniaControl->getClient()->getMapInfo($map); $this->maniaControl->getClient()->getMapInfo($map);
@ -1012,7 +1021,7 @@ class MatchManagerCore implements CallbackListener, CommandListener, TimerListen
} }
} }
} else { } else {
Logger::logError("Impossible to read custom gamemode file"); $this->logError("Impossible to read custom gamemode file");
$this->maniaControl->getChat()->sendErrorToAdmins($this->chatprefix . " Impossible to read custom gamemode file"); $this->maniaControl->getChat()->sendErrorToAdmins($this->chatprefix . " Impossible to read custom gamemode file");
} }
} }
@ -1052,7 +1061,7 @@ class MatchManagerCore implements CallbackListener, CommandListener, TimerListen
* Load functionnal variables * Load functionnal variables
*/ */
public function updateGMvariables() { public function updateGMvariables() {
Logger::log("Updating internal variables"); $this->log("Updating internal variables");
$this->currentgmsettings = $this->maniaControl->getClient()->getModeScriptSettings(); $this->currentgmsettings = $this->maniaControl->getClient()->getModeScriptSettings();
if (isset($this->currentgmsettings[self::SETTING_MATCH_S_POINTSLIMIT])) { if (isset($this->currentgmsettings[self::SETTING_MATCH_S_POINTSLIMIT])) {
@ -1137,7 +1146,7 @@ class MatchManagerCore implements CallbackListener, CommandListener, TimerListen
if ($this->currentgmbase == "RoyalTimeAttack") { if ($this->currentgmbase == "RoyalTimeAttack") {
$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"); $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");
Logger::Log("No data are save in RoyalTimeAttack for the moment, it's not implemented on server side. Waiting a fix from NADEO"); $this->log("No data are save in RoyalTimeAttack for the moment, it's not implemented on server side. Waiting a fix from NADEO");
} }
// Prepare maps in case of "All from the plugin" mode // Prepare maps in case of "All from the plugin" mode
@ -1182,13 +1191,13 @@ class MatchManagerCore implements CallbackListener, CommandListener, TimerListen
$this->maniaControl->getChat()->sendSuccess($this->chatprefix . 'Match start with script ' . $scriptName . ' (based on ' . $this->currentgmbase . ')'); $this->maniaControl->getChat()->sendSuccess($this->chatprefix . 'Match start with script ' . $scriptName . ' (based on ' . $this->currentgmbase . ')');
} }
Logger::log("Match start with script " . $scriptName . '!'); $this->log("Match start with script " . $scriptName . '!');
$this->maniaControl->getClient()->setScriptName($scriptName); $this->maniaControl->getClient()->setScriptName($scriptName);
} }
// Must be after loading the script in case of different MapType // Must be after loading the script in case of different MapType
if ($this->currentsettingmode != 'All from the plugin') { if ($this->currentsettingmode != 'All from the plugin') {
Logger::log("Loading maplist + matchsettings"); $this->log("Loading maplist + matchsettings");
$maplist = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MODE_MAPLIST_FILE); $maplist = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MODE_MAPLIST_FILE);
if (empty($maplist)) { if (empty($maplist)) {
$server = $this->maniaControl->getServer()->login; $server = $this->maniaControl->getServer()->login;
@ -1196,7 +1205,7 @@ class MatchManagerCore implements CallbackListener, CommandListener, TimerListen
} else { } else {
$maplist = 'MatchSettings' . DIRECTORY_SEPARATOR . $maplist; $maplist = 'MatchSettings' . DIRECTORY_SEPARATOR . $maplist;
} }
Logger::log("Load matchsettings: " . $maplist); $this->log("Load matchsettings: " . $maplist);
if (!is_file($this->maniaControl->getServer()->getDirectory()->getMapsFolder() . $maplist)) { if (!is_file($this->maniaControl->getServer()->getDirectory()->getMapsFolder() . $maplist)) {
throw new \Exception("The Maplist file is not accessible or does not exist (the match has not started)"); throw new \Exception("The Maplist file is not accessible or does not exist (the match has not started)");
} }
@ -1217,17 +1226,17 @@ class MatchManagerCore implements CallbackListener, CommandListener, TimerListen
} }
} }
Logger::log("Restructure maplist"); $this->log("Restructure maplist");
$this->maniaControl->getMapManager()->restructureMapList(); $this->maniaControl->getMapManager()->restructureMapList();
$this->matchStarted = true; $this->matchStarted = true;
$this->nbmaps = 0; $this->nbmaps = 0;
$this->nbrounds = 0; $this->nbrounds = 0;
Logger::log("Get Players"); $this->log("Get Players");
$players = $this->maniaControl->getPlayerManager()->getPlayers(); $players = $this->maniaControl->getPlayerManager()->getPlayers();
Logger::log("Player State"); $this->log("Player State");
foreach ($players as $player) { foreach ($players as $player) {
$this->handlePlayerConnect($player); $this->handlePlayerConnect($player);
} }
@ -1242,7 +1251,7 @@ class MatchManagerCore implements CallbackListener, CommandListener, TimerListen
$stmt->bind_param('sssi', $this->matchid, $serverlogin, $this->currentgmbase, $timestamp); $stmt->bind_param('sssi', $this->matchid, $serverlogin, $this->currentgmbase, $timestamp);
if (!$stmt->execute()) { if (!$stmt->execute()) {
Logger::logError('Error executing MySQL query: '. $stmt->error); $this->logError('Error executing MySQL query: '. $stmt->error);
} }
// Trigger Callback // Trigger Callback
@ -1256,12 +1265,12 @@ class MatchManagerCore implements CallbackListener, CommandListener, TimerListen
$this->maniaControl->getCallbackManager()->triggerCallback(self::CB_MATCHMANAGER_STARTMATCH, $this->matchid, $settings); $this->maniaControl->getCallbackManager()->triggerCallback(self::CB_MATCHMANAGER_STARTMATCH, $this->matchid, $settings);
$this->updateAdminUIMenuItems(); $this->updateAdminUIMenuItems();
Logger::log("Skip map"); $this->log("Skip map");
$this->maniaControl->getMapManager()->getMapActions()->skipMap(); $this->maniaControl->getMapManager()->getMapActions()->skipMap();
} catch (Exception $e) { } catch (Exception $e) {
$this->resetMatchVariables(); $this->resetMatchVariables();
Logger::log($e->getMessage()); $this->logError("Can't start the match: ". $e->getMessage());
$this->maniaControl->getChat()->sendErrorToAdmins($this->chatprefix . $e->getMessage()); $this->maniaControl->getChat()->sendErrorToAdmins($this->chatprefix . "Can't start the match: ". $e->getMessage());
} }
} }
@ -1284,7 +1293,7 @@ class MatchManagerCore implements CallbackListener, CommandListener, TimerListen
$scriptname = "Trackmania/TM_RoyalTimeAttack_Online.Script.txt" ; $scriptname = "Trackmania/TM_RoyalTimeAttack_Online.Script.txt" ;
} }
if (isset($scriptname)) { if (isset($scriptname)) {
Logger::log("Loading script: " . $scriptname); $this->log("Loading script: " . $scriptname);
$this->maniaControl->getClient()->setScriptName($scriptname); $this->maniaControl->getClient()->setScriptName($scriptname);
} }
} }
@ -1299,7 +1308,7 @@ class MatchManagerCore implements CallbackListener, CommandListener, TimerListen
$stmt->bind_param('is', $timestamp, $this->matchid); $stmt->bind_param('is', $timestamp, $this->matchid);
if (!$stmt->execute()) { if (!$stmt->execute()) {
Logger::logError('Error executing MySQL query: '. $stmt->error); $this->logError('Error executing MySQL query: '. $stmt->error);
} }
// Match Result // Match Result
@ -1319,7 +1328,7 @@ class MatchManagerCore implements CallbackListener, CommandListener, TimerListen
list($rank, $login, $matchpoints, $mappoints, $roundpoints, $bestracetime, $bestracecheckpoints, $bestlaptime, $bestlapcheckpoints, $prevracetime, $prevracecheckpoints, $teamid) = $score; list($rank, $login, $matchpoints, $mappoints, $roundpoints, $bestracetime, $bestracecheckpoints, $bestlaptime, $bestlapcheckpoints, $prevracetime, $prevracecheckpoints, $teamid) = $score;
if (!$stmt->execute()) { if (!$stmt->execute()) {
Logger::logError('Error executing MySQL query: '. $stmt->error); $this->logError('Error executing MySQL query: '. $stmt->error);
} }
} }
$stmt->close(); $stmt->close();
@ -1335,7 +1344,7 @@ class MatchManagerCore implements CallbackListener, CommandListener, TimerListen
list($rank, $teamid, $teamname, $matchpoints) = $score; list($rank, $teamid, $teamname, $matchpoints) = $score;
if (!$stmt->execute()) { if (!$stmt->execute()) {
Logger::logError('Error executing MySQL query: '. $stmt->error); $this->logError('Error executing MySQL query: '. $stmt->error);
} }
} }
$stmt->close(); $stmt->close();
@ -1347,7 +1356,7 @@ 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("Match finished"); $this->log("Match finished");
$this->resetMatchVariables(); $this->resetMatchVariables();
$this->updateAdminUIMenuItems(); $this->updateAdminUIMenuItems();
@ -1356,7 +1365,8 @@ class MatchManagerCore implements CallbackListener, CommandListener, TimerListen
$this->currentteamsscore = []; $this->currentteamsscore = [];
} catch (Exception $e) { } catch (Exception $e) {
$this->maniaControl->getChat()->sendErrorToAdmins($this->chatprefix . 'Can not finish match: ' . $e->getMessage()); $this->maniaControl->getChat()->sendErrorToAdmins($this->chatprefix . "Can't finish the match: " . $e->getMessage());
$this->logError("Can't finish the match: ". $e->getMessage());
} }
} }
@ -1364,7 +1374,7 @@ class MatchManagerCore implements CallbackListener, CommandListener, TimerListen
* Function called to stop the match * Function called to stop the match
*/ */
public function MatchStop() { public function MatchStop() {
Logger::log("Match stop"); $this->log("Match stop");
if (!$this->matchStarted) { if (!$this->matchStarted) {
$this->maniaControl->getChat()->sendErrorToAdmins($this->chatprefix . " No match launched"); $this->maniaControl->getChat()->sendErrorToAdmins($this->chatprefix . " No match launched");
return; return;
@ -1395,7 +1405,7 @@ class MatchManagerCore implements CallbackListener, CommandListener, TimerListen
$scriptname = "Trackmania/TM_RoyalTimeAttack_Online.Script.txt" ; $scriptname = "Trackmania/TM_RoyalTimeAttack_Online.Script.txt" ;
} }
if (isset($scriptname)) { if (isset($scriptname)) {
Logger::log("Loading script: " . $scriptname); $this->log("Loading script: " . $scriptname);
$this->maniaControl->getClient()->setScriptName($scriptname); $this->maniaControl->getClient()->setScriptName($scriptname);
} }
} }
@ -1403,9 +1413,10 @@ class MatchManagerCore implements CallbackListener, CommandListener, TimerListen
$this->resetMatchVariables(); $this->resetMatchVariables();
$this->updateAdminUIMenuItems(); $this->updateAdminUIMenuItems();
} 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't stop the match: " . $e->getMessage());
$this->logError("Can't stop the match: ". $e->getMessage());
} }
Logger::log("Restarting map to load Gamemode"); $this->log("Restarting map to load Gamemode");
$this->maniaControl->getClient()->restartMap(); $this->maniaControl->getClient()->restartMap();
} }
@ -1414,14 +1425,14 @@ class MatchManagerCore implements CallbackListener, CommandListener, TimerListen
* @param integer $index * @param integer $index
*/ */
public function MatchRecover(int $index): bool { public function MatchRecover(int $index): bool {
Logger::log("Match Recover"); $this->log("Match Recover");
$mysqli = $this->maniaControl->getDatabase()->getMysqli(); $mysqli = $this->maniaControl->getDatabase()->getMysqli();
$stmt = $mysqli->prepare('SELECT `matchid`,`gamemodebase` FROM `' . self::DB_MATCHESINDEX . '` ORDER BY `started` DESC LIMIT ? , 1'); $stmt = $mysqli->prepare('SELECT `matchid`,`gamemodebase` FROM `' . self::DB_MATCHESINDEX . '` ORDER BY `started` DESC LIMIT ? , 1');
$stmt->bind_param('i', $index); $stmt->bind_param('i', $index);
if (!$stmt->execute()) { if (!$stmt->execute()) {
Logger::logError('Error executing MySQL query: '. $stmt->error); $this->logError('Error executing MySQL query: '. $stmt->error);
return false; return false;
} }
$result = $stmt->get_result(); $result = $stmt->get_result();
@ -1438,7 +1449,7 @@ class MatchManagerCore implements CallbackListener, CommandListener, TimerListen
$stmt->bind_param('s', $matchid); $stmt->bind_param('s', $matchid);
if (!$stmt->execute()) { if (!$stmt->execute()) {
Logger::logError('Error executing MySQL query: '. $stmt->error); $this->logError('Error executing MySQL query: '. $stmt->error);
return false; return false;
} }
$result = $stmt->get_result(); $result = $stmt->get_result();
@ -1460,7 +1471,7 @@ class MatchManagerCore implements CallbackListener, CommandListener, TimerListen
$stmt->bind_param('si', $matchid, $timestamp); $stmt->bind_param('si', $matchid, $timestamp);
if (!$stmt->execute()) { if (!$stmt->execute()) {
Logger::logError('Error executing MySQL query: '. $stmt->error); $this->logError('Error executing MySQL query: '. $stmt->error);
return false; return false;
} }
@ -1477,7 +1488,7 @@ class MatchManagerCore implements CallbackListener, CommandListener, TimerListen
} }
} }
$this->maniaControl->getChat()->sendSuccess($this->chatprefix . 'Recovering the match: ' . $matchid ); $this->maniaControl->getChat()->sendSuccess($this->chatprefix . 'Recovering the match: ' . $matchid );
Logger::log('Recovering the match: ' . $matchid); $this->log('Recovering the match: ' . $matchid);
$this->MatchStart(); $this->MatchStart();
return true; return true;
} else { } else {
@ -1505,7 +1516,7 @@ class MatchManagerCore implements CallbackListener, CommandListener, TimerListen
// Red Team // Red Team
$this->maniaControl->getModeScriptEventManager()->setTrackmaniaTeamPoints("1", "", $this->pointstorecover[1], $this->pointstorecover[1]); $this->maniaControl->getModeScriptEventManager()->setTrackmaniaTeamPoints("1", "", $this->pointstorecover[1], $this->pointstorecover[1]);
$this->maniaControl->getChat()->sendSuccess($this->chatprefix . '$<$ff0' . $this->pointstorecover[1] . '$> points recovered for the $<$f00Red$> Team'); $this->maniaControl->getChat()->sendSuccess($this->chatprefix . '$<$ff0' . $this->pointstorecover[1] . '$> points recovered for the $<$f00Red$> Team');
Logger::log("Point recovered: Blue " . $this->pointstorecover[0] . " - Red " . $this->pointstorecover[1]); $this->log("Point recovered: Blue " . $this->pointstorecover[0] . " - Red " . $this->pointstorecover[1]);
$this->pointstorecover = []; $this->pointstorecover = [];
} else { } else {
foreach ($this->pointstorecover as $index => $value) { foreach ($this->pointstorecover as $index => $value) {
@ -1524,7 +1535,7 @@ class MatchManagerCore implements CallbackListener, CommandListener, TimerListen
$this->maniaControl->getModeScriptEventManager()->setTrackmaniaPlayerPoints($player, "", "", $points); $this->maniaControl->getModeScriptEventManager()->setTrackmaniaPlayerPoints($player, "", "", $points);
$this->maniaControl->getChat()->sendSuccess($this->chatprefix . 'Your $<$ff0' . $value . '$> points have been recovered', $player); $this->maniaControl->getChat()->sendSuccess($this->chatprefix . 'Your $<$ff0' . $value . '$> points have been recovered', $player);
unset($this->pointstorecover[$index]); unset($this->pointstorecover[$index]);
Logger::log("Point recovered: " . $index . " " . $points . "(+" . $value . ")"); $this->log("Point recovered: " . $index . " " . $points . "(+" . $value . ")");
} }
} }
} }
@ -1546,7 +1557,7 @@ class MatchManagerCore implements CallbackListener, CommandListener, TimerListen
if ($this->currentgmbase == "RoyalTimeAttack") { if ($this->currentgmbase == "RoyalTimeAttack") {
$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"); $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");
Logger::Log("No data are save in RoyalTimeAttack for the moment, it's not implemented on server side. Waiting a fix from NADEO"); $this->logError("No data are save in RoyalTimeAttack for the moment, it's not implemented on server side. Waiting a fix from NADEO");
} }
$preendroundplayersscore = []; $preendroundplayersscore = [];
@ -1645,10 +1656,10 @@ class MatchManagerCore implements CallbackListener, CommandListener, TimerListen
public function setNadeoPause($admin = false, $time = null) { public function setNadeoPause($admin = false, $time = null) {
if ($this->pauseon) { if ($this->pauseon) {
$this->maniaControl->getChat()->sendErrorToAdmins($this->chatprefix . 'Can\'t launch pause, already running'); $this->maniaControl->getChat()->sendErrorToAdmins($this->chatprefix . 'Can\'t launch pause, already running');
Logger::logError('Can\'t launch pause, already running'); $this->logError('Can\'t launch pause, already running');
return; return;
} }
Logger::log("Launching Pause"); $this->log("Launching Pause");
if ($time === null) { if ($time === null) {
$this->pausetimer = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MATCH_PAUSE_DURATION); $this->pausetimer = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MATCH_PAUSE_DURATION);
@ -1674,7 +1685,7 @@ class MatchManagerCore implements CallbackListener, CommandListener, TimerListen
*/ */
private function unsetNadeoPause() { private function unsetNadeoPause() {
if ($this->pauseon) { if ($this->pauseon) {
Logger::log("End Pause"); $this->log("End Pause");
$this->closePauseWidget(); $this->closePauseWidget();
$this->pauseon = false; $this->pauseon = false;
$this->maniaControl->getModeScriptEventManager()->endPause(); $this->maniaControl->getModeScriptEventManager()->endPause();
@ -1765,14 +1776,14 @@ class MatchManagerCore implements CallbackListener, CommandListener, TimerListen
* Handle XMLRPC callback "Maniaplanet.StartMatch_Start" * Handle XMLRPC callback "Maniaplanet.StartMatch_Start"
*/ */
public function handleStartMatchStartCallback() { public function handleStartMatchStartCallback() {
Logger::log("handleStartMatchStartCallback"); $this->log("handleStartMatchStartCallback");
if ($this->matchStarted) { if ($this->matchStarted) {
Logger::log("Loading settings"); $this->log("Loading settings");
$this->settingsloaded = true; $this->settingsloaded = true;
if ($this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MATCH_SETTINGS_MODE) != 'All from file') { if ($this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MATCH_SETTINGS_MODE) != 'All from file') {
Logger::log("Load Script Settings"); $this->log("Load Script Settings");
$this->loadGMSettings($this->getGMSettings($this->currentgmbase, $this->currentcustomgm)); $this->loadGMSettings($this->getGMSettings($this->currentgmbase, $this->currentcustomgm));
} }
@ -1780,7 +1791,7 @@ class MatchManagerCore implements CallbackListener, CommandListener, TimerListen
} else if ($this->postmatch) { } else if ($this->postmatch) {
$this->postmatch = false; $this->postmatch = false;
Logger::log("Load PostMatch Gamemode Settings"); $this->log("Load PostMatch Gamemode Settings");
$maplist = 'MatchSettings' . DIRECTORY_SEPARATOR . $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MATCH_POST_MATCH_MAPLIST); $maplist = 'MatchSettings' . DIRECTORY_SEPARATOR . $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MATCH_POST_MATCH_MAPLIST);
if (is_file($this->maniaControl->getServer()->getDirectory()->getMapsFolder() . $maplist)) { if (is_file($this->maniaControl->getServer()->getDirectory()->getMapsFolder() . $maplist)) {
$this->maniaControl->getClient()->loadMatchSettings($maplist); $this->maniaControl->getClient()->loadMatchSettings($maplist);
@ -1807,18 +1818,18 @@ class MatchManagerCore implements CallbackListener, CommandListener, TimerListen
* Handle Maniacontrol callback "BeginMatch" * Handle Maniacontrol callback "BeginMatch"
*/ */
public function handleBeginMatchCallback() { public function handleBeginMatchCallback() {
Logger::log("handleBeginMatchCallback"); $this->log("handleBeginMatchCallback");
if ($this->matchStarted && !$this->settingsloaded) { if ($this->matchStarted && !$this->settingsloaded) {
Logger::log("Restarting map to restart match data"); $this->log("Restarting map to restart match data");
$this->maniaControl->getClient()->restartMap(); $this->maniaControl->getClient()->restartMap();
} else if ($this->matchStarted && $this->settingsloaded && $this->nbrounds == 0) { } else if ($this->matchStarted && $this->settingsloaded && $this->nbrounds == 0) {
Logger::Log("Check if Points Repartition need to be re-applied"); $this->log("Check if Points Repartition need to be re-applied");
$this->maniaControl->getModeScriptEventManager()->getTrackmaniaPointsRepartition()->setCallable(function (OnPointsRepartitionStructure $structure) { $this->maniaControl->getModeScriptEventManager()->getTrackmaniaPointsRepartition()->setCallable(function (OnPointsRepartitionStructure $structure) {
$currentgmsettings = $this->maniaControl->getClient()->getModeScriptSettings(); $currentgmsettings = $this->maniaControl->getClient()->getModeScriptSettings();
if (!is_null($this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MATCH_S_POINTSREPARTITION)) && isset($currentgmsettings[self::SETTING_MATCH_S_POINTSREPARTITION])) { if (!is_null($this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MATCH_S_POINTSREPARTITION)) && isset($currentgmsettings[self::SETTING_MATCH_S_POINTSREPARTITION])) {
$pointrepartitionarray = explode(",", $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MATCH_S_POINTSREPARTITION)); $pointrepartitionarray = explode(",", $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MATCH_S_POINTSREPARTITION));
if ($structure->getPointsRepartition() != $pointrepartitionarray) { if ($structure->getPointsRepartition() != $pointrepartitionarray) {
Logger::Log("re-applying Points Repartition for workaround"); $this->log("re-applying Points Repartition for workaround");
$newpoints = array(self::SETTING_MATCH_S_POINTSREPARTITION => $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MATCH_S_POINTSREPARTITION) . ',' . end($pointrepartitionarray)); $newpoints = array(self::SETTING_MATCH_S_POINTSREPARTITION => $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MATCH_S_POINTSREPARTITION) . ',' . end($pointrepartitionarray));
$this->maniaControl->getClient()->setModeScriptSettings($newpoints); $this->maniaControl->getClient()->setModeScriptSettings($newpoints);
} }
@ -1831,7 +1842,7 @@ class MatchManagerCore implements CallbackListener, CommandListener, TimerListen
* Handle Maniacontrol callback "BeginMap" * Handle Maniacontrol callback "BeginMap"
*/ */
public function handleBeginMapCallback() { public function handleBeginMapCallback() {
Logger::log("handleBeginMapCallback"); $this->log("handleBeginMapCallback");
if ($this->matchStarted) { if ($this->matchStarted) {
$this->nbmaps++; $this->nbmaps++;
$this->nbrounds = 0; $this->nbrounds = 0;
@ -1841,7 +1852,7 @@ class MatchManagerCore implements CallbackListener, CommandListener, TimerListen
$totalnbmaps = $this->maniaControl->getMapManager()->getMapsCount(); $totalnbmaps = $this->maniaControl->getMapManager()->getMapsCount();
$this->currentmap = $this->maniaControl->getMapManager()->getCurrentMap(); $this->currentmap = $this->maniaControl->getMapManager()->getCurrentMap();
Logger::log("Current Map: " . Formatter::stripCodes($this->currentmap->name)); $this->log("Current Map: " . Formatter::stripCodes($this->currentmap->name));
$message = $this->chatprefix . '$<$o$iCurrent Map:$>' . "\n"; $message = $this->chatprefix . '$<$o$iCurrent Map:$>' . "\n";
$message .= Formatter::stripCodes($this->currentmap->name); $message .= Formatter::stripCodes($this->currentmap->name);
$this->maniaControl->getChat()->sendInformation($message); $this->maniaControl->getChat()->sendInformation($message);
@ -1867,7 +1878,7 @@ class MatchManagerCore implements CallbackListener, CommandListener, TimerListen
$nbhiddenmaps = count($this->maps) - $totalnbmaps; $nbhiddenmaps = count($this->maps) - $totalnbmaps;
} }
$message .= "\nThen " . $nbhiddenmaps . " hidden maps"; $message .= "\nThen " . $nbhiddenmaps . " hidden maps";
Logger::log("Then " . $nbhiddenmaps . " hidden maps"); $this->log("Then " . $nbhiddenmaps . " hidden maps");
} }
} }
@ -1880,10 +1891,10 @@ class MatchManagerCore implements CallbackListener, CommandListener, TimerListen
if ($index != $i) { if ($index != $i) {
$message .= "\n" . $j . ": " . Formatter::stripCodes($maps[$index]->name); $message .= "\n" . $j . ": " . Formatter::stripCodes($maps[$index]->name);
Logger::log(Formatter::stripCodes($index . ": " . $maps[$index]->name)); $this->log(Formatter::stripCodes($index . ": " . $maps[$index]->name));
} else { } else {
$message .= "\nThen we will return to this map"; $message .= "\nThen we will return to this map";
Logger::log("Then we will return to this map"); $this->log("Then we will return to this map");
$j = 0; $j = 0;
break; break;
} }
@ -1891,11 +1902,11 @@ class MatchManagerCore implements CallbackListener, CommandListener, TimerListen
if ($j + $nbhiddenmaps >= 4) { if ($j + $nbhiddenmaps >= 4) {
if ($this->settings_nbmapsbymatch > 0 && $this->settings_nbmapsbymatch - $j - $nbhiddenmaps - $this->nbmaps + 1 > 0) { 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"; $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"); $this->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)) { } 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); $n = max($totalnbmaps - $j - $nbhiddenmaps, count($this->maps) - $j - $nbhiddenmaps);
$message .= "\n" . "And " . $n . " more maps"; $message .= "\n" . "And " . $n . " more maps";
Logger::log("And " . $n . " more maps"); $this->log("And " . $n . " more maps");
} }
} }
$this->maniaControl->getChat()->sendInformation($message); $this->maniaControl->getChat()->sendInformation($message);
@ -1915,7 +1926,7 @@ class MatchManagerCore implements CallbackListener, CommandListener, TimerListen
* Handle callback "WarmUp.StartRound" * Handle callback "WarmUp.StartRound"
*/ */
public function handleStartWarmUpCallback() { public function handleStartWarmUpCallback() {
Logger::log("handleStartWarmUpCallback"); $this->log("handleStartWarmUpCallback");
// Match Recover // Match Recover
if ($this->matchrecover) { if ($this->matchrecover) {
@ -1927,7 +1938,7 @@ class MatchManagerCore implements CallbackListener, CommandListener, TimerListen
* Handle callback "BeginRound" * Handle callback "BeginRound"
*/ */
public function handleBeginRoundCallback(StartEndStructure $structure) { public function handleBeginRoundCallback(StartEndStructure $structure) {
Logger::log("handleBeginRoundCallback"); $this->log("handleBeginRoundCallback");
if ($this->matchStarted && $this->nbmaps > 0) { if ($this->matchStarted && $this->nbmaps > 0) {
@ -1943,11 +1954,11 @@ class MatchManagerCore implements CallbackListener, CommandListener, TimerListen
$this->maniaControl->getModeScriptEventManager()->getPauseStatus()->setCallable(function (StatusCallbackStructure $structure) { $this->maniaControl->getModeScriptEventManager()->getPauseStatus()->setCallable(function (StatusCallbackStructure $structure) {
if ($structure->getActive()) { if ($structure->getActive()) {
$this->maniaControl->getChat()->sendSuccess($this->chatprefix . 'The match is currently on $<$F00pause$>!'); $this->maniaControl->getChat()->sendSuccess($this->chatprefix . 'The match is currently on $<$F00pause$>!');
Logger::log("Pause"); $this->log("Pause");
} else { } else {
if ($this->settings_nbroundsbymap > 1) { if ($this->settings_nbroundsbymap > 1) {
$this->maniaControl->getChat()->sendInformation($this->chatprefix . '$o$iRound: ' . $this->nbrounds . ' / ' . $this->settings_nbroundsbymap); $this->maniaControl->getChat()->sendInformation($this->chatprefix . '$o$iRound: ' . $this->nbrounds . ' / ' . $this->settings_nbroundsbymap);
Logger::log("Round: " . $this->nbrounds . ' / ' . $this->settings_nbroundsbymap); $this->log("Round: " . $this->nbrounds . ' / ' . $this->settings_nbroundsbymap);
} }
} }
}); });
@ -1967,10 +1978,10 @@ class MatchManagerCore implements CallbackListener, CommandListener, TimerListen
* @param OnScoresStructure $structure * @param OnScoresStructure $structure
*/ */
public function handleTrackmaniaScore(OnScoresStructure $structure) { public function handleTrackmaniaScore(OnScoresStructure $structure) {
Logger::log("handleTrackmaniaScore-" . $structure->getSection()); $this->log("handleTrackmaniaScore-" . $structure->getSection());
if ($this->matchStarted && $this->settingsloaded && !$this->postmatch) { if ($this->matchStarted && $this->settingsloaded && !$this->postmatch) {
Logger::log("Section: " . $structure->getSection()); $this->log("Section: " . $structure->getSection());
if ($structure->getSection() == "EndMatchEarly" || $structure->getSection() == "EndMatch") { if ($structure->getSection() == "EndMatchEarly" || $structure->getSection() == "EndMatch") {
$this->computeCurrentScores($structure); $this->computeCurrentScores($structure);
$this->MatchEnd(); $this->MatchEnd();
@ -1996,7 +2007,7 @@ class MatchManagerCore implements CallbackListener, CommandListener, TimerListen
VALUES (?, ?, ?, ?, ?, ?, ?, ?)'); VALUES (?, ?, ?, ?, ?, ?, ?, ?)');
$stmt->bind_param('siiissii', $this->matchid, $timestamp, $this->nbmaps, $this->nbrounds, $settings, $this->currentmap->uid, $playercount, $spectatorcount); $stmt->bind_param('siiissii', $this->matchid, $timestamp, $this->nbmaps, $this->nbrounds, $settings, $this->currentmap->uid, $playercount, $spectatorcount);
if (!$stmt->execute()) { if (!$stmt->execute()) {
Logger::logError('Error executing MySQL query: '. $stmt->error); $this->logError('Error executing MySQL query: '. $stmt->error);
} }
$stmt->close(); $stmt->close();
@ -2025,7 +2036,7 @@ class MatchManagerCore implements CallbackListener, CommandListener, TimerListen
list($rank, $login, $matchpoints, $mappoints, $roundpoints, $bestracetime, $bestracecheckpoints, $bestlaptime, $bestlapcheckpoints, $prevracetime, $prevracecheckpoints, $teamid) = $score; list($rank, $login, $matchpoints, $mappoints, $roundpoints, $bestracetime, $bestracecheckpoints, $bestlaptime, $bestlapcheckpoints, $prevracetime, $prevracecheckpoints, $teamid) = $score;
if (!$stmt->execute()) { if (!$stmt->execute()) {
Logger::logError('Error executing MySQL query: '. $stmt->error); $this->logError('Error executing MySQL query: '. $stmt->error);
} }
} }
$stmt->close(); $stmt->close();
@ -2041,14 +2052,14 @@ class MatchManagerCore implements CallbackListener, CommandListener, TimerListen
list($rank, $teamid, $teamname, $matchpoints, $mappoints, $roundpoints) = $score; list($rank, $teamid, $teamname, $matchpoints, $mappoints, $roundpoints) = $score;
if (!$stmt->execute()) { if (!$stmt->execute()) {
Logger::logError('Error executing MySQL query: '. $stmt->error); $this->logError('Error executing MySQL query: '. $stmt->error);
} }
} }
$stmt->close(); $stmt->close();
} }
$mysqli->commit(); $mysqli->commit();
Logger::log("Rounds finished: " . $this->nbrounds); $this->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);
} }
} }
@ -2175,7 +2186,7 @@ class MatchManagerCore implements CallbackListener, CommandListener, TimerListen
* @param \ManiaControl\Players\Player $player * @param \ManiaControl\Players\Player $player
*/ */
public function onCommandSetPause(array $chatCallback, Player $player) { public function onCommandSetPause(array $chatCallback, Player $player) {
Logger::log("Pause asked by admin"); $this->log("Pause asked by admin");
$authLevel = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MATCH_AUTHLEVEL); $authLevel = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MATCH_AUTHLEVEL);
if (!$this->maniaControl->getAuthenticationManager()->checkRight($player, AuthenticationManager::getAuthLevel($authLevel))) { if (!$this->maniaControl->getAuthenticationManager()->checkRight($player, AuthenticationManager::getAuthLevel($authLevel))) {
$this->maniaControl->getAuthenticationManager()->sendNotAllowed($player); $this->maniaControl->getAuthenticationManager()->sendNotAllowed($player);
@ -2284,7 +2295,7 @@ class MatchManagerCore implements CallbackListener, CommandListener, TimerListen
$stmt->bind_param('s', $target); $stmt->bind_param('s', $target);
if (!$stmt->execute()) { if (!$stmt->execute()) {
Logger::logError('Error executing MySQL query: '. $stmt->error); $this->logError('Error executing MySQL query: '. $stmt->error);
} }
$result = $stmt->get_result(); $result = $stmt->get_result();