Compare commits

..

16 Commits

Author SHA1 Message Date
beu
787964a8ed improve logging 2025-06-22 19:59:01 +02:00
beu
af10e1678a bump version 2025-06-22 19:56:53 +02:00
beu
33cc10b6c1 fix non-blocking errors 2025-06-22 19:38:50 +02:00
beu
5d2c6c4627 bump version 2025-06-22 19:30:51 +02:00
beu
36280769bb add logging 2025-06-22 19:30:16 +02:00
beu
803b58eb08 improving logging 2025-06-22 19:23:33 +02:00
beu
6928fe2ce2 fix php 8.4 compatibility 2025-06-22 18:58:00 +02:00
beu
8d01340d22 fix missing management of loading and unloading plugins 2025-06-22 18:57:33 +02:00
beu
6887384578 fix php 8.4 compatibility + improve logging / chat messages 2025-06-22 18:57:12 +02:00
beu
f8c8ff6269 move chat prefix as constant 2025-06-22 18:15:58 +02:00
beu
0352d96fdf fix match score saving after an error when launching 2025-06-22 17:57:07 +02:00
beu
ebecb7da73 improve logging 2025-06-22 17:54:17 +02:00
beu
9efa66ac5d improve logging 2025-06-22 11:52:48 +02:00
beu
0fe9dc3e14 prevent crash when no settings 2025-06-22 00:13:46 +02:00
beu
8e632d5057 change default message 2025-03-31 15:35:06 +02:00
beu
7a6fdebc67 fix setteampoints command 2025-03-31 15:34:41 +02:00
14 changed files with 624 additions and 362 deletions

View File

@ -31,7 +31,7 @@ class BeuCustomConfig implements CallbackListener, Plugin {
* Constants * Constants
*/ */
const PLUGIN_ID = 193; const PLUGIN_ID = 193;
const PLUGIN_VERSION = 1.2; const PLUGIN_VERSION = 1.3;
const PLUGIN_NAME = 'BeuCustomConfig'; const PLUGIN_NAME = 'BeuCustomConfig';
const PLUGIN_AUTHOR = 'Beu'; const PLUGIN_AUTHOR = 'Beu';
@ -149,7 +149,7 @@ class BeuCustomConfig implements CallbackListener, Plugin {
]); ]);
} }
public function updateSettings(Setting $setting = null) { public function updateSettings(?Setting $setting = null) {
if ($setting !== null && $setting->belongsToClass($this)) { if ($setting !== null && $setting->belongsToClass($this)) {
$this->changeManiacontrolSettings(); $this->changeManiacontrolSettings();
} }

View File

@ -25,7 +25,7 @@ class BeuDonationButton implements ManialinkPageAnswerListener, CallbackListener
* Constants * Constants
*/ */
const PLUGIN_ID = 169; const PLUGIN_ID = 169;
const PLUGIN_VERSION = 1.0; const PLUGIN_VERSION = 1.1;
const PLUGIN_NAME = 'Beu Donation Button'; const PLUGIN_NAME = 'Beu Donation Button';
const PLUGIN_AUTHOR = 'Beu'; const PLUGIN_AUTHOR = 'Beu';
@ -103,7 +103,7 @@ class BeuDonationButton implements ManialinkPageAnswerListener, CallbackListener
$this->maniaControl->getManialinkManager()->sendManialink($this->manialink,$player->login); $this->maniaControl->getManialinkManager()->sendManialink($this->manialink,$player->login);
} }
public function updateSettings(Setting $setting = null) { public function updateSettings(?Setting $setting = null) {
$this->generateManialink(); $this->generateManialink();
$this->maniaControl->getManialinkManager()->sendManialink($this->manialink); $this->maniaControl->getManialinkManager()->sendManialink($this->manialink);
} }

View File

@ -20,7 +20,7 @@ class MoreModesTools implements CommandListener, Plugin {
* Constants * Constants
*/ */
const PLUGIN_ID = 164; const PLUGIN_ID = 164;
const PLUGIN_VERSION = 1.2; const PLUGIN_VERSION = 1.3;
const PLUGIN_NAME = 'MoreModesTools'; const PLUGIN_NAME = 'MoreModesTools';
const PLUGIN_AUTHOR = 'Beu'; const PLUGIN_AUTHOR = 'Beu';
@ -83,7 +83,7 @@ class MoreModesTools implements CommandListener, Plugin {
$this->maniaControl->getCommandManager()->registerCommandListener(['endwu', 'endwarmup'], $this, 'onCommandEndWarmUp', true, 'End the WarmUp'); $this->maniaControl->getCommandManager()->registerCommandListener(['endwu', 'endwarmup'], $this, 'onCommandEndWarmUp', true, 'End the WarmUp');
$this->maniaControl->getCommandManager()->registerCommandListener(['extendwu', 'extendwarmup'], $this, 'onCommandExtendWarmUp', true, 'If the warm up has a time limit, increase it'); $this->maniaControl->getCommandManager()->registerCommandListener(['extendwu', 'extendwarmup'], $this, 'onCommandExtendWarmUp', true, 'If the warm up has a time limit, increase it');
$this->maniaControl->getCommandManager()->registerCommandListener('setpoints', $this, 'onCommandSetPoints', true, 'Set Points for a player'); $this->maniaControl->getCommandManager()->registerCommandListener('setpoints', $this, 'onCommandSetPoints', true, 'Set Points for a player');
$this->maniaControl->getCommandManager()->registerCommandListener('setteampoints', $this, 'onCommandSetPoints', true, 'Set Points for a team'); $this->maniaControl->getCommandManager()->registerCommandListener('setteampoints', $this, 'onCommandSetTeamPoints', true, 'Set Points for a team');
return true; return true;
} }
@ -166,7 +166,7 @@ class MoreModesTools implements CommandListener, Plugin {
$text = explode(" ", $text); $text = explode(" ", $text);
if (count($text) < 3) { if (count($text) < 3) {
$this->maniaControl->getChat()->sendError('Missing parameters. Eg: //matchsetpoints <Player Name or Login> <Match points> <Map Points (optional)> <Round Points (optional)>', $adminplayer); $this->maniaControl->getChat()->sendError('Missing parameters. Eg: //setpoints <Player Name or Login> <Match points> <Map Points (optional)> <Round Points (optional)>', $adminplayer);
return; return;
} }
@ -240,7 +240,7 @@ class MoreModesTools implements CommandListener, Plugin {
$text = explode(" ", $text); $text = explode(" ", $text);
if (count($text) < 3) { if (count($text) < 3) {
$this->maniaControl->getChat()->sendError('Missing parameters. Eg: //matchsetteampoints <Team Name or Id> <Match points> <Map Points (optional)> <Round Points (optional)>', $adminplayer); $this->maniaControl->getChat()->sendError('Missing parameters. Eg: //setteampoints <Team Name or Id> <Match points> <Map Points (optional)> <Round Points (optional)>', $adminplayer);
return; return;
} }

View File

@ -26,7 +26,7 @@ class SmallTextOverlay implements TimerListener, CallbackListener, Plugin {
* Constants * Constants
*/ */
const PLUGIN_ID = 195; const PLUGIN_ID = 195;
const PLUGIN_VERSION = 1.0; const PLUGIN_VERSION = 1.4;
const PLUGIN_NAME = 'SmallTextOverlay'; const PLUGIN_NAME = 'SmallTextOverlay';
const PLUGIN_AUTHOR = 'Beu'; const PLUGIN_AUTHOR = 'Beu';
@ -115,7 +115,7 @@ class SmallTextOverlay implements TimerListener, CallbackListener, Plugin {
* @param Setting $setting * @param Setting $setting
* @return void * @return void
*/ */
public function updateSettings(Setting $setting = null) { public function updateSettings(?Setting $setting = null) {
if ($setting !== null && !$setting->belongsToClass($this)) { if ($setting !== null && !$setting->belongsToClass($this)) {
return; return;
} }

View File

@ -17,6 +17,7 @@ use ManiaControl\Settings\Setting;
use ManiaControl\Settings\SettingManager; use ManiaControl\Settings\SettingManager;
use ManiaControl\Callbacks\TimerListener; use ManiaControl\Callbacks\TimerListener;
use ManiaControl\Callbacks\Callbacks; use ManiaControl\Callbacks\Callbacks;
use ManiaControl\Logger;
use ManiaControl\Players\Player; use ManiaControl\Players\Player;
use ManiaControl\Players\PlayerManager; use ManiaControl\Players\PlayerManager;
@ -31,10 +32,12 @@ class MatchManagerAdminUI implements CallbackListener, ManialinkPageAnswerListen
* Constants * Constants
*/ */
const PLUGIN_ID = 174; const PLUGIN_ID = 174;
const PLUGIN_VERSION = 2.1; const PLUGIN_VERSION = 2.3;
const PLUGIN_NAME = 'MatchManager Admin UI'; const PLUGIN_NAME = 'MatchManager Admin UI';
const PLUGIN_AUTHOR = 'Beu'; const PLUGIN_AUTHOR = 'Beu';
const LOG_PREFIX = '[MatchManagerAdminUI] ';
const MLID_ADMINUI_SIDEMENU = 'Matchmanager.AdminUI'; const MLID_ADMINUI_SIDEMENU = 'Matchmanager.AdminUI';
const SETTING_POSX = 'Position X of the plugin'; const SETTING_POSX = 'Position X of the plugin';
@ -123,6 +126,23 @@ class MatchManagerAdminUI implements CallbackListener, ManialinkPageAnswerListen
public function unload() { public function unload() {
$this->maniaControl->getManialinkManager()->hideManialink(self::MLID_ADMINUI_SIDEMENU); $this->maniaControl->getManialinkManager()->hideManialink(self::MLID_ADMINUI_SIDEMENU);
} }
/**
* Custom log function to add prefix
*
* @param mixed $message
*/
private function log(mixed $message) {
Logger::log(self::LOG_PREFIX . $message);
}
/**
* Custom logError function to add prefix
*
* @param mixed $message
*/
private function logError(mixed $message) {
Logger::logError(self::LOG_PREFIX . $message);
}
/** /**
* afterPluginInit * afterPluginInit
@ -178,6 +198,8 @@ class MatchManagerAdminUI implements CallbackListener, ManialinkPageAnswerListen
* @return void * @return void
*/ */
public function generateManialink() { public function generateManialink() {
$this->log("Generating interface with ". count($this->menuItems) . " items");
$quadStyle = $this->maniaControl->getManialinkManager()->getStyleManager()->getDefaultQuadStyle(); $quadStyle = $this->maniaControl->getManialinkManager()->getStyleManager()->getDefaultQuadStyle();
$quadSubstyle = $this->maniaControl->getManialinkManager()->getStyleManager()->getDefaultQuadSubstyle(); $quadSubstyle = $this->maniaControl->getManialinkManager()->getStyleManager()->getDefaultQuadSubstyle();
$itemMarginFactorX = 1.3; $itemMarginFactorX = 1.3;
@ -272,7 +294,7 @@ class MatchManagerAdminUI implements CallbackListener, ManialinkPageAnswerListen
} }
class MatchManagerAdminUI_MenuItem { class MatchManagerAdminUI_MenuItem {
private string $actionId ; private string $actionId;
private int $order = 100; private int $order = 100;
private string $description = ''; private string $description = '';
private string $text = ''; private string $text = '';

View File

@ -12,8 +12,8 @@ use ManiaControl\Settings\SettingManager;
use ManiaControl\Callbacks\TimerListener; use ManiaControl\Callbacks\TimerListener;
if (!class_exists('MatchManagerSuite\MatchManagerCore')) { if (!class_exists('MatchManagerSuite\MatchManagerCore')) {
$this->maniaControl->getChat()->sendErrorToAdmins('MatchManager Core is required to use one of MatchManager plugin. Install it and restart Maniacontrol'); $this->maniaControl->getChat()->sendErrorToAdmins('MatchManager Core is required to use MatchManagerAutomaticLauncher plugin. Install it and restart Maniacontrol');
Logger::logError('MatchManager Core is required to use one of MatchManager plugin. Install it and restart Maniacontrol'); Logger::logError('MatchManager Core is required to use MatchManagerAutomaticLauncher plugin. Install it and restart Maniacontrol');
return false; return false;
} }
@ -28,7 +28,7 @@ class MatchManagerAutomaticLauncher implements CallbackListener, TimerListener,
* Constants * Constants
*/ */
const PLUGIN_ID = 172; const PLUGIN_ID = 172;
const PLUGIN_VERSION = 1.1; const PLUGIN_VERSION = 1.2;
const PLUGIN_NAME = 'MatchManager Automatic Launcher'; const PLUGIN_NAME = 'MatchManager Automatic Launcher';
const PLUGIN_AUTHOR = 'Beu'; const PLUGIN_AUTHOR = 'Beu';
@ -42,6 +42,7 @@ class MatchManagerAutomaticLauncher implements CallbackListener, TimerListener,
*/ */
/** @var ManiaControl $maniaControl */ /** @var ManiaControl $maniaControl */
private $maniaControl = null; private $maniaControl = null;
/** @var MatchManagerCore $MatchManagerCore */
private $MatchManagerCore = null; private $MatchManagerCore = null;
@ -101,7 +102,7 @@ class MatchManagerAutomaticLauncher implements CallbackListener, TimerListener,
$this->MatchManagerCore = $this->maniaControl->getPluginManager()->getPlugin(self::MATCHMANAGERCORE_PLUGIN); $this->MatchManagerCore = $this->maniaControl->getPluginManager()->getPlugin(self::MATCHMANAGERCORE_PLUGIN);
if ($this->MatchManagerCore == null) { if ($this->MatchManagerCore == null) {
$this->maniaControl->getChat()->sendErrorToAdmins('MatchManager Core is needed to use ' . self::PLUGIN_NAME . ' plugin.'); $this->maniaControl->getChat()->sendErrorToAdmins('MatchManager Core is needed to use ' . self::PLUGIN_NAME . ' plugin.');
$this->maniaControl->getPluginManager()->deactivatePlugin((get_class())); $this->maniaControl->getPluginManager()->deactivatePlugin((get_class($this)));
} else { } else {
$this->createTimers(); $this->createTimers();
} }
@ -146,7 +147,7 @@ class MatchManagerAutomaticLauncher implements CallbackListener, TimerListener,
public function handlePluginUnloaded(string $pluginClass, Plugin $plugin) { public function handlePluginUnloaded(string $pluginClass, Plugin $plugin) {
if ($pluginClass == self::MATCHMANAGERCORE_PLUGIN) { if ($pluginClass == self::MATCHMANAGERCORE_PLUGIN) {
$this->maniaControl->getChat()->sendErrorToAdmins(self::PLUGIN_NAME . " disabled because MatchManager Core is now disabled"); $this->maniaControl->getChat()->sendErrorToAdmins(self::PLUGIN_NAME . " disabled because MatchManager Core is now disabled");
$this->maniaControl->getPluginManager()->deactivatePlugin((get_class())); $this->maniaControl->getPluginManager()->deactivatePlugin((get_class($this)));
} }
} }
@ -170,6 +171,6 @@ class MatchManagerAutomaticLauncher implements CallbackListener, TimerListener,
$newtimers++; $newtimers++;
} }
} }
$this->maniaControl->getChat()->sendSuccessToAdmins($newtimers . " matches are planned"); $this->maniaControl->getChat()->sendSuccessToAdmins($this->MatchManagerCore->getChatPrefix() . $newtimers . " matches are planned");
} }
} }

View File

