simple admin list
This commit is contained in:
parent
7a15aef94d
commit
c0d084a037
@ -9,23 +9,28 @@
|
|||||||
namespace ManiaControl\Admin;
|
namespace ManiaControl\Admin;
|
||||||
|
|
||||||
|
|
||||||
|
use FML\Controls\Control;
|
||||||
use FML\Controls\Frame;
|
use FML\Controls\Frame;
|
||||||
|
use FML\Controls\Labels\Label_Button;
|
||||||
use FML\Controls\Labels\Label_Text;
|
use FML\Controls\Labels\Label_Text;
|
||||||
use FML\Controls\Quads\Quad_BgRaceScore2;
|
use FML\Controls\Quads\Quad_BgRaceScore2;
|
||||||
use FML\Controls\Quads\Quad_BgsPlayerCard;
|
use FML\Controls\Quads\Quad_BgsPlayerCard;
|
||||||
use FML\Controls\Quads\Quad_UIConstruction_Buttons;
|
use FML\Controls\Quads\Quad_UIConstruction_Buttons;
|
||||||
use FML\ManiaLink;
|
use FML\ManiaLink;
|
||||||
use FML\Script\Script;
|
use FML\Script\Script;
|
||||||
|
use ManiaControl\Callbacks\CallbackListener;
|
||||||
|
use ManiaControl\Callbacks\CallbackManager;
|
||||||
use ManiaControl\ManiaControl;
|
use ManiaControl\ManiaControl;
|
||||||
use ManiaControl\Manialinks\ManialinkManager;
|
use ManiaControl\Manialinks\ManialinkManager;
|
||||||
use ManiaControl\Manialinks\ManialinkPageAnswerListener;
|
use ManiaControl\Manialinks\ManialinkPageAnswerListener;
|
||||||
use ManiaControl\Players\Player;
|
use ManiaControl\Players\Player;
|
||||||
|
|
||||||
class AdminLists implements ManialinkPageAnswerListener {
|
class AdminLists implements ManialinkPageAnswerListener, CallbackListener {
|
||||||
/**
|
/**
|
||||||
* Constants
|
* Constants
|
||||||
*/
|
*/
|
||||||
const ACTION_OPEN_ADMINLISTS = "AdminList.OpenAdminLists";
|
const ACTION_OPEN_ADMINLISTS = "AdminList.OpenAdminLists";
|
||||||
|
const ACTION_REVOKE_RIGHTS = "AdminList.RevokeRights";
|
||||||
const MAX_PLAYERS_PER_PAGE = 15;
|
const MAX_PLAYERS_PER_PAGE = 15;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -36,18 +41,9 @@ class AdminLists implements ManialinkPageAnswerListener {
|
|||||||
public function __construct(ManiaControl $maniaControl) {
|
public function __construct(ManiaControl $maniaControl) {
|
||||||
$this->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');
|
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MP_PLAYERMANIALINKPAGEANSWER, $this, 'handleManialinkPageAnswer');
|
||||||
|
|
||||||
// Update Widget Events
|
// Action Open AdminList
|
||||||
$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');
|
$this->maniaControl->manialinkManager->registerManialinkPageAnswerListener(self::ACTION_OPEN_ADMINLISTS, $this, 'openAdminList');
|
||||||
$itemQuad = new Quad_UIConstruction_Buttons();
|
$itemQuad = new Quad_UIConstruction_Buttons();
|
||||||
$itemQuad->setSubStyle($itemQuad::SUBSTYLE_Author);
|
$itemQuad->setSubStyle($itemQuad::SUBSTYLE_Author);
|
||||||
@ -63,17 +59,14 @@ class AdminLists implements ManialinkPageAnswerListener {
|
|||||||
$width = $this->maniaControl->manialinkManager->styleManager->getListWidgetsWidth();
|
$width = $this->maniaControl->manialinkManager->styleManager->getListWidgetsWidth();
|
||||||
$height = $this->maniaControl->manialinkManager->styleManager->getListWidgetsHeight();
|
$height = $this->maniaControl->manialinkManager->styleManager->getListWidgetsHeight();
|
||||||
|
|
||||||
// get PlayerList
|
// get Admins
|
||||||
// $admins = $this->maniaControl->authenticationManager->
|
$admins = $this->maniaControl->authenticationManager->getAdmins();
|
||||||
/*$players = $this->maniaControl->playerManager->getPlayers();
|
|
||||||
$pagesId = '';
|
$pagesId = '';
|
||||||
if (count($players) > self::MAX_PLAYERS_PER_PAGE) {
|
if (count($admins) > self::MAX_PLAYERS_PER_PAGE) {
|
||||||
$pagesId = 'AdminListsPages';
|
$pagesId = 'AdminListPages';
|
||||||
}*/
|
}
|
||||||
$pagesId = 'AdminListsPages';
|
|
||||||
|
|
||||||
|
//Create ManiaLink
|
||||||
//create manialink
|
|
||||||
$maniaLink = new ManiaLink(ManialinkManager::MAIN_MLID);
|
$maniaLink = new ManiaLink(ManialinkManager::MAIN_MLID);
|
||||||
$script = $maniaLink->getScript();
|
$script = $maniaLink->getScript();
|
||||||
|
|
||||||
@ -83,14 +76,21 @@ class AdminLists implements ManialinkPageAnswerListener {
|
|||||||
|
|
||||||
// Start offsets
|
// Start offsets
|
||||||
$x = -$width / 2;
|
$x = -$width / 2;
|
||||||
|
$y = $height / 2;
|
||||||
|
|
||||||
//Predefine description Label
|
//Predefine description Label
|
||||||
$descriptionLabel = $this->maniaControl->manialinkManager->styleManager->getDefaultDescriptionLabel();
|
$descriptionLabel = $this->maniaControl->manialinkManager->styleManager->getDefaultDescriptionLabel();
|
||||||
$frame->add($descriptionLabel);
|
$frame->add($descriptionLabel);
|
||||||
|
|
||||||
$admins = $this->maniaControl->authenticationManager->getAdmins();
|
// Headline
|
||||||
|
$headFrame = new Frame();
|
||||||
|
$frame->add($headFrame);
|
||||||
|
$headFrame->setY($y - 5);
|
||||||
|
$array = array("Id" => $x + 5, "Nickname" => $x + 18, "Login" => $x + 70, "Actions" => $x + 120);
|
||||||
|
$this->maniaControl->manialinkManager->labelLine($headFrame, $array);
|
||||||
|
|
||||||
$i = 1;
|
$i = 1;
|
||||||
$y = $height / 2 - 10;
|
$y = $y - 10;
|
||||||
$pageFrames = array();
|
$pageFrames = array();
|
||||||
foreach($admins as $admin) {
|
foreach($admins as $admin) {
|
||||||
if (!isset($pageFrame)) {
|
if (!isset($pageFrame)) {
|
||||||
@ -137,6 +137,35 @@ class AdminLists implements ManialinkPageAnswerListener {
|
|||||||
$rightLabel->setText($this->maniaControl->authenticationManager->getAuthLevelAbbreviation($admin->authLevel));
|
$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));
|
$script->addTooltip($rightLabel, $descriptionLabel, array(Script::OPTION_TOOLTIP_TEXT => $this->maniaControl->authenticationManager->getAuthLevelName($admin->authLevel) . " " . $admin->nickname));
|
||||||
|
|
||||||
|
//Revoke Button
|
||||||
|
if ($admin->authLevel > 0 && $this->maniaControl->authenticationManager->checkRight($player, $admin->authLevel + 1)) {
|
||||||
|
//Settings
|
||||||
|
$style = Label_Text::STYLE_TextCardSmall;
|
||||||
|
$textColor = 'FFF';
|
||||||
|
$quadWidth = 24;
|
||||||
|
$quadHeight = 3.4;
|
||||||
|
|
||||||
|
// Quad
|
||||||
|
$quad = new Quad_BgsPlayerCard();
|
||||||
|
$playerFrame->add($quad);
|
||||||
|
$quad->setZ(11);
|
||||||
|
$quad->setX($x + 130);
|
||||||
|
$quad->setSubStyle($quad::SUBSTYLE_BgPlayerCardBig);
|
||||||
|
$quad->setSize($quadWidth, $quadHeight);
|
||||||
|
$quad->setAction(self::ACTION_REVOKE_RIGHTS . "." . $admin->login);
|
||||||
|
|
||||||
|
//Label
|
||||||
|
$label = new Label_Button();
|
||||||
|
$playerFrame->add($label);
|
||||||
|
$label->setX($x + 130);
|
||||||
|
$quad->setZ(12);
|
||||||
|
$label->setAlign(Control::CENTER, Control::CENTER);
|
||||||
|
$label->setStyle($style);
|
||||||
|
$label->setTextSize(1);
|
||||||
|
$label->setTextColor($textColor);
|
||||||
|
$label->setText("Revoke Rights");
|
||||||
|
//$label->setTextColor("700");
|
||||||
|
}
|
||||||
|
|
||||||
$y -= 4;
|
$y -= 4;
|
||||||
$i++;
|
$i++;
|
||||||
@ -149,4 +178,27 @@ class AdminLists implements ManialinkPageAnswerListener {
|
|||||||
$this->maniaControl->manialinkManager->displayWidget($maniaLink, $player, 'AdminList');
|
$this->maniaControl->manialinkManager->displayWidget($maniaLink, $player, 'AdminList');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called on ManialinkPageAnswer
|
||||||
|
*
|
||||||
|
* @param array $callback
|
||||||
|
*/
|
||||||
|
public function handleManialinkPageAnswer(array $callback) {
|
||||||
|
$actionId = $callback[1][2];
|
||||||
|
$actionArray = explode('.', $actionId, 3);
|
||||||
|
if (count($actionArray) <= 2) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$action = $actionArray[0] . "." . $actionArray[1];
|
||||||
|
$adminLogin = $callback[1][1];
|
||||||
|
$targetLogin = $actionArray[2];
|
||||||
|
|
||||||
|
switch($action) {
|
||||||
|
case self::ACTION_REVOKE_RIGHTS:
|
||||||
|
$this->maniaControl->playerManager->playerActions->revokeAuthLevel($adminLogin, $targetLogin);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -315,7 +315,7 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener, Timer
|
|||||||
|
|
||||||
// Show advanced window
|
// Show advanced window
|
||||||
if ($this->playersListShown[$player->login] && $this->playersListShown[$player->login] != self::SHOWN_MAIN_WINDOW) {
|
if ($this->playersListShown[$player->login] && $this->playersListShown[$player->login] != self::SHOWN_MAIN_WINDOW) {
|
||||||
$frame = $this->showAdvancedPlayerWidget($this->playersListShown[$player->login]);
|
$frame = $this->showAdvancedPlayerWidget($player, $this->playersListShown[$player->login]);
|
||||||
$maniaLink->add($frame);
|
$maniaLink->add($frame);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -343,7 +343,7 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener, Timer
|
|||||||
* @param $login
|
* @param $login
|
||||||
* @return Frame
|
* @return Frame
|
||||||
*/
|
*/
|
||||||
public function showAdvancedPlayerWidget($login) {
|
public function showAdvancedPlayerWidget($admin, $login) {
|
||||||
$player = $this->maniaControl->playerManager->getPlayer($login);
|
$player = $this->maniaControl->playerManager->getPlayer($login);
|
||||||
$width = $this->maniaControl->manialinkManager->styleManager->getListWidgetsWidth();
|
$width = $this->maniaControl->manialinkManager->styleManager->getListWidgetsWidth();
|
||||||
$height = $this->maniaControl->manialinkManager->styleManager->getListWidgetsHeight();
|
$height = $this->maniaControl->manialinkManager->styleManager->getListWidgetsHeight();
|
||||||
@ -518,7 +518,7 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener, Timer
|
|||||||
$label->setText("Set Moderator");
|
$label->setText("Set Moderator");
|
||||||
$label->setTextColor($textColor);
|
$label->setTextColor($textColor);
|
||||||
|
|
||||||
if ($this->maniaControl->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_MODERATOR)) {
|
if ($player->authLevel > 0 && $this->maniaControl->authenticationManager->checkRight($admin, $player->authLevel + 1)) {
|
||||||
$y -= 5;
|
$y -= 5;
|
||||||
// Revoke Rights
|
// Revoke Rights
|
||||||
$quad = clone $quad;
|
$quad = clone $quad;
|
||||||
|
@ -253,7 +253,7 @@ class PlayerManager implements CallbackListener {
|
|||||||
*/
|
*/
|
||||||
public function getPlayer($login) {
|
public function getPlayer($login) {
|
||||||
if (!isset($this->players[$login])) {
|
if (!isset($this->players[$login])) {
|
||||||
return null;
|
return $this->getPlayerFromDatabaseByLogin($login);
|
||||||
}
|
}
|
||||||
return $this->players[$login];
|
return $this->players[$login];
|
||||||
}
|
}
|
||||||
@ -313,6 +313,10 @@ class PlayerManager implements CallbackListener {
|
|||||||
$row = $result->fetch_object();
|
$row = $result->fetch_object();
|
||||||
$result->close();
|
$result->close();
|
||||||
|
|
||||||
|
if (!isset($row)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
$player = new Player(false);
|
$player = new Player(false);
|
||||||
$player->index = $playerIndex;
|
$player->index = $playerIndex;
|
||||||
$player->login = $row->login;
|
$player->login = $row->login;
|
||||||
@ -324,6 +328,39 @@ class PlayerManager implements CallbackListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get's a Player out of the database
|
||||||
|
*
|
||||||
|
* @param $playerIndex
|
||||||
|
* @return Player $player
|
||||||
|
*/
|
||||||
|
private function getPlayerFromDatabaseByLogin($playerLogin) {
|
||||||
|
$mysqli = $this->maniaControl->database->mysqli;
|
||||||
|
|
||||||
|
$query = "SELECT * FROM `" . self::TABLE_PLAYERS . "` WHERE `login` LIKE '" . $mysqli->escape_string($playerLogin) . "';";
|
||||||
|
$result = $mysqli->query($query);
|
||||||
|
if (!$result) {
|
||||||
|
trigger_error($mysqli->error);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$row = $result->fetch_object();
|
||||||
|
$result->close();
|
||||||
|
|
||||||
|
if (!isset($row)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$player = new Player(false);
|
||||||
|
$player->index = $row->index;
|
||||||
|
$player->login = $row->login;
|
||||||
|
$player->nickname = $row->nickname;
|
||||||
|
$player->path = $row->path;
|
||||||
|
$player->authLevel = $row->authLevel;
|
||||||
|
|
||||||
|
return $player;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Save player in Database and fill up Object Properties
|
* Save player in Database and fill up Object Properties
|
||||||
*
|
*
|
||||||
|
Loading…
Reference in New Issue
Block a user