began adminlists, severall design fixes

This commit is contained in:
kremsy 2014-01-31 13:40:07 +01:00 committed by Steffen Schröder
parent 337e6e18f9
commit 7a15aef94d
8 changed files with 252 additions and 73 deletions

View File

@ -0,0 +1,152 @@
<?php
/**
* Created by PhpStorm.
* User: Lukas
* Date: 31.01.14
* Time: 12:54
*/
namespace ManiaControl\Admin;
use FML\Controls\Frame;
use FML\Controls\Labels\Label_Text;
use FML\Controls\Quads\Quad_BgRaceScore2;
use FML\Controls\Quads\Quad_BgsPlayerCard;
use FML\Controls\Quads\Quad_UIConstruction_Buttons;
use FML\ManiaLink;
use FML\Script\Script;
use ManiaControl\ManiaControl;
use ManiaControl\Manialinks\ManialinkManager;
use ManiaControl\Manialinks\ManialinkPageAnswerListener;
use ManiaControl\Players\Player;
class AdminLists implements ManialinkPageAnswerListener {
/**
* Constants
*/
const ACTION_OPEN_ADMINLISTS = "AdminList.OpenAdminLists";
const MAX_PLAYERS_PER_PAGE = 15;
/**
* Create a PlayerList Instance
*
* @param ManiaControl $maniaControl
*/
public function __construct(ManiaControl $maniaControl) {
$this->maniaControl = $maniaControl;
/*$this->maniaControl->manialinkManager->registerManialinkPageAnswerListener(self::ACTION_CLOSE_PLAYER_ADV, $this, 'closePlayerAdvancedWidget');
$this->maniaControl->callbackManager->registerCallbackListener(ManialinkManager::CB_MAIN_WINDOW_CLOSED, $this, 'closeWidget');
$this->maniaControl->callbackManager->registerCallbackListener(ManialinkManager::CB_MAIN_WINDOW_OPENED, $this, 'handleWidgetOpened');
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MP_PLAYERMANIALINKPAGEANSWER, $this, 'handleManialinkPageAnswer');
// Update Widget Events
$this->maniaControl->callbackManager->registerCallbackListener(PlayerManager::CB_PLAYERINFOCHANGED, $this, 'updateWidget');
$this->maniaControl->callbackManager->registerCallbackListener(PlayerManager::CB_PLAYERDISCONNECTED, $this, 'updateWidget');
$this->maniaControl->callbackManager->registerCallbackListener(PlayerManager::CB_PLAYERJOINED, $this, 'updateWidget');
$this->maniaControl->callbackManager->registerCallbackListener(AuthenticationManager::CB_AUTH_LEVEL_CHANGED, $this, 'updateWidget');*/
// Action Open Playerlist
$this->maniaControl->manialinkManager->registerManialinkPageAnswerListener(self::ACTION_OPEN_ADMINLISTS, $this, 'openAdminList');
$itemQuad = new Quad_UIConstruction_Buttons();
$itemQuad->setSubStyle($itemQuad::SUBSTYLE_Author);
$itemQuad->setAction(self::ACTION_OPEN_ADMINLISTS);
$this->maniaControl->actionsMenu->addMenuItem($itemQuad, false, 14, 'Open Adminlist');
}
public function openAdminList(array $callback, Player $player) {
$this->showAdminLists($player);
}
public function showAdminLists(Player $player) {
$width = $this->maniaControl->manialinkManager->styleManager->getListWidgetsWidth();
$height = $this->maniaControl->manialinkManager->styleManager->getListWidgetsHeight();
// get PlayerList
// $admins = $this->maniaControl->authenticationManager->
/*$players = $this->maniaControl->playerManager->getPlayers();
$pagesId = '';
if (count($players) > self::MAX_PLAYERS_PER_PAGE) {
$pagesId = 'AdminListsPages';
}*/
$pagesId = 'AdminListsPages';
//create manialink
$maniaLink = new ManiaLink(ManialinkManager::MAIN_MLID);
$script = $maniaLink->getScript();
// Main frame
$frame = $this->maniaControl->manialinkManager->styleManager->getDefaultListFrame($script, $pagesId);
$maniaLink->add($frame);
// Start offsets
$x = -$width / 2;
//Predefine description Label
$descriptionLabel = $this->maniaControl->manialinkManager->styleManager->getDefaultDescriptionLabel();
$frame->add($descriptionLabel);
$admins = $this->maniaControl->authenticationManager->getAdmins();
$i = 1;
$y = $height / 2 - 10;
$pageFrames = array();
foreach($admins as $admin) {
if (!isset($pageFrame)) {
$pageFrame = new Frame();
$frame->add($pageFrame);
if (!empty($pageFrames)) {
$pageFrame->setVisible(false);
}
array_push($pageFrames, $pageFrame);
$y = $height / 2 - 10;
$script->addPage($pageFrame, count($pageFrames), $pagesId);
}
$playerFrame = new Frame();
$pageFrame->add($playerFrame);
$playerFrame->setY($y);
if ($i % 2 != 0) {
$lineQuad = new Quad_BgsPlayerCard();
$playerFrame->add($lineQuad);
$lineQuad->setSize($width, 4);
$lineQuad->setSubStyle($lineQuad::SUBSTYLE_BgPlayerCardBig);
$lineQuad->setZ(0.001);
}
$array = array($i => $x + 5, $admin->nickname => $x + 18, $admin->login => $x + 70);
$this->maniaControl->manialinkManager->labelLine($playerFrame, $array);
// Level Quad
$rightQuad = new Quad_BgRaceScore2();
$playerFrame->add($rightQuad);
$rightQuad->setX($x + 13);
$rightQuad->setZ(5);
$rightQuad->setSubStyle($rightQuad::SUBSTYLE_CupFinisher);
$rightQuad->setSize(7, 3.5);
$rightLabel = new Label_Text();
$playerFrame->add($rightLabel);
$rightLabel->setX($x + 13.9);
$rightLabel->setTextSize(0.8);
$rightLabel->setZ(10);
$rightLabel->setText($this->maniaControl->authenticationManager->getAuthLevelAbbreviation($admin->authLevel));
$script->addTooltip($rightLabel, $descriptionLabel, array(Script::OPTION_TOOLTIP_TEXT => $this->maniaControl->authenticationManager->getAuthLevelName($admin->authLevel) . " " . $admin->nickname));
$y -= 4;
$i++;
if ($i % self::MAX_PLAYERS_PER_PAGE == 0) {
unset($pageFrame);
}
}
// Render and display xml
$this->maniaControl->manialinkManager->displayWidget($maniaLink, $player, 'AdminList');
}
}

