Add support of EndMatch Callback for scores
This commit is contained in:
parent
01be9cc45f
commit
53e67eb0e1
@ -38,7 +38,7 @@ use ManiaControl\Callbacks\TimerListener; // for pause
|
|||||||
class MatchManagerCore implements CallbackListener, CommandListener, TimerListener, CommunicationListener, Plugin {
|
class MatchManagerCore implements CallbackListener, CommandListener, TimerListener, CommunicationListener, Plugin {
|
||||||
|
|
||||||
const PLUGIN_ID = 152;
|
const PLUGIN_ID = 152;
|
||||||
const PLUGIN_VERSION = 5.3;
|
const PLUGIN_VERSION = 5.4;
|
||||||
const PLUGIN_NAME = 'MatchManager Core';
|
const PLUGIN_NAME = 'MatchManager Core';
|
||||||
const PLUGIN_AUTHOR = 'Beu';
|
const PLUGIN_AUTHOR = 'Beu';
|
||||||
|
|
||||||
@ -47,6 +47,8 @@ class MatchManagerCore implements CallbackListener, CommandListener, TimerListen
|
|||||||
const DB_ROUNDSINDEX = 'MatchManager_RoundsIndex';
|
const DB_ROUNDSINDEX = 'MatchManager_RoundsIndex';
|
||||||
const DB_ROUNDSDATA = 'MatchManager_RoundsData';
|
const DB_ROUNDSDATA = 'MatchManager_RoundsData';
|
||||||
const DB_TEAMSDATA = 'MatchManager_TeamsData';
|
const DB_TEAMSDATA = 'MatchManager_TeamsData';
|
||||||
|
const DB_MATCHESRESULT = 'MatchManager_MatchesResult';
|
||||||
|
const DB_MATCHESTEAMSRESULT = 'MatchManager_MatchesTeamsResult';
|
||||||
const MLID_MATCH_PAUSE_WIDGET = 'Pause Widget';
|
const MLID_MATCH_PAUSE_WIDGET = 'Pause Widget';
|
||||||
|
|
||||||
// Internal Callback Trigger
|
// Internal Callback Trigger
|
||||||
@ -533,6 +535,30 @@ class MatchManagerCore implements CallbackListener, CommandListener, TimerListen
|
|||||||
if ($mysqli->error) {
|
if ($mysqli->error) {
|
||||||
trigger_error($mysqli->error, E_USER_ERROR);
|
trigger_error($mysqli->error, E_USER_ERROR);
|
||||||
}
|
}
|
||||||
|
$query = 'CREATE TABLE IF NOT EXISTS `' . self::DB_MATCHESRESULT . '` (
|
||||||
|
`matchid` VARCHAR(100) NOT NULL,
|
||||||
|
`timestamp` INT(10) NOT NULL,
|
||||||
|
`rank` INT(4) NOT NULL,
|
||||||
|
`login` VARCHAR(36) NOT NULL,
|
||||||
|
`matchpoints` INT(10) NOT NULL,
|
||||||
|
`teamid` INT(3) NOT NULL
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;';
|
||||||
|
$mysqli->query($query);
|
||||||
|
if ($mysqli->error) {
|
||||||
|
trigger_error($mysqli->error, E_USER_ERROR);
|
||||||
|
}
|
||||||
|
$query = 'CREATE TABLE IF NOT EXISTS `' . self::DB_MATCHESTEAMSRESULT . '` (
|
||||||
|
`matchid` VARCHAR(100) NOT NULL,
|
||||||
|
`timestamp` INT(10) NOT NULL,
|
||||||
|
`rank` INT(3) NOT NULL,
|
||||||
|
`id` INT(3) NOT NULL,
|
||||||
|
`team` VARCHAR(30) NOT NULL,
|
||||||
|
`matchpoints` INT(10) NOT NULL
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;';
|
||||||
|
$mysqli->query($query);
|
||||||
|
if ($mysqli->error) {
|
||||||
|
trigger_error($mysqli->error, E_USER_ERROR);
|
||||||
|
}
|
||||||
|
|
||||||
// Update table data
|
// Update table data
|
||||||
$mysqliconfig = $this->maniaControl->getDatabase()->getConfig();
|
$mysqliconfig = $this->maniaControl->getDatabase()->getConfig();
|
||||||
@ -1079,10 +1105,12 @@ class MatchManagerCore implements CallbackListener, CommandListener, TimerListen
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MYSQL DATA INSERT
|
||||||
$timestamp = time();
|
$timestamp = time();
|
||||||
|
|
||||||
// MYSQL DATA INSERT
|
|
||||||
$mysqli = $this->maniaControl->getDatabase()->getMysqli();
|
$mysqli = $this->maniaControl->getDatabase()->getMysqli();
|
||||||
|
$mysqli->begin_transaction();
|
||||||
|
|
||||||
$stmt = $mysqli->prepare('UPDATE `' . self::DB_MATCHESINDEX . '` SET `ended` = ? WHERE `matchid` = ?');
|
$stmt = $mysqli->prepare('UPDATE `' . self::DB_MATCHESINDEX . '` SET `ended` = ? WHERE `matchid` = ?');
|
||||||
$stmt->bind_param('is', $timestamp, $this->matchid);
|
$stmt->bind_param('is', $timestamp, $this->matchid);
|
||||||
|
|
||||||
@ -1090,6 +1118,46 @@ class MatchManagerCore implements CallbackListener, CommandListener, TimerListen
|
|||||||
Logger::logError('Error executing MySQL query: '. $stmt->error);
|
Logger::logError('Error executing MySQL query: '. $stmt->error);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Match Result
|
||||||
|
$stmt = $mysqli->prepare('INSERT INTO `' . self::DB_MATCHESRESULT . '`
|
||||||
|
(`matchid`,`timestamp`,`rank`,`login`,`matchpoints`,`teamid`)
|
||||||
|
VALUES (?, ?, ?, ?, ? ,?)');
|
||||||
|
$stmt->bind_param('siisii',
|
||||||
|
$this->matchid,
|
||||||
|
$timestamp,
|
||||||
|
$rank,
|
||||||
|
$login,
|
||||||
|
$matchpoints,
|
||||||
|
$teamid
|
||||||
|
);
|
||||||
|
|
||||||
|
foreach ($this->currentscore as $score) {
|
||||||
|
list($rank, $login, $matchpoints, $mappoints, $roundpoints, $bestracetime, $bestracecheckpoints, $bestlaptime, $bestlapcheckpoints, $prevracetime, $prevracecheckpoints, $teamid) = $score;
|
||||||
|
|
||||||
|
if (!$stmt->execute()) {
|
||||||
|
Logger::logError('Error executing MySQL query: '. $stmt->error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$stmt->close();
|
||||||
|
|
||||||
|
// Teams Rounds data
|
||||||
|
if (count($this->currentteamsscore) > 1) {
|
||||||
|
$stmt = $mysqli->prepare('INSERT INTO `' . self::DB_MATCHESTEAMSRESULT . '` (`matchid`,`timestamp`,`rank`,`id`,`team`,`matchpoints`)
|
||||||
|
VALUES (?, ?, ?, ?, ?, ?)');
|
||||||
|
$stmt->bind_param('siiisi', $this->matchid, $timestamp, $rank, $teamid, $teamname, $matchpoints);
|
||||||
|
|
||||||
|
|
||||||
|
foreach ($this->currentteamsscore as $score) {
|
||||||
|
list($rank, $teamid, $teamname, $matchpoints) = $score;
|
||||||
|
|
||||||
|
if (!$stmt->execute()) {
|
||||||
|
Logger::logError('Error executing MySQL query: '. $stmt->error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$stmt->close();
|
||||||
|
}
|
||||||
|
$mysqli->commit();
|
||||||
|
|
||||||
// Trigger Callback
|
// Trigger Callback
|
||||||
$this->maniaControl->getCallbackManager()->triggerCallback(self::CB_MATCHMANAGER_ENDMATCH, $this->matchid, $this->currentscore, $this->currentteamsscore);
|
$this->maniaControl->getCallbackManager()->triggerCallback(self::CB_MATCHMANAGER_ENDMATCH, $this->matchid, $this->currentscore, $this->currentteamsscore);
|
||||||
|
|
||||||
@ -1604,16 +1672,92 @@ class MatchManagerCore implements CallbackListener, CommandListener, TimerListen
|
|||||||
|
|
||||||
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() == "EndMatchEarly") {
|
if ($structure->getSection() == "EndMatchEarly" || $structure->getSection() == "EndMatch") {
|
||||||
|
$this->computeCurrentScores($structure);
|
||||||
$this->MatchEnd();
|
$this->MatchEnd();
|
||||||
} elseif ($structure->getSection() == "EndMap" && $this->hidenextmaps && isset($this->maps[$this->nbmaps])) {
|
} elseif ($structure->getSection() == "EndMap" && $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") {
|
} elseif ($structure->getSection() == "PreEndRound") {
|
||||||
$this->preendroundscore = $structure;
|
$this->preendroundscore = $structure;
|
||||||
} elseif ($structure->getSection() == "EndRound") {
|
} elseif ($structure->getSection() == "EndRound") {
|
||||||
$timestamp = time();
|
|
||||||
|
|
||||||
if ($this->nbmaps != 0 && ($this->nbrounds <= $this->settings_nbroundsbymap || $this->settings_nbroundsbymap <= 0)) {
|
if ($this->nbmaps != 0 && ($this->nbrounds <= $this->settings_nbroundsbymap || $this->settings_nbroundsbymap <= 0)) {
|
||||||
|
$this->computeCurrentScores($structure);
|
||||||
|
|
||||||
|
$timestamp = time();
|
||||||
|
$settings = json_encode($this->maniaControl->getClient()->getModeScriptSettings());
|
||||||
|
$mysqli = $this->maniaControl->getDatabase()->getMysqli();
|
||||||
|
|
||||||
|
$mysqli->begin_transaction();
|
||||||
|
|
||||||
|
$playercount = $this->maniaControl->getPlayerManager()->getPlayerCount();
|
||||||
|
$spectatorcount = $this->maniaControl->getPlayerManager()->getSpectatorCount();
|
||||||
|
|
||||||
|
$stmt = $mysqli->prepare('INSERT INTO `' . self::DB_ROUNDSINDEX . '`
|
||||||
|
(`matchid`,`timestamp`,`nbmaps`,`nbrounds`,`settings`,`map`,`nbplayers`,`nbspectators`)
|
||||||
|
VALUES (?, ?, ?, ?, ?, ?, ?, ?)');
|
||||||
|
$stmt->bind_param('siiissii', $this->matchid, $timestamp, $this->nbmaps, $this->nbrounds, $settings, $this->currentmap->uid, $playercount, $spectatorcount);
|
||||||
|
if (!$stmt->execute()) {
|
||||||
|
Logger::logError('Error executing MySQL query: '. $stmt->error);
|
||||||
|
}
|
||||||
|
$stmt->close();
|
||||||
|
|
||||||
|
// Round data
|
||||||
|
$stmt = $mysqli->prepare('INSERT INTO `' . self::DB_ROUNDSDATA . '`
|
||||||
|
(`matchid`,`timestamp`,`rank`,`login`,`matchpoints`,`mappoints`,`roundpoints`,`bestracetime`,`bestracecheckpoints`,`bestlaptime`,`bestlapcheckpoints`,`prevracetime`,`prevracecheckpoints`,`teamid`)
|
||||||
|
VALUES (?, ?, ?, ?, ? ,? ,? ,?, ? ,? ,? ,? ,?, ?)');
|
||||||
|
$stmt->bind_param('siisiiiisisisi',
|
||||||
|
$this->matchid,
|
||||||
|
$timestamp,
|
||||||
|
$rank,
|
||||||
|
$login,
|
||||||
|
$matchpoints,
|
||||||
|
$mappoints,
|
||||||
|
$roundpoints,
|
||||||
|
$bestracetime,
|
||||||
|
$bestracecheckpoints,
|
||||||
|
$bestlaptime,
|
||||||
|
$bestlapcheckpoints,
|
||||||
|
$prevracetime,
|
||||||
|
$prevracecheckpoints,
|
||||||
|
$teamid
|
||||||
|
);
|
||||||
|
|
||||||
|
foreach ($this->currentscore as $score) {
|
||||||
|
list($rank, $login, $matchpoints, $mappoints, $roundpoints, $bestracetime, $bestracecheckpoints, $bestlaptime, $bestlapcheckpoints, $prevracetime, $prevracecheckpoints, $teamid) = $score;
|
||||||
|
|
||||||
|
if (!$stmt->execute()) {
|
||||||
|
Logger::logError('Error executing MySQL query: '. $stmt->error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$stmt->close();
|
||||||
|
|
||||||
|
// Teams Rounds data
|
||||||
|
if (count($this->currentteamsscore) > 1) {
|
||||||
|
$stmt = $mysqli->prepare('INSERT INTO `' . self::DB_TEAMSDATA . '` (`matchid`,`timestamp`,`rank`,`id`,`team`,`matchpoints`,`mappoints`,`roundpoints`)
|
||||||
|
VALUES (?, ?, ?, ?, ?, ?, ?, ?)');
|
||||||
|
$stmt->bind_param('siiisiii', $this->matchid, $timestamp, $rank, $teamid, $teamname, $matchpoints, $mappoints, $roundpoints);
|
||||||
|
|
||||||
|
|
||||||
|
foreach ($this->currentteamsscore as $score) {
|
||||||
|
list($rank, $teamid, $teamname, $matchpoints, $mappoints, $roundpoints) = $score;
|
||||||
|
|
||||||
|
if (!$stmt->execute()) {
|
||||||
|
Logger::logError('Error executing MySQL query: '. $stmt->error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$stmt->close();
|
||||||
|
}
|
||||||
|
$mysqli->commit();
|
||||||
|
|
||||||
|
Logger::log("Rounds finished: " . $this->nbrounds);
|
||||||
|
$this->maniaControl->getCallbackManager()->triggerCallback(self::CB_MATCHMANAGER_ENDROUND, $this->matchid, $this->currentscore, $this->currentteamsscore);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private function computeCurrentScores(OnScoresStructure $structure) {
|
||||||
//
|
//
|
||||||
// Players Scores
|
// Players Scores
|
||||||
//
|
//
|
||||||
@ -1629,11 +1773,10 @@ class MatchManagerCore implements CallbackListener, CommandListener, TimerListen
|
|||||||
$preendroundteamsscore = [];
|
$preendroundteamsscore = [];
|
||||||
if ($this->preendroundscore !== null) {
|
if ($this->preendroundscore !== null) {
|
||||||
$preendroundplayersscore = $this->preendroundscore->getPlayerScores();
|
$preendroundplayersscore = $this->preendroundscore->getPlayerScores();
|
||||||
$preendroundteamsscore = $this->preendroundscore->getTeamScores();;
|
$preendroundteamsscore = $this->preendroundscore->getTeamScores();
|
||||||
}
|
}
|
||||||
$this->preendroundscore = null;
|
$this->preendroundscore = null;
|
||||||
|
|
||||||
//$rank = 1;
|
|
||||||
foreach ($results as $result) {
|
foreach ($results as $result) {
|
||||||
/** @var \ManiaControl\Callbacks\Structures\TrackMania\Models\PlayerScore $result */
|
/** @var \ManiaControl\Callbacks\Structures\TrackMania\Models\PlayerScore $result */
|
||||||
$rank = $result->getRank();
|
$rank = $result->getRank();
|
||||||
@ -1707,81 +1850,6 @@ class MatchManagerCore implements CallbackListener, CommandListener, TimerListen
|
|||||||
$rank++;
|
$rank++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
|
||||||
// MySQL queries
|
|
||||||
//
|
|
||||||
$settings = json_encode($this->maniaControl->getClient()->getModeScriptSettings());
|
|
||||||
$mysqli = $this->maniaControl->getDatabase()->getMysqli();
|
|
||||||
|
|
||||||
$mysqli->begin_transaction();
|
|
||||||
|
|
||||||
$playercount = $this->maniaControl->getPlayerManager()->getPlayerCount();
|
|
||||||
$spectatorcount = $this->maniaControl->getPlayerManager()->getSpectatorCount();
|
|
||||||
|
|
||||||
$stmt = $mysqli->prepare('INSERT INTO `' . self::DB_ROUNDSINDEX . '`
|
|
||||||
(`matchid`,`timestamp`,`nbmaps`,`nbrounds`,`settings`,`map`,`nbplayers`,`nbspectators`)
|
|
||||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?)');
|
|
||||||
$stmt->bind_param('siiissii', $this->matchid, $timestamp, $this->nbmaps, $this->nbrounds, $settings, $this->currentmap->uid, $playercount, $spectatorcount);
|
|
||||||
if (!$stmt->execute()) {
|
|
||||||
Logger::logError('Error executing MySQL query: '. $stmt->error);
|
|
||||||
}
|
|
||||||
$stmt->close();
|
|
||||||
|
|
||||||
// Round data
|
|
||||||
$stmt = $mysqli->prepare('INSERT INTO `' . self::DB_ROUNDSDATA . '`
|
|
||||||
(`matchid`,`timestamp`,`rank`,`login`,`matchpoints`,`mappoints`,`roundpoints`,`bestracetime`,`bestracecheckpoints`,`bestlaptime`,`bestlapcheckpoints`,`prevracetime`,`prevracecheckpoints`,`teamid`)
|
|
||||||
VALUES (?, ?, ?, ?, ? ,? ,? ,?, ? ,? ,? ,? ,?, ?)');
|
|
||||||
$stmt->bind_param('siisiiiisisisi',
|
|
||||||
$this->matchid,
|
|
||||||
$timestamp,
|
|
||||||
$rank,
|
|
||||||
$login,
|
|
||||||
$matchpoints,
|
|
||||||
$mappoints,
|
|
||||||
$roundpoints,
|
|
||||||
$bestracetime,
|
|
||||||
$bestracecheckpoints,
|
|
||||||
$bestlaptime,
|
|
||||||
$bestlapcheckpoints,
|
|
||||||
$prevracetime,
|
|
||||||
$prevracecheckpoints,
|
|
||||||
$teamid
|
|
||||||
);
|
|
||||||
|
|
||||||
foreach ($this->currentscore as $score) {
|
|
||||||
list($rank, $login, $matchpoints, $mappoints, $roundpoints, $bestracetime, $bestracecheckpoints, $bestlaptime, $bestlapcheckpoints, $prevracetime, $prevracecheckpoints, $teamid) = $score;
|
|
||||||
|
|
||||||
if (!$stmt->execute()) {
|
|
||||||
Logger::logError('Error executing MySQL query: '. $stmt->error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$stmt->close();
|
|
||||||
|
|
||||||
// Teams Rounds data
|
|
||||||
if (count($teamresults) > 1) {
|
|
||||||
$stmt = $mysqli->prepare('INSERT INTO `' . self::DB_TEAMSDATA . '` (`matchid`,`timestamp`,`rank`,`id`,`team`,`matchpoints`,`mappoints`,`roundpoints`)
|
|
||||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?)');
|
|
||||||
$stmt->bind_param('siiisiii', $this->matchid, $timestamp, $rank, $teamid, $teamname, $matchpoints, $mappoints, $roundpoints);
|
|
||||||
|
|
||||||
|
|
||||||
foreach ($this->currentteamsscore as $score) {
|
|
||||||
list($rank, $teamid, $teamname, $matchpoints, $mappoints, $roundpoints) = $score;
|
|
||||||
|
|
||||||
if (!$stmt->execute()) {
|
|
||||||
Logger::logError('Error executing MySQL query: '. $stmt->error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$stmt->close();
|
|
||||||
}
|
|
||||||
$mysqli->commit();
|
|
||||||
|
|
||||||
Logger::log("Rounds finished: " . $this->nbrounds);
|
|
||||||
$this->maniaControl->getCallbackManager()->triggerCallback(self::CB_MATCHMANAGER_ENDROUND, $this->matchid, $this->currentscore, $this->currentteamsscore);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user