removed 'application' folder to have everything in the root directory

This commit is contained in:
Steffen Schröder
2014-09-29 18:20:09 +02:00
parent 1569fd5488
commit 9642433363
284 changed files with 4 additions and 50 deletions

View File

@ -0,0 +1,450 @@
<?php
namespace MCTeam;
use ManiaControl\Commands\CommandListener;
use ManiaControl\ManiaControl;
use ManiaControl\Players\Player;
use ManiaControl\Plugins\Plugin;
use Maniaplanet\DedicatedServer\Xmlrpc\PlayerStateException;
use Maniaplanet\DedicatedServer\Xmlrpc\UnknownPlayerException;
/**
* ManiaControl Chat-Message Plugin
*
* @author ManiaControl Team <mail@maniacontrol.com>
* @copyright 2014 ManiaControl Team
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
*/
class ChatMessagePlugin implements CommandListener, Plugin {
/*
* Constants
*/
const PLUGIN_ID = 4;
const PLUGIN_VERSION = 0.1;
const PLUGIN_NAME = 'ChatMessagePlugin';
const PLUGIN_AUTHOR = 'kremsy';
const SETTING_AFK_FORCE_SPEC = 'AFK command forces spec';
/*
* Private properties
*/
/** @var ManiaControl $maniaControl */
private $maniaControl = null;
/**
* @see \ManiaControl\Plugins\Plugin::prepare()
*/
public static function prepare(ManiaControl $maniaControl) {
}
/**
* @see \ManiaControl\Plugins\Plugin::getId()
*/
public static function getId() {
return self::PLUGIN_ID;
}
/**
* @see \ManiaControl\Plugins\Plugin::getName()
*/
public static function getName() {
return self::PLUGIN_NAME;
}
/**
* @see \ManiaControl\Plugins\Plugin::getVersion()
*/
public static function getVersion() {
return self::PLUGIN_VERSION;
}
/**
* @see \ManiaControl\Plugins\Plugin::getAuthor()
*/
public static function getAuthor() {
return self::PLUGIN_AUTHOR;
}
/**
* @see \ManiaControl\Plugins\Plugin::getDescription()
*/
public static function getDescription() {
return "Plugin offers various Chat-Commands like /gg /hi /afk /rq...";
}
/**
* @see \ManiaControl\Plugins\Plugin::load()
*/
public function load(ManiaControl $maniaControl) {
$this->maniaControl = $maniaControl;
// Chat commands
$this->maniaControl->getCommandManager()->registerCommandListener('me', $this, 'chat_me', false, 'Can be used to express your feelings/ideas.');
$this->maniaControl->getCommandManager()->registerCommandListener('hi', $this, 'chat_hi', false, 'Writes an hello message to the chat.');
$this->maniaControl->getCommandManager()->registerCommandListener(array('bb', 'bye'), $this, 'chat_bye', false, 'Writes a goodbye message to the chat.');
$this->maniaControl->getCommandManager()->registerCommandListener('thx', $this, 'chat_thx', false, 'Writes a thanks message to the chat.');
$this->maniaControl->getCommandManager()->registerCommandListener('gg', $this, 'chat_gg', false, 'Writes a good game message to the chat.');
$this->maniaControl->getCommandManager()->registerCommandListener('gl', $this, 'chat_gl', false, 'Writes a good luck message to the chat.');
$this->maniaControl->getCommandManager()->registerCommandListener('hf', $this, 'chat_hf', false, 'Writes an have fun message to the chat.');
$this->maniaControl->getCommandManager()->registerCommandListener('glhf', $this, 'chat_glhf', false, 'Writes a good luck, have fun message to the chat.');
$this->maniaControl->getCommandManager()->registerCommandListener('ns', $this, 'chat_ns', false, 'Writes a nice shot message to the chat.');
$this->maniaControl->getCommandManager()->registerCommandListener('n1', $this, 'chat_n1', false, 'Writes a nice one message to the chat.');
$this->maniaControl->getCommandManager()->registerCommandListener('lol', $this, 'chat_lol', false, 'Writes a lol message to the chat.');
$this->maniaControl->getCommandManager()->registerCommandListener('lool', $this, 'chat_lool', false, 'Writes a lool message to the chat.');
$this->maniaControl->getCommandManager()->registerCommandListener('brb', $this, 'chat_brb', false, 'Writes a be right back message to the chat.');
$this->maniaControl->getCommandManager()->registerCommandListener('bgm', $this, 'chat_bgm', false, 'Writes a bad game for me message to the chat.');
$this->maniaControl->getCommandManager()->registerCommandListener('afk', $this, 'chat_afk', false, 'Writes an away from keyboard message to the chat.');
$this->maniaControl->getCommandManager()->registerCommandListener('wp', $this, 'chat_wp', false, 'Writes an well played message to the chat.');
$this->maniaControl->getCommandManager()->registerCommandListener(array('bm', 'bootme'), $this, 'chat_bootme', false, 'Gets you away from this server quickly!');
$this->maniaControl->getCommandManager()->registerCommandListener(array('rq', 'ragequit'), $this, 'chat_ragequit', false, 'Gets you away from this server in rage!');
//TODO block command listener for muted people
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_AFK_FORCE_SPEC, true);
return true;
}
/**
* @see \ManiaControl\Plugins\Plugin::unload()
*/
public function unload() {
}
/**
* Builds a chat message starting with the player's nickname, can used to express emotions
*
* @param array $chat
* @param Player $player
*/
public function chat_me(array $chat, Player $player) {
$message = substr($chat[1][2], 4);
$msg = '$<' . $player->nickname . '$>$s$i$fa0 ' . $message;
$this->sendChat($msg, $player);
}
/**
* Hello Message
*
* @param array $chat
* @param Player $player
*/
public function chat_hi(array $chat, Player $player) {
$command = explode(" ", $chat[1][2]);
if (isset($command[1])) {
$msg = '$ff0[$<' . $player->nickname . '$>] $ff0$iHello $z$<' . $this->getTarget($command[1]) . '$>$i!';
} else {
$msg = '$ff0[$<' . $player->nickname . '$>] $ff0$iHello All!';
}
$this->sendChat($msg, $player);
}
/**
* Bye Message
*
* @param array $chat
* @param Player $player
*/
public function chat_bye(array $chat, Player $player) {
$command = explode(" ", $chat[1][2]);
if (isset($command[1])) {
$msg = '$ff0[$<' . $player->nickname . '$>] $ff0$iBye $z$<' . $this->getTarget($command[1]) . '$>$i!';
} else {
$msg = '$ff0[$<' . $player->nickname . '$>] $ff0$iI have to go... Bye All!';
}
$this->sendChat($msg, $player);
}
/**
* Thx Message
*
* @param array $chat
* @param Player $player
*/
public function chat_thx(array $chat, Player $player) {
$command = explode(" ", $chat[1][2]);
if (isset($command[1])) {
$msg = '$ff0[$<' . $player->nickname . '$>] $ff0$iThanks $z$<' . $this->getTarget($command[1]) . '$>$i!';
} else {
$msg = '$ff0[$<' . $player->nickname . '$>] $ff0$iThanks All!';
}
$this->sendChat($msg, $player);
}
/**
* Good Game Message
*
* @param array $chat
* @param Player $player
*/
public function chat_gg(array $chat, Player $player) {
$command = explode(" ", $chat[1][2]);
if (isset($command[1])) {
$msg = '$ff0[' . $player->getEscapedNickname() . '] $ff0$iGood Game $z$<' . $this->getTarget($command[1]) . '$>$i!';
} else {
$msg = '$ff0[' . $player->getEscapedNickname() . '] $ff0$iGood Game All!';
}
$this->sendChat($msg, $player);
}
/**
* Good Luck Message
*
* @param array $chat
* @param Player $player
*/
public function chat_gl(array $chat, Player $player) {
$command = explode(" ", $chat[1][2]);
if (isset($command[1])) {
$msg = '$ff0[$<' . $player->nickname . '$>] $ff0$iGood Luck $z$<' . $this->getTarget($command[1]) . '$>$i!';
} else {
$msg = '$ff0[$<' . $player->nickname . '$>] $ff0$iGood Luck All!';
}
$this->sendChat($msg, $player);
}
/**
* Have Fun Message
*
* @param array $chat
* @param Player $player
*/
public function chat_hf(array $chat, Player $player) {
$command = explode(" ", $chat[1][2]);
if (isset($command[1])) {
$msg = '$ff0[' . $player->getEscapedNickname() . '] $ff0$iHave Fun $z$<' . $this->getTarget($command[1]) . '$>$i!';
} else {
$msg = '$ff0[' . $player->getEscapedNickname() . '] $ff0$iHave Fun All!';
}
$this->sendChat($msg, $player);
}
/**
* Good Luck and Have Fun Message
*
* @param array $chat
* @param Player $player
*/
public function chat_glhf(array $chat, Player $player) {
$command = explode(" ", $chat[1][2]);
if (isset($command[1])) {
$msg = '$ff0[$<' . $player->nickname . '$>] $ff0$iGood Luck and Have Fun $z$<' . $this->getTarget($command[1]) . '$>$i!';
} else {
$msg = '$ff0[$<' . $player->nickname . '$>] $ff0$iGood Luck and Have Fun All!';
}
$this->sendChat($msg, $player);
}
/**
* Nice Shot Message
*
* @param array $chat
* @param Player $player
*/
public function chat_ns(array $chat, Player $player) {
$command = explode(" ", $chat[1][2]);
if (isset($command[1])) {
$msg = '$ff0[$<' . $player->nickname . '$>] $ff0$iNice Shot $z$<' . $this->getTarget($command[1]) . '$>$i!';
} else {
$msg = '$ff0[$<' . $player->nickname . '$>] $ff0$iNice Shot!';
}
$this->sendChat($msg, $player);
}
/**
* Nice one Message
*
* @param array $chat
* @param Player $player
*/
public function chat_n1(array $chat, Player $player) {
$command = explode(" ", $chat[1][2]);
if (isset($command[1])) {
$msg = '$ff0[$<' . $player->nickname . '$>] $ff0$iNice One $z$<' . $this->getTarget($command[1]) . '$>$i!';
} else {
$msg = '$ff0[$<' . $player->nickname . '$>] $ff0$iNice One!';
}
$this->sendChat($msg, $player);
}
/**
* Well Played message
*
* @param array $chat
* @param Player $player
*/
public function chat_wp(array $chat, Player $player) {
$command = explode(" ", $chat[1][2]);
if (isset($command[1])) {
$msg = '$ff0[$<' . $player->nickname . '$>] $ff0$iWell Played $z$<' . $this->getTarget($command[1]) . '$>$i!';
} else {
$msg = '$ff0[$<' . $player->nickname . '$>] $ff0$iWell Played!';
}
$this->sendChat($msg, $player);
}
/**
* Lol! Message
*
* @param array $chat
* @param Player $player
*/
public function chat_lol(array $chat, Player $player) {
$msg = '$ff0[$<' . $player->nickname . '$>] $ff0$iLoL!';
$this->sendChat($msg, $player);
}
/**
* LooOOooL! Message
*
* @param array $chat
* @param Player $player
*/
public function chat_lool(array $chat, Player $player) {
$msg = '$ff0[$<' . $player->nickname . '$>] $ff0$iLooOOooL!';
$this->sendChat($msg, $player);
}
/**
* Be right back Message
*
* @param array $chat
* @param Player $player
*/
public function chat_brb(array $chat, Player $player) {
$msg = '$ff0[$<' . $player->nickname . '$>] $ff0$iBe Right Back!';
$this->sendChat($msg, $player);
}
/**
* Bad game for me Message
*
* @param array $chat
* @param Player $player
*/
public function chat_bgm(array $chat, Player $player) {
$msg = '$ff0[$<' . $player->nickname . '$>] $ff0$iBad Game for me :(';
$this->sendChat($msg, $player);
}
/**
* Leave the server with an Bootme Message
*
* @param array $chat
* @param Player $player
*/
public function chat_bootme(array $chat, Player $player) {
$msg = '$i$ff0 $<' . $player->nickname . '$>$s$39f chooses to boot back to the real world!';
$this->sendChat($msg, $player, true);
$message = '$39F Thanks for Playing, see you around!$z';
try {
$this->maniaControl->getClient()->kick($player->login, $message);
} catch (UnknownPlayerException $exception) {
$this->maniaControl->getChat()->sendException($exception, $player);
}
}
/**
* Leave the server with an Ragequit
*
* @param array $chat
* @param Player $player
*/
public function chat_ragequit(array $chat, Player $player) {
try {
$message = '$39F Thanks for Playing, please come back soon!$z ';
$this->maniaControl->getClient()->kick($player->login, $message);
$msg = '$i$ff0 $<' . $player->nickname . '$>$s$f00 said: "@"#!" and ragequitted!';
$this->sendChat($msg, $player, true);
} catch (UnknownPlayerException $e) {
$this->maniaControl->getChat()->sendError('Error occurred: ' . $e->getMessage(), $player);
}
}
/**
* Afk Message and force player to spec
*
* @param array $chat
* @param Player $player
*/
public function chat_afk(array $chat, Player $player) {
$msg = '$ff0[$<' . $player->nickname . '$>] $ff0$iAway From Keyboard!';
$this->sendChat($msg, $player);
if (!$this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_AFK_FORCE_SPEC)) {
return;
}
if ($player->isSpectator) {
return;
}
try {
// Force into spec
$this->maniaControl->getClient()->forceSpectator($player->login, 3);
// Free player slot
$this->maniaControl->getClient()->spectatorReleasePlayerSlot($player->login);
} catch (UnknownPlayerException $exception) {
$this->maniaControl->getChat()->sendException($exception, $player);
} catch (PlayerStateException $exception) {
}
}
/**
* Checks if a Player is in the PlayerList and returns the nickname if he is, can be called per login, pid or nickname or lj for
* (last joined)
*
* @param mixed $login
* @return mixed
*/
private function getTarget($login) {
$player = null;
foreach ($this->maniaControl->getPlayerManager()->getPlayers() as $player) {
if ($login == $player || $login == $player->login || $login == $player->pid || $login == $player->nickname) {
return $player->nickname;
}
}
if ($player && strtolower($login) === 'lj') {
return $player->nickname;
}
//returns the text given if nothing matches
return $login;
}
/**
* Checks if the Player is Muted and sends the Chat if he isnt
*
* @param $msg
* @param Player $player
* @param bool $prefix
*/
private function sendChat($msg, Player $player, $prefix = false) {
if (!$player->isMuted()) {
$this->maniaControl->getChat()->sendChat($msg, null, $prefix);
} else {
$this->maniaControl->getChat()->sendError("You can't use this command because you are muted!", $player);
}
}
}

View File

