applied common formatting

This commit is contained in:
Steffen Schröder
2014-05-02 17:50:30 +02:00
parent ba720f46bf
commit a0f5421bea
48 changed files with 3539 additions and 3595 deletions

View File

@ -6,10 +6,10 @@ use ManiaControl\Formatter;
use ManiaControl\ManiaExchange\MXMapInfo;
/**
* Map Class
* Map Model Class
*
* @author kremsy & steeffeen
* @copyright ManiaControl Copyright © 2014 ManiaControl Team
* @author ManiaControl Team <mail@maniacontrol.com>
* @copyright 2014 ManiaControl Team
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
*/
class Map {
@ -76,7 +76,7 @@ class Map {
* @return string
*/
public function getGame() {
switch($this->environment) {
switch ($this->environment) {
case 'Storm':
return "sm";
case 'Canyon':

View File

@ -5,8 +5,8 @@ namespace ManiaControl\Maps;
use FML\Controls\Quad;
use FML\Controls\Quads\Quad_Icons64x64_1;
use FML\Controls\Quads\Quad_UIConstruction_Buttons;
use ManiaControl\Callbacks\CallbackManager;
use ManiaControl\Callbacks\CallbackListener;
use ManiaControl\Callbacks\CallbackManager;
use ManiaControl\Commands\CommandListener;
use ManiaControl\ManiaControl;
use ManiaControl\Manialinks\IconManager;
@ -18,8 +18,8 @@ use Maniaplanet\DedicatedServer\Xmlrpc\FaultException;
/**
* Class offering Commands to manage Maps
*
* @author steeffeen & kremsy
* @copyright ManiaControl Copyright © 2014 ManiaControl Team
* @author ManiaControl Team <mail@maniacontrol.com>
* @copyright 2014 ManiaControl Team
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
*/
class MapCommands implements CommandListener, ManialinkPageAnswerListener, CallbackListener {
@ -194,7 +194,7 @@ class MapCommands implements CommandListener, ManialinkPageAnswerListener, Callb
}
try {
$this->maniaControl->client->nextMap();
} catch(ChangeInProgressException $e) {
} catch (ChangeInProgressException $e) {
}
$message = '$<' . $player->nickname . '$> skipped the current Map!';
$this->maniaControl->chat->sendSuccess($message);
@ -218,7 +218,7 @@ class MapCommands implements CommandListener, ManialinkPageAnswerListener, Callb
try {
$this->maniaControl->client->restartMap();
} catch(ChangeInProgressException $e) {
} catch (ChangeInProgressException $e) {
}
}
@ -254,25 +254,25 @@ class MapCommands implements CommandListener, ManialinkPageAnswerListener, Callb
}
$chatCommand = explode(' ', $chat[1][2]);
if(isset($chatCommand[1])) {
if(strstr($chatCommand[1], '.txt')) {
if (isset($chatCommand[1])) {
if (strstr($chatCommand[1], '.txt')) {
$maplist = $chatCommand[1];
} else {
$maplist = $chatCommand.'.txt';
$maplist = $chatCommand . '.txt';
}
} else {
$maplist = 'maplist.txt';
}
$maplist = 'MatchSettings/'.$maplist;
$maplist = 'MatchSettings/' . $maplist;
try {
$this->maniaControl->client->saveMatchSettings($maplist);
$message = 'Maplist $<$fff'.$maplist.'$> written.';
$message = 'Maplist $<$fff' . $maplist . '$> written.';
$this->maniaControl->chat->sendSuccess($message, $player);
$this->maniaControl->log($message, true);
} catch(FaultException $e) {
$this->maniaControl->chat->sendError('Cannot write maplist $<$fff'.$maplist.'$>!', $player);
} catch (FaultException $e) {
$this->maniaControl->chat->sendError('Cannot write maplist $<$fff' . $maplist . '$>!', $player);
}
}
@ -289,26 +289,26 @@ class MapCommands implements CommandListener, ManialinkPageAnswerListener, Callb
}
$chatCommand = explode(' ', $chat[1][2]);
if(isset($chatCommand[1])) {
if(strstr($chatCommand[1], '.txt')) {
if (isset($chatCommand[1])) {
if (strstr($chatCommand[1], '.txt')) {
$maplist = $chatCommand[1];
} else {
$maplist = $chatCommand[1].'.txt';
$maplist = $chatCommand[1] . '.txt';
}
} else {
$maplist = 'maplist.txt';
}
$maplist = 'MatchSettings/'.$maplist;
$maplist = 'MatchSettings/' . $maplist;
try {
$this->maniaControl->client->loadMatchSettings($maplist);
$message = 'Maplist $<$fff'.$maplist.'$> loaded.';
$message = 'Maplist $<$fff' . $maplist . '$> loaded.';
$this->maniaControl->mapManager->restructureMapList();
$this->maniaControl->chat->sendSuccess($message, $player);
$this->maniaControl->log($message, true);
} catch(FaultException $e) {
$this->maniaControl->chat->sendError('Cannot load maplist $<$fff'.$maplist.'$>!', $player);
} catch (FaultException $e) {
$this->maniaControl->chat->sendError('Cannot load maplist $<$fff' . $maplist . '$>!', $player);
}
}
@ -320,7 +320,7 @@ class MapCommands implements CommandListener, ManialinkPageAnswerListener, Callb
public function handleManialinkPageAnswer(array $callback) {
$actionId = $callback[1][2];
$login = $callback[1][1];
$login = $callback[1][1];
$player = $this->maniaControl->playerManager->getPlayer($login);
if (strstr($actionId, self::ACTION_SHOW_AUTHOR)) {
@ -330,6 +330,30 @@ class MapCommands implements CommandListener, ManialinkPageAnswerListener, Callb
}
}
/**
* Show the Player a List of Maps from the given Author
*
* @param string $author
* @param Player $player
*/
private function showMapListAuthor($author, Player $player) {
$maps = $this->maniaControl->mapManager->getMaps();
$mapList = array();
/** @var Map $map */
foreach ($maps as $map) {
if ($map->authorLogin == $author) {
$mapList[] = $map;
}
}
if (count($mapList) == 0) {
$this->maniaControl->chat->sendError('There are no maps to show!', $player->login);
return;
}
$this->maniaControl->mapManager->mapList->showMapList($player, $mapList);
}
/**
* Handle /maps command
*
@ -339,19 +363,19 @@ class MapCommands implements CommandListener, ManialinkPageAnswerListener, Callb
public function command_List(array $chatCallback, Player $player) {
$chatCommands = explode(' ', $chatCallback[1][2]);
$this->maniaControl->mapManager->mapList->playerCloseWidget($player);
if(isset($chatCommands[1])) {
if($chatCommands[1] == ' ' || $chatCommands[1] == 'all') {
if (isset($chatCommands[1])) {
if ($chatCommands[1] == ' ' || $chatCommands[1] == 'all') {
$this->maniaControl->mapManager->mapList->showMapList($player);
} elseif($chatCommands[1] == 'best') {
} elseif ($chatCommands[1] == 'best') {
$this->showMapListKarma(true, $player);
} elseif($chatCommands[1] == 'worst') {
} elseif ($chatCommands[1] == 'worst') {
$this->showMapListKarma(false, $player);
} elseif($chatCommands[1] == 'newest') {
} elseif ($chatCommands[1] == 'newest') {
$this->showMapListDate(true, $player);
} elseif($chatCommands[1] == 'oldest') {
} elseif ($chatCommands[1] == 'oldest') {
$this->showMapListDate(false, $player);
} elseif($chatCommands[1] == 'author') {
if(isset($chatCommands[2])) {
} elseif ($chatCommands[1] == 'author') {
if (isset($chatCommands[2])) {
$this->showMaplistAuthor($chatCommands[2], $player);
} else {
$this->maniaControl->chat->sendError('There are no maps to show!', $player->login);
@ -362,69 +386,46 @@ class MapCommands implements CommandListener, ManialinkPageAnswerListener, Callb
}
}
/**
* Show the Player a List of Maps from the given Author
* @param string $author
* @param Player $player
*/
private function showMapListAuthor($author, Player $player) {
$maps = $this->maniaControl->mapManager->getMaps();
$mapList = array();
/** @var Map $map */
foreach($maps as $map) {
if($map->authorLogin == $author) {
$mapList[] = $map;
}
}
if(count($mapList) == 0) {
$this->maniaControl->chat->sendError('There are no maps to show!', $player->login);
return;
}
$this->maniaControl->mapManager->mapList->showMapList($player, $mapList);
}
/**
* Show a Karma based MapList
*
* @param bool $best
* @param bool $best
* @param Player $player
*/
private function showMapListKarma($best, Player $player) {
/** @var \MCTeam\KarmaPlugin $karmaPlugin */
$karmaPlugin = $this->maniaControl->pluginManager->getPlugin(MapList::DEFAULT_KARMA_PLUGIN);
if($karmaPlugin) {
$maps = $this->maniaControl->mapManager->getMaps();
if ($karmaPlugin) {
$maps = $this->maniaControl->mapManager->getMaps();
$mapList = array();
foreach($maps as $map) {
if($map instanceof Map) {
if($this->maniaControl->settingManager->getSetting($karmaPlugin, $karmaPlugin::SETTING_NEWKARMA) === true) {
$karma = $karmaPlugin->getMapKarma($map);
foreach ($maps as $map) {
if ($map instanceof Map) {
if ($this->maniaControl->settingManager->getSetting($karmaPlugin, $karmaPlugin::SETTING_NEWKARMA) === true) {
$karma = $karmaPlugin->getMapKarma($map);
$map->karma = round($karma * 100.);
} else {
$votes = $karmaPlugin->getMapVotes($map);
$min = 0;
$plus = 0;
foreach($votes as $vote) {
if(isset($vote->vote)) {
if($vote->vote != 0.5) {
if($vote->vote < 0.5) {
$min = $min+$vote->count;
$min = 0;
$plus = 0;
foreach ($votes as $vote) {
if (isset($vote->vote)) {
if ($vote->vote != 0.5) {
if ($vote->vote < 0.5) {
$min = $min + $vote->count;
} else {
$plus = $plus+$vote->count;
$plus = $plus + $vote->count;
}
}
}
}
$map->karma = $plus-$min;
$map->karma = $plus - $min;
}
$mapList[] = $map;
}
}
usort($mapList, array($this, 'sortByKarma'));
if($best) {
if ($best) {
$mapList = array_reverse($mapList);
}
@ -434,31 +435,20 @@ class MapCommands implements CommandListener, ManialinkPageAnswerListener, Callb
}
}
/**
* Helper Function to sort Maps by Karma
*
* @param Map $a
* @param Map $b
* @return mixed
*/
private function sortByKarma($a, $b) {
return ($a->karma - $b->karma);
}
/**
* Show a Date based MapList
*
* @param bool $newest
* @param bool $newest
* @param Player $player
*/
private function showMapListDate($newest, Player $player) {
$maps = $this->maniaControl->mapManager->getMaps();
usort($maps, function($a, $b) {
usort($maps, function ($a, $b) {
return ($a->index - $b->index);
});
if($newest) {
if ($newest) {
$maps = array_reverse($maps);
}
@ -474,4 +464,15 @@ class MapCommands implements CommandListener, ManialinkPageAnswerListener, Callb
public function command_xList(array $chatCallback, Player $player) {
$this->maniaControl->mapManager->mxList->showList($chatCallback, $player);
}
/**
* Helper Function to sort Maps by Karma
*
* @param Map $a
* @param Map $b
* @return mixed
*/
private function sortByKarma($a, $b) {
return ($a->karma - $b->karma);
}
}

View File

@ -2,7 +2,6 @@
namespace ManiaControl\Maps;
use MCTeam\CustomVotesPlugin;
use FML\Controls\Control;
use FML\Controls\Frame;
use FML\Controls\Gauge;
@ -25,33 +24,34 @@ use ManiaControl\Manialinks\ManialinkManager;
use ManiaControl\Manialinks\ManialinkPageAnswerListener;
use ManiaControl\Players\Player;
use Maniaplanet\DedicatedServer\Xmlrpc\Exception;
use MCTeam\CustomVotesPlugin;
use MCTeam\KarmaPlugin;
/**
* MapList Widget Class
*
* @author steeffeen & kremsy
* @copyright ManiaControl Copyright © 2014 ManiaControl Team
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
*
* @author ManiaControl Team <mail@maniacontrol.com>
* @copyright 2014 ManiaControl Team
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
*/
class MapList implements ManialinkPageAnswerListener, CallbackListener {
/*
* Constants
*/
const ACTION_UPDATE_MAP = 'MapList.UpdateMap';
const ACTION_ERASE_MAP = 'MapList.EraseMap';
const ACTION_SWITCH_MAP = 'MapList.SwitchMap';
const ACTION_START_SWITCH_VOTE = 'MapList.StartMapSwitchVote';
const ACTION_QUEUED_MAP = 'MapList.QueueMap';
const ACTION_UNQUEUE_MAP = 'MapList.UnQueueMap';
const ACTION_CHECK_UPDATE = 'MapList.CheckUpdate';
const ACTION_CLEAR_MAPQUEUE = 'MapList.ClearMapQueue';
const ACTION_PAGING_CHUNKS = 'MapList.PagingChunk.';
const MAX_MAPS_PER_PAGE = 15;
const MAX_PAGES_PER_CHUNK = 2;
const DEFAULT_KARMA_PLUGIN = 'MCTeam\KarmaPlugin';
const ACTION_UPDATE_MAP = 'MapList.UpdateMap';
const ACTION_ERASE_MAP = 'MapList.EraseMap';
const ACTION_SWITCH_MAP = 'MapList.SwitchMap';
const ACTION_START_SWITCH_VOTE = 'MapList.StartMapSwitchVote';
const ACTION_QUEUED_MAP = 'MapList.QueueMap';
const ACTION_UNQUEUE_MAP = 'MapList.UnQueueMap';
const ACTION_CHECK_UPDATE = 'MapList.CheckUpdate';
const ACTION_CLEAR_MAPQUEUE = 'MapList.ClearMapQueue';
const ACTION_PAGING_CHUNKS = 'MapList.PagingChunk.';
const MAX_MAPS_PER_PAGE = 15;
const MAX_PAGES_PER_CHUNK = 2;
const DEFAULT_KARMA_PLUGIN = 'MCTeam\KarmaPlugin';
const DEFAULT_CUSTOM_VOTE_PLUGIN = 'MCTeam\CustomVotesPlugin';
/*
* Private Properties
*/
@ -61,12 +61,12 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
/**
* Create a new MapList Instance
*
*
* @param ManiaControl $maniaControl
*/
public function __construct(ManiaControl $maniaControl) {
$this->maniaControl = $maniaControl;
// Register for Callbacks
$this->maniaControl->callbackManager->registerCallbackListener(ManialinkManager::CB_MAIN_WINDOW_CLOSED, $this, 'closeWidget');
$this->maniaControl->callbackManager->registerCallbackListener(ManialinkManager::CB_MAIN_WINDOW_OPENED, $this, 'handleWidgetOpened');
@ -75,15 +75,15 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
$this->maniaControl->callbackManager->registerCallbackListener(MapManager::CB_MAPS_UPDATED, $this, 'updateWidget');
$this->maniaControl->callbackManager->registerCallbackListener(MapManager::CB_KARMA_UPDATED, $this, 'updateWidget');
$this->maniaControl->callbackManager->registerCallbackListener(Callbacks::BEGINMAP, $this, 'updateWidget');
$this->maniaControl->manialinkManager->registerManialinkPageAnswerListener(self::ACTION_CHECK_UPDATE, $this, 'checkUpdates');
$this->maniaControl->manialinkManager->registerManialinkPageAnswerListener(self::ACTION_CLEAR_MAPQUEUE, $this, 'clearMapQueue');
}
/**
* Clears the Map Queue
*
* @param array $chatCallback
*
* @param array $chatCallback
* @param Player $player
*/
public function clearMapQueue(array $chatCallback, Player $player) {
@ -93,66 +93,66 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
/**
* Check for Map Updates
*
* @param array $chatCallback
*
* @param array $chatCallback
* @param Player $player
*/
public function checkUpdates(array $chatCallback, Player $player) {
// Update Mx Infos
$this->maniaControl->mapManager->mxManager->fetchManiaExchangeMapInformations();
// Reshow the Maplist
$this->showMapList($player);
}
/**
* Display a MapList on the Screen
*
*
* @param Player $player
* @param array $maps
* @param int $chunk
* @param int $startPage
* @param array $maps
* @param int $chunk
* @param int $startPage
*/
public function showMapList(Player $player, $maps = null, $chunk = 0, $startPage = null) {
$width = $this->maniaControl->manialinkManager->styleManager->getListWidgetsWidth();
$width = $this->maniaControl->manialinkManager->styleManager->getListWidgetsWidth();
$height = $this->maniaControl->manialinkManager->styleManager->getListWidgetsHeight();
$this->mapListShown[$player->login] = true;
$queueBuffer = $this->maniaControl->mapManager->mapQueue->getQueueBuffer();
$queueBuffer = $this->maniaControl->mapManager->mapQueue->getQueueBuffer();
// Get Maps
$mapList = null;
$mapList = null;
$pageCount = null;
if (is_array($maps)) {
$mapList = array_slice($maps, $chunk, self::MAX_PAGES_PER_CHUNK * self::MAX_MAPS_PER_PAGE);
$mapList = array_slice($maps, $chunk, self::MAX_PAGES_PER_CHUNK * self::MAX_MAPS_PER_PAGE);
$this->mapsInListShown[$player->login] = $maps;
$pageCount = ceil(count($maps) / self::MAX_MAPS_PER_PAGE);
}
else if (array_key_exists($player->login, $this->mapsInListShown)) {
$completeList = $this->mapsInListShown[$player->login];
$pageCount = ceil(count($maps) / self::MAX_MAPS_PER_PAGE);
} else if (array_key_exists($player->login, $this->mapsInListShown)) {
$completeList = $this->mapsInListShown[$player->login];
$this->mapsInListShown[$player->login] = $completeList;
$mapList = array_slice($completeList, $chunk * self::MAX_PAGES_PER_CHUNK * self::MAX_MAPS_PER_PAGE, self::MAX_PAGES_PER_CHUNK * self::MAX_MAPS_PER_PAGE);
$pageCount = ceil(count($completeList) / self::MAX_MAPS_PER_PAGE);
}
else {
$mapList = $this->maniaControl->mapManager->getMaps($chunk * self::MAX_PAGES_PER_CHUNK * self::MAX_MAPS_PER_PAGE, self::MAX_PAGES_PER_CHUNK * self::MAX_MAPS_PER_PAGE);
$pageCount = ceil($this->maniaControl->mapManager->getMapsCount() / self::MAX_MAPS_PER_PAGE);
$mapList = array_slice($completeList, $chunk * self::MAX_PAGES_PER_CHUNK * self::MAX_MAPS_PER_PAGE, self::MAX_PAGES_PER_CHUNK * self::MAX_MAPS_PER_PAGE);
$pageCount = ceil(count($completeList) / self::MAX_MAPS_PER_PAGE);
} else {
$mapList = $this->maniaControl->mapManager->getMaps($chunk * self::MAX_PAGES_PER_CHUNK * self::MAX_MAPS_PER_PAGE, self::MAX_PAGES_PER_CHUNK * self::MAX_MAPS_PER_PAGE);
$pageCount = ceil($this->maniaControl->mapManager->getMapsCount() / self::MAX_MAPS_PER_PAGE);
$this->mapsInListShown[$player->login] = $this->maniaControl->mapManager->getMaps();
}
// Create ManiaLink
$maniaLink = new ManiaLink(ManialinkManager::MAIN_MLID);
$script = $maniaLink->getScript();
$paging = new Paging();
$script = $maniaLink->getScript();
$paging = new Paging();
$script->addFeature($paging);
if (!is_null($pageCount)) $paging->setCustomMaxPageNumber($pageCount);
if (!is_null($pageCount)) {
$paging->setCustomMaxPageNumber($pageCount);
}
$paging->setChunkActionAppendsPageNumber(true);
$paging->setChunkActions(self::ACTION_PAGING_CHUNKS);
// Main frame
$frame = $this->maniaControl->manialinkManager->styleManager->getDefaultListFrame($script, $paging);
$maniaLink->add($frame);
// Admin Buttons
if ($this->maniaControl->authenticationManager->checkPermission($player, MapQueue::SETTING_PERMISSION_CLEAR_MAPQUEUE)) {
// Clear Map-Queue
@ -162,7 +162,7 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
$label->setTextSize(1);
$label->setPosition($width / 2 - 8, -$height / 2 + 9);
$label->setHAlign(Control::RIGHT);
$quad = new Quad_BgsPlayerCard();
$frame->add($quad);
$quad->setPosition($width / 2 - 5, -$height / 2 + 9, 0.01);
@ -171,7 +171,7 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
$quad->setSize(29, 4);
$quad->setAction(self::ACTION_CLEAR_MAPQUEUE);
}
if ($this->maniaControl->authenticationManager->checkPermission($player, MapManager::SETTING_PERMISSION_CHECK_UPDATE)) {
// Check Update
$label = new Label_Button();
@ -180,7 +180,7 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
$label->setTextSize(1);
$label->setPosition($width / 2 - 41, -$height / 2 + 9, 0.01);
$label->setHAlign(Control::RIGHT);
$quad = new Quad_BgsPlayerCard();
$frame->add($quad);
$quad->setPosition($width / 2 - 37, -$height / 2 + 9, 0.01);
@ -188,7 +188,7 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
$quad->setHAlign(Control::RIGHT);
$quad->setSize(35, 4);
$quad->setAction(self::ACTION_CHECK_UPDATE);
$mxQuad = new Quad();
$frame->add($mxQuad);
$mxQuad->setSize(3, 3);
@ -198,44 +198,41 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
$mxQuad->setZ(0.01);
$mxQuad->setAction(self::ACTION_CHECK_UPDATE);
}
// Headline
$headFrame = new Frame();
$frame->add($headFrame);
$headFrame->setY($height / 2 - 5);
$x = -$width / 2;
$array = array('Id' => $x + 5, 'Mx Id' => $x + 10, 'Map Name' => $x + 20, 'Author' => $x + 68, 'Karma' => $x + 115,
'Actions' => $width / 2 - 15);
$x = -$width / 2;
$array = array('Id' => $x + 5, 'Mx Id' => $x + 10, 'Map Name' => $x + 20, 'Author' => $x + 68, 'Karma' => $x + 115, 'Actions' => $width / 2 - 15);
$this->maniaControl->manialinkManager->labelLine($headFrame, $array);
// Predefine description Label
$descriptionLabel = $this->maniaControl->manialinkManager->styleManager->getDefaultDescriptionLabel();
$frame->add($descriptionLabel);
$queuedMaps = $this->maniaControl->mapManager->mapQueue->getQueuedMapsRanking();
/**
*
* @var KarmaPlugin $karmaPlugin
*/
$karmaPlugin = $this->maniaControl->pluginManager->getPlugin(self::DEFAULT_KARMA_PLUGIN);
$pageNumber = 1 + $chunk * self::MAX_PAGES_PER_CHUNK;
$pageNumber = 1 + $chunk * self::MAX_PAGES_PER_CHUNK;
$startPageNumber = (is_int($startPage) ? $startPage : $pageNumber);
$paging->setStartPageNumber($startPageNumber);
$id = 1 + $chunk * self::MAX_PAGES_PER_CHUNK * self::MAX_MAPS_PER_PAGE;
$y = $height / 2 - 10;
$id = 1 + $chunk * self::MAX_PAGES_PER_CHUNK * self::MAX_MAPS_PER_PAGE;
$y = $height / 2 - 10;
$pageFrames = array();
/**
*
* @var Map $map
*/
$currentMap = $this->maniaControl->mapManager->getCurrentMap();
$mxIcon = $this->maniaControl->manialinkManager->iconManager->getIcon(IconManager::MX_ICON);
$mxIconHover = $this->maniaControl->manialinkManager->iconManager->getIcon(IconManager::MX_ICON_MOVER);
$mxIconGreen = $this->maniaControl->manialinkManager->iconManager->getIcon(IconManager::MX_ICON_GREEN);
$currentMap = $this->maniaControl->mapManager->getCurrentMap();
$mxIcon = $this->maniaControl->manialinkManager->iconManager->getIcon(IconManager::MX_ICON);
$mxIconHover = $this->maniaControl->manialinkManager->iconManager->getIcon(IconManager::MX_ICON_MOVER);
$mxIconGreen = $this->maniaControl->manialinkManager->iconManager->getIcon(IconManager::MX_ICON_GREEN);
$mxIconGreenHover = $this->maniaControl->manialinkManager->iconManager->getIcon(IconManager::MX_ICON_GREEN_MOVER);
foreach ($mapList as $map) {
if (!isset($pageFrame)) {
$pageFrame = new Frame();
@ -245,17 +242,17 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
}
array_push($pageFrames, $pageFrame);
$y = $height / 2 - 10;
$paging->addPage($pageFrame, $pageNumber);
$pageNumber++;
}
// Map Frame
$mapFrame = new Frame();
$pageFrame->add($mapFrame);
$mapFrame->setZ(0.1);
$mapFrame->setY($y);
if ($id % 2 != 0) {
$lineQuad = new Quad_BgsPlayerCard();
$mapFrame->add($lineQuad);
@ -263,7 +260,7 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
$lineQuad->setSubStyle($lineQuad::SUBSTYLE_BgPlayerCardBig);
$lineQuad->setZ(0.001);
}
if ($currentMap === $map) {
$currentQuad = new Quad_Icons64x64_1();
$mapFrame->add($currentQuad);
@ -272,11 +269,11 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
$currentQuad->setSize(4, 4);
$currentQuad->setSubStyle($currentQuad::SUBSTYLE_ArrowBlue);
}
$mxId = '-';
if (isset($map->mx->id)) {
$mxId = $map->mx->id;
$mxQuad = new Quad();
$mapFrame->add($mxQuad);
$mxQuad->setSize(3, 3);
@ -287,7 +284,7 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
$mxQuad->setZ(0.01);
$description = 'View $<' . $map->name . '$> on Mania-Exchange';
$mxQuad->addTooltipLabelFeature($descriptionLabel, $description);
if ($map->updateAvailable()) {
$mxQuad = new Quad();
$mapFrame->add($mxQuad);
@ -299,30 +296,29 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
$mxQuad->setZ(0.01);
$description = 'Update for $<' . $map->name . '$> available on Mania-Exchange!';
$mxQuad->addTooltipLabelFeature($descriptionLabel, $description);
// Update Button
if ($this->maniaControl->authenticationManager->checkPermission($player, MapManager::SETTING_PERMISSION_ADD_MAP)) {
$mxQuad->setAction(self::ACTION_UPDATE_MAP . '.' . $map->uid);
}
}
}
// 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);
$labels = $this->maniaControl->manialinkManager->labelLine($mapFrame, $array);
if (isset($labels[3])) {
/**
*
* @var Label $label
*/
$label = $labels[3];
$label = $labels[3];
$description = 'Click to checkout all maps by $<' . $map->authorLogin . '$>!';
$label->setAction(MapCommands::ACTION_SHOW_AUTHOR . $map->authorLogin);
$label->addTooltipLabelFeature($descriptionLabel, $description);
}
// TODO action detailed map info including mx info
// Map-Queue-Map-Label
if (isset($queuedMaps[$map->uid])) {
$label = new Label_Text();
@ -333,20 +329,18 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
$label->setTextSize(1.5);
$label->setText($queuedMaps[$map->uid]);
$label->setTextColor('fff');
// Checks if the Player who openend the Widget has queued the map
$queuer = $this->maniaControl->mapManager->mapQueue->getQueuer($map->uid);
if ($queuer->login == $player->login) {
$description = 'Remove $<' . $map->name . '$> from the Map Queue';
$label->addTooltipLabelFeature($descriptionLabel, $description);
$label->setAction(self::ACTION_UNQUEUE_MAP . '.' . $map->uid);
}
else {
} else {
$description = '$<' . $map->name . '$> is on Map-Queue Position: ' . $queuedMaps[$map->uid];
$label->addTooltipLabelFeature($descriptionLabel, $description);
}
}
else {
} else {
// Map-Queue-Map-Button
$queueLabel = new Label_Button();
$mapFrame->add($queueLabel);
@ -355,7 +349,7 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
$queueLabel->setSize(3, 3);
$queueLabel->setText('+');
if(in_array($map->uid, $queueBuffer)) {
if (in_array($map->uid, $queueBuffer)) {
if ($this->maniaControl->authenticationManager->checkPermission($player, MapQueue::SETTING_PERMISSION_CLEAR_MAPQUEUE)) {
$queueLabel->setAction(self::ACTION_QUEUED_MAP . '.' . $map->uid);
}
@ -369,7 +363,7 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
$queueLabel->addTooltipLabelFeature($descriptionLabel, $description);
}
}
if ($this->maniaControl->authenticationManager->checkPermission($player, MapManager::SETTING_PERMISSION_REMOVE_MAP)) {
// erase map quad
$eraseLabel = new Label_Button();
@ -380,13 +374,13 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
$eraseLabel->setTextSize(1);
$eraseLabel->setText('x');
$eraseLabel->setTextColor('a00');
$confirmFrame = $this->buildConfirmFrame($maniaLink, $y, $id, $map->uid);
$eraseLabel->addToggleFeature($confirmFrame);
$description = 'Remove Map: $<' . $map->name . '$>';
$eraseLabel->addTooltipLabelFeature($descriptionLabel, $description);
}
if ($this->maniaControl->authenticationManager->checkPermission($player, MapManager::SETTING_PERMISSION_ADD_MAP)) {
// Switch to map
$switchLabel = new Label_Button();
@ -397,14 +391,13 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
$switchLabel->setTextSize(2);
$switchLabel->setText('»');
$switchLabel->setTextColor('0f0');
$confirmFrame = $this->buildConfirmFrame($maniaLink, $y, $id);
$switchLabel->addToggleFeature($confirmFrame);
$description = 'Switch Directly to Map: $<' . $map->name . '$>';
$switchLabel->addTooltipLabelFeature($descriptionLabel, $description);
}
else if ($this->maniaControl->pluginManager->isPluginActive(self::DEFAULT_CUSTOM_VOTE_PLUGIN)) {
} else if ($this->maniaControl->pluginManager->isPluginActive(self::DEFAULT_CUSTOM_VOTE_PLUGIN)) {
// Switch Map Voting
$switchLabel = new Label_Button();
$mapFrame->add($switchLabel);
@ -414,35 +407,35 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
$switchLabel->setTextSize(2);
$switchLabel->setText('»');
$switchLabel->setTextColor('0f0');
$switchLabel->setAction(self::ACTION_START_SWITCH_VOTE . '.' . ($id - 1));
$description = 'Start Map-Switch Vote: $<' . $map->name . '$>';
$switchLabel->addTooltipLabelFeature($descriptionLabel, $description);
}
// Display Karma bar
if ($karmaPlugin) {
$karma = $karmaPlugin->getMapKarma($map);
$votes = $karmaPlugin->getMapVotes($map);
if (is_numeric($karma)) {
if($this->maniaControl->settingManager->getSetting($karmaPlugin, $karmaPlugin::SETTING_NEWKARMA)) {
if ($this->maniaControl->settingManager->getSetting($karmaPlugin, $karmaPlugin::SETTING_NEWKARMA)) {
$karmaText = ' ' . round($karma * 100.) . '% (' . $votes['count'] . ')';
} else {
$min = 0;
$min = 0;
$plus = 0;
foreach($votes as $vote) {
if(isset($vote->vote)) {
if($vote->vote != 0.5) {
if($vote->vote < 0.5) {
$min = $min+$vote->count;
foreach ($votes as $vote) {
if (isset($vote->vote)) {
if ($vote->vote != 0.5) {
if ($vote->vote < 0.5) {
$min = $min + $vote->count;
} else {
$plus = $plus+$vote->count;
$plus = $plus + $vote->count;
}
}
}
}
$endKarma = $plus-$min;
$endKarma = $plus - $min;
$karmaText = ' ' . $endKarma . ' (' . $votes['count'] . 'x / ' . round($karma * 100.) . '%)';
}
@ -456,7 +449,7 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
$karmaGauge->setRatio($karma + 0.15 - $karma * 0.15);
$karmaColor = ColorUtil::floatToStatusColor($karma);
$karmaGauge->setColor($karmaColor . '9');
$karmaLabel = new Label();
$mapFrame->add($karmaLabel);
$karmaLabel->setZ(2);
@ -468,46 +461,46 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
$karmaLabel->setText($karmaText);
}
}
$y -= 4;
if ($id % self::MAX_MAPS_PER_PAGE == 0) {
unset($pageFrame);
}
$id++;
}
$this->maniaControl->manialinkManager->displayWidget($maniaLink, $player, 'MapList');
}
/**
* Builds the confirmation frame
*
*
* @param ManiaLink $maniaLink
* @param $y
* @param $id
* @param bool $mapUid
* @param $y
* @param $id
* @param bool $mapUid
* @return Frame
*/
public function buildConfirmFrame(Manialink $maniaLink, $y, $id, $mapUid = false) {
$width = $this->maniaControl->manialinkManager->styleManager->getListWidgetsWidth();
$quadStyle = $this->maniaControl->manialinkManager->styleManager->getDefaultMainWindowStyle();
$width = $this->maniaControl->manialinkManager->styleManager->getListWidgetsWidth();
$quadStyle = $this->maniaControl->manialinkManager->styleManager->getDefaultMainWindowStyle();
$quadSubstyle = $this->maniaControl->manialinkManager->styleManager->getDefaultMainWindowSubStyle();
$confirmFrame = new Frame();
$maniaLink->add($confirmFrame);
$confirmFrame->setPosition($width / 2 + 6, $y);
$confirmFrame->setVisible(false);
$quad = new Quad();
$confirmFrame->add($quad);
$quad->setStyles($quadStyle, $quadSubstyle);
$quad->setSize(12, 4);
$quad = new Quad_BgsPlayerCard();
$confirmFrame->add($quad);
$quad->setSubStyle($quad::SUBSTYLE_BgCardSystem);
$quad->setSize(11, 3.5);
$label = new Label_Button();
$confirmFrame->add($label);
$label->setAlign(Control::CENTER, Control::CENTER);
@ -515,20 +508,19 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
$label->setTextSize(1);
$label->setScale(0.90);
$label->setX(-1.3);
$buttLabel = new Label_Button();
$confirmFrame->add($buttLabel);
$buttLabel->setPosition(3.2, 0.4, 0.2);
$buttLabel->setSize(3, 3);
$buttLabel->setAlign(Control::CENTER, Control::CENTER);
if (!$mapUid) {
$quad->setAction(self::ACTION_SWITCH_MAP . '.' . ($id - 1));
$buttLabel->setText('»');
$buttLabel->setTextColor('0f0');
$buttLabel->setTextSize(2);
}
else {
} else {
$buttLabel->setTextSize(1);
$buttLabel->setText('x');
$buttLabel->setTextColor('a00');
@ -539,9 +531,9 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
/**
* Unset the player if he opened another Main Widget
*
*
* @param Player $player
* @param $openedWidget
* @param $openedWidget
*/
public function handleWidgetOpened(Player $player, $openedWidget) {
// unset when another main widget got opened
@ -552,7 +544,7 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
/**
* Closes the widget
*
*
* @param \ManiaControl\Players\Player $player
*/
public function closeWidget(Player $player) {
@ -560,35 +552,24 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
unset($this->mapsInListShown[$player->login]);
}
/**
* Closes the widget
*
* @param Player $player
*/
public function playerCloseWidget(Player $player) {
unset($this->mapListShown[$player->login]);
unset($this->mapsInListShown[$player->login]);
$this->maniaControl->manialinkManager->closeWidget($player);
}
/**
* Handle ManialinkPageAnswer Callback
*
*
* @param array $callback
*/
public function handleManialinkPageAnswer(array $callback) {
$actionId = $callback[1][2];
$actionId = $callback[1][2];
$actionArray = explode('.', $actionId);
if (count($actionArray) <= 2) {
return;
}
$action = $actionArray[0] . '.' . $actionArray[1];
$login = $callback[1][1];
$login = $callback[1][1];
$player = $this->maniaControl->playerManager->getPlayer($login);
$mapId = (int) $actionArray[2];
$mapId = (int)$actionArray[2];
switch ($action) {
case self::ACTION_UPDATE_MAP:
$mapUid = $actionArray[2];
@ -602,51 +583,47 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
case self::ACTION_SWITCH_MAP:
try {
$this->maniaControl->client->jumpToMapIndex($mapId);
}
catch (Exception $e) {
} catch (Exception $e) {
// TODO: is it even possible that an exception other than connection errors will be thrown? - remove try-catch?
$this->maniaControl->chat->sendError("Error while Jumping to Map Index");
break;
}
$mapList = $this->maniaControl->mapManager->getMaps();
$map = $mapList[$mapId];
$map = $mapList[$mapId];
$message = '$<' . $player->nickname . '$> skipped to Map $z$<' . $map->name . '$>!';
$this->maniaControl->chat->sendSuccess($message);
$this->maniaControl->log($message, true);
$this->playerCloseWidget($player);
break;
case self::ACTION_START_SWITCH_VOTE:
/**
*
* @var $votesPlugin CustomVotesPlugin
*/
$votesPlugin = $this->maniaControl->pluginManager->getPlugin(self::DEFAULT_CUSTOM_VOTE_PLUGIN);
$mapList = $this->maniaControl->mapManager->getMaps();
$map = $mapList[$mapId];
$mapList = $this->maniaControl->mapManager->getMaps();
$map = $mapList[$mapId];
$message = '$<' . $player->nickname . '$>$s started a vote to switch to $<' . $map->name . '$>!';
/**
*
* @var Map $map
*/
$votesPlugin->defineVote('switchmap', "Goto " . $map->name, true, $message);
$self = $this;
$votesPlugin->startVote($player, 'switchmap', function ($result) use(&$self, &$votesPlugin, &$map) {
$votesPlugin->startVote($player, 'switchmap', function ($result) use (&$self, &$votesPlugin, &$map) {
$self->maniaControl->chat->sendInformation('$sVote Successfully -> Map switched!');
$votesPlugin->undefineVote('switchmap');
try {
$index = $self->maniaControl->mapManager->getMapIndex($map);
$self->maniaControl->client->jumpToMapIndex($index);
}
catch (Exception $e) {
} catch (Exception $e) {
// TODO temp added 19.04.2014
$self->maniaControl->errorHandler->triggerDebugNotice("Exception line 557 MapList.php" . $e->getMessage());
$self->maniaControl->chat->sendError("Error while Switching Map");
}
});
@ -662,14 +639,25 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
default:
if (substr($actionId, 0, strlen(self::ACTION_PAGING_CHUNKS)) === self::ACTION_PAGING_CHUNKS) {
// Paging chunks
$neededPage = (int) substr($actionId, strlen(self::ACTION_PAGING_CHUNKS));
$chunk = (int) ($neededPage / self::MAX_PAGES_PER_CHUNK - 0.5);
$neededPage = (int)substr($actionId, strlen(self::ACTION_PAGING_CHUNKS));
$chunk = (int)($neededPage / self::MAX_PAGES_PER_CHUNK - 0.5);
$this->showMapList($player, null, $chunk, $neededPage);
}
break;
}
}
/**
* Closes the widget
*
* @param Player $player
*/
public function playerCloseWidget(Player $player) {
unset($this->mapListShown[$player->login]);
unset($this->mapsInListShown[$player->login]);
$this->maniaControl->manialinkManager->closeWidget($player);
}
/**
* Reopen the widget on Map Begin, MapListChanged, etc.
*/
@ -679,8 +667,7 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
$player = $this->maniaControl->playerManager->getPlayer($login);
if ($player) {
$this->showMapList($player);
}
else {
} else {
unset($this->mapListShown[$login]);
}
}
@ -696,8 +683,7 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
$player = $this->maniaControl->playerManager->getPlayer($login);
if ($player) {
$this->showMapList($player);
}
else {
} else {
unset($this->mapListShown[$login]);
}
}

View File

@ -22,8 +22,8 @@ use Maniaplanet\DedicatedServer\Xmlrpc\StartIndexOutOfBoundException;
/**
* Manager for Maps
*
* @author kremsy & steeffeen
* @copyright ManiaControl Copyright © 2014 ManiaControl Team
* @author ManiaControl Team <mail@maniacontrol.com>
* @copyright 2014 ManiaControl Team
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
*/
class MapManager implements CallbackListener {
@ -129,44 +129,26 @@ class MapManager implements CallbackListener {
}
/**
* Save a Map in the Database
* Update a Map from Mania Exchange
*
* @param \ManiaControl\Maps\Map $map
* @return bool
* @param Player $admin
* @param string $uid
*/
private function saveMap(Map &$map) {
//TODO saveMaps for whole maplist at once (usage of prepared statements)
$mysqli = $this->maniaControl->database->mysqli;
$mapQuery = "INSERT INTO `" . self::TABLE_MAPS . "` (
`uid`,
`name`,
`authorLogin`,
`fileName`,
`environment`,
`mapType`
) VALUES (
?, ?, ?, ?, ?, ?
) ON DUPLICATE KEY UPDATE
`index` = LAST_INSERT_ID(`index`),
`fileName` = VALUES(`fileName`),
`environment` = VALUES(`environment`),
`mapType` = VALUES(`mapType`);";
public function updateMap(Player $admin, $uid) {
$this->updateMapTimestamp($uid);
$mapStatement = $mysqli->prepare($mapQuery);
if ($mysqli->error) {
trigger_error($mysqli->error);
return false;
if (!isset($uid) || !isset($this->maps[$uid])) {
trigger_error("Error while updating Map, unknown UID: " . $uid);
$this->maniaControl->chat->sendError("Error while updating Map.", $admin->login);
return;
}
$mapStatement->bind_param('ssssss', $map->uid, $map->rawName, $map->authorLogin, $map->fileName, $map->environment, $map->mapType);
$mapStatement->execute();
if ($mapStatement->error) {
trigger_error($mapStatement->error);
$mapStatement->close();
return false;
}
$map->index = $mapStatement->insert_id;
$mapStatement->close();
return true;
/** @var Map $map */
$map = $this->maps[$uid];
$mxId = $map->mx->id;
$this->removeMap($admin, $uid, true, false);
$this->addMapFromMx($mxId, $admin->login, true);
}
/**
@ -198,29 +180,6 @@ class MapManager implements CallbackListener {
return true;
}
/**
* Update a Map from Mania Exchange
*
* @param Player $admin
* @param string $uid
*/
public function updateMap(Player $admin, $uid) {
$this->updateMapTimestamp($uid);
if (!isset($uid) || !isset($this->maps[$uid])) {
trigger_error("Error while updating Map, unknown UID: " . $uid);
$this->maniaControl->chat->sendError("Error while updating Map.", $admin->login);
return;
}
/** @var Map $map */
$map = $this->maps[$uid];
$mxId = $map->mx->id;
$this->removeMap($admin, $uid, true, false);
$this->addMapFromMx($mxId, $admin->login, true);
}
/**
* Remove a Map
*
@ -247,7 +206,7 @@ class MapManager implements CallbackListener {
// Remove map
try {
$this->maniaControl->client->removeMap($map->fileName);
} catch(MapNotInCurrentSelectionException $e) {
} catch (MapNotInCurrentSelectionException $e) {
}
@ -273,330 +232,6 @@ class MapManager implements CallbackListener {
unset($this->maps[$uid]);
}
/**
* Restructures the Maplist
*/
public function restructureMapList() {
$currentIndex = $this->getMapIndex($this->currentMap);
// No RestructureNeeded
if ($currentIndex < Maplist::MAX_MAPS_PER_PAGE - 1) {
return true;
}
$lowerMapArray = array();
$higherMapArray = array();
$i = 0;
foreach($this->maps as $map) {
if ($i < $currentIndex) {
$lowerMapArray[] = $map->fileName;
} else {
$higherMapArray[] = $map->fileName;
}
$i++;
}
$mapArray = array_merge($higherMapArray, $lowerMapArray);
array_shift($mapArray);
try {
$this->maniaControl->client->chooseNextMapList($mapArray);
} catch(Exception $e) {
trigger_error("Error while restructuring the Maplist. " . $e->getMessage());
return false;
}
return true;
}
/**
* Shuffles the MapList
*
* @param Player $admin
* @return bool
*/
public function shuffleMapList($admin = null) {
$shuffledMaps = $this->maps;
shuffle($shuffledMaps);
$mapArray = array();
foreach($shuffledMaps as $map) {
/**
* @var Map $map
*/
$mapArray[] = $map->fileName;
}
try {
$this->maniaControl->client->chooseNextMapList($mapArray);
} catch(Exception $e) {
//TODO temp added 19.04.2014
$this->maniaControl->errorHandler->triggerDebugNotice("Exception line 331 MapManager" . $e->getMessage());
trigger_error("Couldn't shuffle mapList. " . $e->getMessage());
return false;
}
$this->fetchCurrentMap();
if ($admin) {
$message = '$<' . $admin->nickname . '$> shuffled the Maplist!';
$this->maniaControl->chat->sendSuccess($message);
$this->maniaControl->log($message, true);
}
// Restructure if needed
$this->restructureMapList();
return true;
}
/**
* Initializes a Map
*
* @param $rpcMap
* @return Map
*/
public function initializeMap($rpcMap) {
$map = new Map($rpcMap);
$this->saveMap($map);
/*$mapsDirectory = $this->maniaControl->server->getMapsDirectory();
if (is_readable($mapsDirectory . $map->fileName)) {
$mapFetcher = new \GBXChallMapFetcher(true);
$mapFetcher->processFile($mapsDirectory . $map->fileName);
$map->authorNick = FORMATTER::stripDirtyCodes($mapFetcher->authorNick);
$map->authorEInfo = $mapFetcher->authorEInfo;
$map->authorZone = $mapFetcher->authorZone;
$map->comment = $mapFetcher->comment;
}*/
return $map;
}
/**
* Updates the full Map list, needed on Init, addMap and on ShuffleMaps
*/
private function updateFullMapList() {
$tempList = array();
try {
$i = 0;
while(true) {
$maps = $this->maniaControl->client->getMapList(150, $i);
foreach($maps as $rpcMap) {
if (array_key_exists($rpcMap->uId, $this->maps)) {
// Map already exists, only update index
$tempList[$rpcMap->uId] = $this->maps[$rpcMap->uId];
} else { // Insert Map Object
$map = $this->initializeMap($rpcMap);
$tempList[$map->uid] = $map;
}
}
$i += 150;
}
} catch(StartIndexOutOfBoundException $e) {
}
// restore Sorted MapList
$this->maps = $tempList;
// Trigger own callback
$this->maniaControl->callbackManager->triggerCallback(self::CB_MAPS_UPDATED);
// Write MapList
if ($this->maniaControl->settingManager->getSetting($this, self::SETTING_AUTOSAVE_MAPLIST)) {
try {
$this->maniaControl->client->saveMatchSettings($this->maniaControl->settingManager->getSetting($this, self::SETTING_MAPLIST_FILE));
} catch(CouldNotWritePlaylistFileException $e) {
$this->maniaControl->log("Unable to write the playlist file, please checkout your MX-Folders File permissions!");
}
}
}
/**
* Freshly fetch current Map
*
* @return Map
*/
private function fetchCurrentMap() {
$rpcMap = $this->maniaControl->client->getCurrentMapInfo();
if (array_key_exists($rpcMap->uId, $this->maps)) {
$this->currentMap = $this->maps[$rpcMap->uId];
$this->currentMap->nbCheckpoints = $rpcMap->nbCheckpoints;
$this->currentMap->nbLaps = $rpcMap->nbLaps;
return $this->currentMap;
}
$this->currentMap = $this->initializeMap($rpcMap);
$this->maps[$this->currentMap->uid] = $this->currentMap;
return $this->currentMap;
}
/**
* Handle OnInit callback
*/
public function handleOnInit() {
$this->updateFullMapList();
$this->fetchCurrentMap();
// Restructure Maplist
$this->restructureMapList();
}
/**
* Handle AfterInit callback
*/
public function handleAfterInit() {
// Fetch MX infos
$this->mxManager->fetchManiaExchangeMapInformations();
}
/**
* Get Current Map
*
* @return Map currentMap
*/
public function getCurrentMap() {
if (!$this->currentMap) {
return $this->fetchCurrentMap();
}
return $this->currentMap;
}
/**
* Returns map By UID
*
* @param $uid
* @return Map array
*/
public function getMapByUid($uid) {
if (!isset($this->maps[$uid])) {
return null;
}
return $this->maps[$uid];
}
/**
* Handle BeginMap callback
*
* @param array $callback
*/
public function handleBeginMap(array $callback) {
if ($this->mapBegan) {
return;
}
$this->mapBegan = true;
$this->mapEnded = false;
if (!isset($callback[1][0]["UId"])) {
$this->currentMap = $this->fetchCurrentMap();
} else if (array_key_exists($callback[1][0]["UId"], $this->maps)) {
// Map already exists, only update index
$this->currentMap = $this->maps[$callback[1][0]["UId"]];
if (!$this->currentMap->nbCheckpoints || !$this->currentMap->nbLaps) {
$rpcMap = $this->maniaControl->client->getCurrentMapInfo();
$this->currentMap->nbLaps = $rpcMap->nbLaps;
$this->currentMap->nbCheckpoints = $rpcMap->nbCheckpoints;
}
}
// Restructure MapList if id is over 15
$this->restructureMapList();
// Update the mx of the map (for update checks, etc.)
$this->mxManager->fetchManiaExchangeMapInformations($this->currentMap);
// Trigger own BeginMap callback (
//TODO remove deprecated callback later
$this->maniaControl->callbackManager->triggerCallback(self::CB_BEGINMAP, $this->currentMap);
$this->maniaControl->callbackManager->triggerCallback(Callbacks::BEGINMAP, $this->currentMap);
}
/**
* Handle Script BeginMap callback
*
* @param int $mapNumber
*/
public function handleScriptBeginMap($mapNumber) {
$this->handleBeginMap(array());
}
/**
* Handle EndMap Callback
*
* @param array $callback
*/
public function handleEndMap(array $callback) {
if ($this->mapEnded) {
return;
}
$this->mapEnded = true;
$this->mapBegan = false;
// Trigger own EndMap callback
$this->maniaControl->callbackManager->triggerCallback(self::CB_ENDMAP, $this->currentMap);
//TODO remove deprecated callback later
$this->maniaControl->callbackManager->triggerCallback(Callbacks::ENDMAP, $this->currentMap);
}
/**
* Handle Script EndMap Callback
*
* @param int $mapNumber
*/
public function handleScriptEndMap($mapNumber) {
$this->handleEndMap(array());
}
/**
* Handle Maps Modified Callback
*
* @param array $callback
*/
public function mapsModified(array $callback) {
$this->updateFullMapList();
}
/**
* Get all Maps
*
* @param int $offset
* @param int $length
* @return array
*/
public function getMaps($offset = null, $length = null) {
if ($offset === null) {
return array_values($this->maps);
}
if ($length === null) {
return array_slice($this->maps, $offset);
}
return array_slice($this->maps, $offset, $length);
}
/**
* Get the Number of Maps
*
* @return int
*/
public function getMapsCount() {
return count($this->maps);
}
/**
* Returns the MapIndex of a given map
*
* @param Map $map
* @internal param $uid
* @return mixed
*/
public function getMapIndex(Map $map) {
$maps = $this->getMaps();
return array_search($map, $maps);
}
/**
* Adds a Map from Mania Exchange
*
@ -672,7 +307,7 @@ class MapManager implements CallbackListener {
// Write map via write file method
try {
$this->maniaControl->client->writeFileFromString($relativeMapFileName, $file);
} catch(InvalidArgumentException $e) {
} catch (InvalidArgumentException $e) {
if ($e->getMessage() == 'data are too big') {
$this->maniaControl->chat->sendError("Map is too big for a remote save.", $login);
return;
@ -684,7 +319,7 @@ class MapManager implements CallbackListener {
// Check for valid map
try {
$this->maniaControl->client->checkMapForCurrentServerParams($relativeMapFileName);
} catch(MapNotCompatibleOrCompleteException $e) {
} catch (MapNotCompatibleOrCompleteException $e) {
trigger_error("Couldn't check if map is valid ('{$relativeMapFileName}'). " . $e->getMessage());
$this->maniaControl->chat->sendError('Wrong MapType or not validated!', $login);
return;
@ -719,5 +354,370 @@ class MapManager implements CallbackListener {
$this->maniaControl->log($message, true);
}
}
/**
* Returns map By UID
*
* @param $uid
* @return Map array
*/
public function getMapByUid($uid) {
if (!isset($this->maps[$uid])) {
return null;
}
return $this->maps[$uid];
}
/**
* Updates the full Map list, needed on Init, addMap and on ShuffleMaps
*/
private function updateFullMapList() {
$tempList = array();
try {
$i = 0;
while (true) {
$maps = $this->maniaControl->client->getMapList(150, $i);
foreach ($maps as $rpcMap) {
if (array_key_exists($rpcMap->uId, $this->maps)) {
// Map already exists, only update index
$tempList[$rpcMap->uId] = $this->maps[$rpcMap->uId];
} else { // Insert Map Object
$map = $this->initializeMap($rpcMap);
$tempList[$map->uid] = $map;
}
}
$i += 150;
}
} catch (StartIndexOutOfBoundException $e) {
}
// restore Sorted MapList
$this->maps = $tempList;
// Trigger own callback
$this->maniaControl->callbackManager->triggerCallback(self::CB_MAPS_UPDATED);
// Write MapList
if ($this->maniaControl->settingManager->getSetting($this, self::SETTING_AUTOSAVE_MAPLIST)) {
try {
$this->maniaControl->client->saveMatchSettings($this->maniaControl->settingManager->getSetting($this, self::SETTING_MAPLIST_FILE));
} catch (CouldNotWritePlaylistFileException $e) {
$this->maniaControl->log("Unable to write the playlist file, please checkout your MX-Folders File permissions!");
}
}
}
/**
* Initializes a Map
*
* @param $rpcMap
* @return Map
*/
public function initializeMap($rpcMap) {
$map = new Map($rpcMap);
$this->saveMap($map);
/*$mapsDirectory = $this->maniaControl->server->getMapsDirectory();
if (is_readable($mapsDirectory . $map->fileName)) {
$mapFetcher = new \GBXChallMapFetcher(true);
$mapFetcher->processFile($mapsDirectory . $map->fileName);
$map->authorNick = FORMATTER::stripDirtyCodes($mapFetcher->authorNick);
$map->authorEInfo = $mapFetcher->authorEInfo;
$map->authorZone = $mapFetcher->authorZone;
$map->comment = $mapFetcher->comment;
}*/
return $map;
}
/**
* Save a Map in the Database
*
* @param \ManiaControl\Maps\Map $map
* @return bool
*/
private function saveMap(Map &$map) {
//TODO saveMaps for whole maplist at once (usage of prepared statements)
$mysqli = $this->maniaControl->database->mysqli;
$mapQuery = "INSERT INTO `" . self::TABLE_MAPS . "` (
`uid`,
`name`,
`authorLogin`,
`fileName`,
`environment`,
`mapType`
) VALUES (
?, ?, ?, ?, ?, ?
) ON DUPLICATE KEY UPDATE
`index` = LAST_INSERT_ID(`index`),
`fileName` = VALUES(`fileName`),
`environment` = VALUES(`environment`),
`mapType` = VALUES(`mapType`);";
$mapStatement = $mysqli->prepare($mapQuery);
if ($mysqli->error) {
trigger_error($mysqli->error);
return false;
}
$mapStatement->bind_param('ssssss', $map->uid, $map->rawName, $map->authorLogin, $map->fileName, $map->environment, $map->mapType);
$mapStatement->execute();
if ($mapStatement->error) {
trigger_error($mapStatement->error);
$mapStatement->close();
return false;
}
$map->index = $mapStatement->insert_id;
$mapStatement->close();
return true;
}
/**
* Shuffles the MapList
*
* @param Player $admin
* @return bool
*/
public function shuffleMapList($admin = null) {
$shuffledMaps = $this->maps;
shuffle($shuffledMaps);
$mapArray = array();
foreach ($shuffledMaps as $map) {
/**
* @var Map $map
*/
$mapArray[] = $map->fileName;
}
try {
$this->maniaControl->client->chooseNextMapList($mapArray);
} catch (Exception $e) {
//TODO temp added 19.04.2014
$this->maniaControl->errorHandler->triggerDebugNotice("Exception line 331 MapManager" . $e->getMessage());
trigger_error("Couldn't shuffle mapList. " . $e->getMessage());
return false;
}
$this->fetchCurrentMap();
if ($admin) {
$message = '$<' . $admin->nickname . '$> shuffled the Maplist!';
$this->maniaControl->chat->sendSuccess($message);
$this->maniaControl->log($message, true);
}
// Restructure if needed
$this->restructureMapList();
return true;
}
/**
* Freshly fetch current Map
*
* @return Map
*/
private function fetchCurrentMap() {
$rpcMap = $this->maniaControl->client->getCurrentMapInfo();
if (array_key_exists($rpcMap->uId, $this->maps)) {
$this->currentMap = $this->maps[$rpcMap->uId];
$this->currentMap->nbCheckpoints = $rpcMap->nbCheckpoints;
$this->currentMap->nbLaps = $rpcMap->nbLaps;
return $this->currentMap;
}
$this->currentMap = $this->initializeMap($rpcMap);
$this->maps[$this->currentMap->uid] = $this->currentMap;
return $this->currentMap;
}
/**
* Restructures the Maplist
*/
public function restructureMapList() {
$currentIndex = $this->getMapIndex($this->currentMap);
// No RestructureNeeded
if ($currentIndex < Maplist::MAX_MAPS_PER_PAGE - 1) {
return true;
}
$lowerMapArray = array();
$higherMapArray = array();
$i = 0;
foreach ($this->maps as $map) {
if ($i < $currentIndex) {
$lowerMapArray[] = $map->fileName;
} else {
$higherMapArray[] = $map->fileName;
}
$i++;
}
$mapArray = array_merge($higherMapArray, $lowerMapArray);
array_shift($mapArray);
try {
$this->maniaControl->client->chooseNextMapList($mapArray);
} catch (Exception $e) {
trigger_error("Error while restructuring the Maplist. " . $e->getMessage());
return false;
}
return true;
}
/**
* Returns the MapIndex of a given map
*
* @param Map $map
* @internal param $uid
* @return mixed
*/
public function getMapIndex(Map $map) {
$maps = $this->getMaps();
return array_search($map, $maps);
}
/**
* Get all Maps
*
* @param int $offset
* @param int $length
* @return array
*/
public function getMaps($offset = null, $length = null) {
if ($offset === null) {
return array_values($this->maps);
}
if ($length === null) {
return array_slice($this->maps, $offset);
}
return array_slice($this->maps, $offset, $length);
}
/**
* Handle OnInit callback
*/
public function handleOnInit() {
$this->updateFullMapList();
$this->fetchCurrentMap();
// Restructure Maplist
$this->restructureMapList();
}
/**
* Handle AfterInit callback
*/
public function handleAfterInit() {
// Fetch MX infos
$this->mxManager->fetchManiaExchangeMapInformations();
}
/**
* Get Current Map
*
* @return Map currentMap
*/
public function getCurrentMap() {
if (!$this->currentMap) {
return $this->fetchCurrentMap();
}
return $this->currentMap;
}
/**
* Handle Script BeginMap callback
*
* @param int $mapNumber
*/
public function handleScriptBeginMap($mapNumber) {
$this->handleBeginMap(array());
}
/**
* Handle BeginMap callback
*
* @param array $callback
*/
public function handleBeginMap(array $callback) {
if ($this->mapBegan) {
return;
}
$this->mapBegan = true;
$this->mapEnded = false;
if (!isset($callback[1][0]["UId"])) {
$this->currentMap = $this->fetchCurrentMap();
} else if (array_key_exists($callback[1][0]["UId"], $this->maps)) {
// Map already exists, only update index
$this->currentMap = $this->maps[$callback[1][0]["UId"]];
if (!$this->currentMap->nbCheckpoints || !$this->currentMap->nbLaps) {
$rpcMap = $this->maniaControl->client->getCurrentMapInfo();
$this->currentMap->nbLaps = $rpcMap->nbLaps;
$this->currentMap->nbCheckpoints = $rpcMap->nbCheckpoints;
}
}
// Restructure MapList if id is over 15
$this->restructureMapList();
// Update the mx of the map (for update checks, etc.)
$this->mxManager->fetchManiaExchangeMapInformations($this->currentMap);
// Trigger own BeginMap callback (
//TODO remove deprecated callback later
$this->maniaControl->callbackManager->triggerCallback(self::CB_BEGINMAP, $this->currentMap);
$this->maniaControl->callbackManager->triggerCallback(Callbacks::BEGINMAP, $this->currentMap);
}
/**
* Handle Script EndMap Callback
*
* @param int $mapNumber
*/
public function handleScriptEndMap($mapNumber) {
$this->handleEndMap(array());
}
/**
* Handle EndMap Callback
*
* @param array $callback
*/
public function handleEndMap(array $callback) {
if ($this->mapEnded) {
return;
}
$this->mapEnded = true;
$this->mapBegan = false;
// Trigger own EndMap callback
$this->maniaControl->callbackManager->triggerCallback(self::CB_ENDMAP, $this->currentMap);
//TODO remove deprecated callback later
$this->maniaControl->callbackManager->triggerCallback(Callbacks::ENDMAP, $this->currentMap);
}
/**
* Handle Maps Modified Callback
*
* @param array $callback
*/
public function mapsModified(array $callback) {
$this->updateFullMapList();
}
/**
* Get the Number of Maps
*
* @return int
*/
public function getMapsCount() {
return count($this->maps);
}
// TODO: add local map by filename
}

View File

@ -14,9 +14,9 @@ use ManiaControl\Players\Player;
/**
* MapQueue Class
*
* @author steeffeen & kremsy
* @copyright ManiaControl Copyright © 2014 ManiaControl Team
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
* @author ManiaControl Team <mail@maniacontrol.com>
* @copyright 2014 ManiaControl Team
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
*/
class MapQueue implements CallbackListener, CommandListener {
/*
@ -34,7 +34,7 @@ class MapQueue implements CallbackListener, CommandListener {
const ADMIN_COMMAND_CLEAR_MAPQUEUE = 'clearmapqueue';
const ADMIN_COMMAND_CLEAR_JUKEBOX = 'clearjukebox';
/*
* Private Properties
*/
@ -75,7 +75,7 @@ class MapQueue implements CallbackListener, CommandListener {
* Adds current map to buffer on startup
*/
public function handleAfterInit() {
$currentMap = $this->maniaControl->mapManager->getCurrentMap();
$currentMap = $this->maniaControl->mapManager->getCurrentMap();
$this->buffer[] = $currentMap->uid;
}
@ -90,6 +90,34 @@ class MapQueue implements CallbackListener, CommandListener {
$this->clearMapQueue($admin);
}
/**
* Clears the Map Queue
*
* @param $admin
*/
public function clearMapQueue($admin) {
if (!$this->maniaControl->authenticationManager->checkPermission($admin, self::SETTING_PERMISSION_CLEAR_MAPQUEUE)) {
$this->maniaControl->authenticationManager->sendNotAllowed($admin);
return;
}
if (count($this->queuedMaps) == 0) {
$this->maniaControl->chat->sendError('$fa0There are no maps in the jukebox!', $admin->login);
return;
}
$title = $this->maniaControl->authenticationManager->getAuthLevelName($admin->authLevel);
//Destroy map - queue list
$this->queuedMaps = array();
$this->maniaControl->chat->sendInformation('$fa0' . $title . ' $<$fff' . $admin->nickname . '$> cleared the Queued-Map list!');
$this->maniaControl->log($title . ' ' . Formatter::stripCodes($admin->nickname) . ' cleared the Queued-Map list!');
// Trigger callback
$this->maniaControl->callbackManager->triggerCallback(self::CB_MAPQUEUE_CHANGED, array('clear'));
}
/**
* Handles the mapqueue/jukebox command
*
@ -99,12 +127,12 @@ class MapQueue implements CallbackListener, CommandListener {
public function command_MapQueue(array $chat, Player $player) {
$chatCommands = explode(' ', $chat[1][2]);
if(isset($chatCommands[1])) {
if($chatCommands[1] == ' ' || $chatCommands[1] == 'list') {
if (isset($chatCommands[1])) {
if ($chatCommands[1] == ' ' || $chatCommands[1] == 'list') {
$this->showMapQueue($player);
} elseif($chatCommands[1] == 'display') {
} elseif ($chatCommands[1] == 'display') {
$this->showMapQueueManialink($player);
} elseif($chatCommands[1] == 'clear') {
} elseif ($chatCommands[1] == 'clear') {
$this->clearMapQueue($player);
}
} else {
@ -118,15 +146,15 @@ class MapQueue implements CallbackListener, CommandListener {
* @param $player
*/
public function showMapQueue($player) {
if(count($this->queuedMaps) == 0) {
if (count($this->queuedMaps) == 0) {
$this->maniaControl->chat->sendError('$fa0There are no maps in the jukebox!', $player->login);
return;
}
$message = '$fa0Upcoming maps in the Map-Queue:';
$i = 1;
foreach($this->queuedMaps as $queuedMap) {
$message .= ' $<$fff'.$i.'$>. [$<$fff'.Formatter::stripCodes($queuedMap[1]->name).'$>]';
$i = 1;
foreach ($this->queuedMaps as $queuedMap) {
$message .= ' $<$fff' . $i . '$>. [$<$fff' . Formatter::stripCodes($queuedMap[1]->name) . '$>]';
$i++;
}
@ -139,13 +167,13 @@ class MapQueue implements CallbackListener, CommandListener {
* @param $player
*/
public function showMapQueueManialink($player) {
if(count($this->queuedMaps) == 0) {
if (count($this->queuedMaps) == 0) {
$this->maniaControl->chat->sendError('$fa0There are no maps in the jukebox!', $player->login);
return;
}
$maps = array();
foreach($this->queuedMaps as $queuedMap) {
foreach ($this->queuedMaps as $queuedMap) {
$maps[] = $queuedMap[1];
}
@ -161,34 +189,6 @@ class MapQueue implements CallbackListener, CommandListener {
return $this->buffer;
}
/**
* Clears the Map Queue
*
* @param $admin
*/
public function clearMapQueue($admin) {
if (!$this->maniaControl->authenticationManager->checkPermission($admin, self::SETTING_PERMISSION_CLEAR_MAPQUEUE)) {
$this->maniaControl->authenticationManager->sendNotAllowed($admin);
return;
}
if(count($this->queuedMaps) == 0) {
$this->maniaControl->chat->sendError('$fa0There are no maps in the jukebox!', $admin->login);
return;
}
$title = $this->maniaControl->authenticationManager->getAuthLevelName($admin->authLevel);
//Destroy map - queue list
$this->queuedMaps = array();
$this->maniaControl->chat->sendInformation('$fa0'. $title . ' $<$fff' . $admin->nickname . '$> cleared the Queued-Map list!');
$this->maniaControl->log($title . ' ' . Formatter::stripCodes($admin->nickname) . ' cleared the Queued-Map list!');
// Trigger callback
$this->maniaControl->callbackManager->triggerCallback(self::CB_MAPQUEUE_CHANGED, array('clear'));
}
/**
* Adds map as first map in queue (for /replay)
*
@ -216,15 +216,13 @@ class MapQueue implements CallbackListener, CommandListener {
//Check if player is allowed to add (another) map
$admin = false;
if($this->maniaControl->authenticationManager->checkRight($player, 2) ||
$this->maniaControl->authenticationManager->checkRight($player, 3) ||
$this->maniaControl->authenticationManager->checkRight($player, 4)) {
if ($this->maniaControl->authenticationManager->checkRight($player, 2) || $this->maniaControl->authenticationManager->checkRight($player, 3) || $this->maniaControl->authenticationManager->checkRight($player, 4)) {
$admin = true;
}
$mapsForPlayer = 0;
foreach($this->queuedMaps as $queuedMap) {
if($queuedMap[0]->login == $login) {
foreach ($this->queuedMaps as $queuedMap) {
if ($queuedMap[0]->login == $login) {
$mapsForPlayer++;
}
}
@ -232,14 +230,14 @@ class MapQueue implements CallbackListener, CommandListener {
$maxPlayer = $this->maniaControl->settingManager->getSetting($this, self::SETTING_MAPLIMIT_PLAYER);
$maxAdmin = $this->maniaControl->settingManager->getSetting($this, self::SETTING_MAPLIMIT_ADMIN);
if($admin && $maxAdmin != -1) {
if($mapsForPlayer == $maxAdmin) {
$this->maniaControl->chat->sendError('You already have $<$fff'.$maxAdmin.'$> map(s) in the Map-Queue!', $login);
if ($admin && $maxAdmin != -1) {
if ($mapsForPlayer == $maxAdmin) {
$this->maniaControl->chat->sendError('You already have $<$fff' . $maxAdmin . '$> map(s) in the Map-Queue!', $login);
return;
}
} elseif(!$admin && $maxPlayer != -1) {
if($mapsForPlayer == $maxPlayer) {
$this->maniaControl->chat->sendError('You already have $<$fff'.$maxPlayer.'$> map(s) in the Map-Queue!', $login);
} elseif (!$admin && $maxPlayer != -1) {
if ($mapsForPlayer == $maxPlayer) {
$this->maniaControl->chat->sendError('You already have $<$fff' . $maxPlayer . '$> map(s) in the Map-Queue!', $login);
return;
}
}
@ -252,7 +250,7 @@ class MapQueue implements CallbackListener, CommandListener {
//TODO recently maps not able to add to queue-amps setting, and management
// Check if map is in the buffer
if(in_array($uid, $this->buffer)) {
if (in_array($uid, $this->buffer)) {
$this->maniaControl->chat->sendError('That map has recently been played!', $login);
if (!$this->maniaControl->authenticationManager->checkPermission($player, self::SETTING_PERMISSION_CLEAR_MAPQUEUE)) {
return;
@ -297,10 +295,10 @@ class MapQueue implements CallbackListener, CommandListener {
*/
public function endMap(Map $map) {
$this->nextMap = null;
if ($this->maniaControl->settingManager->getSetting($this, self::SETTING_SKIP_MAP_ON_LEAVE) == TRUE) {
if ($this->maniaControl->settingManager->getSetting($this, self::SETTING_SKIP_MAP_ON_LEAVE) == true) {
//Skip Map if requester has left
foreach($this->queuedMaps as $queuedMap) {
foreach ($this->queuedMaps as $queuedMap) {
$player = $queuedMap[0];
//found player, so play this map
@ -308,7 +306,7 @@ class MapQueue implements CallbackListener, CommandListener {
break;
}
if ($this->maniaControl->settingManager->getSetting($this, self::SETTING_SKIP_MAPQUEUE_ADMIN) == FALSE) {
if ($this->maniaControl->settingManager->getSetting($this, self::SETTING_SKIP_MAPQUEUE_ADMIN) == false) {
//Check if the queuer is a admin
if ($player->authLevel > 0) {
break;
@ -321,7 +319,7 @@ class MapQueue implements CallbackListener, CommandListener {
//Player not found, so remove the map from the mapqueue
array_shift($this->queuedMaps);
$this->maniaControl->chat->sendInformation('$fa0$<$fff' . $queuedMap[0]->name .'$> is skipped because $<' . $player->nickname . '$> left the game!');
$this->maniaControl->chat->sendInformation('$fa0$<$fff' . $queuedMap[0]->name . '$> is skipped because $<' . $player->nickname . '$> left the game!');
}
}
@ -332,7 +330,7 @@ class MapQueue implements CallbackListener, CommandListener {
return;
}
$map = $this->nextMap[1];
$this->maniaControl->chat->sendInformation('$fa0Next map will be $<$fff' . $map->name .'$> as requested by $<' . $this->nextMap[0]->nickname . '$>.');
$this->maniaControl->chat->sendInformation('$fa0Next map will be $<$fff' . $map->name . '$> as requested by $<' . $this->nextMap[0]->nickname . '$>.');
$this->maniaControl->client->chooseNextMap($map->fileName);
}
@ -343,11 +341,11 @@ class MapQueue implements CallbackListener, CommandListener {
* @param Map $map
*/
public function beginMap(Map $map) {
if(in_array($map->uid, $this->buffer)) {
if (in_array($map->uid, $this->buffer)) {
return;
}
if(count($this->buffer) >= $this->maniaControl->settingManager->getSetting($this, self::SETTING_BUFFERSIZE)) {
if (count($this->buffer) >= $this->maniaControl->settingManager->getSetting($this, self::SETTING_BUFFERSIZE)) {
array_shift($this->buffer);
}
@ -370,7 +368,7 @@ class MapQueue implements CallbackListener, CommandListener {
* @return array(Player $player, Map $map)
*/
public function getNextQueuedMap() {
foreach($this->queuedMaps as $queuedMap) {
foreach ($this->queuedMaps as $queuedMap) {
//return the first Queued Map
return $queuedMap;
}
@ -385,7 +383,7 @@ class MapQueue implements CallbackListener, CommandListener {
public function getQueuedMapsRanking() {
$i = 1;
$queuedMaps = array();
foreach($this->queuedMaps as $queuedMap) {
foreach ($this->queuedMaps as $queuedMap) {
$map = $queuedMap[1];
$queuedMaps[$map->uid] = $i;
$i++;
@ -407,7 +405,7 @@ class MapQueue implements CallbackListener, CommandListener {
* Dummy Function for testing
*/
public function printAllMaps() {
foreach($this->queuedMaps as $map) {
foreach ($this->queuedMaps as $map) {
$map = $map[1];
var_dump($map->name);
}