Compare commits

...

3 Commits

View File

@ -37,7 +37,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 = 4.0; const PLUGIN_VERSION = 4.2;
const PLUGIN_NAME = 'MatchManager Core'; const PLUGIN_NAME = 'MatchManager Core';
const PLUGIN_AUTHOR = 'Beu'; const PLUGIN_AUTHOR = 'Beu';
@ -321,7 +321,8 @@ class MatchManagerCore implements CallbackListener, CommandListener, TimerListen
private $settings_pointlimit = 100; private $settings_pointlimit = 100;
private $currentscore = array(); private $currentscore = array();
private $preendroundscore = array(); /** @var OnScoresStructure|null $preendroundscore */
private $preendroundscore = null;
private $currentteamsscore = array(); private $currentteamsscore = array();
private $pausetimer = 0; private $pausetimer = 0;
private $pauseon = false; private $pauseon = false;
@ -476,7 +477,7 @@ class MatchManagerCore implements CallbackListener, CommandListener, TimerListen
`matchid` VARCHAR(100) NOT NULL, `matchid` VARCHAR(100) NOT NULL,
`timestamp` INT(10) NOT NULL, `timestamp` INT(10) NOT NULL,
`rank` INT(4) NOT NULL, `rank` INT(4) NOT NULL,
`login` VARCHAR(30) NOT NULL, `login` VARCHAR(36) NOT NULL,
`matchpoints` INT(10) NOT NULL, `matchpoints` INT(10) NOT NULL,
`mappoints` INT(10) NOT NULL, `mappoints` INT(10) NOT NULL,
`roundpoints` INT(10) NOT NULL, `roundpoints` INT(10) NOT NULL,
@ -535,6 +536,20 @@ 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 = 'IF NOT EXISTS( SELECT NULL
FROM INFORMATION_SCHEMA.COLUMNS
WHERE `table_name` = "' . self::DB_ROUNDSDATA . '"
AND `table_schema` = "' . $mysqliconfig->name . '"
AND `column_name` = "login"
AND `CHARACTER_MAXIMUM_LENGTH` = 36) THEN
ALTER TABLE `' . self::DB_ROUNDSDATA . '`
MODIFY `login` VARCHAR(36) NOT NULL;
END IF;';
$mysqli->query($query);
if ($mysqli->error) {
trigger_error($mysqli->error, E_USER_ERROR);
}
} }
public function getMatchStatus() { public function getMatchStatus() {
@ -714,7 +729,7 @@ class MatchManagerCore implements CallbackListener, CommandListener, TimerListen
$this->postmatch = true; $this->postmatch = true;
$this->matchid = ""; $this->matchid = "";
$this->settings_nbroundsbymap = 5; $this->settings_nbroundsbymap = -1;
$this->settings_nbwinners = 2; $this->settings_nbwinners = 2;
$this->settings_nbmapsbymatch = 0; $this->settings_nbmapsbymatch = 0;
$this->settings_pointlimit = 100; $this->settings_pointlimit = 100;
@ -839,7 +854,7 @@ class MatchManagerCore implements CallbackListener, CommandListener, TimerListen
if (isset($this->currentgmsettings[self::SETTING_MATCH_S_ROUNDSPERMAP])) { if (isset($this->currentgmsettings[self::SETTING_MATCH_S_ROUNDSPERMAP])) {
$this->settings_nbroundsbymap = (int) $this->currentgmsettings[self::SETTING_MATCH_S_ROUNDSPERMAP]; $this->settings_nbroundsbymap = (int) $this->currentgmsettings[self::SETTING_MATCH_S_ROUNDSPERMAP];
} else { } else {
$this->settings_nbroundsbymap = 1; $this->settings_nbroundsbymap = -1;
} }
if (isset($this->currentgmsettings[self::SETTING_MATCH_S_MAPSPERMATCH])) { if (isset($this->currentgmsettings[self::SETTING_MATCH_S_MAPSPERMATCH])) {
$this->settings_nbmapsbymatch = (int) $this->currentgmsettings[self::SETTING_MATCH_S_MAPSPERMATCH]; $this->settings_nbmapsbymatch = (int) $this->currentgmsettings[self::SETTING_MATCH_S_MAPSPERMATCH];
@ -1482,7 +1497,7 @@ class MatchManagerCore implements CallbackListener, CommandListener, TimerListen
$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"); Logger::log("Pause");
} else { } else {
if ($this->settings_nbroundsbymap != 1) { if ($this->settings_nbroundsbymap > 1) {
$this->maniaControl->getChat()->sendInformation($this->chatprefix . '$o$iRound: ' . ($this->nbrounds + 1) . ' / ' . $this->settings_nbroundsbymap); $this->maniaControl->getChat()->sendInformation($this->chatprefix . '$o$iRound: ' . ($this->nbrounds + 1) . ' / ' . $this->settings_nbroundsbymap);
Logger::log("Round: " . ($this->nbrounds + 1) . ' / ' . $this->settings_nbroundsbymap); Logger::log("Round: " . ($this->nbrounds + 1) . ' / ' . $this->settings_nbroundsbymap);
} }
@ -1513,7 +1528,7 @@ class MatchManagerCore implements CallbackListener, CommandListener, TimerListen
} 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->getPlayerScores(); $this->preendroundscore = $structure;
} elseif ($structure->getSection() == "EndRound") { } elseif ($structure->getSection() == "EndRound") {
$timestamp = time(); $timestamp = time();
@ -1529,6 +1544,14 @@ class MatchManagerCore implements CallbackListener, CommandListener, TimerListen
Logger::Log("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");
} }
$preendroundplayersscore = [];
$preendroundteamsscore = [];
if ($this->preendroundscore !== null) {
$preendroundplayersscore = $this->preendroundscore->getPlayerScores();
$preendroundteamsscore = $this->preendroundscore->getTeamScores();;
}
$this->preendroundscore = null;
//$rank = 1; //$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 */
@ -1544,19 +1567,18 @@ class MatchManagerCore implements CallbackListener, CommandListener, TimerListen
$prevracetime = $result->getPrevRaceTime(); $prevracetime = $result->getPrevRaceTime();
$prevracecheckpoints = implode(",", $result->getPrevRaceCheckpoints()); $prevracecheckpoints = implode(",", $result->getPrevRaceCheckpoints());
if (count($this->preendroundscore) > 0) { if (count($preendroundplayersscore) > 0) {
foreach ($this->preendroundscore as $k => $preendroundresult) { $preendroundarray = array_filter($preendroundplayersscore, function ($e) use ($player) { return $e->getPlayer() === $player ; });
if ($preendroundresult->getPlayer() === $player) {
if ($roundpoints == 0 && $preendroundresult->getRoundPoints() != 0) {
$roundpoints = $preendroundresult->getRoundPoints();
}
if ($mappoints == 0 && $preendroundresult->getMapPoints() != 0) {
$mappoints = $preendroundresult->getMapPoints();
}
unset($this->preendroundscore[$k]); foreach ($preendroundarray as $key => $preendround) {
break; if ($roundpoints == 0 && $preendround->getRoundPoints() != 0) {
$roundpoints = $preendround->getRoundPoints();
} }
if ($mappoints == 0 && $preendround->getMapPoints() != 0) {
$mappoints = $preendround->getMapPoints();
}
unset($preendroundplayersscore[$key]);
break;
} }
} }
@ -1583,6 +1605,21 @@ class MatchManagerCore implements CallbackListener, CommandListener, TimerListen
$mappoints = $teamresult->getMapPoints(); $mappoints = $teamresult->getMapPoints();
$roundpoints = $teamresult->getRoundPoints(); $roundpoints = $teamresult->getRoundPoints();
if (count($preendroundteamsscore) > 0) {
$preendroundarray = array_filter($preendroundteamsscore, function ($e) use ($teamid) { return $e->getTeamId() === $teamid ; });
foreach ($preendroundarray as $key => $preendround) {
if ($roundpoints == 0 && $preendround->getRoundPoints() != 0) {
$roundpoints = $preendround->getRoundPoints();
}
if ($mappoints == 0 && $preendround->getMapPoints() != 0) {
$mappoints = $preendround->getMapPoints();
}
unset($preendroundteamsscore[$key]);
break;
}
}
$this->currentteamsscore = array_merge($this->currentteamsscore, array( $this->currentteamsscore = array_merge($this->currentteamsscore, array(
array($rank, $teamid, $teamname, $matchpoints, $mappoints, $roundpoints) array($rank, $teamid, $teamname, $matchpoints, $mappoints, $roundpoints)
)); ));
@ -1593,7 +1630,6 @@ class MatchManagerCore implements CallbackListener, CommandListener, TimerListen
// //
// End Round Routines // End Round Routines
// //
$this->preendroundscore = array();
if (!$this->pauseon && !$this->skipround) { if (!$this->pauseon && !$this->skipround) {
if ($this->currentgmbase != "Cup") { if ($this->currentgmbase != "Cup") {
$this->nbrounds++; $this->nbrounds++;