updated depreced callbacks

This commit is contained in:
kremsy 2014-04-28 20:50:38 +02:00 committed by Steffen Schröder
parent 429702d2e6
commit 09e7a1517c
10 changed files with 282 additions and 298 deletions

View File

@ -13,6 +13,7 @@ use FML\Script\Script;
use ManiaControl\Admin\AuthenticationManager; use ManiaControl\Admin\AuthenticationManager;
use ManiaControl\Callbacks\CallbackListener; use ManiaControl\Callbacks\CallbackListener;
use ManiaControl\Callbacks\CallbackManager; use ManiaControl\Callbacks\CallbackManager;
use ManiaControl\Callbacks\Callbacks;
use ManiaControl\ManiaControl; use ManiaControl\ManiaControl;
use ManiaControl\Maps\Map; use ManiaControl\Maps\Map;
use ManiaControl\Maps\MapManager; use ManiaControl\Maps\MapManager;
@ -55,7 +56,7 @@ class ScriptSettings implements ConfiguratorMenu, CallbackListener {
// Register for callbacks // Register for callbacks
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MP_PLAYERMANIALINKPAGEANSWER, $this, 'handleManialinkPageAnswer'); $this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MP_PLAYERMANIALINKPAGEANSWER, $this, 'handleManialinkPageAnswer');
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_ONINIT, $this, 'onInit'); $this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_ONINIT, $this, 'onInit');
$this->maniaControl->callbackManager->registerCallbackListener(MapManager::CB_BEGINMAP, $this, 'onBeginMap'); $this->maniaControl->callbackManager->registerCallbackListener(Callbacks::BEGINMAP, $this, 'onBeginMap');
$this->maniaControl->settingManager->initSetting($this, self::SETTING_LOAD_DEFAULT_SETTINGS_MAP_BEGIN, true); $this->maniaControl->settingManager->initSetting($this, self::SETTING_LOAD_DEFAULT_SETTINGS_MAP_BEGIN, true);
$this->initTables(); $this->initTables();

View File

@ -16,6 +16,7 @@ use FML\ManiaLink;
use FML\Script\Features\Paging; use FML\Script\Features\Paging;
use ManiaControl\Callbacks\CallbackListener; use ManiaControl\Callbacks\CallbackListener;
use ManiaControl\Callbacks\CallbackManager; use ManiaControl\Callbacks\CallbackManager;
use ManiaControl\Callbacks\Callbacks;
use ManiaControl\ColorUtil; use ManiaControl\ColorUtil;
use ManiaControl\Formatter; use ManiaControl\Formatter;
use ManiaControl\ManiaControl; use ManiaControl\ManiaControl;
@ -73,7 +74,7 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
$this->maniaControl->callbackManager->registerCallbackListener(MapQueue::CB_MAPQUEUE_CHANGED, $this, 'updateWidgetQueue'); $this->maniaControl->callbackManager->registerCallbackListener(MapQueue::CB_MAPQUEUE_CHANGED, $this, 'updateWidgetQueue');
$this->maniaControl->callbackManager->registerCallbackListener(MapManager::CB_MAPS_UPDATED, $this, 'updateWidget'); $this->maniaControl->callbackManager->registerCallbackListener(MapManager::CB_MAPS_UPDATED, $this, 'updateWidget');
$this->maniaControl->callbackManager->registerCallbackListener(MapManager::CB_KARMA_UPDATED, $this, 'updateWidget'); $this->maniaControl->callbackManager->registerCallbackListener(MapManager::CB_KARMA_UPDATED, $this, 'updateWidget');
$this->maniaControl->callbackManager->registerCallbackListener(MapManager::CB_BEGINMAP, $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_CHECK_UPDATE, $this, 'checkUpdates');
$this->maniaControl->manialinkManager->registerManialinkPageAnswerListener(self::ACTION_CLEAR_MAPQUEUE, $this, 'clearMapQueue'); $this->maniaControl->manialinkManager->registerManialinkPageAnswerListener(self::ACTION_CLEAR_MAPQUEUE, $this, 'clearMapQueue');

View File

@ -5,6 +5,7 @@ namespace ManiaControl\Maps;
use ManiaControl\Admin\AuthenticationManager; use ManiaControl\Admin\AuthenticationManager;
use ManiaControl\Callbacks\CallbackListener; use ManiaControl\Callbacks\CallbackListener;
use ManiaControl\Callbacks\CallbackManager; use ManiaControl\Callbacks\CallbackManager;
use ManiaControl\Callbacks\Callbacks;
use ManiaControl\Commands\CommandListener; use ManiaControl\Commands\CommandListener;
use ManiaControl\Formatter; use ManiaControl\Formatter;
use ManiaControl\ManiaControl; use ManiaControl\ManiaControl;
@ -50,8 +51,8 @@ class MapQueue implements CallbackListener, CommandListener {
public function __construct(ManiaControl $maniaControl) { public function __construct(ManiaControl $maniaControl) {
$this->maniaControl = $maniaControl; $this->maniaControl = $maniaControl;
$this->maniaControl->callbackManager->registerCallbackListener(MapManager::CB_ENDMAP, $this, 'endMap'); $this->maniaControl->callbackManager->registerCallbackListener(Callbacks::ENDMAP, $this, 'endMap');
$this->maniaControl->callbackManager->registerCallbackListener(MapManager::CB_BEGINMAP, $this, 'beginMap'); $this->maniaControl->callbackManager->registerCallbackListener(Callbacks::BEGINMAP, $this, 'beginMap');
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_AFTERINIT, $this, 'handleAfterInit'); $this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_AFTERINIT, $this, 'handleAfterInit');
// Init settings // Init settings

View File

@ -10,12 +10,12 @@ use FML\ManiaLink;
use FML\Script\Features\Paging; use FML\Script\Features\Paging;
use ManiaControl\Callbacks\CallbackListener; use ManiaControl\Callbacks\CallbackListener;
use ManiaControl\Callbacks\CallbackManager; use ManiaControl\Callbacks\CallbackManager;
use ManiaControl\Callbacks\Callbacks;
use ManiaControl\Callbacks\TimerListener; use ManiaControl\Callbacks\TimerListener;
use ManiaControl\Commands\CommandListener; use ManiaControl\Commands\CommandListener;
use ManiaControl\Formatter; use ManiaControl\Formatter;
use ManiaControl\ManiaControl; use ManiaControl\ManiaControl;
use ManiaControl\Manialinks\ManialinkManager; use ManiaControl\Manialinks\ManialinkManager;
use ManiaControl\Maps\MapManager;
use ManiaControl\Players\Player; use ManiaControl\Players\Player;
use ManiaControl\Players\PlayerManager; use ManiaControl\Players\PlayerManager;
use ManiaControl\Plugins\Plugin; use ManiaControl\Plugins\Plugin;
@ -101,8 +101,8 @@ class Dedimania implements CallbackListener, CommandListener, TimerListener, Plu
$this->maniaControl->settingManager->initSetting($this, self::SETTING_WIDGET_LINEHEIGHT, 4); $this->maniaControl->settingManager->initSetting($this, self::SETTING_WIDGET_LINEHEIGHT, 4);
$this->maniaControl->settingManager->initSetting($this, self::SETTING_WIDGET_LINESCOUNT, 12); $this->maniaControl->settingManager->initSetting($this, self::SETTING_WIDGET_LINESCOUNT, 12);
$this->maniaControl->callbackManager->registerCallbackListener(MapManager::CB_BEGINMAP, $this, 'handleBeginMap'); $this->maniaControl->callbackManager->registerCallbackListener(Callbacks::BEGINMAP, $this, 'handleBeginMap');
$this->maniaControl->callbackManager->registerCallbackListener(MapManager::CB_ENDMAP, $this, 'handleMapEnd'); $this->maniaControl->callbackManager->registerCallbackListener(Callbacks::ENDMAP, $this, 'handleMapEnd');
$this->maniaControl->callbackManager->registerCallbackListener(PlayerManager::CB_PLAYERCONNECT, $this, 'handlePlayerConnect'); $this->maniaControl->callbackManager->registerCallbackListener(PlayerManager::CB_PLAYERCONNECT, $this, 'handlePlayerConnect');
$this->maniaControl->callbackManager->registerCallbackListener(PlayerManager::CB_PLAYERDISCONNECT, $this, 'handlePlayerDisconnect'); $this->maniaControl->callbackManager->registerCallbackListener(PlayerManager::CB_PLAYERDISCONNECT, $this, 'handlePlayerDisconnect');
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_TM_PLAYERCHECKPOINT, $this, 'handlePlayerCheckpoint'); $this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_TM_PLAYERCHECKPOINT, $this, 'handlePlayerCheckpoint');
@ -329,7 +329,7 @@ class Dedimania implements CallbackListener, CommandListener, TimerListener, Plu
//var_dump($data); //var_dump($data);
$content = $this->encode_request(self::DEDIMANIA_SETCHALLENGETIMES, $data); $content = $this->encode_request(self::DEDIMANIA_SETCHALLENGETIMES, $data);
$self = $this; $self = $this;
$maniaControl = $this->maniaControl; $maniaControl = $this->maniaControl;
$this->maniaControl->fileReader->postData(self::DEDIMANIA_URL, function ($data, $error) use (&$self, &$maniaControl) { $this->maniaControl->fileReader->postData(self::DEDIMANIA_URL, function ($data, $error) use (&$self, &$maniaControl) {
if ($error != '') { if ($error != '') {
@ -469,9 +469,11 @@ class Dedimania implements CallbackListener, CommandListener, TimerListener, Plu
// Only improved time // Only improved time
$improvement = 'improved his/her'; $improvement = 'improved his/her';
} }
$message = '$390$<$fff' . $player->nickname . '$> ' . $improvement . ' $<$ff0' . $newRecord->rank . '.$> Dedimania Record: $<$fff' . Formatter::formatTime($newRecord->best).'$>'; $message = '$390$<$fff' . $player->nickname . '$> ' . $improvement . ' $<$ff0' . $newRecord->rank . '.$> Dedimania Record: $<$fff' . Formatter::formatTime($newRecord->best) . '$>';
if(!$oldRecord->nullRecord) $message .= ' ($<$ff0'.$oldRecord->rank.'.$> $<$fff-'.Formatter::formatTime(($oldRecord->best-$time)).'$>)'; if (!$oldRecord->nullRecord) {
$this->maniaControl->chat->sendInformation($message.'!'); $message .= ' ($<$ff0' . $oldRecord->rank . '.$> $<$fff-' . Formatter::formatTime(($oldRecord->best - $time)) . '$>)';
}
$this->maniaControl->chat->sendInformation($message . '!');
$this->updateManialink = true; $this->updateManialink = true;
} }
@ -503,8 +505,8 @@ class Dedimania implements CallbackListener, CommandListener, TimerListener, Plu
//create manialink //create manialink
$maniaLink = new ManiaLink(ManialinkManager::MAIN_MLID); $maniaLink = new ManiaLink(ManialinkManager::MAIN_MLID);
$script = $maniaLink->getScript(); $script = $maniaLink->getScript();
$paging = new Paging(); $paging = new Paging();
$script->addFeature($paging); $script->addFeature($paging);
// Main frame // Main frame
$frame = $this->maniaControl->manialinkManager->styleManager->getDefaultListFrame($script, $paging); $frame = $this->maniaControl->manialinkManager->styleManager->getDefaultListFrame($script, $paging);
@ -537,7 +539,7 @@ class Dedimania implements CallbackListener, CommandListener, TimerListener, Plu
} }
array_push($pageFrames, $pageFrame); array_push($pageFrames, $pageFrame);
$y = $height / 2 - 10; $y = $height / 2 - 10;
$paging->addPage($pageFrame); $paging->addPage($pageFrame);
} }
$recordFrame = new Frame(); $recordFrame = new Frame();
@ -970,7 +972,7 @@ class Dedimania implements CallbackListener, CommandListener, TimerListener, Plu
} else if ($scriptName == 'TimeAttack' || $scriptName == 'Laps' || $scriptName == 'TeamAttack' || $scriptName == 'TimeAttackPlus') { } else if ($scriptName == 'TimeAttack' || $scriptName == 'Laps' || $scriptName == 'TeamAttack' || $scriptName == 'TimeAttackPlus') {
return 'TA'; return 'TA';
} }
break; break;
} }
case 1: case 1:
case 3: case 3:

