* Refactor how "Next maps" are displayed in the chat

* Add RoyalTimeAttack gamemode
* Add support of Royal Map Type
* Fix some bugs during loading maps
* Remove an useless Callback and some unused classes
* bump to 2.0
This commit is contained in:
Beu 2021-08-17 19:46:33 +02:00
parent a64974ff09
commit b660872bda

View File

@ -12,11 +12,9 @@ use ManiaControl\Callbacks\Callbacks;
use ManiaControl\Callbacks\CallbackManager; use ManiaControl\Callbacks\CallbackManager;
use ManiaControl\Callbacks\Structures\Common\StatusCallbackStructure; use ManiaControl\Callbacks\Structures\Common\StatusCallbackStructure;
use ManiaControl\Callbacks\Structures\TrackMania\OnScoresStructure; use ManiaControl\Callbacks\Structures\TrackMania\OnScoresStructure;
use ManiaControl\Callbacks\Structures\TrackMania\OnWayPointEventStructure;
use ManiaControl\Commands\CommandListener; use ManiaControl\Commands\CommandListener;
use ManiaControl\Communication\CommunicationAnswer; use ManiaControl\Communication\CommunicationAnswer;
use ManiaControl\Communication\CommunicationListener; use ManiaControl\Communication\CommunicationListener;
use ManiaControl\Manialinks\ManialinkPageAnswerListener;
use ManiaControl\Players\Player; use ManiaControl\Players\Player;
use ManiaControl\Players\PlayerManager; use ManiaControl\Players\PlayerManager;
use ManiaControl\Plugins\Plugin; use ManiaControl\Plugins\Plugin;
@ -27,7 +25,7 @@ use ManiaControl\Settings\SettingManager;
use ManiaControl\Configurator\GameModeSettings; use ManiaControl\Configurator\GameModeSettings;
use ManiaControl\Utils\Formatter; use ManiaControl\Utils\Formatter;
use Maniaplanet\DedicatedServer\InvalidArgumentException; use Maniaplanet\DedicatedServer\InvalidArgumentException;
use ManiaControl\Callbacks\TimerListener; use ManiaControl\Callbacks\TimerListener; // for pause
use ManiaControl\Maps\Map; use ManiaControl\Maps\Map;
/** /**
@ -36,10 +34,10 @@ use ManiaControl\Maps\Map;
* @author Beu (based on MatchPlugin by jonthekiller) * @author Beu (based on MatchPlugin by jonthekiller)
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3 * @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
*/ */
class MatchManagerCore implements ManialinkPageAnswerListener, CallbackListener, CommandListener, TimerListener, CommunicationListener, Plugin { class MatchManagerCore implements CallbackListener, CommandListener, TimerListener, CommunicationListener, Plugin {
const PLUGIN_ID = 152; const PLUGIN_ID = 152;
const PLUGIN_VERSION = 1.4; const PLUGIN_VERSION = 2.0;
const PLUGIN_NAME = 'MatchManager Core'; const PLUGIN_NAME = 'MatchManager Core';
const PLUGIN_AUTHOR = 'Beu'; const PLUGIN_AUTHOR = 'Beu';
@ -242,7 +240,7 @@ class MatchManagerCore implements ManialinkPageAnswerListener, CallbackListener,
'default' => 1, 'default' => 1,
'description' => 'Rounds without elimination (like a Warmup, but just for the first map)' ], 'description' => 'Rounds without elimination (like a Warmup, but just for the first map)' ],
self::SETTING_MATCH_S_TIMELIMIT => [ self::SETTING_MATCH_S_TIMELIMIT => [
'gamemode' => ['Champion', 'Laps', 'TimeAttack'], 'gamemode' => ['Champion', 'Laps', 'TimeAttack', 'RoyalTimeAttack'],
'type' => 'integer', 'type' => 'integer',
'default' => 600, 'default' => 600,
'description' => 'Time limit (0 = unlimited)' ], 'description' => 'Time limit (0 = unlimited)' ],
@ -267,17 +265,17 @@ class MatchManagerCore implements ManialinkPageAnswerListener, CallbackListener,
'default' => false, 'default' => false,
'description' => 'Use Tie Break (Only available when S_MapsPerMatch > 1)' ], 'description' => 'Use Tie Break (Only available when S_MapsPerMatch > 1)' ],
self::SETTING_MATCH_S_WARMUPDURATION => [ self::SETTING_MATCH_S_WARMUPDURATION => [
'gamemode' => ['Global'], 'gamemode' => ['Champion', 'Cup', 'Knockout', 'Laps', 'Teams', 'TimeAttack', 'Rounds'],
'type' => 'integer', 'type' => 'integer',
'default' => -1, 'default' => -1,
'description' => 'Duration of 1 Warm Up in sec (-1 = one round, 0 = based on Author time)' ], 'description' => 'Duration of 1 Warm Up in sec (-1 = one round, 0 = based on Author time)' ],
self::SETTING_MATCH_S_WARMUPNB => [ self::SETTING_MATCH_S_WARMUPNB => [
'gamemode' => ['Global'], 'gamemode' => ['Champion', 'Cup', 'Knockout', 'Laps', 'Teams', 'TimeAttack', 'Rounds'],
'type' => 'integer', 'type' => 'integer',
'default' => 1, 'default' => 1,
'description' => 'Number of Warm Up' ], 'description' => 'Number of Warm Up' ],
self::SETTING_MATCH_S_WARMUPTIMEOUT => [ self::SETTING_MATCH_S_WARMUPTIMEOUT => [
'gamemode' => ['Global'], 'gamemode' => ['Champion', 'Cup', 'Knockout', 'Laps', 'Teams', 'TimeAttack', 'Rounds'],
'type' => 'integer', 'type' => 'integer',
'default' => -1, 'default' => -1,
'description' => 'Time after the first finished the WarmUP (-1 = based on Author time, only when S_WarmUpDuration = -1)' ], 'description' => 'Time after the first finished the WarmUP (-1 = based on Author time, only when S_WarmUpDuration = -1)' ],
@ -354,6 +352,7 @@ class MatchManagerCore implements ManialinkPageAnswerListener, CallbackListener,
private $postmatch = false; private $postmatch = false;
private $mapsshuffled = false; private $mapsshuffled = false;
private $mapshidden = false; private $mapshidden = false;
private $hidenextmaps = false;
private $maps = array(); private $maps = array();
private $currentgmsettings = array(); private $currentgmsettings = array();
@ -406,15 +405,14 @@ class MatchManagerCore implements ManialinkPageAnswerListener, CallbackListener,
// Init plugin // Init plugin
$this->maniaControl = $maniaControl; $this->maniaControl = $maniaControl;
$this->initTables(); $this->initTables();
$this->maniaControl->getModeScriptEventManager()->unblockCallback("Trackmania.Event.WayPoint");
$this->maniaControl->getModeScriptEventManager()->unBlockAllCallbacks(); $this->maniaControl->getChat()->sendErrorToAdmins($this->chatprefix . "This new version has a lot of code refactoring, please contact me if you encounter any bug via discord @Beu#1337 or Twitter @AmazingBeu");
$this->maniaControl->getModeScriptEventManager()->enableCallbacks();
//Settings //Settings
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_MATCH_AUTHLEVEL, AuthenticationManager::getPermissionLevelNameArray(AuthenticationManager::AUTH_LEVEL_ADMIN), "Admin level needed to use the plugin"); $this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_MATCH_AUTHLEVEL, AuthenticationManager::getPermissionLevelNameArray(AuthenticationManager::AUTH_LEVEL_ADMIN), "Admin level needed to use the plugin");
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_MATCH_SETTINGS_MODE, array('All from the plugin', 'Maps from file & Settings from plugin', 'All from file'), "Loading mode for maps and match settings, depending on your needs"); $this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_MATCH_SETTINGS_MODE, array('All from the plugin', 'Maps from file & Settings from plugin', 'All from file'), "Loading mode for maps and match settings, depending on your needs");
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_MATCH_PAUSE_DURATION, 120, "Default Pause Duration in seconds"); $this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_MATCH_PAUSE_DURATION, 120, "Default Pause Duration in seconds");
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_MATCH_GAMEMODE_BASE, array("Champion", "Cup", "Knockout", "Laps", "Teams", "TimeAttack", "Rounds"), "Gamemode to launch for the match"); $this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_MATCH_GAMEMODE_BASE, array("Champion", "Cup", "Knockout", "Laps", "Teams", "TimeAttack", "Rounds", "RoyalTimeAttack"), "Gamemode to launch for the match");
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_MATCH_PAUSE_POSX, 0, "Position of the Pause Countdown (on X axis)"); $this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_MATCH_PAUSE_POSX, 0, "Position of the Pause Countdown (on X axis)");
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_MATCH_PAUSE_POSY, 43, "Position of the Pause Countdown (on Y axis)"); $this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_MATCH_PAUSE_POSY, 43, "Position of the Pause Countdown (on Y axis)");
@ -441,7 +439,6 @@ class MatchManagerCore implements ManialinkPageAnswerListener, CallbackListener,
$this->maniaControl->getCallbackManager()->registerCallbackListener(Callbacks::MP_STARTROUNDSTART, $this, 'handleBeginRoundCallback'); $this->maniaControl->getCallbackManager()->registerCallbackListener(Callbacks::MP_STARTROUNDSTART, $this, 'handleBeginRoundCallback');
$this->maniaControl->getCallbackManager()->registerCallbackListener(Callbacks::TM_WARMUPSTARTROUND, $this, 'handleStartWarmUpCallback'); $this->maniaControl->getCallbackManager()->registerCallbackListener(Callbacks::TM_WARMUPSTARTROUND, $this, 'handleStartWarmUpCallback');
$this->maniaControl->getCallbackManager()->registerCallbackListener(CallbackManager::CB_MP_BEGINMATCH, $this, 'handleBeginMatchCallback'); $this->maniaControl->getCallbackManager()->registerCallbackListener(CallbackManager::CB_MP_BEGINMATCH, $this, 'handleBeginMatchCallback');
$this->maniaControl->getCallbackManager()->registerCallbackListener(Callbacks::TM_ONFINISHLINE, $this, 'handleFinishCallback');
// Register Socket commands // Register Socket commands
$this->maniaControl->getCommunicationManager()->registerCommunicationListener("Match.GetMatchStatus", $this, function () { return new CommunicationAnswer($this->getMatchStatus()); }); $this->maniaControl->getCommunicationManager()->registerCommunicationListener("Match.GetMatchStatus", $this, function () { return new CommunicationAnswer($this->getMatchStatus()); });
@ -517,32 +514,6 @@ class MatchManagerCore implements ManialinkPageAnswerListener, CallbackListener,
} }
} }
/**
* Generate description prefix (ex: [*] or [Ch,C,KO])
*
* @param string $gamesetting
*/
public function getDescriptionPrefix(string $gamesetting) {
if (in_array('Global', self::GAMEMODES_LIST_SETTINGS[$gamesetting]['gamemode'])) {
$prefix = '[*] ';
} else {
$prefix = '[';
foreach (self::GAMEMODES_LIST_SETTINGS[$gamesetting]['gamemode'] as $gamemode) {
if ($gamemode == "Champion") {
$prefix .= 'Ch,';
} elseif ($gamemode == "TimeAttack") {
$prefix .= 'TA,';
} elseif ($gamemode == "Knockout") {
$prefix .= 'KO,';
} else {
$prefix .= substr($gamemode, 0 ,1) . ',';
}
}
$prefix = substr($prefix, 0, -1) . '] ';
}
return $prefix;
}
public function getMatchStatus() { public function getMatchStatus() {
return $this->matchStarted; return $this->matchStarted;
} }
@ -589,6 +560,7 @@ class MatchManagerCore implements ManialinkPageAnswerListener, CallbackListener,
* @param Setting $setting * @param Setting $setting
*/ */
public function updateSettings(Setting $setting = null) { public function updateSettings(Setting $setting = null) {
Logger::log("updateSettings");
if (isset($setting) && $setting->belongsToClass($this) && $this->matchStarted) { if (isset($setting) && $setting->belongsToClass($this) && $this->matchStarted) {
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;
@ -598,6 +570,10 @@ class MatchManagerCore implements ManialinkPageAnswerListener, CallbackListener,
$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($this->chatprefix . 'You can\'t change the Setting Mode during a Match');
} else if ($setting->setting == self::SETTING_MODE_HIDENEXTMAPS && $setting->value != $this->hidenextmaps) {
$setting->value = $this->hidenextmaps;
$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');
} 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"); Logger::log("Load Script Settings");
@ -619,13 +595,10 @@ class MatchManagerCore implements ManialinkPageAnswerListener, CallbackListener,
$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); $modesettings = $this->getModeSettings($settingsmode);
foreach ($allsettings as $key => $value) { foreach ($allsettings as $key => $value) {
$name = $value->setting; $name = $value->setting;
if (array_key_exists($name,self::SETTINGS_MODE_LIST)) { if (array_key_exists($name,self::SETTINGS_MODE_LIST)) {
if (isset($modesettings[$name])) { if (!isset($modesettings[$name])) {
unset($modesettings[$name]);
} else {
$this->maniaControl->getSettingManager()->deleteSetting($this, $name); $this->maniaControl->getSettingManager()->deleteSetting($this, $name);
} }
} }
@ -640,16 +613,12 @@ class MatchManagerCore implements ManialinkPageAnswerListener, CallbackListener,
foreach ($allsettings as $key => $value) { foreach ($allsettings as $key => $value) {
$name = $value->setting; $name = $value->setting;
if (substr($name,0, 2) == "S_") { if (substr($name,0, 2) == "S_" && !isset($gmsettings[$name])) {
if (isset($gmsettings[$name])) { $this->maniaControl->getSettingManager()->deleteSetting($this, $name);
unset($gmsettings[$name]);
} else {
$this->maniaControl->getSettingManager()->deleteSetting($this, $name);
}
} }
} }
foreach ($gmsettings as $key => $value) { foreach ($gmsettings as $key => $value) {
$this->maniaControl->getSettingManager()->initSetting($this, $key, $value, $this->getDescriptionPrefix($key) . self::GAMEMODES_LIST_SETTINGS[$key]['description']); $this->maniaControl->getSettingManager()->initSetting($this, $key, $value, self::GAMEMODES_LIST_SETTINGS[$key]['description']);
} }
} else { } else {
foreach ($allsettings as $key => $value) { foreach ($allsettings as $key => $value) {
@ -675,9 +644,15 @@ class MatchManagerCore implements ManialinkPageAnswerListener, CallbackListener,
$this->settingsloaded = false; $this->settingsloaded = false;
$this->mapsshuffled = false; $this->mapsshuffled = false;
$this->mapshidden = false; $this->mapshidden = false;
$this->hidenextmaps = false;
$this->maps = array(); $this->maps = array();
$this->postmatch = true; $this->postmatch = true;
$this->matchid = ""; $this->matchid = "";
$this->settings_nbroundsbymap = 5;
$this->settings_nbwinner = 2;
$this->settings_nbmapsbymatch = 0;
$this->settings_pointlimit = 100;
} }
/** /**
@ -692,8 +667,9 @@ class MatchManagerCore implements ManialinkPageAnswerListener, CallbackListener,
$value = $this->maniaControl->getSettingManager()->getSettingValue($this, $gamesetting); $value = $this->maniaControl->getSettingManager()->getSettingValue($this, $gamesetting);
if ($value == null) { if ($value == null) {
$value = $info['default']; $value = $info['default'];
} else {
settype($value, $info['type']);
} }
settype($value, $info['type']);
$gamesettings = array_merge($gamesettings , array($gamesetting => $value )); $gamesettings = array_merge($gamesettings , array($gamesetting => $value ));
} }
} }
@ -741,12 +717,6 @@ class MatchManagerCore implements ManialinkPageAnswerListener, CallbackListener,
} elseif (isset($this->currentgmsettings[self::SETTING_MATCH_S_MAPSPERMATCH])) { } elseif (isset($this->currentgmsettings[self::SETTING_MATCH_S_MAPSPERMATCH])) {
$this->settings_nbmapsbymatch = (int) $this->currentgmsettings[self::SETTING_MATCH_S_MAPSPERMATCH]; $this->settings_nbmapsbymatch = (int) $this->currentgmsettings[self::SETTING_MATCH_S_MAPSPERMATCH];
} }
if (isset($this->currentgmsettings[self::SETTING_MATCH_S_POINTSGAP])) {
$this->settings_pointsgap = (int) $this->currentgmsettings[self::SETTING_MATCH_S_POINTSGAP];
}
if (isset($this->currentgmsettings[self::SETTING_MATCH_S_USETIEBREAK])) {
$this->settings_usetiebreak = (int) $this->currentgmsettings[self::SETTING_MATCH_S_USETIEBREAK];
}
} }
/** /**
@ -777,60 +747,40 @@ class MatchManagerCore implements ManialinkPageAnswerListener, CallbackListener,
$this->currentsettingmode = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MATCH_SETTINGS_MODE); $this->currentsettingmode = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MATCH_SETTINGS_MODE);
$maplist = ""; $maplist = "";
if ($this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MATCH_SETTINGS_MODE) != 'All from the plugin') { if ($this->currentgmbase == "RoyalTimeAttack") {
Logger::log("Loading maplist + matchsettings"); $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");
$maplist = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MODE_MAPLIST_FILE); Logger::Log("No data are save in RoyalTimeAttack for the moment, it's not implemented on server side. Waiting a fix from NADEO");
if (empty($maplist)) {
$server = $this->maniaControl->getServer()->login;
$maplist = 'MatchSettings' . DIRECTORY_SEPARATOR . $server . ".txt";
} else {
$maplist = 'MatchSettings' . DIRECTORY_SEPARATOR . $maplist;
}
Logger::log("Load matchsettings: " . $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)");
}
$this->maniaControl->getClient()->loadMatchSettings($maplist);
} else {
if (strlen($this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MODE_MAPS)) >= 1) {
$maps = explode(',', $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MODE_MAPS));
foreach ($maps as $map) {
try {
$mapInfo = new Map($this->maniaControl->getClient()->getMapInfo($map));
} catch (Exception $e) {
throw new \Exception("Error with the map " . $map . ": " . $e->getMessage());
}
}
if ($this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MODE_SHUFFLE)) {
//shuffle
$this->mapsshuffled = true;
shuffle($maps);
}
//Remove all maps
foreach ($this->maniaControl->getMapManager()->getMaps() as $map) {
$this->maniaControl->getClient()->removeMap($map->fileName);
}
$this->maps = $maps;
if ($this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MODE_HIDENEXTMAPS)) {
$this->maniaControl->getClient()->addMap($this->maps[0]);
} else {
foreach ($this->maps as $map) {
$this->maniaControl->getClient()->addMap($map);
}
}
} else {
throw new \Exception("No maps defined (the match has not started)");
}
} }
Logger::log("Restructure maplist"); // Prepare maps in case of "All from the plugin" mode
$this->maniaControl->getMapManager()->restructureMapList(); if ($this->currentsettingmode == 'All from the plugin' && strlen($this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MODE_MAPS)) >= 1) {
$maps = explode(',', $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MODE_MAPS));
if ($this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MATCH_SETTINGS_MODE) != 'All from file') { foreach ($maps as $map) {
try {
$mapInfo = new Map($this->maniaControl->getClient()->getMapInfo($map));
} catch (Exception $e) {
throw new \Exception("Error with the map " . $map . ": " . $e->getMessage());
}
}
if ($this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MODE_SHUFFLE)) {
//shuffle
$this->mapsshuffled = true;
shuffle($maps);
}
//Remove all maps
foreach ($this->maniaControl->getMapManager()->getMaps() as $map) {
$this->maniaControl->getClient()->removeMap($map->fileName);
}
$this->maps = $maps;
$this->hidenextmaps = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MODE_HIDENEXTMAPS);
}
// Define Gamemode
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;
@ -845,6 +795,40 @@ class MatchManagerCore implements ManialinkPageAnswerListener, CallbackListener,
$this->maniaControl->getClient()->setScriptName($scriptName); $this->maniaControl->getClient()->setScriptName($scriptName);
} }
// Must be after loading the script in case of different MapType
if ($this->currentsettingmode != 'All from the plugin') {
Logger::log("Loading maplist + matchsettings");
$maplist = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MODE_MAPLIST_FILE);
if (empty($maplist)) {
$server = $this->maniaControl->getServer()->login;
$maplist = 'MatchSettings' . DIRECTORY_SEPARATOR . $server . ".txt";
} else {
$maplist = 'MatchSettings' . DIRECTORY_SEPARATOR . $maplist;
}
Logger::log("Load matchsettings: " . $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)");
}
//Remove all maps
foreach ($this->maniaControl->getMapManager()->getMaps() as $map) {
$this->maniaControl->getClient()->removeMap($map->fileName);
}
$this->maniaControl->getClient()->InsertPlaylistFromMatchSettings($maplist);
} elseif ($this->currentsettingmode == 'All from the plugin') {
if ($this->hidenextmaps) {
$this->maniaControl->getClient()->addMap($this->maps[0]);
} else {
foreach ($this->maps as $map) {
$this->maniaControl->getClient()->addMap($map);
}
}
}
Logger::log("Restructure maplist");
$this->maniaControl->getMapManager()->restructureMapList();
$this->matchStarted = true; $this->matchStarted = true;
$this->nbmaps = 0; $this->nbmaps = 0;
$this->nbrounds = 0; $this->nbrounds = 0;
@ -891,7 +875,12 @@ class MatchManagerCore implements ManialinkPageAnswerListener, CallbackListener,
* Function called to end the match * Function called to end the match
*/ */
public function MatchEnd() { public function MatchEnd() {
$scriptName = "Trackmania/TM_TimeAttack_Online.Script.txt" ;
if ($this->currentmap->mapType == "TrackMania\TM_Royal") {
$scriptName = "Trackmania/TM_RoyalTimeAttack_Online.Script.txt" ;
} else {
$scriptName = "Trackmania/TM_TimeAttack_Online.Script.txt" ;
}
try { try {
$this->maniaControl->getClient()->setScriptName($scriptName); $this->maniaControl->getClient()->setScriptName($scriptName);
@ -931,7 +920,11 @@ class MatchManagerCore implements ManialinkPageAnswerListener, CallbackListener,
*/ */
public function MatchStop() { public function MatchStop() {
Logger::log("Match stop"); Logger::log("Match stop");
$scriptName = "Trackmania/TM_TimeAttack_Online.Script.txt"; if ($this->currentmap->mapType == "TrackMania\TM_Royal") {
$scriptName = "Trackmania/TM_RoyalTimeAttack_Online.Script.txt" ;
} else {
$scriptName = "Trackmania/TM_TimeAttack_Online.Script.txt" ;
}
try { try {
// Trigger Callback // Trigger Callback
@ -1201,43 +1194,54 @@ class MatchManagerCore implements ManialinkPageAnswerListener, CallbackListener,
Logger::log("Map: " . $this->nbmaps); Logger::log("Map: " . $this->nbmaps);
$maps = $this->maniaControl->getMapManager()->getMaps(); $maps = $this->maniaControl->getMapManager()->getMaps();
$nbmaps = $this->maniaControl->getMapManager()->getMapsCount(); $totalnbmaps = $this->maniaControl->getMapManager()->getMapsCount();
$i = 1;
$this->currentmap = $this->maniaControl->getMapManager()->getCurrentMap(); $this->currentmap = $this->maniaControl->getMapManager()->getCurrentMap();
Logger::log("Current Map: " . Formatter::stripCodes($this->currentmap->name));
$message = $this->chatprefix . '$<$o$iCurrent Map:$>' . "\n"; $message = $this->chatprefix . '$<$o$iCurrent Map:$>' . "\n";
$message .= Formatter::stripCodes($this->currentmap->name); $message .= Formatter::stripCodes($this->currentmap->name);
$this->maniaControl->getChat()->sendInformation($message); $this->maniaControl->getChat()->sendInformation($message);
Logger::log("Current Map: " . Formatter::stripCodes($this->currentmap->name));
$continue = false; if (!in_array($this->currentgmbase, ["Laps", "TimeAttack", "RoyalTimeAttack"])) {
$current = false; $message = "";
$message = ""; $i = 0;
foreach ($maps as $map) { //TODO check no nextmap in cup mode foreach ($maps as $map) {
if ($this->currentmap->uid == $map->uid) { if ($this->currentmap->uid == $map->uid) {
$continue = true; break;
$current = true; }
$i++;
} }
if ($continue && $this->nbmaps < $this->settings_nbmapsbymatch) {
if ($current) { if (($this->settings_nbmapsbymatch > 0 && $i < $this->settings_nbmapsbymatch - 1 ) || ($this->settings_nbmapsbymatch <= 0 && $totalnbmaps >= 2)) { // TODO manage maps in queue added by an admin
$current = false; $message = $this->chatprefix . '$<$o$iNext Maps:$>';
} elseif (($this->nbmaps + $i) <= ($this->settings_nbmapsbymatch)) { for ($j = 1; $j <= 4 && (($this->settings_nbmapsbymatch > 0 && $j <= $this->settings_nbmapsbymatch - $this->nbmaps) || ($this->settings_nbmapsbymatch <= 0 && $j <= $totalnbmaps)) ; $j++ ) {
if ($i > 0) { $index = $i + $j;
if ($i == 1) {
$message = $this->chatprefix . '$<$o$iNext Maps:$>'; while ($index >= $totalnbmaps) { // return to the start of the array if end of array
} $index = $index - $totalnbmaps;
Logger::log("Map " . $i . ": " . Formatter::stripCodes($map->name)); }
$message .= "\n" . $i . ": " . Formatter::stripCodes($map->name);
$i++; if ($index != $i) {
if ($this->nbmaps == ($nbmaps - ($i - 1) + 1) or $this->settings_nbmapsbymatch == (($i - 1) + $this->nbmaps - 1)) { $message .= "\n" . $j . ": " . Formatter::stripCodes($maps[$index]->name);
$continue = false; Logger::log(Formatter::stripCodes($index . ": " . $maps[$index]->name));
} } else {
$message .= "\nThen we will return to this map";
Logger::log("Then we will return to this map");
break;
} }
} }
if ($j >= 4) {
if ($this->settings_nbmapsbymatch > 0 && $this->settings_nbmapsbymatch - $j - $this->nbmaps + 1 > 0) {
$message .= "\n" . "And " . ($this->settings_nbmapsbymatch - $j - $this->nbmaps + 1) . " more maps";
Logger::log("And " . ($this->settings_nbmapsbymatch - $j - $this->nbmaps + 1) . " more maps");
} elseif ($this->settings_nbmapsbymatch <= 0 && $totalnbmaps - $j > 0) {
$message .= "\n" . "And " . ($totalnbmaps - $j) . " more maps";
Logger::log("And " . ($totalnbmaps - $j) . " more maps");
}
}
$this->maniaControl->getChat()->sendInformation($message);
} }
} }
if (!empty($message)) {
$this->maniaControl->getChat()->sendInformation($message);
}
} }
// Trigger Callback // Trigger Callback
@ -1250,16 +1254,18 @@ class MatchManagerCore implements ManialinkPageAnswerListener, CallbackListener,
if ($this->postmatch) { if ($this->postmatch) {
$scriptName = $this->maniaControl->getClient()->getScriptName()['CurrentValue']; $scriptName = $this->maniaControl->getClient()->getScriptName()['CurrentValue'];
Logger::log("scriptName: " . $scriptName); Logger::log("scriptName: " . $scriptName);
if ($scriptName == "Trackmania/TM_TimeAttack_Online.Script.txt") { if ($scriptName == "Trackmania/TM_TimeAttack_Online.Script.txt" || $scriptName == "Trackmania/TM_RoyalTimeAttack_Online.Script.txt") {
$this->postmatch = false; $this->postmatch = false;
Logger::log("Load Script Settings"); Logger::log("Load Script Settings");
$postmatchsettings = [ $postmatchsettings = [
self::SETTING_MATCH_S_FORCELAPSNB => 0, self::SETTING_MATCH_S_FORCELAPSNB => 0,
self::SETTING_MATCH_S_RESPAWNBEHAVIOUR => 0, self::SETTING_MATCH_S_RESPAWNBEHAVIOUR => 0,
self::SETTING_MATCH_S_WARMUPNB => 0,
self::SETTING_MATCH_S_TIMELIMIT => 600 self::SETTING_MATCH_S_TIMELIMIT => 600
]; ];
if ($scriptName == "Trackmania/TM_TimeAttack_Online.Script.txt") {
$postmatchsettings[self::SETTING_MATCH_S_WARMUPNB] = 0;
}
$this->maniaControl->getClient()->setModeScriptSettings($postmatchsettings); $this->maniaControl->getClient()->setModeScriptSettings($postmatchsettings);
Logger::log("Restarting Map for load settings"); Logger::log("Restarting Map for load settings");
@ -1301,12 +1307,6 @@ class MatchManagerCore implements ManialinkPageAnswerListener, CallbackListener,
Logger::log("Round: " . ($this->nbrounds + 1) . ' / ' . $this->settings_nbroundsbymap); Logger::log("Round: " . ($this->nbrounds + 1) . ' / ' . $this->settings_nbroundsbymap);
} }
}); });
} elseif (in_array($this->currentgmbase, ["Laps", "TimeAttack"])) {
if ($this->nbmaps > 0) {
$this->maniaControl->getChat()->sendInformation($this->chatprefix . '$s$<$o$iMap: ' . ($this->nbmaps));
Logger::log("Map: " . $this->nbmaps);
}
} }
// Match Recover // Match Recover
@ -1316,24 +1316,6 @@ class MatchManagerCore implements ManialinkPageAnswerListener, CallbackListener,
} }
} }
/**
* Handle Finish Callback
*
* @param \ManiaControl\Callbacks\Structures\TrackMania\OnWayPointEventStructure $structure
*/
public function handleFinishCallback(OnWayPointEventStructure $structure) {
if ($this->matchStarted) {
if ($structure->getRaceTime() <= 0) {
Logger::log("handleFinishCallback: Invalid time");
return;
}
$player = $structure->getPlayer();
if (!$player) {
return;
}
}
}
/** /**
* Handle callback "EndRound" * Handle callback "EndRound"
@ -1346,13 +1328,16 @@ class MatchManagerCore implements ManialinkPageAnswerListener, CallbackListener,
Logger::log("Section: " . $structure->getSection()); Logger::log("Section: " . $structure->getSection());
if ($structure->getSection() == "EndMatch") { if ($structure->getSection() == "EndMatch") {
$this->MatchEnd(); $this->MatchEnd();
} } elseif ($structure->getSection() == "EndMap") {
else { if ($this->hidenextmaps && isset($this->maps[$this->nbmaps])) {
$this->maniaControl->getClient()->addMap($this->maps[$this->nbmaps]);
}
} else {
$timestamp = time(); $timestamp = time();
if ($structure->getSection() == "PreEndRound" && in_array($this->currentgmbase, ["Cup", "Teams", "Rounds"])) { if ($structure->getSection() == "PreEndRound" && in_array($this->currentgmbase, ["Cup", "Teams", "Rounds"])) {
$realSection = true; $realSection = true;
} elseif ($structure->getSection() == "EndRound" && in_array($this->currentgmbase, ["Champion", "Knockout", "Laps", "TimeAttack"])) { } elseif ($structure->getSection() == "EndRound" && in_array($this->currentgmbase, ["Champion", "Knockout", "Laps", "TimeAttack", "RoyalTimeAttack"])) {
$realSection = true; $realSection = true;
} else { } else {
$realSection = false; $realSection = false;
@ -1400,9 +1385,14 @@ class MatchManagerCore implements ManialinkPageAnswerListener, CallbackListener,
} elseif ($this->currentgmbase == "Knockout") { } elseif ($this->currentgmbase == "Knockout") {
$this->currentscore = array_merge($this->currentscore, array(array($rank, $player->login, $points, "-1", $time, "-1"))); $this->currentscore = array_merge($this->currentscore, array(array($rank, $player->login, $points, "-1", $time, "-1")));
} }
} elseif (in_array($this->currentgmbase, ["Laps", "TimeAttack"]) && !(($time == 0 || $time == -1) && ($player->isSpectator || $player->isFakePlayer()))) { } elseif (in_array($this->currentgmbase, ["Laps", "TimeAttack", "RoyalTimeAttack"]) && !(($time == 0 || $time == -1) && ($player->isSpectator || $player->isFakePlayer()))) {
$besttime = $result->getBestRaceTime(); $besttime = $result->getBestRaceTime();
if ($this->currentgmbase == "Laps") {
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");
Logger::Log("No data are save in RoyalTimeAttack for the moment, it's not implemented on server side. Waiting a fix from NADEO");
}
if ($this->currentgmbase == "Laps" || $this->currentgmbase == "RoyalTimeAttack") {
$nbcp = count($result->getBestRaceCheckpoints()); $nbcp = count($result->getBestRaceCheckpoints());
$this->currentscore = array_merge($this->currentscore, array(array($rank, $player->login, $nbcp, "-1", $besttime, "-1"))); $this->currentscore = array_merge($this->currentscore, array(array($rank, $player->login, $nbcp, "-1", $besttime, "-1")));
} elseif ($this->currentgmbase == "TimeAttack") { } elseif ($this->currentgmbase == "TimeAttack") {
@ -1448,10 +1438,6 @@ class MatchManagerCore implements ManialinkPageAnswerListener, CallbackListener,
Logger::log("Rounds finished: " . $this->nbrounds); Logger::log("Rounds finished: " . $this->nbrounds);
if ($this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MODE_HIDENEXTMAPS) && $this->nbrounds == $this->settings_nbroundsbymap) {
$this->maniaControl->getClient()->addMap($this->maps[$this->nbmaps]);
}
// Trigger Callback // Trigger Callback
$this->maniaControl->getCallbackManager()->triggerCallback(self::CB_MATCHMANAGER_ENDROUND, $this->matchid, $this->currentscore, []); $this->maniaControl->getCallbackManager()->triggerCallback(self::CB_MATCHMANAGER_ENDROUND, $this->matchid, $this->currentscore, []);
} }
@ -1612,7 +1598,7 @@ class MatchManagerCore implements ManialinkPageAnswerListener, CallbackListener,
return; return;
} }
if (($this->matchStarted) && ($this->currentgmbase != "TimeAttack" || ($this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MATCH_SETTINGS_MODE) != 'All from file' && !empty($this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MATCH_CUSTOM_GAMEMODE))))) { 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))))) {
$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] != "") {
@ -1647,7 +1633,7 @@ class MatchManagerCore implements ManialinkPageAnswerListener, CallbackListener,
$this->maniaControl->getAuthenticationManager()->sendNotAllowed($player); $this->maniaControl->getAuthenticationManager()->sendNotAllowed($player);
return; return;
} }
if (($this->matchStarted) && ($this->currentgmbase != "TimeAttack" || ( $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($this->chatprefix . 'Admin stopped the break');
$this->unsetNadeoPause(); $this->unsetNadeoPause();
} else { } else {
@ -1672,12 +1658,15 @@ class MatchManagerCore implements ManialinkPageAnswerListener, CallbackListener,
$text = explode(" ", $text); $text = explode(" ", $text);
if (isset($text[1]) && isset($text[2]) && is_numeric($text[2]) && $text[2] >= 0 ) { if (isset($text[1]) && isset($text[2]) && is_numeric($text[2]) && $text[2] >= 0 ) {
if (strcasecmp($text[1], "Blue") == 0 || $text[1] == "0") { //TODO: add support of Custom teams if (strcasecmp($text[1], "Blue") == 0 || $text[1] == "0") {
$this->maniaControl->getModeScriptEventManager()->setTrackmaniaTeamPoints("0", "", $text[2], $text[2]); $this->maniaControl->getModeScriptEventManager()->setTrackmaniaTeamPoints("0", "", $text[2], $text[2]);
$this->maniaControl->getChat()->sendSuccess($this->chatprefix . '$<$00fBlue$> Team now has $<$ff0' . $text[2] . '$> points!'); $this->maniaControl->getChat()->sendSuccess($this->chatprefix . '$<$00fBlue$> Team now has $<$ff0' . $text[2] . '$> points!');
} elseif (strcasecmp($text[1], "Red") == 0 || $text[1] == "1") { } elseif (strcasecmp($text[1], "Red") == 0 || $text[1] == "1") {
$this->maniaControl->getModeScriptEventManager()->setTrackmaniaTeamPoints("1", "", $text[2] , $text[2]); $this->maniaControl->getModeScriptEventManager()->setTrackmaniaTeamPoints("1", "", $text[2] , $text[2]);
$this->maniaControl->getChat()->sendSuccess($this->chatprefix . '$<$f00Red$> Team now has $<$ff0' . $text[2] . '$> points!'); $this->maniaControl->getChat()->sendSuccess($this->chatprefix . '$<$f00Red$> Team now has $<$ff0' . $text[2] . '$> points!');
} elseif (is_numeric($text[1])) {//TODO: add support of name of teams (need update from NADEO)
$this->maniaControl->getModeScriptEventManager()->setTrackmaniaTeamPoints($text[1], "", $text[2] , $text[2]);
$this->maniaControl->getChat()->sendSuccess($this->chatprefix . 'Team ' . $text[1] . ' now has $<$ff0' . $text[2] . '$> points!');
} else { } else {
$mysqli = $this->maniaControl->getDatabase()->getMysqli(); $mysqli = $this->maniaControl->getDatabase()->getMysqli();
$query = 'SELECT login FROM `' . PlayerManager::TABLE_PLAYERS . '` WHERE nickname LIKE "' . $text[1] . '"'; $query = 'SELECT login FROM `' . PlayerManager::TABLE_PLAYERS . '` WHERE nickname LIKE "' . $text[1] . '"';