@ -0,0 +1,929 @@
<?php
namespace MCTeam;
use FML\Controls\Control;
use FML\Controls\Frame;
use FML\Controls\Gauge;
use FML\Controls\Label;
use FML\Controls\Labels\Label_Button;
use FML\Controls\Labels\Label_Text;
use FML\Controls\Quad;
use FML\Controls\Quads\Quad_BgsPlayerCard;
use FML\Controls\Quads\Quad_Icons128x32_1;
use FML\Controls\Quads\Quad_Icons64x64_1;
use FML\Controls\Quads\Quad_UIConstruction_Buttons;
use FML\ManiaLink;
use FML\Script\Features\KeyAction;
use ManiaControl\Callbacks\CallbackListener;
use ManiaControl\Callbacks\CallbackManager;
use ManiaControl\Callbacks\Callbacks;
use ManiaControl\Callbacks\TimerListener;
use ManiaControl\Commands\CommandListener;
use ManiaControl\ManiaControl;
use ManiaControl\Manialinks\ManialinkPageAnswerListener;
use ManiaControl\Players\Player;
use ManiaControl\Players\PlayerManager;
use ManiaControl\Plugins\Plugin;
use ManiaControl\Server\Commands;
use ManiaControl\Server\Server;
use ManiaControl\Utils\ColorUtil;
use Maniaplanet\DedicatedServer\Structures\VoteRatio;
use Maniaplanet\DedicatedServer\Xmlrpc\ChangeInProgressException;
use Maniaplanet\DedicatedServer\Xmlrpc\GameModeException;
/**
* ManiaControl Custom-Votes Plugin
*
* @author ManiaControl Team <mail@maniacontrol.com>
* @copyright 2014 ManiaControl Team
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
*/
class CustomVotesPlugin implements CommandListener, CallbackListener, ManialinkPageAnswerListener, TimerListener, Plugin {
/*
* Constants
*/
const PLUGIN_ID = 5;
const PLUGIN_VERSION = 0.1;
const PLUGIN_NAME = 'CustomVotesPlugin';
const PLUGIN_AUTHOR = 'kremsy';
const SETTING_VOTE_ICON_POSX = 'Vote-Icon-Position: X';
const SETTING_VOTE_ICON_POSY = 'Vote-Icon-Position: Y';
const SETTING_VOTE_ICON_WIDTH = 'Vote-Icon-Size: Width';
const SETTING_VOTE_ICON_HEIGHT = 'Vote-Icon-Size: Height';
const SETTING_WIDGET_POSX = 'Widget-Position: X';
const SETTING_WIDGET_POSY = 'Widget-Position: Y';
const SETTING_WIDGET_WIDTH = 'Widget-Size: Width';
const SETTING_WIDGET_HEIGHT = 'Widget-Size: Height';
const SETTING_VOTE_TIME = 'Voting Time';
const SETTING_DEFAULT_PLAYER_RATIO = 'Minimum Player Voters Ratio';
const SETTING_DEFAULT_RATIO = 'Default Success Ratio';
const SETTING_SPECTATOR_ALLOW_VOTE = 'Allow Spectators to vote';
const SETTING_SPECTATOR_ALLOW_START_VOTE = 'Allow Spectators to start a vote';
const MLID_WIDGET = 'CustomVotesPlugin.WidgetId';
const MLID_ICON = 'CustomVotesPlugin.IconWidgetId';
const ACTION_POSITIVE_VOTE = 'CustomVotesPlugin.PositiveVote';
const ACTION_NEGATIVE_VOTE = 'CustomVotesPlugin.NegativeVote';
const ACTION_START_VOTE = 'CustomVotesPlugin.StartVote.';
const CB_CUSTOM_VOTE_FINISHED = 'CustomVotesPlugin.CustomVoteFinished';
/*
* Private properties
*/
/** @var ManiaControl $maniaControl */
private $maniaControl = null;
private $voteCommands = array();
private $voteMenuItems = array();
/** @var CurrentVote $currentVote */
private $currentVote = null;
/**
* @see \ManiaControl\Plugins\Plugin::prepare()
*/
public static function prepare(ManiaControl $maniaControl) {
}
/**
* @see \ManiaControl\Plugins\Plugin::getId()
*/
public static function getId() {
return self::PLUGIN_ID;
}
/**
* @see \ManiaControl\Plugins\Plugin::getName()
*/
public static function getName() {
return self::PLUGIN_NAME;
}
/**
* @see \ManiaControl\Plugins\Plugin::getVersion()
*/
public static function getVersion() {
return self::PLUGIN_VERSION;
}
/**
* @see \ManiaControl\Plugins\Plugin::getAuthor()
*/
public static function getAuthor() {
return self::PLUGIN_AUTHOR;
}
/**
* @see \ManiaControl\Plugins\Plugin::getDescription()
*/
public static function getDescription() {
return 'Plugin offers your Custom Votes like Restart, Skip, Balance...';
}
/**
* @see \ManiaControl\Plugins\Plugin::load()
*/
public function load(ManiaControl $maniaControl) {
$this->maniaControl = $maniaControl;
// Commands
$this->maniaControl->getCommandManager()->registerCommandListener('vote', $this, 'chat_vote', false, 'Starts a new vote.');
// Callbacks
$this->maniaControl->getManialinkManager()->registerManialinkPageAnswerListener(self::ACTION_POSITIVE_VOTE, $this, 'handlePositiveVote');
$this->maniaControl->getManialinkManager()->registerManialinkPageAnswerListener(self::ACTION_NEGATIVE_VOTE, $this, 'handleNegativeVote');
$this->maniaControl->getTimerManager()->registerTimerListening($this, 'handle1Second', 1000);
$this->maniaControl->getCallbackManager()->registerCallbackListener(Commands::CB_VOTE_CANCELLED, $this, 'handleVoteCancelled');
$this->maniaControl->getCallbackManager()->registerCallbackListener(CallbackManager::CB_MP_PLAYERMANIALINKPAGEANSWER, $this, 'handleManialinkPageAnswer');
$this->maniaControl->getCallbackManager()->registerCallbackListener(self::CB_CUSTOM_VOTE_FINISHED, $this, 'handleVoteFinished');
$this->maniaControl->getCallbackManager()->registerCallbackListener(PlayerManager::CB_PLAYERCONNECT, $this, 'handlePlayerConnect');
$this->maniaControl->getCallbackManager()->registerCallbackListener(Server::CB_TEAM_MODE_CHANGED, $this, 'constructMenu');
// Settings
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_VOTE_ICON_POSX, 156.);
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_VOTE_ICON_POSY, -38.6);
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_VOTE_ICON_WIDTH, 6);
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_VOTE_ICON_HEIGHT, 6);
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_WIDGET_POSX, -80); //160 -15
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_WIDGET_POSY, 80); //-15
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_WIDGET_WIDTH, 50); //30
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_WIDGET_HEIGHT, 20); //25
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_DEFAULT_RATIO, 0.75);
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_DEFAULT_PLAYER_RATIO, 0.65);
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_SPECTATOR_ALLOW_VOTE, false);
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_SPECTATOR_ALLOW_START_VOTE, true);
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_VOTE_TIME, 40);
//Define Votes
$this->defineVote("teambalance", "Vote for Team Balance");
$this->defineVote("skipmap", "Vote for Skip Map")->setStopCallback(Callbacks::ENDMAP);
$this->defineVote("nextmap", "Vote for Skip Map")->setStopCallback(Callbacks::ENDMAP);
$this->defineVote("skip", "Vote for Skip Map")->setStopCallback(Callbacks::ENDMAP);
$this->defineVote("restartmap", "Vote for Restart Map")->setStopCallback(Callbacks::ENDMAP);
$this->defineVote("restart", "Vote for Restart Map")->setStopCallback(Callbacks::ENDMAP);
$this->defineVote("pausegame", "Vote for Pause Game");
$this->defineVote("replay", "Vote to replay current map");
foreach ($this->voteCommands as $name => $voteCommand) {
$this->maniaControl->getCommandManager()->registerCommandListener($name, $this, 'handleChatVote', false, $voteCommand->name);
}
/* Disable Standard Votes */
$ratioArray[] = new VoteRatio(VoteRatio::COMMAND_BAN, -1.);
$ratioArray[] = new VoteRatio(VoteRatio::COMMAND_KICK, -1.);
$ratioArray[] = new VoteRatio(VoteRatio::COMMAND_RESTART_MAP, -1.);
$ratioArray[] = new VoteRatio(VoteRatio::COMMAND_TEAM_BALANCE, -1.);
$ratioArray[] = new VoteRatio(VoteRatio::COMMAND_NEXT_MAP, -1.);
$this->maniaControl->getClient()->setCallVoteRatios($ratioArray, false);
$this->constructMenu();
return true;
}
/**
* Define a Vote
*
* @param int $voteIndex
* @param string $voteName
* @param bool $idBased
* @param string $startText
* @param float $neededRatio
* @return \MCTeam\VoteCommand
*/
public function defineVote($voteIndex, $voteName, $idBased = false, $startText = '', $neededRatio = -1) {
if ($neededRatio < 0) {
$neededRatio = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_DEFAULT_RATIO);
}
$voteCommand = new VoteCommand($voteIndex, $voteName, $idBased, $neededRatio);
$voteCommand->startText = $startText;
$this->voteCommands[$voteIndex] = $voteCommand;
return $voteCommand;
}
/**
* Handle ManiaControl OnInit callback
*
* @internal param array $callback
*/
public function constructMenu() {
// Menu RestartMap
$itemQuad = new Quad_UIConstruction_Buttons();
$itemQuad->setSubStyle($itemQuad::SUBSTYLE_Reload);
$itemQuad->setAction(self::ACTION_START_VOTE . 'restartmap');
$this->addVoteMenuItem($itemQuad, 5, 'Vote for Restart-Map');
//Check if Pause exists in current GameMode
try {
$scriptInfos = $this->maniaControl->getClient()->getModeScriptInfo();
$pauseExists = false;
foreach ($scriptInfos->commandDescs as $param) {
if ($param->name === "Command_ForceWarmUp") {
$pauseExists = true;
break;
}
}
// Menu Pause
if ($pauseExists) {
$itemQuad = new Quad_Icons128x32_1();
$itemQuad->setSubStyle($itemQuad::SUBSTYLE_ManiaLinkSwitch);
$itemQuad->setAction(self::ACTION_START_VOTE . 'pausegame');
$this->addVoteMenuItem($itemQuad, 10, 'Vote for a pause of Current Game');
}
} catch (GameModeException $e) {
}
//Menu SkipMap
$itemQuad = new Quad_Icons64x64_1();
$itemQuad->setSubStyle($itemQuad::SUBSTYLE_ArrowFastNext);
$itemQuad->setAction(self::ACTION_START_VOTE . 'skipmap');
$this->addVoteMenuItem($itemQuad, 15, 'Vote for a Map Skip');
if ($this->maniaControl->getServer()->isTeamMode()
) {
//Menu TeamBalance
$itemQuad = new Quad_Icons128x32_1();
$itemQuad->setSubStyle($itemQuad::SUBSTYLE_RT_Team);
$itemQuad->setAction(self::ACTION_START_VOTE . 'teambalance');
$this->addVoteMenuItem($itemQuad, 20, 'Vote for Team-Balance');
}
//Show the Menu's icon
$this->showIcon();
}
/**
* Add a new Vote Menu Item
*
* @param Control $control
* @param int $order
* @param string $description
*/
public function addVoteMenuItem(Control $control, $order = 0, $description = null) {
if (!isset($this->voteMenuItems[$order])) {
$this->voteMenuItems[$order] = array();
array_push($this->voteMenuItems[$order], array($control, $description));
krsort($this->voteMenuItems);
}
}
/**
* Shows the Icon Widget
*
* @param bool $login
*/
private function showIcon($login = false) {
$posX = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_VOTE_ICON_POSX);
$posY = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_VOTE_ICON_POSY);
$width = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_VOTE_ICON_WIDTH);
$height = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_VOTE_ICON_HEIGHT);
$shootManiaOffset = $this->maniaControl->getManialinkManager()->getStyleManager()->getDefaultIconOffsetSM();
$quadStyle = $this->maniaControl->getManialinkManager()->getStyleManager()->getDefaultQuadStyle();
$quadSubstyle = $this->maniaControl->getManialinkManager()->getStyleManager()->getDefaultQuadSubstyle();
$itemMarginFactorX = 1.3;
$itemMarginFactorY = 1.2;
//If game is shootmania lower the icons position by 20
if ($this->maniaControl->getMapManager()->getCurrentMap()->getGame() === 'sm'
) {
$posY -= $shootManiaOffset;
}
$itemSize = $width;
$maniaLink = new ManiaLink(self::MLID_ICON);
//Custom Vote Menu Iconsframe
$frame = new Frame();
$maniaLink->add($frame);
$frame->setPosition($posX, $posY);
$backgroundQuad = new Quad();
$frame->add($backgroundQuad);
$backgroundQuad->setSize($width * $itemMarginFactorX, $height * $itemMarginFactorY);
$backgroundQuad->setStyles($quadStyle, $quadSubstyle);
$iconFrame = new Frame();
$frame->add($iconFrame);
$iconFrame->setSize($itemSize, $itemSize);
$itemQuad = new Quad_UIConstruction_Buttons();
$itemQuad->setSubStyle($itemQuad::SUBSTYLE_Add);
$itemQuad->setSize($itemSize, $itemSize);
$iconFrame->add($itemQuad);
//Define Description Label
$menuEntries = count($this->voteMenuItems);
$descriptionFrame = new Frame();
$maniaLink->add($descriptionFrame);
$descriptionFrame->setPosition($posX - $menuEntries * $itemSize * 1.15 - 6, $posY);
$descriptionLabel = new Label();
$descriptionFrame->add($descriptionLabel);
$descriptionLabel->setAlign($descriptionLabel::RIGHT, $descriptionLabel::TOP);
$descriptionLabel->setSize(40, 4);
$descriptionLabel->setTextSize(1.4);
$descriptionLabel->setTextColor('fff');
//Popout Frame
$popoutFrame = new Frame();
$maniaLink->add($popoutFrame);
$popoutFrame->setPosition($posX - $itemSize * 0.5, $posY);
$popoutFrame->setHAlign($popoutFrame::RIGHT);
$popoutFrame->setSize(4 * $itemSize * $itemMarginFactorX, $itemSize * $itemMarginFactorY);
$popoutFrame->setVisible(false);
$backgroundQuad = new Quad();
$popoutFrame->add($backgroundQuad);
$backgroundQuad->setHAlign($backgroundQuad::RIGHT);
$backgroundQuad->setStyles($quadStyle, $quadSubstyle);
$backgroundQuad->setSize($menuEntries * $itemSize * 1.15 + 2, $itemSize * $itemMarginFactorY);
$itemQuad->addToggleFeature($popoutFrame);
// Add items
$posX = -1;
foreach ($this->voteMenuItems as $menuItems) {
foreach ($menuItems as $menuItem) {
/** @var Quad $menuQuad */
$menuQuad = $menuItem[0];
$popoutFrame->add($menuQuad);
$menuQuad->setSize($itemSize, $itemSize);
$menuQuad->setX($posX);
$menuQuad->setHAlign($menuQuad::RIGHT);
$posX -= $itemSize * 1.05;
if ($menuItem[1]) {
$menuQuad->removeScriptFeatures();
$description = '$s' . $menuItem[1];
$menuQuad->addTooltipLabelFeature($descriptionLabel, $description);
}
}
}
// Send manialink
$this->maniaControl->getManialinkManager()->sendManialink($maniaLink, $login);
}
/**
* @see \ManiaControl\Plugins\Plugin::unload()
*/
public function unload() {
//Enable Standard Votes
$defaultRatio = $this->maniaControl->getClient()->getCallVoteRatio();
$ratioArray[] = new VoteRatio(VoteRatio::COMMAND_BAN, $defaultRatio);
$ratioArray[] = new VoteRatio(VoteRatio::COMMAND_KICK, $defaultRatio);
$ratioArray[] = new VoteRatio(VoteRatio::COMMAND_RESTART_MAP, $defaultRatio);
$ratioArray[] = new VoteRatio(VoteRatio::COMMAND_TEAM_BALANCE, $defaultRatio);
$ratioArray[] = new VoteRatio(VoteRatio::COMMAND_NEXT_MAP, $defaultRatio);
$this->maniaControl->getClient()->setCallVoteRatios($ratioArray, false);
$this->destroyVote();
$this->maniaControl->getManialinkManager()->hideManialink(self::MLID_ICON);
}
/**
* Destroys the current Vote
*/
private function destroyVote() {
$emptyManialink = new ManiaLink(self::MLID_WIDGET);
$this->maniaControl->getManialinkManager()->sendManialink($emptyManialink);
// Remove the Listener for the Stop Callback if a stop callback is defined
if ($this->currentVote && $this->currentVote->stopCallback) {
$this->maniaControl->getCallbackManager()->unregisterCallbackListening($this->currentVote->stopCallback, $this);
}
$this->currentVote = null;
}
/**
* Handle PlayerConnect callback
*
* @param Player $player
*/
public function handlePlayerConnect(Player $player) {
$this->showIcon($player->login);
}
/**
* Chat Vote
*
* @param array $chat
* @param Player $player
*/
public function chat_vote(array $chat, Player $player) {
$command = explode(" ", $chat[1][2]);
if (isset($command[1])) {
if (isset($this->voteCommands[$command[1]])) {
$this->startVote($player, strtolower($command[1]));
}
}
}
/**
* Start a vote
*
* @param Player $player
* @param int $voteIndex
* @param callable $function calls the given function only if the vote is successful and returns as Parameter the Voting-Results
*/
public function startVote(Player $player, $voteIndex, $function = null) {
// Check if the Player is muted
if ($player->isMuted()) {
$this->maniaControl->getChat()->sendError('Muted Players are not allowed to start a vote.', $player);
return;
}
// Spectators are not allowed to start a vote
if ($player->isSpectator
&& !$this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_SPECTATOR_ALLOW_START_VOTE)
) {
$this->maniaControl->getChat()->sendError('Spectators are not allowed to start a vote.', $player);
return;
}
//Vote does not exist
if (!isset($this->voteCommands[$voteIndex])) {
$this->maniaControl->getChat()->sendError('Undefined vote.', $player);
return;
}
//A vote is currently running
if (isset($this->currentVote)) {
$this->maniaControl->getChat()->sendError('There is currently another vote running.', $player);
return;
}
$maxTime = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_VOTE_TIME);
/** @var VoteCommand $voteCommand */
$voteCommand = $this->voteCommands[$voteIndex];
$this->currentVote = new CurrentVote($voteCommand, $player, time() + $maxTime);
$this->currentVote->neededRatio = floatval($this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_DEFAULT_RATIO));
$this->currentVote->neededPlayerRatio = floatval($this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_DEFAULT_PLAYER_RATIO));
$this->currentVote->function = $function;
if ($voteCommand->getStopCallback()) {
$this->maniaControl->getCallbackManager()->registerCallbackListener($voteCommand->getStopCallback(), $this, 'handleStopCallback');
$this->currentVote->stopCallback = $voteCommand->getStopCallback();
}
if ($this->currentVote->voteCommand->startText) {
$message = $this->currentVote->voteCommand->startText;
} else {
$message = '$fff' . $player->getEscapedNickname() . '$s$f8f started a $fff$<' . $this->currentVote->voteCommand->name . '$>$f8f!';
}
$this->maniaControl->getChat()->sendSuccess($message);
}
/**
* Destroys the Vote on the Stop Callback
*/
public function handleStopCallback() {
$this->destroyVote();
}
/**
* Destroy the Vote on Cancelled Callback
*/
public function handleVoteCancelled() {
$this->destroyVote();
}
/**
* Handle Standard Votes
*
* @param string $voteName
* @param float $voteResult
*/
public function handleVoteFinished($voteName, $voteResult) {
if ($voteResult >= $this->currentVote->neededRatio) {
// Call Closure if one exists
if (is_callable($this->currentVote->function)) {
call_user_func($this->currentVote->function, $voteResult);
return;
}
switch ($voteName) {
case 'teambalance':
$this->maniaControl->getClient()->autoTeamBalance();
$this->maniaControl->getChat()->sendInformation('$f8fVote to $fffbalance the Teams$f8f has been successful!');
break;
case 'skipmap':
case 'skip':
case 'nextmap':
try {
$this->maniaControl->getMapManager()->getMapActions()->skipMap();
} catch (ChangeInProgressException $e) {
}
$this->maniaControl->getChat()->sendInformation('$f8fVote to $fffskip the Map$f8f has been successful!');
break;
case 'restartmap':
try {
$this->maniaControl->getClient()->restartMap();
} catch (ChangeInProgressException $e) {
}
$this->maniaControl->getChat()->sendInformation('$f8fVote to $fffrestart the Map$f8f has been successful!');
break;
case 'pausegame':
try {
$this->maniaControl->getClient()->sendModeScriptCommands(array('Command_ForceWarmUp' => true));
$this->maniaControl->getChat()->sendInformation('$f8fVote to $fffpause the current Game$f8f has been successful!');
} catch (GameModeException $ex) {
}
break;
case 'replay':
$this->maniaControl->getMapManager()->getMapQueue()->addFirstMapToMapQueue($this->currentVote->voter, $this->maniaControl->getMapManager()->getCurrentMap());
$this->maniaControl->getChat()->sendInformation('$f8fVote to $fffreplay the Map$f8f has been successful!');
break;
}
} else {
//FIXME bugreport, no fail message on vote fail sometimes
$this->maniaControl->getChat()->sendError('Vote Failed!');
}
}
/**
* Handles the ManialinkPageAnswers and start a vote if a button in the panel got clicked
*
* @param array $callback
*/
public function handleManialinkPageAnswer(array $callback) {
$actionId = $callback[1][2];
$actionArray = explode('.', $actionId);
if (count($actionArray) <= 2) {
return;
}
$voteIndex = $actionArray[2];
if (isset($this->voteCommands[$voteIndex])) {
$login = $callback[1][1];
$player = $this->maniaControl->getPlayerManager()->getPlayer($login);
$this->startVote($player, $voteIndex);
}
}
/**
* Handle a Player Chat Vote
*
* @param array $chat
* @param Player $player
*/
public function handleChatVote(array $chat, Player $player) {
$chatCommand = explode(' ', $chat[1][2]);
$chatCommand = $chatCommand[0];
$chatCommand = str_replace('/', '', $chatCommand);
if (isset($this->voteCommands[$chatCommand])) {
$this->startVote($player, $chatCommand);
}
}
/**
* Undefine a Vote
*
* @param int $voteIndex
*/
public function undefineVote($voteIndex) {
unset($this->voteCommands[$voteIndex]);
}
/**
* Handles a Positive Vote
*
* @param array $callback
* @param Player $player
*/
public function handlePositiveVote(array $callback, Player $player) {
if (!isset($this->currentVote)
|| $player->isSpectator
&& !$this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_SPECTATOR_ALLOW_VOTE)
) {
return;
}
$this->currentVote->votePositive($player->login);
}
/**
* Handles a negative Vote
*
* @param array $callback
* @param Player $player
*/
public function handleNegativeVote(array $callback, Player $player) {
if (!isset($this->currentVote)
|| $player->isSpectator
&& !$this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_SPECTATOR_ALLOW_VOTE)
) {
return;
}
$this->currentVote->voteNegative($player->login);
}
/**
* Handle ManiaControl 1 Second Callback
*/
public function handle1Second() {
if (!isset($this->currentVote)) {
return;
}
$voteCount = $this->currentVote->getVoteCount();
$votePercentage = 0;
if ($voteCount > 0) {
$votePercentage = $this->currentVote->positiveVotes / floatval($voteCount);
}
$timeUntilExpire = $this->currentVote->expireTime - time();
$this->showVoteWidget($timeUntilExpire, $votePercentage);
$playerCount = $this->maniaControl->getPlayerManager()->getPlayerCount();
$playersVoteRatio = 0;
if ($playerCount > 0 && $voteCount > 0) {
$playersVoteRatio = floatval($voteCount) / floatval($playerCount);
}
//Check if vote is over
if ($timeUntilExpire <= 0 || (($playersVoteRatio >= $this->currentVote->neededPlayerRatio) && (($votePercentage >= $this->currentVote->neededRatio) || ($votePercentage <= 1 - $this->currentVote->neededRatio)))) {
// Trigger callback
$this->maniaControl->getCallbackManager()->triggerCallback(self::CB_CUSTOM_VOTE_FINISHED, $this->currentVote->voteCommand->index, $votePercentage);
//reset vote
$this->destroyVote();
}
}
/**
* Show the vote widget
*
* @param int $timeUntilExpire
* @param float $votePercentage
*/
private function showVoteWidget($timeUntilExpire, $votePercentage) {
$posX = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_WIDGET_POSX);
$posY = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_WIDGET_POSY);
$width = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_WIDGET_WIDTH);
$height = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_WIDGET_HEIGHT);
$maxTime = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_VOTE_TIME);
$quadStyle = $this->maniaControl->getManialinkManager()->getStyleManager()->getDefaultQuadStyle();
$quadSubstyle = $this->maniaControl->getManialinkManager()->getStyleManager()->getDefaultQuadSubstyle();
$labelStyle = $this->maniaControl->getManialinkManager()->getStyleManager()->getDefaultLabelStyle();
$maniaLink = new ManiaLink(self::MLID_WIDGET);
// mainframe
$frame = new Frame();
$maniaLink->add($frame);
$frame->setSize($width, $height);
$frame->setPosition($posX, $posY, 30);
// Background Quad
$backgroundQuad = new Quad();
$frame->add($backgroundQuad);
$backgroundQuad->setSize($width, $height);
$backgroundQuad->setStyles($quadStyle, $quadSubstyle);
//Vote for label
$label = new Label_Text();
$frame->add($label);
$label->setY($height / 2 - 3);
$label->setSize($width - 5, $height);
$label->setTextSize(1.3);
$label->setText('$s ' . $this->currentVote->voteCommand->name);
//Started by nick
$label = new Label_Text();
$frame->add($label);
$label->setY($height / 2 - 6);
$label->setSize($width - 5, 2);
$label->setTextSize(1);
$label->setTextColor('F80');
$label->setText('$sStarted by ' . $this->currentVote->voter->nickname);
//Time Gauge
$timeGauge = new Gauge();
$frame->add($timeGauge);
$timeGauge->setY(1.5);
$timeGauge->setSize($width * 0.95, 6);
$timeGauge->setDrawBg(false);
if (!$timeUntilExpire) {
$timeUntilExpire = 1;
}
$timeGaugeRatio = (100 / $maxTime * $timeUntilExpire) / 100;
$timeGauge->setRatio($timeGaugeRatio + 0.15 - $timeGaugeRatio * 0.15);
$gaugeColor = ColorUtil::floatToStatusColor($timeGaugeRatio);
$timeGauge->setColor($gaugeColor . '9');
//Time Left
$label = new Label_Text();
$frame->add($label);
$label->setY(0);
$label->setSize($width - 5, $height);
$label->setTextSize(1.1);
$label->setText('$sTime left: ' . $timeUntilExpire . "s");
$label->setTextColor('FFF');
//Vote Gauge
$voteGauge = new Gauge();
$frame->add($voteGauge);
$voteGauge->setY(-4);
$voteGauge->setSize($width * 0.65, 12);
$voteGauge->setDrawBg(false);
$voteGauge->setRatio($votePercentage + 0.10 - $votePercentage * 0.10);
$gaugeColor = ColorUtil::floatToStatusColor($votePercentage);
$voteGauge->setColor($gaugeColor . '6');
$posY = -4.4;
$voteLabel = new Label();
$frame->add($voteLabel);
$voteLabel->setY($posY);
$voteLabel->setSize($width * 0.65, 12);
$voteLabel->setStyle($labelStyle);
$voteLabel->setTextSize(1);
$voteLabel->setText(' ' . round($votePercentage * 100.) . '% (' . $this->currentVote->getVoteCount() . ')');
$positiveQuad = new Quad_BgsPlayerCard();
$frame->add($positiveQuad);
$positiveQuad->setPosition(-$width / 2 + 6, $posY);
$positiveQuad->setSubStyle($positiveQuad::SUBSTYLE_BgPlayerCardBig);
$positiveQuad->setSize(5, 5);
$positiveLabel = new Label_Button();
$frame->add($positiveLabel);
$positiveLabel->setPosition(-$width / 2 + 6, $posY);
$positiveLabel->setStyle($labelStyle);
$positiveLabel->setTextSize(1);
$positiveLabel->setSize(3, 3);
$positiveLabel->setTextColor('0F0');
$positiveLabel->setText('F1');
$negativeQuad = clone $positiveQuad;
$frame->add($negativeQuad);
$negativeQuad->setX($width / 2 - 6);
$negativeLabel = clone $positiveLabel;
$frame->add($negativeLabel);
$negativeLabel->setX($width / 2 - 6);
$negativeLabel->setTextColor('F00');
$negativeLabel->setText('F2');
// Voting Actions
$positiveQuad->addActionTriggerFeature(self::ACTION_POSITIVE_VOTE);
$negativeQuad->addActionTriggerFeature(self::ACTION_NEGATIVE_VOTE);
$script = $maniaLink->getScript();
$keyActionPositive = new KeyAction(self::ACTION_POSITIVE_VOTE, 'F1');
$script->addFeature($keyActionPositive);
$keyActionNegative = new KeyAction(self::ACTION_NEGATIVE_VOTE, 'F2');
$script->addFeature($keyActionNegative);
// Send manialink
$this->maniaControl->getManialinkManager()->sendManialink($maniaLink);
}
}
/**
* Vote Command Model Class
*/
// TODO: extract classes to own files
class VoteCommand {
public $index = '';
public $name = '';
public $neededRatio = 0;
public $idBased = false;
public $startText = '';
private $stopCallback = '';
/**
* Construct a new Vote Command
*
* @param int $index
* @param string $name
* @param bool $idBased
* @param float $neededRatio
*/
public function __construct($index, $name, $idBased, $neededRatio) {
$this->index = $index;
$this->name = $name;
$this->idBased = $idBased;
$this->neededRatio = $neededRatio;
}
/**
* Gets the Stop Callback
*
* @return string
*/
public function getStopCallback() {
return $this->stopCallback;
}
/**
* Defines a Stop Callback
*
* @param $stopCallback
*/
public function setStopCallback($stopCallback) {
$this->stopCallback = $stopCallback;
}
}
/**
* Current Vote Model Class
*/
class CurrentVote {
const VOTE_FOR_ACTION = '1';
const VOTE_AGAINST_ACTION = '-1';
public $voteCommand = null;
public $expireTime = 0;
public $positiveVotes = 0;
public $neededRatio = 0;
public $neededPlayerRatio = 0;
public $voter = null;
public $map = null;
public $player = null;
public $function = null;
public $stopCallback = "";
private $playersVoted = array();
/**
* Construct a Current Vote
*
* @param VoteCommand $voteCommand
* @param Player $voter
* @param $expireTime
*/
public function __construct(VoteCommand $voteCommand, Player $voter, $expireTime) {
$this->expireTime = $expireTime;
$this->voteCommand = $voteCommand;
$this->voter = $voter;
$this->votePositive($voter->login);
}
/**
* Handle a positive Vote
*
* @param string $login
*/
public function votePositive($login) {
if (isset($this->playersVoted[$login])) {
if ($this->playersVoted[$login] == self::VOTE_AGAINST_ACTION) {
$this->playersVoted[$login] = self::VOTE_FOR_ACTION;
$this->positiveVotes++;
}
} else {
$this->playersVoted[$login] = self::VOTE_FOR_ACTION;
$this->positiveVotes++;
}
}
/**
* Handle a negative Vote
*
* @param string $login
*/
public function voteNegative($login) {
if (isset($this->playersVoted[$login])) {
if ($this->playersVoted[$login] == self::VOTE_FOR_ACTION) {
$this->playersVoted[$login] = self::VOTE_AGAINST_ACTION;
$this->positiveVotes--;
}
} else {
$this->playersVoted[$login] = self::VOTE_AGAINST_ACTION;
}
}
/**
* Get the Number of Votes
*
* @return int
*/
public function getVoteCount() {
return count($this->playersVoted);
}
}

