diff --git a/application/core/Configurators/ScriptSettings.php b/application/core/Configurators/ScriptSettings.php index f14ae93e..396c8093 100644 --- a/application/core/Configurators/ScriptSettings.php +++ b/application/core/Configurators/ScriptSettings.php @@ -13,6 +13,7 @@ use FML\Script\Script; use ManiaControl\Admin\AuthenticationManager; use ManiaControl\Callbacks\CallbackListener; use ManiaControl\Callbacks\CallbackManager; +use ManiaControl\Callbacks\Callbacks; use ManiaControl\ManiaControl; use ManiaControl\Maps\Map; use ManiaControl\Maps\MapManager; @@ -55,7 +56,7 @@ class ScriptSettings implements ConfiguratorMenu, CallbackListener { // Register for callbacks $this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MP_PLAYERMANIALINKPAGEANSWER, $this, 'handleManialinkPageAnswer'); $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->initTables(); diff --git a/application/core/Maps/MapList.php b/application/core/Maps/MapList.php index 2a71793d..9e319670 100644 --- a/application/core/Maps/MapList.php +++ b/application/core/Maps/MapList.php @@ -16,6 +16,7 @@ use FML\ManiaLink; use FML\Script\Features\Paging; use ManiaControl\Callbacks\CallbackListener; use ManiaControl\Callbacks\CallbackManager; +use ManiaControl\Callbacks\Callbacks; use ManiaControl\ColorUtil; use ManiaControl\Formatter; 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(MapManager::CB_MAPS_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_CLEAR_MAPQUEUE, $this, 'clearMapQueue'); diff --git a/application/core/Maps/MapQueue.php b/application/core/Maps/MapQueue.php index c9951128..6bb79195 100644 --- a/application/core/Maps/MapQueue.php +++ b/application/core/Maps/MapQueue.php @@ -5,6 +5,7 @@ namespace ManiaControl\Maps; use ManiaControl\Admin\AuthenticationManager; use ManiaControl\Callbacks\CallbackListener; use ManiaControl\Callbacks\CallbackManager; +use ManiaControl\Callbacks\Callbacks; use ManiaControl\Commands\CommandListener; use ManiaControl\Formatter; use ManiaControl\ManiaControl; @@ -50,8 +51,8 @@ class MapQueue implements CallbackListener, CommandListener { public function __construct(ManiaControl $maniaControl) { $this->maniaControl = $maniaControl; - $this->maniaControl->callbackManager->registerCallbackListener(MapManager::CB_ENDMAP, $this, 'endMap'); - $this->maniaControl->callbackManager->registerCallbackListener(MapManager::CB_BEGINMAP, $this, 'beginMap'); + $this->maniaControl->callbackManager->registerCallbackListener(Callbacks::ENDMAP, $this, 'endMap'); + $this->maniaControl->callbackManager->registerCallbackListener(Callbacks::BEGINMAP, $this, 'beginMap'); $this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_AFTERINIT, $this, 'handleAfterInit'); // Init settings diff --git a/application/plugins/Dedimania/Dedimania.php b/application/plugins/Dedimania/Dedimania.php index 063548dd..5c8c34e3 100644 --- a/application/plugins/Dedimania/Dedimania.php +++ b/application/plugins/Dedimania/Dedimania.php @@ -10,12 +10,12 @@ use FML\ManiaLink; use FML\Script\Features\Paging; use ManiaControl\Callbacks\CallbackListener; use ManiaControl\Callbacks\CallbackManager; +use ManiaControl\Callbacks\Callbacks; use ManiaControl\Callbacks\TimerListener; use ManiaControl\Commands\CommandListener; use ManiaControl\Formatter; use ManiaControl\ManiaControl; use ManiaControl\Manialinks\ManialinkManager; -use ManiaControl\Maps\MapManager; use ManiaControl\Players\Player; use ManiaControl\Players\PlayerManager; 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_LINESCOUNT, 12); - $this->maniaControl->callbackManager->registerCallbackListener(MapManager::CB_BEGINMAP, $this, 'handleBeginMap'); - $this->maniaControl->callbackManager->registerCallbackListener(MapManager::CB_ENDMAP, $this, 'handleMapEnd'); + $this->maniaControl->callbackManager->registerCallbackListener(Callbacks::BEGINMAP, $this, 'handleBeginMap'); + $this->maniaControl->callbackManager->registerCallbackListener(Callbacks::ENDMAP, $this, 'handleMapEnd'); $this->maniaControl->callbackManager->registerCallbackListener(PlayerManager::CB_PLAYERCONNECT, $this, 'handlePlayerConnect'); $this->maniaControl->callbackManager->registerCallbackListener(PlayerManager::CB_PLAYERDISCONNECT, $this, 'handlePlayerDisconnect'); $this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_TM_PLAYERCHECKPOINT, $this, 'handlePlayerCheckpoint'); @@ -329,7 +329,7 @@ class Dedimania implements CallbackListener, CommandListener, TimerListener, Plu //var_dump($data); $content = $this->encode_request(self::DEDIMANIA_SETCHALLENGETIMES, $data); - $self = $this; + $self = $this; $maniaControl = $this->maniaControl; $this->maniaControl->fileReader->postData(self::DEDIMANIA_URL, function ($data, $error) use (&$self, &$maniaControl) { if ($error != '') { @@ -469,9 +469,11 @@ class Dedimania implements CallbackListener, CommandListener, TimerListener, Plu // Only improved time $improvement = 'improved his/her'; } - $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)).'$>)'; - $this->maniaControl->chat->sendInformation($message.'!'); + $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)) . '$>)'; + } + $this->maniaControl->chat->sendInformation($message . '!'); $this->updateManialink = true; } @@ -503,8 +505,8 @@ class Dedimania implements CallbackListener, CommandListener, TimerListener, Plu //create manialink $maniaLink = new ManiaLink(ManialinkManager::MAIN_MLID); $script = $maniaLink->getScript(); - $paging = new Paging(); - $script->addFeature($paging); + $paging = new Paging(); + $script->addFeature($paging); // Main frame $frame = $this->maniaControl->manialinkManager->styleManager->getDefaultListFrame($script, $paging); @@ -537,7 +539,7 @@ class Dedimania implements CallbackListener, CommandListener, TimerListener, Plu } array_push($pageFrames, $pageFrame); $y = $height / 2 - 10; - $paging->addPage($pageFrame); + $paging->addPage($pageFrame); } $recordFrame = new Frame(); @@ -970,7 +972,7 @@ class Dedimania implements CallbackListener, CommandListener, TimerListener, Plu } else if ($scriptName == 'TimeAttack' || $scriptName == 'Laps' || $scriptName == 'TeamAttack' || $scriptName == 'TimeAttackPlus') { return 'TA'; } - break; + break; } case 1: case 3: diff --git a/application/plugins/Endurance.php b/application/plugins/Endurance.php index 4946061e..b2051119 100644 --- a/application/plugins/Endurance.php +++ b/application/plugins/Endurance.php @@ -2,6 +2,7 @@ namespace steeffeen; +use ManiaControl\Callbacks\Callbacks; use ManiaControl\ManiaControl; use ManiaControl\Callbacks\CallbackListener; use ManiaControl\Callbacks\CallbackManager; @@ -50,7 +51,7 @@ class EndurancePlugin implements CallbackListener, Plugin { // Register for callbacks $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'); return true; diff --git a/application/plugins/Karma.php b/application/plugins/Karma.php index 3686893e..8089609b 100644 --- a/application/plugins/Karma.php +++ b/application/plugins/Karma.php @@ -9,11 +9,11 @@ use FML\Controls\Quad; use FML\ManiaLink; use ManiaControl\Callbacks\CallbackListener; use ManiaControl\Callbacks\CallbackManager; +use ManiaControl\Callbacks\Callbacks; use ManiaControl\Callbacks\TimerListener; use ManiaControl\ColorUtil; use ManiaControl\ManiaControl; use ManiaControl\Maps\Map; -use ManiaControl\Maps\MapManager; use ManiaControl\Players\Player; use ManiaControl\Players\PlayerManager; use ManiaControl\Plugins\Plugin; @@ -21,61 +21,58 @@ use ManiaControl\Settings\SettingManager; /** * ManiaControl Karma Plugin - * - * @author kremsy and steeffeen + * + * @author kremsy and steeffeen * @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 { /* * Constants */ - const ID = 2; - const VERSION = 0.1; - const MLID_KARMA = 'KarmaPlugin.MLID'; - const TABLE_KARMA = 'mc_karma'; - const CB_KARMA_CHANGED = 'KarmaPlugin.Changed'; - const CB_KARMA_MXUPDATED = 'KarmaPlugin.MXUpdated'; + const ID = 2; + const VERSION = 0.1; + const MLID_KARMA = 'KarmaPlugin.MLID'; + const TABLE_KARMA = 'mc_karma'; + const CB_KARMA_CHANGED = 'KarmaPlugin.Changed'; + const CB_KARMA_MXUPDATED = 'KarmaPlugin.MXUpdated'; const SETTING_AVAILABLE_VOTES = 'Available Votes (X-Y: Comma separated)'; - const SETTING_WIDGET_ENABLE = 'Enable Karma Widget'; - const SETTING_WIDGET_TITLE = 'Widget-Title'; - const SETTING_WIDGET_POSX = 'Widget-Position: X'; - const SETTING_WIDGET_POSY = 'Widget-Position: Y'; - const SETTING_WIDGET_WIDTH = 'Widget-Size: Width'; - const SETTING_WIDGET_HEIGHT = 'Widget-Size: Height'; - const STAT_PLAYER_MAPVOTES = 'Voted Maps'; - + const SETTING_WIDGET_ENABLE = 'Enable Karma Widget'; + const SETTING_WIDGET_TITLE = 'Widget-Title'; + const SETTING_WIDGET_POSX = 'Widget-Position: X'; + const SETTING_WIDGET_POSY = 'Widget-Position: Y'; + const SETTING_WIDGET_WIDTH = 'Widget-Size: Width'; + const SETTING_WIDGET_HEIGHT = 'Widget-Size: Height'; + const STAT_PLAYER_MAPVOTES = 'Voted Maps'; + /* * 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_IMPORTING = 'Import old MX-Karmas'; - const MX_IMPORT_TABLE = 'mc_karma_mximport'; - const MX_KARMA_URL = 'http://karma.mania-exchange.com/api2/'; - const MX_KARMA_STARTSESSION = 'startSession'; - const MX_KARMA_ACTIVATESESSION = 'activateSession'; - const MX_KARMA_SAVEVOTES = 'saveVotes'; - const MX_KARMA_GETMAPRATING = 'getMapRating'; - + const MX_IMPORT_TABLE = 'mc_karma_mximport'; + const MX_KARMA_URL = 'http://karma.mania-exchange.com/api2/'; + const MX_KARMA_STARTSESSION = 'startSession'; + const MX_KARMA_ACTIVATESESSION = 'activateSession'; + const MX_KARMA_SAVEVOTES = 'saveVotes'; + const MX_KARMA_GETMAPRATING = 'getMapRating'; + /* * Private Properties */ /** - * * @var ManiaControl $maniaControl */ private $maniaControl = null; private $updateManialink = false; /** - * * @var ManiaLink $manialink */ private $manialink = null; private $mxKarma = array(); /** - * * @see \ManiaControl\Plugins\Plugin */ public static function prepare(ManiaControl $maniaControl) { @@ -83,21 +80,20 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin { $maniaControl->settingManager->initSetting(get_class(), self::SETTING_MX_KARMA_IMPORTING, true); $maniaControl->settingManager->initSetting(get_class(), self::SETTING_WIDGET_DISPLAY_MX, true); $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', ''); } } /** - * * @see \ManiaControl\Plugins\Plugin::load() */ public function load(ManiaControl $maniaControl) { $this->maniaControl = $maniaControl; - + // Init database $this->initTables(); - + // Init settings $this->maniaControl->settingManager->initSetting($this, self::SETTING_AVAILABLE_VOTES, '-2,2'); $this->maniaControl->settingManager->initSetting($this, self::SETTING_WIDGET_ENABLE, true); @@ -106,33 +102,32 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin { $this->maniaControl->settingManager->initSetting($this, self::SETTING_WIDGET_POSY, 90 - 10 - 6); $this->maniaControl->settingManager->initSetting($this, self::SETTING_WIDGET_WIDTH, 25.); $this->maniaControl->settingManager->initSetting($this, self::SETTING_WIDGET_HEIGHT, 12.); - + // Register for callbacks $this->maniaControl->timerManager->registerTimerListening($this, 'handle1Second', 1000); - $this->maniaControl->callbackManager->registerCallbackListener(MapManager::CB_BEGINMAP, $this, 'handleBeginMap'); - $this->maniaControl->callbackManager->registerCallbackListener(MapManager::CB_BEGINMAP, $this, 'importMxKarmaVotes'); - $this->maniaControl->callbackManager->registerCallbackListener(MapManager::CB_ENDMAP, $this, 'sendMxKarmaVotes'); + $this->maniaControl->callbackManager->registerCallbackListener(Callbacks::BEGINMAP, $this, 'handleBeginMap'); + $this->maniaControl->callbackManager->registerCallbackListener(Callbacks::BEGINMAP, $this, 'importMxKarmaVotes'); + $this->maniaControl->callbackManager->registerCallbackListener(Callbacks::ENDMAP, $this, 'sendMxKarmaVotes'); $this->maniaControl->callbackManager->registerCallbackListener(PlayerManager::CB_PLAYERCONNECT, $this, 'handlePlayerConnect'); $this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MP_PLAYERCHAT, $this, 'handlePlayerChat'); $this->maniaControl->callbackManager->registerCallbackListener(SettingManager::CB_SETTINGS_CHANGED, $this, 'updateSettings'); - + // Define player stats $this->maniaControl->statisticManager->defineStatMetaData(self::STAT_PLAYER_MAPVOTES); - + // Register Stat in Simple StatsList $this->maniaControl->statisticManager->simpleStatsList->registerStat(self::STAT_PLAYER_MAPVOTES, 100, "VM"); - + $this->updateManialink = true; - + // Open MX-Karma Session $this->mxKarmaOpenSession(); $this->mxKarma['startTime'] = time(); - + return true; } /** - * * @see \ManiaControl\Plugins\Plugin::unload() */ public function unload() { @@ -143,7 +138,6 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin { } /** - * * @see \ManiaControl\Plugins\Plugin::getId() */ public static function getId() { @@ -151,7 +145,6 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin { } /** - * * @see \ManiaControl\Plugins\Plugin::getName() */ public static function getName() { @@ -159,7 +152,6 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin { } /** - * * @see \ManiaControl\Plugins\Plugin::getVersion() */ public static function getVersion() { @@ -167,7 +159,6 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin { } /** - * * @see \ManiaControl\Plugins\Plugin::getAuthor() */ public static function getAuthor() { @@ -175,7 +166,6 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin { } /** - * * @see \ManiaControl\Plugins\Plugin::getDescription() */ public static function getDescription() { @@ -184,49 +174,46 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin { /** * Handle ManiaControl 1 Second callback - * + * * @param $time */ public function handle1Second($time) { if (!$this->updateManialink) { return; } - + $displayMxKarma = $this->maniaControl->settingManager->getSetting($this, self::SETTING_WIDGET_DISPLAY_MX); - + // Get players $players = $this->updateManialink; if ($players === true) { $players = $this->maniaControl->playerManager->getPlayers(); } $this->updateManialink = false; - + // Get map karma $map = $this->maniaControl->mapManager->getCurrentMap(); - + // 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'])) { - $karma = $this->mxKarma['modeVoteAverage'] / 100; + $karma = $this->mxKarma['modeVoteAverage'] / 100; $voteCount = $this->mxKarma['modeVoteCount']; - } - else { - $karma = $this->getMapKarma($map); - $votes = $this->getMapVotes($map); + } else { + $karma = $this->getMapKarma($map); + $votes = $this->getMapVotes($map); $voteCount = $votes['count']; } - + if ($this->maniaControl->settingManager->getSetting($this, self::SETTING_WIDGET_ENABLE)) { // Build karma manialink $this->buildManialink(); - + // Update karma gauge & label /** - * * @var Gauge $karmaGauge */ $karmaGauge = $this->manialink->karmaGauge; /** - * * @var Label $karmaLabel */ $karmaLabel = $this->manialink->karmaLabel; @@ -236,21 +223,20 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin { $karmaColor = ColorUtil::floatToStatusColor($karma); $karmaGauge->setColor($karmaColor . '7'); $karmaLabel->setText(' ' . round($karma * 100.) . '% (' . $voteCount . ')'); - } - else { + } else { $karmaGauge->setRatio(0.); $karmaGauge->setColor('00fb'); $karmaLabel->setText('-'); } - + // Loop players - foreach ($players as $login => $player) { + foreach($players as $login => $player) { // Get player vote // TODO: show the player his own vote in some way // $vote = $this->getPlayerVote($player, $map); // $votesFrame = $this->manialink->votesFrame; // $votesFrame->removeChildren(); - + // Send manialink $this->maniaControl->manialinkManager->sendManialink($this->manialink, $login); } @@ -259,32 +245,32 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin { /** * Handle BeginMap ManiaControl callback - * + * * @param Map $map */ public function handleBeginMap(Map $map) { // send Map Karma to MX from previous Map if (isset($this->mxKarma['map'])) { $votes = array(); - foreach ($this->mxKarma['votes'] as $login => $value) { + foreach($this->mxKarma['votes'] as $login => $value) { $player = $this->maniaControl->playerManager->getPlayer($login); array_push($votes, array("login" => $login, "nickname" => $player->rawNickname, "vote" => $value)); } $this->postKarmaVotes($this->mxKarma['map'], $votes); unset($this->mxKarma['map']); } - + unset($this->mxKarma['votes']); $this->mxKarma['startTime'] = time(); - $this->updateManialink = true; - + $this->updateManialink = true; + // Get Karma votes at begin of map $this->getMxKarmaVotes(); } /** * Handle PlayerConnect callback - * + * * @param \ManiaControl\Players\Player $player */ public function handlePlayerConnect(Player $player) { @@ -292,18 +278,18 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin { return; } $this->queryManialinkUpdateFor($player); - + // Get Mx Karma Vote for Player $this->getMxKarmaVotes($player); } /** * Handle PlayerChat callback - * + * * @param array $chatCallback */ public function handlePlayerChat(array $chatCallback) { - $login = $chatCallback[1][1]; + $login = $chatCallback[1][1]; $player = $this->maniaControl->playerManager->getPlayer($login); if (!$player) { return; @@ -320,7 +306,7 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin { if ($countPositive <= 0 && $countNegative <= 0) { return; } - $vote = $countPositive - $countNegative; + $vote = $countPositive - $countNegative; $success = $this->handleVote($player, $vote); if (!$success) { $this->maniaControl->chat->sendError('Error occurred.', $player->login); @@ -331,57 +317,56 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin { /** * Handle a vote done by a player - * + * * @param Player $player - * @param int $vote + * @param int $vote * @return bool */ private function handleVote(Player $player, $vote) { // Check vote $votesSetting = $this->maniaControl->settingManager->getSetting($this, self::SETTING_AVAILABLE_VOTES); - $votes = explode(',', $votesSetting); - $voteLow = intval($votes[0]); - $voteHigh = $voteLow + 2; + $votes = explode(',', $votesSetting); + $voteLow = intval($votes[0]); + $voteHigh = $voteLow + 2; if (isset($votes[1])) { $voteHigh = intval($votes[1]); } if ($vote < $voteLow || $vote > $voteHigh) { return false; } - + // Calculate actual voting $vote -= $voteLow; $voteHigh -= $voteLow; $vote /= $voteHigh; - + // Save vote $map = $this->maniaControl->mapManager->getCurrentMap(); - + // Update vote in MX karma array if ($this->maniaControl->settingManager->getSetting($this, self::SETTING_MX_KARMA_ACTIVATED) && isset($this->mxKarma["session"])) { if (!isset($this->mxKarma["votes"][$player->login])) { $sum = $this->mxKarma["voteCount"] * $this->mxKarma["voteAverage"] + $vote * 100; $this->mxKarma["voteCount"]++; - + $modeSum = $this->mxKarma["modeVoteCount"] * $this->mxKarma["modeVoteAverage"] + $vote * 100; $this->mxKarma["modeVoteCount"]++; - } - else { + } else { $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; } - - $this->mxKarma["voteAverage"] = $sum / $this->mxKarma["voteCount"]; - $this->mxKarma["modeVoteAverage"] = $modeSum / $this->mxKarma["modeVoteCount"]; + + $this->mxKarma["voteAverage"] = $sum / $this->mxKarma["voteCount"]; + $this->mxKarma["modeVoteAverage"] = $modeSum / $this->mxKarma["modeVoteCount"]; $this->mxKarma["votes"][$player->login] = $vote * 100; } - + $voted = $this->getPlayerVote($player, $map); if (!$voted) { $this->maniaControl->statisticManager->incrementStat(self::STAT_PLAYER_MAPVOTES, $player, $this->maniaControl->server->index); } - + $success = $this->savePlayerVote($player, $map, $vote); if (!$success) { return false; @@ -393,7 +378,7 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin { /** * Query the player to update the manialink - * + * * @param Player $player */ private function queryManialinkUpdateFor(Player $player) { @@ -411,7 +396,7 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin { */ private function initTables() { $mysqli = $this->maniaControl->database->mysqli; - + // Create local table $query = "CREATE TABLE IF NOT EXISTS `" . self::TABLE_KARMA . "` ( `index` int(11) NOT NULL AUTO_INCREMENT, @@ -426,14 +411,14 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin { if ($mysqli->error) { trigger_error($mysqli->error, E_USER_ERROR); } - + // Migrate settings $this->maniaControl->database->migrationHelper->transferSettings('KarmaPlugin', $this); - + if (!$this->maniaControl->settingManager->getSetting($this, self::SETTING_MX_KARMA_ACTIVATED)) { return; } - + // Create mx table $query = "CREATE TABLE IF NOT EXISTS `" . self::MX_IMPORT_TABLE . "` ( `index` int(11) NOT NULL AUTO_INCREMENT, @@ -451,15 +436,15 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin { /** * Save the vote of the player for the map - * + * * @param Player $player - * @param Map $map - * @param float $vote + * @param Map $map + * @param float $vote * @return bool */ private function savePlayerVote(Player $player, Map $map, $vote) { $mysqli = $this->maniaControl->database->mysqli; - $query = "INSERT INTO `" . self::TABLE_KARMA . "` ( + $query = "INSERT INTO `" . self::TABLE_KARMA . "` ( `mapIndex`, `playerIndex`, `vote` @@ -474,20 +459,20 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin { trigger_error($mysqli->error); return false; } - + return $result; } /** * Get the current vote of the player for the map - * + * * @param Player $player - * @param Map $map + * @param Map $map * @return int */ public function getPlayerVote(Player $player, Map $map) { $mysqli = $this->maniaControl->database->mysqli; - $query = "SELECT * FROM `" . self::TABLE_KARMA . "` + $query = "SELECT * FROM `" . self::TABLE_KARMA . "` WHERE `playerIndex` = {$player->index} AND `mapIndex` = {$map->index} AND `vote` >= 0;"; @@ -508,13 +493,13 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin { /** * Get the current karma of the map - * + * * @param Map $map * @return float | bool */ public function getMapKarma(Map $map) { $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} AND `vote` >= 0;"; $result = $mysqli->query($query); @@ -537,13 +522,13 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin { /** * Get the current Votes for the Map - * + * * @param Map $map * @return array */ public function getMapVotes(Map $map) { $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} AND `vote` >= 0 GROUP BY `vote`;"; @@ -554,7 +539,7 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin { } $votes = array(); $count = 0; - while ($vote = $result->fetch_object()) { + while($vote = $result->fetch_object()) { $votes[$vote->vote] = $vote; $count += $vote->count; } @@ -565,35 +550,35 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin { /** * Build karma voting manialink if necessary - * + * * @param bool $forceBuild */ private function buildManialink($forceBuild = false) { if (is_object($this->manialink) && !$forceBuild) { return; } - - $title = $this->maniaControl->settingManager->getSetting($this, self::SETTING_WIDGET_TITLE); - $pos_x = $this->maniaControl->settingManager->getSetting($this, self::SETTING_WIDGET_POSX); - $pos_y = $this->maniaControl->settingManager->getSetting($this, self::SETTING_WIDGET_POSY); - $width = $this->maniaControl->settingManager->getSetting($this, self::SETTING_WIDGET_WIDTH); - $height = $this->maniaControl->settingManager->getSetting($this, self::SETTING_WIDGET_HEIGHT); - $labelStyle = $this->maniaControl->manialinkManager->styleManager->getDefaultLabelStyle(); - $quadStyle = $this->maniaControl->manialinkManager->styleManager->getDefaultQuadStyle(); + + $title = $this->maniaControl->settingManager->getSetting($this, self::SETTING_WIDGET_TITLE); + $pos_x = $this->maniaControl->settingManager->getSetting($this, self::SETTING_WIDGET_POSX); + $pos_y = $this->maniaControl->settingManager->getSetting($this, self::SETTING_WIDGET_POSY); + $width = $this->maniaControl->settingManager->getSetting($this, self::SETTING_WIDGET_WIDTH); + $height = $this->maniaControl->settingManager->getSetting($this, self::SETTING_WIDGET_HEIGHT); + $labelStyle = $this->maniaControl->manialinkManager->styleManager->getDefaultLabelStyle(); + $quadStyle = $this->maniaControl->manialinkManager->styleManager->getDefaultQuadStyle(); $quadSubstyle = $this->maniaControl->manialinkManager->styleManager->getDefaultQuadSubstyle(); - + $manialink = new ManiaLink(self::MLID_KARMA); - + $frame = new Frame(); $manialink->add($frame); $frame->setPosition($pos_x, $pos_y); - + $backgroundQuad = new Quad(); $frame->add($backgroundQuad); $backgroundQuad->setY($height * 0.15); $backgroundQuad->setSize($width, $height); $backgroundQuad->setStyles($quadStyle, $quadSubstyle); - + $titleLabel = new Label(); $frame->add($titleLabel); $titleLabel->setY($height * 0.36); @@ -603,13 +588,13 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin { $titleLabel->setTextSize(1); $titleLabel->setScale(0.90); $titleLabel->setText($title); - + $karmaGauge = new Gauge(); $frame->add($karmaGauge); $karmaGauge->setSize($width * 0.95, $height * 0.92); $karmaGauge->setDrawBg(false); $manialink->karmaGauge = $karmaGauge; - + $karmaLabel = new Label(); $frame->add($karmaLabel); $karmaLabel->setPosition(0, -0.4, 1); @@ -617,17 +602,17 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin { $karmaLabel->setStyle($labelStyle); $karmaLabel->setTextSize(1); $manialink->karmaLabel = $karmaLabel; - + $votesFrame = new Frame(); $frame->add($votesFrame); $manialink->votesFrame = $votesFrame; - + $this->manialink = $manialink; } /** * Update Settings - * + * * @param $class * @param $settingName * @param $value @@ -636,20 +621,19 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin { if (!$class = get_class()) { return; } - + $serverLogin = $this->maniaControl->server->login; if ($settingName == '$l[http://karma.mania-exchange.com/auth/getapikey?server=' . $serverLogin . ']MX Karma Code for ' . $serverLogin . '$l') { $this->mxKarmaOpenSession(); } - + if ($settingName == 'Enable Karma Widget' && $value == true) { $this->updateManialink = true; $this->handle1Second(time()); - } - elseif ($settingName == 'Enable Karma Widget' && $value == false) { + } elseif ($settingName == 'Enable Karma Widget' && $value == false) { $this->updateManialink = false; - $ml = new ManiaLink(self::MLID_KARMA); - $mltext = $ml->render()->saveXML(); + $ml = new ManiaLink(self::MLID_KARMA); + $mltext = $ml->render()->saveXML(); $this->maniaControl->manialinkManager->sendManialink($mltext); } } @@ -661,40 +645,38 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin { if (!$this->maniaControl->settingManager->getSetting($this, self::SETTING_MX_KARMA_ACTIVATED)) { return; } - + $serverLogin = $this->maniaControl->server->login; $mxKarmaCode = $this->maniaControl->settingManager->getSetting($this, '$l[http://karma.mania-exchange.com/auth/getapikey?server=' . $serverLogin . ']MX Karma Code for ' . $serverLogin . '$l'); - + if ($mxKarmaCode == '') { return; } - + $applicationIdentifier = 'ManiaControl v' . ManiaControl::VERSION; - $testMode = 'true'; - + $testMode = 'true'; + $query = self::MX_KARMA_URL . self::MX_KARMA_STARTSESSION; $query .= '?serverLogin=' . $serverLogin; $query .= '&applicationIdentifier=' . urlencode($applicationIdentifier); $query .= '&testMode=' . $testMode; - + $this->mxKarma['connectionInProgress'] = true; - + $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) { $data = json_decode($data); if ($data->success) { $self->mxKarma['session'] = $data->data; $self->activateSession($mxKarmaCode); - } - else { + } else { $self->maniaControl->log("Error while authenticating on Mania-Exchange Karma"); // TODO remove temp trigger $self->maniaControl->errorHandler->triggerDebugNotice("Error while authenticating on Mania-Exchange Karma " . $data->data->message); $self->mxKarma['connectionInProgress'] = false; } - } - else { + } else { $self->maniaControl->log($error); // TODO remove temp trigger $self->maniaControl->errorHandler->triggerDebugNotice("Error while authenticating on Mania-Exchange Karma " . $error); @@ -705,35 +687,33 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin { /** * Activates the MX-Karma Session - * + * * @param $mxKarmaCode */ private function activateSession($mxKarmaCode) { $hash = $this->buildActivationHash($this->mxKarma['session']->sessionSeed, $mxKarmaCode); - + $query = self::MX_KARMA_URL . self::MX_KARMA_ACTIVATESESSION; $query .= '?sessionKey=' . urlencode($this->mxKarma['session']->sessionKey); $query .= '&activationHash=' . urlencode($hash); - + $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) { $data = json_decode($data); if ($data->success && $data->data->activated) { $self->maniaControl->log("Successfully authenticated on Mania-Exchange Karma"); $self->mxKarma['connectionInProgress'] = false; - + // Fetch the Mx Karma Votes $self->getMxKarmaVotes(); - } - else { + } else { $self->maniaControl->log("Error while authenticating on Mania-Exchange Karma " . $data->data->message); // TODO remove temp trigger $self->maniaControl->errorHandler->triggerDebugNotice("Error while authenticating on Mania-Exchange Karma " . $data->data->message . " url Query " . $query); $self->mxKarma['connectionInProgress'] = false; } - } - else { + } else { // TODO remove temp trigger $self->maniaControl->errorHandler->triggerDebugNotice("Error while authenticating on Mania-Exchange Karma " . $error); $self->maniaControl->log($error); @@ -749,76 +729,71 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin { if (!$this->maniaControl->settingManager->getSetting($this, self::SETTING_MX_KARMA_ACTIVATED)) { return; } - + if (!isset($this->mxKarma['session'])) { if (!isset($this->mxKarma['connectionInProgress']) || !$this->mxKarma['connectionInProgress']) { $this->mxKarmaOpenSession(); } return; } - + $map = $this->maniaControl->mapManager->getCurrentMap(); - + $properties = array(); - + $gameMode = $this->maniaControl->server->getGameMode(true); if ($gameMode == 'Script') { - $scriptName = $this->maniaControl->client->getScriptName(); + $scriptName = $this->maniaControl->client->getScriptName(); $properties['gamemode'] = $scriptName["CurrentValue"]; - } - else { + } else { $properties['gamemode'] = $gameMode; } - + $properties['titleid'] = $this->maniaControl->server->titleId; - $properties['mapuid'] = $map->uid; - + $properties['mapuid'] = $map->uid; + if (!$player) { $properties['getvotesonly'] = false; $properties['playerlogins'] = array(); - foreach ($this->maniaControl->playerManager->getPlayers() as $plyr) { + foreach($this->maniaControl->playerManager->getPlayers() as $plyr) { /** - * * @var Player $player */ $properties['playerlogins'][] = $plyr->login; } - } - else { + } else { $properties['getvotesonly'] = true; $properties['playerlogins'] = array($player->login); } - + $content = json_encode($properties); - $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) { + $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) { if (!$error) { $data = json_decode($data); if ($data->success) { - + // Fetch averages if its for the whole server if (!$player) { - $self->mxKarma["voteCount"] = $data->data->votecount; - $self->mxKarma["voteAverage"] = $data->data->voteaverage; - $self->mxKarma["modeVoteCount"] = $data->data->modevotecount; + $self->mxKarma["voteCount"] = $data->data->votecount; + $self->mxKarma["voteAverage"] = $data->data->voteaverage; + $self->mxKarma["modeVoteCount"] = $data->data->modevotecount; $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->updateManialink = true; $self->maniaControl->callbackManager->triggerCallback($self::CB_KARMA_MXUPDATED, $self->mxKarma); $self->maniaControl->log("MX-Karma Votes successfully fetched"); - } - else { + } else { $self->maniaControl->log("Error while fetching votes: " . $data->data->message); // 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)); } - } - else { + } else { $self->maniaControl->log($error); } }, $content, false, 'application/json'); @@ -826,60 +801,60 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin { /** * Import old Karma votes to Mania-Exchange Karma - * + * * @param Map $map */ public function importMxKarmaVotes(Map $map) { if (!$this->maniaControl->settingManager->getSetting($this, self::SETTING_MX_KARMA_ACTIVATED)) { return; } - + if (!$this->maniaControl->settingManager->getSetting($this, self::SETTING_MX_KARMA_IMPORTING)) { return; } - + if (!isset($this->mxKarma['session'])) { if (!isset($this->mxKarma['connectionInProgress']) || !$this->mxKarma['connectionInProgress']) { $this->mxKarmaOpenSession(); } return; } - + $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); if ($mysqli->error) { trigger_error($mysqli->error); return; } $vote = $result->fetch_object(); - + 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); if ($mysqli->error) { trigger_error($mysqli->error); return; } - + $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)); } - + $this->postKarmaVotes($map, $votes, true); - + // Flag Map as Imported in database if it is a import $query = "INSERT INTO `" . self::MX_IMPORT_TABLE . "` (`mapIndex`,`mapImported`) VALUES ({$map->index},true) ON DUPLICATE KEY UPDATE `mapImported` = true;"; $mysqli->query($query); if ($mysqli->error) { trigger_error($mysqli->error); } - + $result2->free(); } $result->free_result(); - + return; } @@ -890,27 +865,27 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin { if (!$this->maniaControl->settingManager->getSetting($this, self::SETTING_MX_KARMA_ACTIVATED)) { return; } - + if (!isset($this->mxKarma['session'])) { if (!isset($this->mxKarma['connectionInProgress']) || !$this->mxKarma['connectionInProgress']) { $this->mxKarmaOpenSession(); } return; } - + if (!isset($this->mxKarma['votes']) || count($this->mxKarma['votes']) == 0) { return; } - + $this->mxKarma['map'] = $map; } /** * Post the Karma votes to MX-Karma - * - * @param Map $map + * + * @param Map $map * @param array $votes - * @param bool $import + * @param bool $import */ private function postKarmaVotes(Map $map, array $votes, $import = false) { if (!isset($this->mxKarma['session'])) { @@ -919,52 +894,48 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin { } return; } - + $gameMode = $this->maniaControl->server->getGameMode(true); - + if (count($votes) == 0) { return; } - + $properties = array(); if ($gameMode == 'Script') { - $scriptName = $this->maniaControl->client->getScriptName(); + $scriptName = $this->maniaControl->client->getScriptName(); $properties['gamemode'] = $scriptName["CurrentValue"]; - } - else { + } else { $properties['gamemode'] = $gameMode; } - + if ($import) { $properties['maptime'] = 0; - } - else { + } else { $properties['maptime'] = time() - $this->mxKarma['startTime']; } - - $properties['votes'] = $votes; - $properties['titleid'] = $this->maniaControl->server->titleId; - $properties['mapname'] = $map->rawName; - $properties['mapuid'] = $map->uid; + + $properties['votes'] = $votes; + $properties['titleid'] = $this->maniaControl->server->titleId; + $properties['mapname'] = $map->rawName; + $properties['mapuid'] = $map->uid; $properties['mapauthor'] = $map->authorLogin; - $properties['isimport'] = $import; - + $properties['isimport'] = $import; + $content = json_encode($properties); - + $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) { $data = json_decode($data); if ($data->success) { $self->maniaControl->log("Votes successfully permitted"); - } - else { + } else { $self->maniaControl->log("Error while updating votes: " . $data->data->message); // 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)); } - } - else { + } else { $self->maniaControl->log($error); } }, $content, false, 'application/json'); @@ -972,7 +943,7 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin { /** * Builds a sha512 activation Hash for the MX-Karma - * + * * @param $sessionSeed * @param $mxKey * @return string diff --git a/application/plugins/LocalRecords.php b/application/plugins/LocalRecords.php index 81a4ea46..78f1dcfe 100644 --- a/application/plugins/LocalRecords.php +++ b/application/plugins/LocalRecords.php @@ -12,6 +12,7 @@ use FML\Script\Features\Paging; use ManiaControl\Admin\AuthenticationManager; use ManiaControl\Callbacks\CallbackListener; use ManiaControl\Callbacks\CallbackManager; +use ManiaControl\Callbacks\Callbacks; use ManiaControl\Callbacks\TimerListener; use ManiaControl\Commands\CommandListener; use ManiaControl\Settings\SettingManager; @@ -96,7 +97,7 @@ class LocalRecordsPlugin implements CallbackListener, CommandListener, TimerList // Register for callbacks $this->maniaControl->timerManager->registerTimerListening($this, 'handle1Second', 1000); $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(PlayerManager::CB_PLAYERCONNECT, $this, 'handlePlayerConnect'); $this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_TM_PLAYERCHECKPOINT, $this, 'handlePlayerCheckpoint'); diff --git a/application/plugins/QueuePlugin.php b/application/plugins/QueuePlugin.php index e33a7eac..0f93aa83 100644 --- a/application/plugins/QueuePlugin.php +++ b/application/plugins/QueuePlugin.php @@ -7,11 +7,11 @@ use FML\Controls\Quads\Quad_Icons64x64_1; use FML\ManiaLink; use ManiaControl\Callbacks\CallbackListener; use ManiaControl\Callbacks\CallbackManager; +use ManiaControl\Callbacks\Callbacks; use ManiaControl\Callbacks\TimerListener; use ManiaControl\Commands\CommandListener; use ManiaControl\ManiaControl; use ManiaControl\Manialinks\ManialinkPageAnswerListener; -use ManiaControl\Maps\MapManager; use ManiaControl\Players\Player; use ManiaControl\Players\PlayerManager; use ManiaControl\Plugins\Plugin; @@ -30,11 +30,11 @@ class QueuePlugin implements CallbackListener, CommandListener, ManialinkPageAns /** * Constants */ - const ID = 22; - const VERSION = 0.1; - const ML_ID = 'Queue.Widget'; - const ML_ADDTOQUEUE = 'Queue.Add'; - const ML_REMOVEFROMQUEUE = 'Queue.Remove'; + const ID = 22; + const VERSION = 0.1; + const ML_ID = 'Queue.Widget'; + const ML_ADDTOQUEUE = 'Queue.Add'; + const ML_REMOVEFROMQUEUE = 'Queue.Remove'; const QUEUE_MAX = 'Maximum number in the queue'; const QUEUE_WIDGET_POS_X = 'X position of the widget'; @@ -50,7 +50,7 @@ class QueuePlugin implements CallbackListener, CommandListener, ManialinkPageAns private $queue = array(); private $spectators = array(); private $showPlay = array(); - private $maxPlayers = 0; + private $maxPlayers = 0; /** * 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_PLAYERDISCONNECT, $this, 'handlePlayerDisconnect'); $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_REMOVEFROMQUEUE, $this, 'handleManiaLinkAnswerRemove'); @@ -86,7 +86,7 @@ class QueuePlugin implements CallbackListener, CommandListener, ManialinkPageAns $this->maniaControl->settingManager->initSetting($this, self::QUEUE_CHATMESSAGES, true); foreach($this->maniaControl->playerManager->getPlayers() as $player) { - if($player->isSpectator) { + if ($player->isSpectator) { $this->spectators[$player->login] = $player->login; $this->maniaControl->client->forceSpectator($player->login, 1); $this->showJoinQueueWidget($player); @@ -168,15 +168,15 @@ class QueuePlugin implements CallbackListener, CommandListener, ManialinkPageAns * @param Player $player */ public function handlePlayerConnect(Player $player) { - $maxPlayers = $this->maniaControl->client->getMaxPlayers(); - $this->maxPlayers = $maxPlayers['CurrentValue']; + $maxPlayers = $this->maniaControl->client->getMaxPlayers(); + $this->maxPlayers = $maxPlayers['CurrentValue']; - if($player->isSpectator) { + if ($player->isSpectator) { $this->spectators[$player->login] = $player->login; $this->maniaControl->client->forceSpectator($player->login, 1); $this->showJoinQueueWidget($player); } else { - if(count($this->queue) != 0) { + if (count($this->queue) != 0) { $this->maniaControl->client->forceSpectator($player->login, 1); $this->spectators[$player->login] = $player->login; $this->showJoinQueueWidget($player); @@ -190,10 +190,10 @@ class QueuePlugin implements CallbackListener, CommandListener, ManialinkPageAns * @param Player $player */ public function handlePlayerDisconnect(Player $player) { - $maxPlayers = $this->maniaControl->client->getMaxPlayers(); - $this->maxPlayers = $maxPlayers['CurrentValue']; + $maxPlayers = $this->maniaControl->client->getMaxPlayers(); + $this->maxPlayers = $maxPlayers['CurrentValue']; - if(isset($this->spectators[$player->login])) { + if (isset($this->spectators[$player->login])) { unset($this->spectators[$player->login]); } $this->removePlayerFromQueue($player->login); @@ -209,27 +209,27 @@ class QueuePlugin implements CallbackListener, CommandListener, ManialinkPageAns $login = $callback[1][0]['Login']; $player = $this->maniaControl->playerManager->getPlayer($login); - if(!is_null($player)) { - if($player->isSpectator) { - if(!isset($this->spectators[$player->login])) { + if (!is_null($player)) { + if ($player->isSpectator) { + if (!isset($this->spectators[$player->login])) { $this->maniaControl->client->forceSpectator($player->login, 1); $this->spectators[$player->login] = $player->login; $this->showJoinQueueWidget($player); } } else { $this->removePlayerFromQueue($player->login); - if(isset($this->spectators[$player->login])) { + if (isset($this->spectators[$player->login])) { unset($this->spectators[$player->login]); } $found = false; foreach($this->showPlay as $showPlay) { - if($showPlay['player']->login == $player->login) { + if ($showPlay['player']->login == $player->login) { $found = true; } } - if(!$found) { + if (!$found) { $this->hideQueueWidget($player); } } @@ -240,7 +240,7 @@ class QueuePlugin implements CallbackListener, CommandListener, ManialinkPageAns * Function called on every second. */ 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(); } @@ -250,22 +250,22 @@ class QueuePlugin implements CallbackListener, CommandListener, ManialinkPageAns } foreach($this->showPlay as $showPlay) { - if(($showPlay['time'] + 5) < time()) { + if (($showPlay['time'] + 5) < time()) { $this->hideQueueWidget($showPlay['player']); unset($this->showPlay[$showPlay['player']->login]); } } } - /** - * Checks for being of new map to retrieve maximum number of players. - * - * @param $currentMap - */ - public function handleBeginMap($currentMap) { - $maxPlayers = $this->maniaControl->client->getMaxPlayers(); - $this->maxPlayers = $maxPlayers['CurrentValue']; - } + /** + * Checks for being of new map to retrieve maximum number of players. + * + * @param $currentMap + */ + public function handleBeginMap($currentMap) { + $maxPlayers = $this->maniaControl->client->getMaxPlayers(); + $this->maxPlayers = $maxPlayers['CurrentValue']; + } /** * 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 */ private function moveFirstPlayerToPlay() { - if(count($this->queue) > 0) { + if (count($this->queue) > 0) { $firstPlayer = $this->maniaControl->playerManager->getPlayer($this->queue[0]->login); $this->forcePlayerToPlay($firstPlayer); } @@ -305,9 +305,11 @@ class QueuePlugin implements CallbackListener, CommandListener, ManialinkPageAns * @param 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 { $this->maniaControl->client->forceSpectator($player->login, 2); } catch(Exception $e) { @@ -325,7 +327,7 @@ class QueuePlugin implements CallbackListener, CommandListener, ManialinkPageAns $teams = array(); /** @var Player $playerObj */ foreach($this->maniaControl->playerManager->players as $playerObj) { - if(!isset($teams[$playerObj->teamId])) { + if (!isset($teams[$playerObj->teamId])) { $teams[$playerObj->teamId] = 1; } else { $teams[$playerObj->teamId]++; @@ -335,21 +337,21 @@ class QueuePlugin implements CallbackListener, CommandListener, ManialinkPageAns $smallestTeam = null; $smallestSize = 999; foreach($teams as $team => $size) { - if($size < $smallestSize) { + if ($size < $smallestSize) { $smallestTeam = $team; $smallestSize = $size; } } try { - if($smallestTeam != -1) { + if ($smallestTeam != -1) { $this->maniaControl->client->forcePlayerTeam($player->login, $smallestTeam); } } catch(Exception $e) { // 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]); } $this->removePlayerFromQueue($player->login); @@ -366,21 +368,23 @@ class QueuePlugin implements CallbackListener, CommandListener, ManialinkPageAns * @return bool */ 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) { - if($queuedPlayer->login == $player->login) { + if ($queuedPlayer->login == $player->login) { $this->maniaControl->chat->sendError('You\'re already in the queue!', $player->login); 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->sendChatMessage('$<$fff' . $player->nickname . '$> just joined the queue!'); } - return true; + return true; } /** @@ -392,7 +396,7 @@ class QueuePlugin implements CallbackListener, CommandListener, ManialinkPageAns $count = 0; $newQueue = array(); foreach($this->queue as $queuePlayer) { - if($queuePlayer->login != $login) { + if ($queuePlayer->login != $login) { $newQueue[$count] = $queuePlayer; $count++; } @@ -407,8 +411,8 @@ class QueuePlugin implements CallbackListener, CommandListener, ManialinkPageAns * @param $message */ private function sendChatMessage($message) { - if($this->maniaControl->settingManager->getSetting($this, self::QUEUE_CHATMESSAGES)) { - $this->maniaControl->chat->sendChat('$z$s$090[Queue] '.$message); + if ($this->maniaControl->settingManager->getSetting($this, self::QUEUE_CHATMESSAGES)) { + $this->maniaControl->chat->sendChat('$z$s$090[Queue] ' . $message); } } @@ -465,17 +469,17 @@ class QueuePlugin implements CallbackListener, CommandListener, ManialinkPageAns $inQueue = false; foreach($this->queue as $queuedPlayer) { - if($queuedPlayer->login == $player->login) { + if ($queuedPlayer->login == $player->login) { $inQueue = true; } } - if($inQueue) { + if ($inQueue) { $message = '$fff$sYou\'re in the queue (click to unqueue).'; $position = 0; foreach(array_values($this->queue) as $i => $queuePlayer) { - if($player->login == $queuePlayer->login) { + if ($player->login == $queuePlayer->login) { $position = ($i + 1); } } @@ -486,7 +490,7 @@ class QueuePlugin implements CallbackListener, CommandListener, ManialinkPageAns $statusLabel->setAction(self::ML_REMOVEFROMQUEUE); $cameraQuad->setAction(self::ML_REMOVEFROMQUEUE); } else { - if(count($this->queue) < $max_queue) { + if (count($this->queue) < $max_queue) { $message = '$0ff$sClick to join spectator waiting list.'; $messageLabel->setAction(self::ML_ADDTOQUEUE); $backgroundQuad->setAction(self::ML_ADDTOQUEUE); diff --git a/application/plugins/ServerRanking.php b/application/plugins/ServerRanking.php index d7239c23..2fea00c4 100644 --- a/application/plugins/ServerRanking.php +++ b/application/plugins/ServerRanking.php @@ -1,6 +1,7 @@ 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 $this->maniaControl->commandManager->registerCommandListener('rank', $this, 'command_showRank', false); diff --git a/application/plugins/WidgetPlugin.php b/application/plugins/WidgetPlugin.php index 3fd5b5cc..c22c3a10 100644 --- a/application/plugins/WidgetPlugin.php +++ b/application/plugins/WidgetPlugin.php @@ -11,6 +11,7 @@ use FML\Controls\Quads\Quad_Icons64x64_1; use FML\ManiaLink; use FML\Script\Script; use ManiaControl\Callbacks\CallbackListener; +use ManiaControl\Callbacks\Callbacks; use ManiaControl\Callbacks\TimerListener; use ManiaControl\Formatter; use ManiaControl\ManiaControl; @@ -101,8 +102,8 @@ class WidgetPlugin implements CallbackListener, TimerListener, Plugin { $this->maniaControl->manialinkManager->customUIManager->setChallengeInfoVisible(false); // Register for callbacks - $this->maniaControl->callbackManager->registerCallbackListener(MapManager::CB_BEGINMAP, $this, 'handleOnBeginMap'); - $this->maniaControl->callbackManager->registerCallbackListener(MapManager::CB_ENDMAP, $this, 'handleOnEndMap'); + $this->maniaControl->callbackManager->registerCallbackListener(Callbacks::BEGINMAP, $this, 'handleOnBeginMap'); + $this->maniaControl->callbackManager->registerCallbackListener(Callbacks::ENDMAP, $this, 'handleOnEndMap'); $this->maniaControl->callbackManager->registerCallbackListener(PlayerManager::CB_PLAYERCONNECT, $this, 'handlePlayerConnect'); $this->maniaControl->callbackManager->registerCallbackListener(PlayerManager::CB_PLAYERDISCONNECT, $this, 'handlePlayerDisconnect');