replaced jukebox through mapqueue
This commit is contained in:
parent
50f79ddec2
commit
060211204d
@ -35,7 +35,7 @@ require_once __DIR__ . '/Manialinks/ManialinkManager.php';
|
||||
require_once __DIR__ . '/Maps/Map.php';
|
||||
require_once __DIR__ . '/Maps/MapManager.php';
|
||||
require_once __DIR__ . '/Maps/MapList.php';
|
||||
require_once __DIR__ . '/Maps/Jukebox.php';
|
||||
require_once __DIR__ . '/Maps/MapQueue.php';
|
||||
require_once __DIR__ . '/Players/PlayerManager.php';
|
||||
require_once __DIR__ . '/Players/PlayerActions.php';
|
||||
require_once __DIR__ . '/Plugins/PluginManager.php';
|
||||
|
@ -13,22 +13,22 @@ use ManiaControl\Players\Player;
|
||||
*
|
||||
* @author steeffeen & kremsy
|
||||
*/
|
||||
class Jukebox implements CallbackListener, CommandListener {
|
||||
class MapQueue implements CallbackListener, CommandListener {
|
||||
/**
|
||||
* Constants
|
||||
*/
|
||||
const CB_JUKEBOX_CHANGED = 'Jukebox.JukeBoxChanged';
|
||||
const CB_MAPQUEUE_CHANGED = 'MapQueue.MapQueueBoxChanged';
|
||||
|
||||
const SETTING_SKIP_MAP_ON_LEAVE = 'Skip Map when the requester leaves';
|
||||
const SETTING_SKIP_JUKED_ADMIN = 'Skip Map when admin leaves';
|
||||
const SETTING_SKIP_MAPQUEUE_ADMIN = 'Skip Map when admin leaves';
|
||||
|
||||
const ADMIN_COMMAND_CLEAR_MAPQUEUE = 'clearmapqueue';
|
||||
const ADMIN_COMMAND_CLEAR_JUKEBOX = 'clearjukebox';
|
||||
|
||||
/**
|
||||
* Private properties
|
||||
*/
|
||||
private $maniaControl = null;
|
||||
private $jukedMaps = array();
|
||||
private $queuedMaps = array();
|
||||
private $nextMap = null;
|
||||
|
||||
/**
|
||||
@ -43,64 +43,65 @@ class Jukebox implements CallbackListener, CommandListener {
|
||||
|
||||
// Init settings
|
||||
$this->maniaControl->settingManager->initSetting($this, self::SETTING_SKIP_MAP_ON_LEAVE, true);
|
||||
$this->maniaControl->settingManager->initSetting($this, self::SETTING_SKIP_JUKED_ADMIN, false);
|
||||
$this->maniaControl->settingManager->initSetting($this, self::SETTING_SKIP_MAPQUEUE_ADMIN, false);
|
||||
|
||||
//Register Admin Commands
|
||||
$this->maniaControl->commandManager->registerCommandListener(self::ADMIN_COMMAND_CLEAR_JUKEBOX, $this, 'command_ClearJukebox', true);
|
||||
$this->maniaControl->commandManager->registerCommandListener(self::ADMIN_COMMAND_CLEAR_MAPQUEUE, $this, 'command_ClearJukebox', true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears the jukebox via admin command clearjukebox
|
||||
* Clears the map-queue via admin command clearjukebox
|
||||
* @param array $chat
|
||||
* @param Player $player
|
||||
*/
|
||||
public function command_ClearJukebox(array $chat, Player $admin){
|
||||
public function command_ClearQueuedMaps(array $chat, Player $admin){
|
||||
$title = $this->maniaControl->authenticationManager->getAuthLevelName($admin->authLevel);
|
||||
|
||||
//Destroy jukebox list
|
||||
$this->jukedMaps = array();
|
||||
$this->queuedMaps = array();
|
||||
|
||||
$this->maniaControl->chat->sendInformation($title . ' $<' . $admin->nickname . '$> cleared the Jukebox!');
|
||||
$this->maniaControl->log($title .' ' . Formatter::stripCodes($admin->nickname) . ' cleared the Jukebox');
|
||||
$this->maniaControl->chat->sendInformation($title . ' $<' . $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_JUKEBOX_CHANGED, array('clear'));
|
||||
$this->maniaControl->callbackManager->triggerCallback(self::CB_MAPQUEUE_CHANGED, array('clear'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a Map to the jukebox
|
||||
* Adds a Map to the map-queue
|
||||
* @param $login
|
||||
* @param $uid
|
||||
*/
|
||||
public function addMapToJukebox($login, $uid){ //TODO if from MX other message
|
||||
public function addMapToMapQueue($login, $uid){ //TODO if from MX other message
|
||||
$player = $this->maniaControl->playerManager->getPlayer($login);
|
||||
|
||||
//Check if the map is already juked
|
||||
if(array_key_exists($uid, $this->jukedMaps)){
|
||||
$this->maniaControl->chat->sendError('Map is already in the Jukebox', $login);
|
||||
if(array_key_exists($uid, $this->queuedMaps)){
|
||||
$this->maniaControl->chat->sendError('Map is already in the Map-Queue', $login);
|
||||
return;
|
||||
}
|
||||
|
||||
//TODO recently maps not able to add to jukebox setting, and management
|
||||
//TODO recently maps not able to add to queue-amps setting, and management
|
||||
|
||||
$map = $this->maniaControl->mapManager->getMapByUid($uid);
|
||||
|
||||
$this->jukedMaps[$uid] = array($player, $map);
|
||||
$this->queuedMaps[$uid] = array($player, $map);
|
||||
|
||||
$this->maniaControl->chat->sendInformation('$<' . $player->nickname . '$> added $<' . $map->name . '$> to the Jukebox!');
|
||||
$this->maniaControl->chat->sendInformation('$<' . $player->nickname . '$> added $<' . $map->name . '$> to the Map-Queue');
|
||||
|
||||
// Trigger callback
|
||||
$this->maniaControl->callbackManager->triggerCallback(self::CB_JUKEBOX_CHANGED, array('add', $this->jukedMaps[$uid]));
|
||||
$this->maniaControl->callbackManager->triggerCallback(self::CB_MAPQUEUE_CHANGED, array('add', $this->queuedMaps[$uid]));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Revmoes a Map from the jukebox
|
||||
* Revmoes a Map from the Map queue
|
||||
* @param $login
|
||||
* @param $uid
|
||||
*/
|
||||
public function removeFromJukebox($login, $uid){
|
||||
unset($this->jukedMaps[$uid]);
|
||||
public function removeFromMapQueue($login, $uid){
|
||||
unset($this->queuedMaps[$uid]);
|
||||
}
|
||||
|
||||
|
||||
@ -113,15 +114,15 @@ class Jukebox implements CallbackListener, CommandListener {
|
||||
if($this->maniaControl->settingManager->getSetting($this, self::SETTING_SKIP_MAP_ON_LEAVE) == TRUE){
|
||||
|
||||
//Skip Map if requester has left
|
||||
foreach($this->jukedMaps as $jukedMap){
|
||||
$player = $jukedMap[0];
|
||||
foreach($this->queuedMaps as $queuedMap){
|
||||
$player = $queuedMap[0];
|
||||
|
||||
//found player, so play this map
|
||||
if($this->maniaControl->playerManager->getPlayer($player->login) != null){
|
||||
break;
|
||||
}
|
||||
|
||||
if($this->maniaControl->settingManager->getSetting($this, self::SETTING_SKIP_JUKED_ADMIN) == FALSE){
|
||||
if($this->maniaControl->settingManager->getSetting($this, self::SETTING_SKIP_MAPQUEUE_ADMIN) == FALSE){
|
||||
//Check if the juker is a admin
|
||||
if($player->authLevel > 0){
|
||||
break;
|
||||
@ -129,16 +130,16 @@ class Jukebox implements CallbackListener, CommandListener {
|
||||
}
|
||||
|
||||
// Trigger callback
|
||||
$this->maniaControl->callbackManager->triggerCallback(self::CB_JUKEBOX_CHANGED, array('skip', $jukedMap[0]));
|
||||
$this->maniaControl->callbackManager->triggerCallback(self::CB_MAPQUEUE_CHANGED, array('skip', $queuedMap[0]));
|
||||
|
||||
//Player not found, so remove the map from the jukebox
|
||||
array_shift($this->jukedMaps);
|
||||
array_shift($this->queuedMaps);
|
||||
|
||||
$this->maniaControl->chat->sendInformation('Juked Map skipped because $<' . $player->nickname . '$> left!');
|
||||
$this->maniaControl->chat->sendInformation('Requested Map skipped because $<' . $player->nickname . '$> left!');
|
||||
}
|
||||
}
|
||||
|
||||
$this->nextMap = array_shift($this->jukedMaps);
|
||||
$this->nextMap = array_shift($this->queuedMaps);
|
||||
|
||||
//Check if Jukebox is empty
|
||||
if($this->nextMap == null)
|
||||
@ -164,22 +165,22 @@ class Jukebox implements CallbackListener, CommandListener {
|
||||
* Returns a list with the indexes of the juked maps
|
||||
* @return array
|
||||
*/
|
||||
public function getJukeBoxRanking(){
|
||||
public function getQueuedMapsRanking(){
|
||||
$i = 1;
|
||||
$jukedMaps = array();
|
||||
foreach($this->jukedMaps as $map){
|
||||
$queuedMaps = array();
|
||||
foreach($this->queuedMaps as $map){
|
||||
$map = $map[1];
|
||||
$jukedMaps[$map->uid] = $i;
|
||||
$queuedMaps[$map->uid] = $i;
|
||||
$i++;
|
||||
}
|
||||
return $jukedMaps;
|
||||
return $queuedMaps;
|
||||
}
|
||||
|
||||
/**
|
||||
* Dummy Function for testing
|
||||
*/
|
||||
public function printAllMaps(){
|
||||
foreach($this->jukedMaps as $map){
|
||||
foreach($this->queuedMaps as $map){
|
||||
$map = $map[1];
|
||||
var_dump($map->name);
|
||||
}
|
||||
|
@ -71,7 +71,7 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
|
||||
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MP_PLAYERMANIALINKPAGEANSWER, $this,'handleManialinkPageAnswer');
|
||||
|
||||
//Update Widget actions
|
||||
$this->maniaControl->callbackManager->registerCallbackListener(Jukebox::CB_JUKEBOX_CHANGED, $this, 'updateWidget');
|
||||
$this->maniaControl->callbackManager->registerCallbackListener(MapQueue::CB_MAPQUEUE_CHANGED, $this, 'updateWidget');
|
||||
$this->maniaControl->callbackManager->registerCallbackListener(MapManager::CB_MAPLIST_UPDATED, $this, 'updateWidget');
|
||||
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MC_BEGINMAP, $this, 'updateWidget'); //TODO not working yet
|
||||
//TODO update on Karma Update
|
||||
@ -257,7 +257,7 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
|
||||
|
||||
//TODO add pages
|
||||
|
||||
$jukedMaps = $this->maniaControl->mapManager->jukebox->getJukeBoxRanking();
|
||||
$jukedMaps = $this->maniaControl->mapManager->mapQueue->getQueuedMapsRanking();
|
||||
/** @var KarmaPlugin $karmaPlugin */
|
||||
$karmaPlugin = $this->maniaControl->pluginManager->getPlugin(self::DEFAULT_KARMA_PLUGIN);
|
||||
|
||||
|
@ -36,7 +36,7 @@ class MapManager implements CallbackListener {
|
||||
/**
|
||||
* Public Properties
|
||||
*/
|
||||
public $jukebox = null;
|
||||
public $mapQueue = null;
|
||||
|
||||
/**
|
||||
* Construct map manager
|
||||
@ -51,7 +51,7 @@ class MapManager implements CallbackListener {
|
||||
|
||||
// Create map commands instance
|
||||
$this->mapCommands = new MapCommands($maniaControl);
|
||||
$this->jukebox = new Jukebox($this->maniaControl);
|
||||
$this->mapQueue = new MapQueue($this->maniaControl);
|
||||
|
||||
// Register for callbacks
|
||||
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MC_ONINIT, $this, 'handleOnInit');
|
||||
@ -342,8 +342,8 @@ class MapManager implements CallbackListener {
|
||||
|
||||
$this->updateFullMapList();
|
||||
|
||||
//Juke requested Map
|
||||
$this->maniaControl->mapManager->jukebox->addMapToJukebox($login, $mapInfo['MapUID']);
|
||||
//Queue requested Map
|
||||
$this->maniaControl->mapManager->mapQueue->addMapToMapQueue($login, $mapInfo['MapUID']);
|
||||
}
|
||||
// TODO: add local map by filename
|
||||
}
|
||||
|
189
application/core/Maps/MapQueue.php
Normal file
189
application/core/Maps/MapQueue.php
Normal file
@ -0,0 +1,189 @@
|
||||
<?php
|
||||
|
||||
namespace ManiaControl\Maps;
|
||||
use ManiaControl\Callbacks\CallbackListener;
|
||||
use ManiaControl\Callbacks\CallbackManager;
|
||||
use ManiaControl\Commands\CommandListener;
|
||||
use ManiaControl\Formatter;
|
||||
use ManiaControl\ManiaControl;
|
||||
use ManiaControl\Players\Player;
|
||||
|
||||
/**
|
||||
* MapQueue Class
|
||||
*
|
||||
* @author steeffeen & kremsy
|
||||
*/
|
||||
class MapQueue implements CallbackListener, CommandListener {
|
||||
/**
|
||||
* Constants
|
||||
*/
|
||||
const CB_MAPQUEUE_CHANGED = 'MapQueue.MapQueueBoxChanged';
|
||||
|
||||
const SETTING_SKIP_MAP_ON_LEAVE = 'Skip Map when the requester leaves';
|
||||
const SETTING_SKIP_MAPQUEUE_ADMIN = 'Skip Map when admin leaves';
|
||||
|
||||
const ADMIN_COMMAND_CLEAR_MAPQUEUE = 'clearmapqueue';
|
||||
const ADMIN_COMMAND_CLEAR_JUKEBOX = 'clearjukebox';
|
||||
/**
|
||||
* Private properties
|
||||
*/
|
||||
private $maniaControl = null;
|
||||
private $queuedMaps = array();
|
||||
private $nextMap = null;
|
||||
|
||||
/**
|
||||
* Create a new server jukebox
|
||||
*
|
||||
* @param ManiaControl $maniaControl
|
||||
*/
|
||||
public function __construct(ManiaControl $maniaControl) {
|
||||
$this->maniaControl = $maniaControl;
|
||||
|
||||
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MC_ENDMAP, $this,'endMap');
|
||||
|
||||
// Init settings
|
||||
$this->maniaControl->settingManager->initSetting($this, self::SETTING_SKIP_MAP_ON_LEAVE, true);
|
||||
$this->maniaControl->settingManager->initSetting($this, self::SETTING_SKIP_MAPQUEUE_ADMIN, false);
|
||||
|
||||
//Register Admin Commands
|
||||
$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);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears the map-queue via admin command clearjukebox
|
||||
* @param array $chat
|
||||
* @param Player $player
|
||||
*/
|
||||
public function command_ClearMapQueue(array $chat, Player $admin){
|
||||
$title = $this->maniaControl->authenticationManager->getAuthLevelName($admin->authLevel);
|
||||
|
||||
//Destroy jukebox list
|
||||
$this->queuedMaps = array();
|
||||
|
||||
$this->maniaControl->chat->sendInformation($title . ' $<' . $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 a Map to the map-queue
|
||||
* @param $login
|
||||
* @param $uid
|
||||
*/
|
||||
public function addMapToMapQueue($login, $uid){ //TODO if from MX other message
|
||||
$player = $this->maniaControl->playerManager->getPlayer($login);
|
||||
|
||||
//Check if the map is already juked
|
||||
if(array_key_exists($uid, $this->queuedMaps)){
|
||||
$this->maniaControl->chat->sendError('Map is already in the Map-Queue', $login);
|
||||
return;
|
||||
}
|
||||
|
||||
//TODO recently maps not able to add to queue-amps setting, and management
|
||||
|
||||
$map = $this->maniaControl->mapManager->getMapByUid($uid);
|
||||
|
||||
$this->queuedMaps[$uid] = array($player, $map);
|
||||
|
||||
$this->maniaControl->chat->sendInformation('$<' . $player->nickname . '$> added $<' . $map->name . '$> to the Map-Queue');
|
||||
|
||||
// Trigger callback
|
||||
$this->maniaControl->callbackManager->triggerCallback(self::CB_MAPQUEUE_CHANGED, array('add', $this->queuedMaps[$uid]));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Revmoes a Map from the Map queue
|
||||
* @param $login
|
||||
* @param $uid
|
||||
*/
|
||||
public function removeFromMapQueue($login, $uid){
|
||||
unset($this->queuedMaps[$uid]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Called on endmap
|
||||
* @param array $callback
|
||||
*/
|
||||
public function endMap(array $callback){
|
||||
$this->nextMap = null;
|
||||
if($this->maniaControl->settingManager->getSetting($this, self::SETTING_SKIP_MAP_ON_LEAVE) == TRUE){
|
||||
|
||||
//Skip Map if requester has left
|
||||
foreach($this->queuedMaps as $queuedMap){
|
||||
$player = $queuedMap[0];
|
||||
|
||||
//found player, so play this map
|
||||
if($this->maniaControl->playerManager->getPlayer($player->login) != null){
|
||||
break;
|
||||
}
|
||||
|
||||
if($this->maniaControl->settingManager->getSetting($this, self::SETTING_SKIP_MAPQUEUE_ADMIN) == FALSE){
|
||||
//Check if the juker is a admin
|
||||
if($player->authLevel > 0){
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Trigger callback
|
||||
$this->maniaControl->callbackManager->triggerCallback(self::CB_MAPQUEUE_CHANGED, array('skip', $queuedMap[0]));
|
||||
|
||||
//Player not found, so remove the map from the jukebox
|
||||
array_shift($this->queuedMaps);
|
||||
|
||||
$this->maniaControl->chat->sendInformation('Requested Map skipped because $<' . $player->nickname . '$> left!');
|
||||
}
|
||||
}
|
||||
|
||||
$this->nextMap = array_shift($this->queuedMaps);
|
||||
|
||||
//Check if Jukebox is empty
|
||||
if($this->nextMap == null)
|
||||
return;
|
||||
$map = $this->nextMap[1];
|
||||
|
||||
|
||||
$success = $this->maniaControl->client->query('ChooseNextMap', $map->fileName);
|
||||
if (!$success) {
|
||||
trigger_error('[' . $this->maniaControl->client->getErrorCode() . '] ChooseNextMap - ' . $this->maniaControl->client->getErrorCode(), E_USER_WARNING);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the next Map if the next map is a queuedmap or null if it's not
|
||||
* @return null
|
||||
*/
|
||||
public function getNextMap(){
|
||||
return $this->nextMap;
|
||||
}
|
||||
/**
|
||||
* Returns a list with the indexes of the queued maps
|
||||
* @return array
|
||||
*/
|
||||
public function getQueuedMapsRanking(){
|
||||
$i = 1;
|
||||
$queuedMaps = array();
|
||||
foreach($this->queuedMaps as $map){
|
||||
$map = $map[1];
|
||||
$queuedMaps[$map->uid] = $i;
|
||||
$i++;
|
||||
}
|
||||
return $queuedMaps;
|
||||
}
|
||||
|
||||
/**
|
||||
* Dummy Function for testing
|
||||
*/
|
||||
public function printAllMaps(){
|
||||
foreach($this->queuedMaps as $map){
|
||||
$map = $map[1];
|
||||
var_dump($map->name);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -198,23 +198,23 @@ class WidgetPlugin implements CallbackListener, Plugin {
|
||||
$backgroundQuad->setSize($width, $height);
|
||||
$backgroundQuad->setStyles($quadStyle, $quadSubstyle);
|
||||
|
||||
// Check if the Next Map is a juked Map
|
||||
$jukedMap = $this->maniaControl->mapManager->jukebox->getNextMap();
|
||||
// Check if the Next Map is a queued Map
|
||||
$queuedMap = $this->maniaControl->mapManager->mapQueue->getNextMap();
|
||||
|
||||
/**
|
||||
* @var Player $requester
|
||||
*/
|
||||
$requester = null;
|
||||
// if the nextmap is not a juked map, get it from map info
|
||||
if ($jukedMap == null) {
|
||||
// if the nextmap is not a queued map, get it from map info
|
||||
if ($queuedMap == null) {
|
||||
$this->maniaControl->client->query("GetNextMapInfo");
|
||||
$map = $this->maniaControl->client->getResponse();
|
||||
$name = $map['Name'];
|
||||
$author = $map['Author'];
|
||||
}
|
||||
else {
|
||||
$requester = $jukedMap[0];
|
||||
$map = $jukedMap[1];
|
||||
$requester = $queuedMap[0];
|
||||
$map = $queuedMap[1];
|
||||
$name = $map->name;
|
||||
$author = $map->authorLogin;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user