View File

@ -0,0 +1,133 @@
<?php
namespace MCTeam\Dedimania;
use ManiaControl\ManiaControl;
use ManiaControl\Players\Player;
use Maniaplanet\DedicatedServer\Structures\Version;
/**
* ManiaControl Dedimania Plugin Data Structure
*
* @author ManiaControl Team <mail@maniacontrol.com>
* @copyright 2014 ManiaControl Team
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
*/
class DedimaniaData {
/*
* Constants
*/
public $game;
public $path;
public $packmask;
public $serverVersion;
public $serverBuild;
public $tool;
public $version;
public $login;
public $code;
public $sessionId = '';
/** @var RecordData[] $records */
public $records = array();
/** @var DedimaniaPlayer[] $players */
public $players = array();
public $directoryAccessChecked = false;
public $serverMaxRank = 30;
/**
* Construct a new Dedimania Data Model
*
* @param string $serverLogin
* @param string $dedimaniaCode
* @param string $path
* @param string $packmask
* @param Version $serverVersion
*/
public function __construct($serverLogin, $dedimaniaCode, $path, $packmask, Version $serverVersion) {
$this->game = "TM2";
$this->login = $serverLogin;
$this->code = $dedimaniaCode;
$this->version = ManiaControl::VERSION;
$this->tool = "ManiaControl";
$this->path = $path;
$this->packmask = $packmask;
$this->serverVersion = $serverVersion->version;
$this->serverBuild = $serverVersion->build;
}
/**
* Sort the Records
*/
public function sortRecords() {
usort($this->records, function (RecordData $first, RecordData $second) {
if ($first->best == $second->best) {
return ($first->rank - $second->rank);
}
return ($first->best - $second->best);
});
}
/**
* Build the Data Array
*
* @return array
*/
public function toArray() {
$array = array();
foreach (get_object_vars($this) as $key => $value) {
if ($key === 'records' || $key === 'sessionId' || $key === 'directoryAccessChecked' || $key === 'serverMaxRank' || $key === 'players') {
continue;
}
$array[ucfirst($key)] = $value;
}
return $array;
}
/**
* Get the Number of Records
*
* @return int
*/
public function getRecordCount() {
return count($this->records);
}
/**
* Get Max Rank for a certain Player
*
* @param mixed $login
* @return int
*/
public function getPlayerMaxRank($login) {
$login = Player::parseLogin($login);
$maxRank = $this->serverMaxRank;
foreach ($this->players as $player) {
/** @var DedimaniaPlayer $player */
if ($player->login === $login) {
if ($player->maxRank > $maxRank) {
$maxRank = $player->maxRank;
}
break;
}
}
return $maxRank;
}
/**
* Add a Player to the Players array
*
* @param DedimaniaPlayer $player
*/
public function addPlayer(DedimaniaPlayer $player) {
$this->players[$player->login] = $player;
}
/**
* Remove a Dedimania Player by its login
*
* @param string $login
*/
public function removePlayer($login) {
unset($this->players[$login]);
}
}

View File

