Check maplist file before start & fix "current/next map" message

This commit is contained in:
Beu 2021-01-19 11:44:23 +01:00
parent 97bcaa494f
commit 827cdca019

View File

@ -39,7 +39,7 @@ use Maniaplanet\DedicatedServer\InvalidArgumentException;
class MatchManagerCore implements ManialinkPageAnswerListener, CallbackListener, CommandListener, TimerListener, CommunicationListener, Plugin {
const PLUGIN_ID = 152;
const PLUGIN_VERSION = 1.0;
const PLUGIN_VERSION = 1.1;
const PLUGIN_NAME = 'MatchManager Core';
const PLUGIN_AUTHOR = 'Beu';
@ -396,7 +396,7 @@ class MatchManagerCore implements ManialinkPageAnswerListener, CallbackListener,
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_MATCH_CUSTOM_GAMEMODE, "", "Load custom gamemode script (some functions can bug, for expert only)");
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_MATCH_GAMEMODE_AFTERMATCH, array("TimeAttack"), "Gamemode to launch after the match");
$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_LOAD_MAPLIST_FILE, true, "Load Maps + Matchsettings from the file (or use the current maplist on the server)");
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_MATCH_LOAD_MAPLIST_FILE, false, "Load Maps + Matchsettings from the file (or use the current maplist on the server)");
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_MATCH_MAPLIST, "match.txt", "Maps + Matchsettings file to load (empty to use server login)");
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_MATCH_MATCHSETTINGS_CONF, false, "Load configuration from matchsettings file instead of Admin Interface (can be usefull with a custom script)");
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_MATCH_PAUSE_DURATION, 120, "Default Pause Duration in seconds");
@ -711,6 +711,11 @@ class MatchManagerCore implements ManialinkPageAnswerListener, CallbackListener,
$maplist = 'MatchSettings' . DIRECTORY_SEPARATOR . $maplist;
}
Logger::log("Load matchsettings: " . $maplist);
if (!is_file($this->maniaControl->getServer()->getDirectory()->getMapsFolder() . $maplist)) {
Logger::log("The Maplist file is not accessible or does not exist (the match has not started)");
$this->maniaControl->getChat()->sendErrorToAdmins($this->chatprefix . "The Maplist file is not accessible or does not exist (the match has not started)");
return;
}
$this->maniaControl->getClient()->loadMatchSettings($maplist);
Logger::log("Restructure maplist");
$this->maniaControl->getMapManager()->restructureMapList();
@ -1156,15 +1161,17 @@ class MatchManagerCore implements ManialinkPageAnswerListener, CallbackListener,
Logger::log("Map: " . $this->nbmaps);
$maps = $this->maniaControl->getMapManager()->getMaps();
$nbmaps = $this->maniaControl->getMapManager()->getMapsCount();
$i = 1;
$this->currentmap = $this->maniaControl->getMapManager()->getCurrentMap();
$message = $this->chatprefix . '$o$iCurrent Map:' . "\n";
$message .= '$o$i' . Formatter::stripCodes($this->currentmap->name);
$message = $this->chatprefix . '$<$o$iCurrent Map:$>' . "\n";
$message .= Formatter::stripCodes($this->currentmap->name);
$this->maniaControl->getChat()->sendInformation($message);
Logger::log("Current Map: " . Formatter::stripCodes($this->currentmap->name));
$continue = false;
$current = false;
$message = $this->chatprefix . '$o$iNext Maps:'; //TODO remove Next map if no next map
$message = "";
foreach ($maps as $map) { //TODO check no nextmap in cup mode
if ($this->currentmap->uid == $map->uid) {
$continue = true;
@ -1174,11 +1181,13 @@ class MatchManagerCore implements ManialinkPageAnswerListener, CallbackListener,
if ($current) {
$current = false;
} elseif (($this->nbmaps + $i) <= ($this->settings_nbmapsbymatch)) {
Logger::log("i: " . $i);
if ($i > 0) {
Logger::log("Map " . $i . ": " . Formatter::stripCodes($map->name));
$message .= "\n" . '$o$i' . $i . ": " . Formatter::stripCodes($map->name);
if ($i == 1) {
$message = $this->chatprefix . '$<$o$iNext Maps:$>';
}
$nbmaps = $this->maniaControl->getMapManager()->getMapsCount();
Logger::log("Map " . $i . ": " . Formatter::stripCodes($map->name));
$message .= "\n" . $i . ": " . Formatter::stripCodes($map->name);
$i++;
if ($this->nbmaps == ($nbmaps - ($i - 1) + 1) or $this->settings_nbmapsbymatch == (($i - 1) + $this->nbmaps - 1)) {
$continue = false;
@ -1186,8 +1195,11 @@ class MatchManagerCore implements ManialinkPageAnswerListener, CallbackListener,
}
}
}
}
if (!empty($message)) {
$this->maniaControl->getChat()->sendInformation($message);
}
}
// Trigger Callback
$currentstatus = [
'nbmaps' => $this->nbmaps,
@ -1661,3 +1673,4 @@ class MatchManagerCore implements ManialinkPageAnswerListener, CallbackListener,
}
}
}