Statslist and Playerlist now have Chunking
This commit is contained in:
parent
a3d7bdbb8a
commit
d6419cea97
@ -4,6 +4,7 @@ namespace ManiaControl\Callbacks\Structures\TrackMania;
|
|||||||
|
|
||||||
use ManiaControl\Callbacks\Structures\Common\CommonScoresStructure;
|
use ManiaControl\Callbacks\Structures\Common\CommonScoresStructure;
|
||||||
use ManiaControl\Callbacks\Structures\TrackMania\Models\PlayerScore;
|
use ManiaControl\Callbacks\Structures\TrackMania\Models\PlayerScore;
|
||||||
|
use ManiaControl\Callbacks\Structures\TrackMania\Models\TeamScore;
|
||||||
use ManiaControl\ManiaControl;
|
use ManiaControl\ManiaControl;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -26,16 +27,16 @@ class OnScoresStructure extends CommonScoresStructure {
|
|||||||
parent::__construct($maniaControl, $data);
|
parent::__construct($maniaControl, $data);
|
||||||
|
|
||||||
$jsonObj = $this->getPlainJsonObject();
|
$jsonObj = $this->getPlainJsonObject();
|
||||||
|
var_dump($jsonObj);
|
||||||
foreach ($jsonObj->players as $jsonPlayer) {
|
foreach ($jsonObj->players as $jsonPlayer) {
|
||||||
$player = $this->maniaControl->getPlayerManager()->getPlayer($jsonPlayer->login);
|
$player = $this->maniaControl->getPlayerManager()->getPlayer($jsonPlayer->login);
|
||||||
if ($player) {
|
if ($player) {
|
||||||
$playerScore = new PlayerScore();
|
$playerScore = new PlayerScore();
|
||||||
$playerScore->setPlayer($this->maniaControl->getPlayerManager()->getPlayer($jsonPlayer->login));
|
$playerScore->setPlayer($this->maniaControl->getPlayerManager()->getPlayer($jsonPlayer->login));
|
||||||
$playerScore->setRank($jsonPlayer->rank);
|
$playerScore->setRank($jsonPlayer->rank);
|
||||||
$playerScore->setRoundPoints($jsonPlayer->roundpoints);
|
|
||||||
$playerScore->setMapPoints($jsonPlayer->mappoints);
|
$playerScore->setMapPoints($jsonPlayer->mappoints);
|
||||||
$playerScore->setMatchPoints($jsonPlayer->matchpoints);
|
$playerScore->setMatchPoints($jsonPlayer->matchpoints);
|
||||||
|
$playerScore->setRoundPoints($jsonPlayer->roundpoints);
|
||||||
$playerScore->setBestRaceTime($jsonPlayer->bestracetime);
|
$playerScore->setBestRaceTime($jsonPlayer->bestracetime);
|
||||||
$playerScore->setBestLapTime($jsonPlayer->bestlaptime);
|
$playerScore->setBestLapTime($jsonPlayer->bestlaptime);
|
||||||
$playerScore->setStuntScore($jsonPlayer->stuntsscore);
|
$playerScore->setStuntScore($jsonPlayer->stuntsscore);
|
||||||
|
@ -55,9 +55,12 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener, Timer
|
|||||||
const ACTION_REVOKE_RIGHTS = 'PlayerList.RevokeRights';
|
const ACTION_REVOKE_RIGHTS = 'PlayerList.RevokeRights';
|
||||||
const ACTION_OPEN_PLAYER_DETAILED = 'PlayerList.OpenPlayerDetailed';
|
const ACTION_OPEN_PLAYER_DETAILED = 'PlayerList.OpenPlayerDetailed';
|
||||||
const ACTION_SPECTATE_PLAYER = 'PlayerList.SpectatePlayer';
|
const ACTION_SPECTATE_PLAYER = 'PlayerList.SpectatePlayer';
|
||||||
|
const ACTION_PAGING_CHUNKS = 'PlayerList.PagingChunks';
|
||||||
|
const CACHE_CURRENT_PAGE = 'PlayerList.CurrentPage';
|
||||||
const DEFAULT_CUSTOM_VOTE_PLUGIN = 'MCTeam\CustomVotesPlugin';
|
const DEFAULT_CUSTOM_VOTE_PLUGIN = 'MCTeam\CustomVotesPlugin';
|
||||||
const SHOWN_MAIN_WINDOW = -1;
|
const SHOWN_MAIN_WINDOW = -1;
|
||||||
const MAX_PLAYERS_PER_PAGE = 15;
|
const MAX_PLAYERS_PER_PAGE = 15;
|
||||||
|
const MAX_PAGES_PER_CHUNK = 2;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Private properties
|
* Private properties
|
||||||
@ -135,18 +138,33 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener, Timer
|
|||||||
*
|
*
|
||||||
* @param Player $player
|
* @param Player $player
|
||||||
*/
|
*/
|
||||||
public function showPlayerList(Player $player) {
|
public function showPlayerList(Player $player, $pageIndex = -1) {
|
||||||
$width = $this->maniaControl->getManialinkManager()->getStyleManager()->getListWidgetsWidth();
|
$width = $this->maniaControl->getManialinkManager()->getStyleManager()->getListWidgetsWidth();
|
||||||
$height = $this->maniaControl->getManialinkManager()->getStyleManager()->getListWidgetsHeight();
|
$height = $this->maniaControl->getManialinkManager()->getStyleManager()->getListWidgetsHeight();
|
||||||
|
|
||||||
// get PlayerList
|
// get PlayerList
|
||||||
$players = $this->maniaControl->getPlayerManager()->getPlayers();
|
$players = $this->maniaControl->getPlayerManager()->getPlayers();
|
||||||
|
|
||||||
|
if ($pageIndex < 0) {
|
||||||
|
$pageIndex = (int) $player->getCache($this, self::CACHE_CURRENT_PAGE);
|
||||||
|
}
|
||||||
|
$player->setCache($this, self::CACHE_CURRENT_PAGE, $pageIndex);
|
||||||
|
|
||||||
|
$totalPlayersCount = count($players);
|
||||||
|
$chunkIndex = $this->getChunkIndexFromPageNumber($pageIndex, $totalPlayersCount);
|
||||||
|
$playerBeginIndex = $this->getChunkStatsBeginIndex($chunkIndex);
|
||||||
|
|
||||||
|
$pagesCount = ceil($totalPlayersCount / self::MAX_PLAYERS_PER_PAGE);
|
||||||
|
|
||||||
//create manialink
|
//create manialink
|
||||||
$maniaLink = new ManiaLink(ManialinkManager::MAIN_MLID);
|
$maniaLink = new ManiaLink(ManialinkManager::MAIN_MLID);
|
||||||
$script = $maniaLink->getScript();
|
$script = $maniaLink->getScript();
|
||||||
$paging = new Paging();
|
$paging = new Paging();
|
||||||
$script->addFeature($paging);
|
$script->addFeature($paging);
|
||||||
|
$paging->setCustomMaxPageNumber($pagesCount);
|
||||||
|
$paging->setChunkActionAppendsPageNumber(true);
|
||||||
|
$paging->setChunkActions(self::ACTION_PAGING_CHUNKS);
|
||||||
|
$paging->setStartPageNumber($pageIndex + 1);
|
||||||
|
|
||||||
// Main frame
|
// Main frame
|
||||||
$frame = $this->maniaControl->getManialinkManager()->getStyleManager()->getDefaultListFrame($script, $paging);
|
$frame = $this->maniaControl->getManialinkManager()->getStyleManager()->getDefaultListFrame($script, $paging);
|
||||||
@ -179,16 +197,22 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener, Timer
|
|||||||
$labelLine->render();
|
$labelLine->render();
|
||||||
|
|
||||||
|
|
||||||
$index = 1;
|
$index = 1;
|
||||||
$posY = $height / 2 - 10;
|
$posY = $height / 2 - 10;
|
||||||
$pageFrame = null;
|
$pageFrame = null;
|
||||||
|
$playerIndex = 1 + $playerBeginIndex;
|
||||||
|
|
||||||
|
//Slice Array to chunk length
|
||||||
|
$players = array_slice($players, $playerBeginIndex, self::MAX_PAGES_PER_CHUNK * self::MAX_PLAYERS_PER_PAGE, true);
|
||||||
|
$pageNumber = 1 + $chunkIndex * self::MAX_PAGES_PER_CHUNK;
|
||||||
|
|
||||||
foreach ($players as $listPlayer) {
|
foreach ($players as $listPlayer) {
|
||||||
if ($index % self::MAX_PLAYERS_PER_PAGE === 1) {
|
if ($index % self::MAX_PLAYERS_PER_PAGE === 1) {
|
||||||
$pageFrame = new Frame();
|
$pageFrame = new Frame();
|
||||||
$frame->addChild($pageFrame);
|
$frame->addChild($pageFrame);
|
||||||
|
|
||||||
$paging->addPageControl($pageFrame);
|
$paging->addPageControl($pageFrame, $pageNumber);
|
||||||
|
$pageNumber++;
|
||||||
$posY = $height / 2 - 10;
|
$posY = $height / 2 - 10;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -205,7 +229,7 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener, Timer
|
|||||||
}
|
}
|
||||||
$labelLine = new LabelLine($playerFrame);
|
$labelLine = new LabelLine($playerFrame);
|
||||||
|
|
||||||
$labelLine->addLabelEntryText($index, $posX + 5, 13);
|
$labelLine->addLabelEntryText($playerIndex, $posX + 5, 13);
|
||||||
$labelLine->addLabelEntryText($listPlayer->nickname, $posX + 18, 43);
|
$labelLine->addLabelEntryText($listPlayer->nickname, $posX + 18, 43);
|
||||||
$labelLine->addLabelEntryText($listPlayer->login, $posX + 70, 26);
|
$labelLine->addLabelEntryText($listPlayer->login, $posX + 70, 26);
|
||||||
$labelLine->addLabelEntryText($path, $posX + 101, 27);
|
$labelLine->addLabelEntryText($path, $posX + 101, 27);
|
||||||
@ -404,6 +428,7 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener, Timer
|
|||||||
|
|
||||||
$posY -= 4;
|
$posY -= 4;
|
||||||
$index++;
|
$index++;
|
||||||
|
$playerIndex++;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Show advanced window
|
// Show advanced window
|
||||||
@ -616,6 +641,30 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener, Timer
|
|||||||
return $frame;
|
return $frame;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the Chunk Index with the given Page Index
|
||||||
|
*
|
||||||
|
* @param int $pageIndex
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
private function getChunkIndexFromPageNumber($pageIndex, $totalPlayersCount) {
|
||||||
|
$pagesCount = ceil($totalPlayersCount / self::MAX_PLAYERS_PER_PAGE);
|
||||||
|
if ($pageIndex > $pagesCount - 1) {
|
||||||
|
$pageIndex = $pagesCount - 1;
|
||||||
|
}
|
||||||
|
return floor($pageIndex / self::MAX_PAGES_PER_CHUNK);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Calculate the First Player Index to show for the given Chunk
|
||||||
|
*
|
||||||
|
* @param int $chunkIndex
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
private function getChunkStatsBeginIndex($chunkIndex) {
|
||||||
|
return $chunkIndex * self::MAX_PAGES_PER_CHUNK * self::MAX_PLAYERS_PER_PAGE;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called on ManialinkPageAnswer
|
* Called on ManialinkPageAnswer
|
||||||
*
|
*
|
||||||
@ -624,119 +673,127 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener, Timer
|
|||||||
public function handleManialinkPageAnswer(array $callback) {
|
public function handleManialinkPageAnswer(array $callback) {
|
||||||
$actionId = $callback[1][2];
|
$actionId = $callback[1][2];
|
||||||
$actionArray = explode('.', $actionId, 3);
|
$actionArray = explode('.', $actionId, 3);
|
||||||
if (count($actionArray) <= 2) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$action = $actionArray[0] . '.' . $actionArray[1];
|
$action = $actionArray[0] . '.' . $actionArray[1];
|
||||||
$adminLogin = $callback[1][1];
|
if (count($actionArray) > 2) {
|
||||||
$targetLogin = $actionArray[2];
|
|
||||||
|
|
||||||
switch ($action) {
|
$adminLogin = $callback[1][1];
|
||||||
case self::ACTION_SPECTATE_PLAYER:
|
$targetLogin = $actionArray[2];
|
||||||
try {
|
|
||||||
$this->maniaControl->getClient()->forceSpectator($adminLogin, PlayerActions::SPECTATOR_BUT_KEEP_SELECTABLE);
|
|
||||||
$this->maniaControl->getClient()->forceSpectatorTarget($adminLogin, $targetLogin, 1);
|
|
||||||
} catch (PlayerStateException $e) {
|
|
||||||
} catch (UnknownPlayerException $e) {
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case self::ACTION_OPEN_PLAYER_DETAILED:
|
|
||||||
$player = $this->maniaControl->getPlayerManager()->getPlayer($adminLogin);
|
|
||||||
$this->maniaControl->getPlayerManager()->getPlayerDetailed()->showPlayerDetailed($player, $targetLogin);
|
|
||||||
unset($this->playersListShown[$player->login]);
|
|
||||||
break;
|
|
||||||
case self::ACTION_FORCE_BLUE:
|
|
||||||
$this->maniaControl->getPlayerManager()->getPlayerActions()->forcePlayerToTeam($adminLogin, $targetLogin, PlayerActions::TEAM_BLUE);
|
|
||||||
break;
|
|
||||||
case self::ACTION_FORCE_RED:
|
|
||||||
$this->maniaControl->getPlayerManager()->getPlayerActions()->forcePlayerToTeam($adminLogin, $targetLogin, PlayerActions::TEAM_RED);
|
|
||||||
break;
|
|
||||||
case self::ACTION_FORCE_SPEC:
|
|
||||||
$this->maniaControl->getPlayerManager()->getPlayerActions()->forcePlayerToSpectator($adminLogin, $targetLogin, PlayerActions::SPECTATOR_BUT_KEEP_SELECTABLE);
|
|
||||||
break;
|
|
||||||
case self::ACTION_FORCE_PLAY:
|
|
||||||
$this->maniaControl->getPlayerManager()->getPlayerActions()->forcePlayerToPlay($adminLogin, $targetLogin);
|
|
||||||
break;
|
|
||||||
case self::ACTION_MUTE_PLAYER:
|
|
||||||
$this->maniaControl->getPlayerManager()->getPlayerActions()->mutePlayer($adminLogin, $targetLogin);
|
|
||||||
$this->showPlayerList($this->maniaControl->getPlayerManager()->getPlayer($adminLogin));
|
|
||||||
break;
|
|
||||||
case self::ACTION_UNMUTE_PLAYER:
|
|
||||||
$this->maniaControl->getPlayerManager()->getPlayerActions()->unMutePlayer($adminLogin, $targetLogin);
|
|
||||||
$this->showPlayerList($this->maniaControl->getPlayerManager()->getPlayer($adminLogin));
|
|
||||||
break;
|
|
||||||
case self::ACTION_WARN_PLAYER:
|
|
||||||
$this->maniaControl->getPlayerManager()->getPlayerActions()->warnPlayer($adminLogin, $targetLogin);
|
|
||||||
break;
|
|
||||||
case self::ACTION_KICK_PLAYER:
|
|
||||||
$this->maniaControl->getPlayerManager()->getPlayerActions()->kickPlayer($adminLogin, $targetLogin);
|
|
||||||
break;
|
|
||||||
case self::ACTION_BAN_PLAYER:
|
|
||||||
$this->maniaControl->getPlayerManager()->getPlayerActions()->banPlayer($adminLogin, $targetLogin);
|
|
||||||
break;
|
|
||||||
case self::ACTION_PLAYER_ADV:
|
|
||||||
$admin = $this->maniaControl->getPlayerManager()->getPlayer($adminLogin);
|
|
||||||
$this->advancedPlayerWidget($admin, $targetLogin);
|
|
||||||
break;
|
|
||||||
case self::ACTION_ADD_AS_MASTER:
|
|
||||||
$this->maniaControl->getPlayerManager()->getPlayerActions()->grandAuthLevel($adminLogin, $targetLogin, AuthenticationManager::AUTH_LEVEL_SUPERADMIN);
|
|
||||||
break;
|
|
||||||
case self::ACTION_ADD_AS_ADMIN:
|
|
||||||
$this->maniaControl->getPlayerManager()->getPlayerActions()->grandAuthLevel($adminLogin, $targetLogin, AuthenticationManager::AUTH_LEVEL_ADMIN);
|
|
||||||
break;
|
|
||||||
case self::ACTION_ADD_AS_MOD:
|
|
||||||
$this->maniaControl->getPlayerManager()->getPlayerActions()->grandAuthLevel($adminLogin, $targetLogin, AuthenticationManager::AUTH_LEVEL_MODERATOR);
|
|
||||||
break;
|
|
||||||
case self::ACTION_REVOKE_RIGHTS:
|
|
||||||
$this->maniaControl->getPlayerManager()->getPlayerActions()->revokeAuthLevel($adminLogin, $targetLogin);
|
|
||||||
break;
|
|
||||||
case self::ACTION_FORCE_SPEC_VOTE:
|
|
||||||
/** @var $votesPlugin CustomVotesPlugin */
|
|
||||||
$votesPlugin = $this->maniaControl->getPluginManager()->getPlugin(self::DEFAULT_CUSTOM_VOTE_PLUGIN);
|
|
||||||
|
|
||||||
$admin = $this->maniaControl->getPlayerManager()->getPlayer($adminLogin);
|
|
||||||
$target = $this->maniaControl->getPlayerManager()->getPlayer($targetLogin);
|
|
||||||
|
|
||||||
$startMessage = $admin->getEscapedNickname() . '$s started a vote to force $<' . $target->nickname . '$> into spectator!';
|
|
||||||
|
|
||||||
$votesPlugin->defineVote('forcespec', 'Force ' . $target->getEscapedNickname() . ' Spec', true, $startMessage);
|
|
||||||
|
|
||||||
$votesPlugin->startVote($admin, 'forcespec', function ($result) use (&$votesPlugin, &$target) {
|
|
||||||
$this->maniaControl->getChat()->sendInformation('$sVote successful -> Player ' . $target->getEscapedNickname() . ' forced to Spectator!');
|
|
||||||
$votesPlugin->undefineVote('forcespec');
|
|
||||||
|
|
||||||
|
switch ($action) {
|
||||||
|
case self::ACTION_SPECTATE_PLAYER:
|
||||||
try {
|
try {
|
||||||
$this->maniaControl->getClient()->forceSpectator($target->login, PlayerActions::SPECTATOR_BUT_KEEP_SELECTABLE);
|
$this->maniaControl->getClient()->forceSpectator($adminLogin, PlayerActions::SPECTATOR_BUT_KEEP_SELECTABLE);
|
||||||
$this->maniaControl->getClient()->spectatorReleasePlayerSlot($target->login);
|
$this->maniaControl->getClient()->forceSpectatorTarget($adminLogin, $targetLogin, 1);
|
||||||
} catch (PlayerStateException $e) {
|
} catch (PlayerStateException $e) {
|
||||||
} catch (UnknownPlayerException $e) {
|
} catch (UnknownPlayerException $e) {
|
||||||
}
|
}
|
||||||
});
|
break;
|
||||||
break;
|
case self::ACTION_OPEN_PLAYER_DETAILED:
|
||||||
case self::ACTION_KICK_PLAYER_VOTE:
|
$player = $this->maniaControl->getPlayerManager()->getPlayer($adminLogin);
|
||||||
/** @var $votesPlugin CustomVotesPlugin */
|
$this->maniaControl->getPlayerManager()->getPlayerDetailed()->showPlayerDetailed($player, $targetLogin);
|
||||||
$votesPlugin = $this->maniaControl->getPluginManager()->getPlugin(self::DEFAULT_CUSTOM_VOTE_PLUGIN);
|
unset($this->playersListShown[$player->login]);
|
||||||
|
break;
|
||||||
|
case self::ACTION_FORCE_BLUE:
|
||||||
|
$this->maniaControl->getPlayerManager()->getPlayerActions()->forcePlayerToTeam($adminLogin, $targetLogin, PlayerActions::TEAM_BLUE);
|
||||||
|
break;
|
||||||
|
case self::ACTION_FORCE_RED:
|
||||||
|
$this->maniaControl->getPlayerManager()->getPlayerActions()->forcePlayerToTeam($adminLogin, $targetLogin, PlayerActions::TEAM_RED);
|
||||||
|
break;
|
||||||
|
case self::ACTION_FORCE_SPEC:
|
||||||
|
$this->maniaControl->getPlayerManager()->getPlayerActions()->forcePlayerToSpectator($adminLogin, $targetLogin, PlayerActions::SPECTATOR_BUT_KEEP_SELECTABLE);
|
||||||
|
break;
|
||||||
|
case self::ACTION_FORCE_PLAY:
|
||||||
|
$this->maniaControl->getPlayerManager()->getPlayerActions()->forcePlayerToPlay($adminLogin, $targetLogin);
|
||||||
|
break;
|
||||||
|
case self::ACTION_MUTE_PLAYER:
|
||||||
|
$this->maniaControl->getPlayerManager()->getPlayerActions()->mutePlayer($adminLogin, $targetLogin);
|
||||||
|
$this->showPlayerList($this->maniaControl->getPlayerManager()->getPlayer($adminLogin));
|
||||||
|
break;
|
||||||
|
case self::ACTION_UNMUTE_PLAYER:
|
||||||
|
$this->maniaControl->getPlayerManager()->getPlayerActions()->unMutePlayer($adminLogin, $targetLogin);
|
||||||
|
$this->showPlayerList($this->maniaControl->getPlayerManager()->getPlayer($adminLogin));
|
||||||
|
break;
|
||||||
|
case self::ACTION_WARN_PLAYER:
|
||||||
|
$this->maniaControl->getPlayerManager()->getPlayerActions()->warnPlayer($adminLogin, $targetLogin);
|
||||||
|
break;
|
||||||
|
case self::ACTION_KICK_PLAYER:
|
||||||
|
$this->maniaControl->getPlayerManager()->getPlayerActions()->kickPlayer($adminLogin, $targetLogin);
|
||||||
|
break;
|
||||||
|
case self::ACTION_BAN_PLAYER:
|
||||||
|
$this->maniaControl->getPlayerManager()->getPlayerActions()->banPlayer($adminLogin, $targetLogin);
|
||||||
|
break;
|
||||||
|
case self::ACTION_PLAYER_ADV:
|
||||||
|
$admin = $this->maniaControl->getPlayerManager()->getPlayer($adminLogin);
|
||||||
|
$this->advancedPlayerWidget($admin, $targetLogin);
|
||||||
|
break;
|
||||||
|
case self::ACTION_ADD_AS_MASTER:
|
||||||
|
$this->maniaControl->getPlayerManager()->getPlayerActions()->grandAuthLevel($adminLogin, $targetLogin, AuthenticationManager::AUTH_LEVEL_SUPERADMIN);
|
||||||
|
break;
|
||||||
|
case self::ACTION_ADD_AS_ADMIN:
|
||||||
|
$this->maniaControl->getPlayerManager()->getPlayerActions()->grandAuthLevel($adminLogin, $targetLogin, AuthenticationManager::AUTH_LEVEL_ADMIN);
|
||||||
|
break;
|
||||||
|
case self::ACTION_ADD_AS_MOD:
|
||||||
|
$this->maniaControl->getPlayerManager()->getPlayerActions()->grandAuthLevel($adminLogin, $targetLogin, AuthenticationManager::AUTH_LEVEL_MODERATOR);
|
||||||
|
break;
|
||||||
|
case self::ACTION_REVOKE_RIGHTS:
|
||||||
|
$this->maniaControl->getPlayerManager()->getPlayerActions()->revokeAuthLevel($adminLogin, $targetLogin);
|
||||||
|
break;
|
||||||
|
case self::ACTION_FORCE_SPEC_VOTE:
|
||||||
|
/** @var $votesPlugin CustomVotesPlugin */
|
||||||
|
$votesPlugin = $this->maniaControl->getPluginManager()->getPlugin(self::DEFAULT_CUSTOM_VOTE_PLUGIN);
|
||||||
|
|
||||||
$admin = $this->maniaControl->getPlayerManager()->getPlayer($adminLogin);
|
$admin = $this->maniaControl->getPlayerManager()->getPlayer($adminLogin);
|
||||||
$target = $this->maniaControl->getPlayerManager()->getPlayer($targetLogin);
|
$target = $this->maniaControl->getPlayerManager()->getPlayer($targetLogin);
|
||||||
|
|
||||||
$startMessage = $admin->getEscapedNickname() . '$s started a vote to kick $<' . $target->nickname . '$>!';
|
$startMessage = $admin->getEscapedNickname() . '$s started a vote to force $<' . $target->nickname . '$> into spectator!';
|
||||||
|
|
||||||
|
$votesPlugin->defineVote('forcespec', 'Force ' . $target->getEscapedNickname() . ' Spec', true, $startMessage);
|
||||||
|
|
||||||
|
$votesPlugin->startVote($admin, 'forcespec', function ($result) use (&$votesPlugin, &$target) {
|
||||||
|
$this->maniaControl->getChat()->sendInformation('$sVote successful -> Player ' . $target->getEscapedNickname() . ' forced to Spectator!');
|
||||||
|
$votesPlugin->undefineVote('forcespec');
|
||||||
|
|
||||||
|
try {
|
||||||
|
$this->maniaControl->getClient()->forceSpectator($target->login, PlayerActions::SPECTATOR_BUT_KEEP_SELECTABLE);
|
||||||
|
$this->maniaControl->getClient()->spectatorReleasePlayerSlot($target->login);
|
||||||
|
} catch (PlayerStateException $e) {
|
||||||
|
} catch (UnknownPlayerException $e) {
|
||||||
|
}
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case self::ACTION_KICK_PLAYER_VOTE:
|
||||||
|
/** @var $votesPlugin CustomVotesPlugin */
|
||||||
|
$votesPlugin = $this->maniaControl->getPluginManager()->getPlugin(self::DEFAULT_CUSTOM_VOTE_PLUGIN);
|
||||||
|
|
||||||
|
$admin = $this->maniaControl->getPlayerManager()->getPlayer($adminLogin);
|
||||||
|
$target = $this->maniaControl->getPlayerManager()->getPlayer($targetLogin);
|
||||||
|
|
||||||
|
$startMessage = $admin->getEscapedNickname() . '$s started a vote to kick $<' . $target->nickname . '$>!';
|
||||||
|
|
||||||
|
|
||||||
$votesPlugin->defineVote('kick', 'Kick ' . $target->getEscapedNickname(), true, $startMessage);
|
$votesPlugin->defineVote('kick', 'Kick ' . $target->getEscapedNickname(), true, $startMessage);
|
||||||
|
|
||||||
$votesPlugin->startVote($admin, 'kick', function ($result) use (&$votesPlugin, &$target) {
|
$votesPlugin->startVote($admin, 'kick', function ($result) use (&$votesPlugin, &$target) {
|
||||||
$this->maniaControl->getChat()->sendInformation('$sVote successful -> ' . $target->getEscapedNickname() . ' got Kicked!');
|
$this->maniaControl->getChat()->sendInformation('$sVote successful -> ' . $target->getEscapedNickname() . ' got Kicked!');
|
||||||
$votesPlugin->undefineVote('kick');
|
$votesPlugin->undefineVote('kick');
|
||||||
|
|
||||||
|
$message = '$39F You got kicked due to a Public Vote!$z ';
|
||||||
|
try {
|
||||||
|
$this->maniaControl->getClient()->kick($target->login, $message);
|
||||||
|
} catch (UnknownPlayerException $e) {
|
||||||
|
}
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} else if (count($actionArray) == 2) {
|
||||||
|
$playerLogin = $callback[1][1];
|
||||||
|
$player = $this->maniaControl->getPlayerManager()->getPlayer($playerLogin);
|
||||||
|
if (substr($action, 0, strlen(self::ACTION_PAGING_CHUNKS)) === self::ACTION_PAGING_CHUNKS) {
|
||||||
|
// Paging chunks
|
||||||
|
$neededPage = (int) substr($action, strlen(self::ACTION_PAGING_CHUNKS));
|
||||||
|
$this->showPlayerList($player, $neededPage - 1);
|
||||||
|
}
|
||||||
|
|
||||||
$message = '$39F You got kicked due to a Public Vote!$z ';
|
|
||||||
try {
|
|
||||||
$this->maniaControl->getClient()->kick($target->login, $message);
|
|
||||||
} catch (UnknownPlayerException $e) {
|
|
||||||
}
|
|
||||||
});
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,7 +37,11 @@ class SimpleStatsList implements ManialinkPageAnswerListener, CallbackListener,
|
|||||||
*/
|
*/
|
||||||
const ACTION_OPEN_STATSLIST = 'SimpleStatsList.OpenStatsList';
|
const ACTION_OPEN_STATSLIST = 'SimpleStatsList.OpenStatsList';
|
||||||
const ACTION_SORT_STATS = 'SimpleStatsList.SortStats';
|
const ACTION_SORT_STATS = 'SimpleStatsList.SortStats';
|
||||||
|
const ACTION_PAGING_CHUNKS = 'SimpleStatsList.PagingChunk';
|
||||||
const MAX_PLAYERS_PER_PAGE = 15;
|
const MAX_PLAYERS_PER_PAGE = 15;
|
||||||
|
const MAX_PAGES_PER_CHUNK = 2;
|
||||||
|
const CACHE_CURRENT_PAGE = 'SimpleStatsList.CurrentPage';
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Private properties
|
* Private properties
|
||||||
@ -74,7 +78,7 @@ class SimpleStatsList implements ManialinkPageAnswerListener, CallbackListener,
|
|||||||
$itemQuad->setAction(self::ACTION_OPEN_STATSLIST);
|
$itemQuad->setAction(self::ACTION_OPEN_STATSLIST);
|
||||||
$this->maniaControl->getActionsMenu()->addMenuItem($itemQuad, true, 14, 'Open Statistics');
|
$this->maniaControl->getActionsMenu()->addMenuItem($itemQuad, true, 14, 'Open Statistics');
|
||||||
//TODO Chunking
|
//TODO Chunking
|
||||||
|
|
||||||
//TODO settings if a stat get shown
|
//TODO settings if a stat get shown
|
||||||
$this->registerStat(PlayerManager::STAT_SERVERTIME, 10, "ST", 20, StatisticManager::STAT_TYPE_TIME);
|
$this->registerStat(PlayerManager::STAT_SERVERTIME, 10, "ST", 20, StatisticManager::STAT_TYPE_TIME);
|
||||||
$this->registerStat(StatisticCollector::STAT_ARROW_HIT, 20, "H");
|
$this->registerStat(StatisticCollector::STAT_ARROW_HIT, 20, "H");
|
||||||
@ -123,13 +127,22 @@ class SimpleStatsList implements ManialinkPageAnswerListener, CallbackListener,
|
|||||||
* @param Player $player
|
* @param Player $player
|
||||||
* @param string $order
|
* @param string $order
|
||||||
*/
|
*/
|
||||||
public function showStatsList(Player $player, $order = PlayerManager::STAT_SERVERTIME) {
|
public function showStatsList(Player $player, $order = PlayerManager::STAT_SERVERTIME, $pageIndex = -1) {
|
||||||
$height = $this->maniaControl->getManialinkManager()->getStyleManager()->getListWidgetsHeight();
|
$height = $this->maniaControl->getManialinkManager()->getStyleManager()->getListWidgetsHeight();
|
||||||
$quadStyle = $this->maniaControl->getManialinkManager()->getStyleManager()->getDefaultMainWindowStyle();
|
$quadStyle = $this->maniaControl->getManialinkManager()->getStyleManager()->getDefaultMainWindowStyle();
|
||||||
$quadSubstyle = $this->maniaControl->getManialinkManager()->getStyleManager()->getDefaultMainWindowSubStyle();
|
$quadSubstyle = $this->maniaControl->getManialinkManager()->getStyleManager()->getDefaultMainWindowSubStyle();
|
||||||
|
|
||||||
|
if ($pageIndex < 0) {
|
||||||
|
$pageIndex = (int) $player->getCache($this, self::CACHE_CURRENT_PAGE);
|
||||||
|
}
|
||||||
|
$player->setCache($this, self::CACHE_CURRENT_PAGE, $pageIndex);
|
||||||
|
|
||||||
|
$totalPlayersCount = $this->maniaControl->getStatisticManager()->getTotalStatsPlayerCount(-1);
|
||||||
|
$chunkIndex = $this->getChunkIndexFromPageNumber($pageIndex, $totalPlayersCount);
|
||||||
|
$playerBeginIndex = $this->getChunkStatsBeginIndex($chunkIndex);
|
||||||
|
|
||||||
|
$pagesCount = ceil($totalPlayersCount / self::MAX_PLAYERS_PER_PAGE);
|
||||||
|
|
||||||
$order = StatisticCollector::STAT_ARROW_HIT;
|
|
||||||
$maniaLink = new ManiaLink(ManialinkManager::MAIN_MLID);
|
$maniaLink = new ManiaLink(ManialinkManager::MAIN_MLID);
|
||||||
$width = $this->statsWidth + 60;
|
$width = $this->statsWidth + 60;
|
||||||
//TODO handle size when stats are empty
|
//TODO handle size when stats are empty
|
||||||
@ -137,6 +150,10 @@ class SimpleStatsList implements ManialinkPageAnswerListener, CallbackListener,
|
|||||||
$script = $maniaLink->getScript();
|
$script = $maniaLink->getScript();
|
||||||
$paging = new Paging();
|
$paging = new Paging();
|
||||||
$script->addFeature($paging);
|
$script->addFeature($paging);
|
||||||
|
$paging->setCustomMaxPageNumber($pagesCount);
|
||||||
|
$paging->setChunkActionAppendsPageNumber(true);
|
||||||
|
$paging->setChunkActions(self::ACTION_PAGING_CHUNKS);
|
||||||
|
$paging->setStartPageNumber($pageIndex + 1);
|
||||||
|
|
||||||
// Main frame
|
// Main frame
|
||||||
$frame = new Frame();
|
$frame = new Frame();
|
||||||
@ -182,8 +199,9 @@ class SimpleStatsList implements ManialinkPageAnswerListener, CallbackListener,
|
|||||||
$posX = $xStart + 55;
|
$posX = $xStart + 55;
|
||||||
$statRankings = array();
|
$statRankings = array();
|
||||||
|
|
||||||
|
|
||||||
foreach ($this->statArray as $key => $stat) {
|
foreach ($this->statArray as $key => $stat) {
|
||||||
$ranking = $this->maniaControl->getStatisticManager()->getStatsRanking($stat["Name"]);
|
$ranking = $this->maniaControl->getStatisticManager()->getStatsRanking($stat["Name"], -1, -1, 20000);
|
||||||
if (!empty($ranking)) {
|
if (!empty($ranking)) {
|
||||||
$statRankings[$stat["Name"]] = $ranking;
|
$statRankings[$stat["Name"]] = $ranking;
|
||||||
|
|
||||||
@ -204,22 +222,26 @@ class SimpleStatsList implements ManialinkPageAnswerListener, CallbackListener,
|
|||||||
|
|
||||||
|
|
||||||
// define standard properties
|
// define standard properties
|
||||||
$index = 1;
|
$index = 1;
|
||||||
$posY -= 10;
|
$posY -= 10;
|
||||||
$pageFrame = null;
|
$pageFrame = null;
|
||||||
|
$playerIndex = 1 + $playerBeginIndex;
|
||||||
|
|
||||||
if (!isset($statRankings[$order])) {
|
if (!isset($statRankings[$order])) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Slice Array to chunk length
|
||||||
|
$statRankings[$order] = array_slice($statRankings{$order}, $playerBeginIndex, self::MAX_PAGES_PER_CHUNK * self::MAX_PLAYERS_PER_PAGE, true);
|
||||||
|
$pageNumber = 1 + $chunkIndex * self::MAX_PAGES_PER_CHUNK;
|
||||||
foreach ($statRankings[$order] as $playerId => $value) {
|
foreach ($statRankings[$order] as $playerId => $value) {
|
||||||
if ($index % self::MAX_PLAYERS_PER_PAGE === 1) {
|
if ($index % self::MAX_PLAYERS_PER_PAGE === 1) {
|
||||||
$pageFrame = new Frame();
|
$pageFrame = new Frame();
|
||||||
$frame->addChild($pageFrame);
|
$frame->addChild($pageFrame);
|
||||||
$pageFrame->setZ(1);
|
$pageFrame->setZ(1);
|
||||||
|
|
||||||
$paging->addPageControl($pageFrame);
|
$paging->addPageControl($pageFrame, $pageNumber);
|
||||||
|
$pageNumber++;
|
||||||
$posY = $height / 2 - 10;
|
$posY = $height / 2 - 10;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -264,7 +286,7 @@ class SimpleStatsList implements ManialinkPageAnswerListener, CallbackListener,
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$labelLine->addLabelEntryText($index, $xStart + 5, 9);
|
$labelLine->addLabelEntryText($playerIndex, $xStart + 5, 9);
|
||||||
$labelLine->addLabelEntryText($listPlayer->login, $xStart + 14, 41);
|
$labelLine->addLabelEntryText($listPlayer->login, $xStart + 14, 41);
|
||||||
$labelLine->render();
|
$labelLine->render();
|
||||||
|
|
||||||
@ -279,6 +301,7 @@ class SimpleStatsList implements ManialinkPageAnswerListener, CallbackListener,
|
|||||||
}
|
}
|
||||||
|
|
||||||
$index++;
|
$index++;
|
||||||
|
$playerIndex++;
|
||||||
$posY -= 4;
|
$posY -= 4;
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -301,6 +324,31 @@ class SimpleStatsList implements ManialinkPageAnswerListener, CallbackListener,
|
|||||||
$this->maniaControl->getManialinkManager()->displayWidget($maniaLink, $player, 'SimpleStatsList');
|
$this->maniaControl->getManialinkManager()->displayWidget($maniaLink, $player, 'SimpleStatsList');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the Chunk Index with the given Page Index
|
||||||
|
*
|
||||||
|
* @param int $pageIndex
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
private function getChunkIndexFromPageNumber($pageIndex, $totalPlayersCount) {
|
||||||
|
$pagesCount = ceil($totalPlayersCount / self::MAX_PLAYERS_PER_PAGE);
|
||||||
|
if ($pageIndex > $pagesCount - 1) {
|
||||||
|
$pageIndex = $pagesCount - 1;
|
||||||
|
}
|
||||||
|
return floor($pageIndex / self::MAX_PAGES_PER_CHUNK);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Calculate the First Player Index to show for the given Chunk
|
||||||
|
*
|
||||||
|
* @param int $chunkIndex
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
private function getChunkStatsBeginIndex($chunkIndex) {
|
||||||
|
return $chunkIndex * self::MAX_PAGES_PER_CHUNK * self::MAX_PLAYERS_PER_PAGE;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called on ManialinkPageAnswer
|
* Called on ManialinkPageAnswer
|
||||||
*
|
*
|
||||||
@ -309,18 +357,24 @@ class SimpleStatsList implements ManialinkPageAnswerListener, CallbackListener,
|
|||||||
public function handleManialinkPageAnswer(array $callback) {
|
public function handleManialinkPageAnswer(array $callback) {
|
||||||
$actionId = $callback[1][2];
|
$actionId = $callback[1][2];
|
||||||
$actionArray = explode('.', $actionId, 3);
|
$actionArray = explode('.', $actionId, 3);
|
||||||
if (count($actionArray) <= 2) {
|
if (count($actionArray) < 2) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$action = $actionArray[0] . '.' . $actionArray[1];
|
$action = $actionArray[0] . '.' . $actionArray[1];
|
||||||
|
|
||||||
|
$playerLogin = $callback[1][1];
|
||||||
|
$player = $this->maniaControl->getPlayerManager()->getPlayer($playerLogin);
|
||||||
switch ($action) {
|
switch ($action) {
|
||||||
case self::ACTION_SORT_STATS:
|
case self::ACTION_SORT_STATS:
|
||||||
$playerLogin = $callback[1][1];
|
|
||||||
$player = $this->maniaControl->getPlayerManager()->getPlayer($playerLogin);
|
|
||||||
$this->showStatsList($player, $actionArray[2]);
|
$this->showStatsList($player, $actionArray[2]);
|
||||||
break;
|
break;
|
||||||
|
default:
|
||||||
|
if (substr($actionId, 0, strlen(self::ACTION_PAGING_CHUNKS)) === self::ACTION_PAGING_CHUNKS) {
|
||||||
|
// Paging chunks
|
||||||
|
$neededPage = (int) substr($actionId, strlen(self::ACTION_PAGING_CHUNKS));
|
||||||
|
$this->showStatsList($player, PlayerManager::STAT_SERVERTIME, $neededPage - 1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,7 @@ use ManiaControl\General\UsageInformationAble;
|
|||||||
use ManiaControl\General\UsageInformationTrait;
|
use ManiaControl\General\UsageInformationTrait;
|
||||||
use ManiaControl\ManiaControl;
|
use ManiaControl\ManiaControl;
|
||||||
use ManiaControl\Players\Player;
|
use ManiaControl\Players\Player;
|
||||||
|
use ManiaControl\Players\PlayerManager;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Statistic Manager Class
|
* Statistic Manager Class
|
||||||
@ -347,6 +348,16 @@ class StatisticManager implements UsageInformationAble {
|
|||||||
return $statsArray;
|
return $statsArray;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the total amount of players who were on the server once
|
||||||
|
*
|
||||||
|
* @param $serverIndex
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function getTotalStatsPlayerCount($serverIndex){
|
||||||
|
return count($this->getStatsRanking(PlayerManager::STAT_SERVERTIME,$serverIndex,-1,20000));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the Stat Id
|
* Return the Stat Id
|
||||||
*
|
*
|
||||||
|
Loading…
Reference in New Issue
Block a user