@ -0,0 +1,36 @@
<?php
namespace MCTeam\Dedimania;
/**
* ManiaControl Dedimania Plugin Player Data Structure
*
* @author ManiaControl Team <mail@maniacontrol.com>
* @copyright 2014 ManiaControl Team
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
*/
class DedimaniaPlayer {
/*
* Public properties
*/
public $login = '';
public $maxRank = -1;
public $banned = false;
public $optionsEnabled = false;
public $options = '';
/**
* Construct a new Dedimania Player Model
*
* @param mixed $player
*/
public function __construct($player) {
$this->login = $player['Login'];
$this->maxRank = $player['MaxRank'];
if (isset($player['Banned'])) {
$this->banned = $player['Banned'];
$this->optionsEnabled = $player['OptionsEnabled'];
$this->options = $player['Options'];
}
}
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,65 @@
<?php
namespace MCTeam\Dedimania;
use ManiaControl\Utils\Formatter;
/**
* ManiaControl Dedimania Plugin Record Data Structure
*
* @author ManiaControl Team <mail@maniacontrol.com>
* @copyright 2014 ManiaControl Team
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
*/
class RecordData {
/*
* Public properties
*/
public $nullRecord = false;
public $login = '';
public $nickName = '';
public $best = -1;
public $rank = -1;
public $maxRank = -1;
public $checkpoints = '';
public $newRecord = false;
public $vReplay = '';
public $top1GReplay = '';
/**
* Construct a Record by a given Record Array
*
* @param array $record
*/
public function __construct($record) {
if (!$record) {
$this->nullRecord = true;
return;
}
$this->login = $record['Login'];
$this->nickName = Formatter::stripDirtyCodes($record['NickName']);
$this->best = $record['Best'];
$this->rank = $record['Rank'];
$this->maxRank = $record['MaxRank'];
$this->checkpoints = $record['Checks'];
}
/**
* Construct a new Record via its Properties
*
* @param string $login
* @param string $nickName
* @param float $best
* @param int $checkpoints
* @param bool $newRecord
*/
public function constructNewRecord($login, $nickName, $best, $checkpoints, $newRecord = false) {
$this->nullRecord = false;
$this->login = $login;
$this->nickName = $nickName;
$this->best = $best;
$this->checkpoints = $checkpoints;
$this->newRecord = $newRecord;
}
}

View File

@ -0,0 +1,536 @@
<?php
namespace MCTeam;
use FML\Controls\Frame;
use FML\Controls\Label;
use FML\Controls\Labels\Label_Text;
use FML\Controls\Quad;
use FML\Controls\Quads\Quad_BgRaceScore2;
use FML\Controls\Quads\Quad_BgsPlayerCard;
use FML\ManiaLink;
use FML\Script\Features\Paging;
use ManiaControl\Admin\AuthenticationManager;
use ManiaControl\Bills\BillManager;
use ManiaControl\Callbacks\CallbackListener;
use ManiaControl\Callbacks\CallbackManager;
use ManiaControl\Commands\CommandListener;
use ManiaControl\ManiaControl;
use ManiaControl\Manialinks\ManialinkManager;
use ManiaControl\Players\Player;
use ManiaControl\Players\PlayerManager;
use ManiaControl\Plugins\Plugin;
/**
* ManiaControl Donation Plugin
*
* @author ManiaControl Team <mail@maniacontrol.com>
* @copyright 2014 ManiaControl Team
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
*/
class DonationPlugin implements CallbackListener, CommandListener, Plugin {
/*
* Constants
*/
const ID = 3;
const VERSION = 0.1;
const AUTHOR = 'MCTeam';
const NAME = 'Donation Plugin';
const SETTING_ANNOUNCE_SERVER_DONATION = 'Enable Server-Donation Announcements';
const STAT_PLAYER_DONATIONS = 'Donated Planets';
const ACTION_DONATE_VALUE = 'Donate.DonateValue';
// DonateWidget Properties
const MLID_DONATE_WIDGET = 'DonationPlugin.DonateWidget';
const SETTING_DONATE_WIDGET_ACTIVATED = 'Donate-Widget Activated';
const SETTING_DONATE_WIDGET_POSX = 'Donate-Widget-Position: X';
const SETTING_DONATE_WIDGET_POSY = 'Donate-Widget-Position: Y';
const SETTING_DONATE_WIDGET_WIDTH = 'Donate-Widget-Size: Width';
const SETTING_DONATE_WIDGET_HEIGHT = 'Donate-Widget-Size: Height';
const SETTING_DONATION_VALUES = 'Donation Values';
const SETTING_MIN_AMOUNT_SHOWN = 'Minimum Donation amount to get shown';
/*
* Private properties
*/
/** @var ManiaControl $maniaControl */
private $maniaControl = null;
/**
* @see \ManiaControl\Plugins\Plugin::prepare()
*/
public static function prepare(ManiaControl $maniaControl) {
}
/**
* @see \ManiaControl\Plugins\Plugin::getId()
*/
public static function getId() {
return self::ID;
}
/**
* @see \ManiaControl\Plugins\Plugin::getName()
*/
public static function getName() {
return self::NAME;
}
/**
* @see \ManiaControl\Plugins\Plugin::getVersion()
*/
public static function getVersion() {
return self::VERSION;
}
/**
* @see \ManiaControl\Plugins\Plugin::getAuthor()
*/
public static function getAuthor() {
return self::AUTHOR;
}
/**
* @see \ManiaControl\Plugins\Plugin::getDescription()
*/
public static function getDescription() {
return 'Plugin offering Commands like /donate, /pay and /planets and a Donation Widget.';
}
/**
* @see \ManiaControl\Plugins\Plugin::load()
*/
public function load(ManiaControl $maniaControl) {
$this->maniaControl = $maniaControl;
// Register for commands
$this->maniaControl->getCommandManager()->registerCommandListener('donate', $this, 'command_Donate', false, 'Donate some planets to the server.');
$this->maniaControl->getCommandManager()->registerCommandListener('pay', $this, 'command_Pay', true, 'Pays planets from the server to a player.');
$this->maniaControl->getCommandManager()->registerCommandListener(array('getplanets', 'planets'), $this, 'command_GetPlanets', true, 'Checks the planets-balance of the server.');
$this->maniaControl->getCommandManager()->registerCommandListener('topdons', $this, 'command_TopDons', false, 'Provides an overview of who donated the most planets.');
// Register for callbacks
$this->maniaControl->getCallbackManager()->registerCallbackListener(PlayerManager::CB_PLAYERCONNECT, $this, 'handlePlayerConnect');
$this->maniaControl->getCallbackManager()->registerCallbackListener(CallbackManager::CB_MP_PLAYERMANIALINKPAGEANSWER, $this, 'handleManialinkPageAnswer');
// Define player stats
$this->maniaControl->getStatisticManager()->defineStatMetaData(self::STAT_PLAYER_DONATIONS);
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_DONATE_WIDGET_ACTIVATED, true);
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_DONATE_WIDGET_POSX, 156.);
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_DONATE_WIDGET_POSY, -31.4);
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_DONATE_WIDGET_WIDTH, 6);
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_DONATE_WIDGET_HEIGHT, 6);
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_DONATION_VALUES, "20,50,100,500,1000,2000");
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_MIN_AMOUNT_SHOWN, 100);
// Register Stat in Simple StatsList
$this->maniaControl->getStatisticManager()->getSimpleStatsList()->registerStat(self::STAT_PLAYER_DONATIONS, 90, "DP", 15);
$this->displayWidget();
return true;
}
/**
* Display the widget
*/
public function displayWidget() {
if ($this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_DONATE_WIDGET_ACTIVATED)
) {
$this->displayDonateWidget();
}
}
/**
* Display the Donation Widget
*
* @param string $login
*/
public function displayDonateWidget($login = null) {
$posX = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_DONATE_WIDGET_POSX);
$posY = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_DONATE_WIDGET_POSY);
$width = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_DONATE_WIDGET_WIDTH);
$height = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_DONATE_WIDGET_HEIGHT);
$values = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_DONATION_VALUES);
$shootManiaOffset = $this->maniaControl->getManialinkManager()->getStyleManager()->getDefaultIconOffsetSM();
$quadStyle = $this->maniaControl->getManialinkManager()->getStyleManager()->getDefaultQuadStyle();
$quadSubstyle = $this->maniaControl->getManialinkManager()->getStyleManager()->getDefaultQuadSubstyle();
$itemMarginFactorX = 1.3;
$itemMarginFactorY = 1.2;
//If game is shootmania lower the icons position by 20
if ($this->maniaControl->getMapManager()->getCurrentMap()->getGame() === 'sm'
) {
$posY -= $shootManiaOffset;
}
$itemSize = $width;
$maniaLink = new ManiaLink(self::MLID_DONATE_WIDGET);
// Donate Menu Icon Frame
$frame = new Frame();
$maniaLink->add($frame);
$frame->setPosition($posX, $posY);
$backgroundQuad = new Quad();
$frame->add($backgroundQuad);
$backgroundQuad->setSize($width * $itemMarginFactorX, $height * $itemMarginFactorY);
$backgroundQuad->setStyles($quadStyle, $quadSubstyle);
$iconFrame = new Frame();
$frame->add($iconFrame);
$iconFrame->setSize($itemSize, $itemSize);
$itemQuad = new Quad_BgRaceScore2();
$itemQuad->setSubStyle($itemQuad::SUBSTYLE_Points);
$itemQuad->setSize($itemSize, $itemSize);
$iconFrame->add($itemQuad);
$valueArray = explode(',', $values);
// Values Menu
$popoutFrame = new Frame();
$maniaLink->add($popoutFrame);
$popoutFrame->setPosition($posX - $itemSize * 0.5, $posY);
$popoutFrame->setHAlign($popoutFrame::RIGHT);
$popoutFrame->setSize(4 * $itemSize * $itemMarginFactorX, $itemSize * $itemMarginFactorY);
$popoutFrame->setVisible(false);
$quad = new Quad();
$popoutFrame->add($quad);
$quad->setHAlign($quad::RIGHT);
$quad->setStyles($quadStyle, $quadSubstyle);
$quad->setSize(strlen($values) * 2 + count($valueArray) * 1, $itemSize * $itemMarginFactorY);
$popoutFrame->add($quad);
$itemQuad->addToggleFeature($popoutFrame);
// Description Label
$descriptionFrame = new Frame();
$maniaLink->add($descriptionFrame);
$descriptionFrame->setPosition($posX - 50, $posY - 5);
$descriptionFrame->setHAlign($descriptionFrame::RIGHT);
$descriptionLabel = new Label();
$descriptionFrame->add($descriptionLabel);
$descriptionLabel->setAlign($descriptionLabel::LEFT, $descriptionLabel::TOP);
$descriptionLabel->setSize(40, 4);
$descriptionLabel->setTextSize(2);
$descriptionLabel->setVisible(true);
$descriptionLabel->setTextColor('0f0');
// Add items
$posX = -2;
foreach (array_reverse($valueArray) as $value) {
$label = new Label_Text();
$popoutFrame->add($label);
$label->setX($posX);
$label->setHAlign($label::RIGHT);
$label->setText('$s$FFF' . $value . '$09FP');
$label->setTextSize(1.2);
$label->setAction(self::ACTION_DONATE_VALUE . "." . $value);
$label->setStyle($label::STYLE_TextCardSmall);
$description = "Donate {$value} Planets";
$label->addTooltipLabelFeature($descriptionLabel, $description);
$posX -= strlen($value) * 2 + 1.7;
}
// Send manialink
$this->maniaControl->getManialinkManager()->sendManialink($maniaLink, $login);
}
/**
* @see \ManiaControl\Plugins\Plugin::unload()
*/
public function unload() {
$this->maniaControl->getManialinkManager()->hideManialink(self::MLID_DONATE_WIDGET);
}
/**
* Handle ManialinkPageAnswer Callback
*
* @param array $callback
*/
public function handleManialinkPageAnswer(array $callback) {
$actionId = $callback[1][2];
$boolSetting = (strpos($actionId, self::ACTION_DONATE_VALUE) === 0);
if (!$boolSetting) {
return;
}
$login = $callback[1][1];
$player = $this->maniaControl->getPlayerManager()->getPlayer($login);
$actionArray = explode(".", $callback[1][2]);
$this->handleDonation($player, intval($actionArray[2]));
}
/**
* Handle a Player Donation
*
* @param Player $player
* @param int $amount
* @param string $receiver
* @param string $receiverName
*/
private function handleDonation(Player $player, $amount, $receiver = '', $receiverName = null) {
if ($amount > 1000000) {
// Prevent too huge donation amounts that would cause xmlrpc parsing errors
$message = "You can only donate 1.000.000 Planets at a time!";
$this->maniaControl->getChat()->sendError($message, $player);
return;
}
if (!$receiverName) {
$serverName = $this->maniaControl->getClient()->getServerName();
$message = 'Donate ' . $amount . ' Planets to $<' . $serverName . '$>?';
} else {
$message = 'Donate ' . $amount . ' Planets to $<' . $receiverName . '$>?';
}
//Send and Handle the Bill
$this->maniaControl->getBillManager()->sendBill(function ($data, $status) use (&$player, $amount, $receiver) {
switch ($status) {
case BillManager::DONATED_TO_SERVER:
if ($this->maniaControl->getSettingManager()->getSettingValue($this, DonationPlugin::SETTING_ANNOUNCE_SERVER_DONATION, true)
&& $amount >= $this->maniaControl->getSettingManager()->getSettingValue($this, DonationPlugin::SETTING_MIN_AMOUNT_SHOWN, true)
) {
$login = null;
$message = $player->getEscapedNickname() . ' donated ' . $amount . ' Planets! Thanks.';
} else {
$login = $player->login;
$message = 'Donation successful! Thanks.';
}
$this->maniaControl->getChat()->sendSuccess($message, $login);
$this->maniaControl->getStatisticManager()->insertStat(DonationPlugin::STAT_PLAYER_DONATIONS, $player, $this->maniaControl->getServer()->index, $amount);
break;
case BillManager::DONATED_TO_RECEIVER:
$message = "Successfully donated {$amount} to '{$receiver}'!";
$this->maniaControl->getChat()->sendSuccess($message, $player);
break;
case BillManager::PLAYER_REFUSED_DONATION:
$message = 'Transaction cancelled.';
$this->maniaControl->getChat()->sendError($message, $player);
break;
case BillManager::ERROR_WHILE_TRANSACTION:
$message = $data;
$this->maniaControl->getChat()->sendError($message, $player);
break;
}
}, $player, $amount, $message);
}
/**
* Handle PlayerConnect callback
*
* @param Player $player
*/
public function handlePlayerConnect(Player $player) {
// Display Map Widget
if ($this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_DONATE_WIDGET_ACTIVATED)
) {
$this->displayDonateWidget($player->login);
}
}
/**
* Handle /donate command
*
* @param array $chatCallback
* @param Player $player
*/
public function command_Donate(array $chatCallback, Player $player) {
$text = $chatCallback[1][2];
$params = explode(' ', $text);
if (count($params) < 2) {
$this->sendDonateUsageExample($player);
return;
}
$amount = (int)$params[1];
if (!$amount || $amount <= 0) {
$this->sendDonateUsageExample($player);
return;
}
if (count($params) >= 3) {
$receiver = $params[2];
$receiverPlayer = $this->maniaControl->getPlayerManager()->getPlayer($receiver);
$receiverName = ($receiverPlayer ? $receiverPlayer->nickname : $receiver);
} else {
$receiver = '';
$receiverName = $this->maniaControl->getClient()->getServerName();
}
$this->handleDonation($player, $amount, $receiver, $receiverName);
}
/**
* Send an usage example for /donate to the player
*
* @param Player $player
*/
private function sendDonateUsageExample(Player $player) {
$message = "Usage Example: '/donate 100'";
$this->maniaControl->getChat()->sendChat($message, $player);
}
/**
* Handle //pay command
*
* @param array $chatCallback
* @param Player $player
*/
public function command_Pay(array $chatCallback, Player $player) {
if (!$this->maniaControl->getAuthenticationManager()->checkRight($player, AuthenticationManager::AUTH_LEVEL_SUPERADMIN)
) {
$this->maniaControl->getAuthenticationManager()->sendNotAllowed($player);
return;
}
$text = $chatCallback[1][2];
$params = explode(' ', $text);
if (count($params) < 2) {
$this->sendPayUsageExample($player);
return;
}
$amount = (int)$params[1];
if (!$amount || $amount <= 0) {
$this->sendPayUsageExample($player);
return;
}
if (count($params) >= 3) {
$receiver = $params[2];
} else {
$receiver = $player->login;
}
$message = 'Payout from $<' . $this->maniaControl->getClient()->getServerName() . '$>.';
$this->maniaControl->getBillManager()->sendPlanets(function ($data, $status) use (&$player, $amount, $receiver) {
switch ($status) {
case BillManager::PAYED_FROM_SERVER:
$message = "Successfully payed out {$amount} to '{$receiver}'!";
$this->maniaControl->getChat()->sendSuccess($message, $player);
break;
case BillManager::PLAYER_REFUSED_DONATION:
$message = 'Transaction cancelled.';
$this->maniaControl->getChat()->sendError($message, $player);
break;
case BillManager::ERROR_WHILE_TRANSACTION:
$message = $data;
$this->maniaControl->getChat()->sendError($message, $player);
break;
}
}, $receiver, $amount, $message);
}
/**
* Send an usage example for /pay to the player
*
* @param Player $player
*/
private function sendPayUsageExample(Player $player) {
$message = "Usage Example: '//pay 100 login'";
$this->maniaControl->getChat()->sendChat($message, $player);
}
/**
* Handle //getplanets command
*
* @param array $chatCallback
* @param Player $player
*/
public function command_GetPlanets(array $chatCallback, Player $player) {
if (!$this->maniaControl->getAuthenticationManager()->checkRight($player, AuthenticationManager::AUTH_LEVEL_ADMIN)
) {
$this->maniaControl->getAuthenticationManager()->sendNotAllowed($player);
return;
}
$planets = $this->maniaControl->getClient()->getServerPlanets();
$message = "This Server has {$planets} Planets!";
$this->maniaControl->getChat()->sendInformation($message, $player);
}
/**
* Handles the /topdons command
*
* @param array $chatCallback
* @param Player $player
*/
public function command_TopDons(array $chatCallback, Player $player) {
$this->showTopDonsList($player);
}
/**
* Provide an Overview ManiaLink with Donators
*
* @param Player $player
*/
private function showTopDonsList(Player $player) {
$stats = $this->maniaControl->getStatisticManager()->getStatsRanking(self::STAT_PLAYER_DONATIONS);
$width = $this->maniaControl->getManialinkManager()->getStyleManager()->getListWidgetsWidth();
$height = $this->maniaControl->getManialinkManager()->getStyleManager()->getListWidgetsHeight();
// create manialink
$maniaLink = new ManiaLink(ManialinkManager::MAIN_MLID);
$script = $maniaLink->getScript();
$paging = new Paging();
$script->addFeature($paging);
// Main frame
$frame = $this->maniaControl->getManialinkManager()->getStyleManager()->getDefaultListFrame($script, $paging);
$maniaLink->add($frame);
// Start offsets
$posX = -$width / 2;
$posY = $height / 2;
//Predefine description Label
$descriptionLabel = $this->maniaControl->getManialinkManager()->getStyleManager()->getDefaultDescriptionLabel();
$frame->add($descriptionLabel);
// Headline
$headFrame = new Frame();
$frame->add($headFrame);
$headFrame->setY($posY - 5);
$array = array('$oId' => $posX + 5, '$oNickname' => $posX + 18, '$oDonated planets' => $posX + 70);
$this->maniaControl->getManialinkManager()->labelLine($headFrame, $array);
$index = 1;
$posY = $posY - 10;
$pageFrame = null;
foreach ($stats as $playerIndex => $donations) {
if ($index % 15 === 1) {
$pageFrame = new Frame();
$frame->add($pageFrame);
$posY = $height / 2 - 10;
$paging->addPage($pageFrame);
}
$playerFrame = new Frame();
$pageFrame->add($playerFrame);
$playerFrame->setY($posY);
if ($index % 2 !== 0) {
$lineQuad = new Quad_BgsPlayerCard();
$playerFrame->add($lineQuad);
$lineQuad->setSize($width, 4);
$lineQuad->setSubStyle($lineQuad::SUBSTYLE_BgPlayerCardBig);
$lineQuad->setZ(0.001);
}
$donatingPlayer = $this->maniaControl->getPlayerManager()->getPlayerByIndex($playerIndex);
$array = array($index => $posX + 5, $donatingPlayer->nickname => $posX + 18, $donations => $posX + 70);
$this->maniaControl->getManialinkManager()->labelLine($playerFrame, $array);
$posY -= 4;
$index++;
if ($index > 100) {
break;
}
}
// Render and display xml
$this->maniaControl->getManialinkManager()->displayWidget($maniaLink, $player, 'TopDons');
}
}

