mapqueue improvements

This commit is contained in:
kremsy 2014-01-28 20:09:09 +01:00 committed by Steffen Schröder
parent fc91133f77
commit 9505fdf974
4 changed files with 90 additions and 46 deletions

View File

@ -37,6 +37,7 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
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 ACTION_UNQUEUE_MAP = 'MapList.UnQueueMap';
const ACTION_CHECK_UPDATE = 'MapList.CheckUpdate'; const ACTION_CHECK_UPDATE = 'MapList.CheckUpdate';
const ACTION_CLEAR_MAPQUEUE = 'MapList.ClearMapQueue'; const ACTION_CLEAR_MAPQUEUE = 'MapList.ClearMapQueue';
const MAX_MAPS_PER_PAGE = 15; const MAX_MAPS_PER_PAGE = 15;
@ -122,7 +123,7 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
$maniaLink->add($frame); $maniaLink->add($frame);
//Admin Buttons //Admin Buttons
if ($this->maniaControl->authenticationManager->checkPermission($player, MapManager::SETTING_PERMISSION_ADD_MAP)) { if ($this->maniaControl->authenticationManager->checkPermission($player, MapQueue::SETTING_PERMISSION_CLEAR_MAPQUEUE)) {
//Clear Map-Queue //Clear Map-Queue
$label = new Label_Button(); $label = new Label_Button();
$frame->add($label); $frame->add($label);
@ -280,7 +281,16 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
$label->setTextSize(1.5); $label->setTextSize(1.5);
$label->setText($queuedMaps[$map->uid]); $label->setText($queuedMaps[$map->uid]);
$label->setTextColor('fff'); $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) {
$script->addTooltip($label, $descriptionLabel, array(Script::OPTION_TOOLTIP_TEXT => 'Remove $<' . $map->name . '$> from the Map Queue'));
$label->setAction(self::ACTION_UNQUEUE_MAP . '.' . $map->uid);
} else {
$script->addTooltip($label, $descriptionLabel, array(Script::OPTION_TOOLTIP_TEXT => '$<' . $map->name . '$> is on Map-Queue Position: ' . $queuedMaps[$map->uid])); $script->addTooltip($label, $descriptionLabel, array(Script::OPTION_TOOLTIP_TEXT => '$<' . $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();
@ -292,7 +302,7 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
$queueLabel->setText('+'); $queueLabel->setText('+');
$queueLabel->setTextColor('09f'); $queueLabel->setTextColor('09f');
$script->addTooltip($queueLabel, $descriptionLabel, array(Script::OPTION_TOOLTIP_TEXT => 'Add Map to the Map Queue: $<' . $map->name . '$>')); $script->addTooltip($queueLabel, $descriptionLabel, array(Script::OPTION_TOOLTIP_TEXT => 'Add $<' . $map->name . '$> to the Map Queue'));
} }
if ($this->maniaControl->authenticationManager->checkPermission($player, MapManager::SETTING_PERMISSION_REMOVE_MAP)) { if ($this->maniaControl->authenticationManager->checkPermission($player, MapManager::SETTING_PERMISSION_REMOVE_MAP)) {
@ -504,6 +514,9 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
case self::ACTION_QUEUED_MAP: case self::ACTION_QUEUED_MAP:
$this->maniaControl->mapManager->mapQueue->addMapToMapQueue($callback[1][1], $actionArray[2]); $this->maniaControl->mapManager->mapQueue->addMapToMapQueue($callback[1][1], $actionArray[2]);
break; break;
case self::ACTION_UNQUEUE_MAP:
$this->maniaControl->mapManager->mapQueue->removeFromMapQueue($player, $actionArray[2]);
break;
} }
} }

View File

