TrackManiaControl/application/core/Players/PlayerList.php

784 lines
28 KiB
PHP
Raw Normal View History

2013-12-18 15:48:33 +01:00
<?php
namespace ManiaControl\Players;
2013-12-19 21:59:10 +01:00
use FML\Controls\Control;
2013-12-18 15:48:33 +01:00
use FML\Controls\Frame;
use FML\Controls\Labels\Label_Button;
2013-12-18 23:35:33 +01:00
use FML\Controls\Labels\Label_Text;
2013-12-18 15:48:33 +01:00
use FML\Controls\Quad;
use FML\Controls\Quads\Quad_BgRaceScore2;
use FML\Controls\Quads\Quad_BgsPlayerCard;
2013-12-19 21:59:10 +01:00
use FML\Controls\Quads\Quad_Emblems;
2013-12-18 15:48:33 +01:00
use FML\Controls\Quads\Quad_Icons64x64_1;
2013-12-31 12:58:50 +01:00
use FML\Controls\Quads\Quad_UIConstruction_Buttons;
2013-12-18 15:48:33 +01:00
use FML\ManiaLink;
2014-04-27 16:22:12 +02:00
use FML\Script\Features\Paging;
2013-12-18 23:35:33 +01:00
use ManiaControl\Admin\AuthenticationManager;
2013-12-18 15:48:33 +01:00
use ManiaControl\Callbacks\CallbackListener;
2013-12-19 21:59:10 +01:00
use ManiaControl\Callbacks\CallbackManager;
2014-01-30 22:35:32 +01:00
use ManiaControl\Callbacks\TimerListener;
2013-12-18 15:48:33 +01:00
use ManiaControl\ManiaControl;
use ManiaControl\Manialinks\ManialinkManager;
use ManiaControl\Manialinks\ManialinkPageAnswerListener;
use ManiaControl\Utils\Formatter;
use Maniaplanet\DedicatedServer\Xmlrpc\PlayerStateException;
use Maniaplanet\DedicatedServer\Xmlrpc\UnknownPlayerException;
2014-05-02 17:50:30 +02:00
use MCTeam\CustomVotesPlugin;
2013-12-18 15:48:33 +01:00
2013-12-24 13:09:39 +01:00
/**
* PlayerList Widget Class
*
2014-05-02 17:50:30 +02:00
* @author ManiaControl Team <mail@maniacontrol.com>
* @copyright 2014 ManiaControl Team
2014-04-19 23:14:37 +02:00
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
2013-12-24 13:09:39 +01:00
*/
2014-01-30 22:35:32 +01:00
class PlayerList implements ManialinkPageAnswerListener, CallbackListener, TimerListener {
/*
2013-12-18 15:48:33 +01:00
* Constants
*/
2014-01-09 18:19:37 +01:00
const ACTION_FORCE_RED = 'PlayerList.ForceRed';
const ACTION_FORCE_BLUE = 'PlayerList.ForceBlue';
const ACTION_FORCE_SPEC = 'PlayerList.ForceSpec';
2014-02-08 00:00:00 +01:00
const ACTION_FORCE_SPEC_VOTE = 'PlayerList.ForceSpecVote';
2014-02-01 19:36:47 +01:00
const ACTION_FORCE_PLAY = 'PlayerList.ForcePlay';
2014-01-09 18:19:37 +01:00
const ACTION_PLAYER_ADV = 'PlayerList.PlayerAdvancedActions';
const ACTION_CLOSE_PLAYER_ADV = 'PlayerList.ClosePlayerAdvWidget';
const ACTION_MUTE_PLAYER = 'PlayerList.MutePlayer';
const ACTION_UNMUTE_PLAYER = 'PlayerList.UnMutePlayer';
const ACTION_WARN_PLAYER = 'PlayerList.WarnPlayer';
const ACTION_KICK_PLAYER = 'PlayerList.KickPlayer';
2014-02-08 00:00:00 +01:00
const ACTION_KICK_PLAYER_VOTE = 'PlayerList.KickPlayerVote';
2014-01-09 18:19:37 +01:00
const ACTION_BAN_PLAYER = 'PlayerList.BanPlayer';
const ACTION_ADD_AS_MASTER = 'PlayerList.PlayerAddAsMaster';
const ACTION_ADD_AS_ADMIN = 'PlayerList.PlayerAddAsAdmin';
const ACTION_ADD_AS_MOD = 'PlayerList.PlayerAddAsModerator';
const ACTION_REVOKE_RIGHTS = 'PlayerList.RevokeRights';
2014-01-03 16:24:35 +01:00
const ACTION_OPEN_PLAYER_DETAILED = 'PlayerList.OpenPlayerDetailed';
2014-01-09 18:19:37 +01:00
const ACTION_SPECTATE_PLAYER = 'PlayerList.SpectatePlayer';
2014-04-29 22:06:58 +02:00
const DEFAULT_CUSTOM_VOTE_PLUGIN = 'MCTeam\CustomVotesPlugin';
2014-01-09 18:19:37 +01:00
const SHOWN_MAIN_WINDOW = -1;
2014-01-27 19:41:07 +01:00
const MAX_PLAYERS_PER_PAGE = 15;
2014-01-09 18:19:37 +01:00
/*
2014-01-06 18:50:26 +01:00
* Private Properties
2013-12-18 15:48:33 +01:00
*/
private $maniaControl = null;
2013-12-19 21:59:10 +01:00
private $playersListShown = array();
2014-01-02 13:35:52 +01:00
2013-12-18 15:48:33 +01:00
/**
2014-01-06 18:50:26 +01:00
* Create a PlayerList Instance
2013-12-18 15:48:33 +01:00
*
* @param ManiaControl $maniaControl
*/
public function __construct(ManiaControl $maniaControl) {
$this->maniaControl = $maniaControl;
2014-01-09 18:19:37 +01:00
2014-01-02 13:35:52 +01:00
$this->maniaControl->manialinkManager->registerManialinkPageAnswerListener(self::ACTION_CLOSE_PLAYER_ADV, $this, 'closePlayerAdvancedWidget');
2013-12-29 22:52:07 +01:00
$this->maniaControl->callbackManager->registerCallbackListener(ManialinkManager::CB_MAIN_WINDOW_CLOSED, $this, 'closeWidget');
$this->maniaControl->callbackManager->registerCallbackListener(ManialinkManager::CB_MAIN_WINDOW_OPENED, $this, 'handleWidgetOpened');
2014-01-09 18:19:37 +01:00
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MP_PLAYERMANIALINKPAGEANSWER, $this, 'handleManialinkPageAnswer');
2013-12-31 12:17:25 +01:00
// Update Widget Events
2013-12-23 21:52:30 +01:00
$this->maniaControl->callbackManager->registerCallbackListener(PlayerManager::CB_PLAYERINFOCHANGED, $this, 'updateWidget');
2014-02-19 10:43:37 +01:00
$this->maniaControl->callbackManager->registerCallbackListener(PlayerManager::CB_PLAYERDISCONNECT, $this, 'updateWidget');
$this->maniaControl->callbackManager->registerCallbackListener(PlayerManager::CB_PLAYERCONNECT, $this, 'updateWidget');
2014-01-02 13:35:52 +01:00
$this->maniaControl->callbackManager->registerCallbackListener(AuthenticationManager::CB_AUTH_LEVEL_CHANGED, $this, 'updateWidget');
2014-01-30 23:38:13 +01:00
}
/**
* Add Player to Shown List
*
2014-01-30 23:38:13 +01:00
* @param Player $player
* @param int $showStatus
*/
2013-12-31 12:17:25 +01:00
public function addPlayerToShownList(Player $player, $showStatus = self::SHOWN_MAIN_WINDOW) {
2013-12-26 17:27:21 +01:00
$this->playersListShown[$player->login] = $showStatus;
}
2013-12-19 21:59:10 +01:00
2014-05-02 17:50:30 +02:00
/**
* Unset the player if he opened another Main Widget
*
* @param Player $player
* @param $openedWidget
*/
public function handleWidgetOpened(Player $player, $openedWidget) {
//unset when another main widget got opened
if ($openedWidget !== 'PlayerList') {
2014-05-02 17:50:30 +02:00
unset($this->playersListShown[$player->login]);
}
}
/**
* Closes the widget
*
* @param Player $player
*/
public function closeWidget(Player $player) {
unset($this->playersListShown[$player->login]);
}
/**
* Closes the player advanced widget widget
*
* @param array $callback
* @param Player $player
*/
public function closePlayerAdvancedWidget(array $callback, Player $player) {
$this->playersListShown[$player->login] = self::SHOWN_MAIN_WINDOW;
$this->showPlayerList($player); // overwrite the manialink
}
2014-01-06 18:50:26 +01:00
/**
* Show the PlayerList Widget to the Player
*
* @param Player $player
*/
2013-12-31 12:17:25 +01:00
public function showPlayerList(Player $player) {
2014-01-28 19:28:17 +01:00
$width = $this->maniaControl->manialinkManager->styleManager->getListWidgetsWidth();
$height = $this->maniaControl->manialinkManager->styleManager->getListWidgetsHeight();
2014-01-27 19:41:07 +01:00
// get PlayerList
$players = $this->maniaControl->playerManager->getPlayers();
2014-01-27 21:27:31 +01:00
2014-01-28 19:28:17 +01:00
//create manialink
$maniaLink = new ManiaLink(ManialinkManager::MAIN_MLID);
$script = $maniaLink->getScript();
2014-05-02 17:50:30 +02:00
$paging = new Paging();
$script->addFeature($paging);
2014-01-27 21:27:31 +01:00
2014-01-28 19:28:17 +01:00
// Main frame
2014-05-12 23:43:12 +02:00
$frame = $this->maniaControl->manialinkManager->styleManager->getDefaultListFrame($script, $paging);
2014-01-28 19:28:17 +01:00
$maniaLink->add($frame);
2014-01-27 19:41:07 +01:00
2013-12-31 12:17:25 +01:00
// Start offsets
2014-01-06 18:50:26 +01:00
$x = -$width / 2;
$y = $height / 2;
2014-01-09 18:19:37 +01:00
2014-01-06 18:50:26 +01:00
// Predefine Description Label
$descriptionLabel = $this->maniaControl->manialinkManager->styleManager->getDefaultDescriptionLabel();
2014-01-03 21:29:22 +01:00
$frame->add($descriptionLabel);
2014-01-09 18:19:37 +01:00
2013-12-31 12:17:25 +01:00
// Headline
2013-12-18 15:48:33 +01:00
$headFrame = new Frame();
$frame->add($headFrame);
2013-12-19 21:59:10 +01:00
$headFrame->setY($y - 5);
2014-01-27 21:27:31 +01:00
if ($this->maniaControl->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_MODERATOR)) {
2014-01-05 00:02:13 +01:00
$array = array("Id" => $x + 5, "Nickname" => $x + 18, "Login" => $x + 70, "Location" => $x + 101, "Actions" => $x + 135);
2014-01-09 18:19:37 +01:00
} else {
2014-01-05 00:02:13 +01:00
$array = array("Id" => $x + 5, "Nickname" => $x + 18, "Login" => $x + 70, "Location" => $x + 101);
2013-12-31 12:17:25 +01:00
}
$this->maniaControl->manialinkManager->labelLine($headFrame, $array);
2014-01-09 18:19:37 +01:00
2014-05-12 23:43:12 +02:00
$i = 1;
$y = $height / 2 - 10;
$pageFrame = null;
2014-05-02 17:50:30 +02:00
foreach ($players as $listPlayer) {
2014-05-12 23:43:12 +02:00
if ($i % self::MAX_PLAYERS_PER_PAGE === 1) {
2014-01-27 19:41:07 +01:00
$pageFrame = new Frame();
$frame->add($pageFrame);
2014-05-12 23:43:12 +02:00
2014-05-02 17:50:30 +02:00
$paging->addPage($pageFrame);
2014-05-12 23:43:12 +02:00
$y = $height / 2 - 10;
2014-01-27 19:41:07 +01:00
}
2014-01-09 18:19:37 +01:00
$path = $listPlayer->getProvince();
2013-12-18 15:48:33 +01:00
$playerFrame = new Frame();
2014-01-27 19:41:07 +01:00
$pageFrame->add($playerFrame);
2014-01-09 18:19:37 +01:00
if ($i % 2 !== 0) {
2013-12-31 02:27:40 +01:00
$lineQuad = new Quad_BgsPlayerCard();
$playerFrame->add($lineQuad);
2014-01-06 18:50:26 +01:00
$lineQuad->setSize($width, 4);
2013-12-31 02:27:40 +01:00
$lineQuad->setSubStyle($lineQuad::SUBSTYLE_BgPlayerCardBig);
$lineQuad->setZ(0.001);
}
2014-01-09 18:19:37 +01:00
2014-01-06 18:50:26 +01:00
$array = array($i => $x + 5, $listPlayer->nickname => $x + 18, $listPlayer->login => $x + 70, $path => $x + 101);
2014-01-09 18:19:37 +01:00
$this->maniaControl->manialinkManager->labelLine($playerFrame, $array);
2013-12-18 15:48:33 +01:00
$playerFrame->setY($y);
2014-01-09 18:19:37 +01:00
// Show current Player Arrow
if ($listPlayer->index === $player->index) {
2014-01-31 15:41:01 +01:00
$currentQuad = new Quad_Icons64x64_1();
$playerFrame->add($currentQuad);
$currentQuad->setX($x + 3.5);
$currentQuad->setZ(0.2);
$currentQuad->setSize(4, 4);
$currentQuad->setSubStyle($currentQuad::SUBSTYLE_ArrowBlue);
}
2013-12-31 12:17:25 +01:00
// Team Emblem
2014-01-27 21:27:31 +01:00
if ($listPlayer->teamId >= 0) {
2013-12-31 16:17:50 +01:00
// Player is in a Team
$teamQuad = new Quad_Emblems();
$playerFrame->add($teamQuad);
$teamQuad->setX($x + 10);
$teamQuad->setZ(0.1);
$teamQuad->setSize(3.8, 3.8);
2014-01-09 18:19:37 +01:00
2014-05-02 17:50:30 +02:00
switch ($listPlayer->teamId) {
2013-12-31 12:17:25 +01:00
case 0:
2013-12-31 17:15:32 +01:00
$teamQuad->setSubStyle($teamQuad::SUBSTYLE_1);
2013-12-31 12:17:25 +01:00
break;
case 1:
2013-12-31 17:15:32 +01:00
$teamQuad->setSubStyle($teamQuad::SUBSTYLE_2);
2013-12-31 12:17:25 +01:00
break;
2013-12-18 23:35:33 +01:00
}
2014-01-27 21:27:31 +01:00
} else if ($listPlayer->isSpectator) {
2013-12-31 16:17:50 +01:00
// Player is in Spectator Mode
$specQuad = new Quad_BgRaceScore2();
$playerFrame->add($specQuad);
$specQuad->setX($x + 10);
$specQuad->setZ(0.1);
2013-12-31 17:15:32 +01:00
$specQuad->setSubStyle($specQuad::SUBSTYLE_Spectator);
2013-12-31 16:17:50 +01:00
$specQuad->setSize(3.8, 3.8);
2013-12-19 21:59:10 +01:00
}
2014-01-09 18:19:37 +01:00
2014-01-31 14:48:24 +01:00
$countryCode = Formatter::mapCountry($listPlayer->getCountry());
if ($countryCode !== 'OTH') {
2013-12-31 12:17:25 +01:00
// Nation Quad
$countryQuad = new Quad();
$playerFrame->add($countryQuad);
2014-04-13 11:50:07 +02:00
$countryQuad->setImage("file://ZoneFlags/Login/{$listPlayer->login}/country");
2014-01-05 00:02:13 +01:00
$countryQuad->setX($x + 98);
2014-01-10 15:58:27 +01:00
$countryQuad->setZ(1);
$countryQuad->setSize(4, 4);
2014-01-09 18:19:37 +01:00
2014-05-02 17:50:30 +02:00
$countryQuad->addTooltipLabelFeature($descriptionLabel, '$<' . $listPlayer->nickname . '$> from ' . $listPlayer->path);
}
2014-01-09 18:19:37 +01:00
2013-12-31 12:17:25 +01:00
// Level Quad
2013-12-19 21:59:10 +01:00
$rightQuad = new Quad_BgRaceScore2();
$playerFrame->add($rightQuad);
$rightQuad->setX($x + 13);
$rightQuad->setZ(3);
2013-12-31 12:17:25 +01:00
$rightQuad->setSize(7, 3.5);
$rightQuad->setSubStyle($rightQuad::SUBSTYLE_CupFinisher);
2014-01-09 18:19:37 +01:00
2013-12-19 21:59:10 +01:00
$rightLabel = new Label_Text();
$playerFrame->add($rightLabel);
$rightLabel->setX($x + 13.9);
$rightLabel->setZ(3.1);
$rightLabel->setText($this->maniaControl->authenticationManager->getAuthLevelAbbreviation($listPlayer->authLevel));
$rightLabel->setTextSize(0.8);
$rightLabel->setTextColor("fff");
2014-01-09 18:19:37 +01:00
2014-05-02 17:50:30 +02:00
$description = $this->maniaControl->authenticationManager->getAuthLevelName($listPlayer) . " " . $listPlayer->nickname;
$rightLabel->addTooltipLabelFeature($descriptionLabel, $description);
2014-01-09 18:19:37 +01:00
2014-01-05 00:02:13 +01:00
// Player Statistics
$playerQuad = new Quad_Icons64x64_1();
$playerFrame->add($playerQuad);
$playerQuad->setX($x + 61);
$playerQuad->setZ(3);
2014-01-05 00:02:13 +01:00
$playerQuad->setSize(2.7, 2.7);
$playerQuad->setSubStyle($playerQuad::SUBSTYLE_TrackInfo);
2014-01-05 00:02:13 +01:00
$playerQuad->setAction(self::ACTION_OPEN_PLAYER_DETAILED . "." . $listPlayer->login);
2014-05-02 17:50:30 +02:00
$description = 'View Statistics of $<' . $listPlayer->nickname . '$>';
$playerQuad->addTooltipLabelFeature($descriptionLabel, $description);
2014-01-09 18:19:37 +01:00
2014-01-05 00:02:13 +01:00
// Camera Quad
$playerQuad = new Quad_UIConstruction_Buttons();
$playerFrame->add($playerQuad);
$playerQuad->setX($x + 64.5);
$playerQuad->setZ(3);
2014-01-05 00:02:13 +01:00
$playerQuad->setSize(3.8, 3.8);
$playerQuad->setSubStyle($playerQuad::SUBSTYLE_Camera);
2014-05-02 17:50:30 +02:00
$description = 'Spectate $<' . $listPlayer->nickname . '$>';
$playerQuad->addTooltipLabelFeature($descriptionLabel, $description);
2014-01-10 15:58:27 +01:00
$playerQuad->setAction(self::ACTION_SPECTATE_PLAYER . "." . $listPlayer->login);
2014-01-09 18:19:37 +01:00
2013-12-31 12:58:50 +01:00
// Player Profile Quad
$playerQuad = new Quad_UIConstruction_Buttons();
$playerFrame->add($playerQuad);
2014-01-05 00:02:13 +01:00
$playerQuad->setX($x + 68);
$playerQuad->setZ(3);
2013-12-31 12:58:50 +01:00
$playerQuad->setSize(3.8, 3.8);
$playerQuad->setSubStyle($playerQuad::SUBSTYLE_Author);
2014-05-02 17:50:30 +02:00
$playerQuad->addPlayerProfileFeature($listPlayer->login);
2014-01-09 18:19:37 +01:00
2013-12-31 12:58:50 +01:00
// Description Label
2014-05-02 17:50:30 +02:00
$description = 'View Player Profile of $<' . $listPlayer->nickname . '$>';
$playerQuad->addTooltipLabelFeature($descriptionLabel, $description);
2014-01-09 18:19:37 +01:00
2014-01-27 21:27:31 +01:00
if ($this->maniaControl->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_MODERATOR)) {
2013-12-31 12:17:25 +01:00
// Further Player actions Quad
2013-12-19 21:59:10 +01:00
$playerQuad = new Quad_Icons64x64_1();
$playerFrame->add($playerQuad);
$playerQuad->setX($x + 132);
$playerQuad->setZ(0.1);
2013-12-31 12:17:25 +01:00
$playerQuad->setSize(3.8, 3.8);
$playerQuad->setSubStyle($playerQuad::SUBSTYLE_Buddy);
2013-12-31 12:17:25 +01:00
$playerQuad->setAction(self::ACTION_PLAYER_ADV . "." . $listPlayer->login);
2014-01-09 18:19:37 +01:00
2014-01-03 21:29:22 +01:00
// Description Label
2014-05-02 17:50:30 +02:00
$description = 'Advanced Player Actions for $<' . $listPlayer->nickname . '$>';
$playerQuad->addTooltipLabelFeature($descriptionLabel, $description);
2014-02-08 00:00:00 +01:00
}
2014-01-09 18:19:37 +01:00
if ($this->maniaControl->server->isTeamMode()) {
2014-02-08 00:00:00 +01:00
if ($this->maniaControl->authenticationManager->checkPermission($player, PlayerActions::SETTING_PERMISSION_FORCE_PLAYER_TEAM)) {
2014-02-01 19:06:21 +01:00
// Force to Red-Team Quad
$redQuad = new Quad_Emblems();
$playerFrame->add($redQuad);
$redQuad->setX($x + 145);
$redQuad->setZ(0.1);
$redQuad->setSize(3.8, 3.8);
$redQuad->setSubStyle($redQuad::SUBSTYLE_2);
$redQuad->setAction(self::ACTION_FORCE_RED . '.' . $listPlayer->login);
2014-02-01 19:06:21 +01:00
// Force to Red-Team Description Label
2014-05-02 17:50:30 +02:00
$description = 'Force $<' . $listPlayer->nickname . '$> to Red Team!';
$redQuad->addTooltipLabelFeature($descriptionLabel, $description);
2014-02-01 19:06:21 +01:00
// Force to Blue-Team Quad
$blueQuad = new Quad_Emblems();
$playerFrame->add($blueQuad);
$blueQuad->setX($x + 141);
$blueQuad->setZ(0.1);
$blueQuad->setSize(3.8, 3.8);
$blueQuad->setSubStyle($blueQuad::SUBSTYLE_1);
$blueQuad->setAction(self::ACTION_FORCE_BLUE . '.' . $listPlayer->login);
2014-02-01 19:06:21 +01:00
// Force to Blue-Team Description Label
2014-05-02 17:50:30 +02:00
$description = 'Force $<' . $listPlayer->nickname . '$> to Blue Team!';
$blueQuad->addTooltipLabelFeature($descriptionLabel, $description);
2014-02-08 00:00:00 +01:00
} else if ($this->maniaControl->pluginManager->isPluginActive(self::DEFAULT_CUSTOM_VOTE_PLUGIN)) {
// Kick Player Vote
$kickQuad = new Quad_UIConstruction_Buttons();
$playerFrame->add($kickQuad);
$kickQuad->setX($x + 141);
$kickQuad->setZ(0.1);
$kickQuad->setSize(3.8, 3.8);
$kickQuad->setSubStyle($kickQuad::SUBSTYLE_Validate_Step2);
$kickQuad->setAction(self::ACTION_KICK_PLAYER_VOTE . '.' . $listPlayer->login);
2014-02-08 00:00:00 +01:00
2014-05-02 17:50:30 +02:00
$description = 'Start a Kick Vote on $<' . $listPlayer->nickname . '$>!';
$kickQuad->addTooltipLabelFeature($descriptionLabel, $description);
2014-02-08 00:00:00 +01:00
}
} else {
if ($this->maniaControl->authenticationManager->checkPermission($player, PlayerActions::SETTING_PERMISSION_FORCE_PLAYER_PLAY)) {
2014-02-01 19:36:47 +01:00
// Force to Play
2014-02-01 19:43:44 +01:00
$playQuad = new Quad_Emblems();
$playerFrame->add($playQuad);
$playQuad->setX($x + 143);
$playQuad->setZ(0.1);
$playQuad->setSize(3.8, 3.8);
$playQuad->setSubStyle($playQuad::SUBSTYLE_2);
$playQuad->setAction(self::ACTION_FORCE_PLAY . '.' . $listPlayer->login);
2014-02-01 19:43:44 +01:00
2014-05-02 17:50:30 +02:00
$description = 'Force $<' . $listPlayer->nickname . '$> to Play!';
$playQuad->addTooltipLabelFeature($descriptionLabel, $description);
2014-02-01 19:06:21 +01:00
}
2014-02-08 00:00:00 +01:00
}
2014-01-09 18:19:37 +01:00
2014-02-08 00:00:00 +01:00
if ($this->maniaControl->authenticationManager->checkPermission($player, PlayerActions::SETTING_PERMISSION_FORCE_PLAYER_SPEC)) {
2013-12-31 12:17:25 +01:00
// Force to Spectator Quad
2013-12-19 21:59:10 +01:00
$spectatorQuad = new Quad_BgRaceScore2();
$playerFrame->add($spectatorQuad);
$spectatorQuad->setX($x + 137);
$spectatorQuad->setZ(0.1);
2013-12-31 12:17:25 +01:00
$spectatorQuad->setSize(3.8, 3.8);
$spectatorQuad->setSubStyle($spectatorQuad::SUBSTYLE_Spectator);
$spectatorQuad->setAction(self::ACTION_FORCE_SPEC . '.' . $listPlayer->login);
2014-01-09 18:19:37 +01:00
2013-12-31 12:17:25 +01:00
// Force to Spectator Description Label
2014-05-02 17:50:30 +02:00
$description = 'Force $<' . $listPlayer->nickname . '$> to Spectator!';
$spectatorQuad->addTooltipLabelFeature($descriptionLabel, $description);
2014-02-08 00:00:00 +01:00
} else if ($this->maniaControl->pluginManager->isPluginActive(self::DEFAULT_CUSTOM_VOTE_PLUGIN)) {
// Force to Spectator Quad
$spectatorQuad = new Quad_BgRaceScore2();
$playerFrame->add($spectatorQuad);
$spectatorQuad->setX($x + 137);
$spectatorQuad->setZ(0.1);
$spectatorQuad->setSize(3.8, 3.8);
$spectatorQuad->setSubStyle($spectatorQuad::SUBSTYLE_Spectator);
$spectatorQuad->setAction(self::ACTION_FORCE_SPEC_VOTE . '.' . $listPlayer->login);
2014-02-08 00:00:00 +01:00
// Force to Spectator Description Label
2014-05-02 17:50:30 +02:00
$description = 'Start a Vote to force $<' . $listPlayer->nickname . '$> to Spectator!';
$spectatorQuad->addTooltipLabelFeature($descriptionLabel, $description);
2013-12-18 23:35:33 +01:00
}
2014-02-08 00:00:00 +01:00
2013-12-18 15:48:33 +01:00
$y -= 4;
2014-01-27 19:41:07 +01:00
$i++;
2013-12-18 15:48:33 +01:00
}
2014-01-09 18:19:37 +01:00
2014-01-06 18:50:26 +01:00
// Show advanced window
$listShownValue = $this->playersListShown[$player->login];
if ($listShownValue && $listShownValue !== self::SHOWN_MAIN_WINDOW) {
$frame = $this->showAdvancedPlayerWidget($player, $listShownValue);
2013-12-26 17:27:21 +01:00
$maniaLink->add($frame);
}
2014-01-09 18:19:37 +01:00
2014-01-06 18:50:26 +01:00
// Render and display xml
$this->maniaControl->manialinkManager->displayWidget($maniaLink, $player, 'PlayerList');
2013-12-18 15:48:33 +01:00
}
/**
* Extra window with special actions on players like warn,kick, ban, authorization levels...
2013-12-31 12:17:25 +01:00
*
* @param Player $admin
* @param string $login
2013-12-26 17:27:21 +01:00
* @return Frame
*/
public function showAdvancedPlayerWidget(Player $admin, $login) {
2014-01-09 18:19:37 +01:00
$player = $this->maniaControl->playerManager->getPlayer($login);
$width = $this->maniaControl->manialinkManager->styleManager->getListWidgetsWidth();
$height = $this->maniaControl->manialinkManager->styleManager->getListWidgetsHeight();
$quadStyle = $this->maniaControl->manialinkManager->styleManager->getDefaultMainWindowStyle();
2014-01-06 18:50:26 +01:00
$quadSubstyle = $this->maniaControl->manialinkManager->styleManager->getDefaultMainWindowSubStyle();
2014-01-09 18:19:37 +01:00
2014-01-09 19:15:06 +01:00
//Settings
2014-01-09 18:19:37 +01:00
$x = $width / 2 + 2.5;
$width = 35;
$height = $height * 0.75;
$hAlign = Control::LEFT;
$style = Label_Text::STYLE_TextCardSmall;
$textSize = 1.5;
$textColor = 'FFF';
2013-12-26 11:25:10 +01:00
$quadWidth = $width - 7;
2014-01-09 18:19:37 +01:00
2013-12-31 12:17:25 +01:00
// mainframe
$frame = new Frame();
2013-12-31 12:17:25 +01:00
$frame->setSize($width, $height);
$frame->setPosition($x + $width / 2, 0);
2014-01-09 18:19:37 +01:00
// Add Close Quad (X)
$closeQuad = new Quad_Icons64x64_1();
$frame->add($closeQuad);
$closeQuad->setPosition($width * 0.4, $height * 0.43, 3);
$closeQuad->setSize(6, 6);
$closeQuad->setSubStyle(Quad_Icons64x64_1::SUBSTYLE_QuitRace);
2013-12-31 12:17:25 +01:00
$closeQuad->setAction(self::ACTION_CLOSE_PLAYER_ADV);
2014-01-09 18:19:37 +01:00
2013-12-31 12:17:25 +01:00
// Background Quad
$backgroundQuad = new Quad();
$frame->add($backgroundQuad);
2013-12-31 12:17:25 +01:00
$backgroundQuad->setSize($width, $height);
2014-01-17 18:58:15 +01:00
$backgroundQuad->setImage('https://dl.dropboxusercontent.com/u/105352981/Stuff/CAM%20SM%20BORDER%20PNG.png'); //TODO just a test
//$backgroundQuad->setStyles($quadStyle, $quadSubstyle);
$backgroundQuad->setZ(0.2);
// Background Quad
$backgroundQuad = new Quad();
$frame->add($backgroundQuad);
$backgroundQuad->setSize($width - 2, $height - 2);
2014-01-06 18:50:26 +01:00
$backgroundQuad->setStyles($quadStyle, $quadSubstyle);
$backgroundQuad->setZ(0.1);
2014-01-09 18:19:37 +01:00
2013-12-31 12:17:25 +01:00
// Show headline
$label = new Label_Text();
$frame->add($label);
$label->setHAlign($hAlign);
$label->setX(-$width / 2 + 5);
$label->setY($height / 2 - 5);
$label->setStyle($style);
$label->setTextSize($textSize);
$label->setText("Advanced Actions");
$label->setTextColor($textColor);
2014-01-09 18:19:37 +01:00
2013-12-31 12:17:25 +01:00
// Show Nickname
$label = new Label_Text();
$frame->add($label);
$label->setHAlign($hAlign);
$label->setX(0);
$label->setY($height / 2 - 8);
$label->setStyle($style);
$label->setTextSize($textSize);
$label->setText($player->nickname);
$label->setTextColor($textColor);
2014-01-09 18:19:37 +01:00
2014-01-06 18:50:26 +01:00
// Mute Player
2014-01-09 18:19:37 +01:00
$y = $height / 2 - 14;
$quad = new Quad_BgsPlayerCard();
$frame->add($quad);
$quad->setX(0);
$quad->setY($y);
2013-12-26 17:27:21 +01:00
$quad->setSubStyle($quad::SUBSTYLE_BgPlayerCardBig);
2013-12-26 11:25:10 +01:00
$quad->setSize($quadWidth, 5);
2014-01-09 18:19:37 +01:00
$label = new Label_Button();
$frame->add($label);
$label->setX(0);
$label->setY($y);
$label->setStyle($style);
$label->setTextSize($textSize);
2014-01-02 16:37:52 +01:00
$label->setTextColor($textColor);
2014-01-09 18:19:37 +01:00
2014-01-27 21:27:31 +01:00
if (!$this->maniaControl->playerManager->playerActions->isPlayerMuted($login)) {
2014-01-02 16:37:52 +01:00
$label->setText("Mute");
$quad->setAction(self::ACTION_MUTE_PLAYER . "." . $login);
2014-01-09 18:19:37 +01:00
} else {
2014-01-02 16:37:52 +01:00
$label->setText("UnMute");
$quad->setAction(self::ACTION_UNMUTE_PLAYER . "." . $login);
}
2014-01-09 18:19:37 +01:00
2014-01-06 18:50:26 +01:00
// Warn Player
2014-01-02 16:37:52 +01:00
$y -= 5;
$quad = clone $quad;
$frame->add($quad);
$quad->setY($y);
2014-01-10 15:58:27 +01:00
$quad->setAction(self::ACTION_WARN_PLAYER . "." . $login);
2014-01-09 18:19:37 +01:00
2014-01-02 16:37:52 +01:00
$label = clone $label;
$frame->add($label);
$label->setY($y);
$label->setText("Warn");
$label->setTextColor($textColor);
2014-01-09 18:19:37 +01:00
$y -= 5;
2014-01-09 18:19:37 +01:00
2013-12-31 12:17:25 +01:00
// Show Kick
2014-01-02 13:35:52 +01:00
$quad = clone $quad;
$frame->add($quad);
$quad->setY($y);
2013-12-31 12:17:25 +01:00
$quad->setAction(self::ACTION_KICK_PLAYER . "." . $login);
2014-01-09 18:19:37 +01:00
2014-01-02 13:35:52 +01:00
$label = clone $label;
$frame->add($label);
$label->setY($y);
$label->setText("Kick");
2013-12-31 02:27:40 +01:00
$label->setTextColor("F90");
2014-01-09 18:19:37 +01:00
$y -= 5;
2013-12-31 12:17:25 +01:00
// Show Ban
2014-01-02 13:35:52 +01:00
$quad = clone $quad;
$frame->add($quad);
$quad->setY($y);
2013-12-31 12:17:25 +01:00
$quad->setAction(self::ACTION_BAN_PLAYER . "." . $login);
2014-01-09 18:19:37 +01:00
2014-01-02 13:35:52 +01:00
$label = clone $label;
$frame->add($label);
$label->setY($y);
$label->setText("Ban");
2013-12-31 02:27:40 +01:00
$label->setTextColor("700");
2014-01-09 18:19:37 +01:00
$y -= 10;
2013-12-31 12:17:25 +01:00
// Show Add as Master-Admin
2014-01-02 13:35:52 +01:00
$quad = clone $quad;
$frame->add($quad);
$quad->setY($y);
2013-12-31 12:17:25 +01:00
$quad->setAction(self::ACTION_ADD_AS_MASTER . "." . $login);
2014-01-09 18:19:37 +01:00
2014-01-02 13:35:52 +01:00
$label = clone $label;
$frame->add($label);
$label->setY($y);
2014-01-09 18:19:37 +01:00
2013-12-31 02:27:40 +01:00
$label->setText("Set SuperAdmin");
2014-01-09 18:19:37 +01:00
$label->setTextColor($textColor);
2014-01-09 18:19:37 +01:00
$y -= 5;
2013-12-31 12:17:25 +01:00
// Show Add as Admin
2014-01-02 13:35:52 +01:00
$quad = clone $quad;
$frame->add($quad);
$quad->setY($y);
2013-12-31 12:17:25 +01:00
$quad->setAction(self::ACTION_ADD_AS_ADMIN . "." . $login);
2014-01-09 18:19:37 +01:00
2014-01-02 13:35:52 +01:00
$label = clone $label;
$frame->add($label);
$label->setY($y);
2013-12-31 02:27:40 +01:00
$label->setText("Set Admin");
$label->setTextColor($textColor);
2014-01-09 18:19:37 +01:00
$y -= 5;
2013-12-31 12:17:25 +01:00
// Show Add as Moderator
2014-01-02 13:35:52 +01:00
$quad = clone $quad;
$frame->add($quad);
$quad->setY($y);
2013-12-31 12:17:25 +01:00
$quad->setAction(self::ACTION_ADD_AS_MOD . "." . $login);
2014-01-09 18:19:37 +01:00
2014-01-02 13:35:52 +01:00
$label = clone $label;
$frame->add($label);
$label->setY($y);
2013-12-31 02:27:40 +01:00
$label->setText("Set Moderator");
$label->setTextColor($textColor);
2014-01-09 18:19:37 +01:00
2014-01-31 14:19:39 +01:00
if ($player->authLevel > 0 && $this->maniaControl->authenticationManager->checkRight($admin, $player->authLevel + 1)) {
2013-12-26 11:25:10 +01:00
$y -= 5;
2013-12-31 12:17:25 +01:00
// Revoke Rights
2014-01-02 13:35:52 +01:00
$quad = clone $quad;
2013-12-26 11:25:10 +01:00
$frame->add($quad);
$quad->setY($y);
2013-12-31 12:17:25 +01:00
$quad->setAction(self::ACTION_REVOKE_RIGHTS . "." . $login);
2014-01-09 18:19:37 +01:00
2014-01-02 13:35:52 +01:00
$label = clone $label;
2013-12-26 11:25:10 +01:00
$frame->add($label);
$label->setY($y);
$label->setText("Revoke Rights");
2013-12-31 02:27:40 +01:00
$label->setTextColor("700");
2013-12-26 11:25:10 +01:00
}
2014-01-09 18:19:37 +01:00
2013-12-26 17:27:21 +01:00
return $frame;
}
2013-12-29 22:52:07 +01:00
2013-12-19 21:59:10 +01:00
/**
2013-12-29 15:52:01 +01:00
* Called on ManialinkPageAnswer
2013-12-31 12:17:25 +01:00
*
2013-12-19 21:59:10 +01:00
* @param array $callback
*/
2013-12-31 12:17:25 +01:00
public function handleManialinkPageAnswer(array $callback) {
2014-01-09 18:19:37 +01:00
$actionId = $callback[1][2];
2014-01-16 13:38:53 +01:00
$actionArray = explode('.', $actionId, 3);
2014-01-27 21:27:31 +01:00
if (count($actionArray) <= 2) {
2014-01-09 18:19:37 +01:00
return;
}
$action = $actionArray[0] . "." . $actionArray[1];
$adminLogin = $callback[1][1];
2013-12-31 16:01:22 +01:00
$targetLogin = $actionArray[2];
2014-01-09 18:19:37 +01:00
2014-05-02 17:50:30 +02:00
switch ($action) {
2014-01-10 18:16:14 +01:00
case self::ACTION_SPECTATE_PLAYER:
2014-01-16 21:51:25 +01:00
try {
2014-01-27 19:41:07 +01:00
$this->maniaControl->client->forceSpectator($adminLogin, PlayerActions::SPECTATOR_BUT_KEEP_SELECTABLE);
2014-01-17 16:16:12 +01:00
$this->maniaControl->client->forceSpectatorTarget($adminLogin, $targetLogin, 1);
} catch (PlayerStateException $e) {
2014-01-16 21:51:25 +01:00
}
2014-01-05 00:43:46 +01:00
break;
2014-01-03 16:24:35 +01:00
case self::ACTION_OPEN_PLAYER_DETAILED:
$player = $this->maniaControl->playerManager->getPlayer($adminLogin);
$this->maniaControl->playerManager->playerDetailed->showPlayerDetailed($player, $targetLogin);
2014-01-04 00:11:12 +01:00
unset($this->playersListShown[$player->login]);
2014-01-03 16:24:35 +01:00
break;
2013-12-23 20:57:50 +01:00
case self::ACTION_FORCE_BLUE:
2014-01-06 18:50:26 +01:00
$this->maniaControl->playerManager->playerActions->forcePlayerToTeam($adminLogin, $targetLogin, PlayerActions::TEAM_BLUE);
2013-12-23 20:57:50 +01:00
break;
case self::ACTION_FORCE_RED:
2014-01-06 18:50:26 +01:00
$this->maniaControl->playerManager->playerActions->forcePlayerToTeam($adminLogin, $targetLogin, PlayerActions::TEAM_RED);
2013-12-23 20:57:50 +01:00
break;
case self::ACTION_FORCE_SPEC:
2014-01-09 18:19:37 +01:00
$this->maniaControl->playerManager->playerActions->forcePlayerToSpectator($adminLogin, $targetLogin, PlayerActions::SPECTATOR_BUT_KEEP_SELECTABLE);
2013-12-23 20:57:50 +01:00
break;
2014-02-01 19:43:44 +01:00
case self::ACTION_FORCE_PLAY:
$this->maniaControl->playerManager->playerActions->forcePlayerToPlay($adminLogin, $targetLogin);
break;
2014-01-02 16:37:52 +01:00
case self::ACTION_MUTE_PLAYER:
$this->maniaControl->playerManager->playerActions->mutePlayer($adminLogin, $targetLogin);
$this->showPlayerList($this->maniaControl->playerManager->getPlayer($adminLogin));
break;
case self::ACTION_UNMUTE_PLAYER:
$this->maniaControl->playerManager->playerActions->unMutePlayer($adminLogin, $targetLogin);
$this->showPlayerList($this->maniaControl->playerManager->getPlayer($adminLogin));
break;
2013-12-23 20:57:50 +01:00
case self::ACTION_WARN_PLAYER:
2013-12-31 16:01:22 +01:00
$this->maniaControl->playerManager->playerActions->warnPlayer($adminLogin, $targetLogin);
2013-12-23 20:57:50 +01:00
break;
case self::ACTION_KICK_PLAYER:
2013-12-31 16:01:22 +01:00
$this->maniaControl->playerManager->playerActions->kickPlayer($adminLogin, $targetLogin);
2013-12-23 20:57:50 +01:00
break;
case self::ACTION_BAN_PLAYER:
2013-12-31 16:01:22 +01:00
$this->maniaControl->playerManager->playerActions->banPlayer($adminLogin, $targetLogin);
2013-12-23 20:57:50 +01:00
break;
case self::ACTION_PLAYER_ADV:
2013-12-31 16:01:22 +01:00
$admin = $this->maniaControl->playerManager->getPlayer($adminLogin);
$this->advancedPlayerWidget($admin, $targetLogin);
2013-12-23 20:57:50 +01:00
break;
2013-12-26 11:25:10 +01:00
case self::ACTION_ADD_AS_MASTER:
2014-01-09 18:19:37 +01:00
$this->maniaControl->playerManager->playerActions->grandAuthLevel($adminLogin, $targetLogin, AuthenticationManager::AUTH_LEVEL_SUPERADMIN);
2013-12-26 11:25:10 +01:00
break;
case self::ACTION_ADD_AS_ADMIN:
2014-01-02 13:35:52 +01:00
$this->maniaControl->playerManager->playerActions->grandAuthLevel($adminLogin, $targetLogin, AuthenticationManager::AUTH_LEVEL_ADMIN);
2013-12-26 11:25:10 +01:00
break;
case self::ACTION_ADD_AS_MOD:
2014-01-09 18:19:37 +01:00
$this->maniaControl->playerManager->playerActions->grandAuthLevel($adminLogin, $targetLogin, AuthenticationManager::AUTH_LEVEL_MODERATOR);
2013-12-26 11:25:10 +01:00
break;
case self::ACTION_REVOKE_RIGHTS:
2013-12-31 16:01:22 +01:00
$this->maniaControl->playerManager->playerActions->revokeAuthLevel($adminLogin, $targetLogin);
2013-12-26 11:25:10 +01:00
break;
2014-02-08 00:00:00 +01:00
case self::ACTION_FORCE_SPEC_VOTE:
/** @var $votesPlugin CustomVotesPlugin */
$votesPlugin = $this->maniaControl->pluginManager->getPlugin(self::DEFAULT_CUSTOM_VOTE_PLUGIN);
$admin = $this->maniaControl->playerManager->getPlayer($adminLogin);
$target = $this->maniaControl->playerManager->getPlayer($targetLogin);
$startMessage = '$<' . $admin->nickname . '$>$s started a vote to force $<' . $target->nickname . '$> into spectator!';
$votesPlugin->defineVote('forcespec', "Force $<" . $target->nickname . "$> Spec", true, $startMessage);
2014-04-20 14:52:26 +02:00
$self = $this;
$votesPlugin->startVote($admin, 'forcespec', function ($result) use (&$self, &$votesPlugin, &$target) {
$self->maniaControl->chat->sendInformation('$sVote Successfully -> Player $<' . $target->nickname . '$> forced to Spectator!');
2014-02-08 00:00:00 +01:00
$votesPlugin->undefineVote('forcespec');
try {
2014-04-20 14:52:26 +02:00
$self->maniaControl->client->forceSpectator($target->login, PlayerActions::SPECTATOR_BUT_KEEP_SELECTABLE);
$self->maniaControl->client->spectatorReleasePlayerSlot($target->login);
} catch (PlayerStateException $e) {
2014-02-08 00:00:00 +01:00
}
});
break;
case self::ACTION_KICK_PLAYER_VOTE:
/** @var $votesPlugin CustomVotesPlugin */
$votesPlugin = $this->maniaControl->pluginManager->getPlugin(self::DEFAULT_CUSTOM_VOTE_PLUGIN);
$admin = $this->maniaControl->playerManager->getPlayer($adminLogin);
$target = $this->maniaControl->playerManager->getPlayer($targetLogin);
$startMessage = '$<' . $admin->nickname . '$>$s started a vote to kick $<' . $target->nickname . '$>!';
$votesPlugin->defineVote('kick', "Kick $<" . $target->nickname . "$>", true, $startMessage);
2014-04-20 14:52:26 +02:00
$self = $this;
$votesPlugin->startVote($admin, 'kick', function ($result) use (&$self, &$votesPlugin, &$target) {
$self->maniaControl->chat->sendInformation('$sVote Successfully -> $<' . $target->nickname . '$> got Kicked!');
2014-02-08 00:00:00 +01:00
$votesPlugin->undefineVote('kick');
$message = '$39F You got kicked due a Public vote!$z ';
2014-04-20 12:54:29 +02:00
try {
2014-04-20 14:52:26 +02:00
$self->maniaControl->client->kick($target->login, $message);
} catch (UnknownPlayerException $e) {
2014-04-20 12:54:29 +02:00
}
2014-02-08 00:00:00 +01:00
});
break;
2013-12-23 20:57:50 +01:00
}
2013-12-19 21:59:10 +01:00
}
2014-05-02 17:50:30 +02:00
/**
* Display the Advanced Player Window
2014-05-02 17:50:30 +02:00
*
* @param Player $caller
* @param string $login
2014-05-02 17:50:30 +02:00
*/
public function advancedPlayerWidget(Player $caller, $login) {
// Set status to target player login
$this->playersListShown[$caller->login] = $login;
2014-05-13 18:26:38 +02:00
// Reopen PlayerList
2014-05-02 17:50:30 +02:00
$this->showPlayerList($caller);
}
2013-12-19 21:59:10 +01:00
/**
2013-12-23 21:52:30 +01:00
* Reopen the widget on PlayerInfoChanged / Player Connect and Disconnect
2013-12-31 12:17:25 +01:00
*
* @param Player $player
2013-12-19 21:59:10 +01:00
*/
public function updateWidget(Player $player) {
2014-05-02 17:50:30 +02:00
foreach ($this->playersListShown as $login => $shown) {
2014-04-19 23:14:37 +02:00
if (!$shown) {
continue;
}
// Check if shown player still exists
$player = $this->maniaControl->playerManager->getPlayer($login);
if (!$player) {
unset($this->playersListShown[$login]);
continue;
}
2014-04-19 23:14:37 +02:00
// Reopen widget
if ($shown !== self::SHOWN_MAIN_WINDOW) {
$this->playersListShown[$login] = false;
2013-12-19 21:59:10 +01:00
}
$this->showPlayerList($player);
2013-12-19 21:59:10 +01:00
}
}
}