View File

@ -0,0 +1,247 @@
<?php
namespace MCTeam;
use ManiaControl\Callbacks\CallbackListener;
use ManiaControl\Callbacks\Callbacks;
use ManiaControl\Commands\CommandListener;
use ManiaControl\ManiaControl;
use ManiaControl\Players\Player;
use ManiaControl\Players\PlayerManager;
use ManiaControl\Plugins\Plugin;
use ManiaControl\Settings\Setting;
use ManiaControl\Settings\SettingManager;
use Maniaplanet\DedicatedServer\Xmlrpc\GameModeException;
/**
* Dynamic Point Limit Plugin
*
* @author ManiaControl Team <mail@maniacontrol.com>
* @copyright 2014 ManiaControl Team
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
*/
// TODO: test setpointlimit command
class DynamicPointLimitPlugin implements CallbackListener, CommandListener, Plugin {
/*
* Constants
*/
const ID = 21;
const VERSION = 0.3;
const NAME = 'Dynamic Point Limit Plugin';
const AUTHOR = 'MCTeam';
const SETTING_POINT_LIMIT_MULTIPLIER = 'Point Limit Multiplier';
const SETTING_POINT_LIMIT_OFFSET = 'Point Limit Offset';
const SETTING_MIN_POINT_LIMIT = 'Minimum Point Limit';
const SETTING_MAX_POINT_LIMIT = 'Maximum Point Limit';
const SETTING_ACCEPT_OTHER_MODES = 'Activate in other Modes than Royal';
const CACHE_SPEC_STATUS = 'SpecStatus';
const SCRIPT_SETTING_MAP_POINTS_LIMIT = 'S_MapPointsLimit';
/*
* Private properties
*/
/** @var ManiaControl $maniaControl */
private $maniaControl = null;
private $lastPointLimit = null;
private $staticMode = null;
/**
* @see \ManiaControl\Plugins\Plugin::prepare()
*/
public static function prepare(ManiaControl $maniaControl) {
$maniaControl->getSettingManager()->initSetting(get_class(), self::SETTING_POINT_LIMIT_MULTIPLIER, 10);
$maniaControl->getSettingManager()->initSetting(get_class(), self::SETTING_POINT_LIMIT_OFFSET, 0);
$maniaControl->getSettingManager()->initSetting(get_class(), self::SETTING_MIN_POINT_LIMIT, 30);
$maniaControl->getSettingManager()->initSetting(get_class(), self::SETTING_MAX_POINT_LIMIT, 200);
$maniaControl->getSettingManager()->initSetting(get_class(), self::SETTING_ACCEPT_OTHER_MODES, false);
}
/**
* @see \ManiaControl\Plugins\Plugin::getId()
*/
public static function getId() {
return self::ID;
}
/**
* @see \ManiaControl\Plugins\Plugin::getName()
*/
public static function getName() {
return self::NAME;
}
/**
* @see \ManiaControl\Plugins\Plugin::getVersion()
*/
public static function getVersion() {
return self::VERSION;
}
/**
* @see \ManiaControl\Plugins\Plugin::getAuthor()
*/
public static function getAuthor() {
return self::AUTHOR;
}
/**
* @see \ManiaControl\Plugins\Plugin::getDescription()
*/
public static function getDescription() {
return 'Plugin offering a dynamic Point Limit according to the Number of Players on the Server.';
}
/**
* @see \ManiaControl\Plugins\Plugin::load()
*/
public function load(ManiaControl $maniaControl) {
$this->maniaControl = $maniaControl;
$allowOthers = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_ACCEPT_OTHER_MODES);
if (!$allowOthers && $this->maniaControl->getServer()->titleId !== 'SMStormRoyal@nadeolabs') {
$error = 'This plugin only supports Royal (check Settings)!';
throw new \Exception($error);
}
$this->maniaControl->getCallbackManager()->registerCallbackListener(PlayerManager::CB_PLAYERCONNECT, $this, 'updatePointLimit');
$this->maniaControl->getCallbackManager()->registerCallbackListener(PlayerManager::CB_PLAYERDISCONNECT, $this, 'updatePointLimit');
$this->maniaControl->getCallbackManager()->registerCallbackListener(PlayerManager::CB_PLAYERINFOCHANGED, $this, 'handlePlayerInfoChangedCallback');
$this->maniaControl->getCallbackManager()->registerCallbackListener(Callbacks::BEGINROUND, $this, 'updatePointLimit');
$this->maniaControl->getCallbackManager()->registerCallbackListener(Callbacks::BEGINMAP, $this, 'handleBeginMap');
$this->maniaControl->getCallbackManager()->registerCallbackListener(SettingManager::CB_SETTING_CHANGED, $this, 'handleSettingChangedCallback');
$this->maniaControl->getCommandManager()->registerCommandListener('setpointlimit', $this, 'commandSetPointlimit', true, 'Setpointlimit XXX or auto');
$this->updatePointLimit();
}
/**
* Update Point Limit
*/
public function updatePointLimit() {
if ($this->staticMode) {
return;
}
$numberOfPlayers = $this->maniaControl->getPlayerManager()->getPlayerCount();
$multiplier = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_POINT_LIMIT_MULTIPLIER);
$offset = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_POINT_LIMIT_OFFSET);
$minValue = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MIN_POINT_LIMIT);
$maxValue = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MAX_POINT_LIMIT);
$pointLimit = $offset + $numberOfPlayers * $multiplier;
if ($pointLimit < $minValue) {
$pointLimit = $minValue;
}
if ($pointLimit > $maxValue) {
$pointLimit = $maxValue;
}
$pointLimit = (int)$pointLimit;
if ($this->lastPointLimit !== $pointLimit) {
try {
$this->maniaControl->getClient()->setModeScriptSettings(array(self::SCRIPT_SETTING_MAP_POINTS_LIMIT => $pointLimit));
$message = "Dynamic PointLimit changed to: {$pointLimit}!";
if ($this->lastPointLimit !== null) {
$message .= " (From {$this->lastPointLimit})";
}
$this->maniaControl->getChat()->sendInformation($message);
$this->lastPointLimit = $pointLimit;
} catch (GameModeException $exception) {
$this->maniaControl->getChat()->sendExceptionToAdmins($exception);
}
}
}
/**
* Handle SetPointLimit Command
*
* @param array $chatCallback
* @param Player $player
*/
public function commandSetPointlimit(array $chatCallback, Player $player) {
$commandParts = explode(' ', $chatCallback[1][2]);
if (count($commandParts) < 2) {
$this->maniaControl->getChat()->sendUsageInfo('Example: //setpointlimit auto', $player);
return;
}
$value = strtolower($commandParts[1]);
if ($value === "auto") {
$this->staticMode = false;
$this->maniaControl->getChat()->sendInformation('Enabled Dynamic PointLimit!');
$this->updatePointLimit();
} else {
if (is_numeric($value)) {
$value = (int)$value;
if ($value <= 0) {
$this->maniaControl->getChat()->sendError('PointLimit needs to be greater than Zero.', $player);
return;
}
try {
$this->maniaControl->getClient()->setModeScriptSettings(array(self::SCRIPT_SETTING_MAP_POINTS_LIMIT => $value));
$this->staticMode = true;
$this->lastPointLimit = $value;
$this->maniaControl->getChat()->sendInformation("PointLimit changed to: {$value} (Fixed)");
} catch (GameModeException $exception) {
$this->maniaControl->getChat()->sendException($exception, $player);
}
} else {
$this->maniaControl->getChat()->sendUsageInfo('Example: //setpointlimit 150', $player);
}
}
}
/**
* @see \ManiaControl\Plugins\Plugin::unload()
*/
public function unload() {
}
/**
* Handle Setting Changed Callback
*
* @param Setting $setting
*/
public function handleSettingChangedCallback(Setting $setting) {
if (!$setting->belongsToClass($this)) {
return;
}
$this->updatePointLimit();
}
/**
* Handle BeginMap Callback
*/
public function handleBeginMap() {
if ($this->staticMode && !is_null($this->lastPointLimit)) {
// Refresh static point limit in case it has been reset
try {
$this->maniaControl->getClient()->setModeScriptSettings(array(self::SCRIPT_SETTING_MAP_POINTS_LIMIT => $this->lastPointLimit));
$message = "PointLimit fixed at {$this->lastPointLimit}.";
$this->maniaControl->getChat()->sendInformation($message);
} catch (GameModeException $e) {
$this->lastPointLimit = null;
}
}
}
/**
* Handle Player Info Changed Callback
*
* @param Player $player
*/
public function handlePlayerInfoChangedCallback(Player $player) {
$lastSpecStatus = $player->getCache($this, self::CACHE_SPEC_STATUS);
$newSpecStatus = $player->isSpectator;
if ($newSpecStatus === $lastSpecStatus && $lastSpecStatus !== null) {
return;
}
$player->setCache($this, self::CACHE_SPEC_STATUS, $newSpecStatus);
$this->updatePointLimit();
}
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,663 @@
<?php
namespace MCTeam;
use FML\Controls\Frame;
use FML\Controls\Label;
use FML\Controls\Quad;
use FML\Controls\Quads\Quad_BgsPlayerCard;
use FML\ManiaLink;
use FML\Script\Features\Paging;
use ManiaControl\Admin\AuthenticationManager;
use ManiaControl\Callbacks\CallbackListener;
use ManiaControl\Callbacks\CallbackManager;
use ManiaControl\Callbacks\Callbacks;
use ManiaControl\Callbacks\Models\RecordCallback;
use ManiaControl\Callbacks\TimerListener;
use ManiaControl\Commands\CommandListener;
use ManiaControl\Logger;
use ManiaControl\ManiaControl;
use ManiaControl\Manialinks\ManialinkManager;
use ManiaControl\Maps\Map;
use ManiaControl\Players\Player;
use ManiaControl\Players\PlayerManager;
use ManiaControl\Plugins\Plugin;
use ManiaControl\Settings\Setting;
use ManiaControl\Settings\SettingManager;
use ManiaControl\Utils\Formatter;
/**
* ManiaControl Local Records Plugin
*
* @author ManiaControl Team <mail@maniacontrol.com>
* @copyright 2014 ManiaControl Team
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
*/
class LocalRecordsPlugin implements CallbackListener, CommandListener, TimerListener, Plugin {
/*
* Constants
*/
const ID = 7;
const VERSION = 0.2;
const NAME = 'Local Records Plugin';
const AUTHOR = 'MCTeam';
const MLID_RECORDS = 'ml_local_records';
const TABLE_RECORDS = 'mc_localrecords';
const SETTING_WIDGET_TITLE = 'Widget Title';
const SETTING_WIDGET_POSX = 'Widget Position: X';
const SETTING_WIDGET_POSY = 'Widget Position: Y';
const SETTING_WIDGET_WIDTH = 'Widget Width';
const SETTING_WIDGET_LINESCOUNT = 'Widget Displayed Lines Count';
const SETTING_WIDGET_LINEHEIGHT = 'Widget Line Height';
const SETTING_WIDGET_ENABLE = 'Enable Local Records Widget';
const SETTING_NOTIFY_ONLY_DRIVER = 'Notify only the Driver on New Records';
const SETTING_NOTIFY_BEST_RECORDS = 'Notify Publicly only for the X Best Records';
const SETTING_ADJUST_OUTER_BORDER = 'Adjust outer Border to Number of actual Records';
const CB_LOCALRECORDS_CHANGED = 'LocalRecords.Changed';
const ACTION_SHOW_RECORDSLIST = 'LocalRecords.ShowRecordsList';
/*
* Private properties
*/
/** @var ManiaControl $maniaControl */
private $maniaControl = null;
private $updateManialink = false;
private $checkpoints = array();
/**
* @see \ManiaControl\Plugins\Plugin::prepare()
*/
public static function prepare(ManiaControl $maniaControl) {
}
/**
* @see \ManiaControl\Plugins\Plugin::getId()
*/
public static function getId() {
return self::ID;
}
/**
* @see \ManiaControl\Plugins\Plugin::getName()
*/
public static function getName() {
return self::NAME;
}
/**
* @see \ManiaControl\Plugins\Plugin::getVersion()
*/
public static function getVersion() {
return self::VERSION;
}
/**
* @see \ManiaControl\Plugins\Plugin::getAuthor()
*/
public static function getAuthor() {
return self::AUTHOR;
}
/**
* @see \ManiaControl\Plugins\Plugin::getDescription()
*/
public static function getDescription() {
return 'Plugin offering tracking of local records and manialinks to display them.';
}
/**
* @see \ManiaControl\Plugins\Plugin::load()
*/
public function load(ManiaControl $maniaControl) {
$this->maniaControl = $maniaControl;
$this->initTables();
// Settings
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_WIDGET_TITLE, 'Local Records');
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_WIDGET_POSX, -139.);
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_WIDGET_POSY, 75);
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_WIDGET_WIDTH, 40.);
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_WIDGET_LINESCOUNT, 15);
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_WIDGET_LINEHEIGHT, 4.);
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_WIDGET_ENABLE, true);
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_NOTIFY_ONLY_DRIVER, false);
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_NOTIFY_BEST_RECORDS, -1);
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_ADJUST_OUTER_BORDER, false);
// Callbacks
$this->maniaControl->getTimerManager()->registerTimerListening($this, 'handle1Second', 1000);
$this->maniaControl->getCallbackManager()->registerCallbackListener(Callbacks::AFTERINIT, $this, 'handleAfterInit');
$this->maniaControl->getCallbackManager()->registerCallbackListener(Callbacks::BEGINMAP, $this, 'handleMapBegin');
$this->maniaControl->getCallbackManager()->registerCallbackListener(SettingManager::CB_SETTING_CHANGED, $this, 'handleSettingChanged');
$this->maniaControl->getCallbackManager()->registerCallbackListener(CallbackManager::CB_MP_PLAYERMANIALINKPAGEANSWER, $this, 'handleManialinkPageAnswer');
$this->maniaControl->getCallbackManager()->registerCallbackListener(PlayerManager::CB_PLAYERCONNECT, $this, 'handlePlayerConnect');
$this->maniaControl->getCallbackManager()->registerCallbackListener(RecordCallback::CHECKPOINT, $this, 'handleCheckpointCallback');
$this->maniaControl->getCallbackManager()->registerCallbackListener(RecordCallback::LAPFINISH, $this, 'handleLapFinishCallback');
$this->maniaControl->getCallbackManager()->registerCallbackListener(RecordCallback::FINISH, $this, 'handleFinishCallback');
$this->maniaControl->getCommandManager()->registerCommandListener(array('recs', 'records'), $this, 'showRecordsList', false, 'Shows a list of Local Records on the current map.');
$this->maniaControl->getCommandManager()->registerCommandListener('delrec', $this, 'deleteRecord', true, 'Removes a record from the database.');
$this->updateManialink = true;
return true;
}
/**
* Initialize needed database tables
*/
private function initTables() {
$mysqli = $this->maniaControl->getDatabase()->getMysqli();
$query = "CREATE TABLE IF NOT EXISTS `" . self::TABLE_RECORDS . "` (
`index` int(11) NOT NULL AUTO_INCREMENT,
`mapIndex` int(11) NOT NULL,
`playerIndex` int(11) NOT NULL,
`time` int(11) NOT NULL,
`changed` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`index`),
UNIQUE KEY `player_map_record` (`mapIndex`,`playerIndex`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1;";
$mysqli->query($query);
if ($mysqli->error) {
trigger_error($mysqli->error, E_USER_ERROR);
}
$mysqli->query("ALTER TABLE `" . self::TABLE_RECORDS . "` ADD `checkpoints` TEXT CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL");
if ($mysqli->error) {
if (!strstr($mysqli->error, 'Duplicate')) {
trigger_error($mysqli->error, E_USER_ERROR);
}
}
}
/**
* @see \ManiaControl\Plugins\Plugin::unload()
*/
public function unload() {
$this->maniaControl->getManialinkManager()->hideManialink(self::MLID_RECORDS);
}
/**
* Handle ManiaControl After Init
*/
public function handleAfterInit() {
$this->updateManialink = true;
}
/**
* Handle 1 Second Callback
*/
public function handle1Second() {
if (!$this->updateManialink) {
return;
}
$this->updateManialink = false;
if ($this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_WIDGET_ENABLE)
) {
$manialink = $this->buildManialink();
$this->maniaControl->getManialinkManager()->sendManialink($manialink);
}
}
/**
* Build the local records manialink
*
* @return string
*/
private function buildManialink() {
$map = $this->maniaControl->getMapManager()->getCurrentMap();
if (!$map) {
return null;
}
$title = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_WIDGET_TITLE);
$posX = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_WIDGET_POSX);
$posY = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_WIDGET_POSY);
$width = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_WIDGET_WIDTH);
$lines = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_WIDGET_LINESCOUNT);
$lineHeight = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_WIDGET_LINEHEIGHT);
$labelStyle = $this->maniaControl->getManialinkManager()->getStyleManager()->getDefaultLabelStyle();
$quadStyle = $this->maniaControl->getManialinkManager()->getStyleManager()->getDefaultQuadStyle();
$quadSubstyle = $this->maniaControl->getManialinkManager()->getStyleManager()->getDefaultQuadSubstyle();
$records = $this->getLocalRecords($map);
if (!is_array($records)) {
Logger::logError("Couldn't fetch player records.");
return null;
}
$manialink = new ManiaLink(self::MLID_RECORDS);
$frame = new Frame();
$manialink->add($frame);
$frame->setPosition($posX, $posY);
$backgroundQuad = new Quad();
$frame->add($backgroundQuad);
$backgroundQuad->setVAlign($backgroundQuad::TOP);
$adjustOuterBorder = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_ADJUST_OUTER_BORDER);
$height = 7. + ($adjustOuterBorder ? count($records) : $lines) * $lineHeight;
$backgroundQuad->setSize($width * 1.05, $height);
$backgroundQuad->setStyles($quadStyle, $quadSubstyle);
$backgroundQuad->setAction(self::ACTION_SHOW_RECORDSLIST);
$titleLabel = new Label();
$frame->add($titleLabel);
$titleLabel->setPosition(0, $lineHeight * -0.9);
$titleLabel->setWidth($width);
$titleLabel->setStyle($labelStyle);
$titleLabel->setTextSize(2);
$titleLabel->setText($title);
$titleLabel->setTranslate(true);
// Times
foreach ($records as $index => $record) {
if ($index >= $lines) {
break;
}
$y = -8. - $index * $lineHeight;
$recordFrame = new Frame();
$frame->add($recordFrame);
$recordFrame->setPosition(0, $y);
/*
* $backgroundQuad = new Quad(); $recordFrame->add($backgroundQuad); $backgroundQuad->setSize($width * 1.04, $lineHeight * 1.4); $backgroundQuad->setStyles($quadStyle, $quadSubstyle);
*/
$rankLabel = new Label();
$recordFrame->add($rankLabel);
$rankLabel->setHAlign($rankLabel::LEFT);
$rankLabel->setX($width * -0.47);
$rankLabel->setSize($width * 0.06, $lineHeight);
$rankLabel->setTextSize(1);
$rankLabel->setTextPrefix('$o');
$rankLabel->setText($record->rank);
$rankLabel->setTextEmboss(true);
$nameLabel = new Label();
$recordFrame->add($nameLabel);
$nameLabel->setHAlign($nameLabel::LEFT);
$nameLabel->setX($width * -0.4);
$nameLabel->setSize($width * 0.6, $lineHeight);
$nameLabel->setTextSize(1);
$nameLabel->setText($record->nickname);
$nameLabel->setTextEmboss(true);
$timeLabel = new Label();
$recordFrame->add($timeLabel);
$timeLabel->setHAlign($timeLabel::RIGHT);
$timeLabel->setX($width * 0.47);
$timeLabel->setSize($width * 0.25, $lineHeight);
$timeLabel->setTextSize(1);
$timeLabel->setText(Formatter::formatTime($record->time));
$timeLabel->setTextEmboss(true);
}
return $manialink;
}
/**
* Fetch local records for the given map
*
* @param Map $map
* @param int $limit
* @return array
*/
public function getLocalRecords(Map $map, $limit = -1) {
$mysqli = $this->maniaControl->getDatabase()->getMysqli();
$limit = ($limit > 0 ? 'LIMIT ' . $limit : '');
$query = "SELECT * FROM (
SELECT recs.*, @rank := @rank + 1 as `rank` FROM `" . self::TABLE_RECORDS . "` recs, (SELECT @rank := 0) ra
WHERE recs.`mapIndex` = {$map->index}
ORDER BY recs.`time` ASC
{$limit}) records
LEFT JOIN `" . PlayerManager::TABLE_PLAYERS . "` players
ON records.`playerIndex` = players.`index`;";
$result = $mysqli->query($query);
if ($mysqli->error) {
trigger_error($mysqli->error);
return null;
}
$records = array();
while ($record = $result->fetch_object()) {
array_push($records, $record);
}
$result->free();
return $records;
}
/**
* Handle Setting Changed Callback
*
* @param Setting $setting
*/
public function handleSettingChanged(Setting $setting) {
if (!$setting->belongsToClass($this)) {
return;
}
switch ($setting->setting) {
case self::SETTING_WIDGET_ENABLE:
{
if ($setting->value) {
$this->updateManialink = true;
} else {
$this->maniaControl->getManialinkManager()->hideManialink(self::MLID_RECORDS);
}
break;
}
}
}
/**
* Handle Checkpoint Callback
*
* @param RecordCallback $callback
*/
public function handleCheckpointCallback(RecordCallback $callback) {
if ($callback->isLegacyCallback) {
return;
}
if (!isset($this->checkpoints[$callback->login])) {
$this->checkpoints[$callback->login] = array();
}
$this->checkpoints[$callback->login][$callback->lapCheckpoint] = $callback->lapTime;
}
/**
* Handle LapFinish Callback
*
* @param RecordCallback $callback
*/
public function handleLapFinishCallback(RecordCallback $callback) {
$this->handleFinishCallback($callback);
}
/**
* Handle Finish Callback
*
* @param RecordCallback $callback
*/
public function handleFinishCallback(RecordCallback $callback) {
if ($callback->isLegacyCallback) {
return;
}
if ($callback->time <= 0) {
// Invalid time
return;
}
$map = $this->maniaControl->getMapManager()->getCurrentMap();
$checkpointsString = $this->getCheckpoints($callback->player->login);
$this->checkpoints[$callback->login] = array();
// Check old record of the player
$oldRecord = $this->getLocalRecord($map, $callback->player);
if ($oldRecord) {
if ($oldRecord->time < $callback->time) {
// Not improved
return;
}
if ($oldRecord->time == $callback->time) {
// Same time
// TODO: respect notify-settings
$message = '$<$fff' . $callback->player->nickname . '$> equalized his/her $<$ff0' . $oldRecord->rank . '.$> Local Record: $<$fff' . Formatter::formatTime($oldRecord->time) . '$>!';
$this->maniaControl->getChat()->sendInformation('$3c0' . $message);
return;
}
}
// Save time
$mysqli = $this->maniaControl->getDatabase()->getMysqli();
$query = "INSERT INTO `" . self::TABLE_RECORDS . "` (
`mapIndex`,
`playerIndex`,
`time`,
`checkpoints`
) VALUES (
{$map->index},
{$callback->player->index},
{$callback->time},
'{$checkpointsString}'
) ON DUPLICATE KEY UPDATE
`time` = VALUES(`time`),
`checkpoints` = VALUES(`checkpoints`);";
$mysqli->query($query);
if ($mysqli->error) {
trigger_error($mysqli->error);
return;
}
$this->updateManialink = true;
// Announce record
$newRecord = $this->getLocalRecord($map, $callback->player);
$improvedRank = (!$oldRecord || $newRecord->rank < $oldRecord->rank);
$notifyOnlyDriver = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_NOTIFY_ONLY_DRIVER);
$notifyOnlyBestRecords = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_NOTIFY_BEST_RECORDS);
$message = '$3c0';
if ($notifyOnlyDriver) {
$message .= 'You';
} else {
$message .= '$<$fff' . $callback->player->nickname . '$>';
}
$message .= ' ' . ($improvedRank ? 'gained' : 'improved') . ' the';
$message .= ' $<$ff0' . $newRecord->rank . '.$> Local Record:';
$message .= ' $<$fff' . Formatter::formatTime($newRecord->time) . '$>!';
if ($oldRecord) {
$message .= ' (';
if ($improvedRank) {
$message .= '$<$ff0' . $oldRecord->rank . '.$> ';
}
$timeDiff = $oldRecord->time - $newRecord->time;
$message .= '$<$fff-' . Formatter::formatTime($timeDiff) . '$>)';
}
if ($notifyOnlyDriver) {
$this->maniaControl->getChat()->sendInformation($message, $callback->player);
} else if (!$notifyOnlyBestRecords || $newRecord->rank <= $notifyOnlyBestRecords) {
$this->maniaControl->getChat()->sendInformation($message);
}
$this->maniaControl->getCallbackManager()->triggerCallback(self::CB_LOCALRECORDS_CHANGED, $newRecord);
}
/**
* Get current checkpoint string for dedimania record
*
* @param string $login
* @return string
*/
private function getCheckpoints($login) {
if (!$login || !isset($this->checkpoints[$login])) {
return null;
}
$string = '';
$count = count($this->checkpoints[$login]);
foreach ($this->checkpoints[$login] as $index => $check) {
$string .= $check;
if ($index < $count - 1) {
$string .= ',';
}
}
return $string;
}
/**
* Retrieve the local record for the given map and login
*
* @param Map $map
* @param Player $player
* @return mixed
*/
private function getLocalRecord(Map $map, Player $player) {
$mysqli = $this->maniaControl->getDatabase()->getMysqli();
$query = "SELECT records.* FROM (
SELECT recs.*, @rank := @rank + 1 as `rank` FROM `" . self::TABLE_RECORDS . "` recs, (SELECT @rank := 0) ra
WHERE recs.`mapIndex` = {$map->index}
ORDER BY recs.`time` ASC) records
WHERE records.`playerIndex` = {$player->index};";
$result = $mysqli->query($query);
if ($mysqli->error) {
trigger_error("Couldn't retrieve player record for '{$player->login}'." . $mysqli->error);
return null;
}
$record = $result->fetch_object();
$result->free();
return $record;
}
/**
* Handle Player Connect Callback
*/
public function handlePlayerConnect() {
$this->updateManialink = true;
}
/**
* Handle Begin Map Callback
*/
public function handleMapBegin() {
$this->updateManialink = true;
}
/**
* Handle PlayerManialinkPageAnswer callback
*
* @param array $callback
*/
public function handleManialinkPageAnswer(array $callback) {
$actionId = $callback[1][2];
$login = $callback[1][1];
$player = $this->maniaControl->getPlayerManager()->getPlayer($login);
if ($actionId === self::ACTION_SHOW_RECORDSLIST) {
$this->showRecordsList(array(), $player);
}
}
/**
* Shows a ManiaLink list with the local records.
*
* @param array $chat
* @param Player $player
*/
public function showRecordsList(array $chat, Player $player) {
$width = $this->maniaControl->getManialinkManager()->getStyleManager()->getListWidgetsWidth();
$height = $this->maniaControl->getManialinkManager()->getStyleManager()->getListWidgetsHeight();
// get PlayerList
$records = $this->getLocalRecords($this->maniaControl->getMapManager()->getCurrentMap());
// create manialink
$maniaLink = new ManiaLink(ManialinkManager::MAIN_MLID);
$script = $maniaLink->getScript();
$paging = new Paging();
$script->addFeature($paging);
// Main frame
$frame = $this->maniaControl->getManialinkManager()->getStyleManager()->getDefaultListFrame($script, $paging);
$maniaLink->add($frame);
// Start offsets
$posX = -$width / 2;
$posY = $height / 2;
// Predefine Description Label
$descriptionLabel = $this->maniaControl->getManialinkManager()->getStyleManager()->getDefaultDescriptionLabel();
$frame->add($descriptionLabel);
// Headline
$headFrame = new Frame();
$frame->add($headFrame);
$headFrame->setY($posY - 5);
$array = array('Rank' => $posX + 5, 'Nickname' => $posX + 18, 'Login' => $posX + 70, 'Time' => $posX + 101);
$this->maniaControl->getManialinkManager()->labelLine($headFrame, $array);
$index = 0;
$posY = $height / 2 - 10;
$pageFrame = null;
foreach ($records as $listRecord) {
if ($index % 15 === 0) {
$pageFrame = new Frame();
$frame->add($pageFrame);
$posY = $height / 2 - 10;
$paging->addPage($pageFrame);
}
$recordFrame = new Frame();
$pageFrame->add($recordFrame);
if ($index % 2 !== 0) {
$lineQuad = new Quad_BgsPlayerCard();
$recordFrame->add($lineQuad);
$lineQuad->setSize($width, 4);
$lineQuad->setSubStyle($lineQuad::SUBSTYLE_BgPlayerCardBig);
$lineQuad->setZ(0.001);
}
if (strlen($listRecord->nickname) < 2) {
$listRecord->nickname = $listRecord->login;
}
$array = array($listRecord->rank => $posX + 5, '$fff' . $listRecord->nickname => $posX + 18, $listRecord->login => $posX + 70, Formatter::formatTime($listRecord->time) => $posX + 101);
$this->maniaControl->getManialinkManager()->labelLine($recordFrame, $array);
$recordFrame->setY($posY);
$posY -= 4;
$index++;
}
// Render and display xml
$this->maniaControl->getManialinkManager()->displayWidget($maniaLink, $player, 'PlayerList');
}
/**
* Delete a Player's record
*
* @param array $chat
* @param Player $player
*/
public function deleteRecord(array $chat, Player $player) {
if (!$this->maniaControl->getAuthenticationManager()->checkRight($player, AuthenticationManager::AUTH_LEVEL_MASTERADMIN)
) {
$this->maniaControl->getAuthenticationManager()->sendNotAllowed($player);
return;
}
$commandParts = explode(' ', $chat[1][2]);
if (count($commandParts) < 2) {
$this->maniaControl->getChat()->sendUsageInfo('Missing Record ID! (Example: //delrec 3)', $player);
return;
}
$recordId = (int)$commandParts[1];
$currentMap = $this->maniaControl->getMapManager()->getCurrentMap();
$records = $this->getLocalRecords($currentMap);
if (count($records) < $recordId) {
$this->maniaControl->getChat()->sendError('Cannot remove record $<$fff' . $recordId . '$>!', $player);
return;
}
$mysqli = $this->maniaControl->getDatabase()->getMysqli();
$query = "DELETE FROM `" . self::TABLE_RECORDS . "`
WHERE `mapIndex` = {$currentMap->index}
AND `playerIndex` = {$player->index};";
$mysqli->query($query);
if ($mysqli->error) {
trigger_error($mysqli->error);
return;
}
$this->maniaControl->getCallbackManager()->triggerCallback(self::CB_LOCALRECORDS_CHANGED, null);
$this->maniaControl->getChat()->sendInformation('Record no. $<$fff' . $recordId . '$> has been removed!');
}
}