@ -43,10 +43,13 @@ class MatchManagerCore implements CallbackListener, CommandListener, TimerListen
* MARK: Constants * MARK: Constants
*/ */
const PLUGIN_ID = 152; const PLUGIN_ID = 152;
const PLUGIN_VERSION = 5.8; const PLUGIN_VERSION = 5.9;
const PLUGIN_NAME = 'MatchManager Core'; const PLUGIN_NAME = 'MatchManager Core';
const PLUGIN_AUTHOR = 'Beu'; const PLUGIN_AUTHOR = 'Beu';
const LOG_PREFIX = '[MatchManagerCore] ';
const CHAT_PREFIX = '$<$fc3$w🏆$m$> ';
// Specific const // Specific const
const DB_MATCHESINDEX = 'MatchManager_MatchesIndex'; const DB_MATCHESINDEX = 'MatchManager_MatchesIndex';
const DB_ROUNDSINDEX = 'MatchManager_RoundsIndex'; const DB_ROUNDSINDEX = 'MatchManager_RoundsIndex';
@ -346,7 +349,6 @@ class MatchManagerCore implements CallbackListener, CommandListener, TimerListen
private $matchStarted = false; private $matchStarted = false;
/** @var ManiaControl $maniaControl */ /** @var ManiaControl $maniaControl */
private $maniaControl = null; private $maniaControl = null;
private $chatprefix = '$<$fc3$w🏆$m$> '; // Would like to create a setting but MC database doesn't support utf8mb4
private $nbmaps = 0; private $nbmaps = 0;
private $nbrounds = 0; private $nbrounds = 0;
private $currentgmbase = ""; private $currentgmbase = "";
@ -693,12 +695,29 @@ class MatchManagerCore implements CallbackListener, CommandListener, TimerListen
} }
public function getChatPrefix() { public function getChatPrefix() {
return $this->chatprefix; return self::CHAT_PREFIX;
} }
/* /*
* MARK: Internal Functions * MARK: Internal Functions
*/ */
/**
* Custom log function to add prefix
*
* @param mixed $message
*/
private function log(mixed $message) {
Logger::log(self::LOG_PREFIX . $message);
}
/**
* Custom logError function to add prefix
*
* @param mixed $message
*/
private function logError(mixed $message) {
Logger::logError(self::LOG_PREFIX . $message);
}
/** /**
* Reset match variables * Reset match variables
@ -706,19 +725,21 @@ class MatchManagerCore implements CallbackListener, CommandListener, TimerListen
* @param Setting $setting * @param Setting $setting
*/ */
public function resetMatchVariables() { public function resetMatchVariables() {
$this->matchStarted = false; $this->log("Reset match variables");
$this->matchrecover = false; $this->matchStarted = false;
$this->pauseon = false; $this->matchrecover = false;
$this->pointstorecover = array(); $this->pauseon = false;
$this->currentscore = array(); // TODO CHECK $this->pointstorecover = array();
$this->preendroundscore = null; $this->currentscore = array();
$this->settingsloaded = false; $this->currentteamsscore = array();
$this->mapsshuffled = false; $this->preendroundscore = null;
$this->mapshidden = false; $this->settingsloaded = false;
$this->hidenextmaps = false; $this->mapsshuffled = false;
$this->maps = array(); $this->mapshidden = false;
$this->postmatch = true; $this->hidenextmaps = false;
$this->matchid = ""; $this->maps = array();
$this->postmatch = false;
$this->matchid = "";
$this->settings_nbroundsbymap = -1; $this->settings_nbroundsbymap = -1;
$this->settings_nbwinners = 2; $this->settings_nbwinners = 2;
@ -775,7 +796,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();
@ -798,58 +819,58 @@ class MatchManagerCore implements CallbackListener, CommandListener, TimerListen
if ($setting->setting == self::SETTING_MATCH_GAMEMODE_BASE && $setting->value != $this->currentgmbase) { if ($setting->setting == self::SETTING_MATCH_GAMEMODE_BASE && $setting->value != $this->currentgmbase) {
$setting->value = $this->currentgmbase; $setting->value = $this->currentgmbase;
$this->maniaControl->getSettingManager()->saveSetting($setting); $this->maniaControl->getSettingManager()->saveSetting($setting);
$this->maniaControl->getChat()->sendErrorToAdmins($this->chatprefix . 'You can\'t change Gamemode during a Match'); $this->maniaControl->getChat()->sendErrorToAdmins(self::CHAT_PREFIX . 'You can\'t change Gamemode during a Match');
} else if ($setting->setting == self::SETTING_MATCH_CUSTOM_GAMEMODE && $setting->value != $this->currentcustomgm) { } else if ($setting->setting == self::SETTING_MATCH_CUSTOM_GAMEMODE && $setting->value != $this->currentcustomgm) {
$setting->value = $this->currentcustomgm; $setting->value = $this->currentcustomgm;
$this->maniaControl->getSettingManager()->saveSetting($setting); $this->maniaControl->getSettingManager()->saveSetting($setting);
$this->maniaControl->getChat()->sendErrorToAdmins($this->chatprefix . 'You can\'t change the Custom Gamemode during a Match'); $this->maniaControl->getChat()->sendErrorToAdmins(self::CHAT_PREFIX . 'You can\'t change the Custom Gamemode during a Match');
} else if ($setting->setting == self::SETTING_MATCH_SETTINGS_MODE && $setting->value != $this->currentsettingmode) { } else if ($setting->setting == self::SETTING_MATCH_SETTINGS_MODE && $setting->value != $this->currentsettingmode) {
$setting->value = $this->currentsettingmode; $setting->value = $this->currentsettingmode;
$this->maniaControl->getSettingManager()->saveSetting($setting); $this->maniaControl->getSettingManager()->saveSetting($setting);
$this->maniaControl->getChat()->sendErrorToAdmins($this->chatprefix . 'You can\'t change the Setting Mode during a Match'); $this->maniaControl->getChat()->sendErrorToAdmins(self::CHAT_PREFIX . 'You can\'t change the Setting Mode during a Match');
} else if ($setting->setting == self::SETTING_MODE_HIDENEXTMAPS && $setting->value != $this->hidenextmaps) { } else if ($setting->setting == self::SETTING_MODE_HIDENEXTMAPS && $setting->value != $this->hidenextmaps) {
$setting->value = $this->hidenextmaps; $setting->value = $this->hidenextmaps;
$this->maniaControl->getSettingManager()->saveSetting($setting); $this->maniaControl->getSettingManager()->saveSetting($setting);
$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(self::CHAT_PREFIX . '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(self::CHAT_PREFIX . '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(self::CHAT_PREFIX . 'Parameters not updated');
} }
$this->updateGMvariables(); $this->updateGMvariables();
} else { } else {
$this->maniaControl->getChat()->sendErrorToAdmins($this->chatprefix . 'Settings are loaded by Matchsettings file only.'); $this->maniaControl->getChat()->sendErrorToAdmins(self::CHAT_PREFIX . 'Settings are loaded by Matchsettings file only.');
} }
} }
} else if (isset($setting) && $setting->belongsToClass($this)) { } else if (isset($setting) && $setting->belongsToClass($this)) {
if ($setting->setting == self::SETTING_MATCH_CUSTOM_GAMEMODE && $setting->value != "") { if ($setting->setting == self::SETTING_MATCH_CUSTOM_GAMEMODE && $setting->value != "") {
$scriptfile = $this->maniaControl->getServer()->getDirectory()->getUserDataFolder() . DIRECTORY_SEPARATOR . "Scripts" . DIRECTORY_SEPARATOR . "Modes" . DIRECTORY_SEPARATOR . $setting->value; $scriptfile = $this->maniaControl->getServer()->getDirectory()->getUserDataFolder() . DIRECTORY_SEPARATOR . "Scripts" . DIRECTORY_SEPARATOR . "Modes" . DIRECTORY_SEPARATOR . $setting->value;
if (!file_exists($scriptfile)) { if (!file_exists($scriptfile)) {
$this->maniaControl->getChat()->sendErrorToAdmins($this->chatprefix . 'Unable to find the gamemode file: "' . $setting->value . '"'); $this->maniaControl->getChat()->sendErrorToAdmins(self::CHAT_PREFIX . 'Unable to find the gamemode file: "' . $setting->value . '"');
} }
} else if ($setting->setting == self::SETTING_MODE_MAPLIST_FILE && $setting->value != "") { } else if ($setting->setting == self::SETTING_MODE_MAPLIST_FILE && $setting->value != "") {
$scriptfile = $this->maniaControl->getServer()->getDirectory()->getMapsFolder() ."MatchSettings" . DIRECTORY_SEPARATOR . $setting->value; $scriptfile = $this->maniaControl->getServer()->getDirectory()->getMapsFolder() ."MatchSettings" . DIRECTORY_SEPARATOR . $setting->value;
if (!file_exists($scriptfile)) { if (!file_exists($scriptfile)) {
$this->maniaControl->getChat()->sendErrorToAdmins($this->chatprefix . 'Unable to find the Maplist file: "' . $setting->value . '"'); $this->maniaControl->getChat()->sendErrorToAdmins(self::CHAT_PREFIX . 'Unable to find the Maplist file: "' . $setting->value . '"');
} }
} else if ($setting->setting == self::SETTING_MATCH_POST_MATCH_MAPLIST && $setting->value != "") { } else if ($setting->setting == self::SETTING_MATCH_POST_MATCH_MAPLIST && $setting->value != "") {
$scriptfile = $this->maniaControl->getServer()->getDirectory()->getMapsFolder() ."MatchSettings" . DIRECTORY_SEPARATOR . $setting->value; $scriptfile = $this->maniaControl->getServer()->getDirectory()->getMapsFolder() ."MatchSettings" . DIRECTORY_SEPARATOR . $setting->value;
if (!file_exists($scriptfile)) { if (!file_exists($scriptfile)) {
$this->maniaControl->getChat()->sendErrorToAdmins($this->chatprefix . 'Unable to find the Post match Maplist file: "' . $setting->value . '"'); $this->maniaControl->getChat()->sendErrorToAdmins(self::CHAT_PREFIX . '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);
} catch (\Exception $e) { } catch (\Exception $e) {
$this->maniaControl->getChat()->sendErrorToAdmins($this->chatprefix . 'Unable to find the map: "' . $map . '"'); $this->maniaControl->getChat()->sendErrorToAdmins(self::CHAT_PREFIX . 'Unable to find the map: "' . $map . '"');
} }
} }
} }
@ -863,36 +884,38 @@ class MatchManagerCore implements CallbackListener, CommandListener, TimerListen
} }
$allsettings = $this->maniaControl->getSettingManager()->getSettingsByClass($this); $allsettings = $this->maniaControl->getSettingManager()->getSettingsByClass($this);
$settingsmode = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MATCH_SETTINGS_MODE); $settingsmode = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MATCH_SETTINGS_MODE);
$modesettings = $this->getModeSettings($settingsmode); if ($allsettings !== null && $settingsmode !== null) {
foreach ($allsettings as $key => $value) { $modesettings = $this->getModeSettings($settingsmode);
$name = $value->setting;
if (array_key_exists($name,self::SETTINGS_MODE_LIST)) {
if (!isset($modesettings[$name])) {
if ($deletesettings) $this->maniaControl->getSettingManager()->deleteSetting($this, $name);
}
}
}
foreach ($modesettings as $key => $value) {
$this->maniaControl->getSettingManager()->initSetting($this, $key, self::SETTINGS_MODE_LIST[$key]['default'], self::SETTINGS_MODE_LIST[$key]['description'], 50);
}
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));
foreach ($allsettings as $key => $value) { foreach ($allsettings as $key => $value) {
$name = $value->setting; $name = $value->setting;
if (substr($name,0, 2) == "S_" && !isset($gmsettings[$name])) { if (array_key_exists($name,self::SETTINGS_MODE_LIST)) {
if ($deletesettings) $this->maniaControl->getSettingManager()->deleteSetting($this, $name); if (!isset($modesettings[$name])) {
if ($deletesettings) $this->maniaControl->getSettingManager()->deleteSetting($this, $name);
}
} }
} }
foreach ($gmsettings as $key => $value) { foreach ($modesettings as $key => $value) {
$this->maniaControl->getSettingManager()->initSetting($this, $key, $value['default'], $value['description'], 100); $this->maniaControl->getSettingManager()->initSetting($this, $key, self::SETTINGS_MODE_LIST[$key]['default'], self::SETTINGS_MODE_LIST[$key]['description'], 50);
} }
} else {
foreach ($allsettings as $key => $value) { if ($settingsmode == 'Maps from file & Settings from plugin' || $settingsmode == 'All from the plugin') {
$name = $value->setting; $gmsettings = $this->getGMSettings($this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MATCH_GAMEMODE_BASE), $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MATCH_CUSTOM_GAMEMODE));
if (substr($name,0, 2) == "S_") {
if ($deletesettings) $this->maniaControl->getSettingManager()->deleteSetting($this, $name); foreach ($allsettings as $key => $value) {
$name = $value->setting;
if (substr($name,0, 2) == "S_" && !isset($gmsettings[$name])) {
if ($deletesettings) $this->maniaControl->getSettingManager()->deleteSetting($this, $name);
}
}
foreach ($gmsettings as $key => $value) {
$this->maniaControl->getSettingManager()->initSetting($this, $key, $value['default'], $value['description'], 100);
}
} else {
foreach ($allsettings as $key => $value) {
$name = $value->setting;
if (substr($name,0, 2) == "S_") {
if ($deletesettings) $this->maniaControl->getSettingManager()->deleteSetting($this, $name);
}
} }
} }
} }
@ -1010,8 +1033,8 @@ 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(self::CHAT_PREFIX . " Impossible to read custom gamemode file");
} }
} }
@ -1050,7 +1073,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])) {
@ -1106,7 +1129,7 @@ class MatchManagerCore implements CallbackListener, CommandListener, TimerListen
*/ */
private function canStartMatch() { private function canStartMatch() {
if ($this->matchStarted) { if ($this->matchStarted) {
$this->maniaControl->getChat()->sendErrorToAdmins($this->chatprefix . " a match is already launched"); $this->maniaControl->getChat()->sendErrorToAdmins(self::CHAT_PREFIX . " a match is already launched");
return false; return false;
} }
@ -1127,6 +1150,8 @@ class MatchManagerCore implements CallbackListener, CommandListener, TimerListen
if (!$this->canStartMatch()) return; if (!$this->canStartMatch()) return;
try { try {
$this->resetMatchVariables();
$this->matchid = $this->maniaControl->getServer()->login . "-" . time(); $this->matchid = $this->maniaControl->getServer()->login . "-" . time();
$this->currentgmbase = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MATCH_GAMEMODE_BASE); $this->currentgmbase = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MATCH_GAMEMODE_BASE);
$this->currentcustomgm = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MATCH_CUSTOM_GAMEMODE); $this->currentcustomgm = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MATCH_CUSTOM_GAMEMODE);
@ -1134,8 +1159,8 @@ class MatchManagerCore implements CallbackListener, CommandListener, TimerListen
$maplist = ""; $maplist = "";
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(self::CHAT_PREFIX . "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
@ -1145,7 +1170,7 @@ class MatchManagerCore implements CallbackListener, CommandListener, TimerListen
try { try {
$mapInfo = $this->maniaControl->getMapManager()->initializeMap($this->maniaControl->getClient()->getMapInfo($map)); $mapInfo = $this->maniaControl->getMapManager()->initializeMap($this->maniaControl->getClient()->getMapInfo($map));
} catch (Exception $e) { } catch (Exception $e) {
throw new \Exception("Error with the map " . $map . ": " . $e->getMessage()); throw new \Exception('Error with the Map to play "' . $map . '": ' . $e->getMessage());
} }
} }
@ -1161,7 +1186,11 @@ class MatchManagerCore implements CallbackListener, CommandListener, TimerListen
// Remove all maps // Remove all maps
foreach ($this->maniaControl->getMapManager()->getMaps() as $map) { foreach ($this->maniaControl->getMapManager()->getMaps() as $map) {
$this->maniaControl->getClient()->removeMap($map->fileName); try {
$this->maniaControl->getClient()->removeMap($map->fileName);
} catch (Exception $e) {
throw new \Exception('Error when removing map "' . $map->getEscapedName() . '" from the playlist: ' . $e->getMessage());
}
} }
$this->maps = $maps; $this->maps = $maps;
@ -1169,24 +1198,25 @@ class MatchManagerCore implements CallbackListener, CommandListener, TimerListen
} }
// Define Gamemode // Define Gamemode
$scriptName = '-';
if ($this->currentsettingmode != 'All from file') { if ($this->currentsettingmode != 'All from file') {
if (empty($this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MATCH_CUSTOM_GAMEMODE))) { if (empty($this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MATCH_CUSTOM_GAMEMODE))) {
$scriptName = "Trackmania/TM_" ; $scriptName = "Trackmania/TM_" ;
$scriptName .= $this->currentgmbase; $scriptName .= $this->currentgmbase;
$scriptName .= "_Online.Script.txt"; $scriptName .= "_Online.Script.txt";
$this->maniaControl->getChat()->sendSuccess($this->chatprefix . 'Match start in ' . $this->currentgmbase . ' mode!'); $this->maniaControl->getChat()->sendSuccess(self::CHAT_PREFIX . 'Match start in ' . $this->currentgmbase . ' mode!');
} else { } else {
$scriptName = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MATCH_CUSTOM_GAMEMODE); $scriptName = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MATCH_CUSTOM_GAMEMODE);
$this->maniaControl->getChat()->sendSuccess($this->chatprefix . 'Match start with script ' . $scriptName . ' (based on ' . $this->currentgmbase . ')'); $this->maniaControl->getChat()->sendSuccess(self::CHAT_PREFIX . '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;
@ -1194,7 +1224,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)");
} }
@ -1215,17 +1245,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);
} }
@ -1240,7 +1270,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
@ -1254,12 +1284,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(self::CHAT_PREFIX . "Can't start the match: ". $e->getMessage());
} }
} }
@ -1275,14 +1305,14 @@ class MatchManagerCore implements CallbackListener, CommandListener, TimerListen
$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);
} else { } else if ($this->currentmap !== null) {
if ($this->currentmap->mapType == "TrackMania\TM_Race") { if ($this->currentmap->mapType == "TrackMania\TM_Race") {
$scriptname = "Trackmania/TM_TimeAttack_Online.Script.txt" ; $scriptname = "Trackmania/TM_TimeAttack_Online.Script.txt" ;
} else if ($this->currentmap->mapType == "TrackMania\TM_Royal") { } else if ($this->currentmap->mapType == "TrackMania\TM_Royal") {
$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);
} }
} }
@ -1297,7 +1327,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
@ -1317,7 +1347,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();
@ -1333,7 +1363,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();
@ -1344,17 +1374,16 @@ class MatchManagerCore implements CallbackListener, CommandListener, TimerListen
$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);
// End notifications // End notifications
$this->maniaControl->getChat()->sendSuccess($this->chatprefix . "Match finished"); $this->maniaControl->getChat()->sendSuccess(self::CHAT_PREFIX . "Match finished");
Logger::log("Match finished"); $this->log("Match finished");
$this->resetMatchVariables(); $this->resetMatchVariables();
$this->postmatch = true;
$this->updateAdminUIMenuItems(); $this->updateAdminUIMenuItems();
// Teams Specifics variables
$this->currentteamsscore = [];
} catch (Exception $e) { } catch (Exception $e) {
$this->maniaControl->getChat()->sendErrorToAdmins($this->chatprefix . 'Can not finish match: ' . $e->getMessage()); $this->maniaControl->getChat()->sendErrorToAdmins(self::CHAT_PREFIX . "Can't finish the match: " . $e->getMessage());
$this->logError("Can't finish the match: ". $e->getMessage());
} }
} }
@ -1362,9 +1391,9 @@ 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(self::CHAT_PREFIX . " No match launched");
return; return;
} }
@ -1375,7 +1404,7 @@ class MatchManagerCore implements CallbackListener, CommandListener, TimerListen
// 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(self::CHAT_PREFIX . 'Match stopped by an Admin!');
// Cancel pause if match stopped during a pause // Cancel pause if match stopped during a pause
if ($this->pauseon) { if ($this->pauseon) {
@ -1386,24 +1415,27 @@ class MatchManagerCore implements CallbackListener, CommandListener, TimerListen
$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);
} else { } else if ($this->currentmap !== null) {
if ($this->currentmap->mapType == "TrackMania\TM_Race") { if ($this->currentmap->mapType == "TrackMania\TM_Race") {
$scriptname = "Trackmania/TM_TimeAttack_Online.Script.txt" ; $scriptname = "Trackmania/TM_TimeAttack_Online.Script.txt" ;
} else if ($this->currentmap->mapType == "TrackMania\TM_Royal") { } else if ($this->currentmap->mapType == "TrackMania\TM_Royal") {
$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);
} }
} }
$this->resetMatchVariables(); $this->resetMatchVariables();
$this->postmatch = true;
$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(self::CHAT_PREFIX . "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();
} }
@ -1412,14 +1444,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();
@ -1436,7 +1468,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();
@ -1458,7 +1490,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;
} }
@ -1474,18 +1506,18 @@ class MatchManagerCore implements CallbackListener, CommandListener, TimerListen
$this->pointstorecover[$value['login']] = $value['matchpoints']; $this->pointstorecover[$value['login']] = $value['matchpoints'];
} }
} }
$this->maniaControl->getChat()->sendSuccess($this->chatprefix . 'Recovering the match: ' . $matchid ); $this->maniaControl->getChat()->sendSuccess(self::CHAT_PREFIX . '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 {
$this->maniaControl->getChat()->sendErrorToAdmins($this->chatprefix . 'No data found from the last round'); $this->maniaControl->getChat()->sendErrorToAdmins(self::CHAT_PREFIX . 'No data found from the last round');
} }
} else { } else {
$this->maniaControl->getChat()->sendErrorToAdmins($this->chatprefix . 'No Rounds found for this match'); $this->maniaControl->getChat()->sendErrorToAdmins(self::CHAT_PREFIX . 'No Rounds found for this match');
} }
} else { } else {
$this->maniaControl->getChat()->sendErrorToAdmins($this->chatprefix . 'Match not found'); $this->maniaControl->getChat()->sendErrorToAdmins(self::CHAT_PREFIX . 'Match not found');
} }
return false; return false;
@ -1499,11 +1531,11 @@ class MatchManagerCore implements CallbackListener, CommandListener, TimerListen
if ($this->currentgmbase == "Teams") { if ($this->currentgmbase == "Teams") {
// Blue Team // Blue Team
$this->maniaControl->getModeScriptEventManager()->setTrackmaniaTeamPoints("0", "", $this->pointstorecover[0], $this->pointstorecover[0]); $this->maniaControl->getModeScriptEventManager()->setTrackmaniaTeamPoints("0", "", $this->pointstorecover[0], $this->pointstorecover[0]);
$this->maniaControl->getChat()->sendSuccess($this->chatprefix . '$<$ff0' . $this->pointstorecover[0] . '$> points recovered for the $<$00fBlue$> Team'); $this->maniaControl->getChat()->sendSuccess(self::CHAT_PREFIX . '$<$ff0' . $this->pointstorecover[0] . '$> points recovered for the $<$00fBlue$> Team');
// 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(self::CHAT_PREFIX . '$<$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) {
@ -1520,9 +1552,9 @@ class MatchManagerCore implements CallbackListener, CommandListener, TimerListen
$points = $value; $points = $value;
} }
$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(self::CHAT_PREFIX . '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 . ")");
} }
} }
} }
@ -1543,8 +1575,8 @@ class MatchManagerCore implements CallbackListener, CommandListener, TimerListen
$results = $structure->getPlayerScores(); $results = $structure->getPlayerScores();
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(self::CHAT_PREFIX . "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 = [];
@ -1642,11 +1674,11 @@ 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(self::CHAT_PREFIX . '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);
@ -1657,7 +1689,7 @@ class MatchManagerCore implements CallbackListener, CommandListener, TimerListen
$this->pauseon = true; $this->pauseon = true;
$this->maniaControl->getModeScriptEventManager()->startPause(); $this->maniaControl->getModeScriptEventManager()->startPause();
$this->maniaControl->getChat()->sendSuccessToAdmins($this->chatprefix . 'You can interrupt the pause with the command //matchendpause'); $this->maniaControl->getChat()->sendSuccessToAdmins(self::CHAT_PREFIX . 'You can interrupt the pause with the command //matchendpause');
if ($this->pausetimer > 0) { if ($this->pausetimer > 0) {
$this->displayPauseWidget(); $this->displayPauseWidget();
@ -1672,7 +1704,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();
@ -1763,14 +1795,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));
} }
@ -1778,7 +1810,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);
@ -1805,18 +1837,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);
} }
@ -1829,7 +1861,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;
@ -1839,8 +1871,8 @@ 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 = self::CHAT_PREFIX . '$<$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);
@ -1854,7 +1886,7 @@ class MatchManagerCore implements CallbackListener, CommandListener, TimerListen
$i++; $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 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:$>'; $message = self::CHAT_PREFIX . '$<$o$iNext Maps:$>';
$nbhiddenmaps = 0; $nbhiddenmaps = 0;
if ($this->hidenextmaps) { if ($this->hidenextmaps) {
@ -1865,7 +1897,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");
} }
} }
@ -1878,10 +1910,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;
} }
@ -1889,11 +1921,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);
@ -1913,7 +1945,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) {
@ -1925,7 +1957,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) {
@ -1940,12 +1972,12 @@ class MatchManagerCore implements CallbackListener, CommandListener, TimerListen
if (in_array($this->currentgmbase, ["Cup", "Teams", "Rounds"])) { if (in_array($this->currentgmbase, ["Cup", "Teams", "Rounds"])) {
$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(self::CHAT_PREFIX . '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(self::CHAT_PREFIX . '$o$iRound: ' . $this->nbrounds . ' / ' . $this->settings_nbroundsbymap);
Logger::log("Round: " . $this->nbrounds . ' / ' . $this->settings_nbroundsbymap); $this->log("Round: " . $this->nbrounds . ' / ' . $this->settings_nbroundsbymap);
} }
} }
}); });
@ -1965,10 +1997,9 @@ 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 - Section: " . $structure->getSection());
if ($this->matchStarted && $this->settingsloaded && !$this->postmatch) { if ($this->matchStarted && $this->settingsloaded && !$this->postmatch) {
Logger::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();
@ -1978,6 +2009,7 @@ class MatchManagerCore implements CallbackListener, CommandListener, TimerListen
$this->preendroundscore = $structure; $this->preendroundscore = $structure;
} elseif ($structure->getSection() == "EndRound") { } elseif ($structure->getSection() == "EndRound") {
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->log("Computing current scores");
$this->computeCurrentScores($structure); $this->computeCurrentScores($structure);
$timestamp = time(); $timestamp = time();
@ -1994,7 +2026,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();
@ -2023,7 +2055,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();
@ -2039,14 +2071,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);
} }
} }
@ -2088,7 +2120,7 @@ class MatchManagerCore implements CallbackListener, CommandListener, TimerListen
if ($this->pauseon == false) { if ($this->pauseon == false) {
$this->MatchStop(); $this->MatchStop();
} else { } else {
$this->maniaControl->getChat()->sendError($this->chatprefix . 'Impossible to stop a match during a pause' ,$player); $this->maniaControl->getChat()->sendError(self::CHAT_PREFIX . 'Impossible to stop a match during a pause' ,$player);
} }
} }
@ -2114,7 +2146,7 @@ class MatchManagerCore implements CallbackListener, CommandListener, TimerListen
} else { } else {
$lastmatches = $this->getMatchesList(3); $lastmatches = $this->getMatchesList(3);
$message = $this->chatprefix . '$<run this command with an index or "latest"$>' . "\n"; $message = self::CHAT_PREFIX . '$<run this command with an index or "latest"$>' . "\n";
foreach ($lastmatches as $index => $value) { foreach ($lastmatches as $index => $value) {
if ($index >= 3) { if ($index >= 3) {
@ -2128,7 +2160,7 @@ class MatchManagerCore implements CallbackListener, CommandListener, TimerListen
} }
} }
$this->maniaControl->getChat()->sendSuccess($message, $player); $this->maniaControl->getChat()->sendSuccess($message, $player);
$this->maniaControl->getChat()->sendError($this->chatprefix . 'For the moment, only point recovery is supported, you have to manage maps and rounds manually'); $this->maniaControl->getChat()->sendError(self::CHAT_PREFIX . 'For the moment, only point recovery is supported, you have to manage maps and rounds manually');
} }
} }
@ -2173,7 +2205,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);
@ -2181,30 +2213,30 @@ class MatchManagerCore implements CallbackListener, CommandListener, TimerListen
} }
if (!$this->getMatchIsRunning()) { if (!$this->getMatchIsRunning()) {
$this->maniaControl->getChat()->sendError($this->chatprefix . 'Can\'t start Pause: Match not started', $player); $this->maniaControl->getChat()->sendError(self::CHAT_PREFIX . 'Can\'t start Pause: Match not started', $player);
} else if ($this->pauseon) { } else if ($this->pauseon) {
$this->maniaControl->getChat()->sendError($this->chatprefix . 'Can\'t start Pause: Pause already running', $player); $this->maniaControl->getChat()->sendError(self::CHAT_PREFIX . 'Can\'t start Pause: Pause already running', $player);
} else if (in_array($this->currentgmbase, ["Laps", "TimeAttack", "RoyalTimeAttack"])) { } else if (in_array($this->currentgmbase, ["Laps", "TimeAttack", "RoyalTimeAttack"])) {
$this->maniaControl->getChat()->sendError($this->chatprefix . 'Can\'t start Pause: Invalid gamemode base', $player); $this->maniaControl->getChat()->sendError(self::CHAT_PREFIX . 'Can\'t start Pause: Invalid gamemode base', $player);
} else { } else {
$text = $chatCallback[1][2]; $text = $chatCallback[1][2];
$text = explode(" ", $text); $text = explode(" ", $text);
if (isset($text[1]) && $text[1] != "") { if (isset($text[1]) && $text[1] != "") {
if (is_numeric($text[1]) && $text[1] > 0) { if (is_numeric($text[1]) && $text[1] > 0) {
$this->maniaControl->getChat()->sendSuccess($this->chatprefix . 'Admin force a pause for $<$ff0' . $text[1] . '$> seconds!'); $this->maniaControl->getChat()->sendSuccess(self::CHAT_PREFIX . 'Admin force a pause for $<$ff0' . $text[1] . '$> seconds!');
$this->setNadeoPause(true, $text[1]); $this->setNadeoPause(true, $text[1]);
} elseif (is_numeric($text[1]) && $text[1] == 0) { } elseif (is_numeric($text[1]) && $text[1] == 0) {
$this->maniaControl->getChat()->sendSuccess($this->chatprefix . 'Admin force an unlimited pause'); $this->maniaControl->getChat()->sendSuccess(self::CHAT_PREFIX . 'Admin force an unlimited pause');
$this->setNadeoPause(true, $text[1]); $this->setNadeoPause(true, $text[1]);
} else { } else {
$this->maniaControl->getChat()->sendError($this->chatprefix . 'Pause time sent is invalid', $player); $this->maniaControl->getChat()->sendError(self::CHAT_PREFIX . 'Pause time sent is invalid', $player);
} }
} else { } else {
$duration = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MATCH_PAUSE_DURATION); $duration = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MATCH_PAUSE_DURATION);
if ($duration > 0) { if ($duration > 0) {
$this->maniaControl->getChat()->sendSuccess($this->chatprefix . 'Admin force a pause for ' . $duration . ' seconds!'); $this->maniaControl->getChat()->sendSuccess(self::CHAT_PREFIX . 'Admin force a pause for ' . $duration . ' seconds!');
} else { } else {
$this->maniaControl->getChat()->sendSuccess($this->chatprefix . 'Admin force a pause'); $this->maniaControl->getChat()->sendSuccess(self::CHAT_PREFIX . 'Admin force a pause');
} }
$this->setNadeoPause(true); $this->setNadeoPause(true);
@ -2225,7 +2257,7 @@ class MatchManagerCore implements CallbackListener, CommandListener, TimerListen
return; return;
} }
if (($this->matchStarted) && (!in_array($this->currentgmbase, ["Laps", "TimeAttack", "RoyalTimeAttack"]) || ( $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MATCH_SETTINGS_MODE) != 'All from file' && !empty($this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MATCH_CUSTOM_GAMEMODE)))) && $this->pauseon) { if (($this->matchStarted) && (!in_array($this->currentgmbase, ["Laps", "TimeAttack", "RoyalTimeAttack"]) || ( $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MATCH_SETTINGS_MODE) != 'All from file' && !empty($this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MATCH_CUSTOM_GAMEMODE)))) && $this->pauseon) {
$this->maniaControl->getChat()->sendSuccess($this->chatprefix . 'Admin stopped the break'); $this->maniaControl->getChat()->sendSuccess(self::CHAT_PREFIX . 'Admin stopped the break');
$this->unsetNadeoPause(); $this->unsetNadeoPause();
} }
} }
@ -2247,7 +2279,7 @@ class MatchManagerCore implements CallbackListener, CommandListener, TimerListen
$text = explode(" ", $text); $text = explode(" ", $text);
if (count($text) < 3) { if (count($text) < 3) {
$this->maniaControl->getChat()->sendError($this->chatprefix . 'Missing parameters. Eg: //matchsetpoints <Player Name or Login> <Match points> <Map Points (optional)> <Round Points (optional)>', $adminplayer); $this->maniaControl->getChat()->sendError(self::CHAT_PREFIX . 'Missing parameters. Eg: //matchsetpoints <Player Name or Login> <Match points> <Map Points (optional)> <Round Points (optional)>', $adminplayer);
return; return;
} }
@ -2257,14 +2289,14 @@ class MatchManagerCore implements CallbackListener, CommandListener, TimerListen
$roundpoints = ''; $roundpoints = '';
if (!is_numeric($matchpoints)) { if (!is_numeric($matchpoints)) {
$this->maniaControl->getChat()->sendError($this->chatprefix . 'Invalid argument: Match points', $adminplayer); $this->maniaControl->getChat()->sendError(self::CHAT_PREFIX . 'Invalid argument: Match points', $adminplayer);
return; return;
} }
if (isset($text[3])) { if (isset($text[3])) {
$mappoints = $text[3]; $mappoints = $text[3];
if (!is_numeric($mappoints)) { if (!is_numeric($mappoints)) {
$this->maniaControl->getChat()->sendError($this->chatprefix . 'Invalid argument: Map points', $adminplayer); $this->maniaControl->getChat()->sendError(self::CHAT_PREFIX . 'Invalid argument: Map points', $adminplayer);
return; return;
} }
} }
@ -2272,7 +2304,7 @@ class MatchManagerCore implements CallbackListener, CommandListener, TimerListen
if (isset($text[4])) { if (isset($text[4])) {
$roundpoints = $text[4]; $roundpoints = $text[4];
if (!is_numeric($roundpoints)) { if (!is_numeric($roundpoints)) {
$this->maniaControl->getChat()->sendError($this->chatprefix . 'Invalid argument: Round points', $adminplayer); $this->maniaControl->getChat()->sendError(self::CHAT_PREFIX . 'Invalid argument: Round points', $adminplayer);
return; return;
} }
} }
@ -2282,7 +2314,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();
@ -2301,12 +2333,12 @@ class MatchManagerCore implements CallbackListener, CommandListener, TimerListen
$player = $this->maniaControl->getPlayerManager()->getPlayer($login,true); $player = $this->maniaControl->getPlayerManager()->getPlayer($login,true);
if ($player) { if ($player) {
$this->maniaControl->getModeScriptEventManager()->setTrackmaniaPlayerPoints($player, $roundpoints, $mappoints, $matchpoints); $this->maniaControl->getModeScriptEventManager()->setTrackmaniaPlayerPoints($player, $roundpoints, $mappoints, $matchpoints);
$this->maniaControl->getChat()->sendSuccess($this->chatprefix . 'Player $<$ff0' . $player->nickname . '$> now has $<$ff0' . $matchpoints . '$> points!'); $this->maniaControl->getChat()->sendSuccess(self::CHAT_PREFIX . 'Player $<$ff0' . $player->nickname . '$> now has $<$ff0' . $matchpoints . '$> points!');
} else { } else {
$this->maniaControl->getChat()->sendError($this->chatprefix . 'Player ' . $target . " isn't connected", $adminplayer); $this->maniaControl->getChat()->sendError(self::CHAT_PREFIX . 'Player ' . $target . " isn't connected", $adminplayer);
} }
} else { } else {
$this->maniaControl->getChat()->sendError($this->chatprefix . 'Player ' . $target . " doesn't exist", $adminplayer); $this->maniaControl->getChat()->sendError(self::CHAT_PREFIX . 'Player ' . $target . " doesn't exist", $adminplayer);
} }
} }
@ -2321,7 +2353,7 @@ class MatchManagerCore implements CallbackListener, CommandListener, TimerListen
$text = explode(" ", $text); $text = explode(" ", $text);
if (count($text) < 3) { if (count($text) < 3) {
$this->maniaControl->getChat()->sendError($this->chatprefix . 'Missing parameters. Eg: //matchsetteampoints <Team Name or Id> <Match points> <Map Points (optional)> <Round Points (optional)>', $adminplayer); $this->maniaControl->getChat()->sendError(self::CHAT_PREFIX . 'Missing parameters. Eg: //matchsetteampoints <Team Name or Id> <Match points> <Map Points (optional)> <Round Points (optional)>', $adminplayer);
return; return;
} }
@ -2331,14 +2363,14 @@ class MatchManagerCore implements CallbackListener, CommandListener, TimerListen
$roundpoints = ''; $roundpoints = '';
if (!is_numeric($matchpoints)) { if (!is_numeric($matchpoints)) {
$this->maniaControl->getChat()->sendError($this->chatprefix . 'Invalid argument: Match points', $adminplayer); $this->maniaControl->getChat()->sendError(self::CHAT_PREFIX . 'Invalid argument: Match points', $adminplayer);
return; return;
} }
if (isset($text[3])) { if (isset($text[3])) {
$mappoints = $text[3]; $mappoints = $text[3];
if (!is_numeric($mappoints)) { if (!is_numeric($mappoints)) {
$this->maniaControl->getChat()->sendError($this->chatprefix . 'Invalid argument: Map points', $adminplayer); $this->maniaControl->getChat()->sendError(self::CHAT_PREFIX . 'Invalid argument: Map points', $adminplayer);
return; return;
} }
} }
@ -2346,22 +2378,22 @@ class MatchManagerCore implements CallbackListener, CommandListener, TimerListen
if (isset($text[4])) { if (isset($text[4])) {
$roundpoints = $text[4]; $roundpoints = $text[4];
if (!is_numeric($roundpoints)) { if (!is_numeric($roundpoints)) {
$this->maniaControl->getChat()->sendError($this->chatprefix . 'Invalid argument: Round points', $adminplayer); $this->maniaControl->getChat()->sendError(self::CHAT_PREFIX . 'Invalid argument: Round points', $adminplayer);
return; return;
} }
} }
if (strcasecmp($target, "Blue") == 0 || $target == "0") { if (strcasecmp($target, "Blue") == 0 || $target == "0") {
$this->maniaControl->getModeScriptEventManager()->setTrackmaniaTeamPoints("0", $roundpoints, $mappoints, $matchpoints); $this->maniaControl->getModeScriptEventManager()->setTrackmaniaTeamPoints("0", $roundpoints, $mappoints, $matchpoints);
$this->maniaControl->getChat()->sendSuccess($this->chatprefix . '$<$00fBlue$> Team now has $<$ff0' . $matchpoints . '$> points!'); $this->maniaControl->getChat()->sendSuccess(self::CHAT_PREFIX . '$<$00fBlue$> Team now has $<$ff0' . $matchpoints . '$> points!');
} elseif (strcasecmp($target, "Red") == 0 || $target == "1") { } elseif (strcasecmp($target, "Red") == 0 || $target == "1") {
$this->maniaControl->getModeScriptEventManager()->setTrackmaniaTeamPoints("1", $roundpoints, $mappoints, $matchpoints); $this->maniaControl->getModeScriptEventManager()->setTrackmaniaTeamPoints("1", $roundpoints, $mappoints, $matchpoints);
$this->maniaControl->getChat()->sendSuccess($this->chatprefix . '$<$f00Red$> Team now has $<$ff0' . $matchpoints . '$> points!'); $this->maniaControl->getChat()->sendSuccess(self::CHAT_PREFIX . '$<$f00Red$> Team now has $<$ff0' . $matchpoints . '$> points!');
} elseif (is_numeric($target)) { //TODO: add support of name of teams (need update from NADEO) } elseif (is_numeric($target)) { //TODO: add support of name of teams (need update from NADEO)
$this->maniaControl->getModeScriptEventManager()->setTrackmaniaTeamPoints($target, $roundpoints, $mappoints, $matchpoints); $this->maniaControl->getModeScriptEventManager()->setTrackmaniaTeamPoints($target, $roundpoints, $mappoints, $matchpoints);
$this->maniaControl->getChat()->sendSuccess($this->chatprefix . 'Team ' . $target . ' now has $<$ff0' . $matchpoints . '$> points!'); $this->maniaControl->getChat()->sendSuccess(self::CHAT_PREFIX . 'Team ' . $target . ' now has $<$ff0' . $matchpoints . '$> points!');
} else { } else {
$this->maniaControl->getChat()->sendError($this->chatprefix . 'Can\'t find team: ' . $target, $adminplayer); $this->maniaControl->getChat()->sendError(self::CHAT_PREFIX . 'Can\'t find team: ' . $target, $adminplayer);
} }
} }

