Compare commits

...

2 Commits

Author SHA1 Message Date
Beu
a1cdbe93e2 fix race condition of the nbround and the nbmaps 2023-10-16 22:54:25 +02:00
Beu
89ce4f0d61 fix once again the nbround 2023-10-16 22:53:47 +02:00
2 changed files with 24 additions and 24 deletions

View File

@ -442,7 +442,6 @@ class MatchManagerCore implements CallbackListener, CommandListener, TimerListen
$this->maniaControl->getCallbackManager()->registerCallbackListener(PlayerManager::CB_PLAYERDISCONNECT, $this, 'handlePlayerDisconnect');
$this->maniaControl->getCallbackManager()->registerCallbackListener(Callbacks::TM_SCORES, $this, 'handleTrackmaniaScore');
$this->maniaControl->getCallbackManager()->registerCallbackListener(Callbacks::MP_STARTROUNDSTART, $this, 'handleBeginRoundCallback');
$this->maniaControl->getCallbackManager()->registerCallbackListener(Callbacks::MP_ENDROUNDEND, $this, 'handleEndRoundCallback');
$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');
@ -456,21 +455,6 @@ class MatchManagerCore implements CallbackListener, CommandListener, TimerListen
$this->maniaControl->getCommunicationManager()->registerCommunicationListener("Match.GetMatchOptions", $this, function () { return new CommunicationAnswer($this->getGMSettings($this->currentgmbase,$this->currentcustomgm)); });
}
public function handleEndRoundCallback(StartEndStructure $structure) {
Logger::log("handleEndRoundCallback");
if (defined("\ManiaControl\ManiaControl::ISTRACKMANIACONTROL") && method_exists($structure, "getValidRoundCount")) {
$this->nbrounds = $structure->getValidRoundCount();
} else if (property_exists($structure->getPlainJsonObject(), "valid")) {
$this->nbrounds = $structure->getPlainJsonObject()->valid;
} else {
$this->nbrounds = $structure->getCount();
}
Logger::log("Rounds finished: " . $this->nbrounds);
$this->maniaControl->getCallbackManager()->triggerCallback(self::CB_MATCHMANAGER_ENDROUND, $this->matchid, $this->currentscore, $this->currentteamsscore);
}
/**
* @see \ManiaControl\Plugins\Plugin::unload()
*/
@ -1523,10 +1507,19 @@ class MatchManagerCore implements CallbackListener, CommandListener, TimerListen
/**
* Handle callback "BeginRound"
*/
public function handleBeginRoundCallback() {
public function handleBeginRoundCallback(StartEndStructure $structure) {
Logger::log("handleBeginRoundCallback");
if ($this->matchStarted && $this->nbmaps > 0) {
if (defined("\ManiaControl\ManiaControl::ISTRACKMANIACONTROL") && method_exists($structure, "getValidRoundCount")) {
$this->nbrounds = $structure->getValidRoundCount();
} else if (property_exists($structure->getPlainJsonObject(), "valid")) {
$this->nbrounds = $structure->getPlainJsonObject()->valid;
} else {
$this->nbrounds = $structure->getCount();
}
if (in_array($this->currentgmbase, ["Cup", "Teams", "Rounds"])) {
$this->maniaControl->getModeScriptEventManager()->getPauseStatus()->setCallable(function (StatusCallbackStructure $structure) {
if ($structure->getActive()) {
@ -1534,8 +1527,8 @@ class MatchManagerCore implements CallbackListener, CommandListener, TimerListen
Logger::log("Pause");
} else {
if ($this->settings_nbroundsbymap > 1) {
$this->maniaControl->getChat()->sendInformation($this->chatprefix . '$o$iRound: ' . ($this->nbrounds + 1) . ' / ' . $this->settings_nbroundsbymap);
Logger::log("Round: " . ($this->nbrounds + 1) . ' / ' . $this->settings_nbroundsbymap);
$this->maniaControl->getChat()->sendInformation($this->chatprefix . '$o$iRound: ' . $this->nbrounds . ' / ' . $this->settings_nbroundsbymap);
Logger::log("Round: " . $this->nbrounds . ' / ' . $this->settings_nbroundsbymap);
}
}
});
@ -1704,6 +1697,9 @@ class MatchManagerCore implements CallbackListener, CommandListener, TimerListen
trigger_error($mysqli->error);
}
}
Logger::log("Rounds finished: " . $this->nbrounds);
$this->maniaControl->getCallbackManager()->triggerCallback(self::CB_MATCHMANAGER_ENDROUND, $this->matchid, $this->currentscore, $this->currentteamsscore);
}
}
return true;