View File

@ -0,0 +1,553 @@
<?php
namespace MCTeam;
use FML\Controls\Frame;
use FML\Controls\Quads\Quad_BgsPlayerCard;
use FML\ManiaLink;
use FML\Script\Features\Paging;
use ManiaControl\Callbacks\CallbackListener;
use ManiaControl\Callbacks\Callbacks;
use ManiaControl\Commands\CommandListener;
use ManiaControl\ManiaControl;
use ManiaControl\Manialinks\ManialinkManager;
use ManiaControl\Players\Player;
use ManiaControl\Players\PlayerManager;
use ManiaControl\Plugins\Plugin;
use ManiaControl\Statistics\StatisticCollector;
use ManiaControl\Statistics\StatisticManager;
use Maniaplanet\DedicatedServer\Structures\AbstractStructure;
/**
* ManiaControl ServerRanking Plugin
*
* @author ManiaControl Team <mail@maniacontrol.com>
* @copyright 2014 ManiaControl Team
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
*/
class ServerRankingPlugin implements Plugin, CallbackListener, CommandListener {
/*
* Constants
*/
const PLUGIN_ID = 6;
const PLUGIN_VERSION = 0.1;
const PLUGIN_NAME = 'Server Ranking Plugin';
const PLUGIN_AUTHOR = 'MCTeam';
const TABLE_RANK = 'mc_rank';
const RANKING_TYPE_RECORDS = 'Records';
const RANKING_TYPE_RATIOS = 'Ratios';
const RANKING_TYPE_POINTS = 'Points';
const SETTING_RANKING_TYPE = 'ServerRankings Type Records/Points/Ratios';
const SETTING_MIN_HITS_RATIO_RANKING = 'Min Hits on Ratio Rankings';
const SETTING_MIN_HITS_POINTS_RANKING = 'Min Hits on Points Rankings';
const SETTING_MIN_REQUIRED_RECORDS = 'Minimum amount of records required on Records Ranking';
const SETTING_MAX_STORED_RECORDS = 'Maximum number of records per map for calculations';
const CB_RANK_BUILT = 'ServerRankingPlugin.RankBuilt';
/*
* Private properties
*/
/** @var ManiaControl $maniaControl * */
private $maniaControl = null;
private $recordCount = 0;
/**
* @see \ManiaControl\Plugins\Plugin::prepare()
*/
public static function prepare(ManiaControl $maniaControl) {
}
/**
* @see \ManiaControl\Plugins\Plugin::getId()
*/
public static function getId() {
return self::PLUGIN_ID;
}
/**
* @see \ManiaControl\Plugins\Plugin::getName()
*/
public static function getName() {
return self::PLUGIN_NAME;
}
/**
* @see \ManiaControl\Plugins\Plugin::getVersion()
*/
public static function getVersion() {
return self::PLUGIN_VERSION;
}
/**
* @see \ManiaControl\Plugins\Plugin::getAuthor()
*/
public static function getAuthor() {
return self::PLUGIN_AUTHOR;
}
/**
* @see \ManiaControl\Plugins\Plugin::getDescription()
*/
public static function getDescription() {
return "ServerRanking Plugin, ServerRanking by an avg build from the records, per count of points, or by a multiplication from Kill/Death Ratio and Laser accuracy";
}
/**
* @see \ManiaControl\Plugins\Plugin::load()
*/
public function load(ManiaControl $maniaControl) {
$this->maniaControl = $maniaControl;
$this->initTables();
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_MIN_HITS_RATIO_RANKING, 100);
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_MIN_HITS_POINTS_RANKING, 15);
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_MIN_REQUIRED_RECORDS, 3);
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_MAX_STORED_RECORDS, 50);
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_RANKING_TYPE, $this->getRankingsTypeArray());
// Callbacks
$this->maniaControl->getCallbackManager()->registerCallbackListener(PlayerManager::CB_PLAYERCONNECT, $this, 'handlePlayerConnect');
$this->maniaControl->getCallbackManager()->registerCallbackListener(Callbacks::ENDMAP, $this, 'handleEndMap');
// Commands
$this->maniaControl->getCommandManager()->registerCommandListener('rank', $this, 'command_showRank', false, 'Shows your current ServerRank.');
$this->maniaControl->getCommandManager()->registerCommandListener('nextrank', $this, 'command_nextRank', false, 'Shows the person in front of you in the ServerRanking.');
$this->maniaControl->getCommandManager()->registerCommandListener(array('topranks', 'top100'), $this, 'command_topRanks', false, 'Shows an overview of the best-ranked 100 players.');
// TODO: only update records count
$this->resetRanks();
}
/**
* Get the RankingsTypeArray
*
* @return array[]
*/
private function getRankingsTypeArray() {
$script = $this->maniaControl->getClient()->getScriptName();
if ($this->maniaControl->getMapManager()->getCurrentMap()->getGame() === 'tm'
) {
//TODO also add obstacle here as default
return array(self::RANKING_TYPE_RECORDS, self::RANKING_TYPE_POINTS, self::RANKING_TYPE_RATIOS);
} else if ($script["CurrentValue"] === 'InstaDM.Script.txt') {
return array(self::RANKING_TYPE_RATIOS, self::RANKING_TYPE_POINTS, self::RANKING_TYPE_RECORDS);
} else {
return array(self::RANKING_TYPE_POINTS, self::RANKING_TYPE_RATIOS, self::RANKING_TYPE_RECORDS);
}
}
/**
* Create necessary database tables
*/
private function initTables() {
$mysqli = $this->maniaControl->getDatabase()->getMysqli();
$query = "CREATE TABLE IF NOT EXISTS `" . self::TABLE_RANK . "` (
`PlayerIndex` int(11) NOT NULL,
`Rank` int(11) NOT NULL,
`Avg` float NOT NULL,
KEY `PlayerIndex` (`PlayerIndex`),
UNIQUE `Rank` (`Rank`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='ServerRanking';";
$mysqli->query($query);
if ($mysqli->error) {
throw new \Exception($mysqli->error);
}
}
/**
* Resets and rebuilds the Ranking
*/
private function resetRanks() {
$mysqli = $this->maniaControl->getDatabase()->getMysqli();
// Erase old Average Data
$query = "TRUNCATE TABLE `" . self::TABLE_RANK . "`;";
$mysqli->query($query);
if ($mysqli->error) {
trigger_error($mysqli->error);
}
$type = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_RANKING_TYPE);
switch ($type) {
case self::RANKING_TYPE_RATIOS:
$minHits = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MIN_HITS_RATIO_RANKING);
$hits = $this->maniaControl->getStatisticManager()->getStatsRanking(StatisticCollector::STAT_ON_HIT, -1, $minHits);
$killDeathRatios = $this->maniaControl->getStatisticManager()->getStatsRanking(StatisticManager::SPECIAL_STAT_KD_RATIO);
$accuracies = $this->maniaControl->getStatisticManager()->getStatsRanking(StatisticManager::SPECIAL_STAT_LASER_ACC);
$ranks = array();
foreach ($hits as $login => $hitCount) {
if (!isset($killDeathRatios[$login]) || !isset($accuracies[$login])) {
continue;
}
$ranks[$login] = $killDeathRatios[$login] * $accuracies[$login] * 1000;
}
arsort($ranks);
break;
case self::RANKING_TYPE_POINTS:
$minHits = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MIN_HITS_POINTS_RANKING);
$ranks = $this->maniaControl->getStatisticManager()->getStatsRanking(StatisticCollector::STAT_ON_HIT, -1, $minHits);
break;
case self::RANKING_TYPE_RECORDS:
// TODO: verify workable status
/** @var LocalRecordsPlugin $localRecordsPlugin */
$localRecordsPlugin = $this->maniaControl->getPluginManager()->getPlugin(__NAMESPACE__ . '\LocalRecordsPlugin');
if (!$localRecordsPlugin) {
return;
}
$requiredRecords = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MIN_REQUIRED_RECORDS);
$maxRecords = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MAX_STORED_RECORDS);
$query = "SELECT `playerIndex`, COUNT(*) AS `Cnt`
FROM `" . LocalRecordsPlugin::TABLE_RECORDS . "`
GROUP BY `PlayerIndex`
HAVING `Cnt` >= {$requiredRecords};";
$result = $mysqli->query($query);
$players = array();
while ($row = $result->fetch_object()) {
$players[$row->playerIndex] = array(0, 0); //sum, count
}
$result->free_result();
$maps = $this->maniaControl->getMapManager()->getMaps();
foreach ($maps as $map) {
$records = $localRecordsPlugin->getLocalRecords($map, $maxRecords);
$index = 1;
foreach ($records as $record) {
if (isset($players[$record->playerIndex])) {
$players[$record->playerIndex][0] += $index;
$players[$record->playerIndex][1]++;
}
$index++;
}
}
$mapCount = count($maps);
//compute each players new average score
$ranks = array();
foreach ($players as $playerIndex => $val) {
$sum = $val[0];
$cnt = $val[1];
// ranked maps sum + $maxRecs rank for all remaining maps
$ranks[$playerIndex] = ($sum + ($mapCount - $cnt) * $maxRecords) / $mapCount;
}
asort($ranks);
break;
}
if (empty($ranks)) {
return;
}
$this->recordCount = count($ranks);
//Compute each player's new average score
$query = "INSERT INTO `" . self::TABLE_RANK . "` VALUES ";
$index = 1;
foreach ($ranks as $playerIndex => $rankValue) {
$query .= '(' . $playerIndex . ',' . $index . ',' . $rankValue . '),';
$index++;
}
$query = substr($query, 0, strlen($query) - 1); // strip trailing ','
$mysqli->query($query);
if ($mysqli->error) {
trigger_error($mysqli->error);
}
}
/**
* @see \ManiaControl\Plugins\Plugin::unload()
*/
public function unload() {
}
/**
* Handle PlayerConnect callback
*
* @param Player $player
*/
public function handlePlayerConnect(Player $player) {
$this->showRank($player);
$this->showNextRank($player);
}
/**
* Shows the serverRank to a certain Player
*
* @param Player $player
*/
public function showRank(Player $player) {
$rankObj = $this->getRank($player);
$type = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_RANKING_TYPE);
$message = '';
if ($rankObj) {
switch ($type) {
case self::RANKING_TYPE_RATIOS:
$killDeathRatio = $this->maniaControl->getStatisticManager()->getStatisticData(StatisticManager::SPECIAL_STAT_KD_RATIO, $player->index);
$accuracy = $this->maniaControl->getStatisticManager()->getStatisticData(StatisticManager::SPECIAL_STAT_LASER_ACC, $player->index);
$message = '$0f3Your Server rank is $<$ff3' . $rankObj->rank . '$> / $<$fff' . $this->recordCount . '$> (K/D: $<$fff' . round($killDeathRatio, 2) . '$> Acc: $<$fff' . round($accuracy * 100) . '%$>)';
break;
case self::RANKING_TYPE_POINTS:
$message = '$0f3Your Server rank is $<$ff3' . $rankObj->rank . '$> / $<$fff' . $this->recordCount . '$> Points: $fff' . $rankObj->avg;
break;
case self::RANKING_TYPE_RECORDS:
$message = '$0f3Your Server rank is $<$ff3' . $rankObj->rank . '$> / $<$fff' . $this->recordCount . '$> Avg: $fff' . round($rankObj->avg, 2);
}
} else {
switch ($type) {
case self::RANKING_TYPE_RATIOS:
$minHits = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MIN_HITS_RATIO_RANKING);
$message = '$0f3 You must make $<$fff' . $minHits . '$> Hits on this server before receiving a rank...';
break;
case self::RANKING_TYPE_POINTS:
$minPoints = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MIN_HITS_POINTS_RANKING);
$message = '$0f3 You must make $<$fff' . $minPoints . '$> Hits on this server before receiving a rank...';
break;
case self::RANKING_TYPE_RECORDS:
$minRecords = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MIN_REQUIRED_RECORDS);
$message = '$0f3 You need $<$fff' . $minRecords . '$> Records on this server before receiving a rank...';
}
}
$this->maniaControl->getChat()->sendChat($message, $player);
}
/**
* Get the Rank Object for the given Player
*
* @param Player $player
* @return Rank
*/
private function getRank(Player $player) {
//TODO setting global from db or local
$mysqli = $this->maniaControl->getDatabase()->getMysqli();
$query = "SELECT * FROM `" . self::TABLE_RANK . "`
WHERE `PlayerIndex` = {$player->index};";
$result = $mysqli->query($query);
if ($mysqli->error) {
trigger_error($mysqli->error);
return null;
}
if ($result->num_rows <= 0) {
$result->free_result();
return null;
}
$row = $result->fetch_array();
$result->free_result();
return Rank::fromArray($row);
}
/**
* Show which Player is next ranked to you
*
* @param Player $player
* @return bool
*/
public function showNextRank(Player $player) {
$rankObject = $this->getRank($player);
if (!$rankObject) {
return false;
}
if ($rankObject->rank > 1) {
$nextRank = $this->getNextRank($player);
$nextPlayer = $this->maniaControl->getPlayerManager()->getPlayerByIndex($nextRank->playerIndex);
$message = '$0f3The next better ranked player is $fff' . $nextPlayer->nickname;
} else {
$message = '$0f3No better ranked player :-)';
}
$this->maniaControl->getChat()->sendChat($message, $player);
return true;
}
/**
* Get the Next Ranked Player
*
* @param Player $player
* @return Rank
*/
private function getNextRank(Player $player) {
$rankObject = $this->getRank($player);
if (!$rankObject) {
return null;
}
$nextRank = $rankObject->rank - 1;
$mysqli = $this->maniaControl->getDatabase()->getMysqli();
$query = "SELECT * FROM `" . self::TABLE_RANK . "`
WHERE `Rank` = {$nextRank};";
$result = $mysqli->query($query);
if ($mysqli->error) {
trigger_error($mysqli->error);
return null;
}
if ($result->num_rows <= 0) {
$result->free();
return null;
}
$row = $result->fetch_array();
$result->free();
return Rank::fromArray($row);
}
/**
* Show Ranks on Map End
*/
public function handleEndMap() {
$this->resetRanks();
foreach ($this->maniaControl->getPlayerManager()->getPlayers() as $player) {
if ($player->isFakePlayer()) {
continue;
}
$this->showRank($player);
$this->showNextRank($player);
}
// Trigger callback
$this->maniaControl->getCallbackManager()->triggerCallback(self::CB_RANK_BUILT);
}
/**
* Shows the current Server-Rank
*
* @param array $chatCallback
* @param Player $player
*/
public function command_showRank(array $chatCallback, Player $player) {
$this->showRank($player);
}
/**
* Show the next better ranked player
*
* @param array $chatCallback
* @param Player $player
*/
public function command_nextRank(array $chatCallback, Player $player) {
if (!$this->showNextRank($player)) {
$message = '$0f3You need to have a ServerRank first!';
$this->maniaControl->getChat()->sendChat($message, $player);
}
}
/**
* Handles /topranks|top100 command
*
* @param array $chatCallback
* @param Player $player
*/
public function command_topRanks(array $chatCallback, Player $player) {
$this->showTopRanksList($player);
}
/**
* Provide a ManiaLink window with the top ranks to the player
*
* @param Player $player
*/
private function showTopRanksList(Player $player) {
$query = "SELECT * FROM `" . self::TABLE_RANK . "`
ORDER BY `Rank` ASC LIMIT 0, 100;";
$mysqli = $this->maniaControl->getDatabase()->getMysqli();
$result = $mysqli->query($query);
if ($mysqli->error) {
trigger_error($mysqli->error);
return;
}
$width = $this->maniaControl->getManialinkManager()->getStyleManager()->getListWidgetsWidth();
$height = $this->maniaControl->getManialinkManager()->getStyleManager()->getListWidgetsHeight();
// create manialink
$maniaLink = new ManiaLink(ManialinkManager::MAIN_MLID);
$script = $maniaLink->getScript();
$paging = new Paging();
$script->addFeature($paging);
// Main frame
$frame = $this->maniaControl->getManialinkManager()->getStyleManager()->getDefaultListFrame($script, $paging);
$maniaLink->add($frame);
// Start offsets
$posX = -$width / 2;
$posY = $height / 2;
//Predefine description Label
$descriptionLabel = $this->maniaControl->getManialinkManager()->getStyleManager()->getDefaultDescriptionLabel();
$frame->add($descriptionLabel);
// Headline
$headFrame = new Frame();
$frame->add($headFrame);
$headFrame->setY($posY - 5);
$array = array('$oRank' => $posX + 5, '$oNickname' => $posX + 18, '$oAverage' => $posX + 70);
$this->maniaControl->getManialinkManager()->labelLine($headFrame, $array);
$index = 1;
$posY -= 10;
$pageFrame = null;
while ($rankedPlayer = $result->fetch_object()) {
if ($index % 15 === 1) {
$pageFrame = new Frame();
$frame->add($pageFrame);
$posY = $height / 2 - 10;
$paging->addPage($pageFrame);
}
$playerFrame = new Frame();
$pageFrame->add($playerFrame);
$playerFrame->setY($posY);
if ($index % 2 !== 0) {
$lineQuad = new Quad_BgsPlayerCard();
$playerFrame->add($lineQuad);
$lineQuad->setSize($width, 4);
$lineQuad->setSubStyle($lineQuad::SUBSTYLE_BgPlayerCardBig);
$lineQuad->setZ(0.001);
}
$playerObject = $this->maniaControl->getPlayerManager()->getPlayerByIndex($rankedPlayer->PlayerIndex);
$array = array($rankedPlayer->Rank => $posX + 5, $playerObject->nickname => $posX + 18, (string)round($rankedPlayer->Avg, 2) => $posX + 70);
$this->maniaControl->getManialinkManager()->labelLine($playerFrame, $array);
$posY -= 4;
$index++;
}
// Render and display xml
$this->maniaControl->getManialinkManager()->displayWidget($maniaLink, $player, 'TopRanks');
}
}
/**
* Rank Structure
*/
// TODO: extract class to own file
class Rank extends AbstractStructure {
public $playerIndex;
public $rank;
public $avg;
}