View File

@ -14,6 +14,7 @@ use ManiaControl\Callbacks\Structures\TrackMania\OnWayPointEventStructure;
use ManiaControl\Callbacks\TimerListener; use ManiaControl\Callbacks\TimerListener;
use ManiaControl\Manialinks\ManialinkPageAnswerListener; use ManiaControl\Manialinks\ManialinkPageAnswerListener;
use ManiaControl\Players\Player; use ManiaControl\Players\Player;
use ManiaControl\Plugins\PluginManager;
use ManiaControl\Plugins\PluginMenu; use ManiaControl\Plugins\PluginMenu;
if (!class_exists('MatchManagerSuite\MatchManagerCore')) { if (!class_exists('MatchManagerSuite\MatchManagerCore')) {
@ -33,10 +34,12 @@ class MatchManagerECircuitMania implements CallbackListener, ManialinkPageAnswer
* Constants * Constants
*/ */
const PLUGIN_ID = 213; const PLUGIN_ID = 213;
const PLUGIN_VERSION = 1.0; const PLUGIN_VERSION = 1.1;
const PLUGIN_NAME = 'MatchManager eCircuitMania'; const PLUGIN_NAME = 'MatchManager eCircuitMania';
const PLUGIN_AUTHOR = 'Beu'; const PLUGIN_AUTHOR = 'Beu';
const LOG_PREFIX = '[MatchManagerECircuitMania] ';
const MATCHMANAGERCORE_PLUGIN = 'MatchManagerSuite\MatchManagerCore'; const MATCHMANAGERCORE_PLUGIN = 'MatchManagerSuite\MatchManagerCore';
const MATCHMANAGERADMINUI_PLUGIN = 'MatchManagerSuite\MatchManagerAdminUI'; const MATCHMANAGERADMINUI_PLUGIN = 'MatchManagerSuite\MatchManagerAdminUI';
@ -108,10 +111,12 @@ class MatchManagerECircuitMania implements CallbackListener, ManialinkPageAnswer
$this->MatchManagerCore = $this->maniaControl->getPluginManager()->getPlugin(self::MATCHMANAGERCORE_PLUGIN); $this->MatchManagerCore = $this->maniaControl->getPluginManager()->getPlugin(self::MATCHMANAGERCORE_PLUGIN);
if ($this->MatchManagerCore === null) { if ($this->MatchManagerCore === null) {
$this->maniaControl->getChat()->sendErrorToAdmins('MatchManager Core is needed to use ' . self::PLUGIN_NAME . ' plugin.'); $this->maniaControl->getChat()->sendErrorToAdmins('MatchManager Core is needed to use ' . self::PLUGIN_NAME . ' plugin.');
$this->maniaControl->getPluginManager()->deactivatePlugin((get_class())); $this->maniaControl->getPluginManager()->deactivatePlugin((get_class($this)));
return; return;
} }
$this->maniaControl->getCallbackManager()->registerCallbackListener(PluginManager::CB_PLUGIN_LOADED, $this, 'handlePluginLoaded');
$this->maniaControl->getCallbackManager()->registerCallbackListener(PluginManager::CB_PLUGIN_UNLOADED, $this, 'handlePluginUnloaded');
$this->maniaControl->getCallbackManager()->registerScriptCallbackListener(self::CB_STARTMAP, $this, 'handleStartMap'); $this->maniaControl->getCallbackManager()->registerScriptCallbackListener(self::CB_STARTMAP, $this, 'handleStartMap');
$this->maniaControl->getCallbackManager()->registerCallbackListener(Callbacks::MP_STARTROUNDSTART, $this, 'handleStartRound'); $this->maniaControl->getCallbackManager()->registerCallbackListener(Callbacks::MP_STARTROUNDSTART, $this, 'handleStartRound');
$this->maniaControl->getCallbackManager()->registerCallbackListener(Callbacks::TM_ONWAYPOINT, $this, 'handleOnWaypoint'); $this->maniaControl->getCallbackManager()->registerCallbackListener(Callbacks::TM_ONWAYPOINT, $this, 'handleOnWaypoint');
@ -130,6 +135,24 @@ class MatchManagerECircuitMania implements CallbackListener, ManialinkPageAnswer
$this->maniaControl->getManialinkManager()->registerManialinkPageAnswerListener(self::ML_ACTION_OPENSETTINGS, $this, 'handleActionOpenSettings'); $this->maniaControl->getManialinkManager()->registerManialinkPageAnswerListener(self::ML_ACTION_OPENSETTINGS, $this, 'handleActionOpenSettings');
} }
/**
* Custom log function to add prefix
*
* @param mixed $message
*/
private function log(mixed $message) {
Logger::log(self::LOG_PREFIX . $message);
}
/**
* Custom logError function to add prefix
*
* @param mixed $message
*/
private function logError(mixed $message) {
Logger::logError(self::LOG_PREFIX . $message);
}
/** /**
* handle Plugin Loaded * handle Plugin Loaded
* *
@ -141,6 +164,22 @@ class MatchManagerECircuitMania implements CallbackListener, ManialinkPageAnswer
} }
} }
/**
* handlePluginUnloaded
*
* @param string $pluginClass
* @param Plugin $plugin
* @return void
*/
public function handlePluginUnloaded(string $pluginClass, Plugin $plugin) {
if ($pluginClass == self::MATCHMANAGERCORE_PLUGIN) {
$this->maniaControl->getChat()->sendErrorToAdmins(self::PLUGIN_NAME . " disabled because MatchManager Core is now disabled");
$this->log(self::PLUGIN_NAME . " disabled because MatchManager Core is now disabled");
$this->maniaControl->getPluginManager()->deactivatePlugin((get_class($this)));
}
}
/** /**
* Add items in AdminUI plugin * Add items in AdminUI plugin
*/ */
@ -214,7 +253,7 @@ class MatchManagerECircuitMania implements CallbackListener, ManialinkPageAnswer
if ($request !== null) { if ($request !== null) {
$request->setContent($payload)->setCallable(function ($content, $error, $headers) use ($payload) { $request->setContent($payload)->setCallable(function ($content, $error, $headers) use ($payload) {
if ($content !== "Created" || $error !== null) { if ($content !== "Created" || $error !== null) {
Logger::logWarning("Error on the 'addRoundTime' request. answer: " . $content . " / error: " . $error . " / payload: " . $payload); $this->logError("Error on the 'addRoundTime' request. answer: " . $content . " / error: " . $error . " / payload: " . $payload);
} }
})->postData(); })->postData();
} }
@ -226,7 +265,6 @@ class MatchManagerECircuitMania implements CallbackListener, ManialinkPageAnswer
$scores = []; $scores = [];
foreach ($structure->getPlayerScores() as $playerscore) { foreach ($structure->getPlayerScores() as $playerscore) {
if ($playerscore->getMatchPoints() <= -2000) continue;
$scores[] = $playerscore; $scores[] = $playerscore;
} }
@ -284,7 +322,7 @@ class MatchManagerECircuitMania implements CallbackListener, ManialinkPageAnswer
if ($request !== null) { if ($request !== null) {
$request->setContent($payload)->setCallable(function ($content, $error, $headers) use ($payload) { $request->setContent($payload)->setCallable(function ($content, $error, $headers) use ($payload) {
if ($content !== "Created" || $error !== null) { if ($content !== "Created" || $error !== null) {
Logger::logWarning("Error on the 'addRound' request. answer: " . $content . " / error: " . $error . " / payload: " . $payload); $this->logError("Error on the 'addRound' request. answer: " . $content . " / error: " . $error . " / payload: " . $payload);
} }
})->postData(); })->postData();
} }
@ -304,7 +342,7 @@ class MatchManagerECircuitMania implements CallbackListener, ManialinkPageAnswer
if ($request !== null) { if ($request !== null) {
$request->setContent($payload)->setCallable(function ($content, $error, $headers) use ($payload) { $request->setContent($payload)->setCallable(function ($content, $error, $headers) use ($payload) {
if ($content !== "Created" || $error !== null) { if ($content !== "Created" || $error !== null) {
Logger::logWarning("Error on the 'removeRound' request. answer: " . $content . " / error: " . $error . " / payload: " . $payload); $this->logError("Error on the 'removeRound' request. answer: " . $content . " / error: " . $error . " / payload: " . $payload);
} }
})->postData(); })->postData();
} }
@ -334,5 +372,11 @@ class MatchManagerECircuitMania implements CallbackListener, ManialinkPageAnswer
/** /**
* Unload the plugin and its Resources * Unload the plugin and its Resources
*/ */
public function unload() {} public function unload() {
/** @var \MatchManagerSuite\MatchManagerAdminUI|null */
$adminUIPlugin = $this->maniaControl->getPluginManager()->getPlugin(self::MATCHMANAGERADMINUI_PLUGIN);
if ($adminUIPlugin !== null) {
$adminUIPlugin->removeMenuItem(self::ML_ACTION_OPENSETTINGS);
}
}
} }

