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');
@ -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;
} }

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;
@ -62,20 +62,17 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
* 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() {
@ -208,8 +198,7 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
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));
} }
@ -365,8 +351,7 @@ 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;
@ -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;
} }
@ -645,8 +630,7 @@ 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();
@ -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);
@ -765,8 +745,7 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
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;
} }
@ -776,22 +755,20 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
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) {
@ -804,21 +781,19 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
$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');
@ -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));
} }
@ -930,15 +905,13 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
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'];
} }
@ -952,19 +925,17 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
$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;
@ -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);
@ -171,12 +171,12 @@ class QueuePlugin implements CallbackListener, CommandListener, ManialinkPageAns
$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);
@ -193,7 +193,7 @@ class QueuePlugin implements CallbackListener, CommandListener, ManialinkPageAns
$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,7 +250,7 @@ class QueuePlugin implements CallbackListener, CommandListener, ManialinkPageAns
} }
foreach($this->showPlay as $showPlay) { foreach($this->showPlay as $showPlay) {
if(($showPlay['time'] + 5) < time()) { if (($showPlay['time'] + 5) < time()) {
$this->hideQueueWidget($showPlay['player']); $this->hideQueueWidget($showPlay['player']);
unset($this->showPlay[$showPlay['player']->login]); unset($this->showPlay[$showPlay['player']->login]);
} }
@ -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,16 +368,18 @@ 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!');
} }
@ -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');