View File

@ -0,0 +1,546 @@
<?php
namespace MCTeam;
use FML\Controls\Frame;
use FML\Controls\Labels\Label_Text;
use FML\Controls\Quad;
use FML\Controls\Quads\Quad_Icons128x128_1;
use FML\Controls\Quads\Quad_Icons64x64_1;
use FML\ManiaLink;
use FML\Script\Script;
use ManiaControl\Callbacks\CallbackListener;
use ManiaControl\Callbacks\Callbacks;
use ManiaControl\Callbacks\TimerListener;
use ManiaControl\ManiaControl;
use ManiaControl\Manialinks\IconManager;
use ManiaControl\Players\Player;
use ManiaControl\Players\PlayerManager;
use ManiaControl\Plugins\Plugin;
use ManiaControl\Settings\Setting;
use ManiaControl\Settings\SettingManager;
use ManiaControl\Utils\Formatter;
/**
* ManiaControl Widget Plugin
*
* @author ManiaControl Team <mail@maniacontrol.com>
* @copyright 2014 ManiaControl Team
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
*/
class WidgetPlugin implements CallbackListener, TimerListener, Plugin {
/*
* Constants
*/
const PLUGIN_ID = 1;
const PLUGIN_VERSION = 0.1;
const PLUGIN_NAME = 'WidgetPlugin';
const PLUGIN_AUTHOR = 'kremsy';
// MapWidget Properties
const MLID_MAP_WIDGET = 'WidgetPlugin.MapWidget';
const SETTING_MAP_WIDGET_ACTIVATED = 'Map-Widget Activated';
const SETTING_MAP_WIDGET_POSX = 'Map-Widget-Position: X';
const SETTING_MAP_WIDGET_POSY = 'Map-Widget-Position: Y';
const SETTING_MAP_WIDGET_WIDTH = 'Map-Widget-Size: Width';
const SETTING_MAP_WIDGET_HEIGHT = 'Map-Widget-Size: Height';
// ClockWidget Properties
const MLID_CLOCK_WIDGET = 'WidgetPlugin.ClockWidget';
const SETTING_CLOCK_WIDGET_ACTIVATED = 'Clock-Widget Activated';
const SETTING_CLOCK_WIDGET_POSX = 'Clock-Widget-Position: X';
const SETTING_CLOCK_WIDGET_POSY = 'Clock-Widget-Position: Y';
const SETTING_CLOCK_WIDGET_WIDTH = 'Clock-Widget-Size: Width';
const SETTING_CLOCK_WIDGET_HEIGHT = 'Clock-Widget-Size: Height';
// NextMapWidget Properties
const MLID_NEXTMAP_WIDGET = 'WidgetPlugin.NextMapWidget';
const SETTING_NEXTMAP_WIDGET_ACTIVATED = 'Nextmap-Widget Activated';
const SETTING_NEXTMAP_WIDGET_POSX = 'Nextmap-Widget-Position: X';
const SETTING_NEXTMAP_WIDGET_POSY = 'Nextmap-Widget-Position: Y';
const SETTING_NEXTMAP_WIDGET_WIDTH = 'Nextmap-Widget-Size: Width';
const SETTING_NEXTMAP_WIDGET_HEIGHT = 'Nextmap-Widget-Size: Height';
// ServerInfoWidget Properties
const MLID_SERVERINFO_WIDGET = 'WidgetPlugin.ServerInfoWidget';
const SETTING_SERVERINFO_WIDGET_ACTIVATED = 'ServerInfo-Widget Activated';
const SETTING_SERVERINFO_WIDGET_POSX = 'ServerInfo-Widget-Position: X';
const SETTING_SERVERINFO_WIDGET_POSY = 'ServerInfo-Widget-Position: Y';
const SETTING_SERVERINFO_WIDGET_WIDTH = 'ServerInfo-Widget-Size: Width';
const SETTING_SERVERINFO_WIDGET_HEIGHT = 'ServerInfo-Widget-Size: Height';
/*
* Private properties
*/
/** @var ManiaControl $maniaControl */
private $maniaControl = null;
/**
* @see \ManiaControl\Plugins\Plugin::prepare()
*/
public static function prepare(ManiaControl $maniaControl) {
}
/**
* @see \ManiaControl\Plugins\Plugin::getId()
*/
public static function getId() {
return self::PLUGIN_ID;
}
/**
* @see \ManiaControl\Plugins\Plugin::getName()
*/
public static function getName() {
return self::PLUGIN_NAME;
}
/**
* @see \ManiaControl\Plugins\Plugin::getVersion()
*/
public static function getVersion() {
return self::PLUGIN_VERSION;
}
/**
* @see \ManiaControl\Plugins\Plugin::getAuthor()
*/
public static function getAuthor() {
return self::PLUGIN_AUTHOR;
}
/**
* @see \ManiaControl\Plugins\Plugin::getDescription()
*/
public static function getDescription() {
return 'Plugin offers some Widgets';
}
/**
* @see \ManiaControl\Plugins\Plugin::load()
*/
public function load(ManiaControl $maniaControl) {
$this->maniaControl = $maniaControl;
// Set CustomUI Setting
$this->maniaControl->getManialinkManager()->getCustomUIManager()->setChallengeInfoVisible(false);
// Callbacks
$this->maniaControl->getCallbackManager()->registerCallbackListener(Callbacks::BEGINMAP, $this, 'handleOnBeginMap');
$this->maniaControl->getCallbackManager()->registerCallbackListener(Callbacks::ENDMAP, $this, 'handleOnEndMap');
$this->maniaControl->getCallbackManager()->registerCallbackListener(PlayerManager::CB_PLAYERCONNECT, $this, 'handlePlayerConnect');
$this->maniaControl->getCallbackManager()->registerCallbackListener(PlayerManager::CB_PLAYERDISCONNECT, $this, 'updateWidgets');
$this->maniaControl->getCallbackManager()->registerCallbackListener(PlayerManager::CB_PLAYERINFOCHANGED, $this, 'updateWidgets');
$this->maniaControl->getCallbackManager()->registerCallbackListener(SettingManager::CB_SETTING_CHANGED, $this, 'updateSettings');
// Settings
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_MAP_WIDGET_ACTIVATED, true);
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_MAP_WIDGET_POSX, 160 - 20);
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_MAP_WIDGET_POSY, 90 - 4.5);
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_MAP_WIDGET_WIDTH, 40);
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_MAP_WIDGET_HEIGHT, 9.);
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_SERVERINFO_WIDGET_ACTIVATED, true);
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_SERVERINFO_WIDGET_POSX, -160 + 17.5);
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_SERVERINFO_WIDGET_POSY, 90 - 4.5);
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_SERVERINFO_WIDGET_WIDTH, 35);
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_SERVERINFO_WIDGET_HEIGHT, 9.);
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_NEXTMAP_WIDGET_ACTIVATED, true);
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_NEXTMAP_WIDGET_POSX, 160 - 20);
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_NEXTMAP_WIDGET_POSY, 90 - 25.5);
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_NEXTMAP_WIDGET_WIDTH, 40);
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_NEXTMAP_WIDGET_HEIGHT, 12.);
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_CLOCK_WIDGET_ACTIVATED, true);
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_CLOCK_WIDGET_POSX, 160 - 5);
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_CLOCK_WIDGET_POSY, 90 - 11);
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_CLOCK_WIDGET_WIDTH, 10);
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_CLOCK_WIDGET_HEIGHT, 5.5);
$this->displayWidgets();
return true;
}
/**
* Display the Widgets
*/
private function displayWidgets() {
// Display Map Widget
if ($this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MAP_WIDGET_ACTIVATED)
) {
$this->maniaControl->getClient()->triggerModeScriptEvent("Siege_SetProgressionLayerPosition", array("160.", "-67.", "0."));
$this->displayMapWidget();
}
if ($this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_CLOCK_WIDGET_ACTIVATED)
) {
$this->displayClockWidget();
}
if ($this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_SERVERINFO_WIDGET_ACTIVATED)
) {
$this->displayServerInfoWidget();
}
}
/**
* Display the Map Widget
*
* @param string $login
*/
public function displayMapWidget($login = null) {
$posX = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MAP_WIDGET_POSX);
$posY = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MAP_WIDGET_POSY);
$width = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MAP_WIDGET_WIDTH);
$height = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MAP_WIDGET_HEIGHT);
$quadStyle = $this->maniaControl->getManialinkManager()->getStyleManager()->getDefaultQuadStyle();
$quadSubstyle = $this->maniaControl->getManialinkManager()->getStyleManager()->getDefaultQuadSubstyle();
$maniaLink = new ManiaLink(self::MLID_MAP_WIDGET);
$script = new Script();
$maniaLink->setScript($script);
// mainframe
$frame = new Frame();
$maniaLink->add($frame);
$frame->setSize($width, $height);
$frame->setPosition($posX, $posY);
// Background Quad
$backgroundQuad = new Quad();
$frame->add($backgroundQuad);
$backgroundQuad->setSize($width, $height);
$backgroundQuad->setStyles($quadStyle, $quadSubstyle);
//$backgroundQuad->addMapInfoFeature();
$map = $this->maniaControl->getMapManager()->getCurrentMap();
$label = new Label_Text();
$frame->add($label);
$label->setPosition(0, 1.5, 0.2);
$label->setTextSize(1.3);
$label->setText(Formatter::stripDirtyCodes($map->name));
$label->setTextColor('fff');
$label->setSize($width - 5, $height);
$label = new Label_Text();
$frame->add($label);
$label->setPosition(0, -1.4, 0.2);
$label->setTextSize(1);
$label->setScale(0.8);
$label->setText($map->authorLogin);
$label->setTextColor('fff');
$label->setSize($width - 5, $height);
if (isset($map->mx->pageurl)) {
$quad = new Quad();
$frame->add($quad);
$quad->setImageFocus($this->maniaControl->getManialinkManager()->getIconManager()->getIcon(IconManager::MX_ICON_MOVER));
$quad->setImage($this->maniaControl->getManialinkManager()->getIconManager()->getIcon(IconManager::MX_ICON));
$quad->setPosition(-$width / 2 + 4, -1.5, -0.5);
$quad->setSize(4, 4);
$quad->setUrl($map->mx->pageurl);
}
// Send manialink
$this->maniaControl->getManialinkManager()->sendManialink($maniaLink, $login);
}
/**
* Displays the Clock Widget
*
* @param bool $login
*/
public function displayClockWidget($login = false) {
$posX = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_CLOCK_WIDGET_POSX);
$posY = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_CLOCK_WIDGET_POSY);
$width = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_CLOCK_WIDGET_WIDTH);
$height = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_CLOCK_WIDGET_HEIGHT);
$quadStyle = $this->maniaControl->getManialinkManager()->getStyleManager()->getDefaultQuadStyle();
$quadSubstyle = $this->maniaControl->getManialinkManager()->getStyleManager()->getDefaultQuadSubstyle();
$maniaLink = new ManiaLink(self::MLID_CLOCK_WIDGET);
// mainframe
$frame = new Frame();
$maniaLink->add($frame);
$frame->setSize($width, $height);
$frame->setPosition($posX, $posY);
// Background Quad
$backgroundQuad = new Quad();
$frame->add($backgroundQuad);
$backgroundQuad->setSize($width, $height);
$backgroundQuad->setStyles($quadStyle, $quadSubstyle);
$label = new Label_Text();
$frame->add($label);
$label->setPosition(0, 1.5, 0.2);
$label->setVAlign($label::TOP);
$label->setTextSize(1);
$label->setTextColor('fff');
$label->addClockFeature(false);
// Send manialink
$this->maniaControl->getManialinkManager()->sendManialink($maniaLink, $login);
}
/**
* Display the Server Info Widget
*
* @param string $login
*/
public function displayServerInfoWidget($login = null) {
$posX = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_SERVERINFO_WIDGET_POSX);
$posY = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_SERVERINFO_WIDGET_POSY);
$width = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_SERVERINFO_WIDGET_WIDTH);
$height = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_SERVERINFO_WIDGET_HEIGHT);
$quadStyle = $this->maniaControl->getManialinkManager()->getStyleManager()->getDefaultQuadStyle();
$quadSubstyle = $this->maniaControl->getManialinkManager()->getStyleManager()->getDefaultQuadSubstyle();
$maniaLink = new ManiaLink(self::MLID_SERVERINFO_WIDGET);
// mainframe
$frame = new Frame();
$maniaLink->add($frame);
$frame->setSize($width, $height);
$frame->setPosition($posX, $posY);
// Background Quad
$backgroundQuad = new Quad();
$frame->add($backgroundQuad);
$backgroundQuad->setSize($width, $height);
$backgroundQuad->setStyles($quadStyle, $quadSubstyle);
$serverName = $this->maniaControl->getClient()->getServerName();
$playerCount = $this->maniaControl->getPlayerManager()->getPlayerCount(true);
$maxPlayers = $this->maniaControl->getClient()->getMaxPlayers();
$spectatorCount = $this->maniaControl->getPlayerManager()->getSpectatorCount();
$maxSpectators = $this->maniaControl->getClient()->getMaxSpectators();
$label = new Label_Text();
$frame->add($label);
$label->setPosition(0, 1.5, 0.2);
$label->setSize($width - 5, $height);
$label->setTextSize(1.3);
$label->setText(Formatter::stripDirtyCodes($serverName));
$label->setTextColor('fff');
//$label->setAutoNewLine(true);
// Player Quad / Label
$label = new Label_Text();
$frame->add($label);
$label->setPosition(-$width / 2 + 9, -1.5, 0.2);
$label->setHAlign($label::LEFT);
$label->setTextSize(1);
$label->setScale(0.8);
$label->setText($playerCount . " / " . $maxPlayers['NextValue']);
$label->setTextColor('fff');
$quad = new Quad_Icons128x128_1();
$frame->add($quad);
$quad->setSubStyle($quad::SUBSTYLE_Multiplayer);
$quad->setPosition(-$width / 2 + 7, -1.6, 0.2);
$quad->setSize(2.5, 2.5);
// Spectator Quad / Label
$label = new Label_Text();
$frame->add($label);
$label->setPosition(2, -1.5, 0.2);
$label->setHAlign($label::LEFT);
$label->setTextSize(1);
$label->setScale(0.8);
$label->setText($spectatorCount . " / " . $maxSpectators['NextValue']);
$label->setTextColor('fff');
$quad = new Quad_Icons64x64_1();
$frame->add($quad);
$quad->setSubStyle($quad::SUBSTYLE_Camera);
$quad->setPosition(0, -1.6, 0.2);
$quad->setSize(3.3, 2.5);
// Favorite quad
$quad = new Quad_Icons64x64_1();
$frame->add($quad);
$quad->setSubStyle($quad::SUBSTYLE_StateFavourite);
$quad->setPosition($width / 2 - 4, -1.5, -0.5);
$quad->setSize(3, 3);
$quad->setManialink('maniacontrol?favorite=' . urlencode($this->maniaControl->getServer()->login));
// Send manialink
$this->maniaControl->getManialinkManager()->sendManialink($maniaLink, $login);
}
/**
* @see \ManiaControl\Plugins\Plugin::unload()
*/
public function unload() {
//Restore Siege Progression Layer
$this->maniaControl->getClient()->triggerModeScriptEvent('Siege_SetProgressionLayerPosition', array("160.", "90.", "0."));
$this->closeWidget(self::MLID_CLOCK_WIDGET);
$this->closeWidget(self::MLID_SERVERINFO_WIDGET);
$this->closeWidget(self::MLID_MAP_WIDGET);
$this->closeWidget(self::MLID_NEXTMAP_WIDGET);
}
/**
* Close a Widget
*
* @param string $widgetId
*/
public function closeWidget($widgetId) {
$this->maniaControl->getManialinkManager()->hideManialink($widgetId);
}
/**
* Handle Begin Map Callback
*/
public function handleOnBeginMap() {
if ($this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MAP_WIDGET_ACTIVATED)
) {
$this->displayMapWidget();
}
$this->closeWidget(self::MLID_NEXTMAP_WIDGET);
}
/**
* Handle End Map Callback
*/
public function handleOnEndMap() {
if ($this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_NEXTMAP_WIDGET_ACTIVATED)
) {
$this->displayNextMapWidget();
}
}
/**
* Display the Next Map (Only at the end of the Map)
*
* @param string $login
*/
public function displayNextMapWidget($login = null) {
$posX = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_NEXTMAP_WIDGET_POSX);
$posY = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_NEXTMAP_WIDGET_POSY);
$width = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_NEXTMAP_WIDGET_WIDTH);
$height = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_NEXTMAP_WIDGET_HEIGHT);
$quadStyle = $this->maniaControl->getManialinkManager()->getStyleManager()->getDefaultQuadStyle();
$quadSubstyle = $this->maniaControl->getManialinkManager()->getStyleManager()->getDefaultQuadSubstyle();
$labelStyle = $this->maniaControl->getManialinkManager()->getStyleManager()->getDefaultLabelStyle();
$maniaLink = new ManiaLink(self::MLID_NEXTMAP_WIDGET);
// mainframe
$frame = new Frame();
$maniaLink->add($frame);
$frame->setSize($width, $height);
$frame->setPosition($posX, $posY);
// Background Quad
$backgroundQuad = new Quad();
$frame->add($backgroundQuad);
$backgroundQuad->setSize($width, $height);
$backgroundQuad->setStyles($quadStyle, $quadSubstyle);
// Check if the Next Map is a queued Map
$queuedMap = $this->maniaControl->getMapManager()->getMapQueue()->getNextMap();
/**
* @var Player $requester
*/
$requester = null;
// if the nextmap is not a queued map, get it from map info
if (!$queuedMap) {
$map = $this->maniaControl->getClient()->getNextMapInfo();
$name = Formatter::stripDirtyCodes($map->name);
$author = $map->author;
} else {
$requester = $queuedMap[0];
$map = $queuedMap[1];
$name = $map->name;
$author = $map->authorLogin;
}
$label = new Label_Text();
$frame->add($label);
$label->setPosition(0, $height / 2 - 2.3, 0.2);
$label->setTextSize(1);
$label->setText('Next Map');
$label->setTextColor('fff');
$label->setStyle($labelStyle);
$label = new Label_Text();
$frame->add($label);
$label->setPosition(0, $height / 2 - 5.5, 0.2);
$label->setTextSize(1.3);
$label->setText($name);
$label->setTextColor('fff');
$label = new Label_Text();
$frame->add($label);
$label->setPosition(0, -$height / 2 + 4);
$label->setZ(0.2);
$label->setTextSize(1);
$label->setScale(0.8);
$label->setText($author);
$label->setTextColor('fff');
if ($requester) {
$label = new Label_Text();
$frame->add($label);
$label->setPosition(0, -$height / 2 + 2, 0.2);
$label->setTextSize(1);
$label->setScale(0.7);
$label->setText($author);
$label->setTextColor('f80');
$label->setText('Requested by ' . $requester->getEscapedNickname());
}
// Send manialink
$this->maniaControl->getManialinkManager()->sendManialink($maniaLink, $login);
}
/**
* Handle PlayerConnect callback
*
* @param Player $player
*/
public function handlePlayerConnect(Player $player) {
// Display Map Widget
if ($this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MAP_WIDGET_ACTIVATED)
) {
$this->displayMapWidget($player->login);
}
if ($this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_CLOCK_WIDGET_ACTIVATED)
) {
$this->displayClockWidget($player->login);
}
if ($this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_SERVERINFO_WIDGET_ACTIVATED)
) {
$this->displayServerInfoWidget();
}
}
/**
* Update Widgets on Setting Changes
*
* @param Setting $setting
*/
public function updateSettings(Setting $setting) {
if ($setting->belongsToClass($this)) {
$this->displayWIdgets();
}
}
/**
* Update Widget on certain callbacks
*/
public function updateWidgets() {
if ($this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_SERVERINFO_WIDGET_ACTIVATED)
) {
$this->displayServerInfoWidget();
}
}
}