View File

@ -21,8 +21,8 @@ use ManiaControl\Plugins\PluginMenu;
use ManiaControl\Utils\WebReader; use ManiaControl\Utils\WebReader;
if (!class_exists('MatchManagerSuite\MatchManagerCore')) { if (!class_exists('MatchManagerSuite\MatchManagerCore')) {
$this->maniaControl->getChat()->sendErrorToAdmins('MatchManager Core is required to use one of MatchManager plugin. Install it and restart Maniacontrol'); $this->maniaControl->getChat()->sendErrorToAdmins('MatchManager Core is required to use MatchManagerGSheet plugin. Install it and restart Maniacontrol');
Logger::logError('MatchManager Core is required to use one of MatchManager plugin. Install it and restart Maniacontrol'); Logger::logError('MatchManager Core is required to use MatchManagerGSheet plugin. Install it and restart Maniacontrol');
return false; return false;
} }
use MatchManagerSuite\MatchManagerCore; use MatchManagerSuite\MatchManagerCore;
@ -39,10 +39,12 @@ class MatchManagerGSheet implements CallbackListener, TimerListener, CommandLis
* Constants * Constants
*/ */
const PLUGIN_ID = 156; const PLUGIN_ID = 156;
const PLUGIN_VERSION = 2.3; const PLUGIN_VERSION = 2.4;
const PLUGIN_NAME = 'MatchManager GSheet'; const PLUGIN_NAME = 'MatchManager GSheet';
const PLUGIN_AUTHOR = 'Beu'; const PLUGIN_AUTHOR = 'Beu';
const LOG_PREFIX = '[MatchManagerGSheet] ';
// Other MatchManager plugin // Other MatchManager plugin
const MATCHMANAGERADMINUI_PLUGIN = 'MatchManagerSuite\MatchManagerAdminUI'; const MATCHMANAGERADMINUI_PLUGIN = 'MatchManagerSuite\MatchManagerAdminUI';
@ -193,9 +195,9 @@ class MatchManagerGSheet implements CallbackListener, TimerListener, CommandLis
$this->access_token = $this->getSecretSetting("access_token"); $this->access_token = $this->getSecretSetting("access_token");
$this->maniaControl->getChat()->sendErrorToAdmins('To use the MatchManagerGSheet plugin, $<$l[https://github.com/AmazingBeu/ManiacontrolPlugins/wiki/MatchManager-GSheet]check the doc$>'); $this->maniaControl->getChat()->sendErrorToAdmins($this->MatchManagerCore->getChatPrefix() .'To use the MatchManagerGSheet plugin, $<$l[https://github.com/AmazingBeu/ManiacontrolPlugins/wiki/MatchManager-GSheet]check the doc$>');
$this->maniaControl->getChat()->sendErrorToAdmins('Since MatchManagerGSheet 2.0, Player names are in the results and no more in a separated list'); $this->maniaControl->getChat()->sendErrorToAdmins($this->MatchManagerCore->getChatPrefix() .'Since MatchManagerGSheet 2.0, Player names are in the results and no more in a separated list');
$this->updateAdminUIMenuItems(); $this->updateAdminUIMenuItems();
@ -213,6 +215,24 @@ class MatchManagerGSheet implements CallbackListener, TimerListener, CommandLis
} }
} }
/**
* Custom log function to add prefix
*
* @param mixed $message
*/
private function log(mixed $message) {
Logger::log(self::LOG_PREFIX . $message);
}
/**
* Custom logError function to add prefix
*
* @param mixed $message
*/
private function logError(mixed $message) {
Logger::logError(self::LOG_PREFIX . $message);
}
/** /**
* handle Plugin Loaded * handle Plugin Loaded
* *
@ -243,7 +263,8 @@ class MatchManagerGSheet implements CallbackListener, TimerListener, CommandLis
public function handlePluginUnloaded(string $pluginClass, Plugin $plugin) { public function handlePluginUnloaded(string $pluginClass, Plugin $plugin) {
if ($pluginClass == self::MATCHMANAGERCORE_PLUGIN) { if ($pluginClass == self::MATCHMANAGERCORE_PLUGIN) {
$this->maniaControl->getChat()->sendErrorToAdmins(self::PLUGIN_NAME . " disabled because MatchManager Core is now disabled"); $this->maniaControl->getChat()->sendErrorToAdmins(self::PLUGIN_NAME . " disabled because MatchManager Core is now disabled");
$this->maniaControl->getPluginManager()->deactivatePlugin((get_class())); $this->log(self::PLUGIN_NAME . " disabled because MatchManager Core is now disabled");
$this->maniaControl->getPluginManager()->deactivatePlugin((get_class($this)));
} }
} }
@ -272,7 +293,7 @@ class MatchManagerGSheet implements CallbackListener, TimerListener, CommandLis
if ($setting->belongsToClass($this)) { if ($setting->belongsToClass($this)) {
if (($setting->setting == self::SETTING_MATCHMANAGERGSHEET_CLIENT_SECRET && $setting->value == "hidden") || $setting->setting == self::SETTING_MATCHMANAGERGSHEET_CLIENT_ID) { if (($setting->setting == self::SETTING_MATCHMANAGERGSHEET_CLIENT_SECRET && $setting->value == "hidden") || $setting->setting == self::SETTING_MATCHMANAGERGSHEET_CLIENT_ID) {
// (Check when hidden = true to avoid double message) // (Check when hidden = true to avoid double message)
$this->maniaControl->getChat()->sendErrorToAdmins('Google API Session cleared. You must revalidate a session with //matchgsheet step1'); $this->maniaControl->getChat()->sendErrorToAdmins($this->MatchManagerCore->getChatPrefix() .'Google API Session cleared. You must revalidate a session with //matchgsheet step1');
$this->saveSecretSetting("access_token"); $this->saveSecretSetting("access_token");
$this->saveSecretSetting("expire"); $this->saveSecretSetting("expire");
@ -292,7 +313,7 @@ class MatchManagerGSheet implements CallbackListener, TimerListener, CommandLis
public function handlePlayerConnect(Player $player) { public function handlePlayerConnect(Player $player) {
if ($this->maniaControl->getAuthenticationManager()->checkRight($player, AuthenticationManager::AUTH_LEVEL_ADMIN)) { if ($this->maniaControl->getAuthenticationManager()->checkRight($player, AuthenticationManager::AUTH_LEVEL_ADMIN)) {
$this->maniaControl->getChat()->sendError('Since MatchManagerGSheet 2.0, Player names are in the results and no more in a separated list', $player->login); $this->maniaControl->getChat()->sendError($this->MatchManagerCore->getChatPrefix() .'Since MatchManagerGSheet 2.0, Player names are in the results and no more in a separated list', $player->login);
} }
} }
@ -346,15 +367,15 @@ class MatchManagerGSheet implements CallbackListener, TimerListener, CommandLis
} elseif (isset($text[1]) && $text[1] == 'check') { } elseif (isset($text[1]) && $text[1] == 'check') {
$this->CheckSpeadsheetAccess($player); $this->CheckSpeadsheetAccess($player);
} else { } else {
$this->maniaControl->getChat()->sendError('use argument "step1", "step2" or "check"', $player); $this->maniaControl->getChat()->sendError($this->MatchManagerCore->getChatPrefix() .'use argument "step1", "step2" or "check"', $player);
} }
} }
private function OAuth2Step1(Player $player) { private function OAuth2Step1(Player $player) {
$clientid = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MATCHMANAGERGSHEET_CLIENT_ID); $clientid = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MATCHMANAGERGSHEET_CLIENT_ID);
if (empty($clientid)) { if (empty($clientid)) {
Logger::logError('Client ID empty'); $this->logError('Client ID empty');
$this->maniaControl->getChat()->sendError('Client ID empty', $player); $this->maniaControl->getChat()->sendError($this->MatchManagerCore->getChatPrefix() .'Client ID empty', $player);
return; return;
} }
@ -362,29 +383,29 @@ class MatchManagerGSheet implements CallbackListener, TimerListener, CommandLis
$asyncHttpRequest->setContentType("application/x-www-form-urlencoded"); $asyncHttpRequest->setContentType("application/x-www-form-urlencoded");
$asyncHttpRequest->setCallable(function ($json, $error) use ($player) { $asyncHttpRequest->setCallable(function ($json, $error) use ($player) {
if (!$json || $error) { if (!$json || $error) {
Logger::logError('Error from Google API: ' . $error); $this->logError('Error from Google API: ' . $error);
$this->maniaControl->getChat()->sendError('Error from Google API: ' . $error, $player); $this->maniaControl->getChat()->sendError($this->MatchManagerCore->getChatPrefix() .'Error from Google API: ' . $error, $player);
return; return;
} }
$data = json_decode($json); $data = json_decode($json);
if (!$data) { if (!$data) {
Logger::logError('Json parse error: ' . $json); $this->logError('Json parse error: ' . $json);
$this->maniaControl->getChat()->sendError('Json parse error: ' . $json, $player); $this->maniaControl->getChat()->sendError($this->MatchManagerCore->getChatPrefix() .'Json parse error: ' . $json, $player);
return; return;
} }
if (property_exists($data, "error")) { if (property_exists($data, "error")) {
Logger::logError('Request error: ' . $data->error->code . " ". $data->error->message); $this->logError('Request error: ' . $data->error->code . " ". $data->error->message);
$this->maniaControl->getChat()->sendErrorToAdmins('Request error: ' . $data->error->code . " ". $data->error->message); $this->maniaControl->getChat()->sendErrorToAdmins($this->MatchManagerCore->getChatPrefix() .'Request error: ' . $data->error->code . " ". $data->error->message);
return; return;
} }
if (isset($data->device_code)) { if (isset($data->device_code)) {
$this->device_code = $data->device_code; $this->device_code = $data->device_code;
$this->maniaControl->getChat()->sendSuccess('Open $<$l['. $data->verification_url .'?user_code=' . $data->user_code . ']this link$> and type this code: "' . $data->user_code .'"' , $player); $this->maniaControl->getChat()->sendSuccess($this->MatchManagerCore->getChatPrefix() .'Open $<$l['. $data->verification_url .'?user_code=' . $data->user_code . ']this link$> and type this code: "' . $data->user_code .'"' , $player);
$this->maniaControl->getChat()->sendSuccess('After have validate the App, type the commande "//matchgsheet step2"' , $player); $this->maniaControl->getChat()->sendSuccess($this->MatchManagerCore->getChatPrefix() .'After have validate the App, type the commande "//matchgsheet step2"' , $player);
} elseif (isset($data->error_code)) { } elseif (isset($data->error_code)) {
$this->maniaControl->getChat()->sendError('Google refused the request: ' . $data->error_code, $player); $this->maniaControl->getChat()->sendError($this->MatchManagerCore->getChatPrefix() .'Google refused the request: ' . $data->error_code, $player);
} else { } else {
$this->maniaControl->getChat()->sendError('Unkown error' , $player); $this->maniaControl->getChat()->sendError($this->MatchManagerCore->getChatPrefix() .'Unkown error' , $player);
} }
}); });
@ -394,21 +415,21 @@ class MatchManagerGSheet implements CallbackListener, TimerListener, CommandLis
private function OAuth2Step2(Player $player) { private function OAuth2Step2(Player $player) {
$clientid = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MATCHMANAGERGSHEET_CLIENT_ID); $clientid = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MATCHMANAGERGSHEET_CLIENT_ID);
if (empty($clientid)) { if (empty($clientid)) {
Logger::logError('Client ID empty'); $this->logError('Client ID empty');
$this->maniaControl->getChat()->sendError('Client ID empty', $player); $this->maniaControl->getChat()->sendError($this->MatchManagerCore->getChatPrefix() .'Client ID empty', $player);
return; return;
} }
$clientsecret = $this->getSecretSetting("client_secret"); $clientsecret = $this->getSecretSetting("client_secret");
if (empty($clientsecret)) { if (empty($clientsecret)) {
Logger::logError('Client Secret empty'); $this->logError('Client Secret empty');
$this->maniaControl->getChat()->sendError('Client Secret empty', $player); $this->maniaControl->getChat()->sendError($this->MatchManagerCore->getChatPrefix() .'Client Secret empty', $player);
return; return;
} }
if (empty($this->device_code)) { if (empty($this->device_code)) {
Logger::logError('No device_code. Have you run the step 1?'); $this->logError('No device_code. Have you run the step 1?');
$this->maniaControl->getChat()->sendError('No device_code. Have you run the step 1?', $player); $this->maniaControl->getChat()->sendError($this->MatchManagerCore->getChatPrefix() .'No device_code. Have you run the step 1?', $player);
return; return;
} }
@ -417,19 +438,19 @@ class MatchManagerGSheet implements CallbackListener, TimerListener, CommandLis
$asyncHttpRequest->setHeaders(array("Content-Length: 0")); $asyncHttpRequest->setHeaders(array("Content-Length: 0"));
$asyncHttpRequest->setCallable(function ($json, $error) use ($player) { $asyncHttpRequest->setCallable(function ($json, $error) use ($player) {
if (!$json || $error) { if (!$json || $error) {
Logger::logError('Error from Google API: ' . $error); $this->logError('Error from Google API: ' . $error);
$this->maniaControl->getChat()->sendError('Error from Google API: ' . $error, $player); $this->maniaControl->getChat()->sendError($this->MatchManagerCore->getChatPrefix() .'Error from Google API: ' . $error, $player);
return; return;
} }
$data = json_decode($json); $data = json_decode($json);
if (!$data) { if (!$data) {
Logger::logError('Json parse error: ' . $json); $this->logError('Json parse error: ' . $json);
$this->maniaControl->getChat()->sendError('Json parse error: ' . $json, $player); $this->maniaControl->getChat()->sendError($this->MatchManagerCore->getChatPrefix() .'Json parse error: ' . $json, $player);
return; return;
} }
if (property_exists($data, "error")) { if (property_exists($data, "error")) {
Logger::logError('Request error: ' . $data->error->code . " ". $data->error->message); $this->logError('Request error: ' . $data->error->code . " ". $data->error->message);
$this->maniaControl->getChat()->sendErrorToAdmins('Request error: ' . $data->error->code . " ". $data->error->message); $this->maniaControl->getChat()->sendErrorToAdmins($this->MatchManagerCore->getChatPrefix() .'Request error: ' . $data->error->code . " ". $data->error->message);
return; return;
} }
@ -438,13 +459,13 @@ class MatchManagerGSheet implements CallbackListener, TimerListener, CommandLis
$this->saveSecretSetting("access_token", $data->access_token); $this->saveSecretSetting("access_token", $data->access_token);
$this->saveSecretSetting("expire", time() + $data->expires_in); $this->saveSecretSetting("expire", time() + $data->expires_in);
$this->saveSecretSetting("refresh_token", $data->refresh_token); $this->saveSecretSetting("refresh_token", $data->refresh_token);
$this->maniaControl->getChat()->sendSuccess('Maniacontrol is registered' , $player); $this->maniaControl->getChat()->sendSuccess($this->MatchManagerCore->getChatPrefix() .'Maniacontrol is registered' , $player);
} elseif (isset($data->error_description)) { } elseif (isset($data->error_description)) {
Logger::logError('Google refused the request: ' . $data->error_description); $this->logError('Google refused the request: ' . $data->error_description);
$this->maniaControl->getChat()->sendError('Google refused the request: ' . $data->error_description , $player); $this->maniaControl->getChat()->sendError($this->MatchManagerCore->getChatPrefix() .'Google refused the request: ' . $data->error_description , $player);
} else { } else {
Logger::logError('Unkown error' . $data->error_description); $this->logError('Unkown error' . $data->error_description);
$this->maniaControl->getChat()->sendError('Unkown error' , $player); $this->maniaControl->getChat()->sendError($this->MatchManagerCore->getChatPrefix() .'Unkown error' , $player);
} }
}); });
@ -452,7 +473,7 @@ class MatchManagerGSheet implements CallbackListener, TimerListener, CommandLis
} }
private function refreshTokenIfNeeded() { private function refreshTokenIfNeeded() {
Logger::Log('refreshTokenIfNeeded'); $this->log('Refresh Google API token if needed');
$this->access_token = $this->getSecretSetting("access_token"); $this->access_token = $this->getSecretSetting("access_token");
$expire = $this->getSecretSetting("expire"); $expire = $this->getSecretSetting("expire");
$refreshtoken = $this->getSecretSetting("refresh_token"); $refreshtoken = $this->getSecretSetting("refresh_token");
@ -465,18 +486,18 @@ class MatchManagerGSheet implements CallbackListener, TimerListener, CommandLis
$json = $response->getContent(); $json = $response->getContent();
$error = $response->getError(); $error = $response->getError();
if (!$json || $error) { if (!$json || $error) {
Logger::logError('Error during token refresh: ' . $error); $this->logError('Error during token refresh: ' . $error);
$this->maniaControl->getChat()->sendErrorToAdmins('Error during token refresh: ' . $error); $this->maniaControl->getChat()->sendErrorToAdmins($this->MatchManagerCore->getChatPrefix() .'Error during token refresh: ' . $error);
return; return;
} }
$data = json_decode($json); $data = json_decode($json);
if (!$data) { if (!$data) {
Logger::logError('Json parse error: ' . $json); $this->logError('Json parse error: ' . $json);
return; return;
} }
if (property_exists($data, "error")) { if (property_exists($data, "error")) {
Logger::logError('Request error: ' . $data->error->code . " ". $data->error->message); $this->logError('Request error: ' . $data->error->code . " ". $data->error->message);
$this->maniaControl->getChat()->sendErrorToAdmins('Request error: ' . $data->error->code . " ". $data->error->message); $this->maniaControl->getChat()->sendErrorToAdmins($this->MatchManagerCore->getChatPrefix() .'Request error: ' . $data->error->code . " ". $data->error->message);
return; return;
} }
@ -484,10 +505,12 @@ class MatchManagerGSheet implements CallbackListener, TimerListener, CommandLis
$this->access_token = $data->access_token; $this->access_token = $data->access_token;
$this->saveSecretSetting("access_token", $data->access_token); $this->saveSecretSetting("access_token", $data->access_token);
$this->saveSecretSetting("expire", time() + $data->expires_in); $this->saveSecretSetting("expire", time() + $data->expires_in);
$this->log('Successfully updated Google API token');
} elseif (isset($data->error_description)) { } elseif (isset($data->error_description)) {
$this->maniaControl->getChat()->sendErrorToAdmins('Google refused the request: ' . $data->error_description); $this->maniaControl->getChat()->sendErrorToAdmins($this->MatchManagerCore->getChatPrefix() .'Google refused the request: ' . $data->error_description);
} else { } else {
$this->maniaControl->getChat()->sendErrorToAdmins('Unkown error'); $this->maniaControl->getChat()->sendErrorToAdmins($this->MatchManagerCore->getChatPrefix() .'Unkown error');
} }
} }
return true; return true;
@ -530,7 +553,7 @@ class MatchManagerGSheet implements CallbackListener, TimerListener, CommandLis
private function CheckSpeadsheetAccess(Player $player) { private function CheckSpeadsheetAccess(Player $player) {
$spreadsheetid = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MATCHMANAGERGSHEET_SPREADSHEET); $spreadsheetid = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MATCHMANAGERGSHEET_SPREADSHEET);
if ($spreadsheetid === "") { if ($spreadsheetid === "") {
$this->maniaControl->getChat()->sendError('Empty Spreadsheet Id', $player); $this->maniaControl->getChat()->sendError($this->MatchManagerCore->getChatPrefix() .'Empty Spreadsheet Id', $player);
return; return;
} }
@ -540,32 +563,32 @@ class MatchManagerGSheet implements CallbackListener, TimerListener, CommandLis
$asyncHttpRequest->setHeaders(array("Authorization: Bearer " . $this->access_token)); $asyncHttpRequest->setHeaders(array("Authorization: Bearer " . $this->access_token));
$asyncHttpRequest->setCallable(function ($json, $error) use ($player) { $asyncHttpRequest->setCallable(function ($json, $error) use ($player) {
if (!$json || $error) { if (!$json || $error) {
Logger::logError('Error: ' . $error); $this->logError('Error: ' . $error);
$this->maniaControl->getChat()->sendError('Error: ' . $error, $player); $this->maniaControl->getChat()->sendError($this->MatchManagerCore->getChatPrefix() .'Error: ' . $error, $player);
return; return;
} }
$data = json_decode($json); $data = json_decode($json);
if (!$data) { if (!$data) {
Logger::logError('Json parse error: ' . $json); $this->logError('Json parse error: ' . $json);
$this->maniaControl->getChat()->sendError('Json parse error: ' . $json, $player); $this->maniaControl->getChat()->sendError($this->MatchManagerCore->getChatPrefix() .'Json parse error: ' . $json, $player);
return; return;
} }
if (property_exists($data, "error")) { if (property_exists($data, "error")) {
Logger::logError('Request error: ' . $data->error->code . " ". $data->error->message); $this->logError('Request error: ' . $data->error->code . " ". $data->error->message);
$this->maniaControl->getChat()->sendErrorToAdmins('Request error: ' . $data->error->code . " ". $data->error->message); $this->maniaControl->getChat()->sendErrorToAdmins($this->MatchManagerCore->getChatPrefix() .'Request error: ' . $data->error->code . " ". $data->error->message);
return; return;
} }
if (isset($data->properties->title)) { if (isset($data->properties->title)) {
$this->maniaControl->getChat()->sendSuccess('Speadsheet name: ' . $data->properties->title, $player); $this->maniaControl->getChat()->sendSuccess($this->MatchManagerCore->getChatPrefix() .'Speadsheet name: ' . $data->properties->title, $player);
} else { } else {
$this->maniaControl->getChat()->sendError("Can't access to the Spreadsheet: " . $data->error->message, $player); $this->maniaControl->getChat()->sendError($this->MatchManagerCore->getChatPrefix() ."Can't access to the Spreadsheet: " . $data->error->message, $player);
} }
}); });
$asyncHttpRequest->getData(1000); $asyncHttpRequest->getData(1000);
} else { } else {
$this->maniaControl->getChat()->sendError("Can't have access to Google API service", $player); $this->maniaControl->getChat()->sendError($this->MatchManagerCore->getChatPrefix() ."Can't have access to Google API service", $player);
} }
} }
@ -632,23 +655,24 @@ class MatchManagerGSheet implements CallbackListener, TimerListener, CommandLis
$asyncHttpRequest->setContent(json_encode($data)); $asyncHttpRequest->setContent(json_encode($data));
$asyncHttpRequest->setCallable(function ($json, $error) use ($sheetname, $spreadsheetid, $currentscore, $currentteamsscore, $matchstatus, $nbmaps, $nbrounds) { $asyncHttpRequest->setCallable(function ($json, $error) use ($sheetname, $spreadsheetid, $currentscore, $currentteamsscore, $matchstatus, $nbmaps, $nbrounds) {
if (!$json || $error) { if (!$json || $error) {
Logger::logError('Error from Google API: ' . $error); $this->logError('Error from Google API: ' . $error);
$this->maniaControl->getChat()->sendErrorToAdmins('Error from Google API: ' . $error); $this->maniaControl->getChat()->sendErrorToAdmins($this->MatchManagerCore->getChatPrefix() .'Error from Google API: ' . $error);
return; return;
} }
$data = json_decode($json); $data = json_decode($json);
if (!$data) { if (!$data) {
Logger::logError('Json parse error: ' . $json); $this->logError('Json parse error: ' . $json);
$this->maniaControl->getChat()->sendErrorToAdmins('Json parse error: ' . $json); $this->maniaControl->getChat()->sendErrorToAdmins($this->MatchManagerCore->getChatPrefix() .'Json parse error: ' . $json);
return; return;
} }
if (property_exists($data, "error")) { if (property_exists($data, "error")) {
Logger::logError('Request error: ' . $data->error->code . " ". $data->error->message); $this->logError('Request error: ' . $data->error->code . " ". $data->error->message);
$this->maniaControl->getChat()->sendErrorToAdmins('Request error: ' . $data->error->code . " ". $data->error->message); $this->maniaControl->getChat()->sendErrorToAdmins($this->MatchManagerCore->getChatPrefix() .'Request error: ' . $data->error->code . " ". $data->error->message);
return; return;
} }
if ($this->currentdatamode == "All Rounds Data" && $matchstatus == "running") { if ($this->currentdatamode == "All Rounds Data" && $matchstatus == "running") {
$this->log('Successfully sent Info data');
$newcurrentscore = []; $newcurrentscore = [];
foreach ($currentscore as $score) { foreach ($currentscore as $score) {
array_push($newcurrentscore, array_merge([$nbmaps, $nbrounds], $score)); array_push($newcurrentscore, array_merge([$nbmaps, $nbrounds], $score));
@ -665,26 +689,28 @@ class MatchManagerGSheet implements CallbackListener, TimerListener, CommandLis
$asyncHttpRequest->setContent(json_encode($data)); $asyncHttpRequest->setContent(json_encode($data));
$asyncHttpRequest->setCallable(function ($json, $error) use ($sheetname, $spreadsheetid, $currentteamsscore, $nbmaps, $nbrounds) { $asyncHttpRequest->setCallable(function ($json, $error) use ($sheetname, $spreadsheetid, $currentteamsscore, $nbmaps, $nbrounds) {
if (!$json || $error) { if (!$json || $error) {
Logger::logError('Error from Google API: ' . $error); $this->logError('Error from Google API: ' . $error);
$this->maniaControl->getChat()->sendErrorToAdmins('Error from Google API: ' . $error); $this->maniaControl->getChat()->sendErrorToAdmins($this->MatchManagerCore->getChatPrefix() .'Error from Google API: ' . $error);
return; return;
} }
$data = json_decode($json); $data = json_decode($json);
if (!$data) { if (!$data) {
Logger::logError('Json parse error: ' . $json); $this->logError('Json parse error: ' . $json);
$this->maniaControl->getChat()->sendErrorToAdmins('Json parse error: ' . $json); $this->maniaControl->getChat()->sendErrorToAdmins($this->MatchManagerCore->getChatPrefix() .'Json parse error: ' . $json);
return; return;
} }
if (property_exists($data, "error")) { if (property_exists($data, "error")) {
Logger::logError('Request error: ' . $data->error->code . " ". $data->error->message); $this->logError('Request error: ' . $data->error->code . " ". $data->error->message);
$this->maniaControl->getChat()->sendErrorToAdmins('Request error: ' . $data->error->code . " ". $data->error->message); $this->maniaControl->getChat()->sendErrorToAdmins($this->MatchManagerCore->getChatPrefix() .'Request error: ' . $data->error->code . " ". $data->error->message);
return; return;
} }
$this->log('Successfully appending Player Scores data');
if (!empty($currentteamsscore)) { if (!empty($currentteamsscore)) {
$newcurrentteamsscore = []; $newcurrentteamsscore = [];
foreach ($currentteamsscore as $score) { foreach ($currentteamsscore as $score) {
array_push($newcurrentteamsscore,array_merge([$nbmaps, $nbrounds], $score)); array_push($newcurrentteamsscore, array_merge([$nbmaps, $nbrounds], $score));
} }
$data = new \stdClass; $data = new \stdClass;
@ -698,41 +724,45 @@ class MatchManagerGSheet implements CallbackListener, TimerListener, CommandLis
$asyncHttpRequest->setContent(json_encode($data)); $asyncHttpRequest->setContent(json_encode($data));
$asyncHttpRequest->setCallable(function ($json, $error) { $asyncHttpRequest->setCallable(function ($json, $error) {
if (!$json || $error) { if (!$json || $error) {
Logger::logError('Error from Google API: ' . $error); $this->logError('Error from Google API: ' . $error);
$this->maniaControl->getChat()->sendErrorToAdmins('Error from Google API: ' . $error); $this->maniaControl->getChat()->sendErrorToAdmins($this->MatchManagerCore->getChatPrefix() .'Error from Google API: ' . $error);
return; return;
} }
$data = json_decode($json); $data = json_decode($json);
if (!$data) { if (!$data) {
Logger::logError('Json parse error: ' . $json); $this->logError('Json parse error: ' . $json);
$this->maniaControl->getChat()->sendErrorToAdmins('Json parse error: ' . $json); $this->maniaControl->getChat()->sendErrorToAdmins($this->MatchManagerCore->getChatPrefix() .'Json parse error: ' . $json);
return; return;
} }
if (property_exists($data, "error")) { if (property_exists($data, "error")) {
Logger::logError('Request error: ' . $data->error->code . " ". $data->error->message); $this->logError('Request error: ' . $data->error->code . " ". $data->error->message);
$this->maniaControl->getChat()->sendErrorToAdmins('Request error: ' . $data->error->code . " ". $data->error->message); $this->maniaControl->getChat()->sendErrorToAdmins($this->MatchManagerCore->getChatPrefix() .'Request error: ' . $data->error->code . " ". $data->error->message);
return; return;
} }
$this->log('Successfully appending Team Scores data');
}); });
$asyncHttpRequest->postData(1000); $asyncHttpRequest->postData(1000);
} }
}); });
$asyncHttpRequest->postData(1000); $asyncHttpRequest->postData(1000);
} else {
$this->log('Successfully sent Info and Scores data');
} }
}); });
$asyncHttpRequest->postData(1000); $asyncHttpRequest->postData(1000);
} else { } else {
$this->maniaControl->getChat()->sendErrorToAdmins('Impossible to update the Google Sheet'); $this->maniaControl->getChat()->sendErrorToAdmins($this->MatchManagerCore->getChatPrefix() .'Impossible to update the Google Sheet');
} }
} }
function onCallbackEndRound(String $matchid, Array $currentscore, Array $currentteamsscore) { function onCallbackEndRound(String $matchid, Array $currentscore, Array $currentteamsscore) {
Logger::Log('onCallbackEndRound'); $this->log('onCallbackEndRound');
$this->matchstatus = "running"; $this->matchstatus = "running";
$this->UpdateGSheetData($matchid, $currentscore, $currentteamsscore); $this->UpdateGSheetData($matchid, $currentscore, $currentteamsscore);
} }
function onCallbackEndMatch(String $matchid, Array $currentscore, Array $currentteamsscore) { function onCallbackEndMatch(String $matchid, Array $currentscore, Array $currentteamsscore) {
Logger::Log('onCallbackEndMatch'); $this->log('onCallbackEndMatch');
$this->matchstatus = "ended"; $this->matchstatus = "ended";
$this->maniaControl->getTimerManager()->registerOneTimeListening($this, function () use ($matchid, $currentscore, $currentteamsscore) { $this->maniaControl->getTimerManager()->registerOneTimeListening($this, function () use ($matchid, $currentscore, $currentteamsscore) {
@ -740,7 +770,7 @@ class MatchManagerGSheet implements CallbackListener, TimerListener, CommandLis
}, 1000); // Wait a sec before sending last data to avoid collision }, 1000); // Wait a sec before sending last data to avoid collision
} }
function onCallbackStopMatch(String $matchid, Array $currentscore, Array $currentteamsscore) { function onCallbackStopMatch(String $matchid, Array $currentscore, Array $currentteamsscore) {
Logger::Log('onCallbackStopMatch'); $this->log('onCallbackStopMatch');
$this->matchstatus = "stopped"; $this->matchstatus = "stopped";
$this->UpdateGSheetData($matchid, $currentscore, $currentteamsscore); $this->UpdateGSheetData($matchid, $currentscore, $currentteamsscore);
} }
@ -759,19 +789,19 @@ class MatchManagerGSheet implements CallbackListener, TimerListener, CommandLis
$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) {
if (!$json || $error) { if (!$json || $error) {
Logger::logError('Error from Google API: ' . $error); $this->logError('Error from Google API: ' . $error);
$this->maniaControl->getChat()->sendErrorToAdmins('Error from Google API: ' . $error); $this->maniaControl->getChat()->sendErrorToAdmins($this->MatchManagerCore->getChatPrefix() .'Error from Google API: ' . $error);
return; return;
} }
$data = json_decode($json); $data = json_decode($json);
if (!$data) { if (!$data) {
Logger::logError('Json parse error: ' . $json); $this->logError('Json parse error: ' . $json);
$this->maniaControl->getChat()->sendErrorToAdmins('Json parse error: ' . $json); $this->maniaControl->getChat()->sendErrorToAdmins($this->MatchManagerCore->getChatPrefix() .'Json parse error: ' . $json);
return; return;
} }
if (property_exists($data, "error")) { if (property_exists($data, "error")) {
Logger::logError('Request error: ' . $data->error->code . " ". $data->error->message); $this->logError('Request error: ' . $data->error->code . " ". $data->error->message);
$this->maniaControl->getChat()->sendErrorToAdmins('Request error: ' . $data->error->code . " ". $data->error->message); $this->maniaControl->getChat()->sendErrorToAdmins($this->MatchManagerCore->getChatPrefix() .'Request error: ' . $data->error->code . " ". $data->error->message);
return; return;
} }
@ -812,7 +842,7 @@ class MatchManagerGSheet implements CallbackListener, TimerListener, CommandLis
$i = 0; $i = 0;
if (!$sheetexists) { if (!$sheetexists) {
Logger::Log("Creating new Sheet: " . $sheetname); $this->log("Creating new Sheet: " . $sheetname);
$sheetid = rand(1000,2147483646); $sheetid = rand(1000,2147483646);
while (in_array($sheetid, $sheetsid)) { while (in_array($sheetid, $sheetsid)) {
$sheetid = rand(1000,2147483646); $sheetid = rand(1000,2147483646);
@ -907,43 +937,47 @@ class MatchManagerGSheet implements CallbackListener, TimerListener, CommandLis
$asyncHttpRequest->setContent(json_encode($data)); $asyncHttpRequest->setContent(json_encode($data));
$asyncHttpRequest->setCallable(function ($json, $error) use ($sheetname, $spreadsheetid) { $asyncHttpRequest->setCallable(function ($json, $error) use ($sheetname, $spreadsheetid) {
if (!$json || $error) { if (!$json || $error) {
Logger::logError('Error from Google API: ' . $error); $this->logError('Error from Google API: ' . $error);
$this->maniaControl->getChat()->sendErrorToAdmins('Error from Google API: ' . $error); $this->maniaControl->getChat()->sendErrorToAdmins($this->MatchManagerCore->getChatPrefix() .'Error from Google API: ' . $error);
return; return;
} }
$data = json_decode($json); $data = json_decode($json);
if (!$data) { if (!$data) {
Logger::logError('Json parse error: ' . $json); $this->logError('Json parse error: ' . $json);
$this->maniaControl->getChat()->sendErrorToAdmins('Json parse error: ' . $json); $this->maniaControl->getChat()->sendErrorToAdmins($this->MatchManagerCore->getChatPrefix() .'Json parse error: ' . $json);
return; return;
} }
if (property_exists($data, "error")) { if (property_exists($data, "error")) {
Logger::logError('Request error: ' . $data->error->code . " ". $data->error->message); $this->logError('Request error: ' . $data->error->code . " ". $data->error->message);
$this->maniaControl->getChat()->sendErrorToAdmins('Request error: ' . $data->error->code . " ". $data->error->message); $this->maniaControl->getChat()->sendErrorToAdmins($this->MatchManagerCore->getChatPrefix() .'Request error: ' . $data->error->code . " ". $data->error->message);
return; return;
} }
$this->log('Successfully created sheet with formatting');
// Clear Scoreboards data // Clear Scoreboards data
$asyncHttpRequest = new AsyncHttpRequest($this->maniaControl, 'https://sheets.googleapis.com/v4/spreadsheets/' . $spreadsheetid . '/values/' . urlencode("'". $sheetname . "'") . '!A1:Z300:clear'); $asyncHttpRequest = new AsyncHttpRequest($this->maniaControl, 'https://sheets.googleapis.com/v4/spreadsheets/' . $spreadsheetid . '/values/' . urlencode("'". $sheetname . "'") . '!A1:Z300:clear');
$asyncHttpRequest->setHeaders(array("Authorization: Bearer " . $this->access_token)); $asyncHttpRequest->setHeaders(array("Authorization: Bearer " . $this->access_token));
$asyncHttpRequest->setCallable(function ($json, $error) use ($sheetname, $spreadsheetid) { $asyncHttpRequest->setCallable(function ($json, $error) use ($sheetname, $spreadsheetid) {
if (!$json || $error) { if (!$json || $error) {
Logger::logError('Error from Google API: ' . $error); $this->logError('Error from Google API: ' . $error);
$this->maniaControl->getChat()->sendErrorToAdmins('Error from Google API: ' . $error); $this->maniaControl->getChat()->sendErrorToAdmins($this->MatchManagerCore->getChatPrefix() .'Error from Google API: ' . $error);
return; return;
} }
$data = json_decode($json); $data = json_decode($json);
if (!$data) { if (!$data) {
Logger::logError('Json parse error: ' . $json); $this->logError('Json parse error: ' . $json);
$this->maniaControl->getChat()->sendErrorToAdmins('Json parse error: ' . $json); $this->maniaControl->getChat()->sendErrorToAdmins($this->MatchManagerCore->getChatPrefix() .'Json parse error: ' . $json);
return; return;
} }
if (property_exists($data, "error")) { if (property_exists($data, "error")) {
Logger::logError('Request error: ' . $data->error->code . " ". $data->error->message); $this->logError('Request error: ' . $data->error->code . " ". $data->error->message);
$this->maniaControl->getChat()->sendErrorToAdmins('Request error: ' . $data->error->code . " ". $data->error->message); $this->maniaControl->getChat()->sendErrorToAdmins($this->MatchManagerCore->getChatPrefix() .'Request error: ' . $data->error->code . " ". $data->error->message);
return; return;
} }
$this->log('Successfully cleared all the data');
// Add headers data // Add headers data
$data = new \stdClass; $data = new \stdClass;
$data->valueInputOption = "RAW"; $data->valueInputOption = "RAW";
@ -966,21 +1000,23 @@ class MatchManagerGSheet implements CallbackListener, TimerListener, CommandLis
$asyncHttpRequest->setContent(json_encode($data)); $asyncHttpRequest->setContent(json_encode($data));
$asyncHttpRequest->setCallable(function ($json, $error) { $asyncHttpRequest->setCallable(function ($json, $error) {
if (!$json || $error) { if (!$json || $error) {
Logger::logError('Error from Google API: ' . $error); $this->logError('Error from Google API: ' . $error);
$this->maniaControl->getChat()->sendErrorToAdmins('Error from Google API: ' . $error); $this->maniaControl->getChat()->sendErrorToAdmins($this->MatchManagerCore->getChatPrefix() .'Error from Google API: ' . $error);
return; return;
} }
$data = json_decode($json); $data = json_decode($json);
if (!$data) { if (!$data) {
Logger::logError('Json parse error: ' . $json); $this->logError('Json parse error: ' . $json);
$this->maniaControl->getChat()->sendErrorToAdmins('Json parse error: ' . $json); $this->maniaControl->getChat()->sendErrorToAdmins($this->MatchManagerCore->getChatPrefix() .'Json parse error: ' . $json);
return; return;
} }
if (property_exists($data, "error")) { if (property_exists($data, "error")) {
Logger::logError('Request error: ' . $data->error->code . " ". $data->error->message); $this->logError('Request error: ' . $data->error->code . " ". $data->error->message);
$this->maniaControl->getChat()->sendErrorToAdmins('Request error: ' . $data->error->code . " ". $data->error->message); $this->maniaControl->getChat()->sendErrorToAdmins('$this->MatchManagerCore->getChatPrefix() .Request error: ' . $data->error->code . " ". $data->error->message);
return; return;
} }
$this->log('Successfully added headers data');
}); });
$asyncHttpRequest->postData(1000); $asyncHttpRequest->postData(1000);
}); });

View File

@ -27,8 +27,8 @@ use ManiaControl\Commands\CommandListener;
use ManiaControl\Plugins\PluginMenu; use ManiaControl\Plugins\PluginMenu;
if (!class_exists('MatchManagerSuite\MatchManagerCore')) { if (!class_exists('MatchManagerSuite\MatchManagerCore')) {
$this->maniaControl->getChat()->sendErrorToAdmins('MatchManager Core is required to use one of MatchManager plugin. Install it and restart Maniacontrol'); $this->maniaControl->getChat()->sendErrorToAdmins('MatchManager Core is required to use MatchManagerMultipleConfigManager plugin. Install it and restart Maniacontrol');
Logger::logError('MatchManager Core is required to use one of MatchManager plugin. Install it and restart Maniacontrol'); Logger::logError('MatchManager Core is required to use MatchManagerMultipleConfigManager plugin. Install it and restart Maniacontrol');
return false; return false;
} }
use MatchManagerSuite\MatchManagerCore; use MatchManagerSuite\MatchManagerCore;
@ -44,10 +44,13 @@ class MatchManagerMultipleConfigManager implements ManialinkPageAnswerListener,
* Constants * Constants
*/ */
const PLUGIN_ID = 171; const PLUGIN_ID = 171;
const PLUGIN_VERSION = 1.6; const PLUGIN_VERSION = 1.7;
const PLUGIN_NAME = 'MatchManager Multiple Config Manager'; const PLUGIN_NAME = 'MatchManager Multiple Config Manager';
const PLUGIN_AUTHOR = 'Beu'; const PLUGIN_AUTHOR = 'Beu';
const LOG_PREFIX = '[MatchManagerMultipleConfigManager] ';
// MatchManagerWidget Properties // MatchManagerWidget Properties
const MATCHMANAGERCORE_PLUGIN = 'MatchManagerSuite\MatchManagerCore'; const MATCHMANAGERCORE_PLUGIN = 'MatchManagerSuite\MatchManagerCore';
const MATCHMANAGERADMINUI_PLUGIN = 'MatchManagerSuite\MatchManagerAdminUI'; const MATCHMANAGERADMINUI_PLUGIN = 'MatchManagerSuite\MatchManagerAdminUI';
@ -71,6 +74,7 @@ class MatchManagerMultipleConfigManager implements ManialinkPageAnswerListener,
*/ */
/** @var ManiaControl $maniaControl */ /** @var ManiaControl $maniaControl */
private $maniaControl = null; private $maniaControl = null;
/** @var MatchManagerCore $MatchManagerCore */
private $MatchManagerCore = null; private $MatchManagerCore = null;
/** /**
@ -152,6 +156,24 @@ class MatchManagerMultipleConfigManager implements ManialinkPageAnswerListener,
} }
} }
/**
* Custom log function to add prefix
*
* @param mixed $message
*/
private function log(mixed $message) {
Logger::log(self::LOG_PREFIX . $message);
}
/**
* Custom logError function to add prefix
*
* @param mixed $message
*/
private function logError(mixed $message) {
Logger::logError(self::LOG_PREFIX . $message);
}
/** /**
* handle Plugin Loaded * handle Plugin Loaded
* *
@ -182,7 +204,8 @@ class MatchManagerMultipleConfigManager implements ManialinkPageAnswerListener,
public function handlePluginUnloaded(string $pluginClass, Plugin $plugin) { public function handlePluginUnloaded(string $pluginClass, Plugin $plugin) {
if ($pluginClass == self::MATCHMANAGERCORE_PLUGIN) { if ($pluginClass == self::MATCHMANAGERCORE_PLUGIN) {
$this->maniaControl->getChat()->sendErrorToAdmins(self::PLUGIN_NAME . " disabled because MatchManager Core is now disabled"); $this->maniaControl->getChat()->sendErrorToAdmins(self::PLUGIN_NAME . " disabled because MatchManager Core is now disabled");
$this->maniaControl->getPluginManager()->deactivatePlugin((get_class())); $this->log(self::PLUGIN_NAME . " disabled because MatchManager Core is now disabled");
$this->maniaControl->getPluginManager()->deactivatePlugin((get_class($this)));
} }
} }
@ -248,7 +271,7 @@ class MatchManagerMultipleConfigManager implements ManialinkPageAnswerListener,
break; break;
case self::ML_ACTION_REMOVE_CONFIG: case self::ML_ACTION_REMOVE_CONFIG:
$id = intval($actionArray[2]); $id = intval($actionArray[2]);
Logger::log("[MatchManagerMultipleConfigManager] Removing config: " . $id); $this->log("Removing config: " . $id);
$mysqli = $this->maniaControl->getDatabase()->getMysqli(); $mysqli = $this->maniaControl->getDatabase()->getMysqli();
$query = $mysqli->prepare('DELETE FROM `'. self::DB_MATCHCONFIG .'` WHERE id = ?;'); $query = $mysqli->prepare('DELETE FROM `'. self::DB_MATCHCONFIG .'` WHERE id = ?;');
@ -288,8 +311,8 @@ class MatchManagerMultipleConfigManager implements ManialinkPageAnswerListener,
*/ */
public function loadConfig(int $id) { public function loadConfig(int $id) {
if ($this->MatchManagerCore->getMatchStatus()) { if ($this->MatchManagerCore->getMatchStatus()) {
Logger::logError("Impossible to load config during a match"); $this->logError("Impossible to load config during a match");
$this->maniaControl->getChat()->sendErrorToAdmins('Impossible to load config during a match'); $this->maniaControl->getChat()->sendErrorToAdmins($this->MatchManagerCore->getChatPrefix() .'Impossible to load config during a match');
return; return;
} }
$mysqli = $this->maniaControl->getDatabase()->getMysqli(); $mysqli = $this->maniaControl->getDatabase()->getMysqli();
@ -310,7 +333,7 @@ class MatchManagerMultipleConfigManager implements ManialinkPageAnswerListener,
if ($result[0] && $result[0]["config"]) { if ($result[0] && $result[0]["config"]) {
$allconfigs = json_decode($result[0]["config"],true); $allconfigs = json_decode($result[0]["config"],true);
if ($allconfigs != null) { if ($allconfigs != null) {
Logger::log("[MatchManagerMultipleConfigManager] Loading config: " . $id); $this->log("Loading config: " . $id);
$someconfignotloaded = false; $someconfignotloaded = false;
foreach ($allconfigs as $plugin => $configs) { foreach ($allconfigs as $plugin => $configs) {
$pluginclass = $this->maniaControl->getPluginManager()->getPlugin($plugin); $pluginclass = $this->maniaControl->getPluginManager()->getPlugin($plugin);
@ -321,22 +344,22 @@ class MatchManagerMultipleConfigManager implements ManialinkPageAnswerListener,
$setting = $this->maniaControl->getSettingManager()->getSettingObject($pluginclass, $name); $setting = $this->maniaControl->getSettingManager()->getSettingObject($pluginclass, $name);
if ($setting != null) { if ($setting != null) {
if ($setting->value != $value) { if ($setting->value != $value) {
Logger::log("Saving new setting " . $name); $this->log("Saving new setting " . $name);
$setting->value = $value; $setting->value = $value;
$this->maniaControl->getSettingManager()->saveSetting($setting); $this->maniaControl->getSettingManager()->saveSetting($setting);
} }
} else { } else {
$someconfignotloaded = true; $someconfignotloaded = true;
Logger::log("Unable to load setting: " . $name); $this->log("Unable to load setting: " . $name);
} }
} }
} }
} }
if ($someconfignotloaded) { if ($someconfignotloaded) {
$this->maniaControl->getChat()->sendErrorToAdmins('One or more settings could not be imported'); $this->maniaControl->getChat()->sendErrorToAdmins($this->MatchManagerCore->getChatPrefix() .'One or more settings could not be imported');
} }
$this->maniaControl->getSettingManager()->clearStorage(); $this->maniaControl->getSettingManager()->clearStorage();
$this->maniaControl->getChat()->sendSuccessToAdmins('MatchManager Config "' . $result[0]["name"] . '" loaded'); $this->maniaControl->getChat()->sendSuccessToAdmins($this->MatchManagerCore->getChatPrefix() .'MatchManager Config "' . $result[0]["name"] . '" loaded');
} }
} }
@ -350,7 +373,7 @@ class MatchManagerMultipleConfigManager implements ManialinkPageAnswerListener,
* @return void * @return void
*/ */
public function saveCurrentConfig(array $fields) { public function saveCurrentConfig(array $fields) {
Logger::log("[MatchManagerMultipleConfigManager] Saving current config"); $this->log("Saving current config");
$result = array(); $result = array();
$configname = ""; $configname = "";
$gamemodebase = ""; $gamemodebase = "";

View File

@ -21,8 +21,8 @@ use ManiaControl\Commands\CommandListener;
if (!class_exists('MatchManagerSuite\MatchManagerCore')) { if (!class_exists('MatchManagerSuite\MatchManagerCore')) {
$this->maniaControl->getChat()->sendErrorToAdmins('MatchManager Core is required to use one of MatchManager plugin. Install it and restart Maniacontrol'); $this->maniaControl->getChat()->sendErrorToAdmins('MatchManager Core is required to use MatchManagerPlayersPause plugin. Install it and restart Maniacontrol');
Logger::logError('MatchManager Core is required to use one of MatchManager plugin. Install it and restart Maniacontrol'); Logger::logError('MatchManager Core is required to use MatchManagerPlayersPause plugin. Install it and restart Maniacontrol');
return false; return false;
} }
@ -38,10 +38,12 @@ class MatchManagerPlayersPause implements ManialinkPageAnswerListener, CommandLi
* Constants * Constants
*/ */
const PLUGIN_ID = 159; const PLUGIN_ID = 159;
const PLUGIN_VERSION = 1.5; const PLUGIN_VERSION = 1.6;
const PLUGIN_NAME = 'MatchManager Players Pause'; const PLUGIN_NAME = 'MatchManager Players Pause';
const PLUGIN_AUTHOR = 'Beu'; const PLUGIN_AUTHOR = 'Beu';
const LOG_PREFIX = '[MatchManagerPlayersPause] ';
// MatchManagerWidget Properties // MatchManagerWidget Properties
const MATCHMANAGERCORE_PLUGIN = 'MatchManagerSuite\MatchManagerCore'; const MATCHMANAGERCORE_PLUGIN = 'MatchManagerSuite\MatchManagerCore';
@ -58,6 +60,7 @@ class MatchManagerPlayersPause implements ManialinkPageAnswerListener, CommandLi
*/ */
/** @var ManiaControl $maniaControl */ /** @var ManiaControl $maniaControl */
private $maniaControl = null; private $maniaControl = null;
/** @var MatchManagerCore $MatchManagerCore */
private $MatchManagerCore = null; private $MatchManagerCore = null;
private $playerspausestate = array(); private $playerspausestate = array();
@ -160,6 +163,24 @@ class MatchManagerPlayersPause implements ManialinkPageAnswerListener, CommandLi
$this->closePauseWidget(); $this->closePauseWidget();
} }
/**
* Custom log function to add prefix
*
* @param mixed $message
*/
private function log(mixed $message) {
Logger::log(self::LOG_PREFIX . $message);
}
/**
* Custom logError function to add prefix
*
* @param mixed $message
*/
private function logError(mixed $message) {
Logger::logError(self::LOG_PREFIX . $message);
}
/** /**
* handlePluginUnloaded * handlePluginUnloaded
* *
@ -170,7 +191,8 @@ class MatchManagerPlayersPause implements ManialinkPageAnswerListener, CommandLi
public function handlePluginUnloaded(string $pluginClass, Plugin $plugin) { public function handlePluginUnloaded(string $pluginClass, Plugin $plugin) {
if ($pluginClass == self::MATCHMANAGERCORE_PLUGIN) { if ($pluginClass == self::MATCHMANAGERCORE_PLUGIN) {
$this->maniaControl->getChat()->sendErrorToAdmins(self::PLUGIN_NAME . " disabled because MatchManager Core is now disabled"); $this->maniaControl->getChat()->sendErrorToAdmins(self::PLUGIN_NAME . " disabled because MatchManager Core is now disabled");
$this->maniaControl->getPluginManager()->deactivatePlugin((get_class())); $this->log(self::PLUGIN_NAME . " disabled because MatchManager Core is now disabled");
$this->maniaControl->getPluginManager()->deactivatePlugin((get_class($this)));
} }
} }
@ -211,7 +233,7 @@ class MatchManagerPlayersPause implements ManialinkPageAnswerListener, CommandLi
if ($nbpause >= $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MATCH_PAUSE_NBPLAYERS)) { if ($nbpause >= $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MATCH_PAUSE_NBPLAYERS)) {
$this->playerspausestate = array(); $this->playerspausestate = array();
$this->closePauseWidget(); $this->closePauseWidget();
Logger::log('Pause requested by players'); $this->log('Pause requested by players');
if (!$this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MATCH_PAUSE_WAIT_END_ROUND)) { if (!$this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MATCH_PAUSE_WAIT_END_ROUND)) {
if ($this->maniaControl->getSettingManager()->getSettingValue($this->maniaControl, MatchManagerCore::SETTING_MATCH_PAUSE_DURATION) <= 0) { if ($this->maniaControl->getSettingManager()->getSettingValue($this->maniaControl, MatchManagerCore::SETTING_MATCH_PAUSE_DURATION) <= 0) {
$this->maniaControl->getChat()->sendInformation($this->MatchManagerCore->getChatPrefix() . 'Ask the admins to resume the match'); $this->maniaControl->getChat()->sendInformation($this->MatchManagerCore->getChatPrefix() . 'Ask the admins to resume the match');

View File

@ -20,8 +20,8 @@ use ManiaControl\Commands\CommandListener;
use Maniaplanet\DedicatedServer\InvalidArgumentException; use Maniaplanet\DedicatedServer\InvalidArgumentException;
if (!class_exists('MatchManagerSuite\MatchManagerCore')) { if (!class_exists('MatchManagerSuite\MatchManagerCore')) {
$this->maniaControl->getChat()->sendErrorToAdmins('MatchManager Core is required to use one of MatchManager plugin. Install it and restart Maniacontrol'); $this->maniaControl->getChat()->sendErrorToAdmins('MatchManager Core is required to use MatchManagerReadyButton plugin. Install it and restart Maniacontrol');
Logger::logError('MatchManager Core is required to use one of MatchManager plugin. Install it and restart Maniacontrol'); Logger::logError('MatchManager Core is required to use MatchManagerReadyButton plugin. Install it and restart Maniacontrol');
return false; return false;
} }
@ -37,10 +37,12 @@ class MatchManagerReadyButton implements ManialinkPageAnswerListener, CommandLis
* Constants * Constants
*/ */
const PLUGIN_ID = 158; const PLUGIN_ID = 158;
const PLUGIN_VERSION = 1.5; const PLUGIN_VERSION = 1.6;
const PLUGIN_NAME = 'MatchManager Ready Button'; const PLUGIN_NAME = 'MatchManager Ready Button';
const PLUGIN_AUTHOR = 'Beu'; const PLUGIN_AUTHOR = 'Beu';
const LOG_PREFIX = '[MatchManagerReadyButton] ';
// MatchManagerWidget Properties // MatchManagerWidget Properties
const MATCHMANAGERCORE_PLUGIN = 'MatchManagerSuite\MatchManagerCore'; const MATCHMANAGERCORE_PLUGIN = 'MatchManagerSuite\MatchManagerCore';
@ -57,6 +59,7 @@ class MatchManagerReadyButton implements ManialinkPageAnswerListener, CommandLis
*/ */
/** @var ManiaControl $maniaControl */ /** @var ManiaControl $maniaControl */
private $maniaControl = null; private $maniaControl = null;
/** @var MatchManagerCore $MatchManagerCore */
private $MatchManagerCore = null; private $MatchManagerCore = null;
private $playersreadystate = array(); private $playersreadystate = array();
@ -154,6 +157,24 @@ class MatchManagerReadyButton implements ManialinkPageAnswerListener, CommandLis
$this->closeReadyWidget(); $this->closeReadyWidget();
} }
/**
* Custom log function to add prefix
*
* @param mixed $message
*/
private function log(mixed $message) {
Logger::log(self::LOG_PREFIX . $message);
}
/**
* Custom logError function to add prefix
*
* @param mixed $message
*/
private function logError(mixed $message) {
Logger::logError(self::LOG_PREFIX . $message);
}
/** /**
* handlePluginUnloaded * handlePluginUnloaded
* *
@ -164,7 +185,7 @@ class MatchManagerReadyButton implements ManialinkPageAnswerListener, CommandLis
public function handlePluginUnloaded(string $pluginClass, Plugin $plugin) { public function handlePluginUnloaded(string $pluginClass, Plugin $plugin) {
if ($pluginClass == self::MATCHMANAGERCORE_PLUGIN) { if ($pluginClass == self::MATCHMANAGERCORE_PLUGIN) {
$this->maniaControl->getChat()->sendErrorToAdmins(self::PLUGIN_NAME . " disabled because MatchManager Core is now disabled"); $this->maniaControl->getChat()->sendErrorToAdmins(self::PLUGIN_NAME . " disabled because MatchManager Core is now disabled");
$this->maniaControl->getPluginManager()->deactivatePlugin((get_class())); $this->maniaControl->getPluginManager()->deactivatePlugin((get_class($this)));
} }
} }
@ -205,7 +226,7 @@ class MatchManagerReadyButton implements ManialinkPageAnswerListener, CommandLis
if ($nbready >= $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MATCH_READY_NBPLAYERS)) { if ($nbready >= $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MATCH_READY_NBPLAYERS)) {
$this->playersreadystate = array(); $this->playersreadystate = array();
$this->closeReadyWidget(); $this->closeReadyWidget();
Logger::log('Start Match via Ready Button'); $this->log('Start Match via Ready Button');
$this->MatchManagerCore->MatchStart(); $this->MatchManagerCore->MatchStart();
return; return;
} }

View File

@ -19,8 +19,8 @@ use ManiaControl\Utils\WebReader;
if (!class_exists('MatchManagerSuite\MatchManagerCore')) { if (!class_exists('MatchManagerSuite\MatchManagerCore')) {
$this->maniaControl->getChat()->sendErrorToAdmins('MatchManager Core is required to use one of MatchManager plugin. Install it and restart Maniacontrol'); $this->maniaControl->getChat()->sendErrorToAdmins('MatchManager Core is required to use MatchManagerTMWTDuoIntegration plugin. Install it and restart Maniacontrol');
Logger::logError('MatchManager Core is required to use one of MatchManager plugin. Install it and restart Maniacontrol'); Logger::logError('MatchManager Core is required to use MatchManagerTMWTDuoIntegration plugin. Install it and restart Maniacontrol');
return false; return false;
} }
use MatchManagerSuite\MatchManagerCore; use MatchManagerSuite\MatchManagerCore;
@ -37,10 +37,12 @@ class MatchManagerTMWTDuoIntegration implements CallbackListener, ManialinkPageA
* Constants * Constants
*/ */
const PLUGIN_ID = 211; const PLUGIN_ID = 211;
const PLUGIN_VERSION = 1.0; const PLUGIN_VERSION = 1.2;
const PLUGIN_NAME = 'MatchManager TMWT Duo Integration'; const PLUGIN_NAME = 'MatchManager TMWT Duo Integration';
const PLUGIN_AUTHOR = 'Beu'; const PLUGIN_AUTHOR = 'Beu';
const LOG_PREFIX = '[MatchManagerTMWTDuoIntegration] ';
// Other MatchManager plugin // Other MatchManager plugin
const MATCHMANAGERCORE_PLUGIN = 'MatchManagerSuite\MatchManagerCore'; const MATCHMANAGERCORE_PLUGIN = 'MatchManagerSuite\MatchManagerCore';
const MATCHMANAGERADMINUI_PLUGIN = 'MatchManagerSuite\MatchManagerAdminUI'; const MATCHMANAGERADMINUI_PLUGIN = 'MatchManagerSuite\MatchManagerAdminUI';
@ -62,6 +64,7 @@ class MatchManagerTMWTDuoIntegration implements CallbackListener, ManialinkPageA
const SETTING_PICKANDBAN_ENABLE = 'Enable Pick & Ban'; const SETTING_PICKANDBAN_ENABLE = 'Enable Pick & Ban';
const SETTING_PICKANDBAN_STEPCONFIG = 'Pick & Ban: Step config'; const SETTING_PICKANDBAN_STEPCONFIG = 'Pick & Ban: Step config';
const SETTING_PICKANDBAN_STEPDURATION = 'Pick & Ban: Step duration'; const SETTING_PICKANDBAN_STEPDURATION = 'Pick & Ban: Step duration';
const SETTING_PICKANDBAN_OVERRIDEMAPORDER = 'Pick & Ban: Override Map Order';
const SETTING_PICKANDBAN_RESULTDURATION = 'Pick & Ban: Result duration'; const SETTING_PICKANDBAN_RESULTDURATION = 'Pick & Ban: Result duration';
const STATE_NOTHING = 0; const STATE_NOTHING = 0;
@ -74,6 +77,7 @@ class MatchManagerTMWTDuoIntegration implements CallbackListener, ManialinkPageA
*/ */
/** @var ManiaControl $maniaControl */ /** @var ManiaControl $maniaControl */
private $maniaControl = null; private $maniaControl = null;
/** @var MatchManagerCore $MatchManagerCore */
private $MatchManagerCore = null; private $MatchManagerCore = null;
private $state = 0; private $state = 0;
@ -139,7 +143,8 @@ class MatchManagerTMWTDuoIntegration implements CallbackListener, ManialinkPageA
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_PICKANDBAN_ENABLE, false, '', 20); $this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_PICKANDBAN_ENABLE, false, '', 20);
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_PICKANDBAN_STEPCONFIG, '', 'Similar syntax as the ofiicial Competition Tool. e.g: b:1,b:0,p:0,p:1,p:1,p:0,b:0,b:1,p:r'); $this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_PICKANDBAN_STEPCONFIG, '', 'Similar syntax as the ofiicial Competition Tool. e.g: b:1,b:0,p:0,p:1,p:1,p:0,b:0,b:1,p:r');
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_PICKANDBAN_STEPDURATION, 60000, 'Each step duration in ms', 110); $this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_PICKANDBAN_STEPDURATION, 60000, 'Each step duration in ms', 110);
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_PICKANDBAN_RESULTDURATION, 10000, 'result duration in ms', 120); $this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_PICKANDBAN_OVERRIDEMAPORDER, '', 'Override map order received by the server. e.g: 1,2,4,3,5', 120);
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_PICKANDBAN_RESULTDURATION, 10000, 'result duration in ms', 130);
// Callbacks // Callbacks
$this->maniaControl->getManialinkManager()->registerManialinkPageAnswerListener(self::ML_ACTION_OPENSETTINGS, $this, 'handleActionOpenSettings'); $this->maniaControl->getManialinkManager()->registerManialinkPageAnswerListener(self::ML_ACTION_OPENSETTINGS, $this, 'handleActionOpenSettings');
@ -157,6 +162,24 @@ class MatchManagerTMWTDuoIntegration implements CallbackListener, ManialinkPageA
$this->updateAdminUIMenuItems(); $this->updateAdminUIMenuItems();
} }
/**
* Custom log function to add prefix
*
* @param mixed $message
*/
private function log(mixed $message) {
Logger::log(self::LOG_PREFIX . $message);
}
/**
* Custom logError function to add prefix
*
* @param mixed $message
*/
private function logError(mixed $message) {
Logger::logError(self::LOG_PREFIX . $message);
}
/** /**
* handle Plugin Loaded * handle Plugin Loaded
* *
@ -221,20 +244,20 @@ class MatchManagerTMWTDuoIntegration implements CallbackListener, ManialinkPageA
*/ */
public function canStartMatch() { public function canStartMatch() {
if ($this->maniaControl->getSettingManager()->getSettingValue($this->MatchManagerCore, 'S_TeamsUrl') === '') { if ($this->maniaControl->getSettingManager()->getSettingValue($this->MatchManagerCore, 'S_TeamsUrl') === '') {
$this->maniaControl->getChat()->sendErrorToAdmins($this->MatchManagerCore->getChatPrefix() . " S_TeamsUrl must be defined"); $this->maniaControl->getChat()->sendErrorToAdmins($this->MatchManagerCore->getChatPrefix() . "S_TeamsUrl must be defined");
return false; return false;
} }
if ( if (
$this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_TEAM1) === '' || $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_TEAM1) === '' ||
$this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_TEAM2) === '' $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_TEAM2) === ''
) { ) {
$this->maniaControl->getChat()->sendErrorToAdmins($this->MatchManagerCore->getChatPrefix() . " Team Id must be defined"); $this->maniaControl->getChat()->sendErrorToAdmins($this->MatchManagerCore->getChatPrefix() . "Team Id must be defined");
return false; return false;
} }
if ($this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_PICKANDBAN_ENABLE)) { if ($this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_PICKANDBAN_ENABLE)) {
if ($this->maniaControl->getSettingManager()->getSettingValue($this->MatchManagerCore, $this->MatchManagerCore::SETTING_MATCH_SETTINGS_MODE) !== "All from the plugin") { if ($this->maniaControl->getSettingManager()->getSettingValue($this->MatchManagerCore, $this->MatchManagerCore::SETTING_MATCH_SETTINGS_MODE) !== "All from the plugin") {
$this->maniaControl->getChat()->sendErrorToAdmins('TMWT Pick and bans are only supported in Match Manager Core "All from the plugin" mode'); $this->maniaControl->getChat()->sendErrorToAdmins($this->MatchManagerCore->getChatPrefix() .'TMWT Pick and bans are only supported in MatchManagerCore "All from the plugin" mode');
return false; return false;
} }
} }
@ -254,8 +277,8 @@ class MatchManagerTMWTDuoIntegration implements CallbackListener, ManialinkPageA
if ($setting !== null && !$setting->value) { if ($setting !== null && !$setting->value) {
$setting->value = true; $setting->value = true;
$this->maniaControl->getSettingManager()->saveSetting($setting); $this->maniaControl->getSettingManager()->saveSetting($setting);
Logger::logWarning('Remplacing S_IsMatchmaking setting value in MatchManagerCore for TMWT integration'); $this->logError('Remplacing S_IsMatchmaking setting value in MatchManagerCore for TMWT integration');
$this->maniaControl->getChat()->sendErrorToAdmins('Remplacing S_IsMatchmaking setting value in MatchManagerCore for TMWT integration'); $this->maniaControl->getChat()->sendErrorToAdmins($this->MatchManagerCore->getChatPrefix() .'Remplacing S_IsMatchmaking setting value in MatchManagerCore for TMWT integration');
} }
if ($this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_PICKANDBAN_ENABLE)) { if ($this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_PICKANDBAN_ENABLE)) {
@ -263,8 +286,8 @@ class MatchManagerTMWTDuoIntegration implements CallbackListener, ManialinkPageA
if ($setting !== null && !$setting->value) { if ($setting !== null && !$setting->value) {
$setting->value = true; $setting->value = true;
$this->maniaControl->getSettingManager()->saveSetting($setting); $this->maniaControl->getSettingManager()->saveSetting($setting);
Logger::logWarning('Remplacing S_PickAndBan_Enable setting value in MatchManagerCore for TMWT integration'); $this->logError('Remplacing S_PickAndBan_Enable setting value in MatchManagerCore for TMWT integration');
$this->maniaControl->getChat()->sendErrorToAdmins('Remplacing S_PickAndBan_Enable setting value in MatchManagerCore for TMWT integration'); $this->maniaControl->getChat()->sendErrorToAdmins($this->MatchManagerCore->getChatPrefix() .'Remplacing S_PickAndBan_Enable setting value in MatchManagerCore for TMWT integration');
} }
} }
} }
@ -317,14 +340,14 @@ class MatchManagerTMWTDuoIntegration implements CallbackListener, ManialinkPageA
if ($team->Id === $team1) { if ($team->Id === $team1) {
$team1 = null; $team1 = null;
foreach ($team->Players as $player) { foreach ($team->Players as $player) {
Logger::log($player->AccountId ." added to team 1"); $this->log($player->AccountId ." added to team 1");
$this->maniaControl->getClient()->triggerModeScriptEvent(self::XMLRPC_METHOD_ADDPLAYER, [$player->AccountId, "1"], true); $this->maniaControl->getClient()->triggerModeScriptEvent(self::XMLRPC_METHOD_ADDPLAYER, [$player->AccountId, "1"], true);
} }
} }
if ($team->Id === $team2) { if ($team->Id === $team2) {
$team2 = null; $team2 = null;
foreach ($team->Players as $player) { foreach ($team->Players as $player) {
Logger::log($player->AccountId ." added to team 2"); $this->log($player->AccountId ." added to team 2");
$this->maniaControl->getClient()->triggerModeScriptEvent(self::XMLRPC_METHOD_ADDPLAYER, [$player->AccountId, "2"], true); $this->maniaControl->getClient()->triggerModeScriptEvent(self::XMLRPC_METHOD_ADDPLAYER, [$player->AccountId, "2"], true);
} }
} }
@ -333,8 +356,8 @@ class MatchManagerTMWTDuoIntegration implements CallbackListener, ManialinkPageA
} }
if ($this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_PICKANDBAN_ENABLE)) { if ($this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_PICKANDBAN_ENABLE)) {
Logger::log('Starting Pick & ban in 10 seconds'); $this->log('Starting Pick & ban in 10 seconds');
$this->maniaControl->getChat()->sendSuccess('Starting pick & ban in 10 seconds'); $this->maniaControl->getChat()->sendSuccess($this->MatchManagerCore->getChatPrefix() .'Starting pick & ban in 10 seconds');
$this->maniaControl->getTimerManager()->registerOneTimeListening($this, function () { $this->maniaControl->getTimerManager()->registerOneTimeListening($this, function () {
$payload = [ $payload = [
'stepDuration' => $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_PICKANDBAN_STEPDURATION), 'stepDuration' => $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_PICKANDBAN_STEPDURATION),
@ -364,12 +387,12 @@ class MatchManagerTMWTDuoIntegration implements CallbackListener, ManialinkPageA
$json = json_encode($payload); $json = json_encode($payload);
Logger::log('Starting Pick & ban: '. $json); $this->log('Starting Pick & ban: '. $json);
$this->maniaControl->getClient()->triggerModeScriptEvent(self::XMLRPC_METHOD_STARTPICKANDBAN, [$json], true); $this->maniaControl->getClient()->triggerModeScriptEvent(self::XMLRPC_METHOD_STARTPICKANDBAN, [$json], true);
}, 5000); }, 5000);
} else { } else {
$this->state = self::STATE_MATCH; $this->state = self::STATE_MATCH;
Logger::log('Sending match start callback'); $this->log('Sending match start callback');
$this->maniaControl->getClient()->triggerModeScriptEvent(self::XMLRPC_METHOD_MATCHSTARTED, [], true); $this->maniaControl->getClient()->triggerModeScriptEvent(self::XMLRPC_METHOD_MATCHSTARTED, [], true);
} }
} }
@ -385,13 +408,30 @@ class MatchManagerTMWTDuoIntegration implements CallbackListener, ManialinkPageA
*/ */
public function handlePickAndBanComplete(array $structure) { public function handlePickAndBanComplete(array $structure) {
if (!$this->MatchManagerCore->getMatchStatus()) return; if (!$this->MatchManagerCore->getMatchStatus()) return;
Logger::log('Received picks: '. $structure[1][0]); $this->log('Received picks: '. $structure[1][0]);
$this->maniaControl->getTimerManager()->registerOneTimeListening($this, function () use ($structure) { $this->maniaControl->getTimerManager()->registerOneTimeListening($this, function () use ($structure) {
try { try {
$json = json_decode($structure[1][0]); $json = json_decode($structure[1][0]);
$mapUids = array_column($json->playlist, 'uid'); $mapUids = array_column($json->playlist, 'uid');
$order = explode(',', $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_PICKANDBAN_OVERRIDEMAPORDER));
if (count($order) === count($mapUids)) {
$this->log("Re-ordering maps");
try {
$orderedMapUid = [];
foreach ($order as $number) {
$orderedMapUid[] = $mapUids[$number - 1];
}
$mapUids = $orderedMapUid;
} catch (\Throwable $th) {
$this->logError("Invalid Map order setting");
$this->maniaControl->getChat()->sendErrorToAdmins($this->MatchManagerCore->getChatPrefix() ."Invalid Map order setting");
}
}
$mapList = []; $mapList = [];
foreach ($this->maniaControl->getMapManager()->getMaps() as $map) { foreach ($this->maniaControl->getMapManager()->getMaps() as $map) {
$index = array_search($map->uid, $mapUids); $index = array_search($map->uid, $mapUids);
@ -404,19 +444,19 @@ class MatchManagerTMWTDuoIntegration implements CallbackListener, ManialinkPageA
} }
if (count($mapUids) !== count($mapList)) { if (count($mapUids) !== count($mapList)) {
Logger::logError("Missing maps: ". implode(' ', array_diff($mapUids, $mapList))); $this->logError("Missing maps: ". implode(' ', array_diff($mapUids, $mapList)));
} }
ksort($mapList); ksort($mapList);
$this->maniaControl->getClient()->chooseNextMapList(array_values($mapList)); $this->maniaControl->getClient()->chooseNextMapList(array_values($mapList));
} catch (\Throwable $th) { } catch (\Throwable $th) {
Logger::logError("Can't apply map list: ". $th->getMessage()); $this->logError("Can't apply map list: ". $th->getMessage());
$this->maniaControl->getChat()->sendError("Can't apply map list: ". $th->getMessage()); $this->maniaControl->getChat()->sendError($this->MatchManagerCore->getChatPrefix() ."Can't apply map list: ". $th->getMessage());
} }
$this->state = self::STATE_MATCH; $this->state = self::STATE_MATCH;
Logger::log('Sending match start callback'); $this->log('Sending match start callback');
$this->maniaControl->getClient()->triggerModeScriptEvent(self::XMLRPC_METHOD_MATCHSTARTED, [], true); $this->maniaControl->getClient()->triggerModeScriptEvent(self::XMLRPC_METHOD_MATCHSTARTED, [], true);
$this->maniaControl->getMapManager()->getMapActions()->skipMap(); $this->maniaControl->getMapManager()->getMapActions()->skipMap();
}, $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_PICKANDBAN_RESULTDURATION)); }, $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_PICKANDBAN_RESULTDURATION));
@ -431,8 +471,8 @@ class MatchManagerTMWTDuoIntegration implements CallbackListener, ManialinkPageA
*/ */
public function handlePluginUnloaded(string $pluginClass, Plugin $plugin) { public function handlePluginUnloaded(string $pluginClass, Plugin $plugin) {
if ($pluginClass == self::MATCHMANAGERCORE_PLUGIN) { if ($pluginClass == self::MATCHMANAGERCORE_PLUGIN) {
$this->maniaControl->getChat()->sendErrorToAdmins(self::PLUGIN_NAME . " disabled because MatchManager Core is now disabled"); $this->maniaControl->getChat()->sendErrorToAdmins($this->MatchManagerCore->getChatPrefix() .self::PLUGIN_NAME . " disabled because MatchManager Core is now disabled");
$this->maniaControl->getPluginManager()->deactivatePlugin((get_class())); $this->maniaControl->getPluginManager()->deactivatePlugin((get_class($this)));
} }
} }
@ -446,7 +486,7 @@ class MatchManagerTMWTDuoIntegration implements CallbackListener, ManialinkPageA
if ($setting->setting === self::SETTING_PICKANDBAN_ENABLE || $setting->setting === $this->MatchManagerCore::SETTING_MATCH_SETTINGS_MODE) { if ($setting->setting === self::SETTING_PICKANDBAN_ENABLE || $setting->setting === $this->MatchManagerCore::SETTING_MATCH_SETTINGS_MODE) {
if ($this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_PICKANDBAN_ENABLE)) { if ($this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_PICKANDBAN_ENABLE)) {
if ($this->maniaControl->getSettingManager()->getSettingValue($this->MatchManagerCore, $this->MatchManagerCore::SETTING_MATCH_SETTINGS_MODE) !== "All from the plugin") { if ($this->maniaControl->getSettingManager()->getSettingValue($this->MatchManagerCore, $this->MatchManagerCore::SETTING_MATCH_SETTINGS_MODE) !== "All from the plugin") {
$this->maniaControl->getChat()->sendErrorToAdmins('TMWT Pick and bans are only supported in Match Manager Core "All from the plugin" mode'); $this->maniaControl->getChat()->sendErrorToAdmins($this->MatchManagerCore->getChatPrefix() .'TMWT Pick and bans are only supported in Match Manager Core "All from the plugin" mode');
} }
} }
} }
@ -456,7 +496,7 @@ class MatchManagerTMWTDuoIntegration implements CallbackListener, ManialinkPageA
* @see \ManiaControl\Plugins\Plugin::unload() * @see \ManiaControl\Plugins\Plugin::unload()
*/ */
public function unload() { public function unload() {
$this->MatchManagerCore->removeCanStartFunction($this, 'canStartMatch'); if ($this->MatchManagerCore !== null) $this->MatchManagerCore->removeCanStartFunction($this, 'canStartMatch');
/** @var \MatchManagerSuite\MatchManagerAdminUI|null */ /** @var \MatchManagerSuite\MatchManagerAdminUI|null */
$adminUIPlugin = $this->maniaControl->getPluginManager()->getPlugin(self::MATCHMANAGERADMINUI_PLUGIN); $adminUIPlugin = $this->maniaControl->getPluginManager()->getPlugin(self::MATCHMANAGERADMINUI_PLUGIN);
if ($adminUIPlugin !== null) { if ($adminUIPlugin !== null) {

View File

@ -20,8 +20,8 @@ use ManiaControl\Settings\Setting;
use ManiaControl\Settings\SettingManager; use ManiaControl\Settings\SettingManager;
if (!class_exists('MatchManagerSuite\MatchManagerCore')) { if (!class_exists('MatchManagerSuite\MatchManagerCore')) {
$this->maniaControl->getChat()->sendErrorToAdmins('MatchManager Core is required to use one of MatchManager plugin. Install it and restart Maniacontrol'); $this->maniaControl->getChat()->sendErrorToAdmins('MatchManager Core is required to use MatchManagerWidget plugin. Install it and restart Maniacontrol');
Logger::logError('MatchManager Core is required to use one of MatchManager plugin. Install it and restart Maniacontrol'); $this->logError('MatchManager Core is required to use MatchManagerWidget plugin. Install it and restart Maniacontrol');
return false; return false;
} }
use MatchManagerSuite\MatchManagerCore; use MatchManagerSuite\MatchManagerCore;
@ -38,10 +38,12 @@ class MatchManagerWidget implements ManialinkPageAnswerListener, CallbackListene
* Constants * Constants
*/ */
const PLUGIN_ID = 153; const PLUGIN_ID = 153;
const PLUGIN_VERSION = 1.8; const PLUGIN_VERSION = 1.9;
const PLUGIN_NAME = 'MatchManager Widget'; const PLUGIN_NAME = 'MatchManager Widget';
const PLUGIN_AUTHOR = 'Beu'; const PLUGIN_AUTHOR = 'Beu';
const LOG_PREFIX = '[MatchManagerWidget] ';
// MatchManagerWidget Properties // MatchManagerWidget Properties
const MATCHMANAGERWIDGET_COMPATIBLE_GM = ["Cup", "Teams", "Rounds"]; const MATCHMANAGERWIDGET_COMPATIBLE_GM = ["Cup", "Teams", "Rounds"];
const MATCHMANAGERCORE_PLUGIN = 'MatchManagerSuite\MatchManagerCore'; const MATCHMANAGERCORE_PLUGIN = 'MatchManagerSuite\MatchManagerCore';
@ -64,6 +66,7 @@ class MatchManagerWidget implements ManialinkPageAnswerListener, CallbackListene
*/ */
/** @var ManiaControl $maniaControl */ /** @var ManiaControl $maniaControl */
private $maniaControl = null; private $maniaControl = null;
/** @var MatchManagerCore $MatchManagerCore */
private $MatchManagerCore = null; private $MatchManagerCore = null;
private $gmbase = ""; private $gmbase = "";
private $manialinkData = null; private $manialinkData = null;
@ -171,6 +174,24 @@ class MatchManagerWidget implements ManialinkPageAnswerListener, CallbackListene
$this->closeWidgets(); $this->closeWidgets();
} }
/**
* Custom log function to add prefix
*
* @param mixed $message
*/
private function log(mixed $message) {
Logger::log(self::LOG_PREFIX . $message);
}
/**
* Custom logError function to add prefix
*
* @param mixed $message
*/
private function logError(mixed $message) {
Logger::logError(self::LOG_PREFIX . $message);
}
/** /**
* handlePluginUnloaded * handlePluginUnloaded
* *
@ -181,7 +202,7 @@ class MatchManagerWidget implements ManialinkPageAnswerListener, CallbackListene
public function handlePluginUnloaded(string $pluginClass, Plugin $plugin) { public function handlePluginUnloaded(string $pluginClass, Plugin $plugin) {
if ($pluginClass == self::MATCHMANAGERCORE_PLUGIN) { if ($pluginClass == self::MATCHMANAGERCORE_PLUGIN) {
$this->maniaControl->getChat()->sendErrorToAdmins(self::PLUGIN_NAME . " disabled because MatchManager Core is now disabled"); $this->maniaControl->getChat()->sendErrorToAdmins(self::PLUGIN_NAME . " disabled because MatchManager Core is now disabled");
$this->maniaControl->getPluginManager()->deactivatePlugin((get_class())); $this->maniaControl->getPluginManager()->deactivatePlugin((get_class($this)));
} }
} }
@ -215,7 +236,7 @@ class MatchManagerWidget implements ManialinkPageAnswerListener, CallbackListene
* @param array $settings * @param array $settings
*/ */
public function InitMatch(string $matchid, array $settings) { public function InitMatch(string $matchid, array $settings) {
Logger::Log("InitMatch"); $this->log("InitMatch");
$this->gmbase = $settings['currentgmbase']; $this->gmbase = $settings['currentgmbase'];
$this->displayManialinks(false); $this->displayManialinks(false);
} }
@ -224,7 +245,7 @@ class MatchManagerWidget implements ManialinkPageAnswerListener, CallbackListene
* Clear variables and hide widget * Clear variables and hide widget
*/ */
public function ClearMatch() { public function ClearMatch() {
Logger::Log("ClearMatch"); $this->log("ClearMatch");
$this->gmbase = ""; $this->gmbase = "";
$this->manialinkData = ""; $this->manialinkData = "";
$this->closeWidgets(); $this->closeWidgets();
@ -295,7 +316,7 @@ class MatchManagerWidget implements ManialinkPageAnswerListener, CallbackListene
* @param Player $player * @param Player $player
*/ */
public function handlePlayerConnect(Player $player) { public function handlePlayerConnect(Player $player) {
Logger::Log("handlePlayerConnect"); $this->log("handlePlayerConnect");
if (strlen($this->gmbase) > 0) { if (strlen($this->gmbase) > 0) {
$this->displayManialinks($player->login); $this->displayManialinks($player->login);
@ -405,7 +426,7 @@ class MatchManagerWidget implements ManialinkPageAnswerListener, CallbackListene
* Generate the manilink of the background of the widget * Generate the manilink of the background of the widget
*/ */
public function generateMatchLiveWidgetBackground() { public function generateMatchLiveWidgetBackground() {
Logger::Log("generateMatchLiveWidgetBackground"); $this->log("generateMatchLiveWidgetBackground");
$posX = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MATCHMANAGERWIDGET_LIVE_POSX); $posX = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MATCHMANAGERWIDGET_LIVE_POSX);
$posY = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MATCHMANAGERWIDGET_LIVE_POSY); $posY = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MATCHMANAGERWIDGET_LIVE_POSY);
@ -448,7 +469,7 @@ class MatchManagerWidget implements ManialinkPageAnswerListener, CallbackListene
* @param array $currentscore * @param array $currentscore
*/ */
public function generateMatchLiveWidgetData(array $currentscore) { public function generateMatchLiveWidgetData(array $currentscore) {
Logger::Log("generateMatchLiveWidgetData"); $this->log("generateMatchLiveWidgetData");
if ($this->gmbase == "Cup") { if ($this->gmbase == "Cup") {
$pointlimit = $this->MatchManagerCore->getMatchPointsLimit(); $pointlimit = $this->MatchManagerCore->getMatchPointsLimit();