fixed tripple endmap cb problem

This commit is contained in:
kremsy 2013-12-28 22:43:57 +01:00
parent 5bc897cf33
commit 19a8f3e2dc
4 changed files with 113 additions and 14 deletions

View File

@ -55,7 +55,7 @@ class CallbackManager {
private $last1Second = -1;
private $last5Second = -1;
private $last1Minute = -1;
private $mapEnded = false;
/**
* Construct callbacks manager
*
@ -204,11 +204,15 @@ class CallbackManager {
case 'ManiaPlanet.BeginMap':
{
$this->triggerCallback(self::CB_MC_BEGINMAP, $callback);
$this->mapEnded = false;
break;
}
case 'ManiaPlanet.EndMap':
{
$this->triggerCallback(self::CB_MC_ENDMAP, $callback);
if(!$this->mapEnded){
$this->triggerCallback(self::CB_MC_ENDMAP, $callback);
$this->mapEnded = true;
}
break;
}
case self::CB_MP_MODESCRIPTCALLBACK:
@ -244,13 +248,19 @@ class CallbackManager {
case 'EndMap':
{
$this->triggerScriptCallback($scriptCallbackName, $scriptCallbackData);
$this->triggerCallback(self::CB_MC_ENDMAP, $callback);
if(!$this->mapEnded){
$this->triggerCallback(self::CB_MC_ENDMAP, $callback);
$this->mapEnded = true;
}
break;
}
case 'LibXmlRpc_EndMap':
{
$this->triggerScriptCallback($scriptCallbackName, $scriptCallbackData);
$this->triggerCallback(self::CB_MC_ENDMAP, $callback);
if(!$this->mapEnded){
$this->triggerCallback(self::CB_MC_ENDMAP, $callback);
$this->mapEnded = true;
}
break;
}
default:

View File

@ -1,6 +1,8 @@
<?php
namespace ManiaControl\Maps;
use ManiaControl\Callbacks\CallbackListener;
use ManiaControl\Callbacks\CallbackManager;
use ManiaControl\ManiaControl;
/**
@ -8,7 +10,7 @@ use ManiaControl\ManiaControl;
*
* @author steeffeen & kremsy
*/
class Jukebox {
class Jukebox implements CallbackListener {
/**
* Constants
*/
@ -28,10 +30,17 @@ class Jukebox {
public function __construct(ManiaControl $maniaControl) {
$this->maniaControl = $maniaControl;
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MC_BEGINMAP, $this,'beginMap');
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MC_ENDMAP, $this,'endMap');
}
public function addMapToJukebox($uid){
/**
* Adds a Map to the jukebox
* @param $login
* @param $uid
*/
public function addMapToJukebox($login, $uid){
//Check if the map is already juked
if(array_key_exists($uid, $this->jukedMaps)){
@ -41,11 +50,77 @@ class Jukebox {
//TODO recently maps not able to add to jukebox setting, and management
$this->jukedMaps[$uid] = $this->maniaControl->mapManager->getMapByUid($uid);
//$this->jukedMapsUid[$uid] = array($login, $this->maniaControl->mapManager->getMapByUid($uid));
$this->jukedMaps[$uid] = array($login, $this->maniaControl->mapManager->getMapByUid($uid));
//TODO Message
// Trigger callback
$this->maniaControl->callbackManager->triggerCallback(self::CB_JUKEBOX_CHANGED, array('add', $this->jukedMaps[$uid]));
$this->printAllMaps();
}
/**
* Revmoes a Map from the jukebox
* @param $login
* @param $uid
*/
public function removeFromJukebox($login, $uid){
//unset($this->jukedMapsUid[$uid]);
unset($this->jukedMaps[$uid]);
}
public function beginMap(){
}
public function endMap(){
var_dump("endmap");
//TODO setting admin no skip
//TODO setting skip map if requester left
//Skip Map if requester has left
for($i = 0; $i < count($this->jukedMaps); $i++){
$jukedMap = reset($this->jukedMaps);
//found player, so play this map
if($this->maniaControl->playerManager->getPlayer($jukedMap[0]) == null){
break;
}
// Trigger callback
$this->maniaControl->callbackManager->triggerCallback(self::CB_JUKEBOX_CHANGED, array('skip', $jukedMap[0]));
//Player not found, so remove the map from the jukebox
array_shift($this->jukedMaps);
//TODO Message, report skip
}
$nextMap = array_shift($this->jukedMaps);
//Check if Jukebox is empty
if(!isset($nextMap))
return;
$nextMap = $nextMap[1];
//var_dump($nextMap);
var_dump($nextMap->name);
$this->printAllMaps();
//Set pointer back to last map
end($this->jukedMaps);
}
public function printAllMaps(){
foreach($this->jukedMaps as $map){
$map = $map[1];
var_dump($map->name);
}
}
}

View File

@ -46,7 +46,7 @@ class Map {
* @param array $rpc_infos
*/
public function __construct(ManiaControl $maniaControl, $rpc_infos = null) {
$this->maniaControl = $maniaControl;
// $this->maniaControl = $maniaControl;
$this->startTime = time();
if (!$rpc_infos) {
@ -67,7 +67,7 @@ class Map {
$this->authorNick = $this->authorLogin;
$mapsDirectory = $this->maniaControl->server->getMapsDirectory();
/*$mapsDirectory = $this->maniaControl->server->getMapsDirectory();
if ($this->maniaControl->server->checkAccess($mapsDirectory)) {
$this->mapFetcher = new \GBXChallMapFetcher(true);
try {
@ -86,6 +86,6 @@ class Map {
// TODO: define timeout if mx is down,todo fetch all map infos at once (maybe way faster)
$serverInfo = $this->maniaControl->server->getSystemInfo();
$title = strtoupper(substr($serverInfo['TitleId'], 0, 2));
$this->mx = new \MXInfoFetcher($title, $this->uid, false);
$this->mx = new \MXInfoFetcher($title, $this->uid, false);*/
}
}

View File

@ -34,6 +34,7 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
const ACTION_ADD_MAP = 'MapList.AddMap';
const ACTION_ERASE_MAP = 'MapList.EraseMap';
const ACTION_SWITCH_MAP = 'MapList.SwitchMap';
const ACTION_JUKE_MAP = 'MapList.JukeMap';
const MAX_MAPS_PER_PAGE = 15;
@ -173,7 +174,6 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
}
//TODO add MX info screen
//TODO add download Map button
//render and display xml
$this->maniaControl->manialinkManager->displayWidget($maniaLink, $player);
@ -242,7 +242,17 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
$this->displayMap($id, $map, $mapFrame, $tooltips);
$mapFrame->setY($y);
if($this->maniaControl->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_ADMIN)){ //todoSET as setting who can add maps
//Juke-Map-Button
$jukeQuad = new Quad_UIConstruction_Buttons();
$mapFrame->add($jukeQuad);
$jukeQuad->setX($this->width/2 - 15);
$jukeQuad->setZ(0.2);
$jukeQuad->setSize(4,4);
$jukeQuad->setSubStyle($jukeQuad::SUBSTYLE_Erase);
$jukeQuad->setAction(self::ACTION_JUKE_MAP . "." . $map->uid);
//TODO description and jukebox button
if($this->maniaControl->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_ADMIN)){ //TODO SET as setting who can add maps
//erase map quad
$eraseQuad = new Quad_UIConstruction_Buttons();
$mapFrame->add($eraseQuad);
@ -263,7 +273,7 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
$descriptionLabel->setText("Remove Map: {$map->name}");
$tooltips->add($eraseQuad, $descriptionLabel);
}
if($this->maniaControl->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_OPERATOR)){ //todoSET as setting who can add maps
if($this->maniaControl->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_OPERATOR)){ //TODO SET as setting who can add maps
//switch to map quad
$switchToQuad = new Quad_Icons64x64_1();
$mapFrame->add($switchToQuad);
@ -349,8 +359,9 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
$addMap = (strpos($actionId, self::ACTION_ADD_MAP) === 0);
$eraseMap = (strpos($actionId, self::ACTION_ERASE_MAP) === 0);
$switchMap = (strpos($actionId, self::ACTION_SWITCH_MAP) === 0);
$jukeMap = (strpos($actionId, self::ACTION_JUKE_MAP) === 0);
if(!$addMap && !$eraseMap && !$switchMap)
if(!$addMap && !$eraseMap && !$switchMap && !$jukeMap)
return;
$actionArray = explode(".", $actionId);
@ -368,6 +379,9 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
$this->maniaControl->chat->sendSuccess('Map switched to $z$<' . $mapList[$actionArray[2]]->name . '$>!'); //TODO specified message, who done it?
$this->maniaControl->log('Skipped to $z$<' . $mapList[$actionArray[2]]->name . '$>!');
}else if($jukeMap){
$this->maniaControl->mapManager->jukebox->addMapToJukebox($callback[1][1], $actionArray[2]);
}
}