View File

@ -2,6 +2,7 @@
namespace steeffeen; namespace steeffeen;
use ManiaControl\Callbacks\Callbacks;
use ManiaControl\ManiaControl; use ManiaControl\ManiaControl;
use ManiaControl\Callbacks\CallbackListener; use ManiaControl\Callbacks\CallbackListener;
use ManiaControl\Callbacks\CallbackManager; use ManiaControl\Callbacks\CallbackManager;
@ -50,7 +51,7 @@ class EndurancePlugin implements CallbackListener, Plugin {
// Register for callbacks // Register for callbacks
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_ONINIT, $this, 'callback_OnInit'); $this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_ONINIT, $this, 'callback_OnInit');
$this->maniaControl->callbackManager->registerCallbackListener(MapManager::CB_BEGINMAP, $this, 'callback_BeginMap'); $this->maniaControl->callbackManager->registerCallbackListener(Callbacks::BEGINMAP, $this, 'callback_BeginMap');
$this->maniaControl->callbackManager->registerScriptCallbackListener(self::CB_CHECKPOINT, $this, 'callback_Checkpoint'); $this->maniaControl->callbackManager->registerScriptCallbackListener(self::CB_CHECKPOINT, $this, 'callback_Checkpoint');
return true; return true;

View File

@ -9,11 +9,11 @@ use FML\Controls\Quad;
use FML\ManiaLink; use FML\ManiaLink;
use ManiaControl\Callbacks\CallbackListener; use ManiaControl\Callbacks\CallbackListener;
use ManiaControl\Callbacks\CallbackManager; use ManiaControl\Callbacks\CallbackManager;
use ManiaControl\Callbacks\Callbacks;
use ManiaControl\Callbacks\TimerListener; use ManiaControl\Callbacks\TimerListener;
use ManiaControl\ColorUtil; use ManiaControl\ColorUtil;
use ManiaControl\ManiaControl; use ManiaControl\ManiaControl;
use ManiaControl\Maps\Map; use ManiaControl\Maps\Map;
use ManiaControl\Maps\MapManager;
use ManiaControl\Players\Player; use ManiaControl\Players\Player;
use ManiaControl\Players\PlayerManager; use ManiaControl\Players\PlayerManager;
use ManiaControl\Plugins\Plugin; use ManiaControl\Plugins\Plugin;
@ -22,60 +22,57 @@ use ManiaControl\Settings\SettingManager;
/** /**
* ManiaControl Karma Plugin * ManiaControl Karma Plugin
* *
* @author kremsy and steeffeen * @author kremsy and steeffeen
* @copyright ManiaControl Copyright © 2014 ManiaControl Team * @copyright ManiaControl Copyright © 2014 ManiaControl Team
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3 * @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
*/ */
class KarmaPlugin implements CallbackListener, TimerListener, Plugin { class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
/* /*
* Constants * Constants
*/ */
const ID = 2; const ID = 2;
const VERSION = 0.1; const VERSION = 0.1;
const MLID_KARMA = 'KarmaPlugin.MLID'; const MLID_KARMA = 'KarmaPlugin.MLID';
const TABLE_KARMA = 'mc_karma'; const TABLE_KARMA = 'mc_karma';
const CB_KARMA_CHANGED = 'KarmaPlugin.Changed'; const CB_KARMA_CHANGED = 'KarmaPlugin.Changed';
const CB_KARMA_MXUPDATED = 'KarmaPlugin.MXUpdated'; const CB_KARMA_MXUPDATED = 'KarmaPlugin.MXUpdated';
const SETTING_AVAILABLE_VOTES = 'Available Votes (X-Y: Comma separated)'; const SETTING_AVAILABLE_VOTES = 'Available Votes (X-Y: Comma separated)';
const SETTING_WIDGET_ENABLE = 'Enable Karma Widget'; const SETTING_WIDGET_ENABLE = 'Enable Karma Widget';
const SETTING_WIDGET_TITLE = 'Widget-Title'; const SETTING_WIDGET_TITLE = 'Widget-Title';
const SETTING_WIDGET_POSX = 'Widget-Position: X'; const SETTING_WIDGET_POSX = 'Widget-Position: X';
const SETTING_WIDGET_POSY = 'Widget-Position: Y'; const SETTING_WIDGET_POSY = 'Widget-Position: Y';
const SETTING_WIDGET_WIDTH = 'Widget-Size: Width'; const SETTING_WIDGET_WIDTH = 'Widget-Size: Width';
const SETTING_WIDGET_HEIGHT = 'Widget-Size: Height'; const SETTING_WIDGET_HEIGHT = 'Widget-Size: Height';
const STAT_PLAYER_MAPVOTES = 'Voted Maps'; const STAT_PLAYER_MAPVOTES = 'Voted Maps';
/* /*
* Constants MX Karma * Constants MX Karma
*/ */
const SETTING_WIDGET_DISPLAY_MX = 'Display MX-Karma in Widget'; const SETTING_WIDGET_DISPLAY_MX = 'Display MX-Karma in Widget';
const SETTING_MX_KARMA_ACTIVATED = 'Activate MX-Karma'; const SETTING_MX_KARMA_ACTIVATED = 'Activate MX-Karma';
const SETTING_MX_KARMA_IMPORTING = 'Import old MX-Karmas'; const SETTING_MX_KARMA_IMPORTING = 'Import old MX-Karmas';
const MX_IMPORT_TABLE = 'mc_karma_mximport'; const MX_IMPORT_TABLE = 'mc_karma_mximport';
const MX_KARMA_URL = 'http://karma.mania-exchange.com/api2/'; const MX_KARMA_URL = 'http://karma.mania-exchange.com/api2/';
const MX_KARMA_STARTSESSION = 'startSession'; const MX_KARMA_STARTSESSION = 'startSession';
const MX_KARMA_ACTIVATESESSION = 'activateSession'; const MX_KARMA_ACTIVATESESSION = 'activateSession';
const MX_KARMA_SAVEVOTES = 'saveVotes'; const MX_KARMA_SAVEVOTES = 'saveVotes';
const MX_KARMA_GETMAPRATING = 'getMapRating'; const MX_KARMA_GETMAPRATING = 'getMapRating';
/* /*
* Private Properties * Private Properties
*/ */
/** /**
*
* @var ManiaControl $maniaControl * @var ManiaControl $maniaControl
*/ */
private $maniaControl = null; private $maniaControl = null;
private $updateManialink = false; private $updateManialink = false;
/** /**
*
* @var ManiaLink $manialink * @var ManiaLink $manialink
*/ */
private $manialink = null; private $manialink = null;
private $mxKarma = array(); private $mxKarma = array();
/** /**
*
* @see \ManiaControl\Plugins\Plugin * @see \ManiaControl\Plugins\Plugin
*/ */
public static function prepare(ManiaControl $maniaControl) { public static function prepare(ManiaControl $maniaControl) {
@ -83,13 +80,12 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
$maniaControl->settingManager->initSetting(get_class(), self::SETTING_MX_KARMA_IMPORTING, true); $maniaControl->settingManager->initSetting(get_class(), self::SETTING_MX_KARMA_IMPORTING, true);
$maniaControl->settingManager->initSetting(get_class(), self::SETTING_WIDGET_DISPLAY_MX, true); $maniaControl->settingManager->initSetting(get_class(), self::SETTING_WIDGET_DISPLAY_MX, true);
$servers = $maniaControl->server->getAllServers(); $servers = $maniaControl->server->getAllServers();
foreach ($servers as $server) { foreach($servers as $server) {
$maniaControl->settingManager->initSetting(get_class(), '$l[http://karma.mania-exchange.com/auth/getapikey?server=' . $server->login . ']MX Karma Code for ' . $server->login . '$l', ''); $maniaControl->settingManager->initSetting(get_class(), '$l[http://karma.mania-exchange.com/auth/getapikey?server=' . $server->login . ']MX Karma Code for ' . $server->login . '$l', '');
} }
} }
/** /**
*
* @see \ManiaControl\Plugins\Plugin::load() * @see \ManiaControl\Plugins\Plugin::load()
*/ */
public function load(ManiaControl $maniaControl) { public function load(ManiaControl $maniaControl) {
@ -109,9 +105,9 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
// Register for callbacks // Register for callbacks
$this->maniaControl->timerManager->registerTimerListening($this, 'handle1Second', 1000); $this->maniaControl->timerManager->registerTimerListening($this, 'handle1Second', 1000);
$this->maniaControl->callbackManager->registerCallbackListener(MapManager::CB_BEGINMAP, $this, 'handleBeginMap'); $this->maniaControl->callbackManager->registerCallbackListener(Callbacks::BEGINMAP, $this, 'handleBeginMap');
$this->maniaControl->callbackManager->registerCallbackListener(MapManager::CB_BEGINMAP, $this, 'importMxKarmaVotes'); $this->maniaControl->callbackManager->registerCallbackListener(Callbacks::BEGINMAP, $this, 'importMxKarmaVotes');
$this->maniaControl->callbackManager->registerCallbackListener(MapManager::CB_ENDMAP, $this, 'sendMxKarmaVotes'); $this->maniaControl->callbackManager->registerCallbackListener(Callbacks::ENDMAP, $this, 'sendMxKarmaVotes');
$this->maniaControl->callbackManager->registerCallbackListener(PlayerManager::CB_PLAYERCONNECT, $this, 'handlePlayerConnect'); $this->maniaControl->callbackManager->registerCallbackListener(PlayerManager::CB_PLAYERCONNECT, $this, 'handlePlayerConnect');
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MP_PLAYERCHAT, $this, 'handlePlayerChat'); $this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MP_PLAYERCHAT, $this, 'handlePlayerChat');
$this->maniaControl->callbackManager->registerCallbackListener(SettingManager::CB_SETTINGS_CHANGED, $this, 'updateSettings'); $this->maniaControl->callbackManager->registerCallbackListener(SettingManager::CB_SETTINGS_CHANGED, $this, 'updateSettings');
@ -132,7 +128,6 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
} }
/** /**
*
* @see \ManiaControl\Plugins\Plugin::unload() * @see \ManiaControl\Plugins\Plugin::unload()
*/ */
public function unload() { public function unload() {
@ -143,7 +138,6 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
} }
/** /**
*
* @see \ManiaControl\Plugins\Plugin::getId() * @see \ManiaControl\Plugins\Plugin::getId()
*/ */
public static function getId() { public static function getId() {
@ -151,7 +145,6 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
} }
/** /**
*
* @see \ManiaControl\Plugins\Plugin::getName() * @see \ManiaControl\Plugins\Plugin::getName()
*/ */
public static function getName() { public static function getName() {
@ -159,7 +152,6 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
} }
/** /**
*
* @see \ManiaControl\Plugins\Plugin::getVersion() * @see \ManiaControl\Plugins\Plugin::getVersion()
*/ */
public static function getVersion() { public static function getVersion() {
@ -167,7 +159,6 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
} }
/** /**
*
* @see \ManiaControl\Plugins\Plugin::getAuthor() * @see \ManiaControl\Plugins\Plugin::getAuthor()
*/ */
public static function getAuthor() { public static function getAuthor() {
@ -175,7 +166,6 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
} }
/** /**
*
* @see \ManiaControl\Plugins\Plugin::getDescription() * @see \ManiaControl\Plugins\Plugin::getDescription()
*/ */
public static function getDescription() { public static function getDescription() {
@ -206,12 +196,11 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
// Display the mx Karma if the setting is choosen and the MX session is available // Display the mx Karma if the setting is choosen and the MX session is available
if ($displayMxKarma && isset($this->mxKarma['session']) && isset($this->mxKarma['voteCount'])) { if ($displayMxKarma && isset($this->mxKarma['session']) && isset($this->mxKarma['voteCount'])) {
$karma = $this->mxKarma['modeVoteAverage'] / 100; $karma = $this->mxKarma['modeVoteAverage'] / 100;
$voteCount = $this->mxKarma['modeVoteCount']; $voteCount = $this->mxKarma['modeVoteCount'];
} } else {
else { $karma = $this->getMapKarma($map);
$karma = $this->getMapKarma($map); $votes = $this->getMapVotes($map);
$votes = $this->getMapVotes($map);
$voteCount = $votes['count']; $voteCount = $votes['count'];
} }
@ -221,12 +210,10 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
// Update karma gauge & label // Update karma gauge & label
/** /**
*
* @var Gauge $karmaGauge * @var Gauge $karmaGauge
*/ */
$karmaGauge = $this->manialink->karmaGauge; $karmaGauge = $this->manialink->karmaGauge;
/** /**
*
* @var Label $karmaLabel * @var Label $karmaLabel
*/ */
$karmaLabel = $this->manialink->karmaLabel; $karmaLabel = $this->manialink->karmaLabel;
@ -236,15 +223,14 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
$karmaColor = ColorUtil::floatToStatusColor($karma); $karmaColor = ColorUtil::floatToStatusColor($karma);
$karmaGauge->setColor($karmaColor . '7'); $karmaGauge->setColor($karmaColor . '7');
$karmaLabel->setText(' ' . round($karma * 100.) . '% (' . $voteCount . ')'); $karmaLabel->setText(' ' . round($karma * 100.) . '% (' . $voteCount . ')');
} } else {
else {
$karmaGauge->setRatio(0.); $karmaGauge->setRatio(0.);
$karmaGauge->setColor('00fb'); $karmaGauge->setColor('00fb');
$karmaLabel->setText('-'); $karmaLabel->setText('-');
} }
// Loop players // Loop players
foreach ($players as $login => $player) { foreach($players as $login => $player) {
// Get player vote // Get player vote
// TODO: show the player his own vote in some way // TODO: show the player his own vote in some way
// $vote = $this->getPlayerVote($player, $map); // $vote = $this->getPlayerVote($player, $map);
@ -266,7 +252,7 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
// send Map Karma to MX from previous Map // send Map Karma to MX from previous Map
if (isset($this->mxKarma['map'])) { if (isset($this->mxKarma['map'])) {
$votes = array(); $votes = array();
foreach ($this->mxKarma['votes'] as $login => $value) { foreach($this->mxKarma['votes'] as $login => $value) {
$player = $this->maniaControl->playerManager->getPlayer($login); $player = $this->maniaControl->playerManager->getPlayer($login);
array_push($votes, array("login" => $login, "nickname" => $player->rawNickname, "vote" => $value)); array_push($votes, array("login" => $login, "nickname" => $player->rawNickname, "vote" => $value));
} }
@ -276,7 +262,7 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
unset($this->mxKarma['votes']); unset($this->mxKarma['votes']);
$this->mxKarma['startTime'] = time(); $this->mxKarma['startTime'] = time();
$this->updateManialink = true; $this->updateManialink = true;
// Get Karma votes at begin of map // Get Karma votes at begin of map
$this->getMxKarmaVotes(); $this->getMxKarmaVotes();
@ -303,7 +289,7 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
* @param array $chatCallback * @param array $chatCallback
*/ */
public function handlePlayerChat(array $chatCallback) { public function handlePlayerChat(array $chatCallback) {
$login = $chatCallback[1][1]; $login = $chatCallback[1][1];
$player = $this->maniaControl->playerManager->getPlayer($login); $player = $this->maniaControl->playerManager->getPlayer($login);
if (!$player) { if (!$player) {
return; return;
@ -320,7 +306,7 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
if ($countPositive <= 0 && $countNegative <= 0) { if ($countPositive <= 0 && $countNegative <= 0) {
return; return;
} }
$vote = $countPositive - $countNegative; $vote = $countPositive - $countNegative;
$success = $this->handleVote($player, $vote); $success = $this->handleVote($player, $vote);
if (!$success) { if (!$success) {
$this->maniaControl->chat->sendError('Error occurred.', $player->login); $this->maniaControl->chat->sendError('Error occurred.', $player->login);
@ -333,15 +319,15 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
* Handle a vote done by a player * Handle a vote done by a player
* *
* @param Player $player * @param Player $player
* @param int $vote * @param int $vote
* @return bool * @return bool
*/ */
private function handleVote(Player $player, $vote) { private function handleVote(Player $player, $vote) {
// Check vote // Check vote
$votesSetting = $this->maniaControl->settingManager->getSetting($this, self::SETTING_AVAILABLE_VOTES); $votesSetting = $this->maniaControl->settingManager->getSetting($this, self::SETTING_AVAILABLE_VOTES);
$votes = explode(',', $votesSetting); $votes = explode(',', $votesSetting);
$voteLow = intval($votes[0]); $voteLow = intval($votes[0]);
$voteHigh = $voteLow + 2; $voteHigh = $voteLow + 2;
if (isset($votes[1])) { if (isset($votes[1])) {
$voteHigh = intval($votes[1]); $voteHigh = intval($votes[1]);
} }
@ -365,15 +351,14 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
$modeSum = $this->mxKarma["modeVoteCount"] * $this->mxKarma["modeVoteAverage"] + $vote * 100; $modeSum = $this->mxKarma["modeVoteCount"] * $this->mxKarma["modeVoteAverage"] + $vote * 100;
$this->mxKarma["modeVoteCount"]++; $this->mxKarma["modeVoteCount"]++;
} } else {
else {
$oldVote = $this->mxKarma["votes"][$player->login]; $oldVote = $this->mxKarma["votes"][$player->login];
$sum = $this->mxKarma["voteCount"] * $this->mxKarma["voteAverage"] - $oldVote + $vote * 100; $sum = $this->mxKarma["voteCount"] * $this->mxKarma["voteAverage"] - $oldVote + $vote * 100;
$modeSum = $this->mxKarma["modeVoteCount"] * $this->mxKarma["modeVoteAverage"] - $oldVote + $vote * 100; $modeSum = $this->mxKarma["modeVoteCount"] * $this->mxKarma["modeVoteAverage"] - $oldVote + $vote * 100;
} }
$this->mxKarma["voteAverage"] = $sum / $this->mxKarma["voteCount"]; $this->mxKarma["voteAverage"] = $sum / $this->mxKarma["voteCount"];
$this->mxKarma["modeVoteAverage"] = $modeSum / $this->mxKarma["modeVoteCount"]; $this->mxKarma["modeVoteAverage"] = $modeSum / $this->mxKarma["modeVoteCount"];
$this->mxKarma["votes"][$player->login] = $vote * 100; $this->mxKarma["votes"][$player->login] = $vote * 100;
} }
@ -453,13 +438,13 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
* Save the vote of the player for the map * Save the vote of the player for the map
* *
* @param Player $player * @param Player $player
* @param Map $map * @param Map $map
* @param float $vote * @param float $vote
* @return bool * @return bool
*/ */
private function savePlayerVote(Player $player, Map $map, $vote) { private function savePlayerVote(Player $player, Map $map, $vote) {
$mysqli = $this->maniaControl->database->mysqli; $mysqli = $this->maniaControl->database->mysqli;
$query = "INSERT INTO `" . self::TABLE_KARMA . "` ( $query = "INSERT INTO `" . self::TABLE_KARMA . "` (
`mapIndex`, `mapIndex`,
`playerIndex`, `playerIndex`,
`vote` `vote`
@ -482,12 +467,12 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
* Get the current vote of the player for the map * Get the current vote of the player for the map
* *
* @param Player $player * @param Player $player
* @param Map $map * @param Map $map
* @return int * @return int
*/ */
public function getPlayerVote(Player $player, Map $map) { public function getPlayerVote(Player $player, Map $map) {
$mysqli = $this->maniaControl->database->mysqli; $mysqli = $this->maniaControl->database->mysqli;
$query = "SELECT * FROM `" . self::TABLE_KARMA . "` $query = "SELECT * FROM `" . self::TABLE_KARMA . "`
WHERE `playerIndex` = {$player->index} WHERE `playerIndex` = {$player->index}
AND `mapIndex` = {$map->index} AND `mapIndex` = {$map->index}
AND `vote` >= 0;"; AND `vote` >= 0;";
@ -514,7 +499,7 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
*/ */
public function getMapKarma(Map $map) { public function getMapKarma(Map $map) {
$mysqli = $this->maniaControl->database->mysqli; $mysqli = $this->maniaControl->database->mysqli;
$query = "SELECT AVG(`vote`) AS `karma` FROM `" . self::TABLE_KARMA . "` $query = "SELECT AVG(`vote`) AS `karma` FROM `" . self::TABLE_KARMA . "`
WHERE `mapIndex` = {$map->index} WHERE `mapIndex` = {$map->index}
AND `vote` >= 0;"; AND `vote` >= 0;";
$result = $mysqli->query($query); $result = $mysqli->query($query);
@ -543,7 +528,7 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
*/ */
public function getMapVotes(Map $map) { public function getMapVotes(Map $map) {
$mysqli = $this->maniaControl->database->mysqli; $mysqli = $this->maniaControl->database->mysqli;
$query = "SELECT `vote`, COUNT(`vote`) AS `count` FROM `" . self::TABLE_KARMA . "` $query = "SELECT `vote`, COUNT(`vote`) AS `count` FROM `" . self::TABLE_KARMA . "`
WHERE `mapIndex` = {$map->index} WHERE `mapIndex` = {$map->index}
AND `vote` >= 0 AND `vote` >= 0
GROUP BY `vote`;"; GROUP BY `vote`;";
@ -554,7 +539,7 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
} }
$votes = array(); $votes = array();
$count = 0; $count = 0;
while ($vote = $result->fetch_object()) { while($vote = $result->fetch_object()) {
$votes[$vote->vote] = $vote; $votes[$vote->vote] = $vote;
$count += $vote->count; $count += $vote->count;
} }
@ -573,13 +558,13 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
return; return;
} }
$title = $this->maniaControl->settingManager->getSetting($this, self::SETTING_WIDGET_TITLE); $title = $this->maniaControl->settingManager->getSetting($this, self::SETTING_WIDGET_TITLE);
$pos_x = $this->maniaControl->settingManager->getSetting($this, self::SETTING_WIDGET_POSX); $pos_x = $this->maniaControl->settingManager->getSetting($this, self::SETTING_WIDGET_POSX);
$pos_y = $this->maniaControl->settingManager->getSetting($this, self::SETTING_WIDGET_POSY); $pos_y = $this->maniaControl->settingManager->getSetting($this, self::SETTING_WIDGET_POSY);
$width = $this->maniaControl->settingManager->getSetting($this, self::SETTING_WIDGET_WIDTH); $width = $this->maniaControl->settingManager->getSetting($this, self::SETTING_WIDGET_WIDTH);
$height = $this->maniaControl->settingManager->getSetting($this, self::SETTING_WIDGET_HEIGHT); $height = $this->maniaControl->settingManager->getSetting($this, self::SETTING_WIDGET_HEIGHT);
$labelStyle = $this->maniaControl->manialinkManager->styleManager->getDefaultLabelStyle(); $labelStyle = $this->maniaControl->manialinkManager->styleManager->getDefaultLabelStyle();
$quadStyle = $this->maniaControl->manialinkManager->styleManager->getDefaultQuadStyle(); $quadStyle = $this->maniaControl->manialinkManager->styleManager->getDefaultQuadStyle();
$quadSubstyle = $this->maniaControl->manialinkManager->styleManager->getDefaultQuadSubstyle(); $quadSubstyle = $this->maniaControl->manialinkManager->styleManager->getDefaultQuadSubstyle();
$manialink = new ManiaLink(self::MLID_KARMA); $manialink = new ManiaLink(self::MLID_KARMA);
@ -645,11 +630,10 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
if ($settingName == 'Enable Karma Widget' && $value == true) { if ($settingName == 'Enable Karma Widget' && $value == true) {
$this->updateManialink = true; $this->updateManialink = true;
$this->handle1Second(time()); $this->handle1Second(time());
} } elseif ($settingName == 'Enable Karma Widget' && $value == false) {
elseif ($settingName == 'Enable Karma Widget' && $value == false) {
$this->updateManialink = false; $this->updateManialink = false;
$ml = new ManiaLink(self::MLID_KARMA); $ml = new ManiaLink(self::MLID_KARMA);
$mltext = $ml->render()->saveXML(); $mltext = $ml->render()->saveXML();
$this->maniaControl->manialinkManager->sendManialink($mltext); $this->maniaControl->manialinkManager->sendManialink($mltext);
} }
} }
@ -670,7 +654,7 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
} }
$applicationIdentifier = 'ManiaControl v' . ManiaControl::VERSION; $applicationIdentifier = 'ManiaControl v' . ManiaControl::VERSION;
$testMode = 'true'; $testMode = 'true';
$query = self::MX_KARMA_URL . self::MX_KARMA_STARTSESSION; $query = self::MX_KARMA_URL . self::MX_KARMA_STARTSESSION;
$query .= '?serverLogin=' . $serverLogin; $query .= '?serverLogin=' . $serverLogin;
@ -680,21 +664,19 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
$this->mxKarma['connectionInProgress'] = true; $this->mxKarma['connectionInProgress'] = true;
$self = $this; $self = $this;
$this->maniaControl->fileReader->loadFile($query, function ($data, $error) use(&$self, $mxKarmaCode) { $this->maniaControl->fileReader->loadFile($query, function ($data, $error) use (&$self, $mxKarmaCode) {
if (!$error) { if (!$error) {
$data = json_decode($data); $data = json_decode($data);
if ($data->success) { if ($data->success) {
$self->mxKarma['session'] = $data->data; $self->mxKarma['session'] = $data->data;
$self->activateSession($mxKarmaCode); $self->activateSession($mxKarmaCode);
} } else {
else {
$self->maniaControl->log("Error while authenticating on Mania-Exchange Karma"); $self->maniaControl->log("Error while authenticating on Mania-Exchange Karma");
// TODO remove temp trigger // TODO remove temp trigger
$self->maniaControl->errorHandler->triggerDebugNotice("Error while authenticating on Mania-Exchange Karma " . $data->data->message); $self->maniaControl->errorHandler->triggerDebugNotice("Error while authenticating on Mania-Exchange Karma " . $data->data->message);
$self->mxKarma['connectionInProgress'] = false; $self->mxKarma['connectionInProgress'] = false;
} }
} } else {
else {
$self->maniaControl->log($error); $self->maniaControl->log($error);
// TODO remove temp trigger // TODO remove temp trigger
$self->maniaControl->errorHandler->triggerDebugNotice("Error while authenticating on Mania-Exchange Karma " . $error); $self->maniaControl->errorHandler->triggerDebugNotice("Error while authenticating on Mania-Exchange Karma " . $error);
@ -716,7 +698,7 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
$query .= '&activationHash=' . urlencode($hash); $query .= '&activationHash=' . urlencode($hash);
$self = $this; $self = $this;
$this->maniaControl->fileReader->loadFile($query, function ($data, $error) use(&$self, $query) { $this->maniaControl->fileReader->loadFile($query, function ($data, $error) use (&$self, $query) {
if (!$error) { if (!$error) {
$data = json_decode($data); $data = json_decode($data);
if ($data->success && $data->data->activated) { if ($data->success && $data->data->activated) {
@ -725,15 +707,13 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
// Fetch the Mx Karma Votes // Fetch the Mx Karma Votes
$self->getMxKarmaVotes(); $self->getMxKarmaVotes();
} } else {
else {
$self->maniaControl->log("Error while authenticating on Mania-Exchange Karma " . $data->data->message); $self->maniaControl->log("Error while authenticating on Mania-Exchange Karma " . $data->data->message);
// TODO remove temp trigger // TODO remove temp trigger
$self->maniaControl->errorHandler->triggerDebugNotice("Error while authenticating on Mania-Exchange Karma " . $data->data->message . " url Query " . $query); $self->maniaControl->errorHandler->triggerDebugNotice("Error while authenticating on Mania-Exchange Karma " . $data->data->message . " url Query " . $query);
$self->mxKarma['connectionInProgress'] = false; $self->mxKarma['connectionInProgress'] = false;
} }
} } else {
else {
// TODO remove temp trigger // TODO remove temp trigger
$self->maniaControl->errorHandler->triggerDebugNotice("Error while authenticating on Mania-Exchange Karma " . $error); $self->maniaControl->errorHandler->triggerDebugNotice("Error while authenticating on Mania-Exchange Karma " . $error);
$self->maniaControl->log($error); $self->maniaControl->log($error);
@ -763,62 +743,57 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
$gameMode = $this->maniaControl->server->getGameMode(true); $gameMode = $this->maniaControl->server->getGameMode(true);
if ($gameMode == 'Script') { if ($gameMode == 'Script') {
$scriptName = $this->maniaControl->client->getScriptName(); $scriptName = $this->maniaControl->client->getScriptName();
$properties['gamemode'] = $scriptName["CurrentValue"]; $properties['gamemode'] = $scriptName["CurrentValue"];
} } else {
else {
$properties['gamemode'] = $gameMode; $properties['gamemode'] = $gameMode;
} }
$properties['titleid'] = $this->maniaControl->server->titleId; $properties['titleid'] = $this->maniaControl->server->titleId;
$properties['mapuid'] = $map->uid; $properties['mapuid'] = $map->uid;
if (!$player) { if (!$player) {
$properties['getvotesonly'] = false; $properties['getvotesonly'] = false;
$properties['playerlogins'] = array(); $properties['playerlogins'] = array();
foreach ($this->maniaControl->playerManager->getPlayers() as $plyr) { foreach($this->maniaControl->playerManager->getPlayers() as $plyr) {
/** /**
*
* @var Player $player * @var Player $player
*/ */
$properties['playerlogins'][] = $plyr->login; $properties['playerlogins'][] = $plyr->login;
} }
} } else {
else {
$properties['getvotesonly'] = true; $properties['getvotesonly'] = true;
$properties['playerlogins'] = array($player->login); $properties['playerlogins'] = array($player->login);
} }
$content = json_encode($properties); $content = json_encode($properties);
$self = $this; $self = $this;
$this->maniaControl->fileReader->postData(self::MX_KARMA_URL . self::MX_KARMA_GETMAPRATING . "?sessionKey=" . urlencode($this->mxKarma['session']->sessionKey), function ($data, $error) use(&$self, &$player) { $this->maniaControl->fileReader->postData(self::MX_KARMA_URL . self::MX_KARMA_GETMAPRATING . "?sessionKey=" . urlencode($this->mxKarma['session']->sessionKey), function ($data, $error) use (&$self, &$player) {
if (!$error) { if (!$error) {
$data = json_decode($data); $data = json_decode($data);
if ($data->success) { if ($data->success) {
// Fetch averages if its for the whole server // Fetch averages if its for the whole server
if (!$player) { if (!$player) {
$self->mxKarma["voteCount"] = $data->data->votecount; $self->mxKarma["voteCount"] = $data->data->votecount;
$self->mxKarma["voteAverage"] = $data->data->voteaverage; $self->mxKarma["voteAverage"] = $data->data->voteaverage;
$self->mxKarma["modeVoteCount"] = $data->data->modevotecount; $self->mxKarma["modeVoteCount"] = $data->data->modevotecount;
$self->mxKarma["modeVoteAverage"] = $data->data->modevoteaverage; $self->mxKarma["modeVoteAverage"] = $data->data->modevoteaverage;
} }
foreach ($data->data->votes as $votes) { foreach($data->data->votes as $votes) {
$self->mxKarma["votes"][$votes->login] = $votes->vote; $self->mxKarma["votes"][$votes->login] = $votes->vote;
} }
$self->updateManialink = true; $self->updateManialink = true;
$self->maniaControl->callbackManager->triggerCallback($self::CB_KARMA_MXUPDATED, $self->mxKarma); $self->maniaControl->callbackManager->triggerCallback($self::CB_KARMA_MXUPDATED, $self->mxKarma);
$self->maniaControl->log("MX-Karma Votes successfully fetched"); $self->maniaControl->log("MX-Karma Votes successfully fetched");
} } else {
else {
$self->maniaControl->log("Error while fetching votes: " . $data->data->message); $self->maniaControl->log("Error while fetching votes: " . $data->data->message);
// TODO remove temp trigger // TODO remove temp trigger
$self->maniaControl->errorHandler->triggerDebugNotice("Error while fetching votes: " . $data->data->message . " " . KarmaPlugin::MX_KARMA_URL . KarmaPlugin::MX_KARMA_SAVEVOTES . "?sessionKey=" . urlencode($self->mxKarma['session']->sessionKey)); $self->maniaControl->errorHandler->triggerDebugNotice("Error while fetching votes: " . $data->data->message . " " . KarmaPlugin::MX_KARMA_URL . KarmaPlugin::MX_KARMA_SAVEVOTES . "?sessionKey=" . urlencode($self->mxKarma['session']->sessionKey));
} }
} } else {
else {
$self->maniaControl->log($error); $self->maniaControl->log($error);
} }
}, $content, false, 'application/json'); }, $content, false, 'application/json');
@ -846,7 +821,7 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
} }
$mysqli = $this->maniaControl->database->mysqli; $mysqli = $this->maniaControl->database->mysqli;
$query = "SELECT mapImported FROM `" . self::MX_IMPORT_TABLE . "` WHERE `mapIndex` = {$map->index};"; $query = "SELECT mapImported FROM `" . self::MX_IMPORT_TABLE . "` WHERE `mapIndex` = {$map->index};";
$result = $mysqli->query($query); $result = $mysqli->query($query);
if ($mysqli->error) { if ($mysqli->error) {
trigger_error($mysqli->error); trigger_error($mysqli->error);
@ -855,7 +830,7 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
$vote = $result->fetch_object(); $vote = $result->fetch_object();
if ($result->field_count == 0 || !$vote) { if ($result->field_count == 0 || !$vote) {
$query = "SELECT vote, login, nickname FROM `" . self::TABLE_KARMA . "` k LEFT JOIN `" . PlayerManager::TABLE_PLAYERS . "` p ON (k.playerIndex=p.index) WHERE mapIndex = {$map->index}"; $query = "SELECT vote, login, nickname FROM `" . self::TABLE_KARMA . "` k LEFT JOIN `" . PlayerManager::TABLE_PLAYERS . "` p ON (k.playerIndex=p.index) WHERE mapIndex = {$map->index}";
$result2 = $mysqli->query($query); $result2 = $mysqli->query($query);
if ($mysqli->error) { if ($mysqli->error) {
trigger_error($mysqli->error); trigger_error($mysqli->error);
@ -863,7 +838,7 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
} }
$votes = array(); $votes = array();
while ($row = $result2->fetch_object()) { while($row = $result2->fetch_object()) {
array_push($votes, array("login" => $row->login, "nickname" => $row->nickname, "vote" => $row->vote * 100)); array_push($votes, array("login" => $row->login, "nickname" => $row->nickname, "vote" => $row->vote * 100));
} }
@ -908,9 +883,9 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
/** /**
* Post the Karma votes to MX-Karma * Post the Karma votes to MX-Karma
* *
* @param Map $map * @param Map $map
* @param array $votes * @param array $votes
* @param bool $import * @param bool $import
*/ */
private function postKarmaVotes(Map $map, array $votes, $import = false) { private function postKarmaVotes(Map $map, array $votes, $import = false) {
if (!isset($this->mxKarma['session'])) { if (!isset($this->mxKarma['session'])) {
@ -928,43 +903,39 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
$properties = array(); $properties = array();
if ($gameMode == 'Script') { if ($gameMode == 'Script') {
$scriptName = $this->maniaControl->client->getScriptName(); $scriptName = $this->maniaControl->client->getScriptName();
$properties['gamemode'] = $scriptName["CurrentValue"]; $properties['gamemode'] = $scriptName["CurrentValue"];
} } else {
else {
$properties['gamemode'] = $gameMode; $properties['gamemode'] = $gameMode;
} }
if ($import) { if ($import) {
$properties['maptime'] = 0; $properties['maptime'] = 0;
} } else {
else {
$properties['maptime'] = time() - $this->mxKarma['startTime']; $properties['maptime'] = time() - $this->mxKarma['startTime'];
} }
$properties['votes'] = $votes; $properties['votes'] = $votes;
$properties['titleid'] = $this->maniaControl->server->titleId; $properties['titleid'] = $this->maniaControl->server->titleId;
$properties['mapname'] = $map->rawName; $properties['mapname'] = $map->rawName;
$properties['mapuid'] = $map->uid; $properties['mapuid'] = $map->uid;
$properties['mapauthor'] = $map->authorLogin; $properties['mapauthor'] = $map->authorLogin;
$properties['isimport'] = $import; $properties['isimport'] = $import;
$content = json_encode($properties); $content = json_encode($properties);
$self = $this; $self = $this;
$this->maniaControl->fileReader->postData(self::MX_KARMA_URL . self::MX_KARMA_SAVEVOTES . "?sessionKey=" . urlencode($this->mxKarma['session']->sessionKey), function ($data, $error) use(&$self) { $this->maniaControl->fileReader->postData(self::MX_KARMA_URL . self::MX_KARMA_SAVEVOTES . "?sessionKey=" . urlencode($this->mxKarma['session']->sessionKey), function ($data, $error) use (&$self) {
if (!$error) { if (!$error) {
$data = json_decode($data); $data = json_decode($data);
if ($data->success) { if ($data->success) {
$self->maniaControl->log("Votes successfully permitted"); $self->maniaControl->log("Votes successfully permitted");
} } else {
else {
$self->maniaControl->log("Error while updating votes: " . $data->data->message); $self->maniaControl->log("Error while updating votes: " . $data->data->message);
// TODO remove temp trigger // TODO remove temp trigger
$self->maniaControl->errorHandler->triggerDebugNotice("Error while updating votes: " . $data->data->message . " " . KarmaPlugin::MX_KARMA_URL . $self::MX_KARMA_SAVEVOTES . "?sessionKey=" . urlencode($self->mxKarma['session']->sessionKey)); $self->maniaControl->errorHandler->triggerDebugNotice("Error while updating votes: " . $data->data->message . " " . KarmaPlugin::MX_KARMA_URL . $self::MX_KARMA_SAVEVOTES . "?sessionKey=" . urlencode($self->mxKarma['session']->sessionKey));
} }
} } else {
else {
$self->maniaControl->log($error); $self->maniaControl->log($error);
} }
}, $content, false, 'application/json'); }, $content, false, 'application/json');

View File

@ -12,6 +12,7 @@ use FML\Script\Features\Paging;
use ManiaControl\Admin\AuthenticationManager; use ManiaControl\Admin\AuthenticationManager;
use ManiaControl\Callbacks\CallbackListener; use ManiaControl\Callbacks\CallbackListener;
use ManiaControl\Callbacks\CallbackManager; use ManiaControl\Callbacks\CallbackManager;
use ManiaControl\Callbacks\Callbacks;
use ManiaControl\Callbacks\TimerListener; use ManiaControl\Callbacks\TimerListener;
use ManiaControl\Commands\CommandListener; use ManiaControl\Commands\CommandListener;
use ManiaControl\Settings\SettingManager; use ManiaControl\Settings\SettingManager;
@ -96,7 +97,7 @@ class LocalRecordsPlugin implements CallbackListener, CommandListener, TimerList
// Register for callbacks // Register for callbacks
$this->maniaControl->timerManager->registerTimerListening($this, 'handle1Second', 1000); $this->maniaControl->timerManager->registerTimerListening($this, 'handle1Second', 1000);
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_AFTERINIT, $this, 'handleAfterInit'); $this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_AFTERINIT, $this, 'handleAfterInit');
$this->maniaControl->callbackManager->registerCallbackListener(MapManager::CB_BEGINMAP, $this, 'handleMapBegin'); $this->maniaControl->callbackManager->registerCallbackListener(Callbacks::BEGINMAP, $this, 'handleMapBegin');
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_TM_PLAYERFINISH, $this, 'handlePlayerFinish'); $this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_TM_PLAYERFINISH, $this, 'handlePlayerFinish');
$this->maniaControl->callbackManager->registerCallbackListener(PlayerManager::CB_PLAYERCONNECT, $this, 'handlePlayerConnect'); $this->maniaControl->callbackManager->registerCallbackListener(PlayerManager::CB_PLAYERCONNECT, $this, 'handlePlayerConnect');
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_TM_PLAYERCHECKPOINT, $this, 'handlePlayerCheckpoint'); $this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_TM_PLAYERCHECKPOINT, $this, 'handlePlayerCheckpoint');

View File

@ -7,11 +7,11 @@ use FML\Controls\Quads\Quad_Icons64x64_1;
use FML\ManiaLink; use FML\ManiaLink;
use ManiaControl\Callbacks\CallbackListener; use ManiaControl\Callbacks\CallbackListener;
use ManiaControl\Callbacks\CallbackManager; use ManiaControl\Callbacks\CallbackManager;
use ManiaControl\Callbacks\Callbacks;
use ManiaControl\Callbacks\TimerListener; use ManiaControl\Callbacks\TimerListener;
use ManiaControl\Commands\CommandListener; use ManiaControl\Commands\CommandListener;
use ManiaControl\ManiaControl; use ManiaControl\ManiaControl;
use ManiaControl\Manialinks\ManialinkPageAnswerListener; use ManiaControl\Manialinks\ManialinkPageAnswerListener;
use ManiaControl\Maps\MapManager;
use ManiaControl\Players\Player; use ManiaControl\Players\Player;
use ManiaControl\Players\PlayerManager; use ManiaControl\Players\PlayerManager;
use ManiaControl\Plugins\Plugin; use ManiaControl\Plugins\Plugin;
@ -30,11 +30,11 @@ class QueuePlugin implements CallbackListener, CommandListener, ManialinkPageAns
/** /**
* Constants * Constants
*/ */
const ID = 22; const ID = 22;
const VERSION = 0.1; const VERSION = 0.1;
const ML_ID = 'Queue.Widget'; const ML_ID = 'Queue.Widget';
const ML_ADDTOQUEUE = 'Queue.Add'; const ML_ADDTOQUEUE = 'Queue.Add';
const ML_REMOVEFROMQUEUE = 'Queue.Remove'; const ML_REMOVEFROMQUEUE = 'Queue.Remove';
const QUEUE_MAX = 'Maximum number in the queue'; const QUEUE_MAX = 'Maximum number in the queue';
const QUEUE_WIDGET_POS_X = 'X position of the widget'; const QUEUE_WIDGET_POS_X = 'X position of the widget';
@ -50,7 +50,7 @@ class QueuePlugin implements CallbackListener, CommandListener, ManialinkPageAns
private $queue = array(); private $queue = array();
private $spectators = array(); private $spectators = array();
private $showPlay = array(); private $showPlay = array();
private $maxPlayers = 0; private $maxPlayers = 0;
/** /**
* Prepares the Plugin * Prepares the Plugin
@ -75,7 +75,7 @@ class QueuePlugin implements CallbackListener, CommandListener, ManialinkPageAns
$this->maniaControl->callbackManager->registerCallbackListener(PlayerManager::CB_PLAYERCONNECT, $this, 'handlePlayerConnect'); $this->maniaControl->callbackManager->registerCallbackListener(PlayerManager::CB_PLAYERCONNECT, $this, 'handlePlayerConnect');
$this->maniaControl->callbackManager->registerCallbackListener(PlayerManager::CB_PLAYERDISCONNECT, $this, 'handlePlayerDisconnect'); $this->maniaControl->callbackManager->registerCallbackListener(PlayerManager::CB_PLAYERDISCONNECT, $this, 'handlePlayerDisconnect');
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MP_PLAYERINFOCHANGED, $this, 'handlePlayerInfoChanged'); $this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MP_PLAYERINFOCHANGED, $this, 'handlePlayerInfoChanged');
$this->maniaControl->callbackManager->registerCallbackListener(MapManager::CB_BEGINMAP, $this, 'handleBeginMap'); $this->maniaControl->callbackManager->registerCallbackListener(Callbacks::BEGINMAP, $this, 'handleBeginMap');
$this->maniaControl->manialinkManager->registerManialinkPageAnswerListener(self::ML_ADDTOQUEUE, $this, 'handleManiaLinkAnswerAdd'); $this->maniaControl->manialinkManager->registerManialinkPageAnswerListener(self::ML_ADDTOQUEUE, $this, 'handleManiaLinkAnswerAdd');
$this->maniaControl->manialinkManager->registerManialinkPageAnswerListener(self::ML_REMOVEFROMQUEUE, $this, 'handleManiaLinkAnswerRemove'); $this->maniaControl->manialinkManager->registerManialinkPageAnswerListener(self::ML_REMOVEFROMQUEUE, $this, 'handleManiaLinkAnswerRemove');
@ -86,7 +86,7 @@ class QueuePlugin implements CallbackListener, CommandListener, ManialinkPageAns
$this->maniaControl->settingManager->initSetting($this, self::QUEUE_CHATMESSAGES, true); $this->maniaControl->settingManager->initSetting($this, self::QUEUE_CHATMESSAGES, true);
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);
@ -168,15 +168,15 @@ class QueuePlugin implements CallbackListener, CommandListener, ManialinkPageAns
* @param Player $player * @param Player $player
*/ */
public function handlePlayerConnect(Player $player) { public function handlePlayerConnect(Player $player) {
$maxPlayers = $this->maniaControl->client->getMaxPlayers(); $maxPlayers = $this->maniaControl->client->getMaxPlayers();
$this->maxPlayers = $maxPlayers['CurrentValue']; $this->maxPlayers = $maxPlayers['CurrentValue'];
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);
@ -190,10 +190,10 @@ class QueuePlugin implements CallbackListener, CommandListener, ManialinkPageAns
* @param Player $player * @param Player $player
*/ */
public function handlePlayerDisconnect(Player $player) { public function handlePlayerDisconnect(Player $player) {
$maxPlayers = $this->maniaControl->client->getMaxPlayers(); $maxPlayers = $this->maniaControl->client->getMaxPlayers();
$this->maxPlayers = $maxPlayers['CurrentValue']; $this->maxPlayers = $maxPlayers['CurrentValue'];
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);
@ -209,27 +209,27 @@ 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])) { if (isset($this->spectators[$player->login])) {
unset($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) { if (!$found) {
$this->hideQueueWidget($player); $this->hideQueueWidget($player);
} }
} }
@ -240,7 +240,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->maxPlayers > (count($this->maniaControl->playerManager->players) - count($this->spectators))) { if ($this->maxPlayers > (count($this->maniaControl->playerManager->players) - count($this->spectators))) {
$this->moveFirstPlayerToPlay(); $this->moveFirstPlayerToPlay();
} }
@ -250,22 +250,22 @@ 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]);
} }
} }
} }
/** /**
* Checks for being of new map to retrieve maximum number of players. * Checks for being of new map to retrieve maximum number of players.
* *
* @param $currentMap * @param $currentMap
*/ */
public function handleBeginMap($currentMap) { public function handleBeginMap($currentMap) {
$maxPlayers = $this->maniaControl->client->getMaxPlayers(); $maxPlayers = $this->maniaControl->client->getMaxPlayers();
$this->maxPlayers = $maxPlayers['CurrentValue']; $this->maxPlayers = $maxPlayers['CurrentValue'];
} }
/** /**
* Function handling the click of the widget to add them to the queue. * Function handling the click of the widget to add them to the queue.
@ -293,7 +293,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);
} }
@ -305,9 +305,11 @@ 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->getServerPassword() != false && $this->maniaControl->settingManager->getSetting($this, self::QUEUE_ACTIVE_ON_PASS) == false) return; if ($this->maniaControl->client->getServerPassword() != false && $this->maniaControl->settingManager->getSetting($this, self::QUEUE_ACTIVE_ON_PASS) == false) {
return;
}
if($this->maxPlayers > (count($this->maniaControl->playerManager->players) - count($this->spectators))) { if ($this->maxPlayers > (count($this->maniaControl->playerManager->players) - count($this->spectators))) {
try { try {
$this->maniaControl->client->forceSpectator($player->login, 2); $this->maniaControl->client->forceSpectator($player->login, 2);
} catch(Exception $e) { } catch(Exception $e) {
@ -325,7 +327,7 @@ class QueuePlugin implements CallbackListener, CommandListener, ManialinkPageAns
$teams = array(); $teams = array();
/** @var Player $playerObj */ /** @var Player $playerObj */
foreach($this->maniaControl->playerManager->players as $playerObj) { foreach($this->maniaControl->playerManager->players as $playerObj) {
if(!isset($teams[$playerObj->teamId])) { if (!isset($teams[$playerObj->teamId])) {
$teams[$playerObj->teamId] = 1; $teams[$playerObj->teamId] = 1;
} else { } else {
$teams[$playerObj->teamId]++; $teams[$playerObj->teamId]++;
@ -335,21 +337,21 @@ class QueuePlugin implements CallbackListener, CommandListener, ManialinkPageAns
$smallestTeam = null; $smallestTeam = null;
$smallestSize = 999; $smallestSize = 999;
foreach($teams as $team => $size) { foreach($teams as $team => $size) {
if($size < $smallestSize) { if ($size < $smallestSize) {
$smallestTeam = $team; $smallestTeam = $team;
$smallestSize = $size; $smallestSize = $size;
} }
} }
try { try {
if($smallestTeam != -1) { if ($smallestTeam != -1) {
$this->maniaControl->client->forcePlayerTeam($player->login, $smallestTeam); $this->maniaControl->client->forcePlayerTeam($player->login, $smallestTeam);
} }
} catch(Exception $e) { } catch(Exception $e) {
// TODO: only possible valid exceptions should be "wrong login" or "not in team mode" - throw others (like connection error) // TODO: only possible valid exceptions should be "wrong login" or "not in team mode" - throw others (like connection error)
} }
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);
@ -366,21 +368,23 @@ class QueuePlugin implements CallbackListener, CommandListener, ManialinkPageAns
* @return bool * @return bool
*/ */
private function addPlayerToQueue(Player $player) { private function addPlayerToQueue(Player $player) {
if($this->maniaControl->client->getServerPassword() != false && $this->maniaControl->settingManager->getSetting($this, self::QUEUE_ACTIVE_ON_PASS) == false) return false; if ($this->maniaControl->client->getServerPassword() != false && $this->maniaControl->settingManager->getSetting($this, self::QUEUE_ACTIVE_ON_PASS) == false) {
return false;
}
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->sendChatMessage('$<$fff' . $player->nickname . '$> just joined the queue!'); $this->sendChatMessage('$<$fff' . $player->nickname . '$> just joined the queue!');
} }
return true; return true;
} }
/** /**
@ -392,7 +396,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++;
} }
@ -407,8 +411,8 @@ class QueuePlugin implements CallbackListener, CommandListener, ManialinkPageAns
* @param $message * @param $message
*/ */
private function sendChatMessage($message) { private function sendChatMessage($message) {
if($this->maniaControl->settingManager->getSetting($this, self::QUEUE_CHATMESSAGES)) { if ($this->maniaControl->settingManager->getSetting($this, self::QUEUE_CHATMESSAGES)) {
$this->maniaControl->chat->sendChat('$z$s$090[Queue] '.$message); $this->maniaControl->chat->sendChat('$z$s$090[Queue] ' . $message);
} }
} }
@ -465,17 +469,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);
} }
} }
@ -486,7 +490,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);

View File

@ -1,6 +1,7 @@
<?php <?php
use ManiaControl\Callbacks\CallbackListener; use ManiaControl\Callbacks\CallbackListener;
use ManiaControl\Callbacks\Callbacks;
use ManiaControl\Commands\CommandListener; use ManiaControl\Commands\CommandListener;
use ManiaControl\ManiaControl; use ManiaControl\ManiaControl;
use ManiaControl\Maps\Map; use ManiaControl\Maps\Map;
@ -92,7 +93,7 @@ class ServerRankingPlugin implements Plugin, CallbackListener, CommandListener {
//Register CallbackListeners //Register CallbackListeners
$this->maniaControl->callbackManager->registerCallbackListener(PlayerManager::CB_PLAYERCONNECT, $this, 'handlePlayerConnect'); $this->maniaControl->callbackManager->registerCallbackListener(PlayerManager::CB_PLAYERCONNECT, $this, 'handlePlayerConnect');
$this->maniaControl->callbackManager->registerCallbackListener(MapManager::CB_ENDMAP, $this, 'handleEndMap'); $this->maniaControl->callbackManager->registerCallbackListener(Callbacks::ENDMAP, $this, 'handleEndMap');
//Register CommandListener //Register CommandListener
$this->maniaControl->commandManager->registerCommandListener('rank', $this, 'command_showRank', false); $this->maniaControl->commandManager->registerCommandListener('rank', $this, 'command_showRank', false);

View File

@ -11,6 +11,7 @@ use FML\Controls\Quads\Quad_Icons64x64_1;
use FML\ManiaLink; use FML\ManiaLink;
use FML\Script\Script; use FML\Script\Script;
use ManiaControl\Callbacks\CallbackListener; use ManiaControl\Callbacks\CallbackListener;
use ManiaControl\Callbacks\Callbacks;
use ManiaControl\Callbacks\TimerListener; use ManiaControl\Callbacks\TimerListener;
use ManiaControl\Formatter; use ManiaControl\Formatter;
use ManiaControl\ManiaControl; use ManiaControl\ManiaControl;
@ -101,8 +102,8 @@ class WidgetPlugin implements CallbackListener, TimerListener, Plugin {
$this->maniaControl->manialinkManager->customUIManager->setChallengeInfoVisible(false); $this->maniaControl->manialinkManager->customUIManager->setChallengeInfoVisible(false);
// Register for callbacks // Register for callbacks
$this->maniaControl->callbackManager->registerCallbackListener(MapManager::CB_BEGINMAP, $this, 'handleOnBeginMap'); $this->maniaControl->callbackManager->registerCallbackListener(Callbacks::BEGINMAP, $this, 'handleOnBeginMap');
$this->maniaControl->callbackManager->registerCallbackListener(MapManager::CB_ENDMAP, $this, 'handleOnEndMap'); $this->maniaControl->callbackManager->registerCallbackListener(Callbacks::ENDMAP, $this, 'handleOnEndMap');
$this->maniaControl->callbackManager->registerCallbackListener(PlayerManager::CB_PLAYERCONNECT, $this, 'handlePlayerConnect'); $this->maniaControl->callbackManager->registerCallbackListener(PlayerManager::CB_PLAYERCONNECT, $this, 'handlePlayerConnect');
$this->maniaControl->callbackManager->registerCallbackListener(PlayerManager::CB_PLAYERDISCONNECT, $this, 'handlePlayerDisconnect'); $this->maniaControl->callbackManager->registerCallbackListener(PlayerManager::CB_PLAYERDISCONNECT, $this, 'handlePlayerDisconnect');