View File

@ -35,7 +35,7 @@ class MatchManagerGSheet implements CallbackListener, TimerListener, CommandLis
* Constants
*/
const PLUGIN_ID = 156;
const PLUGIN_VERSION = 1.5;
const PLUGIN_VERSION = 1.6;
const PLUGIN_NAME = 'MatchManager GSheet';
const PLUGIN_AUTHOR = 'Beu';
@ -95,6 +95,7 @@ class MatchManagerGSheet implements CallbackListener, TimerListener, CommandLis
private $maniaControl = null;
private $MatchManagerCore = null;
private $matchstatus = "";
private $chatprefix = '$<$fc3$w🏆$m$> '; // Would like to create a setting but MC database doesn't support utf8mb4
private $device_code = "";
private $access_token = "";
private $matchid = "";
@ -509,13 +510,16 @@ class MatchManagerGSheet implements CallbackListener, TimerListener, CommandLis
$data->data[3] = new \stdClass;
$data->data[3]->range = "'" . $sheetname . "'!" . self::MODE_SPECIFICS_SETTINGS[$this->currentdatamode]["TeamsScoreTable_BeginLetter"] . "2";
$data->data[3]->values = $currentteamsscore;
} else {
$nbmaps = $this->MatchManagerCore->getMapNumber();
$nbrounds = $this->MatchManagerCore->getRoundNumber();
}
$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->setHeaders(array("Authorization: Bearer " . $this->access_token));
$asyncHttpRequest->setContent(json_encode($data));
$asyncHttpRequest->setCallable(function ($json, $error) use ($sheetname, $currentscore, $currentteamsscore, $matchstatus) {
$asyncHttpRequest->setCallable(function ($json, $error) use ($sheetname, $currentscore, $currentteamsscore, $matchstatus, $nbmaps, $nbrounds) {
if (!$json || $error) {
Logger::logError('Error from Google API: ' . $error);
$this->maniaControl->getChat()->sendErrorToAdmins('Error from Google API: ' . $error);
@ -531,7 +535,7 @@ class MatchManagerGSheet implements CallbackListener, TimerListener, CommandLis
if ($this->currentdatamode == "All Rounds Data" && $matchstatus == "running") {
$newcurrentscore = [];
foreach ($currentscore as $score) {
array_push($newcurrentscore,array_merge([$this->MatchManagerCore->getMapNumber() , $this->MatchManagerCore->getRoundNumber()], $score));
array_push($newcurrentscore,array_merge([$nbmaps, $nbrounds], $score));
}
$data = new \stdClass;
@ -543,7 +547,7 @@ class MatchManagerGSheet implements CallbackListener, TimerListener, CommandLis
$asyncHttpRequest->setContentType(AsyncHttpRequest::CONTENT_TYPE_JSON);
$asyncHttpRequest->setHeaders(array("Authorization: Bearer " . $this->access_token));
$asyncHttpRequest->setContent(json_encode($data));
$asyncHttpRequest->setCallable(function ($json, $error) use ($sheetname, $currentscore, $currentteamsscore) {
$asyncHttpRequest->setCallable(function ($json, $error) use ($sheetname, $currentteamsscore, $nbmaps, $nbrounds) {
if (!$json || $error) {
Logger::logError('Error from Google API: ' . $error);
$this->maniaControl->getChat()->sendErrorToAdmins('Error from Google API: ' . $error);
@ -559,7 +563,7 @@ class MatchManagerGSheet implements CallbackListener, TimerListener, CommandLis
if (!empty($currentteamsscore)) {
$newcurrentteamsscore = [];
foreach ($currentteamsscore as $score) {
array_push($newcurrentteamsscore,array_merge([$this->MatchManagerCore->getMapNumber() , $this->MatchManagerCore->getRoundNumber()], $score));
array_push($newcurrentteamsscore,array_merge([$nbmaps, $nbrounds], $score));
}
$data = new \stdClass;