@ -205,7 +205,7 @@ class MapManager implements CallbackListener {
$map = $this->maps[$uid]; $map = $this->maps[$uid];
//Unset the Map everywhere //Unset the Map everywhere
$this->mapQueue->removeFromMapQueue($admin->login, $map->uid); $this->mapQueue->removeFromMapQueue($admin, $map->uid);
$this->mxManager->unsetMap($map->mx->id); $this->mxManager->unsetMap($map->mx->id);
// Remove map // Remove map

View File

@ -2,6 +2,7 @@
namespace ManiaControl\Maps; namespace ManiaControl\Maps;
use ManiaControl\Admin\AuthenticationManager;
use ManiaControl\Callbacks\CallbackListener; use ManiaControl\Callbacks\CallbackListener;
use ManiaControl\Callbacks\CallbackManager; use ManiaControl\Callbacks\CallbackManager;
use ManiaControl\Commands\CommandListener; use ManiaControl\Commands\CommandListener;
@ -22,6 +23,7 @@ class MapQueue implements CallbackListener, CommandListener {
const SETTING_SKIP_MAP_ON_LEAVE = 'Skip Map when the requester leaves'; const SETTING_SKIP_MAP_ON_LEAVE = 'Skip Map when the requester leaves';
const SETTING_SKIP_MAPQUEUE_ADMIN = 'Skip Map when admin leaves'; const SETTING_SKIP_MAPQUEUE_ADMIN = 'Skip Map when admin leaves';
const SETTING_PERMISSION_CLEAR_MAPQUEUE = 'Clear Mapqueue';
const ADMIN_COMMAND_CLEAR_MAPQUEUE = 'clearmapqueue'; const ADMIN_COMMAND_CLEAR_MAPQUEUE = 'clearmapqueue';
const ADMIN_COMMAND_CLEAR_JUKEBOX = 'clearjukebox'; const ADMIN_COMMAND_CLEAR_JUKEBOX = 'clearjukebox';
@ -46,6 +48,8 @@ class MapQueue implements CallbackListener, CommandListener {
$this->maniaControl->settingManager->initSetting($this, self::SETTING_SKIP_MAP_ON_LEAVE, true); $this->maniaControl->settingManager->initSetting($this, self::SETTING_SKIP_MAP_ON_LEAVE, true);
$this->maniaControl->settingManager->initSetting($this, self::SETTING_SKIP_MAPQUEUE_ADMIN, false); $this->maniaControl->settingManager->initSetting($this, self::SETTING_SKIP_MAPQUEUE_ADMIN, false);
$this->maniaControl->authenticationManager->definePermissionLevel(self::SETTING_PERMISSION_CLEAR_MAPQUEUE, AuthenticationManager::AUTH_LEVEL_MODERATOR);
//Register Admin Commands //Register Admin Commands
$this->maniaControl->commandManager->registerCommandListener(self::ADMIN_COMMAND_CLEAR_JUKEBOX, $this, 'command_ClearMapQueue', true); $this->maniaControl->commandManager->registerCommandListener(self::ADMIN_COMMAND_CLEAR_JUKEBOX, $this, 'command_ClearMapQueue', true);
$this->maniaControl->commandManager->registerCommandListener(self::ADMIN_COMMAND_CLEAR_MAPQUEUE, $this, 'command_ClearMapQueue', true); $this->maniaControl->commandManager->registerCommandListener(self::ADMIN_COMMAND_CLEAR_MAPQUEUE, $this, 'command_ClearMapQueue', true);
@ -67,6 +71,11 @@ class MapQueue implements CallbackListener, CommandListener {
* @param $admin * @param $admin
*/ */
public function clearMapQueue($admin) { public function clearMapQueue($admin) {
if (!$this->maniaControl->authenticationManager->checkPermission($admin, self::SETTING_PERMISSION_CLEAR_MAPQUEUE)) {
$this->maniaControl->authenticationManager->sendNotAllowed($admin);
return;
}
$title = $this->maniaControl->authenticationManager->getAuthLevelName($admin->authLevel); $title = $this->maniaControl->authenticationManager->getAuthLevelName($admin->authLevel);
//Destroy map - queue list //Destroy map - queue list
@ -90,7 +99,7 @@ class MapQueue implements CallbackListener, CommandListener {
$player = $this->maniaControl->playerManager->getPlayer($login); $player = $this->maniaControl->playerManager->getPlayer($login);
//Check if the map is already juked //Check if the map is already juked
if(array_key_exists($uid, $this->queuedMaps)) { if (array_key_exists($uid, $this->queuedMaps)) {
$this->maniaControl->chat->sendError('Map is already in the Map-Queue', $login); $this->maniaControl->chat->sendError('Map is already in the Map-Queue', $login);
return; return;
} }
@ -105,17 +114,26 @@ class MapQueue implements CallbackListener, CommandListener {
// Trigger callback // Trigger callback
$this->maniaControl->callbackManager->triggerCallback(self::CB_MAPQUEUE_CHANGED, array('add', $this->queuedMaps[$uid])); $this->maniaControl->callbackManager->triggerCallback(self::CB_MAPQUEUE_CHANGED, array('add', $this->queuedMaps[$uid]));
} }
/** /**
* Revmoes a Map from the Map queue * Revmoes a Map from the Map queue
* *
* @param $login * @param \ManiaControl\Players\Player $player
* @param $uid * @param $uid
* @internal param $login
*/ */
public function removeFromMapQueue($login, $uid) { public function removeFromMapQueue(Player $player, $uid) {
if (!isset($this->queuedMaps[$uid])) {
return;
}
$map = $this->queuedMaps[$uid][1];
unset($this->queuedMaps[$uid]); unset($this->queuedMaps[$uid]);
$this->maniaControl->chat->sendInformation('$<' . $player->nickname . '$> removed $<' . $map->name . '$> from the Map Queue');
// Trigger callback
$this->maniaControl->callbackManager->triggerCallback(self::CB_MAPQUEUE_CHANGED, array('remove', $map));
} }
@ -126,20 +144,20 @@ class MapQueue implements CallbackListener, CommandListener {
*/ */
public function endMap(array $callback) { public function endMap(array $callback) {
$this->nextMap = null; $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 //Skip Map if requester has left
foreach($this->queuedMaps as $queuedMap) { foreach($this->queuedMaps as $queuedMap) {
$player = $queuedMap[0]; $player = $queuedMap[0];
//found player, so play this map //found player, so play this map
if($this->maniaControl->playerManager->getPlayer($player->login) != null) { if ($this->maniaControl->playerManager->getPlayer($player->login) != null) {
break; 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 //Check if the queuer is a admin
if($player->authLevel > 0) { if ($player->authLevel > 0) {
break; break;
} }
} }
@ -157,16 +175,16 @@ class MapQueue implements CallbackListener, CommandListener {
$this->nextMap = array_shift($this->queuedMaps); $this->nextMap = array_shift($this->queuedMaps);
//Check if Map Queue is empty //Check if Map Queue is empty
if($this->nextMap == null) { if ($this->nextMap == null) {
return; return;
} }
$map = $this->nextMap[1]; $map = $this->nextMap[1];
$success = $this->maniaControl->client->chooseNextMap($map->fileName); try {
if(!$success) { //TODO error code? $this->maniaControl->client->chooseNextMap($map->fileName);
//trigger_error('[' . $this->maniaControl->client->getErrorCode() . '] ChooseNextMap - ' . $this->maniaControl->client->getErrorCode(), E_USER_WARNING); } catch(\Exception $e) {
return; //do nothing
} }
} }
@ -209,6 +227,16 @@ class MapQueue implements CallbackListener, CommandListener {
return $queuedMaps; return $queuedMaps;
} }
/**
* Returns the Queuer of a Map
*
* @param $uid
* @return mixed
*/
public function getQueuer($uid) {
return $this->queuedMaps[$uid][0];
}
/** /**
* Dummy Function for testing * Dummy Function for testing
*/ */

View File

@ -3,7 +3,6 @@ use FML\Controls\Frame;
use FML\Controls\Labels\Label_Button; use FML\Controls\Labels\Label_Button;
use FML\Controls\Labels\Label_Text; use FML\Controls\Labels\Label_Text;
use FML\Controls\Quad; use FML\Controls\Quad;
use FML\Controls\Quads\Quad_Icons64x64_1; use FML\Controls\Quads\Quad_Icons64x64_1;
use FML\ManiaLink; use FML\ManiaLink;
use ManiaControl\Callbacks\CallbackListener; use ManiaControl\Callbacks\CallbackListener;
@ -74,7 +73,7 @@ class QueuePlugin implements CallbackListener, CommandListener, ManialinkPageAns
$this->maniaControl->settingManager->initSetting($this, self::QUEUE_MAX, 8); $this->maniaControl->settingManager->initSetting($this, self::QUEUE_MAX, 8);
foreach($this->maniaControl->playerManager->getPlayers() as $player) { foreach($this->maniaControl->playerManager->getPlayers() as $player) {
if($player->isSpectator) { if ($player->isSpectator) {
$this->spectators[$player->login] = $player->login; $this->spectators[$player->login] = $player->login;
$this->maniaControl->client->forceSpectator($player->login, 1); $this->maniaControl->client->forceSpectator($player->login, 1);
$this->showJoinQueueWidget($player); $this->showJoinQueueWidget($player);
@ -158,12 +157,12 @@ class QueuePlugin implements CallbackListener, CommandListener, ManialinkPageAns
$login = $callback[1]->login; $login = $callback[1]->login;
$player = $this->maniaControl->playerManager->getPlayer($login); $player = $this->maniaControl->playerManager->getPlayer($login);
if($player->isSpectator) { if ($player->isSpectator) {
$this->spectators[$player->login] = $player->login; $this->spectators[$player->login] = $player->login;
$this->maniaControl->client->forceSpectator($player->login, 1); $this->maniaControl->client->forceSpectator($player->login, 1);
$this->showJoinQueueWidget($player); $this->showJoinQueueWidget($player);
} else { } else {
if(count($this->queue) != 0) { if (count($this->queue) != 0) {
$this->maniaControl->client->forceSpectator($player->login, 1); $this->maniaControl->client->forceSpectator($player->login, 1);
$this->spectators[$player->login] = $player->login; $this->spectators[$player->login] = $player->login;
$this->showJoinQueueWidget($player); $this->showJoinQueueWidget($player);
@ -179,7 +178,7 @@ class QueuePlugin implements CallbackListener, CommandListener, ManialinkPageAns
public function handlePlayerDisconnect(array $callback) { public function handlePlayerDisconnect(array $callback) {
/** @var Player $player */ /** @var Player $player */
$player = $callback[1]; $player = $callback[1];
if(isset($this->spectators[$player->login])) { if (isset($this->spectators[$player->login])) {
unset($this->spectators[$player->login]); unset($this->spectators[$player->login]);
} }
$this->removePlayerFromQueue($player->login); $this->removePlayerFromQueue($player->login);
@ -195,25 +194,29 @@ class QueuePlugin implements CallbackListener, CommandListener, ManialinkPageAns
$login = $callback[1][0]['Login']; $login = $callback[1][0]['Login'];
$player = $this->maniaControl->playerManager->getPlayer($login); $player = $this->maniaControl->playerManager->getPlayer($login);
if(!is_null($player)) { if (!is_null($player)) {
if($player->isSpectator) { if ($player->isSpectator) {
if(!isset($this->spectators[$player->login])) { if (!isset($this->spectators[$player->login])) {
$this->maniaControl->client->forceSpectator($player->login, 1); $this->maniaControl->client->forceSpectator($player->login, 1);
$this->spectators[$player->login] = $player->login; $this->spectators[$player->login] = $player->login;
$this->showJoinQueueWidget($player); $this->showJoinQueueWidget($player);
} }
} else { } else {
$this->removePlayerFromQueue($player->login); $this->removePlayerFromQueue($player->login);
if(isset($this->spectators[$player->login])) unset($this->spectators[$player->login]); if (isset($this->spectators[$player->login])) {
unset($this->spectators[$player->login]);
}
$found = false; $found = false;
foreach($this->showPlay as $showPlay) { foreach($this->showPlay as $showPlay) {
if($showPlay['player']->login == $player->login) { if ($showPlay['player']->login == $player->login) {
$found = true; $found = true;
} }
} }
if(!$found) $this->hideQueueWidget($player); if (!$found) {
$this->hideQueueWidget($player);
}
} }
} }
} }
@ -222,7 +225,7 @@ class QueuePlugin implements CallbackListener, CommandListener, ManialinkPageAns
* Function called on every second. * Function called on every second.
*/ */
public function handleEverySecond() { public function handleEverySecond() {
if($this->maniaControl->client->getMaxPlayers()['CurrentValue'] > (count($this->maniaControl->playerManager->players)-count($this->spectators))) { if ($this->maniaControl->client->getMaxPlayers()['CurrentValue'] > (count($this->maniaControl->playerManager->players) - count($this->spectators))) {
$this->moveFirstPlayerToPlay(); $this->moveFirstPlayerToPlay();
} }
@ -232,7 +235,7 @@ class QueuePlugin implements CallbackListener, CommandListener, ManialinkPageAns
} }
foreach($this->showPlay as $showPlay) { foreach($this->showPlay as $showPlay) {
if(($showPlay['time'] + 5) < time()) { if (($showPlay['time'] + 5) < time()) {
$this->hideQueueWidget($showPlay['player']); $this->hideQueueWidget($showPlay['player']);
unset($this->showPlay[$showPlay['player']->login]); unset($this->showPlay[$showPlay['player']->login]);
} }
@ -265,7 +268,7 @@ class QueuePlugin implements CallbackListener, CommandListener, ManialinkPageAns
* Function used to move the first queued player to the * Function used to move the first queued player to the
*/ */
private function moveFirstPlayerToPlay() { private function moveFirstPlayerToPlay() {
if(count($this->queue) > 0) { if (count($this->queue) > 0) {
$firstPlayer = $this->maniaControl->playerManager->getPlayer($this->queue[0]->login); $firstPlayer = $this->maniaControl->playerManager->getPlayer($this->queue[0]->login);
$this->forcePlayerToPlay($firstPlayer); $this->forcePlayerToPlay($firstPlayer);
} }
@ -277,10 +280,10 @@ class QueuePlugin implements CallbackListener, CommandListener, ManialinkPageAns
* @param Player $player * @param Player $player
*/ */
private function forcePlayerToPlay(Player $player) { private function forcePlayerToPlay(Player $player) {
if($this->maniaControl->client->getMaxPlayers()['CurrentValue'] > count($this->maniaControl->playerManager->players)) { if ($this->maniaControl->client->getMaxPlayers()['CurrentValue'] > count($this->maniaControl->playerManager->players)) {
$this->maniaControl->client->forceSpectator($player->login, 2); $this->maniaControl->client->forceSpectator($player->login, 2);
$this->maniaControl->client->forceSpectator($player->login, 0); $this->maniaControl->client->forceSpectator($player->login, 0);
if(isset($this->spectators[$player->login])) { if (isset($this->spectators[$player->login])) {
unset($this->spectators[$player->login]); unset($this->spectators[$player->login]);
} }
$this->removePlayerFromQueue($player->login); $this->removePlayerFromQueue($player->login);
@ -297,13 +300,13 @@ class QueuePlugin implements CallbackListener, CommandListener, ManialinkPageAns
*/ */
private function addPlayerToQueue(Player $player) { private function addPlayerToQueue(Player $player) {
foreach($this->queue as $queuedPlayer) { foreach($this->queue as $queuedPlayer) {
if($queuedPlayer->login == $player->login) { if ($queuedPlayer->login == $player->login) {
$this->maniaControl->chat->sendError('You\'re already in the queue!', $player->login); $this->maniaControl->chat->sendError('You\'re already in the queue!', $player->login);
return false; return false;
} }
} }
if($this->maniaControl->settingManager->getSetting($this, self::QUEUE_MAX) > count($this->queue)) { if ($this->maniaControl->settingManager->getSetting($this, self::QUEUE_MAX) > count($this->queue)) {
$this->queue[count($this->queue)] = $player; $this->queue[count($this->queue)] = $player;
$this->maniaControl->chat->sendChat('$z$s$090[Queue] $<$fff' . $player->nickname . '$> just joined the queue!'); $this->maniaControl->chat->sendChat('$z$s$090[Queue] $<$fff' . $player->nickname . '$> just joined the queue!');
} }
@ -318,7 +321,7 @@ class QueuePlugin implements CallbackListener, CommandListener, ManialinkPageAns
$count = 0; $count = 0;
$newQueue = array(); $newQueue = array();
foreach($this->queue as $queuePlayer) { foreach($this->queue as $queuePlayer) {
if($queuePlayer->login != $login) { if ($queuePlayer->login != $login) {
$newQueue[$count] = $queuePlayer; $newQueue[$count] = $queuePlayer;
$count++; $count++;
} }
@ -375,17 +378,17 @@ class QueuePlugin implements CallbackListener, CommandListener, ManialinkPageAns
$inQueue = false; $inQueue = false;
foreach($this->queue as $queuedPlayer) { foreach($this->queue as $queuedPlayer) {
if($queuedPlayer->login == $player->login) { if ($queuedPlayer->login == $player->login) {
$inQueue = true; $inQueue = true;
} }
} }
if($inQueue) { if ($inQueue) {
$message = '$fff$sYou\'re in the queue (click to unqueue).'; $message = '$fff$sYou\'re in the queue (click to unqueue).';
$position = 0; $position = 0;
foreach(array_values($this->queue) as $i => $queuePlayer) { foreach(array_values($this->queue) as $i => $queuePlayer) {
if($player->login == $queuePlayer->login) { if ($player->login == $queuePlayer->login) {
$position = ($i + 1); $position = ($i + 1);
} }
} }
@ -396,7 +399,7 @@ class QueuePlugin implements CallbackListener, CommandListener, ManialinkPageAns
$statusLabel->setAction(self::ML_REMOVEFROMQUEUE); $statusLabel->setAction(self::ML_REMOVEFROMQUEUE);
$cameraQuad->setAction(self::ML_REMOVEFROMQUEUE); $cameraQuad->setAction(self::ML_REMOVEFROMQUEUE);
} else { } else {
if(count($this->queue) < $max_queue) { if (count($this->queue) < $max_queue) {
$message = '$0ff$sClick to join spectator waiting list.'; $message = '$0ff$sClick to join spectator waiting list.';
$messageLabel->setAction(self::ML_ADDTOQUEUE); $messageLabel->setAction(self::ML_ADDTOQUEUE);
$backgroundQuad->setAction(self::ML_ADDTOQUEUE); $backgroundQuad->setAction(self::ML_ADDTOQUEUE);
@ -412,7 +415,7 @@ class QueuePlugin implements CallbackListener, CommandListener, ManialinkPageAns
$messageLabel->setText($message); $messageLabel->setText($message);
$messageLabel->setStyle(Label_Text::STYLE_TextStaticSmall); $messageLabel->setStyle(Label_Text::STYLE_TextStaticSmall);
$this->maniaControl->manialinkManager->displayWidget($maniaLink, $player, 'Queue'); $this->maniaControl->manialinkManager->displayWidget($maniaLink, $player);
} }
/** /**