Add a setting to disable ManiaExchange
This commit is contained in:
parent
129053e951
commit
0ad0d06f85
@ -71,6 +71,7 @@ class ManiaExchangeList implements CallbackListener, ManialinkPageAnswerListener
|
|||||||
* @param array $callback
|
* @param array $callback
|
||||||
*/
|
*/
|
||||||
public function handleManialinkPageAnswer(array $callback) {
|
public function handleManialinkPageAnswer(array $callback) {
|
||||||
|
if (!$this->maniaControl->getMapManager()->getMXManager()->getStatus()) return;
|
||||||
$actionId = $callback[1][2];
|
$actionId = $callback[1][2];
|
||||||
$actionArray = explode('.', $actionId);
|
$actionArray = explode('.', $actionId);
|
||||||
if (count($actionArray) <= 2) {
|
if (count($actionArray) <= 2) {
|
||||||
@ -101,6 +102,7 @@ class ManiaExchangeList implements CallbackListener, ManialinkPageAnswerListener
|
|||||||
* @param Player $player
|
* @param Player $player
|
||||||
*/
|
*/
|
||||||
public function showListCommand(array $chatCallback, Player $player) {
|
public function showListCommand(array $chatCallback, Player $player) {
|
||||||
|
if (!$this->maniaControl->getMapManager()->getMXManager()->getStatus()) return;
|
||||||
$this->mapListShown[$player->login] = true;
|
$this->mapListShown[$player->login] = true;
|
||||||
$params = explode(' ', $chatCallback[1][2]);
|
$params = explode(' ', $chatCallback[1][2]);
|
||||||
$searchString = '';
|
$searchString = '';
|
||||||
@ -141,6 +143,7 @@ class ManiaExchangeList implements CallbackListener, ManialinkPageAnswerListener
|
|||||||
* @param string $searchString
|
* @param string $searchString
|
||||||
*/
|
*/
|
||||||
private function getMXMapsAndShowList(Player $player, $author = '', $environment = '', $searchString = '') {
|
private function getMXMapsAndShowList(Player $player, $author = '', $environment = '', $searchString = '') {
|
||||||
|
if (!$this->maniaControl->getMapManager()->getMXManager()->getStatus()) return;
|
||||||
//TODO do more clean solution
|
//TODO do more clean solution
|
||||||
if($environment == ""){
|
if($environment == ""){
|
||||||
$titleId = $this->maniaControl->getServer()->titleId;
|
$titleId = $this->maniaControl->getServer()->titleId;
|
||||||
@ -191,6 +194,7 @@ class ManiaExchangeList implements CallbackListener, ManialinkPageAnswerListener
|
|||||||
* @internal param array $chatCallback
|
* @internal param array $chatCallback
|
||||||
*/
|
*/
|
||||||
private function showManiaExchangeList(array $maps, Player $player) {
|
private function showManiaExchangeList(array $maps, Player $player) {
|
||||||
|
if (!$this->maniaControl->getMapManager()->getMXManager()->getStatus()) return;
|
||||||
// Start offsets
|
// Start offsets
|
||||||
$width = $this->maniaControl->getManialinkManager()->getStyleManager()->getListWidgetsWidth();
|
$width = $this->maniaControl->getManialinkManager()->getStyleManager()->getListWidgetsWidth();
|
||||||
$height = $this->maniaControl->getManialinkManager()->getStyleManager()->getListWidgetsHeight();
|
$height = $this->maniaControl->getManialinkManager()->getStyleManager()->getListWidgetsHeight();
|
||||||
@ -340,6 +344,7 @@ class ManiaExchangeList implements CallbackListener, ManialinkPageAnswerListener
|
|||||||
* @param $openedWidget
|
* @param $openedWidget
|
||||||
*/
|
*/
|
||||||
public function handleWidgetOpened(Player $player, $openedWidget) {
|
public function handleWidgetOpened(Player $player, $openedWidget) {
|
||||||
|
if (!$this->maniaControl->getMapManager()->getMXManager()->getStatus()) return;
|
||||||
//unset when another main widget got opened
|
//unset when another main widget got opened
|
||||||
if ($openedWidget !== 'ManiaExchangeList') {
|
if ($openedWidget !== 'ManiaExchangeList') {
|
||||||
unset($this->mapListShown[$player->login]);
|
unset($this->mapListShown[$player->login]);
|
||||||
@ -355,5 +360,4 @@ class ManiaExchangeList implements CallbackListener, ManialinkPageAnswerListener
|
|||||||
public function closeWidget(Player $player) {
|
public function closeWidget(Player $player) {
|
||||||
unset($this->mapListShown[$player->login]);
|
unset($this->mapListShown[$player->login]);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -54,6 +54,7 @@ class ManiaExchangeManager implements UsageInformationAble {
|
|||||||
*/
|
*/
|
||||||
/** @var ManiaControl $maniaControl */
|
/** @var ManiaControl $maniaControl */
|
||||||
private $maniaControl = null;
|
private $maniaControl = null;
|
||||||
|
private $enabled = true;
|
||||||
private $mxIdUidVector = array();
|
private $mxIdUidVector = array();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -67,6 +68,22 @@ class ManiaExchangeManager implements UsageInformationAble {
|
|||||||
//$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_MX_KEY, "");
|
//$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_MX_KEY, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the status of the plugin
|
||||||
|
*
|
||||||
|
* @param bool $status
|
||||||
|
*/
|
||||||
|
public function setStatus(bool $status) {
|
||||||
|
$this->enabled = $status;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the status of the plugin
|
||||||
|
*/
|
||||||
|
public function getStatus() {
|
||||||
|
return $this->enabled;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unset Map by Mx Id
|
* Unset Map by Mx Id
|
||||||
*
|
*
|
||||||
@ -84,6 +101,7 @@ class ManiaExchangeManager implements UsageInformationAble {
|
|||||||
* @param mixed $maps
|
* @param mixed $maps
|
||||||
*/
|
*/
|
||||||
public function fetchManiaExchangeMapInformation($maps = null) {
|
public function fetchManiaExchangeMapInformation($maps = null) {
|
||||||
|
if (!$this->enabled) return;
|
||||||
if ($maps) {
|
if ($maps) {
|
||||||
// Fetch Information for a single map
|
// Fetch Information for a single map
|
||||||
$maps = array($maps);
|
$maps = array($maps);
|
||||||
@ -160,7 +178,7 @@ class ManiaExchangeManager implements UsageInformationAble {
|
|||||||
* @param string $string
|
* @param string $string
|
||||||
*/
|
*/
|
||||||
public function fetchMaplistByMixedUidIdString($string) {
|
public function fetchMaplistByMixedUidIdString($string) {
|
||||||
|
if (!$this->enabled) return;
|
||||||
// For TM2020
|
// For TM2020
|
||||||
if ($this->maniaControl->getServer()->titleId == "Trackmania") {
|
if ($this->maniaControl->getServer()->titleId == "Trackmania") {
|
||||||
// Get Title Prefix
|
// Get Title Prefix
|
||||||
@ -217,6 +235,7 @@ class ManiaExchangeManager implements UsageInformationAble {
|
|||||||
* @param array $mxMapInfos
|
* @param array $mxMapInfos
|
||||||
*/
|
*/
|
||||||
public function updateMapObjectsWithManiaExchangeIds(array $mxMapInfos) {
|
public function updateMapObjectsWithManiaExchangeIds(array $mxMapInfos) {
|
||||||
|
if (!$this->enabled) return;
|
||||||
$mysqli = $this->maniaControl->getDatabase()->getMysqli();
|
$mysqli = $this->maniaControl->getDatabase()->getMysqli();
|
||||||
// Save map data
|
// Save map data
|
||||||
$saveMapQuery = "UPDATE `" . MapManager::TABLE_MAPS . "`
|
$saveMapQuery = "UPDATE `" . MapManager::TABLE_MAPS . "`
|
||||||
@ -269,6 +288,7 @@ class ManiaExchangeManager implements UsageInformationAble {
|
|||||||
* @param callable $function
|
* @param callable $function
|
||||||
*/
|
*/
|
||||||
public function fetchMapInfo($mapId, callable $function) {
|
public function fetchMapInfo($mapId, callable $function) {
|
||||||
|
if (!$this->enabled) return;
|
||||||
// For TM2020
|
// For TM2020
|
||||||
if ($this->maniaControl->getServer()->titleId == "Trackmania") {
|
if ($this->maniaControl->getServer()->titleId == "Trackmania") {
|
||||||
// Get Title Prefix
|
// Get Title Prefix
|
||||||
@ -335,6 +355,7 @@ class ManiaExchangeManager implements UsageInformationAble {
|
|||||||
* @see \ManiaControl\ManiaExchange\ManiaExchangeMapSearch
|
* @see \ManiaControl\ManiaExchange\ManiaExchangeMapSearch
|
||||||
*/
|
*/
|
||||||
public function fetchMapsAsync(callable $function, $name = '', $author = '', $env = '', $maxMapsReturned = 100, $sortOrder = ManiaExchangeMapSearch::SEARCH_ORDER_UPDATED_NEWEST) {
|
public function fetchMapsAsync(callable $function, $name = '', $author = '', $env = '', $maxMapsReturned = 100, $sortOrder = ManiaExchangeMapSearch::SEARCH_ORDER_UPDATED_NEWEST) {
|
||||||
|
if (!$this->enabled) return;
|
||||||
$mapSearch = new ManiaExchangeMapSearch($this->maniaControl);
|
$mapSearch = new ManiaExchangeMapSearch($this->maniaControl);
|
||||||
$mapSearch->setMapName($name);
|
$mapSearch->setMapName($name);
|
||||||
$mapSearch->setAuthorName($author);
|
$mapSearch->setAuthorName($author);
|
||||||
|
@ -140,6 +140,8 @@ class ManiaExchangeMapSearch implements UsageInformationAble {
|
|||||||
* @param callable $function
|
* @param callable $function
|
||||||
*/
|
*/
|
||||||
public function fetchMapsAsync(callable $function) {
|
public function fetchMapsAsync(callable $function) {
|
||||||
|
if (!$this->maniaControl->getMapManager()->getMXManager()->getStatus()) return;
|
||||||
|
|
||||||
// compile search URL
|
// compile search URL
|
||||||
$parameters = "";
|
$parameters = "";
|
||||||
|
|
||||||
|
@ -8,6 +8,7 @@ use FML\Controls\Quads\Quad_UIConstruction_Buttons;
|
|||||||
use ManiaControl\Admin\AuthenticationManager;
|
use ManiaControl\Admin\AuthenticationManager;
|
||||||
use ManiaControl\Callbacks\CallbackListener;
|
use ManiaControl\Callbacks\CallbackListener;
|
||||||
use ManiaControl\Callbacks\CallbackManager;
|
use ManiaControl\Callbacks\CallbackManager;
|
||||||
|
use ManiaControl\Callbacks\Callbacks;
|
||||||
use ManiaControl\Commands\CommandListener;
|
use ManiaControl\Commands\CommandListener;
|
||||||
use ManiaControl\Logger;
|
use ManiaControl\Logger;
|
||||||
use ManiaControl\ManiaControl;
|
use ManiaControl\ManiaControl;
|
||||||
@ -49,7 +50,6 @@ class MapCommands implements CommandListener, ManialinkPageAnswerListener, Callb
|
|||||||
*/
|
*/
|
||||||
public function __construct(ManiaControl $maniaControl) {
|
public function __construct(ManiaControl $maniaControl) {
|
||||||
$this->maniaControl = $maniaControl;
|
$this->maniaControl = $maniaControl;
|
||||||
$this->initActionsMenuButtons();
|
|
||||||
|
|
||||||
// Admin commands
|
// Admin commands
|
||||||
$this->maniaControl->getCommandManager()->registerCommandListener(array('nextmap', 'next', 'skip'), $this, 'command_NextMap', true, 'Skips to the next map.');
|
$this->maniaControl->getCommandManager()->registerCommandListener(array('nextmap', 'next', 'skip'), $this, 'command_NextMap', true, 'Skips to the next map.');
|
||||||
@ -68,6 +68,7 @@ class MapCommands implements CommandListener, ManialinkPageAnswerListener, Callb
|
|||||||
$this->maniaControl->getCommandManager()->registerCommandListener(array('xmaps', 'xlist'), $this, 'command_xList', false, 'Shows maps from ManiaExchange.');
|
$this->maniaControl->getCommandManager()->registerCommandListener(array('xmaps', 'xlist'), $this, 'command_xList', false, 'Shows maps from ManiaExchange.');
|
||||||
|
|
||||||
// Callbacks
|
// Callbacks
|
||||||
|
$this->maniaControl->getCallbackManager()->registerCallbackListener(Callbacks::AFTERINIT, $this, 'handleAfterInit');
|
||||||
$this->maniaControl->getCallbackManager()->registerCallbackListener(CallbackManager::CB_MP_PLAYERMANIALINKPAGEANSWER, $this, 'handleManialinkPageAnswer');
|
$this->maniaControl->getCallbackManager()->registerCallbackListener(CallbackManager::CB_MP_PLAYERMANIALINKPAGEANSWER, $this, 'handleManialinkPageAnswer');
|
||||||
$this->maniaControl->getManialinkManager()->registerManialinkPageAnswerListener(self::ACTION_OPEN_XLIST, $this, 'command_xList');
|
$this->maniaControl->getManialinkManager()->registerManialinkPageAnswerListener(self::ACTION_OPEN_XLIST, $this, 'command_xList');
|
||||||
$this->maniaControl->getManialinkManager()->registerManialinkPageAnswerListener(self::ACTION_OPEN_MAPLIST, $this, 'command_List');
|
$this->maniaControl->getManialinkManager()->registerManialinkPageAnswerListener(self::ACTION_OPEN_MAPLIST, $this, 'command_List');
|
||||||
@ -75,16 +76,22 @@ class MapCommands implements CommandListener, ManialinkPageAnswerListener, Callb
|
|||||||
$this->maniaControl->getManialinkManager()->registerManialinkPageAnswerListener(self::ACTION_SKIP_MAP, $this, 'command_NextMap');
|
$this->maniaControl->getManialinkManager()->registerManialinkPageAnswerListener(self::ACTION_SKIP_MAP, $this, 'command_NextMap');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function handleAfterInit() {
|
||||||
|
$this->initActionsMenuButtons();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add all Actions Menu Buttons
|
* Add all Actions Menu Buttons
|
||||||
*/
|
*/
|
||||||
private function initActionsMenuButtons() {
|
private function initActionsMenuButtons() {
|
||||||
// Menu Open xList
|
// Menu Open xList
|
||||||
$itemQuad = new Quad();
|
if ($this->maniaControl->getMapManager()->getMXManager()->getStatus()) {
|
||||||
$itemQuad->setImageUrl($this->maniaControl->getManialinkManager()->getIconManager()->getIcon(IconManager::MX_ICON));
|
$itemQuad = new Quad();
|
||||||
$itemQuad->setImageFocusUrl($this->maniaControl->getManialinkManager()->getIconManager()->getIcon(IconManager::MX_ICON_MOVER));
|
$itemQuad->setImageUrl($this->maniaControl->getManialinkManager()->getIconManager()->getIcon(IconManager::MX_ICON));
|
||||||
$itemQuad->setAction(self::ACTION_OPEN_XLIST);
|
$itemQuad->setImageFocusUrl($this->maniaControl->getManialinkManager()->getIconManager()->getIcon(IconManager::MX_ICON_MOVER));
|
||||||
$this->maniaControl->getActionsMenu()->addPlayerMenuItem($itemQuad, 5, 'Open MX List');
|
$itemQuad->setAction(self::ACTION_OPEN_XLIST);
|
||||||
|
$this->maniaControl->getActionsMenu()->addPlayerMenuItem($itemQuad, 5, 'Open MX List');
|
||||||
|
}
|
||||||
|
|
||||||
// Menu Open List
|
// Menu Open List
|
||||||
$itemQuad = new Quad_Icons64x64_1();
|
$itemQuad = new Quad_Icons64x64_1();
|
||||||
|
@ -19,6 +19,8 @@ use ManiaControl\ManiaExchange\ManiaExchangeList;
|
|||||||
use ManiaControl\ManiaExchange\ManiaExchangeManager;
|
use ManiaControl\ManiaExchange\ManiaExchangeManager;
|
||||||
use ManiaControl\ManiaExchange\MXMapInfo;
|
use ManiaControl\ManiaExchange\MXMapInfo;
|
||||||
use ManiaControl\Players\Player;
|
use ManiaControl\Players\Player;
|
||||||
|
use ManiaControl\Settings\Setting;
|
||||||
|
use ManiaControl\Settings\SettingManager;
|
||||||
use ManiaControl\Utils\Formatter;
|
use ManiaControl\Utils\Formatter;
|
||||||
use Maniaplanet\DedicatedServer\InvalidArgumentException;
|
use Maniaplanet\DedicatedServer\InvalidArgumentException;
|
||||||
use Maniaplanet\DedicatedServer\Xmlrpc\AlreadyInListException;
|
use Maniaplanet\DedicatedServer\Xmlrpc\AlreadyInListException;
|
||||||
@ -56,6 +58,7 @@ class MapManager implements CallbackListener, CommunicationListener, UsageInform
|
|||||||
const SETTING_AUTOSAVE_MAPLIST = 'Autosave Maplist file';
|
const SETTING_AUTOSAVE_MAPLIST = 'Autosave Maplist file';
|
||||||
const SETTING_MAPLIST_FILE = 'File to write Maplist in';
|
const SETTING_MAPLIST_FILE = 'File to write Maplist in';
|
||||||
const SETTING_WRITE_OWN_MAPLIST_FILE = 'Write a own Maplist File for every Server called serverlogin.txt';
|
const SETTING_WRITE_OWN_MAPLIST_FILE = 'Write a own Maplist File for every Server called serverlogin.txt';
|
||||||
|
const SETTING_ENABLE_MX = 'Enable MX features';
|
||||||
|
|
||||||
const SEARCH_BY_AUTHOR = 'Author';
|
const SEARCH_BY_AUTHOR = 'Author';
|
||||||
const SEARCH_BY_MAP_NAME = 'Mapname';
|
const SEARCH_BY_MAP_NAME = 'Mapname';
|
||||||
@ -116,6 +119,7 @@ class MapManager implements CallbackListener, CommunicationListener, UsageInform
|
|||||||
// Callbacks
|
// Callbacks
|
||||||
$this->maniaControl->getCallbackManager()->registerCallbackListener(Callbacks::ONINIT, $this, 'handleOnInit');
|
$this->maniaControl->getCallbackManager()->registerCallbackListener(Callbacks::ONINIT, $this, 'handleOnInit');
|
||||||
$this->maniaControl->getCallbackManager()->registerCallbackListener(Callbacks::AFTERINIT, $this, 'handleAfterInit');
|
$this->maniaControl->getCallbackManager()->registerCallbackListener(Callbacks::AFTERINIT, $this, 'handleAfterInit');
|
||||||
|
$this->maniaControl->getCallbackManager()->registerCallbackListener(SettingManager::CB_SETTING_CHANGED, $this, 'updateSettings');
|
||||||
$this->maniaControl->getCallbackManager()->registerCallbackListener(CallbackManager::CB_MP_MAPLISTMODIFIED, $this, 'mapsModified');
|
$this->maniaControl->getCallbackManager()->registerCallbackListener(CallbackManager::CB_MP_MAPLISTMODIFIED, $this, 'mapsModified');
|
||||||
|
|
||||||
// Permissions
|
// Permissions
|
||||||
@ -131,6 +135,9 @@ class MapManager implements CallbackListener, CommunicationListener, UsageInform
|
|||||||
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_AUTOSAVE_MAPLIST, true);
|
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_AUTOSAVE_MAPLIST, true);
|
||||||
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_MAPLIST_FILE, "MatchSettings/tracklist.txt");
|
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_MAPLIST_FILE, "MatchSettings/tracklist.txt");
|
||||||
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_WRITE_OWN_MAPLIST_FILE, false);
|
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_WRITE_OWN_MAPLIST_FILE, false);
|
||||||
|
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_ENABLE_MX, true);
|
||||||
|
|
||||||
|
$this->mxManager->setStatus($this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_ENABLE_MX, true));
|
||||||
|
|
||||||
//Initlaize Communication Listenings
|
//Initlaize Communication Listenings
|
||||||
$this->initalizeCommunicationListenings();
|
$this->initalizeCommunicationListenings();
|
||||||
@ -213,6 +220,19 @@ class MapManager implements CallbackListener, CommunicationListener, UsageInform
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update Settings
|
||||||
|
*
|
||||||
|
* @param ?Setting $setting
|
||||||
|
*/
|
||||||
|
public function updateSettings(Setting $setting = null) {
|
||||||
|
if (!isset($setting) || !$setting->belongsToClass($this)) return;
|
||||||
|
|
||||||
|
if ($setting->setting === self::SETTING_ENABLE_MX) {
|
||||||
|
$this->mxManager->setStatus($this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_ENABLE_MX, true));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update the Timestamp of a Map
|
* Update the Timestamp of a Map
|
||||||
*
|
*
|
||||||
|
Loading…
Reference in New Issue
Block a user