minor cleanup

This commit is contained in:
kremsy 2014-02-13 00:46:41 +01:00 committed by Steffen Schröder
parent b1921fcc2b
commit 22707ea946
9 changed files with 61 additions and 59 deletions

View File

@ -90,10 +90,10 @@ class AuthenticationManager implements CallbackListener {
trigger_error($mysqli->error, E_USER_ERROR); trigger_error($mysqli->error, E_USER_ERROR);
return false; return false;
} }
$adminStatement->bind_param('si', $login, $masterAdminLevel);
$success = true; $success = true;
foreach($masterAdmins as $masterAdmin) { foreach($masterAdmins as $masterAdmin) {
$login = (string)$masterAdmin; $login = (string)$masterAdmin;
$adminStatement->bind_param('si', $login, $masterAdminLevel);
$adminStatement->execute(); $adminStatement->execute();
if ($adminStatement->error) { if ($adminStatement->error) {
trigger_error($adminStatement->error); trigger_error($adminStatement->error);

View File

@ -172,7 +172,7 @@ class Configurator implements CallbackListener, CommandListener, ManialinkPageAn
$player = $callback[1]; $player = $callback[1];
$openedWidget = $callback[2]; $openedWidget = $callback[2];
//unset when another main widget got opened //unset when another main widget got opened
if($openedWidget != 'Configurator') { if ($openedWidget != 'Configurator') {
unset($this->playersMenuShown[$player->login]); unset($this->playersMenuShown[$player->login]);
} }
} }
@ -203,7 +203,7 @@ class Configurator implements CallbackListener, CommandListener, ManialinkPageAn
* @param Player $player * @param Player $player
*/ */
public function toggleMenu(Player $player) { public function toggleMenu(Player $player) {
if(isset($this->playersMenuShown[$player->login])) { if (isset($this->playersMenuShown[$player->login])) {
$this->hideMenu($player); $this->hideMenu($player);
} else { } else {
$this->showMenu($player); $this->showMenu($player);
@ -220,7 +220,7 @@ class Configurator implements CallbackListener, CommandListener, ManialinkPageAn
$i = 0; $i = 0;
foreach($this->menus as $menu) { foreach($this->menus as $menu) {
/** @var ConfiguratorMenu $menu */ /** @var ConfiguratorMenu $menu */
if($menu->getTitle() == $name) { if ($menu->getTitle() == $name) {
return $i; return $i;
} }
$i++; $i++;
@ -279,7 +279,7 @@ class Configurator implements CallbackListener, CommandListener, ManialinkPageAn
$menuItemY = $menuHeight * 0.42; $menuItemY = $menuHeight * 0.42;
$menuId = 0; $menuId = 0;
foreach($this->menus as $index => $menu) { foreach($this->menus as $menu) {
/** @var ConfiguratorMenu $menu */ /** @var ConfiguratorMenu $menu */
// Add title // Add title
@ -292,7 +292,7 @@ class Configurator implements CallbackListener, CommandListener, ManialinkPageAn
$menuItemLabel->setAction(self::ACTION_SELECTMENU . '.' . $menuId); $menuItemLabel->setAction(self::ACTION_SELECTMENU . '.' . $menuId);
//Show a Menu //Show a Menu
if($menuId == $menuIdShown) { if ($menuId == $menuIdShown) {
$menuControl = $menu->getMenu($subMenuWidth, $subMenuHeight, $script); $menuControl = $menu->getMenu($subMenuWidth, $subMenuHeight, $script);
$menusFrame->add($menuControl); $menusFrame->add($menuControl);
$script->addMenu($menuItemLabel, $menuControl); $script->addMenu($menuItemLabel, $menuControl);
@ -344,7 +344,7 @@ class Configurator implements CallbackListener, CommandListener, ManialinkPageAn
public function handleManialinkPageAnswer(array $callback) { public function handleManialinkPageAnswer(array $callback) {
$actionId = $callback[1][2]; $actionId = $callback[1][2];
$boolSelectMenu = (strpos($actionId, self::ACTION_SELECTMENU) === 0); $boolSelectMenu = (strpos($actionId, self::ACTION_SELECTMENU) === 0);
if(!$boolSelectMenu) { if (!$boolSelectMenu) {
return; return;
} }

View File

@ -2,9 +2,7 @@
namespace ManiaControl\Configurators; namespace ManiaControl\Configurators;
use FML\Script\Pages;
use FML\Script\Script; use FML\Script\Script;
use FML\Script\Tooltips;
use ManiaControl\Players\Player; use ManiaControl\Players\Player;
/** /**
@ -24,8 +22,8 @@ interface ConfiguratorMenu {
/** /**
* Get the Configurator Menu Frame * Get the Configurator Menu Frame
* *
* @param float $width * @param float $width
* @param float $height * @param float $height
* @param Script $script * @param Script $script
* @return \FML\Controls\Frame * @return \FML\Controls\Frame
*/ */
@ -34,7 +32,7 @@ interface ConfiguratorMenu {
/** /**
* Save the Config Data * Save the Config Data
* *
* @param array $configData * @param array $configData
* @param Player $player * @param Player $player
*/ */
public function saveConfigData(array $configData, Player $player); public function saveConfigData(array $configData, Player $player);

View File

@ -351,9 +351,9 @@ class ServerSettings implements ConfiguratorMenu, CallbackListener {
} }
// Notifications // Notifications
$settingsCount = count($newSettings); //$settingsCount = count($newSettings);
$settingIndex = 0; $settingIndex = 0;
$title = $this->maniaControl->authenticationManager->getAuthLevelName($player->authLevel); //$title = $this->maniaControl->authenticationManager->getAuthLevelName($player->authLevel);
// $chatMessage = '$ff0' . $title . ' $<' . $player->nickname . '$> set ScriptSetting' . ($settingsCount > 1 ? 's' : '') . ' '; // $chatMessage = '$ff0' . $title . ' $<' . $player->nickname . '$> set ScriptSetting' . ($settingsCount > 1 ? 's' : '') . ' ';
foreach($newSettings as $setting => $value) { foreach($newSettings as $setting => $value) {

View File

@ -73,6 +73,7 @@ abstract class Formatter {
return $r . ' ' . $str . ($r > 1 ? 's' : '') . ' ago'; return $r . ' ' . $str . ($r > 1 ? 's' : '') . ' ago';
} }
} }
return '';
} }
/** /**

View File

@ -21,7 +21,8 @@ class MXMapInfo {
* Returns map object with all available data from MX map data * Returns map object with all available data from MX map data
* *
* @param String $prefix MX URL prefix * @param String $prefix MX URL prefix
* @param Object $map The MX map data from MXInfoSearcher * @param $mx
* @internal param Object $map The MX map data from MXInfoSearcher
* @return MXMapInfo * @return MXMapInfo
*/ */
public function __construct($prefix, $mx) { public function __construct($prefix, $mx) {

View File

@ -133,7 +133,8 @@ class PluginManager {
if ($this->isPluginActive($pluginClass)) { if ($this->isPluginActive($pluginClass)) {
return false; return false;
} }
$plugin = new $pluginClass(); $plugin = new $pluginClass();
/** @var Plugin $plugin */
$this->activePlugins[$pluginClass] = $plugin; $this->activePlugins[$pluginClass] = $plugin;
$this->savePluginStatus($pluginClass, true); $this->savePluginStatus($pluginClass, true);
try { try {
@ -164,6 +165,7 @@ class PluginManager {
return false; return false;
} }
$plugin = $this->activePlugins[$pluginClass]; $plugin = $this->activePlugins[$pluginClass];
/** @var Plugin $plugin */
unset($this->activePlugins[$pluginClass]); unset($this->activePlugins[$pluginClass]);
$plugin->unload(); $plugin->unload();
$interfaces = class_implements($pluginClass); $interfaces = class_implements($pluginClass);

View File

@ -29,12 +29,12 @@ class PluginMenu implements CallbackListener, ConfiguratorMenu, ManialinkPageAns
/** /**
* Constants * Constants
*/ */
const ACTION_PREFIX_ENABLEPLUGIN = 'PluginMenu.Enable.'; const ACTION_PREFIX_ENABLEPLUGIN = 'PluginMenu.Enable.';
const ACTION_PREFIX_DISABLEPLUGIN = 'PluginMenu.Disable.'; const ACTION_PREFIX_DISABLEPLUGIN = 'PluginMenu.Disable.';
const ACTION_PREFIX_SETTINGS = 'PluginMenu.Settings.'; const ACTION_PREFIX_SETTINGS = 'PluginMenu.Settings.';
const ACTION_PREFIX_SETTING = 'PluginMenuSetting'; const ACTION_PREFIX_SETTING = 'PluginMenuSetting';
const ACTION_SETTING_BOOL = 'PluginMenuActionBoolSetting.'; const ACTION_SETTING_BOOL = 'PluginMenuActionBoolSetting.';
const ACTION_BACK_TO_PLUGINS = 'PluginMenu.BackToPlugins'; const ACTION_BACK_TO_PLUGINS = 'PluginMenu.BackToPlugins';
const SETTING_PERMISSION_CHANGE_PLUGIN_SETTINGS = 'Change Plugin Settings'; const SETTING_PERMISSION_CHANGE_PLUGIN_SETTINGS = 'Change Plugin Settings';
/** /**
@ -57,7 +57,6 @@ class PluginMenu implements CallbackListener, ConfiguratorMenu, ManialinkPageAns
} }
/** /**
*
* @see \ManiaControl\Configurators\ConfiguratorMenu::getTitle() * @see \ManiaControl\Configurators\ConfiguratorMenu::getTitle()
*/ */
public function getTitle() { public function getTitle() {
@ -74,7 +73,6 @@ class PluginMenu implements CallbackListener, ConfiguratorMenu, ManialinkPageAns
} }
/** /**
*
* @see \ManiaControl\Configurators\ConfiguratorMenu::getMenu() * @see \ManiaControl\Configurators\ConfiguratorMenu::getMenu()
*/ */
public function getMenu($width, $height, Script $script) { public function getMenu($width, $height, Script $script) {
@ -116,7 +114,7 @@ class PluginMenu implements CallbackListener, ConfiguratorMenu, ManialinkPageAns
//Show Settings Menu //Show Settings Menu
if($this->settingsClass != '') { //TODO improve if ($this->settingsClass != '') { //TODO improve
/** @var ManiaControl/SettingManager $this->maniaControl->settingManager */ /** @var ManiaControl/SettingManager $this->maniaControl->settingManager */
$settings = $this->maniaControl->settingManager->getSettingsByClass($this->settingsClass); $settings = $this->maniaControl->settingManager->getSettingsByClass($this->settingsClass);
$pageFrames = array(); $pageFrames = array();
@ -124,11 +122,11 @@ class PluginMenu implements CallbackListener, ConfiguratorMenu, ManialinkPageAns
$y = 0; $y = 0;
$index = 1; $index = 1;
$settingHeight = 5.; $settingHeight = 5.;
foreach($settings as $id => $setting) { foreach($settings as $setting) {
if(!isset($pageFrame)) { if (!isset($pageFrame)) {
$pageFrame = new Frame(); $pageFrame = new Frame();
$frame->add($pageFrame); $frame->add($pageFrame);
if(!empty($pageFrames)) { if (!empty($pageFrames)) {
$pageFrame->setVisible(false); $pageFrame->setVisible(false);
} }
array_push($pageFrames, $pageFrame); array_push($pageFrames, $pageFrame);
@ -140,7 +138,7 @@ class PluginMenu implements CallbackListener, ConfiguratorMenu, ManialinkPageAns
$pageFrame->add($settingFrame); $pageFrame->add($settingFrame);
$settingFrame->setY($y); $settingFrame->setY($y);
if($index == 1) { if ($index == 1) {
//Headline Label //Headline Label
$headLabel = new Label_Text(); $headLabel = new Label_Text();
$settingFrame->add($headLabel); $settingFrame->add($headLabel);
@ -154,10 +152,10 @@ class PluginMenu implements CallbackListener, ConfiguratorMenu, ManialinkPageAns
$y -= $settingHeight; $y -= $settingHeight;
if($index % $pageMaxCount == $pageMaxCount - 1) { if ($index % $pageMaxCount == $pageMaxCount - 1) {
$pageFrame = new Frame(); $pageFrame = new Frame();
$frame->add($pageFrame); $frame->add($pageFrame);
if(!empty($pageFrames)) { if (!empty($pageFrames)) {
$pageFrame->setVisible(false); $pageFrame->setVisible(false);
} }
array_push($pageFrames, $pageFrame); array_push($pageFrames, $pageFrame);
@ -196,10 +194,10 @@ class PluginMenu implements CallbackListener, ConfiguratorMenu, ManialinkPageAns
$entry->setDefault($setting->value); $entry->setDefault($setting->value);
if($setting->type == "bool") { if ($setting->type == "bool") {
if($setting->value == "0") { if ($setting->value == "0") {
$substyle = Quad_Icons64x64_1::SUBSTYLE_LvlRed; $substyle = Quad_Icons64x64_1::SUBSTYLE_LvlRed;
} else if($setting->value == "1") { } else if ($setting->value == "1") {
$substyle = Quad_Icons64x64_1::SUBSTYLE_LvlGreen; $substyle = Quad_Icons64x64_1::SUBSTYLE_LvlGreen;
} }
@ -216,7 +214,7 @@ class PluginMenu implements CallbackListener, ConfiguratorMenu, ManialinkPageAns
$y -= $settingHeight; $y -= $settingHeight;
if($index % $pageSettingsMaxCount == $pageSettingsMaxCount - 1) { if ($index % $pageSettingsMaxCount == $pageSettingsMaxCount - 1) {
unset($pageFrame); unset($pageFrame);
} }
@ -241,10 +239,11 @@ class PluginMenu implements CallbackListener, ConfiguratorMenu, ManialinkPageAns
$pageFrames = array(); $pageFrames = array();
$y = 0.; $y = 0.;
foreach($pluginClasses as $index => $pluginClass) { foreach($pluginClasses as $index => $pluginClass) {
if(!isset($pageFrame)) { /** @var Plugin $pluginClass */
if (!isset($pageFrame)) {
$pageFrame = new Frame(); $pageFrame = new Frame();
$frame->add($pageFrame); $frame->add($pageFrame);
if(!empty($pageFrames)) { if (!empty($pageFrames)) {
$pageFrame->setVisible(false); $pageFrame->setVisible(false);
} }
@ -263,7 +262,7 @@ class PluginMenu implements CallbackListener, ConfiguratorMenu, ManialinkPageAns
$pluginFrame->add($activeQuad); $pluginFrame->add($activeQuad);
$activeQuad->setPosition($width * -0.45, -0.1, 1); $activeQuad->setPosition($width * -0.45, -0.1, 1);
$activeQuad->setSize($entryHeight * 0.9, $entryHeight * 0.9); $activeQuad->setSize($entryHeight * 0.9, $entryHeight * 0.9);
if($active) { if ($active) {
$activeQuad->setSubStyle($activeQuad::SUBSTYLE_LvlGreen); $activeQuad->setSubStyle($activeQuad::SUBSTYLE_LvlGreen);
} else { } else {
$activeQuad->setSubStyle($activeQuad::SUBSTYLE_LvlRed); $activeQuad->setSubStyle($activeQuad::SUBSTYLE_LvlRed);
@ -305,7 +304,7 @@ class PluginMenu implements CallbackListener, ConfiguratorMenu, ManialinkPageAns
$statusChangeButton->setHAlign(Control::RIGHT); $statusChangeButton->setHAlign(Control::RIGHT);
$statusChangeButton->setX($width * 0.45); $statusChangeButton->setX($width * 0.45);
$statusChangeButton->setStyle($statusChangeButton::STYLE_CardButtonSmall); $statusChangeButton->setStyle($statusChangeButton::STYLE_CardButtonSmall);
if($active) { if ($active) {
$statusChangeButton->setTextPrefix('$f00'); $statusChangeButton->setTextPrefix('$f00');
$statusChangeButton->setText('Deactivate'); $statusChangeButton->setText('Deactivate');
$statusChangeButton->setAction(self::ACTION_PREFIX_DISABLEPLUGIN . $pluginClass); $statusChangeButton->setAction(self::ACTION_PREFIX_DISABLEPLUGIN . $pluginClass);
@ -316,7 +315,7 @@ class PluginMenu implements CallbackListener, ConfiguratorMenu, ManialinkPageAns
} }
$y -= $entryHeight; $y -= $entryHeight;
if($index % $pageMaxCount == $pageMaxCount - 1) { if ($index % $pageMaxCount == $pageMaxCount - 1) {
unset($pageFrame); unset($pageFrame);
} }
} }
@ -325,7 +324,6 @@ class PluginMenu implements CallbackListener, ConfiguratorMenu, ManialinkPageAns
} }
/** /**
*
* @see \ManiaControl\Configurators\ConfiguratorMenu::saveConfigData() * @see \ManiaControl\Configurators\ConfiguratorMenu::saveConfigData()
*/ */
public function saveConfigData(array $configData, Player $player) { public function saveConfigData(array $configData, Player $player) {
@ -335,7 +333,7 @@ class PluginMenu implements CallbackListener, ConfiguratorMenu, ManialinkPageAns
} }
$prefix = explode(".", $configData[3][0]['Name']); $prefix = explode(".", $configData[3][0]['Name']);
if($prefix[0] != self::ACTION_PREFIX_SETTING) { if ($prefix[0] != self::ACTION_PREFIX_SETTING) {
return; return;
} }
@ -347,11 +345,11 @@ class PluginMenu implements CallbackListener, ConfiguratorMenu, ManialinkPageAns
$settingName = substr($setting['Name'], $prefixLength + 1); $settingName = substr($setting['Name'], $prefixLength + 1);
$oldSetting = $maniaControlSettings[$settingName]; $oldSetting = $maniaControlSettings[$settingName];
if($setting['Value'] == $oldSetting->value || $oldSetting->type == 'bool') { if ($setting['Value'] == $oldSetting->value || $oldSetting->type == 'bool') {
continue; continue;
} }
$this->maniaControl->settingManager->updateSetting($oldSetting->class, $oldSetting->setting, $setting['Value']); $this->maniaControl->settingManager->setSetting($oldSetting->class, $oldSetting->setting, $setting['Value']);
} }
//Reopen the Menu //Reopen the Menu
@ -371,38 +369,40 @@ class PluginMenu implements CallbackListener, ConfiguratorMenu, ManialinkPageAns
$settings = (strpos($actionId, self::ACTION_PREFIX_SETTINGS) === 0); $settings = (strpos($actionId, self::ACTION_PREFIX_SETTINGS) === 0);
$boolSetting = (strpos($actionId, self::ACTION_SETTING_BOOL) === 0); $boolSetting = (strpos($actionId, self::ACTION_SETTING_BOOL) === 0);
if(!$enable && !$disable && !$settings && !$boolSetting) { if (!$enable && !$disable && !$settings && !$boolSetting) {
return; return;
} }
$login = $callback[1][1]; $login = $callback[1][1];
$player = $this->maniaControl->playerManager->getPlayer($login); $player = $this->maniaControl->playerManager->getPlayer($login);
if(!$player) { if (!$player) {
return; return;
} }
if($enable) { if ($enable) {
$pluginClass = substr($actionId, strlen(self::ACTION_PREFIX_ENABLEPLUGIN)); $pluginClass = substr($actionId, strlen(self::ACTION_PREFIX_ENABLEPLUGIN));
$activated = $this->maniaControl->pluginManager->activatePlugin($pluginClass, $player->login); /** @var Plugin $pluginClass */
if($activated) { $activated = $this->maniaControl->pluginManager->activatePlugin($pluginClass, $player->login);
if ($activated) {
$this->maniaControl->chat->sendSuccess($pluginClass::getName() . ' activated!', $player->login); $this->maniaControl->chat->sendSuccess($pluginClass::getName() . ' activated!', $player->login);
$this->maniaControl->configurator->showMenu($player); $this->maniaControl->configurator->showMenu($player);
$this->maniaControl->log(Formatter::stripCodes("{$player->login} activated '{$pluginClass}'!")); $this->maniaControl->log(Formatter::stripCodes("{$player->login} activated '{$pluginClass}'!"));
} else { } else {
$this->maniaControl->chat->sendError('Error activating ' . $pluginClass::getName() . '!', $player->login); $this->maniaControl->chat->sendError('Error activating ' . $pluginClass::getName() . '!', $player->login);
} }
} else if($disable) { } else if ($disable) {
$pluginClass = substr($actionId, strlen(self::ACTION_PREFIX_DISABLEPLUGIN)); $pluginClass = substr($actionId, strlen(self::ACTION_PREFIX_DISABLEPLUGIN));
/** @var Plugin $pluginClass */
$deactivated = $this->maniaControl->pluginManager->deactivatePlugin($pluginClass); $deactivated = $this->maniaControl->pluginManager->deactivatePlugin($pluginClass);
if($deactivated) { if ($deactivated) {
$this->maniaControl->chat->sendSuccess($pluginClass::getName() . ' deactivated!', $player->login); $this->maniaControl->chat->sendSuccess($pluginClass::getName() . ' deactivated!', $player->login);
$this->maniaControl->configurator->showMenu($player); $this->maniaControl->configurator->showMenu($player);
$this->maniaControl->log(Formatter::stripCodes("{$player->login} deactivated '{$pluginClass}'!")); $this->maniaControl->log(Formatter::stripCodes("{$player->login} deactivated '{$pluginClass}'!"));
} else { } else {
$this->maniaControl->chat->sendError('Error deactivating ' . $pluginClass::getName() . '!', $player->login); $this->maniaControl->chat->sendError('Error deactivating ' . $pluginClass::getName() . '!', $player->login);
} }
} else if($settings) { //Open Settings Menu } else if ($settings) { //Open Settings Menu
$pluginClass = substr($actionId, strlen(self::ACTION_PREFIX_SETTINGS)); $pluginClass = substr($actionId, strlen(self::ACTION_PREFIX_SETTINGS));
$this->settingsClass = $pluginClass; $this->settingsClass = $pluginClass;
} else if($boolSetting) { } else if ($boolSetting) {
$actionArray = explode(".", $actionId); $actionArray = explode(".", $actionId);
$setting = $actionArray[1]; $setting = $actionArray[1];
@ -435,16 +435,16 @@ class PluginMenu implements CallbackListener, ConfiguratorMenu, ManialinkPageAns
$oldSetting = $this->maniaControl->settingManager->getSettingByIndex($setting); $oldSetting = $this->maniaControl->settingManager->getSettingByIndex($setting);
if(!isset($oldSetting)) { if (!isset($oldSetting)) {
var_dump('no setting ' . $setting); var_dump('no setting ' . $setting);
return; return;
} }
//Toggle value //Toggle value
if($oldSetting->value == "1") { if ($oldSetting->value == "1") {
$this->maniaControl->settingManager->updateSetting($oldSetting->class, $oldSetting->setting, "0"); $this->maniaControl->settingManager->setSetting($oldSetting->class, $oldSetting->setting, "0");
} else { } else {
$this->maniaControl->settingManager->updateSetting($oldSetting->class, $oldSetting->setting, "1"); $this->maniaControl->settingManager->setSetting($oldSetting->class, $oldSetting->setting, "1");
} }
} }
} }

View File

@ -96,7 +96,7 @@ class RankingManager implements CallbackListener {
public function getLeaders() { public function getLeaders() {
$leaders = array(); $leaders = array();
$prev = -1; $prev = -1;
foreach($this->rankings as $player => $score) { foreach($this->rankings as $score) {
if ($prev != -1 && $prev < $score) { if ($prev != -1 && $prev < $score) {
return $leaders; return $leaders;
} }