readded team plugins with proper names
added empty files for replacing old files
This commit is contained in:
452
application/plugins/MCTeam/ChatMessagePlugin.php
Normal file
452
application/plugins/MCTeam/ChatMessagePlugin.php
Normal file
@ -0,0 +1,452 @@
|
||||
<?php
|
||||
|
||||
namespace MCTeam;
|
||||
|
||||
use ManiaControl\Commands\CommandListener;
|
||||
use ManiaControl\ManiaControl;
|
||||
use ManiaControl\Players\Player;
|
||||
use ManiaControl\Plugins\Plugin;
|
||||
use Maniaplanet\DedicatedServer\Xmlrpc\Exception;
|
||||
|
||||
/**
|
||||
* ManiaControl Chat-Message Plugin
|
||||
*
|
||||
* @author kremsy <kremsy@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;
|
||||
|
||||
/**
|
||||
* Prepares the Plugin
|
||||
*
|
||||
* @param ManiaControl $maniaControl
|
||||
* @return mixed
|
||||
*/
|
||||
public static function prepare(ManiaControl $maniaControl) {
|
||||
//do nothing
|
||||
}
|
||||
|
||||
/**
|
||||
* Get plugin id
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public static function getId() {
|
||||
return self::PLUGIN_ID;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Plugin Name
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function getName() {
|
||||
return self::PLUGIN_NAME;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Plugin Version
|
||||
*
|
||||
* @return float,,
|
||||
*/
|
||||
public static function getVersion() {
|
||||
return self::PLUGIN_VERSION;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Plugin Author
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function getAuthor() {
|
||||
return self::PLUGIN_AUTHOR;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Plugin Description
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function getDescription() {
|
||||
return "Plugin offers various Chat-Commands like /gg /hi /afk /rq...";
|
||||
}
|
||||
|
||||
/**
|
||||
* Load the plugin
|
||||
*
|
||||
* @param \ManiaControl\ManiaControl $maniaControl
|
||||
* @return bool
|
||||
*/
|
||||
public function load(ManiaControl $maniaControl) {
|
||||
$this->maniaControl = $maniaControl;
|
||||
|
||||
$this->maniaControl->commandManager->registerCommandListener('me', $this, 'chat_me', false, 'Can be used to express your feelings/ideas.');
|
||||
$this->maniaControl->commandManager->registerCommandListener('hi', $this, 'chat_hi', false, 'Writes an hello message to the chat.');
|
||||
$this->maniaControl->commandManager->registerCommandListener(array('bb', 'bye'), $this, 'chat_bye', false, 'Writes a goodbye message to the chat.');
|
||||
$this->maniaControl->commandManager->registerCommandListener('thx', $this, 'chat_thx', false, 'Writes a thanks message to the chat.');
|
||||
$this->maniaControl->commandManager->registerCommandListener('gg', $this, 'chat_gg', false, 'Writes a good game message to the chat.');
|
||||
$this->maniaControl->commandManager->registerCommandListener('gl', $this, 'chat_gl', false, 'Writes a good luck message to the chat.');
|
||||
$this->maniaControl->commandManager->registerCommandListener('hf', $this, 'chat_hf', false, 'Writes an have fun message to the chat.');
|
||||
$this->maniaControl->commandManager->registerCommandListener('glhf', $this, 'chat_glhf', false, 'Writes a good luck, have fun message to the chat.');
|
||||
$this->maniaControl->commandManager->registerCommandListener('ns', $this, 'chat_ns', false, 'Writes a nice shot message to the chat.');
|
||||
$this->maniaControl->commandManager->registerCommandListener('n1', $this, 'chat_n1', false, 'Writes a nice one message to the chat.');
|
||||
$this->maniaControl->commandManager->registerCommandListener('lol', $this, 'chat_lol', false, 'Writes a lol message to the chat.');
|
||||
$this->maniaControl->commandManager->registerCommandListener('lool', $this, 'chat_lool', false, 'Writes a lool message to the chat.');
|
||||
$this->maniaControl->commandManager->registerCommandListener('brb', $this, 'chat_brb', false, 'Writes a be right back message to the chat.');
|
||||
$this->maniaControl->commandManager->registerCommandListener('bgm', $this, 'chat_bgm', false, 'Writes a bad game for me message to the chat.');
|
||||
$this->maniaControl->commandManager->registerCommandListener('afk', $this, 'chat_afk', false, 'Writes an away from keyboard message to the chat.');
|
||||
$this->maniaControl->commandManager->registerCommandListener(array('bm', 'bootme'), $this, 'chat_bootme', false, 'Gets you away from this server quickly!');
|
||||
$this->maniaControl->commandManager->registerCommandListener(array('rq', 'ragequit'), $this, 'chat_ragequit', false, 'Gets you away from this server in rage!');
|
||||
//TODO block commandlistener for muted people
|
||||
$this->maniaControl->settingManager->initSetting($this, self::SETTING_AFK_FORCE_SPEC, true);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Unload the plugin and its resources
|
||||
*/
|
||||
public function unload() {
|
||||
$this->maniaControl->commandManager->unregisterCommandListener($this);
|
||||
unset($this->maniaControl);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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->maniaControl->chat->sendChat($msg, null, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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->maniaControl->chat->sendChat($msg, null, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 $login
|
||||
* @return mixed
|
||||
*/
|
||||
private function getTarget($login) {
|
||||
/** @var Player $player */
|
||||
$player = null;
|
||||
foreach ($this->maniaControl->playerManager->getPlayers() as $player) {
|
||||
if ($login == $player->login || $login == $player->pid || $login == $player->nickname) {
|
||||
return $player->nickname;
|
||||
}
|
||||
}
|
||||
|
||||
if ($player && $login == 'lj') {
|
||||
return $player->nickname;
|
||||
}
|
||||
|
||||
//returns the text given if nothing matches
|
||||
return $login;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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->maniaControl->chat->sendChat($msg, null, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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->maniaControl->chat->sendChat($msg, null, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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->nickname . '$>] $ff0$iGood Game $z$<' . $this->getTarget($command[1]) . '$>$i!';
|
||||
} else {
|
||||
$msg = '$ff0[$<' . $player->nickname . '$>] $ff0$iGood Game All!';
|
||||
}
|
||||
|
||||
$this->maniaControl->chat->sendChat($msg, null, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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->maniaControl->chat->sendChat($msg, null, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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->nickname . '$>] $ff0$iHave Fun $z$<' . $this->getTarget($command[1]) . '$>$i!';
|
||||
} else {
|
||||
$msg = '$ff0[$<' . $player->nickname . '$>] $ff0$iHave Fun All!';
|
||||
}
|
||||
|
||||
$this->maniaControl->chat->sendChat($msg, null, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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->maniaControl->chat->sendChat($msg, null, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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->maniaControl->chat->sendChat($msg, null, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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->maniaControl->chat->sendChat($msg, null, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Lol! Message
|
||||
*
|
||||
* @param array $chat
|
||||
* @param Player $player
|
||||
*/
|
||||
public function chat_lol(array $chat, Player $player) {
|
||||
$msg = '$ff0[$<' . $player->nickname . '$>] $ff0$iLoL!';
|
||||
$this->maniaControl->chat->sendChat($msg, null, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* LooOOooL! Message
|
||||
*
|
||||
* @param array $chat
|
||||
* @param Player $player
|
||||
*/
|
||||
public function chat_lool(array $chat, Player $player) {
|
||||
$msg = '$ff0[$<' . $player->nickname . '$>] $ff0$iLooOOooL!';
|
||||
$this->maniaControl->chat->sendChat($msg, null, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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->maniaControl->chat->sendChat($msg, null, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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->maniaControl->chat->sendChat($msg, null, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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->maniaControl->chat->sendChat($msg, null, true);
|
||||
|
||||
$message = '$39F Thanks for Playing, see you around!$z';
|
||||
try {
|
||||
$this->maniaControl->client->kick($player->login, $message);
|
||||
} catch (Exception $e) {
|
||||
$this->maniaControl->errorHandler->triggerDebugNotice("ChatMessagePlugin Debug Line 316: " . $e->getMessage());
|
||||
// TODO: only possible valid exception should be "wrong login" - throw others (like connection error)
|
||||
$this->maniaControl->chat->sendError('Error occurred: ' . $e->getMessage(), $player->login);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Leave the server with an Ragequit
|
||||
*
|
||||
* @param array $chat
|
||||
* @param Player $player
|
||||
*/
|
||||
public function chat_ragequit(array $chat, Player $player) {
|
||||
$msg = '$i$ff0 $<' . $player->nickname . '$>$s$f00 said: "@"#!" and ragequitted!';
|
||||
$this->maniaControl->chat->sendChat($msg, null, true);
|
||||
|
||||
$message = '$39F Thanks for Playing, please come back soon!$z ';
|
||||
try {
|
||||
$this->maniaControl->client->kick($player->login, $message);
|
||||
} catch (Exception $e) {
|
||||
$this->maniaControl->errorHandler->triggerDebugNotice("ChatMessagePlugin Debug Line " . $e->getLine() . ": " . $e->getMessage());
|
||||
// TODO: only possible valid exception should be "wrong login" - throw others (like connection error)
|
||||
$this->maniaControl->chat->sendError('Error occurred: ' . $e->getMessage(), $player->login);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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->maniaControl->chat->sendChat($msg, null, false);
|
||||
|
||||
if ($this->maniaControl->settingManager->getSetting($this, self::SETTING_AFK_FORCE_SPEC)) {
|
||||
if ($player->isSpectator) {
|
||||
return;
|
||||
}
|
||||
|
||||
// force into spec
|
||||
try {
|
||||
$this->maniaControl->client->forceSpectator($player->login, 3);
|
||||
} catch (Exception $e) {
|
||||
$this->maniaControl->errorHandler->triggerDebugNotice("ChatMessagePlugin Debug Line " . $e->getLine() . ": " . $e->getMessage());
|
||||
// TODO: only possible valid exception should be "wrong login" - throw others (like connection error)
|
||||
$this->maniaControl->chat->sendError('Error occurred: ' . $e->getMessage(), $player->login);
|
||||
return;
|
||||
}
|
||||
|
||||
// free player slot
|
||||
try {
|
||||
$this->maniaControl->client->spectatorReleasePlayerSlot($player->login);
|
||||
} catch (Exception $e) {
|
||||
if ($e->getMessage() != 'The player is not a spectator') {
|
||||
$this->maniaControl->errorHandler->triggerDebugNotice("ChatMessagePlugin Debug Line " . $e->getLine() . ": " . $e->getMessage());
|
||||
// TODO: only possible valid exception should be "wrong login" - throw others (like connection error)
|
||||
//to nothing
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
868
application/plugins/MCTeam/CustomVotesPlugin.php
Normal file
868
application/plugins/MCTeam/CustomVotesPlugin.php
Normal file
@ -0,0 +1,868 @@
|
||||
<?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 ManiaControl\Callbacks\CallbackListener;
|
||||
use ManiaControl\Callbacks\CallbackManager;
|
||||
use ManiaControl\Callbacks\TimerListener;
|
||||
use ManiaControl\ColorUtil;
|
||||
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\Server;
|
||||
use ManiaControl\Server\ServerCommands;
|
||||
use Maniaplanet\DedicatedServer\Structures\VoteRatio;
|
||||
use Maniaplanet\DedicatedServer\Xmlrpc\NotInScriptModeException;
|
||||
use FML\Script\Features\KeyAction;
|
||||
|
||||
|
||||
/**
|
||||
* ManiaControl Custom-Votes Plugin
|
||||
*
|
||||
* @author kremsy
|
||||
* @copyright ManiaControl 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 Specators to vote';
|
||||
const SETTING_SPECTATOR_ALLOW_START_VOTE = 'Allow Specators 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;
|
||||
|
||||
/**
|
||||
* Prepares the Plugin
|
||||
*
|
||||
* @param ManiaControl $maniaControl
|
||||
* @return mixed
|
||||
*/
|
||||
public static function prepare(ManiaControl $maniaControl) {
|
||||
//do nothing
|
||||
}
|
||||
|
||||
/**
|
||||
* Load the plugin
|
||||
*
|
||||
* @param \ManiaControl\ManiaControl $maniaControl
|
||||
* @return bool
|
||||
*/
|
||||
public function load(ManiaControl $maniaControl) {
|
||||
$this->maniaControl = $maniaControl;
|
||||
|
||||
$this->maniaControl->commandManager->registerCommandListener('vote', $this, 'chat_vote', false, 'Starts a new vote.');
|
||||
$this->maniaControl->timerManager->registerTimerListening($this, 'handle1Second', 1000);
|
||||
$this->maniaControl->callbackManager->registerCallbackListener(ServerCommands::CB_VOTE_CANCELED, $this, 'handleVoteCanceled');
|
||||
$this->maniaControl->manialinkManager->registerManialinkPageAnswerListener(self::ACTION_POSITIVE_VOTE, $this, 'handlePositiveVote');
|
||||
$this->maniaControl->manialinkManager->registerManialinkPageAnswerListener(self::ACTION_NEGATIVE_VOTE, $this, 'handleNegativeVote');
|
||||
|
||||
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MP_PLAYERMANIALINKPAGEANSWER, $this, 'handleManialinkPageAnswer');
|
||||
$this->maniaControl->callbackManager->registerCallbackListener(self::CB_CUSTOM_VOTE_FINISHED, $this, 'handleVoteFinished');
|
||||
$this->maniaControl->callbackManager->registerCallbackListener(PlayerManager::CB_PLAYERCONNECT, $this, 'handlePlayerConnect');
|
||||
$this->maniaControl->callbackManager->registerCallbackListener(Server::CB_TEAM_MODE_CHANGED, $this, 'constructMenu');
|
||||
|
||||
//Settings
|
||||
$this->maniaControl->settingManager->initSetting($this, self::SETTING_VOTE_ICON_POSX, 156.);
|
||||
$this->maniaControl->settingManager->initSetting($this, self::SETTING_VOTE_ICON_POSY, -38.6);
|
||||
$this->maniaControl->settingManager->initSetting($this, self::SETTING_VOTE_ICON_WIDTH, 6);
|
||||
$this->maniaControl->settingManager->initSetting($this, self::SETTING_VOTE_ICON_HEIGHT, 6);
|
||||
|
||||
$this->maniaControl->settingManager->initSetting($this, self::SETTING_WIDGET_POSX, -80); //160 -15
|
||||
$this->maniaControl->settingManager->initSetting($this, self::SETTING_WIDGET_POSY, 80); //-15
|
||||
$this->maniaControl->settingManager->initSetting($this, self::SETTING_WIDGET_WIDTH, 50); //30
|
||||
$this->maniaControl->settingManager->initSetting($this, self::SETTING_WIDGET_HEIGHT, 20); //25
|
||||
|
||||
$this->maniaControl->settingManager->initSetting($this, self::SETTING_DEFAULT_RATIO, 0.75);
|
||||
$this->maniaControl->settingManager->initSetting($this, self::SETTING_DEFAULT_PLAYER_RATIO, 0.65);
|
||||
$this->maniaControl->settingManager->initSetting($this, self::SETTING_SPECTATOR_ALLOW_VOTE, false);
|
||||
$this->maniaControl->settingManager->initSetting($this, self::SETTING_SPECTATOR_ALLOW_START_VOTE, false);
|
||||
$this->maniaControl->settingManager->initSetting($this, self::SETTING_VOTE_TIME, 60);
|
||||
|
||||
//Define Votes
|
||||
$this->defineVote("teambalance", "Vote for Team Balance");
|
||||
$this->defineVote("skipmap", "Vote for Skip Map");
|
||||
$this->defineVote("nextmap", "Vote for Skip Map");
|
||||
$this->defineVote("skip", "Vote for Skip Map");
|
||||
$this->defineVote("restartmap", "Vote for Restart Map");
|
||||
$this->defineVote("restart", "Vote for Restart Map");
|
||||
$this->defineVote("pausegame", "Vote for Pause Game");
|
||||
$this->defineVote("replay", "Vote to replay current map");
|
||||
|
||||
foreach($this->voteCommands as $name => $voteCommand) {
|
||||
$this->maniaControl->commandManager->registerCommandListener($name, $this, 'handleChatVote', false, $voteCommand->name);
|
||||
}
|
||||
|
||||
/* Disable Standard Votes */
|
||||
$array["Command"] = VoteRatio::COMMAND_BAN;
|
||||
$array["Param"] = "";
|
||||
$array["Ratio"] = (float)-1;
|
||||
$ratioArray[] = $array;
|
||||
|
||||
$array["Command"] = VoteRatio::COMMAND_KICK;
|
||||
$ratioArray[] = $array;
|
||||
|
||||
$array["Command"] = VoteRatio::COMMAND_RESTART_MAP;
|
||||
$ratioArray[] = $array;
|
||||
|
||||
$array["Command"] = VoteRatio::COMMAND_TEAM_BALANCE;
|
||||
$ratioArray[] = $array;
|
||||
|
||||
$array["Command"] = VoteRatio::COMMAND_NEXT_MAP;
|
||||
$ratioArray[] = $array;
|
||||
|
||||
$this->maniaControl->client->setCallVoteRatiosEx(false, $ratioArray);
|
||||
|
||||
$this->constructMenu();
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Unload the plugin and its resources
|
||||
*/
|
||||
public function unload() {
|
||||
//Enable Standard Votes
|
||||
$defaultRatio = $this->maniaControl->client->getCallVoteRatio();
|
||||
|
||||
$array["Command"] = VoteRatio::COMMAND_BAN;
|
||||
$array["Param"] = "";
|
||||
$array["Ratio"] = (float)$defaultRatio;
|
||||
$ratioArray[] = $array;
|
||||
$array["Command"] = VoteRatio::COMMAND_KICK;
|
||||
$ratioArray[] = $array;
|
||||
$array["Command"] = VoteRatio::COMMAND_RESTART_MAP;
|
||||
$ratioArray[] = $array;
|
||||
$array["Command"] = VoteRatio::COMMAND_TEAM_BALANCE;
|
||||
$ratioArray[] = $array;
|
||||
$array["Command"] = VoteRatio::COMMAND_NEXT_MAP;
|
||||
$ratioArray[] = $array;
|
||||
|
||||
$this->maniaControl->client->setCallVoteRatiosEx(false, $ratioArray);
|
||||
|
||||
$this->destroyVote();
|
||||
$emptyManialink = new ManiaLink(self::MLID_ICON);
|
||||
$this->maniaControl->manialinkManager->sendManialink($emptyManialink);
|
||||
$this->maniaControl->commandManager->unregisterCommandListener($this);
|
||||
$this->maniaControl->callbackManager->unregisterCallbackListener($this);
|
||||
$this->maniaControl->manialinkManager->unregisterManialinkPageAnswerListener($this);
|
||||
$this->maniaControl->timerManager->unregisterTimerListenings($this);
|
||||
unset($this->maniaControl);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle PlayerConnect callback
|
||||
*
|
||||
* @param Player $player
|
||||
*/
|
||||
public function handlePlayerConnect(Player $player) {
|
||||
$this->showIcon($player->login);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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->client->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(NotInScriptModeException $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 Mapskip');
|
||||
|
||||
if ($this->maniaControl->server->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();
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroy the Vote on Canceled Callback
|
||||
*
|
||||
* @param Player $player
|
||||
*/
|
||||
public function handleVoteCanceled(Player $player) {
|
||||
//reset vote
|
||||
$this->destroyVote();
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle Standard Votes
|
||||
*
|
||||
* @param $voteName
|
||||
* @param $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->client->autoTeamBalance();
|
||||
$this->maniaControl->chat->sendInformation('$f8fVote to $fffbalance the teams$f8f has been successfull!');
|
||||
break;
|
||||
case 'skipmap':
|
||||
case 'skip':
|
||||
case 'nextmap':
|
||||
$this->maniaControl->client->nextMap();
|
||||
$this->maniaControl->chat->sendInformation('$f8fVote to $fffskip the map$f8f has been successfull!');
|
||||
break;
|
||||
case 'restartmap':
|
||||
$this->maniaControl->client->restartMap();
|
||||
$this->maniaControl->chat->sendInformation('$f8fVote to $fffrestart the map$f8f has been successfull!');
|
||||
break;
|
||||
case 'pausegame':
|
||||
$this->maniaControl->client->sendModeScriptCommands(array('Command_ForceWarmUp' => True));
|
||||
$this->maniaControl->chat->sendInformation('$f8fVote to $fffpause the current game$f8f has been successfull!');
|
||||
break;
|
||||
case 'replay':
|
||||
$this->maniaControl->mapManager->mapQueue->addFirstMapToMapQueue($this->currentVote->voter, $this->maniaControl->mapManager->getCurrentMap());
|
||||
$this->maniaControl->chat->sendInformation('$f8fVote to $fffreplay the map$f8f has been successfull!');
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
$this->maniaControl->chat->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->playerManager->getPlayer($login);
|
||||
$this->startVote($player, $voteIndex);
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Defines a Vote
|
||||
*
|
||||
* @param $voteIndex
|
||||
* @param $voteName
|
||||
* @param bool $idBased
|
||||
* @param $neededRatio
|
||||
*/
|
||||
public function defineVote($voteIndex, $voteName, $idBased = false, $startText = '', $neededRatio = -1) {
|
||||
if ($neededRatio == -1) {
|
||||
$neededRatio = $this->maniaControl->settingManager->getSetting($this, self::SETTING_DEFAULT_RATIO);
|
||||
}
|
||||
$voteCommand = new VoteCommand($voteIndex, $voteName, $idBased, $neededRatio);
|
||||
$voteCommand->startText = $startText;
|
||||
$this->voteCommands[$voteIndex] = $voteCommand;
|
||||
}
|
||||
|
||||
/**
|
||||
* Undefines a Vote
|
||||
*
|
||||
* @param $voteIndex
|
||||
*/
|
||||
public function undefineVote($voteIndex) {
|
||||
unset($this->voteCommands[$voteIndex]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Starts a vote
|
||||
*
|
||||
* @param \ManiaControl\Players\Player $player
|
||||
* @param $voteIndex
|
||||
* @param $action
|
||||
*/
|
||||
public function startVote(Player $player, $voteIndex, $function = null) {
|
||||
//Player is muted
|
||||
if ($this->maniaControl->playerManager->playerActions->isPlayerMuted($player)) {
|
||||
$this->maniaControl->chat->sendError('Muted Players are not allowed to start a vote.', $player->login);
|
||||
return;
|
||||
}
|
||||
|
||||
//Specators are not allowed to start a vote
|
||||
if ($player->isSpectator && !$this->maniaControl->settingManager->getSetting($this, self::SETTING_SPECTATOR_ALLOW_START_VOTE)) {
|
||||
$this->maniaControl->chat->sendError('Spectators are not allowed to start a vote.', $player->login);
|
||||
return;
|
||||
}
|
||||
|
||||
//Vote does not exist
|
||||
if (!isset($this->voteCommands[$voteIndex])) {
|
||||
$this->maniaControl->chat->sendError('Undefined vote.', $player->login);
|
||||
return;
|
||||
}
|
||||
|
||||
//A vote is currently running
|
||||
if (isset($this->currentVote)) {
|
||||
$this->maniaControl->chat->sendError('There is currently another vote running.', $player->login);
|
||||
return;
|
||||
}
|
||||
|
||||
$maxTime = $this->maniaControl->settingManager->getSetting($this, self::SETTING_VOTE_TIME);
|
||||
|
||||
$this->currentVote = $this->voteCommands[$voteIndex];
|
||||
|
||||
$this->currentVote = new CurrentVote($this->voteCommands[$voteIndex], $player, time() + $maxTime);
|
||||
$this->currentVote->neededRatio = floatval($this->maniaControl->settingManager->getSetting($this, self::SETTING_DEFAULT_RATIO));
|
||||
$this->currentVote->neededPlayerRatio = floatval($this->maniaControl->settingManager->getSetting($this, self::SETTING_DEFAULT_PLAYER_RATIO));
|
||||
$this->currentVote->function = $function;
|
||||
|
||||
if ($this->currentVote->voteCommand->startText != '') {
|
||||
$message = $this->currentVote->voteCommand->startText;
|
||||
} else {
|
||||
$message = '$fff$<' . $player->nickname . '$>$s$f8f started a $fff$<' . $this->currentVote->voteCommand->name . '$>$f8f!';
|
||||
}
|
||||
|
||||
$this->maniaControl->chat->sendSuccess($message);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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->settingManager->getSetting($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->settingManager->getSetting($this, self::SETTING_SPECTATOR_ALLOW_VOTE)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->currentVote->voteNegative($player->login);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle ManiaControl 1 Second callback
|
||||
*
|
||||
* @param $time
|
||||
*/
|
||||
public function handle1Second($time) {
|
||||
if (!isset($this->currentVote)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$votePercentage = $this->currentVote->positiveVotes / $this->currentVote->getVoteCount();
|
||||
|
||||
$timeUntilExpire = $this->currentVote->expireTime - time();
|
||||
$this->showVoteWidget($timeUntilExpire, $votePercentage);
|
||||
|
||||
$playerCount = $this->maniaControl->playerManager->getPlayerCount();
|
||||
$playersVoteRatio = (100 / $playerCount * $this->currentVote->getVoteCount()) / 100;
|
||||
|
||||
//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->callbackManager->triggerCallback(self::CB_CUSTOM_VOTE_FINISHED, $this->currentVote->voteCommand->index, $votePercentage);
|
||||
|
||||
//reset vote
|
||||
$this->destroyVote();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroys the current Vote
|
||||
*/
|
||||
private function destroyVote() {
|
||||
$emptyManialink = new ManiaLink(self::MLID_WIDGET);
|
||||
$this->maniaControl->manialinkManager->sendManialink($emptyManialink);
|
||||
|
||||
unset($this->currentVote);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows the vote widget
|
||||
*
|
||||
* @param $timeUntilExpire
|
||||
* @param $votePercentage
|
||||
*/
|
||||
private function showVoteWidget($timeUntilExpire, $votePercentage) {
|
||||
$pos_x = $this->maniaControl->settingManager->getSetting($this, self::SETTING_WIDGET_POSX);
|
||||
$pos_y = $this->maniaControl->settingManager->getSetting($this, self::SETTING_WIDGET_POSY);
|
||||
$width = $this->maniaControl->settingManager->getSetting($this, self::SETTING_WIDGET_WIDTH);
|
||||
$height = $this->maniaControl->settingManager->getSetting($this, self::SETTING_WIDGET_HEIGHT);
|
||||
$maxTime = $this->maniaControl->settingManager->getSetting($this, self::SETTING_VOTE_TIME);
|
||||
|
||||
$quadStyle = $this->maniaControl->manialinkManager->styleManager->getDefaultQuadStyle();
|
||||
$quadSubstyle = $this->maniaControl->manialinkManager->styleManager->getDefaultQuadSubstyle();
|
||||
$labelStyle = $this->maniaControl->manialinkManager->styleManager->getDefaultLabelStyle();
|
||||
|
||||
$maniaLink = new ManiaLink(self::MLID_WIDGET);
|
||||
|
||||
// mainframe
|
||||
$frame = new Frame();
|
||||
$maniaLink->add($frame);
|
||||
$frame->setSize($width, $height);
|
||||
$frame->setPosition($pos_x, $pos_y, 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->setAlign(Control::CENTER, Control::CENTER);
|
||||
$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->setAlign(Control::CENTER, Control::CENTER);
|
||||
$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->setAlign(Control::CENTER, Control::CENTER);
|
||||
$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');
|
||||
|
||||
$y = -4.4;
|
||||
$voteLabel = new Label();
|
||||
$frame->add($voteLabel);
|
||||
$voteLabel->setY($y);
|
||||
$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, $y);
|
||||
$positiveQuad->setSubStyle($positiveQuad::SUBSTYLE_BgPlayerCardBig);
|
||||
$positiveQuad->setSize(5, 5);
|
||||
|
||||
$positiveLabel = new Label_Button();
|
||||
$frame->add($positiveLabel);
|
||||
$positiveLabel->setPosition(-$width / 2 + 6, $y);
|
||||
$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->manialinkManager->sendManialink($maniaLink);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows the Icon Widget
|
||||
*
|
||||
* @param bool $login
|
||||
*/
|
||||
private function showIcon($login = false) {
|
||||
$posX = $this->maniaControl->settingManager->getSetting($this, self::SETTING_VOTE_ICON_POSX);
|
||||
$posY = $this->maniaControl->settingManager->getSetting($this, self::SETTING_VOTE_ICON_POSY);
|
||||
$width = $this->maniaControl->settingManager->getSetting($this, self::SETTING_VOTE_ICON_WIDTH);
|
||||
$height = $this->maniaControl->settingManager->getSetting($this, self::SETTING_VOTE_ICON_HEIGHT);
|
||||
$shootManiaOffset = $this->maniaControl->manialinkManager->styleManager->getDefaultIconOffsetSM();
|
||||
$quadStyle = $this->maniaControl->manialinkManager->styleManager->getDefaultQuadStyle();
|
||||
$quadSubstyle = $this->maniaControl->manialinkManager->styleManager->getDefaultQuadSubstyle();
|
||||
$itemMarginFactorX = 1.3;
|
||||
$itemMarginFactorY = 1.2;
|
||||
|
||||
//If game is shootmania lower the icons position by 20
|
||||
if($this->maniaControl->mapManager->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(Control::RIGHT, Control::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(Control::RIGHT);
|
||||
$popoutFrame->setSize(4 * $itemSize * $itemMarginFactorX, $itemSize * $itemMarginFactorY);
|
||||
$popoutFrame->setVisible(false);
|
||||
|
||||
$backgroundQuad = new Quad();
|
||||
$popoutFrame->add($backgroundQuad);
|
||||
$backgroundQuad->setHAlign(Control::RIGHT);
|
||||
$backgroundQuad->setStyles($quadStyle, $quadSubstyle);
|
||||
$backgroundQuad->setSize($menuEntries * $itemSize * 1.15 + 2, $itemSize * $itemMarginFactorY);
|
||||
|
||||
$itemQuad->addToggleFeature($popoutFrame);
|
||||
|
||||
// Add items
|
||||
$x = -1;
|
||||
foreach($this->voteMenuItems as $menuItems) {
|
||||
foreach($menuItems as $menuItem) {
|
||||
$menuQuad = $menuItem[0];
|
||||
/**
|
||||
* @var Quad $menuQuad
|
||||
*/
|
||||
$popoutFrame->add($menuQuad);
|
||||
$menuQuad->setSize($itemSize, $itemSize);
|
||||
$menuQuad->setX($x);
|
||||
$menuQuad->setHAlign(Control::RIGHT);
|
||||
$x -= $itemSize * 1.05;
|
||||
|
||||
if ($menuItem[1]) {
|
||||
$menuQuad->removeScriptFeatures();
|
||||
$description = '$s' . $menuItem[1];
|
||||
$menuQuad->addTooltipLabelFeature($descriptionLabel, $description);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Send manialink
|
||||
$this->maniaControl->manialinkManager->sendManialink($maniaLink, $login);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get plugin id
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public static function getId() {
|
||||
return self::PLUGIN_ID;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Plugin Name
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function getName() {
|
||||
return self::PLUGIN_NAME;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Plugin Version
|
||||
*
|
||||
* @return float,,
|
||||
*/
|
||||
public static function getVersion() {
|
||||
return self::PLUGIN_VERSION;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Plugin Author
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function getAuthor() {
|
||||
return self::PLUGIN_AUTHOR;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Plugin Description
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function getDescription() {
|
||||
return 'Plugin offers your Custom Votes like Restart, Skip, Balance...';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Vote Command Structure
|
||||
*/
|
||||
class VoteCommand {
|
||||
public $index = '';
|
||||
public $name = '';
|
||||
public $neededRatio = 0;
|
||||
public $idBased = false;
|
||||
public $startText = '';
|
||||
|
||||
public function __construct($index, $name, $idBased, $neededRatio) {
|
||||
$this->index = $index;
|
||||
$this->name = $name;
|
||||
$this->idBased = $idBased;
|
||||
$this->neededRatio = $neededRatio;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Current Vote Structure
|
||||
*/
|
||||
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;
|
||||
|
||||
private $playersVoted = array();
|
||||
|
||||
public function __construct(VoteCommand $voteCommand, Player $voter, $expireTime) {
|
||||
$this->expireTime = $expireTime;
|
||||
$this->voteCommand = $voteCommand;
|
||||
$this->voter = $voter;
|
||||
$this->votePositive($voter->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++;
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
public function getVoteCount() {
|
||||
return count($this->playersVoted);
|
||||
}
|
||||
|
||||
}
|
556
application/plugins/MCTeam/DonationPlugin.php
Normal file
556
application/plugins/MCTeam/DonationPlugin.php
Normal file
@ -0,0 +1,556 @@
|
||||
<?php
|
||||
|
||||
namespace MCTeam;
|
||||
|
||||
use FML\Controls\Control;
|
||||
use FML\Controls\Frame;
|
||||
use FML\Controls\Label;
|
||||
use FML\Controls\Labels\Label_Button;
|
||||
use FML\Controls\Labels\Label_Text;
|
||||
use FML\Controls\Quad;
|
||||
use FML\Controls\Quads\Quad_BgsPlayerCard;
|
||||
use FML\Controls\Quads\Quad_Icons128x128_1;
|
||||
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;
|
||||
use ManiaControl\Statistics\StatisticManager;
|
||||
|
||||
/**
|
||||
* ManiaControl Donation Plugin
|
||||
*
|
||||
* @author kremsy and steeffeen
|
||||
* @copyright ManiaControl 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 SETTING_ANNOUNCE_SERVERDONATION = '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;
|
||||
|
||||
/**
|
||||
* Prepares the Plugin
|
||||
*
|
||||
* @param ManiaControl $maniaControl
|
||||
* @return mixed
|
||||
*/
|
||||
public static function prepare(ManiaControl $maniaControl) {
|
||||
//do nothing
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @see \ManiaControl\Plugins\Plugin::load()
|
||||
*/
|
||||
public function load(ManiaControl $maniaControl) {
|
||||
$this->maniaControl = $maniaControl;
|
||||
|
||||
// Register for commands
|
||||
$this->maniaControl->commandManager->registerCommandListener('donate', $this, 'command_Donate', false, 'Donate some planets to the server.');
|
||||
$this->maniaControl->commandManager->registerCommandListener('pay', $this, 'command_Pay', true, 'Pays planets from the server to a player.');
|
||||
$this->maniaControl->commandManager->registerCommandListener('planets', $this, 'command_GetPlanets', true, 'Checks the planets-balance of the server.');
|
||||
$this->maniaControl->commandManager->registerCommandListener('topdons', $this, 'command_TopDons', false, 'Provides an overview of who dontated the most planets.');
|
||||
|
||||
// Register for callbacks
|
||||
$this->maniaControl->callbackManager->registerCallbackListener(PlayerManager::CB_PLAYERCONNECT, $this, 'handlePlayerConnect');
|
||||
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MP_PLAYERMANIALINKPAGEANSWER, $this, 'handleManialinkPageAnswer');
|
||||
|
||||
// Define player stats
|
||||
$this->maniaControl->statisticManager->defineStatMetaData(self::STAT_PLAYER_DONATIONS);
|
||||
|
||||
$this->maniaControl->settingManager->initSetting($this, self::SETTING_DONATE_WIDGET_ACTIVATED, true);
|
||||
$this->maniaControl->settingManager->initSetting($this, self::SETTING_DONATE_WIDGET_POSX, 156.);
|
||||
$this->maniaControl->settingManager->initSetting($this, self::SETTING_DONATE_WIDGET_POSY, -31.4);
|
||||
$this->maniaControl->settingManager->initSetting($this, self::SETTING_DONATE_WIDGET_WIDTH, 6);
|
||||
$this->maniaControl->settingManager->initSetting($this, self::SETTING_DONATE_WIDGET_HEIGHT, 6);
|
||||
$this->maniaControl->settingManager->initSetting($this, self::SETTING_DONATION_VALUES, "20,50,100,500,1000,2000");
|
||||
$this->maniaControl->settingManager->initSetting($this, self::SETTING_MIN_AMOUNT_SHOWN, 100);
|
||||
|
||||
// Register Stat in Simple StatsList
|
||||
$this->maniaControl->statisticManager->simpleStatsList->registerStat(self::STAT_PLAYER_DONATIONS, 90, "DP", 15);
|
||||
|
||||
$this->displayWidget();
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see \ManiaControl\Plugins\Plugin::unload()
|
||||
*/
|
||||
public function unload() {
|
||||
$emptyManialink = new ManiaLink(self::MLID_DONATE_WIDGET);
|
||||
$this->maniaControl->manialinkManager->sendManialink($emptyManialink);
|
||||
|
||||
$this->maniaControl->callbackManager->unregisterCallbackListener($this);
|
||||
$this->maniaControl->commandManager->unregisterCommandListener($this);
|
||||
unset($this->maniaControl);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see \ManiaControl\Plugins\Plugin::getId()
|
||||
*/
|
||||
public static function getId() {
|
||||
return self::ID;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see \ManiaControl\Plugins\Plugin::getName()
|
||||
*/
|
||||
public static function getName() {
|
||||
return 'Donations Plugin';
|
||||
}
|
||||
|
||||
/**
|
||||
* @see \ManiaControl\Plugins\Plugin::getVersion()
|
||||
*/
|
||||
public static function getVersion() {
|
||||
return self::VERSION;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see \ManiaControl\Plugins\Plugin::getAuthor()
|
||||
*/
|
||||
public static function getAuthor() {
|
||||
return 'steeffeen and kremsy';
|
||||
}
|
||||
|
||||
/**
|
||||
* @see \ManiaControl\Plugins\Plugin::getDescription()
|
||||
*/
|
||||
public static function getDescription() {
|
||||
return 'Plugin offering commands like /donate, /pay and /planets and a donation widget.';
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle ManiaControl OnStartup
|
||||
*
|
||||
* @param array $callback
|
||||
*/
|
||||
public function displayWidget() {
|
||||
if ($this->maniaControl->settingManager->getSetting($this, self::SETTING_DONATE_WIDGET_ACTIVATED)) {
|
||||
$this->displayDonateWidget();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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->playerManager->getPlayer($login);
|
||||
$actionArray = explode(".", $callback[1][2]);
|
||||
$this->handleDonation($player, intval($actionArray[2]));
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle PlayerConnect callback
|
||||
*
|
||||
* @param Player $player
|
||||
*/
|
||||
public function handlePlayerConnect(Player $player) {
|
||||
// Display Map Widget
|
||||
if ($this->maniaControl->settingManager->getSetting($this, self::SETTING_DONATE_WIDGET_ACTIVATED)) {
|
||||
$this->displayDonateWidget($player->login);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays the Donate Widget
|
||||
*
|
||||
* @param bool $login
|
||||
*/
|
||||
public function displayDonateWidget($login = false) {
|
||||
$posX = $this->maniaControl->settingManager->getSetting($this, self::SETTING_DONATE_WIDGET_POSX);
|
||||
$posY = $this->maniaControl->settingManager->getSetting($this, self::SETTING_DONATE_WIDGET_POSY);
|
||||
$width = $this->maniaControl->settingManager->getSetting($this, self::SETTING_DONATE_WIDGET_WIDTH);
|
||||
$height = $this->maniaControl->settingManager->getSetting($this, self::SETTING_DONATE_WIDGET_HEIGHT);
|
||||
$values = $this->maniaControl->settingManager->getSetting($this, self::SETTING_DONATION_VALUES);
|
||||
$shootManiaOffset = $this->maniaControl->manialinkManager->styleManager->getDefaultIconOffsetSM();
|
||||
$quadStyle = $this->maniaControl->manialinkManager->styleManager->getDefaultQuadStyle();
|
||||
$quadSubstyle = $this->maniaControl->manialinkManager->styleManager->getDefaultQuadSubstyle();
|
||||
$itemMarginFactorX = 1.3;
|
||||
$itemMarginFactorY = 1.2;
|
||||
|
||||
//If game is shootmania lower the icons position by 20
|
||||
if($this->maniaControl->mapManager->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_Icons128x128_1();
|
||||
$itemQuad->setSubStyle($itemQuad::SUBSTYLE_Coppers);
|
||||
$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(Control::RIGHT);
|
||||
$popoutFrame->setSize(4 * $itemSize * $itemMarginFactorX, $itemSize * $itemMarginFactorY);
|
||||
$popoutFrame->setVisible(false);
|
||||
|
||||
$quad = new Quad();
|
||||
$popoutFrame->add($quad);
|
||||
$quad->setHAlign(Control::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(Control::RIGHT);
|
||||
|
||||
$descriptionLabel = new Label();
|
||||
$descriptionFrame->add($descriptionLabel);
|
||||
$descriptionLabel->setAlign(Control::LEFT, Control::TOP);
|
||||
$descriptionLabel->setSize(40, 4);
|
||||
$descriptionLabel->setTextSize(2);
|
||||
$descriptionLabel->setVisible(true);
|
||||
$descriptionLabel->setTextColor("0F0");
|
||||
|
||||
// Add items
|
||||
$x = -2;
|
||||
foreach(array_reverse($valueArray) as $value) {
|
||||
$label = new Label_Button();
|
||||
$popoutFrame->add($label);
|
||||
$label->setX($x);
|
||||
$label->setHAlign(Control::RIGHT);
|
||||
$label->setText('$s$FFF' . $value . '$09FP');
|
||||
$label->setTextSize(1.2);
|
||||
$label->setAction(self::ACTION_DONATE_VALUE . "." . $value);
|
||||
$label->setStyle(Label_Text::STYLE_TextCardSmall);
|
||||
$description = "Donate {$value} Planets";
|
||||
$label->addTooltipLabelFeature($descriptionLabel, $description);
|
||||
|
||||
$x -= strlen($value) * 2 + 1.7;
|
||||
}
|
||||
|
||||
// Send manialink
|
||||
$this->maniaControl->manialinkManager->sendManialink($maniaLink, $login);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle /donate command
|
||||
*
|
||||
* @param array $chatCallback
|
||||
* @param Player $player
|
||||
* @return bool
|
||||
*/
|
||||
public function command_Donate(array $chatCallback, Player $player) {
|
||||
$text = $chatCallback[1][2];
|
||||
$params = explode(' ', $text);
|
||||
if (count($params) < 2) {
|
||||
$this->sendDonateUsageExample($player);
|
||||
return false;
|
||||
}
|
||||
$amount = (int)$params[1];
|
||||
if (!$amount || $amount <= 0) {
|
||||
$this->sendDonateUsageExample($player);
|
||||
return false;
|
||||
}
|
||||
if (count($params) >= 3) {
|
||||
$receiver = $params[2];
|
||||
$receiverPlayer = $this->maniaControl->playerManager->getPlayer($receiver);
|
||||
$receiverName = ($receiverPlayer ? $receiverPlayer->nickname : $receiver);
|
||||
} else {
|
||||
$receiver = '';
|
||||
$receiverName = $this->maniaControl->client->getServerName();
|
||||
}
|
||||
|
||||
return $this->handleDonation($player, $amount, $receiver, $receiverName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles a Player Donate
|
||||
*
|
||||
* @param Player $player
|
||||
* @param $value
|
||||
*/
|
||||
private function handleDonation(Player $player, $amount, $receiver = '', $receiverName = false) {
|
||||
|
||||
if (!$receiverName) {
|
||||
$serverName = $this->maniaControl->client->getServerName();
|
||||
$message = 'Donate ' . $amount . ' Planets to $<' . $serverName . '$>?';
|
||||
} else {
|
||||
$message = 'Donate ' . $amount . ' Planets to $<' . $receiverName . '$>?';
|
||||
}
|
||||
|
||||
//Send and Handle the Bill
|
||||
$self = $this;
|
||||
$this->maniaControl->billManager->sendBill(function ($data, $status) use (&$self, &$player, $amount, $receiver) {
|
||||
switch($status) {
|
||||
case BillManager::DONATED_TO_SERVER:
|
||||
if ($self->maniaControl->settingManager->getSetting($self, DonationPlugin::SETTING_ANNOUNCE_SERVERDONATION, true) && $amount >= $self->maniaControl->settingManager->getSetting($self, DonationPlugin::SETTING_MIN_AMOUNT_SHOWN, true)) {
|
||||
$login = null;
|
||||
$message = '$<' . $player->nickname . '$> donated ' . $amount . ' Planets! Thanks.';
|
||||
} else {
|
||||
$login = $player->login;
|
||||
$message = 'Donation successful! Thanks.';
|
||||
}
|
||||
$self->maniaControl->chat->sendSuccess($message, $login);
|
||||
$self->maniaControl->statisticManager->insertStat(DonationPlugin::STAT_PLAYER_DONATIONS, $player, $self->maniaControl->server->index, $amount);
|
||||
break;
|
||||
case BillManager::DONATED_TO_RECEIVER:
|
||||
$message = "Successfully donated {$amount} to '{$receiver}'!";
|
||||
$self->maniaControl->chat->sendSuccess($message, $player->login);
|
||||
break;
|
||||
case BillManager::PLAYER_REFUSED_DONATION:
|
||||
$message = 'Transaction cancelled.';
|
||||
$self->maniaControl->chat->sendError($message, $player->login);
|
||||
break;
|
||||
case BillManager::ERROR_WHILE_TRANSACTION:
|
||||
$message = $data;
|
||||
$self->maniaControl->chat->sendError($message, $player->login);
|
||||
break;
|
||||
}
|
||||
}, $player, $amount, $message);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle //pay command
|
||||
*
|
||||
* @param array $chatCallback
|
||||
* @param Player $player
|
||||
* @return bool
|
||||
*/
|
||||
public function command_Pay(array $chatCallback, Player $player) {
|
||||
if (!$this->maniaControl->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_SUPERADMIN)) {
|
||||
$this->maniaControl->authenticationManager->sendNotAllowed($player);
|
||||
return false;
|
||||
}
|
||||
$text = $chatCallback[1][2];
|
||||
$params = explode(' ', $text);
|
||||
if (count($params) < 2) {
|
||||
$this->sendPayUsageExample($player);
|
||||
return false;
|
||||
}
|
||||
$amount = (int)$params[1];
|
||||
if (!$amount || $amount <= 0) {
|
||||
$this->sendPayUsageExample($player);
|
||||
return false;
|
||||
}
|
||||
if (count($params) >= 3) {
|
||||
$receiver = $params[2];
|
||||
} else {
|
||||
$receiver = $player->login;
|
||||
}
|
||||
$message = 'Payout from $<' . $this->maniaControl->client->getServerName() . '$>.';
|
||||
|
||||
$self = $this;
|
||||
$this->maniaControl->billManager->sendPlanets(function ($data, $status) use (&$self, &$player, $amount, $receiver) {
|
||||
switch($status) {
|
||||
case BillManager::PAYED_FROM_SERVER:
|
||||
$message = "Successfully payed out {$amount} to '{$receiver}'!";
|
||||
$self->maniaControl->chat->sendSuccess($message, $player->login);
|
||||
break;
|
||||
case BillManager::PLAYER_REFUSED_DONATION:
|
||||
$message = 'Transaction cancelled.';
|
||||
$self->maniaControl->chat->sendError($message, $player->login);
|
||||
break;
|
||||
case BillManager::ERROR_WHILE_TRANSACTION:
|
||||
$message = $data;
|
||||
$self->maniaControl->chat->sendError($message, $player->login);
|
||||
break;
|
||||
}
|
||||
}, $receiver, $amount, $message);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle //getplanets command
|
||||
*
|
||||
* @param array $chatCallback
|
||||
* @param Player $player
|
||||
* @return bool
|
||||
*/
|
||||
public function command_GetPlanets(array $chatCallback, Player $player) {
|
||||
if (!$this->maniaControl->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_ADMIN)) {
|
||||
$this->maniaControl->authenticationManager->sendNotAllowed($player);
|
||||
return false;
|
||||
}
|
||||
$planets = $this->maniaControl->client->getServerPlanets();
|
||||
$message = "This Server has {$planets} Planets!";
|
||||
return $this->maniaControl->chat->sendInformation($message, $player->login);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send an usage example for /donate to the player
|
||||
*
|
||||
* @param Player $player
|
||||
* @return boolean
|
||||
*/
|
||||
private function sendDonateUsageExample(Player $player) {
|
||||
$message = "Usage Example: '/donate 100'";
|
||||
return $this->maniaControl->chat->sendChat($message, $player->login);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send an usage example for /pay to the player
|
||||
*
|
||||
* @param Player $player
|
||||
* @return boolean
|
||||
*/
|
||||
private function sendPayUsageExample(Player $player) {
|
||||
$message = "Usage Example: '/pay 100 login'";
|
||||
return $this->maniaControl->chat->sendChat($message, $player->login);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the /topdons command
|
||||
*
|
||||
* @param array $chatCallback
|
||||
* @param Player $player
|
||||
*/
|
||||
public function command_TopDons(array $chatCallback, Player $player) {
|
||||
$this->showTopDonsList($player);
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides a ManiaLink overview with donators.
|
||||
*
|
||||
* @param Player $player
|
||||
* @return null
|
||||
*/
|
||||
private function showTopDonsList(Player $player) {
|
||||
$stats = $this->maniaControl->statisticManager->getStatsRanking(self::STAT_PLAYER_DONATIONS);
|
||||
|
||||
$width = $this->maniaControl->manialinkManager->styleManager->getListWidgetsWidth();
|
||||
$height = $this->maniaControl->manialinkManager->styleManager->getListWidgetsHeight();
|
||||
|
||||
// create manialink
|
||||
$maniaLink = new ManiaLink(ManialinkManager::MAIN_MLID);
|
||||
$script = $maniaLink->getScript();
|
||||
$paging = new Paging();
|
||||
$script->addFeature($paging);
|
||||
|
||||
// Main frame
|
||||
$frame = $this->maniaControl->manialinkManager->styleManager->getDefaultListFrame($script, $paging);
|
||||
$maniaLink->add($frame);
|
||||
|
||||
// Start offsets
|
||||
$x = -$width / 2;
|
||||
$y = $height / 2;
|
||||
|
||||
//Predefine description Label
|
||||
$descriptionLabel = $this->maniaControl->manialinkManager->styleManager->getDefaultDescriptionLabel();
|
||||
$frame->add($descriptionLabel);
|
||||
|
||||
// Headline
|
||||
$headFrame = new Frame();
|
||||
$frame->add($headFrame);
|
||||
$headFrame->setY($y - 5);
|
||||
$array = array('$oId' => $x + 5, '$oNickname' => $x + 18, '$oDonated planets' => $x + 70);
|
||||
$this->maniaControl->manialinkManager->labelLine($headFrame, $array);
|
||||
|
||||
$i = 1;
|
||||
$y = $y - 10;
|
||||
$pageFrames = array();
|
||||
foreach($stats as $playerIndex => $donations) {
|
||||
if (!isset($pageFrame)) {
|
||||
$pageFrame = new Frame();
|
||||
$frame->add($pageFrame);
|
||||
if (!empty($pageFrames)) {
|
||||
$pageFrame->setVisible(false);
|
||||
}
|
||||
array_push($pageFrames, $pageFrame);
|
||||
$y = $height / 2 - 10;
|
||||
$paging->addPage($pageFrame);
|
||||
}
|
||||
|
||||
|
||||
$playerFrame = new Frame();
|
||||
$pageFrame->add($playerFrame);
|
||||
$playerFrame->setY($y);
|
||||
|
||||
if ($i % 2 != 0) {
|
||||
$lineQuad = new Quad_BgsPlayerCard();
|
||||
$playerFrame->add($lineQuad);
|
||||
$lineQuad->setSize($width, 4);
|
||||
$lineQuad->setSubStyle($lineQuad::SUBSTYLE_BgPlayerCardBig);
|
||||
$lineQuad->setZ(0.001);
|
||||
}
|
||||
|
||||
$donatingPlayer = $this->maniaControl->playerManager->getPlayerByIndex($playerIndex);
|
||||
$array = array($i => $x + 5, $donatingPlayer->nickname => $x + 18, $donations => $x + 70);
|
||||
$this->maniaControl->manialinkManager->labelLine($playerFrame, $array);
|
||||
|
||||
$y -= 4;
|
||||
$i++;
|
||||
if (($i - 1) % 15 == 0) {
|
||||
unset($pageFrame);
|
||||
}
|
||||
|
||||
if($i > 100) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Render and display xml
|
||||
$this->maniaControl->manialinkManager->displayWidget($maniaLink, $player, 'TopDons');
|
||||
}
|
||||
}
|
988
application/plugins/MCTeam/KarmaPlugin.php
Normal file
988
application/plugins/MCTeam/KarmaPlugin.php
Normal file
@ -0,0 +1,988 @@
|
||||
<?php
|
||||
|
||||
namespace MCTeam;
|
||||
|
||||
use FML\Controls\Frame;
|
||||
use FML\Controls\Gauge;
|
||||
use FML\Controls\Label;
|
||||
use FML\Controls\Quad;
|
||||
use FML\ManiaLink;
|
||||
use ManiaControl\Callbacks\CallbackListener;
|
||||
use ManiaControl\Callbacks\CallbackManager;
|
||||
use ManiaControl\Callbacks\Callbacks;
|
||||
use ManiaControl\Callbacks\TimerListener;
|
||||
use ManiaControl\ColorUtil;
|
||||
use ManiaControl\ManiaControl;
|
||||
use ManiaControl\Maps\Map;
|
||||
use ManiaControl\Players\Player;
|
||||
use ManiaControl\Players\PlayerManager;
|
||||
use ManiaControl\Plugins\Plugin;
|
||||
use ManiaControl\Settings\SettingManager;
|
||||
|
||||
/**
|
||||
* ManiaControl Karma Plugin
|
||||
*
|
||||
* @author ManiaControl Team <mail@maniacontrol.com>
|
||||
* @copyright 2014 ManiaControl Team
|
||||
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
||||
*/
|
||||
class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
|
||||
/*
|
||||
* Constants
|
||||
*/
|
||||
const ID = 2;
|
||||
const VERSION = 0.1;
|
||||
const MLID_KARMA = 'KarmaPlugin.MLID';
|
||||
const TABLE_KARMA = 'mc_karma';
|
||||
const CB_KARMA_CHANGED = 'KarmaPlugin.Changed';
|
||||
const CB_KARMA_MXUPDATED = 'KarmaPlugin.MXUpdated';
|
||||
const SETTING_AVAILABLE_VOTES = 'Available Votes (X-Y: Comma separated)';
|
||||
const SETTING_WIDGET_ENABLE = 'Enable Karma Widget';
|
||||
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-Size: Width';
|
||||
const SETTING_WIDGET_HEIGHT = 'Widget-Size: Height';
|
||||
const SETTING_NEWKARMA = 'Enable "new karma" (percentage), disable = RASP karma';
|
||||
const STAT_PLAYER_MAPVOTES = 'Voted Maps';
|
||||
|
||||
/*
|
||||
* Constants MX Karma
|
||||
*/
|
||||
const SETTING_WIDGET_DISPLAY_MX = 'Display MX-Karma in Widget';
|
||||
const SETTING_MX_KARMA_ACTIVATED = 'Activate MX-Karma';
|
||||
const SETTING_MX_KARMA_IMPORTING = 'Import old MX-Karmas';
|
||||
const MX_IMPORT_TABLE = 'mc_karma_mximport';
|
||||
const MX_KARMA_URL = 'http://karma.mania-exchange.com/api2/';
|
||||
const MX_KARMA_STARTSESSION = 'startSession';
|
||||
const MX_KARMA_ACTIVATESESSION = 'activateSession';
|
||||
const MX_KARMA_SAVEVOTES = 'saveVotes';
|
||||
const MX_KARMA_GETMAPRATING = 'getMapRating';
|
||||
|
||||
/*
|
||||
* Private Properties
|
||||
*/
|
||||
/**
|
||||
* @var ManiaControl $maniaControl
|
||||
*/
|
||||
private $maniaControl = null;
|
||||
private $updateManialink = false;
|
||||
/**
|
||||
* @var ManiaLink $manialink
|
||||
*/
|
||||
private $manialink = null;
|
||||
private $mxKarma = array();
|
||||
|
||||
/**
|
||||
* @see \ManiaControl\Plugins\Plugin
|
||||
*/
|
||||
public static function prepare(ManiaControl $maniaControl) {
|
||||
$maniaControl->settingManager->initSetting(get_class(), self::SETTING_MX_KARMA_ACTIVATED, true);
|
||||
$maniaControl->settingManager->initSetting(get_class(), self::SETTING_MX_KARMA_IMPORTING, true);
|
||||
$maniaControl->settingManager->initSetting(get_class(), self::SETTING_WIDGET_DISPLAY_MX, true);
|
||||
$servers = $maniaControl->server->getAllServers();
|
||||
foreach ($servers as $server) {
|
||||
$maniaControl->settingManager->initSetting(get_class(), '$l[http://karma.mania-exchange.com/auth/getapikey?server=' . $server->login . ']MX Karma Code for ' . $server->login . '$l', '');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see \ManiaControl\Plugins\Plugin::getId()
|
||||
*/
|
||||
public static function getId() {
|
||||
return self::ID;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see \ManiaControl\Plugins\Plugin::getName()
|
||||
*/
|
||||
public static function getName() {
|
||||
return 'Karma Plugin';
|
||||
}
|
||||
|
||||
/**
|
||||
* @see \ManiaControl\Plugins\Plugin::getVersion()
|
||||
*/
|
||||
public static function getVersion() {
|
||||
return self::VERSION;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see \ManiaControl\Plugins\Plugin::getAuthor()
|
||||
*/
|
||||
public static function getAuthor() {
|
||||
return 'steeffeen and kremsy';
|
||||
}
|
||||
|
||||
/**
|
||||
* @see \ManiaControl\Plugins\Plugin::getDescription()
|
||||
*/
|
||||
public static function getDescription() {
|
||||
return 'Plugin offering Karma Voting for Maps.';
|
||||
}
|
||||
|
||||
/**
|
||||
* @see \ManiaControl\Plugins\Plugin::load()
|
||||
*/
|
||||
public function load(ManiaControl $maniaControl) {
|
||||
$this->maniaControl = $maniaControl;
|
||||
|
||||
// Init database
|
||||
$this->initTables();
|
||||
|
||||
// Init settings
|
||||
$this->maniaControl->settingManager->initSetting($this, self::SETTING_AVAILABLE_VOTES, '-2,2');
|
||||
$this->maniaControl->settingManager->initSetting($this, self::SETTING_WIDGET_ENABLE, true);
|
||||
$this->maniaControl->settingManager->initSetting($this, self::SETTING_WIDGET_TITLE, 'Map-Karma');
|
||||
$this->maniaControl->settingManager->initSetting($this, self::SETTING_WIDGET_POSX, 160 - 27.5);
|
||||
$this->maniaControl->settingManager->initSetting($this, self::SETTING_WIDGET_POSY, 90 - 10 - 6);
|
||||
$this->maniaControl->settingManager->initSetting($this, self::SETTING_WIDGET_WIDTH, 25.);
|
||||
$this->maniaControl->settingManager->initSetting($this, self::SETTING_WIDGET_HEIGHT, 12.);
|
||||
$this->maniaControl->settingManager->initSetting($this, self::SETTING_NEWKARMA, true);
|
||||
|
||||
// Register for callbacks
|
||||
$this->maniaControl->timerManager->registerTimerListening($this, 'handle1Second', 1000);
|
||||
$this->maniaControl->callbackManager->registerCallbackListener(Callbacks::BEGINMAP, $this, 'handleBeginMap');
|
||||
$this->maniaControl->callbackManager->registerCallbackListener(Callbacks::BEGINMAP, $this, 'importMxKarmaVotes');
|
||||
$this->maniaControl->callbackManager->registerCallbackListener(Callbacks::ENDMAP, $this, 'sendMxKarmaVotes');
|
||||
$this->maniaControl->callbackManager->registerCallbackListener(PlayerManager::CB_PLAYERCONNECT, $this, 'handlePlayerConnect');
|
||||
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MP_PLAYERCHAT, $this, 'handlePlayerChat');
|
||||
$this->maniaControl->callbackManager->registerCallbackListener(SettingManager::CB_SETTINGS_CHANGED, $this, 'updateSettings');
|
||||
|
||||
// Define player stats
|
||||
$this->maniaControl->statisticManager->defineStatMetaData(self::STAT_PLAYER_MAPVOTES);
|
||||
|
||||
// Register Stat in Simple StatsList
|
||||
$this->maniaControl->statisticManager->simpleStatsList->registerStat(self::STAT_PLAYER_MAPVOTES, 100, "VM");
|
||||
|
||||
$this->updateManialink = true;
|
||||
|
||||
// Open MX-Karma Session
|
||||
$this->mxKarmaOpenSession();
|
||||
$this->mxKarma['startTime'] = time();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create necessary database tables
|
||||
*/
|
||||
private function initTables() {
|
||||
$mysqli = $this->maniaControl->database->mysqli;
|
||||
|
||||
// Create local table
|
||||
$query = "CREATE TABLE IF NOT EXISTS `" . self::TABLE_KARMA . "` (
|
||||
`index` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`mapIndex` int(11) NOT NULL,
|
||||
`playerIndex` int(11) NOT NULL,
|
||||
`vote` float NOT NULL DEFAULT '-1',
|
||||
`changed` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
PRIMARY KEY (`index`),
|
||||
UNIQUE KEY `player_map_vote` (`mapIndex`, `playerIndex`)
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT='Save players map votes' AUTO_INCREMENT=1;";
|
||||
$mysqli->query($query);
|
||||
if ($mysqli->error) {
|
||||
trigger_error($mysqli->error, E_USER_ERROR);
|
||||
}
|
||||
|
||||
// Migrate settings
|
||||
$this->maniaControl->database->migrationHelper->transferSettings('KarmaPlugin', $this);
|
||||
|
||||
if (!$this->maniaControl->settingManager->getSetting($this, self::SETTING_MX_KARMA_ACTIVATED)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Create mx table
|
||||
$query = "CREATE TABLE IF NOT EXISTS `" . self::MX_IMPORT_TABLE . "` (
|
||||
`index` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`mapIndex` int(11) NOT NULL,
|
||||
`mapImported` tinyint(1) NOT NULL,
|
||||
`time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
PRIMARY KEY (`index`),
|
||||
UNIQUE KEY `mapIndex` (`mapIndex`)
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT='MX Karma Import Table' AUTO_INCREMENT=1;";
|
||||
$mysqli->query($query);
|
||||
if ($mysqli->error) {
|
||||
trigger_error($mysqli->error, E_USER_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Open a Mx Karma Session
|
||||
*/
|
||||
private function mxKarmaOpenSession() {
|
||||
if (!$this->maniaControl->settingManager->getSetting($this, self::SETTING_MX_KARMA_ACTIVATED)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$serverLogin = $this->maniaControl->server->login;
|
||||
$mxKarmaCode = $this->maniaControl->settingManager->getSetting($this, '$l[http://karma.mania-exchange.com/auth/getapikey?server=' . $serverLogin . ']MX Karma Code for ' . $serverLogin . '$l');
|
||||
|
||||
if ($mxKarmaCode == '') {
|
||||
return;
|
||||
}
|
||||
|
||||
$applicationIdentifier = 'ManiaControl v' . ManiaControl::VERSION;
|
||||
$testMode = 'true';
|
||||
|
||||
$query = self::MX_KARMA_URL . self::MX_KARMA_STARTSESSION;
|
||||
$query .= '?serverLogin=' . $serverLogin;
|
||||
$query .= '&applicationIdentifier=' . urlencode($applicationIdentifier);
|
||||
$query .= '&testMode=' . $testMode;
|
||||
|
||||
$this->mxKarma['connectionInProgress'] = true;
|
||||
|
||||
$self = $this;
|
||||
$this->maniaControl->fileReader->loadFile($query, function ($data, $error) use (&$self, $mxKarmaCode) {
|
||||
if (!$error) {
|
||||
$data = json_decode($data);
|
||||
if ($data->success) {
|
||||
$self->mxKarma['session'] = $data->data;
|
||||
$self->activateSession($mxKarmaCode);
|
||||
} else {
|
||||
$self->maniaControl->log("Error while authenticating on Mania-Exchange Karma");
|
||||
// TODO remove temp trigger
|
||||
$self->maniaControl->errorHandler->triggerDebugNotice("Error while authenticating on Mania-Exchange Karma " . $data->data->message);
|
||||
$self->mxKarma['connectionInProgress'] = false;
|
||||
}
|
||||
} else {
|
||||
$self->maniaControl->log($error);
|
||||
// TODO remove temp trigger
|
||||
$self->maniaControl->errorHandler->triggerDebugNotice("Error while authenticating on Mania-Exchange Karma " . $error);
|
||||
$self->mxKarma['connectionInProgress'] = false;
|
||||
}
|
||||
}, "application/json", 1000);
|
||||
}
|
||||
|
||||
/**
|
||||
* Activates the MX-Karma Session
|
||||
*
|
||||
* @param $mxKarmaCode
|
||||
*/
|
||||
private function activateSession($mxKarmaCode) {
|
||||
$hash = $this->buildActivationHash($this->mxKarma['session']->sessionSeed, $mxKarmaCode);
|
||||
|
||||
$query = self::MX_KARMA_URL . self::MX_KARMA_ACTIVATESESSION;
|
||||
$query .= '?sessionKey=' . urlencode($this->mxKarma['session']->sessionKey);
|
||||
$query .= '&activationHash=' . urlencode($hash);
|
||||
|
||||
$self = $this;
|
||||
$this->maniaControl->fileReader->loadFile($query, function ($data, $error) use (&$self, $query) {
|
||||
if (!$error) {
|
||||
$data = json_decode($data);
|
||||
if ($data->success && $data->data->activated) {
|
||||
$self->maniaControl->log("Successfully authenticated on Mania-Exchange Karma");
|
||||
$self->mxKarma['connectionInProgress'] = false;
|
||||
|
||||
// Fetch the Mx Karma Votes
|
||||
$self->getMxKarmaVotes();
|
||||
} else {
|
||||
$self->maniaControl->log("Error while authenticating on Mania-Exchange Karma " . $data->data->message);
|
||||
// TODO remove temp trigger
|
||||
$self->maniaControl->errorHandler->triggerDebugNotice("Error while authenticating on Mania-Exchange Karma " . $data->data->message . " url Query " . $query);
|
||||
$self->mxKarma['connectionInProgress'] = false;
|
||||
}
|
||||
} else {
|
||||
// TODO remove temp trigger
|
||||
$self->maniaControl->errorHandler->triggerDebugNotice("Error while authenticating on Mania-Exchange Karma " . $error);
|
||||
$self->maniaControl->log($error);
|
||||
$self->mxKarma['connectionInProgress'] = false;
|
||||
}
|
||||
}, "application/json", 1000);
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds a sha512 activation Hash for the MX-Karma
|
||||
*
|
||||
* @param $sessionSeed
|
||||
* @param $mxKey
|
||||
* @return string
|
||||
*/
|
||||
private function buildActivationHash($sessionSeed, $mxKey) {
|
||||
return hash('sha512', $mxKey . $sessionSeed);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch the mxKarmaVotes for the current map
|
||||
*/
|
||||
public function getMxKarmaVotes(Player $player = null) {
|
||||
if (!$this->maniaControl->settingManager->getSetting($this, self::SETTING_MX_KARMA_ACTIVATED)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!isset($this->mxKarma['session'])) {
|
||||
if (!isset($this->mxKarma['connectionInProgress']) || !$this->mxKarma['connectionInProgress']) {
|
||||
$this->mxKarmaOpenSession();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
$map = $this->maniaControl->mapManager->getCurrentMap();
|
||||
|
||||
$properties = array();
|
||||
|
||||
$gameMode = $this->maniaControl->server->getGameMode(true);
|
||||
if ($gameMode == 'Script') {
|
||||
$scriptName = $this->maniaControl->client->getScriptName();
|
||||
$properties['gamemode'] = $scriptName["CurrentValue"];
|
||||
} else {
|
||||
$properties['gamemode'] = $gameMode;
|
||||
}
|
||||
|
||||
$properties['titleid'] = $this->maniaControl->server->titleId;
|
||||
$properties['mapuid'] = $map->uid;
|
||||
|
||||
if (!$player) {
|
||||
$properties['getvotesonly'] = false;
|
||||
$properties['playerlogins'] = array();
|
||||
foreach ($this->maniaControl->playerManager->getPlayers() as $plyr) {
|
||||
/**
|
||||
* @var Player $player
|
||||
*/
|
||||
$properties['playerlogins'][] = $plyr->login;
|
||||
}
|
||||
} else {
|
||||
$properties['getvotesonly'] = true;
|
||||
$properties['playerlogins'] = array($player->login);
|
||||
}
|
||||
|
||||
$content = json_encode($properties);
|
||||
$self = $this;
|
||||
$this->maniaControl->fileReader->postData(self::MX_KARMA_URL . self::MX_KARMA_GETMAPRATING . "?sessionKey=" . urlencode($this->mxKarma['session']->sessionKey), function ($data, $error) use (&$self, &$player) {
|
||||
if (!$error) {
|
||||
$data = json_decode($data);
|
||||
if ($data->success) {
|
||||
|
||||
// Fetch averages if its for the whole server
|
||||
if (!$player) {
|
||||
$self->mxKarma["voteCount"] = $data->data->votecount;
|
||||
$self->mxKarma["voteAverage"] = $data->data->voteaverage;
|
||||
$self->mxKarma["modeVoteCount"] = $data->data->modevotecount;
|
||||
$self->mxKarma["modeVoteAverage"] = $data->data->modevoteaverage;
|
||||
}
|
||||
|
||||
foreach ($data->data->votes as $votes) {
|
||||
$self->mxKarma["votes"][$votes->login] = $votes->vote;
|
||||
}
|
||||
|
||||
$self->updateManialink = true;
|
||||
$self->maniaControl->callbackManager->triggerCallback($self::CB_KARMA_MXUPDATED, $self->mxKarma);
|
||||
$self->maniaControl->log("MX-Karma Votes successfully fetched");
|
||||
} else {
|
||||
$self->maniaControl->log("Error while fetching votes: " . $data->data->message);
|
||||
// TODO remove temp trigger
|
||||
$self->maniaControl->errorHandler->triggerDebugNotice("Error while fetching votes: " . $data->data->message . " " . KarmaPlugin::MX_KARMA_URL . KarmaPlugin::MX_KARMA_SAVEVOTES . "?sessionKey=" . urlencode($self->mxKarma['session']->sessionKey));
|
||||
}
|
||||
} else {
|
||||
$self->maniaControl->log($error);
|
||||
}
|
||||
}, $content, false, 'application/json');
|
||||
}
|
||||
|
||||
/**
|
||||
* @see \ManiaControl\Plugins\Plugin::unload()
|
||||
*/
|
||||
public function unload() {
|
||||
$this->maniaControl->manialinkManager->hideManialink(self::MLID_KARMA);
|
||||
$this->maniaControl->callbackManager->unregisterCallbackListener($this);
|
||||
$this->maniaControl->timerManager->unregisterTimerListenings($this);
|
||||
unset($this->maniaControl);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle BeginMap ManiaControl callback
|
||||
*
|
||||
* @param Map $map
|
||||
*/
|
||||
public function handleBeginMap(Map $map) {
|
||||
// send Map Karma to MX from previous Map
|
||||
if (isset($this->mxKarma['map'])) {
|
||||
$votes = array();
|
||||
foreach ($this->mxKarma['votes'] as $login => $value) {
|
||||
$player = $this->maniaControl->playerManager->getPlayer($login);
|
||||
array_push($votes, array("login" => $login, "nickname" => $player->rawNickname, "vote" => $value));
|
||||
}
|
||||
$this->postKarmaVotes($this->mxKarma['map'], $votes);
|
||||
unset($this->mxKarma['map']);
|
||||
}
|
||||
|
||||
unset($this->mxKarma['votes']);
|
||||
$this->mxKarma['startTime'] = time();
|
||||
$this->updateManialink = true;
|
||||
|
||||
// Get Karma votes at begin of map
|
||||
$this->getMxKarmaVotes();
|
||||
}
|
||||
|
||||
/**
|
||||
* Post the Karma votes to MX-Karma
|
||||
*
|
||||
* @param Map $map
|
||||
* @param array $votes
|
||||
* @param bool $import
|
||||
*/
|
||||
private function postKarmaVotes(Map $map, array $votes, $import = false) {
|
||||
if (!isset($this->mxKarma['session'])) {
|
||||
if (!isset($this->mxKarma['connectionInProgress']) || !$this->mxKarma['connectionInProgress']) {
|
||||
$this->mxKarmaOpenSession();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
$gameMode = $this->maniaControl->server->getGameMode(true);
|
||||
|
||||
if (count($votes) == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
$properties = array();
|
||||
if ($gameMode == 'Script') {
|
||||
$scriptName = $this->maniaControl->client->getScriptName();
|
||||
$properties['gamemode'] = $scriptName["CurrentValue"];
|
||||
} else {
|
||||
$properties['gamemode'] = $gameMode;
|
||||
}
|
||||
|
||||
if ($import) {
|
||||
$properties['maptime'] = 0;
|
||||
} else {
|
||||
$properties['maptime'] = time() - $this->mxKarma['startTime'];
|
||||
}
|
||||
|
||||
$properties['votes'] = $votes;
|
||||
$properties['titleid'] = $this->maniaControl->server->titleId;
|
||||
$properties['mapname'] = $map->rawName;
|
||||
$properties['mapuid'] = $map->uid;
|
||||
$properties['mapauthor'] = $map->authorLogin;
|
||||
$properties['isimport'] = $import;
|
||||
|
||||
$content = json_encode($properties);
|
||||
|
||||
$self = $this;
|
||||
$this->maniaControl->fileReader->postData(self::MX_KARMA_URL . self::MX_KARMA_SAVEVOTES . "?sessionKey=" . urlencode($this->mxKarma['session']->sessionKey), function ($data, $error) use (&$self) {
|
||||
if (!$error) {
|
||||
$data = json_decode($data);
|
||||
if ($data->success) {
|
||||
$self->maniaControl->log("Votes successfully permitted");
|
||||
} else {
|
||||
$self->maniaControl->log("Error while updating votes: " . $data->data->message);
|
||||
// TODO remove temp trigger
|
||||
$self->maniaControl->errorHandler->triggerDebugNotice("Error while updating votes: " . $data->data->message . " " . KarmaPlugin::MX_KARMA_URL . $self::MX_KARMA_SAVEVOTES . "?sessionKey=" . urlencode($self->mxKarma['session']->sessionKey));
|
||||
}
|
||||
} else {
|
||||
$self->maniaControl->log($error);
|
||||
}
|
||||
}, $content, false, 'application/json');
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle PlayerConnect callback
|
||||
*
|
||||
* @param \ManiaControl\Players\Player $player
|
||||
*/
|
||||
public function handlePlayerConnect(Player $player) {
|
||||
if (!$player) {
|
||||
return;
|
||||
}
|
||||
$this->queryManialinkUpdateFor($player);
|
||||
|
||||
// Get Mx Karma Vote for Player
|
||||
$this->getMxKarmaVotes($player);
|
||||
}
|
||||
|
||||
/**
|
||||
* Query the player to update the manialink
|
||||
*
|
||||
* @param Player $player
|
||||
*/
|
||||
private function queryManialinkUpdateFor(Player $player) {
|
||||
if ($this->updateManialink === true) {
|
||||
return;
|
||||
}
|
||||
if (!is_array($this->updateManialink)) {
|
||||
$this->updateManialink = array();
|
||||
}
|
||||
$this->updateManialink[$player->login] = $player;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle PlayerChat callback
|
||||
*
|
||||
* @param array $chatCallback
|
||||
*/
|
||||
public function handlePlayerChat(array $chatCallback) {
|
||||
$login = $chatCallback[1][1];
|
||||
$player = $this->maniaControl->playerManager->getPlayer($login);
|
||||
if (!$player) {
|
||||
return;
|
||||
}
|
||||
$message = $chatCallback[1][2];
|
||||
if ($chatCallback[1][3]) {
|
||||
$message = substr($message, 1);
|
||||
}
|
||||
if (preg_match('/[^+-]/', $message)) {
|
||||
return;
|
||||
}
|
||||
$countPositive = substr_count($message, '+');
|
||||
$countNegative = substr_count($message, '-');
|
||||
if ($countPositive <= 0 && $countNegative <= 0) {
|
||||
return;
|
||||
}
|
||||
$vote = $countPositive - $countNegative;
|
||||
$success = $this->handleVote($player, $vote);
|
||||
if (!$success) {
|
||||
$this->maniaControl->chat->sendError('Error occurred.', $player->login);
|
||||
return;
|
||||
}
|
||||
$this->maniaControl->chat->sendSuccess('Vote updated!', $player->login);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle a vote done by a player
|
||||
*
|
||||
* @param Player $player
|
||||
* @param int $vote
|
||||
* @return bool
|
||||
*/
|
||||
private function handleVote(Player $player, $vote) {
|
||||
// Check vote
|
||||
$votesSetting = $this->maniaControl->settingManager->getSetting($this, self::SETTING_AVAILABLE_VOTES);
|
||||
$votes = explode(',', $votesSetting);
|
||||
$voteLow = intval($votes[0]);
|
||||
$voteHigh = $voteLow + 2;
|
||||
if (isset($votes[1])) {
|
||||
$voteHigh = intval($votes[1]);
|
||||
}
|
||||
if ($vote < $voteLow || $vote > $voteHigh) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Calculate actual voting
|
||||
$vote -= $voteLow;
|
||||
$voteHigh -= $voteLow;
|
||||
$vote /= $voteHigh;
|
||||
|
||||
// Save vote
|
||||
$map = $this->maniaControl->mapManager->getCurrentMap();
|
||||
|
||||
// Update vote in MX karma array
|
||||
if ($this->maniaControl->settingManager->getSetting($this, self::SETTING_MX_KARMA_ACTIVATED) && isset($this->mxKarma["session"])) {
|
||||
if (!isset($this->mxKarma["votes"][$player->login])) {
|
||||
$sum = $this->mxKarma["voteCount"] * $this->mxKarma["voteAverage"] + $vote * 100;
|
||||
$this->mxKarma["voteCount"]++;
|
||||
|
||||
$modeSum = $this->mxKarma["modeVoteCount"] * $this->mxKarma["modeVoteAverage"] + $vote * 100;
|
||||
$this->mxKarma["modeVoteCount"]++;
|
||||
} else {
|
||||
$oldVote = $this->mxKarma["votes"][$player->login];
|
||||
$sum = $this->mxKarma["voteCount"] * $this->mxKarma["voteAverage"] - $oldVote + $vote * 100;
|
||||
$modeSum = $this->mxKarma["modeVoteCount"] * $this->mxKarma["modeVoteAverage"] - $oldVote + $vote * 100;
|
||||
}
|
||||
|
||||
$this->mxKarma["voteAverage"] = $sum / $this->mxKarma["voteCount"];
|
||||
$this->mxKarma["modeVoteAverage"] = $modeSum / $this->mxKarma["modeVoteCount"];
|
||||
$this->mxKarma["votes"][$player->login] = $vote * 100;
|
||||
}
|
||||
|
||||
$voted = $this->getPlayerVote($player, $map);
|
||||
if (!$voted) {
|
||||
$this->maniaControl->statisticManager->incrementStat(self::STAT_PLAYER_MAPVOTES, $player, $this->maniaControl->server->index);
|
||||
}
|
||||
|
||||
$success = $this->savePlayerVote($player, $map, $vote);
|
||||
if (!$success) {
|
||||
return false;
|
||||
}
|
||||
$this->maniaControl->callbackManager->triggerCallback(self::CB_KARMA_CHANGED);
|
||||
$this->updateManialink = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current vote of the player for the map
|
||||
*
|
||||
* @param Player $player
|
||||
* @param Map $map
|
||||
* @return int
|
||||
*/
|
||||
public function getPlayerVote(Player $player, Map $map) {
|
||||
$mysqli = $this->maniaControl->database->mysqli;
|
||||
$query = "SELECT * FROM `" . self::TABLE_KARMA . "`
|
||||
WHERE `playerIndex` = {$player->index}
|
||||
AND `mapIndex` = {$map->index}
|
||||
AND `vote` >= 0;";
|
||||
$result = $mysqli->query($query);
|
||||
if ($mysqli->error) {
|
||||
trigger_error($mysqli->error);
|
||||
return false;
|
||||
}
|
||||
if ($result->num_rows <= 0) {
|
||||
$result->free();
|
||||
return false;
|
||||
}
|
||||
$item = $result->fetch_object();
|
||||
$result->free();
|
||||
$vote = $item->vote;
|
||||
return floatval($vote);
|
||||
}
|
||||
|
||||
/**
|
||||
* Save the vote of the player for the map
|
||||
*
|
||||
* @param Player $player
|
||||
* @param Map $map
|
||||
* @param float $vote
|
||||
* @return bool
|
||||
*/
|
||||
private function savePlayerVote(Player $player, Map $map, $vote) {
|
||||
$mysqli = $this->maniaControl->database->mysqli;
|
||||
$query = "INSERT INTO `" . self::TABLE_KARMA . "` (
|
||||
`mapIndex`,
|
||||
`playerIndex`,
|
||||
`vote`
|
||||
) VALUES (
|
||||
{$map->index},
|
||||
{$player->index},
|
||||
{$vote}
|
||||
) ON DUPLICATE KEY UPDATE
|
||||
`vote` = VALUES(`vote`);";
|
||||
$result = $mysqli->query($query);
|
||||
if ($mysqli->error) {
|
||||
trigger_error($mysqli->error);
|
||||
return false;
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all players votes
|
||||
*
|
||||
* @param Map $map
|
||||
* @return array
|
||||
*/
|
||||
public function getMapPlayerVotes(Map $map) {
|
||||
$mysqli = $this->maniaControl->database->mysqli;
|
||||
$query = "SELECT * FROM `" . self::TABLE_KARMA . "`
|
||||
WHERE `mapIndex` = {$map->index}
|
||||
AND `vote` >= 0";
|
||||
$result = $mysqli->query($query);
|
||||
if ($mysqli->error) {
|
||||
trigger_error($mysqli->error);
|
||||
return false;
|
||||
}
|
||||
|
||||
$votes = array();
|
||||
while ($vote = $result->fetch_object()) {
|
||||
$player = $this->maniaControl->playerManager->getPlayerByIndex($vote->playerIndex);
|
||||
$karma = $vote->vote;
|
||||
$votes[] = array('player' => $player, 'karma' => $karma);
|
||||
}
|
||||
|
||||
usort($votes, function ($a, $b) {
|
||||
return $a['karma'] - $b['karma'];
|
||||
});
|
||||
$votes = array_reverse($votes);
|
||||
|
||||
return $votes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update Settings
|
||||
*
|
||||
* @param $class
|
||||
* @param $settingName
|
||||
* @param $value
|
||||
*/
|
||||
public function updateSettings($class, $settingName, $value) {
|
||||
if (!$class = get_class()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$serverLogin = $this->maniaControl->server->login;
|
||||
if ($settingName == '$l[http://karma.mania-exchange.com/auth/getapikey?server=' . $serverLogin . ']MX Karma Code for ' . $serverLogin . '$l') {
|
||||
$this->mxKarmaOpenSession();
|
||||
}
|
||||
|
||||
if ($settingName == 'Enable Karma Widget' && $value == true) {
|
||||
$this->updateManialink = true;
|
||||
$this->handle1Second(time());
|
||||
} elseif ($settingName == 'Enable Karma Widget' && $value == false) {
|
||||
$this->updateManialink = false;
|
||||
$ml = new ManiaLink(self::MLID_KARMA);
|
||||
$mltext = $ml->render()->saveXML();
|
||||
$this->maniaControl->manialinkManager->sendManialink($mltext);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle ManiaControl 1 Second callback
|
||||
*
|
||||
* @param $time
|
||||
*/
|
||||
public function handle1Second($time) {
|
||||
if (!$this->updateManialink) {
|
||||
return;
|
||||
}
|
||||
|
||||
$displayMxKarma = $this->maniaControl->settingManager->getSetting($this, self::SETTING_WIDGET_DISPLAY_MX);
|
||||
|
||||
// Get players
|
||||
$players = $this->updateManialink;
|
||||
if ($players === true) {
|
||||
$players = $this->maniaControl->playerManager->getPlayers();
|
||||
}
|
||||
$this->updateManialink = false;
|
||||
|
||||
// Get map karma
|
||||
$map = $this->maniaControl->mapManager->getCurrentMap();
|
||||
|
||||
// Display the mx Karma if the setting is choosen and the MX session is available
|
||||
if ($displayMxKarma && isset($this->mxKarma['session']) && isset($this->mxKarma['voteCount'])) {
|
||||
$karma = $this->mxKarma['modeVoteAverage'] / 100;
|
||||
$voteCount = $this->mxKarma['modeVoteCount'];
|
||||
} else {
|
||||
$karma = $this->getMapKarma($map);
|
||||
$votes = $this->getMapVotes($map);
|
||||
$voteCount = $votes['count'];
|
||||
}
|
||||
|
||||
if ($this->maniaControl->settingManager->getSetting($this, self::SETTING_WIDGET_ENABLE)) {
|
||||
// Build karma manialink
|
||||
$this->buildManialink();
|
||||
|
||||
// Update karma gauge & label
|
||||
/**
|
||||
* @var Gauge $karmaGauge
|
||||
*/
|
||||
$karmaGauge = $this->manialink->karmaGauge;
|
||||
/**
|
||||
* @var Label $karmaLabel
|
||||
*/
|
||||
$karmaLabel = $this->manialink->karmaLabel;
|
||||
if (is_numeric($karma) && $voteCount > 0) {
|
||||
$karma = floatval($karma);
|
||||
$karmaGauge->setRatio($karma + 0.15 - $karma * 0.15);
|
||||
$karmaColor = ColorUtil::floatToStatusColor($karma);
|
||||
$karmaGauge->setColor($karmaColor . '7');
|
||||
$karmaLabel->setText(' ' . round($karma * 100.) . '% (' . $voteCount . ')');
|
||||
} else {
|
||||
$karmaGauge->setRatio(0.);
|
||||
$karmaGauge->setColor('00fb');
|
||||
$karmaLabel->setText('-');
|
||||
}
|
||||
|
||||
// Loop players
|
||||
foreach ($players as $login => $player) {
|
||||
// Get player vote
|
||||
// TODO: show the player his own vote in some way
|
||||
// $vote = $this->getPlayerVote($player, $map);
|
||||
// $votesFrame = $this->manialink->votesFrame;
|
||||
// $votesFrame->removeChildren();
|
||||
|
||||
// Send manialink
|
||||
$this->maniaControl->manialinkManager->sendManialink($this->manialink, $login);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current karma of the map
|
||||
*
|
||||
* @param Map $map
|
||||
* @return float | bool
|
||||
*/
|
||||
public function getMapKarma(Map $map) {
|
||||
$mysqli = $this->maniaControl->database->mysqli;
|
||||
$query = "SELECT AVG(`vote`) AS `karma` FROM `" . self::TABLE_KARMA . "`
|
||||
WHERE `mapIndex` = {$map->index}
|
||||
AND `vote` >= 0;";
|
||||
$result = $mysqli->query($query);
|
||||
if ($mysqli->error) {
|
||||
trigger_error($mysqli->error);
|
||||
return false;
|
||||
}
|
||||
if ($result->num_rows <= 0) {
|
||||
$result->free();
|
||||
return false;
|
||||
}
|
||||
$item = $result->fetch_object();
|
||||
$result->free();
|
||||
$karma = $item->karma;
|
||||
if ($karma === null) {
|
||||
return false;
|
||||
}
|
||||
return floatval($karma);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current Votes for the Map
|
||||
*
|
||||
* @param Map $map
|
||||
* @return array
|
||||
*/
|
||||
public function getMapVotes(Map $map) {
|
||||
$mysqli = $this->maniaControl->database->mysqli;
|
||||
$query = "SELECT `vote`, COUNT(`vote`) AS `count` FROM `" . self::TABLE_KARMA . "`
|
||||
WHERE `mapIndex` = {$map->index}
|
||||
AND `vote` >= 0
|
||||
GROUP BY `vote`;";
|
||||
$result = $mysqli->query($query);
|
||||
if ($mysqli->error) {
|
||||
trigger_error($mysqli->error);
|
||||
return false;
|
||||
}
|
||||
$votes = array();
|
||||
$count = 0;
|
||||
while ($vote = $result->fetch_object()) {
|
||||
$votes[$vote->vote] = $vote;
|
||||
$count += $vote->count;
|
||||
}
|
||||
$votes['count'] = $count;
|
||||
$result->free();
|
||||
return $votes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build karma voting manialink if necessary
|
||||
*
|
||||
* @param bool $forceBuild
|
||||
*/
|
||||
private function buildManialink($forceBuild = false) {
|
||||
if (is_object($this->manialink) && !$forceBuild) {
|
||||
return;
|
||||
}
|
||||
|
||||
$title = $this->maniaControl->settingManager->getSetting($this, self::SETTING_WIDGET_TITLE);
|
||||
$pos_x = $this->maniaControl->settingManager->getSetting($this, self::SETTING_WIDGET_POSX);
|
||||
$pos_y = $this->maniaControl->settingManager->getSetting($this, self::SETTING_WIDGET_POSY);
|
||||
$width = $this->maniaControl->settingManager->getSetting($this, self::SETTING_WIDGET_WIDTH);
|
||||
$height = $this->maniaControl->settingManager->getSetting($this, self::SETTING_WIDGET_HEIGHT);
|
||||
$labelStyle = $this->maniaControl->manialinkManager->styleManager->getDefaultLabelStyle();
|
||||
$quadStyle = $this->maniaControl->manialinkManager->styleManager->getDefaultQuadStyle();
|
||||
$quadSubstyle = $this->maniaControl->manialinkManager->styleManager->getDefaultQuadSubstyle();
|
||||
|
||||
$manialink = new ManiaLink(self::MLID_KARMA);
|
||||
|
||||
$frame = new Frame();
|
||||
$manialink->add($frame);
|
||||
$frame->setPosition($pos_x, $pos_y);
|
||||
|
||||
$backgroundQuad = new Quad();
|
||||
$frame->add($backgroundQuad);
|
||||
$backgroundQuad->setY($height * 0.15);
|
||||
$backgroundQuad->setSize($width, $height);
|
||||
$backgroundQuad->setStyles($quadStyle, $quadSubstyle);
|
||||
|
||||
$titleLabel = new Label();
|
||||
$frame->add($titleLabel);
|
||||
$titleLabel->setY($height * 0.36);
|
||||
$titleLabel->setWidth($width * 0.85);
|
||||
$titleLabel->setStyle($labelStyle);
|
||||
$titleLabel->setTranslate(true);
|
||||
$titleLabel->setTextSize(1);
|
||||
$titleLabel->setScale(0.90);
|
||||
$titleLabel->setText($title);
|
||||
|
||||
$karmaGauge = new Gauge();
|
||||
$frame->add($karmaGauge);
|
||||
$karmaGauge->setSize($width * 0.95, $height * 0.92);
|
||||
$karmaGauge->setDrawBg(false);
|
||||
$manialink->karmaGauge = $karmaGauge;
|
||||
|
||||
$karmaLabel = new Label();
|
||||
$frame->add($karmaLabel);
|
||||
$karmaLabel->setPosition(0, -0.4, 1);
|
||||
$karmaLabel->setSize($width * 0.9, $height * 0.9);
|
||||
$karmaLabel->setStyle($labelStyle);
|
||||
$karmaLabel->setTextSize(1);
|
||||
$manialink->karmaLabel = $karmaLabel;
|
||||
|
||||
$votesFrame = new Frame();
|
||||
$frame->add($votesFrame);
|
||||
$manialink->votesFrame = $votesFrame;
|
||||
|
||||
$this->manialink = $manialink;
|
||||
}
|
||||
|
||||
/**
|
||||
* Import old Karma votes to Mania-Exchange Karma
|
||||
*
|
||||
* @param Map $map
|
||||
*/
|
||||
public function importMxKarmaVotes(Map $map) {
|
||||
if (!$this->maniaControl->settingManager->getSetting($this, self::SETTING_MX_KARMA_ACTIVATED)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!$this->maniaControl->settingManager->getSetting($this, self::SETTING_MX_KARMA_IMPORTING)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!isset($this->mxKarma['session'])) {
|
||||
if (!isset($this->mxKarma['connectionInProgress']) || !$this->mxKarma['connectionInProgress']) {
|
||||
$this->mxKarmaOpenSession();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
$mysqli = $this->maniaControl->database->mysqli;
|
||||
$query = "SELECT mapImported FROM `" . self::MX_IMPORT_TABLE . "` WHERE `mapIndex` = {$map->index};";
|
||||
$result = $mysqli->query($query);
|
||||
if ($mysqli->error) {
|
||||
trigger_error($mysqli->error);
|
||||
return;
|
||||
}
|
||||
$vote = $result->fetch_object();
|
||||
|
||||
if ($result->field_count == 0 || !$vote) {
|
||||
$query = "SELECT vote, login, nickname FROM `" . self::TABLE_KARMA . "` k LEFT JOIN `" . PlayerManager::TABLE_PLAYERS . "` p ON (k.playerIndex=p.index) WHERE mapIndex = {$map->index}";
|
||||
$result2 = $mysqli->query($query);
|
||||
if ($mysqli->error) {
|
||||
trigger_error($mysqli->error);
|
||||
return;
|
||||
}
|
||||
|
||||
$votes = array();
|
||||
while ($row = $result2->fetch_object()) {
|
||||
array_push($votes, array("login" => $row->login, "nickname" => $row->nickname, "vote" => $row->vote * 100));
|
||||
}
|
||||
|
||||
$this->postKarmaVotes($map, $votes, true);
|
||||
|
||||
// Flag Map as Imported in database if it is a import
|
||||
$query = "INSERT INTO `" . self::MX_IMPORT_TABLE . "` (`mapIndex`,`mapImported`) VALUES ({$map->index},true) ON DUPLICATE KEY UPDATE `mapImported` = true;";
|
||||
$mysqli->query($query);
|
||||
if ($mysqli->error) {
|
||||
trigger_error($mysqli->error);
|
||||
}
|
||||
|
||||
$result2->free();
|
||||
}
|
||||
$result->free_result();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Save Mx Karma Votes at Mapend
|
||||
*/
|
||||
public function sendMxKarmaVotes(Map $map) {
|
||||
if (!$this->maniaControl->settingManager->getSetting($this, self::SETTING_MX_KARMA_ACTIVATED)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!isset($this->mxKarma['session'])) {
|
||||
if (!isset($this->mxKarma['connectionInProgress']) || !$this->mxKarma['connectionInProgress']) {
|
||||
$this->mxKarmaOpenSession();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (!isset($this->mxKarma['votes']) || count($this->mxKarma['votes']) == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->mxKarma['map'] = $map;
|
||||
}
|
||||
}
|
660
application/plugins/MCTeam/LocalRecordsPlugin.php
Normal file
660
application/plugins/MCTeam/LocalRecordsPlugin.php
Normal file
@ -0,0 +1,660 @@
|
||||
<?php
|
||||
|
||||
namespace MCTeam;
|
||||
|
||||
use FML\Controls\Control;
|
||||
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\TimerListener;
|
||||
use ManiaControl\Commands\CommandListener;
|
||||
use ManiaControl\Settings\SettingManager;
|
||||
use ManiaControl\Formatter;
|
||||
use ManiaControl\ManiaControl;
|
||||
use ManiaControl\Maps\Map;
|
||||
use ManiaControl\Maps\MapManager;
|
||||
use ManiaControl\Manialinks\ManialinkManager;
|
||||
use ManiaControl\Players\Player;
|
||||
use ManiaControl\Players\PlayerManager;
|
||||
use ManiaControl\Plugins\Plugin;
|
||||
|
||||
/**
|
||||
* ManiaControl Local Records Plugin
|
||||
*
|
||||
* @author steeffeen
|
||||
* @copyright ManiaControl 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 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();
|
||||
|
||||
/**
|
||||
* Prepares the Plugin
|
||||
*
|
||||
* @param ManiaControl $maniaControl
|
||||
* @return mixed
|
||||
*/
|
||||
public static function prepare(ManiaControl $maniaControl) {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @see \ManiaControl\Plugins\Plugin::load()
|
||||
*/
|
||||
public function load(ManiaControl $maniaControl) {
|
||||
$this->maniaControl = $maniaControl;
|
||||
$this->initTables();
|
||||
|
||||
// Init settings
|
||||
$this->maniaControl->settingManager->initSetting($this, self::SETTING_WIDGET_TITLE, 'Local Records');
|
||||
$this->maniaControl->settingManager->initSetting($this, self::SETTING_WIDGET_POSX, -139.);
|
||||
$this->maniaControl->settingManager->initSetting($this, self::SETTING_WIDGET_POSY, 75);
|
||||
$this->maniaControl->settingManager->initSetting($this, self::SETTING_WIDGET_WIDTH, 40.);
|
||||
$this->maniaControl->settingManager->initSetting($this, self::SETTING_WIDGET_LINESCOUNT, 15);
|
||||
$this->maniaControl->settingManager->initSetting($this, self::SETTING_WIDGET_LINEHEIGHT, 4.);
|
||||
$this->maniaControl->settingManager->initSetting($this, self::SETTING_WIDGET_ENABLE, true);
|
||||
$this->maniaControl->settingManager->initSetting($this, self::SETTING_NOTIFY_ONLY_DRIVER, false);
|
||||
$this->maniaControl->settingManager->initSetting($this, self::SETTING_NOTIFY_BEST_RECORDS, -1);
|
||||
$this->maniaControl->settingManager->initSetting($this, self::SETTING_ADJUST_OUTER_BORDER, false);
|
||||
|
||||
// Register for callbacks
|
||||
$this->maniaControl->timerManager->registerTimerListening($this, 'handle1Second', 1000);
|
||||
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_AFTERINIT, $this, 'handleAfterInit');
|
||||
$this->maniaControl->callbackManager->registerCallbackListener(Callbacks::BEGINMAP, $this, 'handleMapBegin');
|
||||
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_TM_PLAYERFINISH, $this, 'handlePlayerFinish');
|
||||
$this->maniaControl->callbackManager->registerCallbackListener(PlayerManager::CB_PLAYERCONNECT, $this, 'handlePlayerConnect');
|
||||
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_TM_PLAYERCHECKPOINT, $this, 'handlePlayerCheckpoint');
|
||||
$this->maniaControl->callbackManager->registerCallbackListener(SettingManager::CB_SETTINGS_CHANGED, $this, 'handleSettingsChanged');
|
||||
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MP_PLAYERMANIALINKPAGEANSWER, $this, 'handleManialinkPageAnswer');
|
||||
$this->maniaControl->commandManager->registerCommandListener(array('recs', 'records'), $this, 'showRecordsList', false, 'Shows a list of Local Records on the current map.');
|
||||
$this->maniaControl->commandManager->registerCommandListener('delrec', $this, 'deleteRecord', true, 'Removes a record from the database.');
|
||||
|
||||
$this->updateManialink = true;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @see \ManiaControl\Plugins\Plugin::unload()
|
||||
*/
|
||||
public function unload() {
|
||||
$this->maniaControl->callbackManager->unregisterCallbackListener($this);
|
||||
$this->maniaControl->timerManager->unregisterTimerListenings($this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize needed database tables
|
||||
*/
|
||||
private function initTables() {
|
||||
$mysqli = $this->maniaControl->database->mysqli;
|
||||
$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::getId()
|
||||
*/
|
||||
public static function getId() {
|
||||
return self::ID;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @see \ManiaControl\Plugins\Plugin::getName()
|
||||
*/
|
||||
public static function getName() {
|
||||
return 'Local Records Plugin';
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @see \ManiaControl\Plugins\Plugin::getVersion()
|
||||
*/
|
||||
public static function getVersion() {
|
||||
return self::VERSION;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @see \ManiaControl\Plugins\Plugin::getAuthor()
|
||||
*/
|
||||
public static function getAuthor() {
|
||||
return 'steeffeen';
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @see \ManiaControl\Plugins\Plugin::getDescription()
|
||||
*/
|
||||
public static function getDescription() {
|
||||
return 'Plugin offering tracking of local records and manialinks to display them.';
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle ManiaControl After Init
|
||||
*/
|
||||
public function handleAfterInit() {
|
||||
$this->updateManialink = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle 1Second callback
|
||||
*
|
||||
* @param $time
|
||||
*/
|
||||
public function handle1Second($time) {
|
||||
if (!$this->updateManialink) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->updateManialink = false;
|
||||
if ($this->maniaControl->settingManager->getSetting($this, self::SETTING_WIDGET_ENABLE)) {
|
||||
$manialink = $this->buildManialink();
|
||||
$this->maniaControl->manialinkManager->sendManialink($manialink);
|
||||
}
|
||||
}
|
||||
|
||||
public function handleSettingsChanged($class, $settingName, $value) {
|
||||
if (!$class = get_class()) {
|
||||
return;
|
||||
}
|
||||
if ($settingName == 'Enable Local Records Widget' && $value == true) {
|
||||
$this->updateManialink = true;
|
||||
}
|
||||
elseif ($settingName == 'Enable Local Records Widget' && $value == false) {
|
||||
$ml = new ManiaLink(self::MLID_RECORDS);
|
||||
$mltext = $ml->render()->saveXML();
|
||||
$this->maniaControl->manialinkManager->sendManialink($mltext);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle PlayerCheckpoint callback
|
||||
*
|
||||
* @param $callback
|
||||
*/
|
||||
public function handlePlayerCheckpoint($callback) {
|
||||
$data = $callback[1];
|
||||
$login = $data[1];
|
||||
$time = $data[2];
|
||||
// $lap = $data[3];
|
||||
$cpIndex = $data[4];
|
||||
if (!isset($this->checkpoints[$login]) || $cpIndex <= 0) {
|
||||
$this->checkpoints[$login] = array();
|
||||
}
|
||||
$this->checkpoints[$login][$cpIndex] = $time;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle PlayerConnect callback
|
||||
*
|
||||
* @param Player $player
|
||||
*/
|
||||
public function handlePlayerConnect(Player $player) {
|
||||
$this->updateManialink = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle BeginMap callback
|
||||
*
|
||||
* @param Map $map
|
||||
*/
|
||||
public function handleMapBegin(Map $map) {
|
||||
$this->updateManialink = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle PlayerFinish callback
|
||||
*
|
||||
* @param array $callback
|
||||
*/
|
||||
public function handlePlayerFinish(array $callback) {
|
||||
$data = $callback[1];
|
||||
if ($data[0] <= 0 || $data[2] <= 0) {
|
||||
// Invalid player or time
|
||||
return;
|
||||
}
|
||||
|
||||
$login = $data[1];
|
||||
$player = $this->maniaControl->playerManager->getPlayer($login);
|
||||
if (!$player) {
|
||||
// Invalid player
|
||||
return;
|
||||
}
|
||||
|
||||
$time = $data[2];
|
||||
$map = $this->maniaControl->mapManager->getCurrentMap();
|
||||
|
||||
// Check old record of the player
|
||||
$oldRecord = $this->getLocalRecord($map, $player);
|
||||
$oldRank = -1;
|
||||
if ($oldRecord) {
|
||||
$oldRank = $oldRecord->rank;
|
||||
if ($oldRecord->time < $time) {
|
||||
// Not improved
|
||||
return;
|
||||
}
|
||||
if ($oldRecord->time == $time) {
|
||||
// Same time
|
||||
$message = '$<$fff' . $player->nickname . '$> equalized his/her $<$ff0' . $oldRecord->rank . '.$> Local Record: $<$fff' . Formatter::formatTime($oldRecord->time) . '$>!';
|
||||
$this->maniaControl->chat->sendInformation('$3c0' . $message);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Save time
|
||||
$mysqli = $this->maniaControl->database->mysqli;
|
||||
$query = "INSERT INTO `" . self::TABLE_RECORDS . "` (
|
||||
`mapIndex`,
|
||||
`playerIndex`,
|
||||
`time`,
|
||||
`checkpoints`
|
||||
) VALUES (
|
||||
{$map->index},
|
||||
{$player->index},
|
||||
{$time},
|
||||
'{$this->getCheckpoints($player->login)}'
|
||||
) 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, $player);
|
||||
|
||||
$notifyOnlyDriver = $this->maniaControl->settingManager->getSetting($this, self::SETTING_NOTIFY_ONLY_DRIVER);
|
||||
$notifyOnlyBestRecords = $this->maniaControl->settingManager->getSetting($this, self::SETTING_NOTIFY_BEST_RECORDS);
|
||||
if ($notifyOnlyDriver || $notifyOnlyBestRecords > 0 && $newRecord->rank > $notifyOnlyBestRecords) {
|
||||
$improvement = ((!$oldRecord || $newRecord->rank < $oldRecord->rank) ? 'gained the' : 'improved your');
|
||||
$message = 'You ' . $improvement . ' $<$ff0' . $newRecord->rank . '.$> Local Record: $<$fff' . Formatter::formatTime($newRecord->time) . '$>';
|
||||
if ($oldRecord) $oldRank = ($improvement == 'improved your') ? '' : $oldRecord->rank . '. ';
|
||||
if ($oldRecord) $message .= ' ($<$ff0' . $oldRank . '$>$<$fff-' . Formatter::formatTime(($oldRecord->time - $newRecord->time)) . '$>!';
|
||||
$this->maniaControl->chat->sendInformation('$3c0' . $message.'!', $player->login);
|
||||
} else {
|
||||
$improvement = ((!$oldRecord || $newRecord->rank < $oldRecord->rank) ? 'gained the' : 'improved the');
|
||||
$message = '$<$fff' . $player->nickname . '$> ' . $improvement . ' $<$ff0' . $newRecord->rank . '.$> Local Record: $<$fff' . Formatter::formatTime($newRecord->time) . '$>';
|
||||
if ($oldRecord) $oldRank = ($improvement == 'improved the') ? '' : $oldRecord->rank . '. ';
|
||||
if ($oldRecord) $message .= ' ($<$ff0' . $oldRank . '$>$<$fff-' . Formatter::formatTime(($oldRecord->time - $newRecord->time)) . '$>)';
|
||||
$this->maniaControl->chat->sendInformation('$3c0' . $message.'!');
|
||||
}
|
||||
|
||||
$this->maniaControl->callbackManager->triggerCallback(self::CB_LOCALRECORDS_CHANGED, $newRecord);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle PlayerManialinkPageAnswer callback
|
||||
*
|
||||
* @param array $callback
|
||||
*/
|
||||
public function handleManialinkPageAnswer(array $callback) {
|
||||
$actionId = $callback[1][2];
|
||||
|
||||
$login = $callback[1][1];
|
||||
$player = $this->maniaControl->playerManager->getPlayer($login);
|
||||
|
||||
if ($actionId == self::ACTION_SHOW_RECORDSLIST) {
|
||||
$this->showRecordsList(array(), $player);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a Player's record
|
||||
*
|
||||
* @param array $chat
|
||||
* @param Player $player
|
||||
*/
|
||||
public function deleteRecord(array $chat, Player $player) {
|
||||
if (!$this->maniaControl->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_MASTERADMIN)) {
|
||||
$this->maniaControl->authenticationManager->sendNotAllowed($player);
|
||||
return;
|
||||
}
|
||||
|
||||
$chatCommand = explode(' ', $chat[1][2]);
|
||||
$recordId = (int) $chatCommand[1];
|
||||
if (is_integer($recordId)) {
|
||||
$currentMap = $this->maniaControl->mapManager->getCurrentMap();
|
||||
$records = $this->getLocalRecords($currentMap);
|
||||
if (count($records) < $recordId) {
|
||||
$this->maniaControl->chat->sendError('Cannot remove record $<$fff' . $recordId . '$>!', $player);
|
||||
return;
|
||||
}
|
||||
|
||||
$mysqli = $this->maniaControl->database->mysqli;
|
||||
$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->callbackManager->triggerCallback(self::CB_LOCALRECORDS_CHANGED, null);
|
||||
$this->maniaControl->chat->sendInformation('Record no. $<$fff' . $recordId . '$> has been removed!');
|
||||
}
|
||||
else {
|
||||
$this->maniaControl->chat->sendError('Cannot remove record $<$fff' . $recordId . '$>, because it\'s not an integer!', $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->manialinkManager->styleManager->getListWidgetsWidth();
|
||||
$height = $this->maniaControl->manialinkManager->styleManager->getListWidgetsHeight();
|
||||
|
||||
// get PlayerList
|
||||
$records = $this->getLocalRecords($this->maniaControl->mapManager->getCurrentMap());
|
||||
|
||||
$pagesId = '';
|
||||
if (count($records) > 15) {
|
||||
$pagesId = 'RecordsListPages';
|
||||
}
|
||||
|
||||
// create manialink
|
||||
$maniaLink = new ManiaLink(ManialinkManager::MAIN_MLID);
|
||||
$script = $maniaLink->getScript();
|
||||
$paging = new Paging();
|
||||
$script->addFeature($paging);
|
||||
|
||||
// Main frame
|
||||
$frame = $this->maniaControl->manialinkManager->styleManager->getDefaultListFrame($script, $paging);
|
||||
$maniaLink->add($frame);
|
||||
|
||||
// Start offsets
|
||||
$x = -$width / 2;
|
||||
$y = $height / 2;
|
||||
|
||||
// Predefine Description Label
|
||||
$descriptionLabel = $this->maniaControl->manialinkManager->styleManager->getDefaultDescriptionLabel();
|
||||
$frame->add($descriptionLabel);
|
||||
|
||||
// Headline
|
||||
$headFrame = new Frame();
|
||||
$frame->add($headFrame);
|
||||
$headFrame->setY($y - 5);
|
||||
$array = array("Rank" => $x + 5, "Nickname" => $x + 18, "Login" => $x + 70, "Time" => $x + 101);
|
||||
$this->maniaControl->manialinkManager->labelLine($headFrame, $array);
|
||||
|
||||
$i = 0;
|
||||
$y = $height / 2 - 10;
|
||||
$pageFrames = array();
|
||||
foreach ($records as $listRecord) {
|
||||
if (!isset($pageFrame)) {
|
||||
$pageFrame = new Frame();
|
||||
$frame->add($pageFrame);
|
||||
if (!empty($pageFrames)) {
|
||||
$pageFrame->setVisible(false);
|
||||
}
|
||||
array_push($pageFrames, $pageFrame);
|
||||
$y = $height / 2 - 10;
|
||||
|
||||
$paging->addPage($pageFrame);
|
||||
}
|
||||
|
||||
$recordFrame = new Frame();
|
||||
$pageFrame->add($recordFrame);
|
||||
|
||||
if ($i % 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 => $x + 5, '$fff' . $listRecord->nickname => $x + 18, $listRecord->login => $x + 70,
|
||||
Formatter::formatTime($listRecord->time) => $x + 101);
|
||||
$this->maniaControl->manialinkManager->labelLine($recordFrame, $array);
|
||||
|
||||
$recordFrame->setY($y);
|
||||
|
||||
$y -= 4;
|
||||
$i++;
|
||||
if ($i % 15 == 0) {
|
||||
unset($pageFrame);
|
||||
}
|
||||
}
|
||||
|
||||
// Render and display xml
|
||||
$this->maniaControl->manialinkManager->displayWidget($maniaLink, $player, 'PlayerList');
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the local records manialink
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function buildManialink() {
|
||||
$map = $this->maniaControl->mapManager->getCurrentMap();
|
||||
if (!$map) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$title = $this->maniaControl->settingManager->getSetting($this, self::SETTING_WIDGET_TITLE);
|
||||
$pos_x = $this->maniaControl->settingManager->getSetting($this, self::SETTING_WIDGET_POSX);
|
||||
$pos_y = $this->maniaControl->settingManager->getSetting($this, self::SETTING_WIDGET_POSY);
|
||||
$width = $this->maniaControl->settingManager->getSetting($this, self::SETTING_WIDGET_WIDTH);
|
||||
$lines = $this->maniaControl->settingManager->getSetting($this, self::SETTING_WIDGET_LINESCOUNT);
|
||||
$lineHeight = $this->maniaControl->settingManager->getSetting($this, self::SETTING_WIDGET_LINEHEIGHT);
|
||||
$labelStyle = $this->maniaControl->manialinkManager->styleManager->getDefaultLabelStyle();
|
||||
$quadStyle = $this->maniaControl->manialinkManager->styleManager->getDefaultQuadStyle();
|
||||
$quadSubstyle = $this->maniaControl->manialinkManager->styleManager->getDefaultQuadSubstyle();
|
||||
|
||||
$records = $this->getLocalRecords($map);
|
||||
if (!is_array($records)) {
|
||||
trigger_error("Couldn't fetch player records.");
|
||||
return null;
|
||||
}
|
||||
|
||||
$manialink = new ManiaLink(self::MLID_RECORDS);
|
||||
$frame = new Frame();
|
||||
$manialink->add($frame);
|
||||
$frame->setPosition($pos_x, $pos_y);
|
||||
|
||||
$backgroundQuad = new Quad();
|
||||
$frame->add($backgroundQuad);
|
||||
$backgroundQuad->setVAlign(Control::TOP);
|
||||
$adjustOuterBorder = $this->maniaControl->settingManager->getSetting($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(Control::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(Control::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(Control::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->database->mysqli;
|
||||
$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;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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->database->mysqli;
|
||||
$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;
|
||||
}
|
||||
}
|
563
application/plugins/MCTeam/ServerRankingPlugin.php
Normal file
563
application/plugins/MCTeam/ServerRankingPlugin.php
Normal file
@ -0,0 +1,563 @@
|
||||
<?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\Maps\Map;
|
||||
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 kremsy
|
||||
* @copyright ManiaControl 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 = 'ServerRankingPlugin';
|
||||
const PLUGIN_AUTHOR = 'kremsy';
|
||||
const TABLE_RANK = 'mc_rank';
|
||||
const RANKING_TYPE_RECORDS = 'Records';
|
||||
const RANKING_TYPE_RATIOS = 'Ratios';
|
||||
const RANKING_TYPE_POINTS = 'Points';
|
||||
const SETTING_MIN_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;
|
||||
|
||||
/**
|
||||
* Prepares the Plugin
|
||||
*
|
||||
* @param ManiaControl $maniaControl
|
||||
* @return mixed
|
||||
*/
|
||||
public static function prepare(ManiaControl $maniaControl) {
|
||||
//Todo
|
||||
}
|
||||
|
||||
/**
|
||||
* Load the plugin
|
||||
*
|
||||
* @param \ManiaControl\ManiaControl $maniaControl
|
||||
* @throws Exception
|
||||
* @return bool
|
||||
*/
|
||||
public function load(ManiaControl $maniaControl) {
|
||||
$this->maniaControl = $maniaControl;
|
||||
|
||||
$this->initTables();
|
||||
|
||||
$maniaControl->settingManager->initSetting($this, self::SETTING_MIN_HITS_RATIO_RANKING, 100);
|
||||
$maniaControl->settingManager->initSetting($this, self::SETTING_MIN_HITS_POINTS_RANKING, 15);
|
||||
|
||||
$maniaControl->settingManager->initSetting($this, self::SETTING_MIN_REQUIRED_RECORDS, 3);
|
||||
$maniaControl->settingManager->initSetting($this, self::SETTING_MAX_STORED_RECORDS, 50);
|
||||
|
||||
$script = $this->maniaControl->client->getScriptName();
|
||||
|
||||
if ($this->maniaControl->mapManager->getCurrentMap()->getGame() == 'tm') {
|
||||
//TODO also add obstacle here as default
|
||||
$maniaControl->settingManager->initSetting($this, self::SETTING_MIN_RANKING_TYPE, self::RANKING_TYPE_RECORDS);
|
||||
} else if ($script["CurrentValue"] == "InstaDM.Script.txt") {
|
||||
$maniaControl->settingManager->initSetting($this, self::SETTING_MIN_RANKING_TYPE, self::RANKING_TYPE_RATIOS);
|
||||
} else {
|
||||
$maniaControl->settingManager->initSetting($this, self::SETTING_MIN_RANKING_TYPE, self::RANKING_TYPE_POINTS);
|
||||
}
|
||||
|
||||
//Check if the type is Correct
|
||||
$type = $this->maniaControl->settingManager->getSetting($this, self::SETTING_MIN_RANKING_TYPE);
|
||||
if ($type != self::RANKING_TYPE_RECORDS && $type != self::RANKING_TYPE_POINTS && $type != self::RANKING_TYPE_RATIOS) {
|
||||
$error = 'Ranking Type is not correct, possible values(' . self::RANKING_TYPE_RATIOS . ', ' . self::RANKING_TYPE_POINTS . ', ' . self::RANKING_TYPE_POINTS . ')';
|
||||
throw new Exception($error);
|
||||
}
|
||||
|
||||
//Register CallbackListeners
|
||||
$this->maniaControl->callbackManager->registerCallbackListener(PlayerManager::CB_PLAYERCONNECT, $this, 'handlePlayerConnect');
|
||||
$this->maniaControl->callbackManager->registerCallbackListener(Callbacks::ENDMAP, $this, 'handleEndMap');
|
||||
|
||||
//Register CommandListener
|
||||
$this->maniaControl->commandManager->registerCommandListener('rank', $this, 'command_showRank', false, 'Shows your current serverrank.');
|
||||
$this->maniaControl->commandManager->registerCommandListener('nextrank', $this, 'command_nextRank', false, 'Shows the person in front of you in the serverranking.');
|
||||
$this->maniaControl->commandManager->registerCommandListener(array('topranks', 'top100'), $this, 'command_topRanks', false, 'Shows an overview of the best-ranked 100 players.');
|
||||
|
||||
$this->resetRanks(); //TODO only update records count
|
||||
}
|
||||
|
||||
/**
|
||||
* Unload the plugin and its resources
|
||||
*/
|
||||
public function unload() {
|
||||
$this->maniaControl->callbackManager->unregisterCallbackListener($this);
|
||||
$this->maniaControl->commandManager->unregisterCommandListener($this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get plugin id
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public static function getId() {
|
||||
return self::PLUGIN_ID;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Plugin Name
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function getName() {
|
||||
return self::PLUGIN_NAME;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Plugin Version
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
public static function getVersion() {
|
||||
return self::PLUGIN_VERSION;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Plugin Author
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function getAuthor() {
|
||||
return self::PLUGIN_AUTHOR;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Plugin Description
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
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";
|
||||
}
|
||||
|
||||
/**
|
||||
* Create necessary database tables
|
||||
*/
|
||||
private function initTables() {
|
||||
$mysqli = $this->maniaControl->database->mysqli;
|
||||
$query = "CREATE TABLE IF NOT EXISTS `" . self::TABLE_RANK . "` (
|
||||
`PlayerIndex` mediumint(9) NOT NULL default 0,
|
||||
`Rank` mediumint(9) NOT NULL default 0,
|
||||
`Avg` float NOT NULL default 0,
|
||||
KEY `PlayerIndex` (`PlayerIndex`),
|
||||
UNIQUE `Rank` (`Rank`)
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT='Mania Control Serverranking';";
|
||||
$mysqli->query($query);
|
||||
if ($mysqli->error) {
|
||||
trigger_error($mysqli->error, E_USER_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Resets and rebuilds the Ranking
|
||||
*/
|
||||
private function resetRanks() {
|
||||
$mysqli = $this->maniaControl->database->mysqli;
|
||||
|
||||
// Erase old Average Data
|
||||
$mysqli->query('TRUNCATE TABLE ' . self::TABLE_RANK);
|
||||
$type = $this->maniaControl->settingManager->getSetting($this, self::SETTING_MIN_RANKING_TYPE);
|
||||
|
||||
switch($type) {
|
||||
case self::RANKING_TYPE_RATIOS:
|
||||
$minHits = $this->maniaControl->settingManager->getSetting($this, self::SETTING_MIN_HITS_RATIO_RANKING);
|
||||
|
||||
$hits = $this->maniaControl->statisticManager->getStatsRanking(StatisticCollector::STAT_ON_HIT, -1, $minHits);
|
||||
$killDeathRatios = $this->maniaControl->statisticManager->getStatsRanking(StatisticManager::SPECIAL_STAT_KD_RATIO);
|
||||
$accuracies = $this->maniaControl->statisticManager->getStatsRanking(StatisticManager::SPECIAL_STAT_LASER_ACC);
|
||||
|
||||
$ranks = array();
|
||||
foreach($hits as $player => $hitCount) {
|
||||
if (!isset($killDeathRatios[$player]) || !isset($accuracies[$player])) {
|
||||
continue;
|
||||
}
|
||||
$ranks[$player] = $killDeathRatios[$player] * $accuracies[$player] * 1000;
|
||||
|
||||
}
|
||||
|
||||
arsort($ranks);
|
||||
|
||||
|
||||
break;
|
||||
case self::RANKING_TYPE_POINTS:
|
||||
$minHits = $this->maniaControl->settingManager->getSetting($this, self::SETTING_MIN_HITS_POINTS_RANKING);
|
||||
|
||||
$ranks = $this->maniaControl->statisticManager->getStatsRanking(StatisticCollector::STAT_ON_HIT, -1, $minHits);
|
||||
|
||||
break;
|
||||
case self::RANKING_TYPE_RECORDS: //TODO verify workable status
|
||||
if (!$this->maniaControl->pluginManager->isPluginActive('MCTeam\LocalRecordsPlugin')) {
|
||||
return;
|
||||
}
|
||||
|
||||
$requiredRecords = $this->maniaControl->settingManager->getSetting($this, self::SETTING_MIN_REQUIRED_RECORDS);
|
||||
$maxRecords = $this->maniaControl->settingManager->getSetting($this, self::SETTING_MAX_STORED_RECORDS);
|
||||
|
||||
$query = 'SELECT playerIndex, COUNT(*) AS Cnt
|
||||
FROM ' . \MCTeam\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();
|
||||
|
||||
/** @var \MCTeam\LocalRecordsPlugin $localRecordsPlugin */
|
||||
$localRecordsPlugin = $this->maniaControl->pluginManager->getPlugin('MCTeam\LocalRecordsPlugin');
|
||||
$maps = $this->maniaControl->mapManager->getMaps();
|
||||
foreach($maps as $map) {
|
||||
$records = $localRecordsPlugin->getLocalRecords($map, $maxRecords);
|
||||
|
||||
$i = 1;
|
||||
foreach($records as $record) {
|
||||
if (isset($players[$record->playerIndex])) {
|
||||
$players[$record->playerIndex][0] += $i;
|
||||
$players[$record->playerIndex][1]++;
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
|
||||
$mapCount = count($maps);
|
||||
|
||||
//compute each players new average score
|
||||
$ranks = array();
|
||||
foreach($players as $player => $val) {
|
||||
$sum = $val[0];
|
||||
$cnt = $val[1];
|
||||
// ranked maps sum + $maxRecs rank for all remaining maps
|
||||
$ranks[$player] = ($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 ";
|
||||
$i = 1;
|
||||
|
||||
foreach($ranks as $player => $rankValue) {
|
||||
$query .= '(' . $player . ',' . $i . ',' . $rankValue . '),';
|
||||
$i++;
|
||||
}
|
||||
$query = substr($query, 0, strlen($query) - 1); // strip trailing ','
|
||||
|
||||
$mysqli->query($query);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle PlayerConnect callback
|
||||
*
|
||||
* @param Player $player
|
||||
*/
|
||||
public function handlePlayerConnect(Player $player) {
|
||||
$this->showRank($player);
|
||||
$this->showNextRank($player);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows Ranks on endMap
|
||||
*
|
||||
* @param Map $map
|
||||
*/
|
||||
public function handleEndMap(Map $map) {
|
||||
$this->resetRanks();
|
||||
|
||||
foreach($this->maniaControl->playerManager->getPlayers() as $player) {
|
||||
/** @var Player $player */
|
||||
if ($player->isFakePlayer()) {
|
||||
continue;
|
||||
}
|
||||
$this->showRank($player);
|
||||
$this->showNextRank($player);
|
||||
}
|
||||
|
||||
// Trigger callback
|
||||
$this->maniaControl->callbackManager->triggerCallback(self::CB_RANK_BUILT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows the serverRank to a certain Player
|
||||
*
|
||||
* @param Player $player
|
||||
*/
|
||||
public function showRank(Player $player) {
|
||||
$rankObj = $this->getRank($player);
|
||||
|
||||
$type = $this->maniaControl->settingManager->getSetting($this, self::SETTING_MIN_RANKING_TYPE);
|
||||
|
||||
$message = '';
|
||||
if ($rankObj) {
|
||||
switch($type) {
|
||||
case self::RANKING_TYPE_RATIOS:
|
||||
$kd = $this->maniaControl->statisticManager->getStatisticData(StatisticManager::SPECIAL_STAT_KD_RATIO, $player->index);
|
||||
$acc = $this->maniaControl->statisticManager->getStatisticData(StatisticManager::SPECIAL_STAT_LASER_ACC, $player->index);
|
||||
$message = '$0f3Your Server rank is $<$ff3' . $rankObj->rank . '$> / $<$fff' . $this->recordCount . '$> (K/D: $<$fff' . round($kd, 2) . '$> Acc: $<$fff' . round($acc * 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->settingManager->getSetting($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:
|
||||
$minHits = $this->maniaControl->settingManager->getSetting($this, self::SETTING_MIN_HITS_POINTS_RANKING);
|
||||
$message = '$0f3 You must make $<$fff' . $minHits . '$> Hits on this server before receiving a rank...';
|
||||
break;
|
||||
case self::RANKING_TYPE_RECORDS:
|
||||
$minHits = $this->maniaControl->settingManager->getSetting($this, self::SETTING_MIN_REQUIRED_RECORDS);
|
||||
$message = '$0f3 You need $<$fff' . $minHits . '$> Records on this server before receiving a rank...';
|
||||
}
|
||||
}
|
||||
$this->maniaControl->chat->sendChat($message, $player->login);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets A Rank As Object with properties Avg PlayerIndex and Rank
|
||||
*
|
||||
* @param Player $player
|
||||
* @return Rank $rank
|
||||
*/
|
||||
private function getRank(Player $player) {
|
||||
//TODO setting global from db or local
|
||||
$mysqli = $this->maniaControl->database->mysqli;
|
||||
|
||||
$result = $mysqli->query('SELECT * FROM ' . self::TABLE_RANK . ' WHERE PlayerIndex=' . $player->index);
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Next Ranked Player
|
||||
*
|
||||
* @param Player $player
|
||||
* @return Rank
|
||||
*/
|
||||
private function getNextRank(Player $player) {
|
||||
$mysqli = $this->maniaControl->database->mysqli;
|
||||
$rankObject = $this->getRank($player);
|
||||
$nextRank = $rankObject->rank - 1;
|
||||
|
||||
$result = $mysqli->query('SELECT * FROM ' . self::TABLE_RANK . ' WHERE Rank=' . $nextRank);
|
||||
if ($result->num_rows > 0) {
|
||||
$row = $result->fetch_array();
|
||||
$result->free_result();
|
||||
return Rank::fromArray($row);
|
||||
} else {
|
||||
$result->free_result();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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->chat->sendChat($message, $player->login);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Shows which Player is next ranked to you
|
||||
*
|
||||
* @param Player $player
|
||||
*/
|
||||
public function showNextRank(Player $player) {
|
||||
$rankObject = $this->getRank($player);
|
||||
|
||||
if ($rankObject) {
|
||||
if ($rankObject->rank > 1) {
|
||||
$nextRank = $this->getNextRank($player);
|
||||
$nextPlayer = $this->maniaControl->playerManager->getPlayerByIndex($nextRank->playerIndex);
|
||||
$message = '$0f3The next better ranked player is $fff' . $nextPlayer->nickname;
|
||||
} else {
|
||||
$message = '$0f3No better ranked player :-)';
|
||||
}
|
||||
$this->maniaControl->chat->sendChat($message, $player->login);
|
||||
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles /topranks|top100 command
|
||||
*
|
||||
* @param array $chatCallback
|
||||
* @param Player $player
|
||||
*/
|
||||
public function command_topRanks(array $chatCallback, Player $player) {
|
||||
$this->showTopRanksList($player);
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides 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->database->mysqli;
|
||||
$result = $mysqli->query($query);
|
||||
if ($mysqli->error) {
|
||||
trigger_error($mysqli->error);
|
||||
return null;
|
||||
}
|
||||
|
||||
$width = $this->maniaControl->manialinkManager->styleManager->getListWidgetsWidth();
|
||||
$height = $this->maniaControl->manialinkManager->styleManager->getListWidgetsHeight();
|
||||
|
||||
// create manialink
|
||||
$maniaLink = new ManiaLink(ManialinkManager::MAIN_MLID);
|
||||
$script = $maniaLink->getScript();
|
||||
$paging = new Paging();
|
||||
$script->addFeature($paging);
|
||||
|
||||
// Main frame
|
||||
$frame = $this->maniaControl->manialinkManager->styleManager->getDefaultListFrame($script, $paging);
|
||||
$maniaLink->add($frame);
|
||||
|
||||
// Start offsets
|
||||
$x = -$width / 2;
|
||||
$y = $height / 2;
|
||||
|
||||
//Predefine description Label
|
||||
$descriptionLabel = $this->maniaControl->manialinkManager->styleManager->getDefaultDescriptionLabel();
|
||||
$frame->add($descriptionLabel);
|
||||
|
||||
// Headline
|
||||
$headFrame = new Frame();
|
||||
$frame->add($headFrame);
|
||||
$headFrame->setY($y - 5);
|
||||
$array = array('$oRank' => $x + 5, '$oNickname' => $x + 18, '$oAverage' => $x + 70);
|
||||
$this->maniaControl->manialinkManager->labelLine($headFrame, $array);
|
||||
|
||||
$i = 1;
|
||||
$y = $y - 10;
|
||||
$pageFrames = array();
|
||||
while($rankedPlayer = $result->fetch_object()) {
|
||||
if (!isset($pageFrame)) {
|
||||
$pageFrame = new Frame();
|
||||
$frame->add($pageFrame);
|
||||
if (!empty($pageFrames)) {
|
||||
$pageFrame->setVisible(false);
|
||||
}
|
||||
array_push($pageFrames, $pageFrame);
|
||||
$y = $height / 2 - 10;
|
||||
$paging->addPage($pageFrame);
|
||||
}
|
||||
|
||||
|
||||
$playerFrame = new Frame();
|
||||
$pageFrame->add($playerFrame);
|
||||
$playerFrame->setY($y);
|
||||
|
||||
if ($i % 2 != 0) {
|
||||
$lineQuad = new Quad_BgsPlayerCard();
|
||||
$playerFrame->add($lineQuad);
|
||||
$lineQuad->setSize($width, 4);
|
||||
$lineQuad->setSubStyle($lineQuad::SUBSTYLE_BgPlayerCardBig);
|
||||
$lineQuad->setZ(0.001);
|
||||
}
|
||||
|
||||
$playerObject = $this->maniaControl->playerManager->getPlayerByIndex($rankedPlayer->PlayerIndex);
|
||||
$array = array($rankedPlayer->Rank => $x + 5, $playerObject->nickname => $x + 18, (string)round($rankedPlayer->Avg, 2) => $x + 70);
|
||||
$this->maniaControl->manialinkManager->labelLine($playerFrame, $array);
|
||||
|
||||
$y -= 4;
|
||||
$i++;
|
||||
if (($i - 1) % 15 == 0) {
|
||||
unset($pageFrame);
|
||||
}
|
||||
}
|
||||
|
||||
// Render and display xml
|
||||
$this->maniaControl->manialinkManager->displayWidget($maniaLink, $player, 'TopRanks');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Rank Structure
|
||||
*/
|
||||
class Rank extends AbstractStructure {
|
||||
public $playerIndex;
|
||||
public $rank;
|
||||
public $avg;
|
||||
}
|
592
application/plugins/MCTeam/WidgetPlugin.php
Normal file
592
application/plugins/MCTeam/WidgetPlugin.php
Normal file
@ -0,0 +1,592 @@
|
||||
<?php
|
||||
|
||||
namespace MCTeam;
|
||||
|
||||
use FML\Controls\Control;
|
||||
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\Formatter;
|
||||
use ManiaControl\ManiaControl;
|
||||
use ManiaControl\Manialinks\IconManager;
|
||||
use ManiaControl\Maps\Map;
|
||||
use ManiaControl\Players\Player;
|
||||
use ManiaControl\Players\PlayerManager;
|
||||
use ManiaControl\Plugins\Plugin;
|
||||
|
||||
/**
|
||||
* 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_MAPWIDGET = '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_CLOCKWIDGET = '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_NEXTMAPWIDGET = '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_SERVERINFOWIDGET = '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;
|
||||
|
||||
/**
|
||||
* Prepares the Plugin
|
||||
*
|
||||
* @param ManiaControl $maniaControl
|
||||
* @return mixed
|
||||
*/
|
||||
public static function prepare(ManiaControl $maniaControl) {
|
||||
//do nothing
|
||||
}
|
||||
|
||||
/**
|
||||
* Get plugin id
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public static function getId() {
|
||||
return self::PLUGIN_ID;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Plugin Name
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function getName() {
|
||||
return self::PLUGIN_NAME;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Plugin Version
|
||||
*
|
||||
* @return float,,
|
||||
*/
|
||||
public static function getVersion() {
|
||||
return self::PLUGIN_VERSION;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Plugin Author
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function getAuthor() {
|
||||
return self::PLUGIN_AUTHOR;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Plugin Description
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function getDescription() {
|
||||
return 'Plugin offers some Widgets';
|
||||
}
|
||||
|
||||
/**
|
||||
* Load the plugin
|
||||
*
|
||||
* @param ManiaControl $maniaControl
|
||||
* @return bool
|
||||
*/
|
||||
public function load(ManiaControl $maniaControl) {
|
||||
$this->maniaControl = $maniaControl;
|
||||
|
||||
// Set CustomUI Setting
|
||||
$this->maniaControl->manialinkManager->customUIManager->setChallengeInfoVisible(false);
|
||||
|
||||
// Register for callbacks
|
||||
$this->maniaControl->callbackManager->registerCallbackListener(Callbacks::BEGINMAP, $this, 'handleOnBeginMap');
|
||||
$this->maniaControl->callbackManager->registerCallbackListener(Callbacks::ENDMAP, $this, 'handleOnEndMap');
|
||||
$this->maniaControl->callbackManager->registerCallbackListener(PlayerManager::CB_PLAYERCONNECT, $this, 'handlePlayerConnect');
|
||||
$this->maniaControl->callbackManager->registerCallbackListener(PlayerManager::CB_PLAYERDISCONNECT, $this, 'handlePlayerDisconnect');
|
||||
|
||||
$this->maniaControl->settingManager->initSetting($this, self::SETTING_MAP_WIDGET_ACTIVATED, true);
|
||||
$this->maniaControl->settingManager->initSetting($this, self::SETTING_MAP_WIDGET_POSX, 160 - 20);
|
||||
$this->maniaControl->settingManager->initSetting($this, self::SETTING_MAP_WIDGET_POSY, 90 - 4.5);
|
||||
$this->maniaControl->settingManager->initSetting($this, self::SETTING_MAP_WIDGET_WIDTH, 40);
|
||||
$this->maniaControl->settingManager->initSetting($this, self::SETTING_MAP_WIDGET_HEIGHT, 9.);
|
||||
|
||||
$this->maniaControl->settingManager->initSetting($this, self::SETTING_SERVERINFO_WIDGET_ACTIVATED, true);
|
||||
$this->maniaControl->settingManager->initSetting($this, self::SETTING_SERVERINFO_WIDGET_POSX, -160 + 17.5);
|
||||
$this->maniaControl->settingManager->initSetting($this, self::SETTING_SERVERINFO_WIDGET_POSY, 90 - 4.5);
|
||||
$this->maniaControl->settingManager->initSetting($this, self::SETTING_SERVERINFO_WIDGET_WIDTH, 35);
|
||||
$this->maniaControl->settingManager->initSetting($this, self::SETTING_SERVERINFO_WIDGET_HEIGHT, 9.);
|
||||
|
||||
$this->maniaControl->settingManager->initSetting($this, self::SETTING_NEXTMAP_WIDGET_ACTIVATED, true);
|
||||
$this->maniaControl->settingManager->initSetting($this, self::SETTING_NEXTMAP_WIDGET_POSX, 160 - 20);
|
||||
$this->maniaControl->settingManager->initSetting($this, self::SETTING_NEXTMAP_WIDGET_POSY, 90 - 25.5);
|
||||
$this->maniaControl->settingManager->initSetting($this, self::SETTING_NEXTMAP_WIDGET_WIDTH, 40);
|
||||
$this->maniaControl->settingManager->initSetting($this, self::SETTING_NEXTMAP_WIDGET_HEIGHT, 12.);
|
||||
|
||||
$this->maniaControl->settingManager->initSetting($this, self::SETTING_CLOCK_WIDGET_ACTIVATED, true);
|
||||
$this->maniaControl->settingManager->initSetting($this, self::SETTING_CLOCK_WIDGET_POSX, 160 - 5);
|
||||
$this->maniaControl->settingManager->initSetting($this, self::SETTING_CLOCK_WIDGET_POSY, 90 - 11);
|
||||
$this->maniaControl->settingManager->initSetting($this, self::SETTING_CLOCK_WIDGET_WIDTH, 10);
|
||||
$this->maniaControl->settingManager->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->settingManager->getSetting($this, self::SETTING_MAP_WIDGET_ACTIVATED)) {
|
||||
$this->maniaControl->client->triggerModeScriptEventArray("Siege_SetProgressionLayerPosition", array("160.", "-67.", "0."));
|
||||
$this->displayMapWidget();
|
||||
}
|
||||
if ($this->maniaControl->settingManager->getSetting($this, self::SETTING_CLOCK_WIDGET_ACTIVATED)) {
|
||||
$this->displayClockWidget();
|
||||
}
|
||||
if ($this->maniaControl->settingManager->getSetting($this, self::SETTING_SERVERINFO_WIDGET_ACTIVATED)) {
|
||||
$this->displayServerInfoWidget();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the Map Widget
|
||||
*
|
||||
* @param string $login
|
||||
*/
|
||||
public function displayMapWidget($login = null) {
|
||||
$pos_x = $this->maniaControl->settingManager->getSetting($this, self::SETTING_MAP_WIDGET_POSX);
|
||||
$pos_y = $this->maniaControl->settingManager->getSetting($this, self::SETTING_MAP_WIDGET_POSY);
|
||||
$width = $this->maniaControl->settingManager->getSetting($this, self::SETTING_MAP_WIDGET_WIDTH);
|
||||
$height = $this->maniaControl->settingManager->getSetting($this, self::SETTING_MAP_WIDGET_HEIGHT);
|
||||
$quadStyle = $this->maniaControl->manialinkManager->styleManager->getDefaultQuadStyle();
|
||||
$quadSubstyle = $this->maniaControl->manialinkManager->styleManager->getDefaultQuadSubstyle();
|
||||
|
||||
$maniaLink = new ManiaLink(self::MLID_MAPWIDGET);
|
||||
$script = new Script();
|
||||
$maniaLink->setScript($script);
|
||||
|
||||
// mainframe
|
||||
$frame = new Frame();
|
||||
$maniaLink->add($frame);
|
||||
$frame->setSize($width, $height);
|
||||
$frame->setPosition($pos_x, $pos_y);
|
||||
|
||||
// Background Quad
|
||||
$backgroundQuad = new Quad();
|
||||
$frame->add($backgroundQuad);
|
||||
$backgroundQuad->setSize($width, $height);
|
||||
$backgroundQuad->setStyles($quadStyle, $quadSubstyle);
|
||||
$backgroundQuad->addMapInfoFeature();
|
||||
|
||||
$map = $this->maniaControl->mapManager->getCurrentMap();
|
||||
|
||||
$label = new Label_Text();
|
||||
$frame->add($label);
|
||||
$label->setY(1.5);
|
||||
$label->setX(0);
|
||||
$label->setAlign(Control::CENTER, Control::CENTER);
|
||||
$label->setZ(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->setX(0);
|
||||
$label->setY(-1.4);
|
||||
|
||||
$label->setAlign(Control::CENTER, Control::CENTER);
|
||||
$label->setZ(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->manialinkManager->iconManager->getIcon(IconManager::MX_ICON_MOVER));
|
||||
$quad->setImage($this->maniaControl->manialinkManager->iconManager->getIcon(IconManager::MX_ICON));
|
||||
$quad->setPosition(-$width / 2 + 4, -1.5, -0.5);
|
||||
$quad->setSize(4, 4);
|
||||
$quad->setHAlign(Control::CENTER);
|
||||
$quad->setUrl($map->mx->pageurl);
|
||||
}
|
||||
|
||||
// Send manialink
|
||||
$this->maniaControl->manialinkManager->sendManialink($maniaLink, $login);
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays the Clock Widget
|
||||
*
|
||||
* @param bool $login
|
||||
*/
|
||||
public function displayClockWidget($login = false) {
|
||||
$pos_x = $this->maniaControl->settingManager->getSetting($this, self::SETTING_CLOCK_WIDGET_POSX);
|
||||
$pos_y = $this->maniaControl->settingManager->getSetting($this, self::SETTING_CLOCK_WIDGET_POSY);
|
||||
$width = $this->maniaControl->settingManager->getSetting($this, self::SETTING_CLOCK_WIDGET_WIDTH);
|
||||
$height = $this->maniaControl->settingManager->getSetting($this, self::SETTING_CLOCK_WIDGET_HEIGHT);
|
||||
$quadStyle = $this->maniaControl->manialinkManager->styleManager->getDefaultQuadStyle();
|
||||
$quadSubstyle = $this->maniaControl->manialinkManager->styleManager->getDefaultQuadSubstyle();
|
||||
|
||||
$maniaLink = new ManiaLink(self::MLID_CLOCKWIDGET);
|
||||
|
||||
// mainframe
|
||||
$frame = new Frame();
|
||||
$maniaLink->add($frame);
|
||||
$frame->setSize($width, $height);
|
||||
$frame->setPosition($pos_x, $pos_y);
|
||||
|
||||
// Background Quad
|
||||
$backgroundQuad = new Quad();
|
||||
$frame->add($backgroundQuad);
|
||||
$backgroundQuad->setSize($width, $height);
|
||||
$backgroundQuad->setStyles($quadStyle, $quadSubstyle);
|
||||
|
||||
$label = new Label_Text();
|
||||
$frame->add($label);
|
||||
$label->setY(1.5);
|
||||
$label->setX(0);
|
||||
$label->setAlign(Control::CENTER, Control::TOP);
|
||||
$label->setZ(0.2);
|
||||
$label->setTextSize(1);
|
||||
$label->setTextColor("FFF");
|
||||
$label->addClockFeature(false);
|
||||
|
||||
// Send manialink
|
||||
$this->maniaControl->manialinkManager->sendManialink($maniaLink, $login);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the Server Info Widget
|
||||
*
|
||||
* @param string $login
|
||||
*/
|
||||
public function displayServerInfoWidget($login = null) {
|
||||
$pos_x = $this->maniaControl->settingManager->getSetting($this, self::SETTING_SERVERINFO_WIDGET_POSX);
|
||||
$pos_y = $this->maniaControl->settingManager->getSetting($this, self::SETTING_SERVERINFO_WIDGET_POSY);
|
||||
$width = $this->maniaControl->settingManager->getSetting($this, self::SETTING_SERVERINFO_WIDGET_WIDTH);
|
||||
$height = $this->maniaControl->settingManager->getSetting($this, self::SETTING_SERVERINFO_WIDGET_HEIGHT);
|
||||
$quadStyle = $this->maniaControl->manialinkManager->styleManager->getDefaultQuadStyle();
|
||||
$quadSubstyle = $this->maniaControl->manialinkManager->styleManager->getDefaultQuadSubstyle();
|
||||
|
||||
$maniaLink = new ManiaLink(self::MLID_SERVERINFOWIDGET);
|
||||
|
||||
// mainframe
|
||||
$frame = new Frame();
|
||||
$maniaLink->add($frame);
|
||||
$frame->setSize($width, $height);
|
||||
$frame->setPosition($pos_x, $pos_y);
|
||||
|
||||
// Background Quad
|
||||
$backgroundQuad = new Quad();
|
||||
$frame->add($backgroundQuad);
|
||||
$backgroundQuad->setSize($width, $height);
|
||||
$backgroundQuad->setStyles($quadStyle, $quadSubstyle);
|
||||
|
||||
$maxPlayers = $this->maniaControl->client->getMaxPlayers();
|
||||
|
||||
$maxSpectators = $this->maniaControl->client->getMaxSpectators();
|
||||
|
||||
$serverName = $this->maniaControl->client->getServerName();
|
||||
|
||||
$players = $this->maniaControl->playerManager->getPlayers();
|
||||
$playerCount = 0;
|
||||
$spectatorCount = 0;
|
||||
/**
|
||||
* @var Player $player
|
||||
*/
|
||||
foreach ($players as $player) {
|
||||
if ($player->isSpectator) {
|
||||
$spectatorCount++;
|
||||
} else {
|
||||
$playerCount++;
|
||||
}
|
||||
}
|
||||
|
||||
$label = new Label_Text();
|
||||
$frame->add($label);
|
||||
$label->setPosition(0, 1.5, 0.2);
|
||||
$label->setAlign(Control::CENTER, Control::CENTER);
|
||||
$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->setAlign(Control::LEFT, Control::CENTER);
|
||||
$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);
|
||||
$quad->setHAlign(Control::CENTER);
|
||||
|
||||
// Spectator Quad / Label
|
||||
$label = new Label_Text();
|
||||
$frame->add($label);
|
||||
$label->setPosition(2, -1.5, 0.2);
|
||||
$label->setAlign(Control::LEFT, Control::CENTER);
|
||||
$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);
|
||||
$quad->setHAlign(Control::CENTER);
|
||||
|
||||
// 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->setHAlign(Control::CENTER);
|
||||
$quad->setManialink('mcontrol?favorite=' . urlencode($this->maniaControl->server->login));
|
||||
|
||||
// Send manialink
|
||||
$this->maniaControl->manialinkManager->sendManialink($maniaLink, $login);
|
||||
}
|
||||
|
||||
/**
|
||||
* Unload the plugin and its resources
|
||||
*/
|
||||
public function unload() {
|
||||
//Restore Siege Progression Layer
|
||||
$this->maniaControl->client->triggerModeScriptEventArray("Siege_SetProgressionLayerPosition", array("160.", "90.", "0."));
|
||||
|
||||
$this->closeWidget(self::MLID_CLOCKWIDGET);
|
||||
$this->closeWidget(self::MLID_SERVERINFOWIDGET);
|
||||
$this->closeWidget(self::MLID_MAPWIDGET);
|
||||
$this->closeWidget(self::MLID_NEXTMAPWIDGET);
|
||||
$this->maniaControl->callbackManager->unregisterCallbackListener($this);
|
||||
$this->maniaControl->timerManager->unregisterTimerListenings($this);
|
||||
unset($this->maniaControl);
|
||||
}
|
||||
|
||||
/**
|
||||
* Closes a Widget
|
||||
*
|
||||
* @param $widgetId
|
||||
*/
|
||||
public function closeWidget($widgetId) {
|
||||
$emptyManialink = new ManiaLink($widgetId);
|
||||
$this->maniaControl->manialinkManager->sendManialink($emptyManialink);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle on Begin Map
|
||||
*
|
||||
* @param Map $map
|
||||
*/
|
||||
public function handleOnBeginMap(Map $map) {
|
||||
// Display Map Widget
|
||||
if ($this->maniaControl->settingManager->getSetting($this, self::SETTING_MAP_WIDGET_ACTIVATED)) {
|
||||
$this->displayMapWidget();
|
||||
}
|
||||
$this->closeWidget(self::MLID_NEXTMAPWIDGET);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle on End Map
|
||||
*
|
||||
* @param Map $map
|
||||
*/
|
||||
public function handleOnEndMap(Map $map) {
|
||||
// Display Map Widget
|
||||
if ($this->maniaControl->settingManager->getSetting($this, self::SETTING_NEXTMAP_WIDGET_ACTIVATED)) {
|
||||
$this->displayNextMapWidget();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays the Next Map (Only at the end of the Map)
|
||||
*
|
||||
* @param bool $login
|
||||
*/
|
||||
public function displayNextMapWidget($login = false) {
|
||||
$pos_x = $this->maniaControl->settingManager->getSetting($this, self::SETTING_NEXTMAP_WIDGET_POSX);
|
||||
$pos_y = $this->maniaControl->settingManager->getSetting($this, self::SETTING_NEXTMAP_WIDGET_POSY);
|
||||
$width = $this->maniaControl->settingManager->getSetting($this, self::SETTING_NEXTMAP_WIDGET_WIDTH);
|
||||
$height = $this->maniaControl->settingManager->getSetting($this, self::SETTING_NEXTMAP_WIDGET_HEIGHT);
|
||||
$quadStyle = $this->maniaControl->manialinkManager->styleManager->getDefaultQuadStyle();
|
||||
$quadSubstyle = $this->maniaControl->manialinkManager->styleManager->getDefaultQuadSubstyle();
|
||||
$labelStyle = $this->maniaControl->manialinkManager->styleManager->getDefaultLabelStyle();
|
||||
|
||||
$maniaLink = new ManiaLink(self::MLID_NEXTMAPWIDGET);
|
||||
|
||||
// mainframe
|
||||
$frame = new Frame();
|
||||
$maniaLink->add($frame);
|
||||
$frame->setSize($width, $height);
|
||||
$frame->setPosition($pos_x, $pos_y);
|
||||
|
||||
// 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->mapManager->mapQueue->getNextMap();
|
||||
|
||||
/**
|
||||
* @var Player $requester
|
||||
*/
|
||||
$requester = null;
|
||||
// if the nextmap is not a queued map, get it from map info
|
||||
if (!$queuedMap) {
|
||||
$map = $this->maniaControl->client->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->setY($height / 2 - 2.3);
|
||||
$label->setX(0);
|
||||
$label->setAlign(Control::CENTER, Control::CENTER);
|
||||
$label->setZ(0.2);
|
||||
$label->setTextSize(1);
|
||||
$label->setText("Next Map");
|
||||
$label->setTextColor("FFF");
|
||||
$label->setStyle($labelStyle);
|
||||
|
||||
$label = new Label_Text();
|
||||
$frame->add($label);
|
||||
$label->setY($height / 2 - 5.5);
|
||||
$label->setX(0);
|
||||
$label->setAlign(Control::CENTER, Control::CENTER);
|
||||
$label->setZ(0.2);
|
||||
$label->setTextSize(1.3);
|
||||
$label->setText($name);
|
||||
$label->setTextColor("FFF");
|
||||
|
||||
$label = new Label_Text();
|
||||
$frame->add($label);
|
||||
$label->setX(0);
|
||||
$label->setY(-$height / 2 + 4);
|
||||
|
||||
$label->setAlign(Control::CENTER, Control::CENTER);
|
||||
$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->setX(0);
|
||||
$label->setY(-$height / 2 + 2);
|
||||
$label->setAlign(Control::CENTER, Control::CENTER);
|
||||
$label->setZ(0.2);
|
||||
$label->setTextSize(1);
|
||||
$label->setScale(0.7);
|
||||
$label->setText($author);
|
||||
$label->setTextColor("F80");
|
||||
$label->setText("Requested by " . $requester->nickname);
|
||||
}
|
||||
|
||||
// Send manialink
|
||||
$this->maniaControl->manialinkManager->sendManialink($maniaLink, $login);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle PlayerConnect callback
|
||||
*
|
||||
* @param Player $player
|
||||
*/
|
||||
public function handlePlayerConnect(Player $player) {
|
||||
// Display Map Widget
|
||||
if ($this->maniaControl->settingManager->getSetting($this, self::SETTING_MAP_WIDGET_ACTIVATED)) {
|
||||
$this->displayMapWidget($player->login);
|
||||
}
|
||||
if ($this->maniaControl->settingManager->getSetting($this, self::SETTING_CLOCK_WIDGET_ACTIVATED)) {
|
||||
$this->displayClockWidget($player->login);
|
||||
}
|
||||
if ($this->maniaControl->settingManager->getSetting($this, self::SETTING_SERVERINFO_WIDGET_ACTIVATED)) {
|
||||
$this->displayServerInfoWidget();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle PlayerConnect callback
|
||||
*
|
||||
* @param Player $player
|
||||
*/
|
||||
public function handlePlayerDisconnect(Player $player) {
|
||||
if ($this->maniaControl->settingManager->getSetting($this, self::SETTING_SERVERINFO_WIDGET_ACTIVATED)) {
|
||||
$this->displayServerInfoWidget();
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user