View File

@ -2,11 +2,11 @@
namespace ManiaControl\Admin;
use ManiaControl\Callbacks\CallbackListener;
use ManiaControl\Callbacks\CallbackManager;
use ManiaControl\ManiaControl;
use ManiaControl\Players\Player;
use ManiaControl\Players\PlayerManager;
use ManiaControl\Callbacks\CallbackListener;
use ManiaControl\Callbacks\CallbackManager;
/**
* Class managing Authentication Levels
@ -17,18 +17,18 @@ class AuthenticationManager implements CallbackListener {
/**
* Constants
*/
const AUTH_LEVEL_PLAYER = 0;
const AUTH_LEVEL_MODERATOR = 1;
const AUTH_LEVEL_ADMIN = 2;
const AUTH_LEVEL_SUPERADMIN = 3;
const AUTH_LEVEL_PLAYER = 0;
const AUTH_LEVEL_MODERATOR = 1;
const AUTH_LEVEL_ADMIN = 2;
const AUTH_LEVEL_SUPERADMIN = 3;
const AUTH_LEVEL_MASTERADMIN = 4;
const CB_AUTH_LEVEL_CHANGED = 'AuthenticationManager.AuthLevelChanged';
const CB_AUTH_LEVEL_CHANGED = 'AuthenticationManager.AuthLevelChanged';
/**
* Public Properties
*/
public $authCommands = null;
/**
* Private Properties
*/
@ -42,7 +42,7 @@ class AuthenticationManager implements CallbackListener {
public function __construct(ManiaControl $maniaControl) {
$this->maniaControl = $maniaControl;
$this->authCommands = new AuthCommands($maniaControl);
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MC_ONINIT, $this, 'handleOnInit');
}
@ -57,9 +57,9 @@ class AuthenticationManager implements CallbackListener {
*/
private function updateMasterAdmins() {
$mysqli = $this->maniaControl->database->mysqli;
// Remove all MasterAdmins
$adminQuery = "UPDATE `" . PlayerManager::TABLE_PLAYERS . "`
$adminQuery = "UPDATE `" . PlayerManager::TABLE_PLAYERS . "`
SET `authLevel` = ?
WHERE `authLevel` = ?;";
$adminStatement = $mysqli->prepare($adminQuery);
@ -67,7 +67,7 @@ class AuthenticationManager implements CallbackListener {
trigger_error($mysqli->error, E_USER_ERROR);
return false;
}
$adminLevel = self::AUTH_LEVEL_SUPERADMIN;
$adminLevel = self::AUTH_LEVEL_SUPERADMIN;
$masterAdminLevel = self::AUTH_LEVEL_MASTERADMIN;
$adminStatement->bind_param('ii', $adminLevel, $masterAdminLevel);
$adminStatement->execute();
@ -75,10 +75,10 @@ class AuthenticationManager implements CallbackListener {
trigger_error($adminStatement->error);
}
$adminStatement->close();
// Set MasterAdmins
$masterAdmins = $this->maniaControl->config->masteradmins->xpath('login');
$adminQuery = "INSERT INTO `" . PlayerManager::TABLE_PLAYERS . "` (
$masterAdmins = $this->maniaControl->config->masteradmins->xpath('login');
$adminQuery = "INSERT INTO `" . PlayerManager::TABLE_PLAYERS . "` (
`login`,
`authLevel`
) VALUES (
@ -92,8 +92,8 @@ class AuthenticationManager implements CallbackListener {
}
$adminStatement->bind_param('si', $login, $masterAdminLevel);
$success = true;
foreach ($masterAdmins as $masterAdmin) {
$login = (string) $masterAdmin;
foreach($masterAdmins as $masterAdmin) {
$login = (string)$masterAdmin;
$adminStatement->execute();
if ($adminStatement->error) {
trigger_error($adminStatement->error);
@ -104,20 +104,51 @@ class AuthenticationManager implements CallbackListener {
return $success;
}
/**
* Get a List of all Admins
*
* @param $authLevel
* @return array|null
*/
public function getAdmins($authLevel = -1) {
$mysqli = $this->maniaControl->database->mysqli;
if ($authLevel == -1) {
$query = "SELECT * FROM `" . PlayerManager::TABLE_PLAYERS . "` WHERE `authLevel` > 0 ORDER BY `authLevel` DESC;";
} else {
$query = "SELECT * FROM `" . PlayerManager::TABLE_PLAYERS . "` WHERE `authLevel` = " . $authLevel . ";";
}
$result = $mysqli->query($query);
if (!$result) {
trigger_error($mysqli->error);
return null;
}
$admins = array();
while($row = $result->fetch_object()) {
array_push($admins, $row);
}
return $admins;
}
/**
* Grant the Auth Level to the Player
*
* @param Player $player
* @param int $authLevel
* @param int $authLevel
* @return bool
*/
public function grantAuthLevel(Player &$player, $authLevel) {
if (!$player || !is_numeric($authLevel)) return false;
$authLevel = (int) $authLevel;
if ($authLevel >= self::AUTH_LEVEL_MASTERADMIN) return false;
$mysqli = $this->maniaControl->database->mysqli;
$authQuery = "INSERT INTO `" . PlayerManager::TABLE_PLAYERS . "` (
if (!$player || !is_numeric($authLevel)) {
return false;
}
$authLevel = (int)$authLevel;
if ($authLevel >= self::AUTH_LEVEL_MASTERADMIN)
return false;
$mysqli = $this->maniaControl->database->mysqli;
$authQuery = "INSERT INTO `" . PlayerManager::TABLE_PLAYERS . "` (
`login`,
`authLevel`
) VALUES (
@ -137,10 +168,10 @@ class AuthenticationManager implements CallbackListener {
return false;
}
$authStatement->close();
$player->authLevel = $authLevel;
$this->maniaControl->callbackManager->triggerCallback(self::CB_AUTH_LEVEL_CHANGED, array(self::CB_AUTH_LEVEL_CHANGED, $player));
return true;
}
@ -151,7 +182,8 @@ class AuthenticationManager implements CallbackListener {
* @return bool
*/
public function sendNotAllowed(Player $player) {
if (!$player) return false;
if (!$player)
return false;
return $this->maniaControl->chat->sendError('You do not have the required Rights to perform this Command!', $player->login);
}
@ -159,7 +191,7 @@ class AuthenticationManager implements CallbackListener {
* Check if the Player has enough Rights
*
* @param Player $player
* @param int $neededAuthLevel
* @param int $neededAuthLevel
* @return bool
*/
public static function checkRight(Player $player, $neededAuthLevel) {
@ -170,7 +202,7 @@ class AuthenticationManager implements CallbackListener {
* Checks the permission by a right name
*
* @param Player $player
* @param $rightName
* @param $rightName
* @return bool
*/
public function checkPermission(Player $player, $rightName) {
@ -229,7 +261,7 @@ class AuthenticationManager implements CallbackListener {
if ($authLevelInt == self::AUTH_LEVEL_MODERATOR) {
return 'MOD';
}
return 'PL';
return '';
}
/**

View File

@ -127,17 +127,12 @@ class ManiaExchangeList implements CallbackListener, ManialinkPageAnswerListener
$pagesId = 'MxListPages';
// Main frame
$frame = $this->maniaControl->manialinkManager->styleManager->defaultListFrame($script, $pagesId);
$frame = $this->maniaControl->manialinkManager->styleManager->getDefaultListFrame($script, $pagesId);
$maniaLink->add($frame);
// Predefine Description Label
$descriptionLabel = new Label();
//Predefine description Label
$descriptionLabel = $this->maniaControl->manialinkManager->styleManager->getDefaultDescriptionLabel();
$frame->add($descriptionLabel);
$descriptionLabel->setAlign(Control::LEFT, Control::TOP);
$descriptionLabel->setPosition($x + 10, -$height / 2 + 5);
$descriptionLabel->setSize($width * 0.7, 4);
$descriptionLabel->setTextSize(2);
$descriptionLabel->setVisible(false);
// Headline
$headFrame = new Frame();

View File

@ -4,6 +4,7 @@ namespace ManiaControl\Manialinks;
use FML\Controls\Control;
use FML\Controls\Frame;
use FML\Controls\Label;
use FML\Controls\Labels\Label_Text;
use FML\Controls\Quad;
use FML\Controls\Quads\Quad_BgRaceScore2;
@ -130,12 +131,32 @@ class StyleManager {
}
/**
* Gets the Default Description Label
*
* @return Label
*/
public function getDefaultDescriptionLabel() {
$width = $this->getListWidgetsWidth();
$height = $this->getListWidgetsHeight();
// Predefine Description Label
$descriptionLabel = new Label();
$descriptionLabel->setAlign(Control::LEFT, Control::TOP);
$descriptionLabel->setPosition(-$width / 2 + 10, -$height / 2 + 5);
$descriptionLabel->setSize($width * 0.7, 4);
$descriptionLabel->setTextSize(2);
$descriptionLabel->setVisible(false);
return $descriptionLabel;
}
/**
* Builds the Default List Frame
*
* @return Frame $frame
*/
public function defaultListFrame(Script $script = null, $pagesId = '') {
public function getDefaultListFrame(Script $script = null, $pagesId = '') {
$width = $this->getListWidgetsWidth();
$height = $this->getListWidgetsHeight();
$quadStyle = $this->getDefaultMainWindowStyle();

View File

@ -119,7 +119,7 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
$script = $maniaLink->getScript();
// Main frame
$frame = $this->maniaControl->manialinkManager->styleManager->defaultListFrame($script, $pagesId);
$frame = $this->maniaControl->manialinkManager->styleManager->getDefaultListFrame($script, $pagesId);
$maniaLink->add($frame);
//Admin Buttons
@ -176,14 +176,9 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
$array = array('Id' => $x + 5, 'Mx Id' => $x + 10, 'Map Name' => $x + 20, 'Author' => $x + 68, 'Karma' => $x + 115, 'Actions' => $width / 2 - 15);
$this->maniaControl->manialinkManager->labelLine($headFrame, $array);
// Predefine Description Label
$descriptionLabel = new Label();
//Predefine description Label
$descriptionLabel = $this->maniaControl->manialinkManager->styleManager->getDefaultDescriptionLabel();
$frame->add($descriptionLabel);
$descriptionLabel->setAlign(Control::LEFT, Control::TOP);
$descriptionLabel->setPosition($x + 10, -$height / 2 + 5);
$descriptionLabel->setSize($width * 0.7, 4);
$descriptionLabel->setTextSize(2);
$descriptionLabel->setVisible(false);
$queuedMaps = $this->maniaControl->mapManager->mapQueue->getQueuedMapsRanking();
/**

View File

@ -55,7 +55,7 @@ class PlayerDetailed {
$script = $maniaLink->getScript();
// Main frame
$frame = $this->maniaControl->manialinkManager->styleManager->defaultListFrame($script);
$frame = $this->maniaControl->manialinkManager->styleManager->getDefaultListFrame($script);
$maniaLink->add($frame);
// Create script and features

View File

@ -4,7 +4,6 @@ namespace ManiaControl\Players;
use FML\Controls\Control;
use FML\Controls\Frame;
use FML\Controls\Label;
use FML\Controls\Labels\Label_Button;
use FML\Controls\Labels\Label_Text;
use FML\Controls\Quad;
@ -82,6 +81,7 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener, Timer
/**
* Add Player to Shown List
*
* @param Player $player
* @param int $showStatus
*/
@ -110,7 +110,7 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener, Timer
$script = $maniaLink->getScript();
// Main frame
$frame = $this->maniaControl->manialinkManager->styleManager->defaultListFrame($script, $pagesId);
$frame = $this->maniaControl->manialinkManager->styleManager->getDefaultListFrame($script, $pagesId);
$maniaLink->add($frame);
// Start offsets
@ -118,13 +118,8 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener, Timer
$y = $height / 2;
// Predefine Description Label
$descriptionLabel = new Label();
$descriptionLabel = $this->maniaControl->manialinkManager->styleManager->getDefaultDescriptionLabel();
$frame->add($descriptionLabel);
$descriptionLabel->setAlign(Control::LEFT, Control::TOP);
$descriptionLabel->setPosition($x + 10, -$height / 2 + 5);
$descriptionLabel->setSize($width * 0.7, 4);
$descriptionLabel->setTextSize(2);
$descriptionLabel->setVisible(false);
// Headline
$headFrame = new Frame();
@ -225,6 +220,8 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener, Timer
$rightLabel->setX($x + 13.9);
$rightLabel->setTextSize(0.8);
$rightLabel->setZ(10);
$rightLabel->setText($this->maniaControl->authenticationManager->getAuthLevelAbbreviation($listPlayer->authLevel));
$rightLabel->setTextColor("fff");
$script->addTooltip($rightLabel, $descriptionLabel, array(Script::OPTION_TOOLTIP_TEXT => $this->maniaControl->authenticationManager->getAuthLevelName($listPlayer->authLevel) . " " . $listPlayer->nickname));
@ -260,22 +257,6 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener, Timer
// Description Label
$script->addTooltip($playerQuad, $descriptionLabel, array(Script::OPTION_TOOLTIP_TEXT => "View Player profile of " . $listPlayer->nickname));
switch($listPlayer->authLevel) {
case authenticationManager::AUTH_LEVEL_MASTERADMIN:
$rightLabel->setText("MA");
break;
case authenticationManager::AUTH_LEVEL_SUPERADMIN:
$rightLabel->setText("SA");
break;
case authenticationManager::AUTH_LEVEL_ADMIN:
$rightLabel->setText("AD");
break;
case authenticationManager::AUTH_LEVEL_MODERATOR:
$rightLabel->setText("MOD");
}
$rightLabel->setTextColor("fff");
if ($this->maniaControl->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_MODERATOR)) {
// Further Player actions Quad
$playerQuad = new Quad_Icons64x64_1();

View File

@ -2,6 +2,7 @@
namespace ManiaControl\Players;
use ManiaControl\Admin\AdminLists;
use ManiaControl\Callbacks\CallbackListener;
use ManiaControl\Callbacks\CallbackManager;
use ManiaControl\Formatter;
@ -33,6 +34,7 @@ class PlayerManager implements CallbackListener {
public $playerCommands = null;
public $playerDetailed = null;
public $playerList = null;
public $adminLists = null;
public $players = array();
/**
@ -53,6 +55,7 @@ class PlayerManager implements CallbackListener {
$this->playerActions = new PlayerActions($maniaControl);
$this->playerDetailed = new PlayerDetailed($maniaControl);
$this->playerList = new PlayerList($this->maniaControl);
$this->adminLists = new AdminLists($this->maniaControl);
// Init settings
$this->maniaControl->settingManager->initSetting($this, self::SETTING_JOIN_LEAVE_MESSAGES, true);