small fixes

This commit is contained in:
kremsy 2014-01-08 18:07:09 +01:00
parent 6d2aa1b487
commit a7212c13c5
2 changed files with 199 additions and 210 deletions

View File

@ -34,15 +34,15 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
/** /**
* Constants * Constants
*/ */
const ACTION_ADD_MAP = 'MapList.AddMap'; const ACTION_ADD_MAP = 'MapList.AddMap';
const ACTION_ERASE_MAP = 'MapList.EraseMap'; const ACTION_ERASE_MAP = 'MapList.EraseMap';
const ACTION_SWITCH_MAP = 'MapList.SwitchMap'; const ACTION_SWITCH_MAP = 'MapList.SwitchMap';
const ACTION_QUEUED_MAP = 'MapList.QueueMap'; const ACTION_QUEUED_MAP = 'MapList.QueueMap';
const MAX_MAPS_PER_PAGE = 15; const MAX_MAPS_PER_PAGE = 15;
const SHOW_MX_LIST = 1; const SHOW_MX_LIST = 1;
const SHOW_MAP_LIST = 2; const SHOW_MAP_LIST = 2;
const DEFAULT_KARMA_PLUGIN = 'KarmaPlugin'; const DEFAULT_KARMA_PLUGIN = 'KarmaPlugin';
/** /**
* Private Properties * Private Properties
*/ */
@ -56,11 +56,10 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
*/ */
public function __construct(ManiaControl $maniaControl) { public function __construct(ManiaControl $maniaControl) {
$this->maniaControl = $maniaControl; $this->maniaControl = $maniaControl;
// Register for Callbacks // Register for Callbacks
$this->maniaControl->callbackManager->registerCallbackListener(ManialinkManager::CB_MAIN_WINDOW_CLOSED, $this, 'closeWidget'); $this->maniaControl->callbackManager->registerCallbackListener(ManialinkManager::CB_MAIN_WINDOW_CLOSED, $this, 'closeWidget');
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MP_PLAYERMANIALINKPAGEANSWER, $this, $this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MP_PLAYERMANIALINKPAGEANSWER, $this, 'handleManialinkPageAnswer');
'handleManialinkPageAnswer');
$this->maniaControl->callbackManager->registerCallbackListener(MapQueue::CB_MAPQUEUE_CHANGED, $this, 'updateWidget'); $this->maniaControl->callbackManager->registerCallbackListener(MapQueue::CB_MAPQUEUE_CHANGED, $this, 'updateWidget');
$this->maniaControl->callbackManager->registerCallbackListener(MapManager::CB_MAPS_UPDATED, $this, 'updateWidget'); $this->maniaControl->callbackManager->registerCallbackListener(MapManager::CB_MAPS_UPDATED, $this, 'updateWidget');
$this->maniaControl->callbackManager->registerCallbackListener(MapManager::CB_KARMA_UPDATED, $this, 'updateWidget'); $this->maniaControl->callbackManager->registerCallbackListener(MapManager::CB_KARMA_UPDATED, $this, 'updateWidget');
@ -71,90 +70,87 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
/** /**
* Display the Mania Exchange List * Display the Mania Exchange List
* *
* @param array $chatCallback * @param array $chatCallback
* @param Player $player * @param Player $player
*/ */
public function showManiaExchangeList(array $chatCallback, Player $player) { public function showManiaExchangeList(array $chatCallback, Player $player) {
$this->mapListShown[$player->login] = self::SHOW_MX_LIST; $this->mapListShown[$player->login] = self::SHOW_MX_LIST;
$params = explode(' ', $chatCallback[1][2]); $params = explode(' ', $chatCallback[1][2]);
$serverInfo = $this->maniaControl->server->getSystemInfo(); $serverInfo = $this->maniaControl->server->getSystemInfo();
$title = strtoupper(substr($serverInfo['TitleId'], 0, 2)); $title = strtoupper(substr($serverInfo['TitleId'], 0, 2));
$mapName = ''; $mapName = '';
$author = ''; $author = '';
$environment = ''; $environment = '';
// TODO also get actual environment // TODO also get actual environment
$recent = true; $recent = true;
if (count($params) > 1) { if(count($params) > 1) {
foreach ($params as $param) { foreach($params as $param) {
if ($param == '/xlist') { if($param == '/xlist') {
continue; continue;
} }
if (strtolower(substr($param, 0, 5)) == 'auth:') { if(strtolower(substr($param, 0, 5)) == 'auth:') {
$author = substr($param, 5); $author = substr($param, 5);
} } elseif(strtolower(substr($param, 0, 4)) == 'env:') {
elseif (strtolower(substr($param, 0, 4)) == 'env:') {
$environment = substr($param, 4); $environment = substr($param, 4);
} } else {
else { if($mapName == '') {
if ($mapName == '') {
$mapName = $param; $mapName = $param;
} } else { // concatenate words in name
else { // concatenate words in name
$mapName .= '%20' . $param; $mapName .= '%20' . $param;
} }
} }
} }
$recent = false; $recent = false;
} }
// search for matching maps // search for matching maps
$maps = new MXInfoSearcher($title, $mapName, $author, $environment, $recent); $maps = new MXInfoSearcher($title, $mapName, $author, $environment, $recent);
// check if there are any results // check if there are any results
if (!$maps->valid()) { if(!$maps->valid()) {
$this->maniaControl->chat->sendError('No maps found, or MX is down!', $player->login); $this->maniaControl->chat->sendError('No maps found, or MX is down!', $player->login);
if ($maps->error != '') { if($maps->error != '') {
trigger_error($maps->error, E_USER_WARNING); trigger_error($maps->error, E_USER_WARNING);
} }
return; return;
} }
$maniaLink = new ManiaLink(ManialinkManager::MAIN_MLID); $maniaLink = new ManiaLink(ManialinkManager::MAIN_MLID);
$frame = $this->buildMainFrame(); $frame = $this->buildMainFrame();
$maniaLink->add($frame); $maniaLink->add($frame);
// Create script and features // Create script and features
$script = new Script(); $script = new Script();
$maniaLink->setScript($script); $maniaLink->setScript($script);
// Start offsets // Start offsets
$width = $this->maniaControl->manialinkManager->styleManager->getListWidgetsWidth(); $width = $this->maniaControl->manialinkManager->styleManager->getListWidgetsWidth();
$height = $this->maniaControl->manialinkManager->styleManager->getListWidgetsHeight(); $height = $this->maniaControl->manialinkManager->styleManager->getListWidgetsHeight();
$x = -$width / 2; $x = -$width / 2;
$y = $height / 2; $y = $height / 2;
// Headline // Headline
$headFrame = new Frame(); $headFrame = new Frame();
$frame->add($headFrame); $frame->add($headFrame);
$headFrame->setY($y - 5); $headFrame->setY($y - 5);
$array = array('Id' => $x + 5, 'Name' => $x + 17, 'Author' => $x + 65, 'Mood' => $x + 100, 'Type' => $x + 115); $array = array('Id' => $x + 5, 'Name' => $x + 17, 'Author' => $x + 65, 'Mood' => $x + 100, 'Type' => $x + 115);
$this->maniaControl->manialinkManager->labelLine($headFrame, $array); $this->maniaControl->manialinkManager->labelLine($headFrame, $array);
$i = 0; $i = 0;
$y -= 10; $y -= 10;
foreach ($maps as $map) { foreach($maps as $map) {
$mapFrame = new Frame(); $mapFrame = new Frame();
$frame->add($mapFrame); $frame->add($mapFrame);
$array = array($map->id => $x + 5, $map->name => $x + 17, $map->author => $x + 65, $map->mood => $x + 100, $map->maptype => $x + 115); $array = array($map->id => $x + 5, $map->name => $x + 17, $map->author => $x + 65, $map->mood => $x + 100, $map->maptype => $x + 115);
$this->maniaControl->manialinkManager->labelLine($mapFrame, $array); $this->maniaControl->manialinkManager->labelLine($mapFrame, $array);
$mapFrame->setY($y); $mapFrame->setY($y);
if ($this->maniaControl->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_ADMIN)) { if($this->maniaControl->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_ADMIN)) {
// TODO: SET as setting who can add maps Add-Map-Button // TODO: SET as setting who can add maps Add-Map-Button
$addQuad = new Quad_Icons64x64_1(); $addQuad = new Quad_Icons64x64_1();
$mapFrame->add($addQuad); $mapFrame->add($addQuad);
@ -163,7 +159,7 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
$addQuad->setSubStyle($addQuad::SUBSTYLE_Add); $addQuad->setSubStyle($addQuad::SUBSTYLE_Add);
$addQuad->setSize(4, 4); $addQuad->setSize(4, 4);
$addQuad->setAction(self::ACTION_ADD_MAP . '.' . $map->id); $addQuad->setAction(self::ACTION_ADD_MAP . '.' . $map->id);
// Description Label // Description Label
$descriptionLabel = new Label(); $descriptionLabel = new Label();
$frame->add($descriptionLabel); $frame->add($descriptionLabel);
@ -175,16 +171,16 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
$descriptionLabel->setText('Add-Map: $<' . Formatter::stripDirtyCodes($map->name) . '$>'); $descriptionLabel->setText('Add-Map: $<' . Formatter::stripDirtyCodes($map->name) . '$>');
$script->addTooltip($addQuad, $descriptionLabel); $script->addTooltip($addQuad, $descriptionLabel);
} }
$y -= 4; $y -= 4;
$i++; $i++;
if ($i == self::MAX_MAPS_PER_PAGE) { if($i == self::MAX_MAPS_PER_PAGE) {
break; break;
} }
} }
// TODO add MX info screen // TODO add MX info screen
// render and display xml // render and display xml
$this->maniaControl->manialinkManager->displayWidget($maniaLink, $player); $this->maniaControl->manialinkManager->displayWidget($maniaLink, $player);
} }
@ -195,22 +191,22 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
* @return Frame $frame * @return Frame $frame
*/ */
public function buildMainFrame() { public function buildMainFrame() {
$width = $this->maniaControl->manialinkManager->styleManager->getListWidgetsWidth(); $width = $this->maniaControl->manialinkManager->styleManager->getListWidgetsWidth();
$height = $this->maniaControl->manialinkManager->styleManager->getListWidgetsHeight(); $height = $this->maniaControl->manialinkManager->styleManager->getListWidgetsHeight();
$quadStyle = $this->maniaControl->manialinkManager->styleManager->getDefaultMainWindowStyle(); $quadStyle = $this->maniaControl->manialinkManager->styleManager->getDefaultMainWindowStyle();
$quadSubstyle = $this->maniaControl->manialinkManager->styleManager->getDefaultMainWindowSubStyle(); $quadSubstyle = $this->maniaControl->manialinkManager->styleManager->getDefaultMainWindowSubStyle();
// mainframe // mainframe
$frame = new Frame(); $frame = new Frame();
$frame->setSize($width, $height); $frame->setSize($width, $height);
$frame->setPosition(0, 0); $frame->setPosition(0, 0);
// Background Quad // Background Quad
$backgroundQuad = new Quad(); $backgroundQuad = new Quad();
$frame->add($backgroundQuad); $frame->add($backgroundQuad);
$backgroundQuad->setSize($width, $height); $backgroundQuad->setSize($width, $height);
$backgroundQuad->setStyles($quadStyle, $quadSubstyle); $backgroundQuad->setStyles($quadStyle, $quadSubstyle);
// Add Close Quad (X) // Add Close Quad (X)
$closeQuad = new Quad_Icons64x64_1(); $closeQuad = new Quad_Icons64x64_1();
$frame->add($closeQuad); $frame->add($closeQuad);
@ -218,7 +214,7 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
$closeQuad->setSize(6, 6); $closeQuad->setSize(6, 6);
$closeQuad->setSubStyle(Quad_Icons64x64_1::SUBSTYLE_QuitRace); $closeQuad->setSubStyle(Quad_Icons64x64_1::SUBSTYLE_QuitRace);
$closeQuad->setAction(ManialinkManager::ACTION_CLOSEWIDGET); $closeQuad->setAction(ManialinkManager::ACTION_CLOSEWIDGET);
return $frame; return $frame;
} }
@ -228,44 +224,44 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
* @param Player $player * @param Player $player
*/ */
public function showMapList(Player $player) { public function showMapList(Player $player) {
$width = $this->maniaControl->manialinkManager->styleManager->getListWidgetsWidth(); $width = $this->maniaControl->manialinkManager->styleManager->getListWidgetsWidth();
$height = $this->maniaControl->manialinkManager->styleManager->getListWidgetsHeight(); $height = $this->maniaControl->manialinkManager->styleManager->getListWidgetsHeight();
// Get Maplist // Get Maplist
$mapList = $this->maniaControl->mapManager->getMaps(); $mapList = $this->maniaControl->mapManager->getMaps();
$this->mapListShown[$player->login] = self::SHOW_MAP_LIST; $this->mapListShown[$player->login] = self::SHOW_MAP_LIST;
$maniaLink = new ManiaLink(ManialinkManager::MAIN_MLID); $maniaLink = new ManiaLink(ManialinkManager::MAIN_MLID);
$frame = $this->buildMainFrame(); $frame = $this->buildMainFrame();
$maniaLink->add($frame); $maniaLink->add($frame);
// Create script and features // Create script and features
$script = new Script(); $script = new Script();
$maniaLink->setScript($script); $maniaLink->setScript($script);
// Pagers // Pagers
// Config // Config
$pagerSize = 6.; $pagerSize = 6.;
$pagesId = 'MapListPages'; $pagesId = 'MapListPages';
if (count($mapList) > self::MAX_MAPS_PER_PAGE) { if(count($mapList) > self::MAX_MAPS_PER_PAGE) {
$pagerPrev = new Quad_Icons64x64_1(); $pagerPrev = new Quad_Icons64x64_1();
$frame->add($pagerPrev); $frame->add($pagerPrev);
$pagerPrev->setPosition($width * 0.42, $height * -0.44, 2); $pagerPrev->setPosition($width * 0.42, $height * -0.44, 2);
$pagerPrev->setSize($pagerSize, $pagerSize); $pagerPrev->setSize($pagerSize, $pagerSize);
$pagerPrev->setSubStyle(Quad_Icons64x64_1::SUBSTYLE_ArrowPrev); $pagerPrev->setSubStyle(Quad_Icons64x64_1::SUBSTYLE_ArrowPrev);
$pagerNext = new Quad_Icons64x64_1(); $pagerNext = new Quad_Icons64x64_1();
$frame->add($pagerNext); $frame->add($pagerNext);
$pagerNext->setPosition($width * 0.45, $height * -0.44, 2); $pagerNext->setPosition($width * 0.45, $height * -0.44, 2);
$pagerNext->setSize($pagerSize, $pagerSize); $pagerNext->setSize($pagerSize, $pagerSize);
$pagerNext->setSubStyle(Quad_Icons64x64_1::SUBSTYLE_ArrowNext); $pagerNext->setSubStyle(Quad_Icons64x64_1::SUBSTYLE_ArrowNext);
$script->addPager($pagerPrev, -1, $pagesId); $script->addPager($pagerPrev, -1, $pagesId);
$script->addPager($pagerNext, 1, $pagesId); $script->addPager($pagerNext, 1, $pagesId);
$pageCountLabel = new Label_Text(); $pageCountLabel = new Label_Text();
$frame->add($pageCountLabel); $frame->add($pageCountLabel);
$pageCountLabel->setHAlign(Control::RIGHT); $pageCountLabel->setHAlign(Control::RIGHT);
@ -274,16 +270,15 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
$pageCountLabel->setTextSize(1.3); $pageCountLabel->setTextSize(1.3);
$script->addPageLabel($pageCountLabel, $pagesId); $script->addPageLabel($pageCountLabel, $pagesId);
} }
// Headline // Headline
$headFrame = new Frame(); $headFrame = new Frame();
$frame->add($headFrame); $frame->add($headFrame);
$headFrame->setY($height / 2 - 5); $headFrame->setY($height / 2 - 5);
$x = -$width / 2; $x = -$width / 2;
$array = array('Id' => $x + 5, 'Mx Id' => $x + 10, 'Map Name' => $x + 20, 'Author' => $x + 68, 'Karma' => $x + 115, $array = array('Id' => $x + 5, 'Mx Id' => $x + 10, 'Map Name' => $x + 20, 'Author' => $x + 68, 'Karma' => $x + 115, 'Actions' => $width / 2 - 15);
'Actions' => $width / 2 - 15);
$this->maniaControl->manialinkManager->labelLine($headFrame, $array); $this->maniaControl->manialinkManager->labelLine($headFrame, $array);
// Predefine Description Label // Predefine Description Label
$preDefinedDescriptionLabel = new Label(); $preDefinedDescriptionLabel = new Label();
$preDefinedDescriptionLabel->setAlign(Control::LEFT, Control::TOP); $preDefinedDescriptionLabel->setAlign(Control::LEFT, Control::TOP);
@ -291,49 +286,49 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
$preDefinedDescriptionLabel->setSize($width * 0.7, 4); $preDefinedDescriptionLabel->setSize($width * 0.7, 4);
$preDefinedDescriptionLabel->setTextSize(2); $preDefinedDescriptionLabel->setTextSize(2);
$preDefinedDescriptionLabel->setVisible(false); $preDefinedDescriptionLabel->setVisible(false);
$queuedMaps = $this->maniaControl->mapManager->mapQueue->getQueuedMapsRanking(); $queuedMaps = $this->maniaControl->mapManager->mapQueue->getQueuedMapsRanking();
/** /**
* *
* @var KarmaPlugin $karmaPlugin * @var KarmaPlugin $karmaPlugin
*/ */
$karmaPlugin = $this->maniaControl->pluginManager->getPlugin(self::DEFAULT_KARMA_PLUGIN); $karmaPlugin = $this->maniaControl->pluginManager->getPlugin(self::DEFAULT_KARMA_PLUGIN);
$id = 1; $id = 1;
$y = $height / 2 - 10; $y = $height / 2 - 10;
$pageFrames = array(); $pageFrames = array();
/** /**
* *
* @var Map $map * @var Map $map
*/ */
foreach ($mapList as $map) { foreach($mapList as $map) {
if (!isset($pageFrame)) { if(!isset($pageFrame)) {
$pageFrame = new Frame(); $pageFrame = new Frame();
$frame->add($pageFrame); $frame->add($pageFrame);
if (!empty($pageFrames)) { if(!empty($pageFrames)) {
$pageFrame->setVisible(false); $pageFrame->setVisible(false);
} }
array_push($pageFrames, $pageFrame); array_push($pageFrames, $pageFrame);
$y = $height / 2 - 10; $y = $height / 2 - 10;
$script->addPage($pageFrame, count($pageFrames), $pagesId); $script->addPage($pageFrame, count($pageFrames), $pagesId);
} }
// Map Frame // Map Frame
$mapFrame = new Frame(); $mapFrame = new Frame();
$pageFrame->add($mapFrame); $pageFrame->add($mapFrame);
$mapFrame->setZ(0.1); $mapFrame->setZ(0.1);
$mapFrame->setY($y); $mapFrame->setY($y);
if ($id % 2 != 0) { if($id % 2 != 0) {
$lineQuad = new Quad_BgsPlayerCard(); $lineQuad = new Quad_BgsPlayerCard();
$mapFrame->add($lineQuad); $mapFrame->add($lineQuad);
$lineQuad->setSize($width, 4); $lineQuad->setSize($width, 4);
$lineQuad->setSubStyle($lineQuad::SUBSTYLE_BgPlayerCardBig); $lineQuad->setSubStyle($lineQuad::SUBSTYLE_BgPlayerCardBig);
$lineQuad->setZ(0.001); $lineQuad->setZ(0.001);
} }
if ($this->maniaControl->mapManager->getCurrentMap() === $map) { if($this->maniaControl->mapManager->getCurrentMap() === $map) {
$currentQuad = new Quad_Icons64x64_1(); $currentQuad = new Quad_Icons64x64_1();
$mapFrame->add($currentQuad); $mapFrame->add($currentQuad);
$currentQuad->setX($x + 3.5); $currentQuad->setX($x + 3.5);
@ -341,24 +336,24 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
$currentQuad->setSize(4, 4); $currentQuad->setSize(4, 4);
$currentQuad->setSubStyle($currentQuad::SUBSTYLE_ArrowBlue); $currentQuad->setSubStyle($currentQuad::SUBSTYLE_ArrowBlue);
} }
$mxId = '-'; $mxId = '-';
if (isset($map->mx->id)) { if(isset($map->mx->id)) {
$mxId = $map->mx->id; $mxId = $map->mx->id;
} }
// Display Maps // Display Maps
$array = array($id => $x + 5, $mxId => $x + 10, Formatter::stripDirtyCodes($map->name) => $x + 20, $map->authorNick => $x + 68); $array = array($id => $x + 5, $mxId => $x + 10, Formatter::stripDirtyCodes($map->name) => $x + 20, $map->authorNick => $x + 68);
$this->maniaControl->manialinkManager->labelLine($mapFrame, $array); $this->maniaControl->manialinkManager->labelLine($mapFrame, $array);
// TODO detailed mx info page with link to mxo // TODO detailed mx info page with link to mxo
// TODO action detailed map info // TODO action detailed map info
// MapQueue Description Label // MapQueue Description Label
$descriptionLabel = clone $preDefinedDescriptionLabel; $descriptionLabel = clone $preDefinedDescriptionLabel;
$frame->add($descriptionLabel); $frame->add($descriptionLabel);
// Map-Queue-Map-Label // Map-Queue-Map-Label
if (isset($queuedMaps[$map->uid])) { if(isset($queuedMaps[$map->uid])) {
$label = new Label_Text(); $label = new Label_Text();
$mapFrame->add($label); $mapFrame->add($label);
$label->setX($width / 2 - 15); $label->setX($width / 2 - 15);
@ -368,8 +363,7 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
$label->setText($queuedMaps[$map->uid]); $label->setText($queuedMaps[$map->uid]);
$label->setTextColor('fff'); $label->setTextColor('fff');
$descriptionLabel->setText('$<' . $map->name . '$> is on Map-Queue Position: ' . $queuedMaps[$map->uid]); $descriptionLabel->setText('$<' . $map->name . '$> is on Map-Queue Position: ' . $queuedMaps[$map->uid]);
} } else {
else {
// Map-Queue-Map-Button // Map-Queue-Map-Button
$queueLabel = new Label_Button(); $queueLabel = new Label_Button();
$mapFrame->add($queueLabel); $mapFrame->add($queueLabel);
@ -379,12 +373,12 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
$queueLabel->setAction(self::ACTION_QUEUED_MAP . '.' . $map->uid); $queueLabel->setAction(self::ACTION_QUEUED_MAP . '.' . $map->uid);
$queueLabel->setText('+'); $queueLabel->setText('+');
$queueLabel->setTextColor('09f'); $queueLabel->setTextColor('09f');
$descriptionLabel->setText('Add Map to the Map Queue: $<' . $map->name . '$>'); $descriptionLabel->setText('Add Map to the Map Queue: $<' . $map->name . '$>');
$script->addTooltip($queueLabel, $descriptionLabel); $script->addTooltip($queueLabel, $descriptionLabel);
} }
if ($this->maniaControl->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_ADMIN)) { if($this->maniaControl->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_ADMIN)) {
// TODO SET as setting who can add maps // TODO SET as setting who can add maps
// erase map quad // erase map quad
$eraseLabel = new Label_Button(); $eraseLabel = new Label_Button();
@ -395,19 +389,19 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
$eraseLabel->setTextSize(1); $eraseLabel->setTextSize(1);
$eraseLabel->setText('x'); $eraseLabel->setText('x');
$eraseLabel->setTextColor('a00'); $eraseLabel->setTextColor('a00');
$confirmFrame = $this->buildConfirmFrame($maniaLink, $y, $id, $map->uid); $confirmFrame = $this->buildConfirmFrame($maniaLink, $y, $id, $map->uid);
//$script->addToggle($eraseLabel, $confirmFrame); //TODO //$script->addToggle($eraseLabel, $confirmFrame); //TODO
$script->addTooltip($eraseLabel, $confirmFrame, Script::OPTION_TOOLTIP_STAYONCLICK); $script->addTooltip($eraseLabel, $confirmFrame, Script::OPTION_TOOLTIP_STAYONCLICK);
// Description Label // Description Label
$descriptionLabel = clone $preDefinedDescriptionLabel; $descriptionLabel = clone $preDefinedDescriptionLabel;
$frame->add($descriptionLabel); $frame->add($descriptionLabel);
$descriptionLabel->setText('Remove Map: $<' . $map->name . '$>'); $descriptionLabel->setText('Remove Map: $<' . $map->name . '$>');
$script->addTooltip($eraseLabel, $descriptionLabel); $script->addTooltip($eraseLabel, $descriptionLabel);
} }
if ($this->maniaControl->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_MODERATOR)) { if($this->maniaControl->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_MODERATOR)) {
// TODO SET as setting who can add maps // TODO SET as setting who can add maps
// Switch to map // Switch to map
$switchLabel = new Label_Button(); $switchLabel = new Label_Button();
@ -418,22 +412,22 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
$switchLabel->setTextSize(2); $switchLabel->setTextSize(2);
$switchLabel->setText('»'); $switchLabel->setText('»');
$switchLabel->setTextColor('0f0'); $switchLabel->setTextColor('0f0');
$confirmFrame = $this->buildConfirmFrame($maniaLink, $y, $id); $confirmFrame = $this->buildConfirmFrame($maniaLink, $y, $id);
$script->addTooltip($switchLabel, $confirmFrame, Script::OPTION_TOOLTIP_STAYONCLICK); //TODO $script->addTooltip($switchLabel, $confirmFrame, Script::OPTION_TOOLTIP_STAYONCLICK); //TODO
//$script->addToggle($switchLabel, $confirmFrame); //$script->addToggle($switchLabel, $confirmFrame);
$descriptionLabel = clone $preDefinedDescriptionLabel; $descriptionLabel = clone $preDefinedDescriptionLabel;
$frame->add($descriptionLabel); $frame->add($descriptionLabel);
$descriptionLabel->setText('Switch Directly to Map: $<' . $map->name . '$>'); $descriptionLabel->setText('Switch Directly to Map: $<' . $map->name . '$>');
$script->addTooltip($switchLabel, $descriptionLabel); $script->addTooltip($switchLabel, $descriptionLabel);
} }
// Display Karma bar // Display Karma bar
if ($karmaPlugin) { if($karmaPlugin) {
$karma = $karmaPlugin->getMapKarma($map); $karma = $karmaPlugin->getMapKarma($map);
$votes = $karmaPlugin->getMapVotes($map); $votes = $karmaPlugin->getMapVotes($map);
if (is_numeric($karma)) { if(is_numeric($karma)) {
$karmaGauge = new Gauge(); $karmaGauge = new Gauge();
$mapFrame->add($karmaGauge); $mapFrame->add($karmaGauge);
$karmaGauge->setZ(2); $karmaGauge->setZ(2);
@ -444,7 +438,7 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
$karmaGauge->setRatio($karma + 0.15 - $karma * 0.15); $karmaGauge->setRatio($karma + 0.15 - $karma * 0.15);
$karmaColor = ColorUtil::floatToStatusColor($karma); $karmaColor = ColorUtil::floatToStatusColor($karma);
$karmaGauge->setColor($karmaColor . '9'); $karmaGauge->setColor($karmaColor . '9');
$karmaLabel = new Label(); $karmaLabel = new Label();
$mapFrame->add($karmaLabel); $mapFrame->add($karmaLabel);
$karmaLabel->setZ(2); $karmaLabel->setZ(2);
@ -456,14 +450,13 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
$karmaLabel->setText(' ' . round($karma * 100.) . '% (' . $votes['count'] . ')'); $karmaLabel->setText(' ' . round($karma * 100.) . '% (' . $votes['count'] . ')');
} }
} }
$y -= 4; $y -= 4;
if ($id % self::MAX_MAPS_PER_PAGE == 0) { if($id % self::MAX_MAPS_PER_PAGE == 0) {
unset($pageFrame); unset($pageFrame);
} }
$id++; $id++;
} }
// TODO page 0 bug?
$this->maniaControl->manialinkManager->displayWidget($maniaLink, $player); $this->maniaControl->manialinkManager->displayWidget($maniaLink, $player);
} }
@ -471,30 +464,30 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
* Builds the confirmation frame * Builds the confirmation frame
* *
* @param ManiaLink $maniaLink * @param ManiaLink $maniaLink
* @param $y * @param $y
* @param $id * @param $id
* @param bool $mapUid * @param bool $mapUid
* @return Frame * @return Frame
*/ */
public function buildConfirmFrame(Manialink $maniaLink, $y, $id, $mapUid = false) { public function buildConfirmFrame(Manialink $maniaLink, $y, $id, $mapUid = false) {
$width = $this->maniaControl->manialinkManager->styleManager->getListWidgetsWidth(); $width = $this->maniaControl->manialinkManager->styleManager->getListWidgetsWidth();
$quadStyle = $this->maniaControl->manialinkManager->styleManager->getDefaultMainWindowStyle(); $quadStyle = $this->maniaControl->manialinkManager->styleManager->getDefaultMainWindowStyle();
$quadSubstyle = $this->maniaControl->manialinkManager->styleManager->getDefaultMainWindowSubStyle(); $quadSubstyle = $this->maniaControl->manialinkManager->styleManager->getDefaultMainWindowSubStyle();
$confirmFrame = new Frame(); $confirmFrame = new Frame();
$maniaLink->add($confirmFrame); $maniaLink->add($confirmFrame);
$confirmFrame->setPosition($width / 2 + 6, $y); $confirmFrame->setPosition($width / 2 + 6, $y);
$quad = new Quad(); $quad = new Quad();
$confirmFrame->add($quad); $confirmFrame->add($quad);
$quad->setStyles($quadStyle, $quadSubstyle); $quad->setStyles($quadStyle, $quadSubstyle);
$quad->setSize(12, 4); $quad->setSize(12, 4);
$quad = new Quad_BgsPlayerCard(); $quad = new Quad_BgsPlayerCard();
$confirmFrame->add($quad); $confirmFrame->add($quad);
$quad->setSubStyle($quad::SUBSTYLE_BgCardSystem); $quad->setSubStyle($quad::SUBSTYLE_BgCardSystem);
$quad->setSize(11, 3.5); $quad->setSize(11, 3.5);
$label = new Label_Button(); $label = new Label_Button();
$confirmFrame->add($label); $confirmFrame->add($label);
$label->setAlign(Control::CENTER, Control::CENTER); $label->setAlign(Control::CENTER, Control::CENTER);
@ -502,21 +495,20 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
$label->setTextSize(1); $label->setTextSize(1);
$label->setScale(0.90); $label->setScale(0.90);
$label->setX(-1.3); $label->setX(-1.3);
$buttLabel = new Label_Button(); $buttLabel = new Label_Button();
$confirmFrame->add($buttLabel); $confirmFrame->add($buttLabel);
$buttLabel->setPosition(3.2, 0.4, 0.2); $buttLabel->setPosition(3.2, 0.4, 0.2);
$buttLabel->setSize(3, 3); $buttLabel->setSize(3, 3);
// $buttLabel->setTextSize(1); // $buttLabel->setTextSize(1);
$buttLabel->setAlign(Control::CENTER, Control::CENTER); $buttLabel->setAlign(Control::CENTER, Control::CENTER);
if (!$mapUid) { if(!$mapUid) {
$quad->setAction(self::ACTION_SWITCH_MAP . '.' . ($id - 1)); $quad->setAction(self::ACTION_SWITCH_MAP . '.' . ($id - 1));
$buttLabel->setText('»'); $buttLabel->setText('»');
$buttLabel->setTextColor('0f0'); $buttLabel->setTextColor('0f0');
$buttLabel->setTextSize(2); $buttLabel->setTextSize(2);
} } else {
else {
$buttLabel->setTextSize(1); $buttLabel->setTextSize(1);
$buttLabel->setText('x'); $buttLabel->setText('x');
$buttLabel->setTextColor('a00'); $buttLabel->setTextColor('a00');
@ -551,32 +543,34 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
* @param array $callback * @param array $callback
*/ */
public function handleManialinkPageAnswer(array $callback) { public function handleManialinkPageAnswer(array $callback) {
$actionId = $callback[1][2]; $actionId = $callback[1][2];
$actionArray = explode('.', $actionId); $actionArray = explode('.', $actionId);
if (count($actionArray) <= 2) return; if(count($actionArray) <= 2) {
return;
}
$action = $actionArray[0] . '.' . $actionArray[1]; $action = $actionArray[0] . '.' . $actionArray[1];
$login = $callback[1][1]; $login = $callback[1][1];
$player = $this->maniaControl->playerManager->getPlayer($login); $player = $this->maniaControl->playerManager->getPlayer($login);
$mapId = (int) $actionArray[2]; $mapId = (int)$actionArray[2];
switch ($action) { switch($action) {
case self::ACTION_ADD_MAP: case self::ACTION_ADD_MAP:
$this->maniaControl->mapManager->addMapFromMx($mapId, $player->login); $this->maniaControl->mapManager->addMapFromMx($mapId, $player->login);
break; break;
case self::ACTION_ERASE_MAP: case self::ACTION_ERASE_MAP:
$this->maniaControl->mapManager->eraseMap($mapId, $actionArray[3]); $this->maniaControl->mapManager->removeMap($mapId, $actionArray[3]);
$this->showMapList($player); $this->showMapList($player);
break; break;
case self::ACTION_SWITCH_MAP: case self::ACTION_SWITCH_MAP:
$this->maniaControl->client->query('JumpToMapIndex', $mapId); $this->maniaControl->client->query('JumpToMapIndex', $mapId);
$mapList = $this->maniaControl->mapManager->getMapList(); $mapList = $this->maniaControl->mapManager->getMaps();
$map = $mapList[$mapId]; $map = $mapList[$mapId];
$message = '$<' . $player->nickname . '$> skipped to Map $z$<' . $map->name . '$>!'; $message = '$<' . $player->nickname . '$> skipped to Map $z$<' . $map->name . '$>!';
$this->maniaControl->chat->sendSuccess($message); $this->maniaControl->chat->sendSuccess($message);
$this->maniaControl->log($message, true); $this->maniaControl->log($message, true);
$this->playerCloseWidget($player); $this->playerCloseWidget($player);
break; break;
case self::ACTION_QUEUED_MAP: case self::ACTION_QUEUED_MAP:
@ -591,18 +585,16 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
* @param array $callback * @param array $callback
*/ */
public function updateWidget(array $callback) { public function updateWidget(array $callback) {
foreach ($this->mapListShown as $login => $shown) { foreach($this->mapListShown as $login => $shown) {
if ($shown) { if($shown) {
$player = $this->maniaControl->playerManager->getPlayer($login); $player = $this->maniaControl->playerManager->getPlayer($login);
if ($player != null) { if($player != null) {
if ($shown == self::SHOW_MX_LIST) { if($shown == self::SHOW_MX_LIST) {
// TODO //TODO
} } else if($shown == self::SHOW_MAP_LIST) {
else if ($shown == self::SHOW_MAP_LIST) {
$this->showMapList($player); $this->showMapList($player);
} }
} } else {
else {
unset($this->mapListShown[$login]); unset($this->mapListShown[$login]);
} }
} }

View File

@ -2,11 +2,10 @@
namespace ManiaControl\Maps; namespace ManiaControl\Maps;
use ManiaControl\FileUtil;
use ManiaControl\Formatter;
use ManiaControl\ManiaControl;
use ManiaControl\Callbacks\CallbackListener; use ManiaControl\Callbacks\CallbackListener;
use ManiaControl\Callbacks\CallbackManager; use ManiaControl\Callbacks\CallbackManager;
use ManiaControl\FileUtil;
use ManiaControl\ManiaControl;
require_once __DIR__ . '/Map.php'; require_once __DIR__ . '/Map.php';
require_once __DIR__ . '/MapCommands.php'; require_once __DIR__ . '/MapCommands.php';
@ -22,17 +21,17 @@ class MapManager implements CallbackListener {
/** /**
* Constants * Constants
*/ */
const TABLE_MAPS = 'mc_maps'; const TABLE_MAPS = 'mc_maps';
const CB_MAPS_UPDATED = 'MapManager.MapsUpdated'; const CB_MAPS_UPDATED = 'MapManager.MapsUpdated';
const CB_KARMA_UPDATED = 'MapManager.KarmaUpdated'; const CB_KARMA_UPDATED = 'MapManager.KarmaUpdated';
/** /**
* Public Properties * Public Properties
*/ */
public $mapQueue = null; public $mapQueue = null;
public $mapCommands = null; public $mapCommands = null;
public $mapList = null; public $mapList = null;
/** /**
* Private Properties * Private Properties
*/ */
@ -49,12 +48,12 @@ class MapManager implements CallbackListener {
public function __construct(ManiaControl $maniaControl) { public function __construct(ManiaControl $maniaControl) {
$this->maniaControl = $maniaControl; $this->maniaControl = $maniaControl;
$this->initTables(); $this->initTables();
// Create map commands instance // Create map commands instance
$this->mapList = new MapList($this->maniaControl); $this->mapList = new MapList($this->maniaControl);
$this->mapCommands = new MapCommands($maniaControl); $this->mapCommands = new MapCommands($maniaControl);
$this->mapQueue = new MapQueue($this->maniaControl); $this->mapQueue = new MapQueue($this->maniaControl);
// Register for callbacks // Register for callbacks
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MC_ONINIT, $this, 'handleOnInit'); $this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MC_ONINIT, $this, 'handleOnInit');
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MC_BEGINMAP, $this, 'handleBeginMap'); $this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MC_BEGINMAP, $this, 'handleBeginMap');
@ -68,7 +67,7 @@ class MapManager implements CallbackListener {
*/ */
private function initTables() { private function initTables() {
$mysqli = $this->maniaControl->database->mysqli; $mysqli = $this->maniaControl->database->mysqli;
$query = "CREATE TABLE IF NOT EXISTS `" . self::TABLE_MAPS . "` ( $query = "CREATE TABLE IF NOT EXISTS `" . self::TABLE_MAPS . "` (
`index` int(11) NOT NULL AUTO_INCREMENT, `index` int(11) NOT NULL AUTO_INCREMENT,
`uid` varchar(50) COLLATE utf8_unicode_ci NOT NULL, `uid` varchar(50) COLLATE utf8_unicode_ci NOT NULL,
`name` varchar(150) COLLATE utf8_unicode_ci NOT NULL, `name` varchar(150) COLLATE utf8_unicode_ci NOT NULL,
@ -81,7 +80,7 @@ class MapManager implements CallbackListener {
UNIQUE KEY `uid` (`uid`) UNIQUE KEY `uid` (`uid`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Map data' AUTO_INCREMENT=1;"; ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Map data' AUTO_INCREMENT=1;";
$result = $mysqli->query($query); $result = $mysqli->query($query);
if ($mysqli->error) { if($mysqli->error) {
trigger_error($mysqli->error, E_USER_ERROR); trigger_error($mysqli->error, E_USER_ERROR);
return false; return false;
} }
@ -95,8 +94,8 @@ class MapManager implements CallbackListener {
* @return bool * @return bool
*/ */
private function saveMap(Map &$map) { private function saveMap(Map &$map) {
$mysqli = $this->maniaControl->database->mysqli; $mysqli = $this->maniaControl->database->mysqli;
$mapQuery = "INSERT INTO `" . self::TABLE_MAPS . "` ( $mapQuery = "INSERT INTO `" . self::TABLE_MAPS . "` (
`uid`, `uid`,
`name`, `name`,
`authorLogin`, `authorLogin`,
@ -108,13 +107,13 @@ class MapManager implements CallbackListener {
) ON DUPLICATE KEY UPDATE ) ON DUPLICATE KEY UPDATE
`index` = LAST_INSERT_ID(`index`);"; `index` = LAST_INSERT_ID(`index`);";
$mapStatement = $mysqli->prepare($mapQuery); $mapStatement = $mysqli->prepare($mapQuery);
if ($mysqli->error) { if($mysqli->error) {
trigger_error($mysqli->error); trigger_error($mysqli->error);
return false; return false;
} }
$mapStatement->bind_param('ssssss', $map->uid, $map->name, $map->authorLogin, $map->fileName, $map->environment, $map->mapType); $mapStatement->bind_param('ssssss', $map->uid, $map->name, $map->authorLogin, $map->fileName, $map->environment, $map->mapType);
$mapStatement->execute(); $mapStatement->execute();
if ($mapStatement->error) { if($mapStatement->error) {
trigger_error($mapStatement->error); trigger_error($mapStatement->error);
$mapStatement->close(); $mapStatement->close();
return false; return false;
@ -127,11 +126,11 @@ class MapManager implements CallbackListener {
/** /**
* Remove a Map * Remove a Map
* *
* @param int $id * @param int $id
* @param string $uid * @param string $uid
* @param bool $eraseFile * @param bool $eraseFile
*/ */
public function removeMap($id, $uid, $eraseFile = false) { public function removeMap($id, $uid, $eraseFile = false) { //TODO erasefile?
$map = $this->mapsUids[$uid]; $map = $this->mapsUids[$uid];
$this->maniaControl->client->query('RemoveMap', $map->fileName); $this->maniaControl->client->query('RemoveMap', $map->fileName);
$this->maniaControl->chat->sendSuccess('Map $<' . $map->name . '$> removed!'); $this->maniaControl->chat->sendSuccess('Map $<' . $map->name . '$> removed!');
@ -145,30 +144,29 @@ class MapManager implements CallbackListener {
* Updates the full Map list, needed on Init, addMap and on ShuffleMaps * Updates the full Map list, needed on Init, addMap and on ShuffleMaps
*/ */
private function updateFullMapList() { private function updateFullMapList() {
if (!$this->maniaControl->client->query('GetMapList', 100, 0)) { if(!$this->maniaControl->client->query('GetMapList', 100, 0)) {
trigger_error("Couldn't fetch mapList. " . $this->maniaControl->getClientErrorText()); trigger_error("Couldn't fetch mapList. " . $this->maniaControl->getClientErrorText());
return null; return null;
} }
$tempList = array(); $tempList = array();
$maps = $this->maniaControl->client->getResponse(); $maps = $this->maniaControl->client->getResponse();
foreach ($maps as $rpcMap) { foreach($maps as $rpcMap) {
if (array_key_exists($rpcMap["UId"], $this->mapsUids)) { if(array_key_exists($rpcMap["UId"], $this->mapsUids)) {
// Map already exists, only update index // Map already exists, only update index
$tempList[] = $this->mapsUids[$rpcMap["UId"]]; $tempList[] = $this->mapsUids[$rpcMap["UId"]];
} } else { // Insert Map Object
else { // Insert Map Object
$map = new Map($this->maniaControl, $rpcMap); $map = new Map($this->maniaControl, $rpcMap);
$this->saveMap($map); $this->saveMap($map);
$tempList[] = $map; $tempList[] = $map;
$this->mapsUids[$map->uid] = $map; $this->mapsUids[$map->uid] = $map;
} }
} }
// restore Sorted Maplist // restore Sorted Maplist
$this->maps = $tempList; $this->maps = $tempList;
// Trigger own callback // Trigger own callback
$this->maniaControl->callbackManager->triggerCallback(self::CB_MAPS_UPDATED, array(self::CB_MAPS_UPDATED)); $this->maniaControl->callbackManager->triggerCallback(self::CB_MAPS_UPDATED, array(self::CB_MAPS_UPDATED));
} }
@ -179,20 +177,20 @@ class MapManager implements CallbackListener {
* @return bool * @return bool
*/ */
private function fetchCurrentMap() { private function fetchCurrentMap() {
if (!$this->maniaControl->client->query('GetCurrentMapInfo')) { if(!$this->maniaControl->client->query('GetCurrentMapInfo')) {
trigger_error("Couldn't fetch map info. " . $this->maniaControl->getClientErrorText()); trigger_error("Couldn't fetch map info. " . $this->maniaControl->getClientErrorText());
return false; return false;
} }
$rpcMap = $this->maniaControl->client->getResponse(); $rpcMap = $this->maniaControl->client->getResponse();
if (!array_key_exists($rpcMap["UId"], $this->mapsUids)) { if(!array_key_exists($rpcMap["UId"], $this->mapsUids)) {
$this->currentMap = $this->mapsUids[$rpcMap["UId"]]; $this->currentMap = $this->mapsUids[$rpcMap["UId"]];
return true; return true;
} }
$map = new Map($this->maniaControl, $rpcMap); $map = new Map($this->maniaControl, $rpcMap);
$this->saveMap($map); $this->saveMap($map);
$this->mapsUids[$map->uid] = $map; $this->mapsUids[$map->uid] = $map;
$this->maps[] = $map; $this->maps[] = $map;
$this->currentMap = $map; $this->currentMap = $map;
return true; return true;
} }
@ -222,7 +220,7 @@ class MapManager implements CallbackListener {
* @return mixed * @return mixed
*/ */
public function getMapByUid($uid) { public function getMapByUid($uid) {
if (!isset($this->mapsUids[$uid])) { if(!isset($this->mapsUids[$uid])) {
return null; return null;
} }
return $this->mapsUids[$uid]; return $this->mapsUids[$uid];
@ -234,11 +232,10 @@ class MapManager implements CallbackListener {
* @param array $callback * @param array $callback
*/ */
public function handleBeginMap(array $callback) { public function handleBeginMap(array $callback) {
if (array_key_exists($callback[1][0]["UId"], $this->mapsUids)) { if(array_key_exists($callback[1][0]["UId"], $this->mapsUids)) {
// Map already exists, only update index // Map already exists, only update index
$this->currentMap = $this->mapsUids[$callback[1][0]["UId"]]; $this->currentMap = $this->mapsUids[$callback[1][0]["UId"]];
} } else {
else {
// can this ever happen? // can this ever happen?
$this->fetchCurrentMap(); $this->fetchCurrentMap();
} }
@ -269,50 +266,50 @@ class MapManager implements CallbackListener {
*/ */
public function addMapFromMx($mapId, $login) { public function addMapFromMx($mapId, $login) {
// Check if ManiaControl can even write to the maps dir // Check if ManiaControl can even write to the maps dir
if (!$this->maniaControl->client->query('GetMapsDirectory')) { if(!$this->maniaControl->client->query('GetMapsDirectory')) {
trigger_error("Couldn't get map directory. " . $this->maniaControl->getClientErrorText()); trigger_error("Couldn't get map directory. " . $this->maniaControl->getClientErrorText());
$this->maniaControl->chat->sendError("ManiaControl couldn't retrieve the maps directory.", $login); $this->maniaControl->chat->sendError("ManiaControl couldn't retrieve the maps directory.", $login);
return; return;
} }
$mapDir = $this->maniaControl->client->getResponse(); $mapDir = $this->maniaControl->client->getResponse();
if (!is_dir($mapDir)) { if(!is_dir($mapDir)) {
trigger_error("ManiaControl doesn't have have access to the maps directory in '{$mapDir}'."); trigger_error("ManiaControl doesn't have have access to the maps directory in '{$mapDir}'.");
$this->maniaControl->chat->sendError("ManiaControl doesn't have access to the maps directory.", $login); $this->maniaControl->chat->sendError("ManiaControl doesn't have access to the maps directory.", $login);
return; return;
} }
$downloadDirectory = $this->maniaControl->settingManager->getSetting($this, 'MapDownloadDirectory', 'MX'); $downloadDirectory = $this->maniaControl->settingManager->getSetting($this, 'MapDownloadDirectory', 'MX');
// Create download directory if necessary // Create download directory if necessary
if (!is_dir($mapDir . $downloadDirectory) && !mkdir($mapDir . $downloadDirectory)) { if(!is_dir($mapDir . $downloadDirectory) && !mkdir($mapDir . $downloadDirectory)) {
trigger_error("ManiaControl doesn't have to rights to save maps in '{$mapDir}{$downloadDirectory}'."); trigger_error("ManiaControl doesn't have to rights to save maps in '{$mapDir}{$downloadDirectory}'.");
$this->maniaControl->chat->sendError("ManiaControl doesn't have the rights to save maps.", $login); $this->maniaControl->chat->sendError("ManiaControl doesn't have the rights to save maps.", $login);
return; return;
} }
$mapDir .= $downloadDirectory . '/'; $mapDir .= $downloadDirectory . '/';
// Download the map // Download the map
if (is_numeric($mapId)) { if(is_numeric($mapId)) {
// Load from MX // Load from MX
$serverInfo = $this->maniaControl->server->getSystemInfo(); $serverInfo = $this->maniaControl->server->getSystemInfo();
$title = strtolower(substr($serverInfo['TitleId'], 0, 2)); $title = strtolower(substr($serverInfo['TitleId'], 0, 2));
// Check if map exists // Check if map exists
$url = "http://api.mania-exchange.com/{$title}/maps/{$mapId}?format=json"; $url = "http://api.mania-exchange.com/{$title}/maps/{$mapId}?format=json";
$mapInfo = FileUtil::loadFile($url, "application/json"); $mapInfo = FileUtil::loadFile($url, "application/json");
if (!$mapInfo || strlen($mapInfo) <= 0) { if(!$mapInfo || strlen($mapInfo) <= 0) {
// Invalid id // Invalid id
$this->maniaControl->chat->sendError('Invalid MX-Id!', $login); $this->maniaControl->chat->sendError('Invalid MX-Id!', $login);
return; return;
} }
$mapInfo = json_decode($mapInfo, true); $mapInfo = json_decode($mapInfo, true);
$mapInfo = $mapInfo[0]; $mapInfo = $mapInfo[0];
$url = "http://{$title}.mania-exchange.com/tracks/download/{$mapId}"; $url = "http://{$title}.mania-exchange.com/tracks/download/{$mapId}";
$file = FileUtil::loadFile($url); $file = FileUtil::loadFile($url);
if (!$file) { if(!$file) {
// Download error // Download error
$this->maniaControl->chat->sendError('Download failed!', $login); $this->maniaControl->chat->sendError('Download failed!', $login);
return; return;
@ -320,35 +317,35 @@ class MapManager implements CallbackListener {
// Save map // Save map
$fileName = $mapId . '_' . $mapInfo['Name'] . '.Map.Gbx'; $fileName = $mapId . '_' . $mapInfo['Name'] . '.Map.Gbx';
$fileName = FileUtil::getClearedFileName($fileName); $fileName = FileUtil::getClearedFileName($fileName);
if (!file_put_contents($mapDir . $fileName, $file)) { if(!file_put_contents($mapDir . $fileName, $file)) {
// Save error // Save error
$this->maniaControl->chat->sendError('Saving map failed!', $login); $this->maniaControl->chat->sendError('Saving map failed!', $login);
return; return;
} }
// Check for valid map // Check for valid map
$mapFileName = $downloadDirectory . '/' . $fileName; $mapFileName = $downloadDirectory . '/' . $fileName;
if (!$this->maniaControl->client->query('CheckMapForCurrentServerParams', $mapFileName)) { if(!$this->maniaControl->client->query('CheckMapForCurrentServerParams', $mapFileName)) {
trigger_error("Couldn't check if map is valid ('{$mapFileName}'). " . $this->maniaControl->getClientErrorText()); trigger_error("Couldn't check if map is valid ('{$mapFileName}'). " . $this->maniaControl->getClientErrorText());
$this->maniaControl->chat->sendError('Error checking map!', $login); $this->maniaControl->chat->sendError('Error checking map!', $login);
return; return;
} }
$response = $this->maniaControl->client->getResponse(); $response = $this->maniaControl->client->getResponse();
if (!$response) { if(!$response) {
// Invalid map type // Invalid map type
$this->maniaControl->chat->sendError("Invalid map type.", $login); $this->maniaControl->chat->sendError("Invalid map type.", $login);
return; return;
} }
// Add map to map list // Add map to map list
if (!$this->maniaControl->client->query('InsertMap', $mapFileName)) { if(!$this->maniaControl->client->query('InsertMap', $mapFileName)) {
// TODO irgendein bug? // TODO irgendein bug?
$this->maniaControl->chat->sendError("Couldn't add map to match settings!", $login); $this->maniaControl->chat->sendError("Couldn't add map to match settings!", $login);
return; return;
} }
$this->maniaControl->chat->sendSuccess('Map $<' . $mapInfo['Name'] . '$> added!'); $this->maniaControl->chat->sendSuccess('Map $<' . $mapInfo['Name'] . '$> added!');
$this->updateFullMapList(); $this->updateFullMapList();
// Queue requested Map // Queue requested Map
$this->maniaControl->mapManager->mapQueue->addMapToMapQueue($login, $mapInfo['MapUID']); $this->maniaControl->mapManager->mapQueue->addMapToMapQueue($login, $mapInfo['MapUID']);
} }