improved PHPDoc & applied common style

This commit is contained in:
Steffen Schröder 2014-05-03 23:49:58 +02:00
parent 8296e8457c
commit 9aea33951a
14 changed files with 1787 additions and 1883 deletions

File diff suppressed because it is too large Load Diff

View File

@ -1,4 +1,5 @@
<?php
namespace Dedimania;
use ManiaControl\ManiaControl;
@ -7,11 +8,14 @@ use Maniaplanet\DedicatedServer\Structures\Version;
/**
* ManiaControl Dedimania Plugin DataStructure
*
* @author kremsy and steeffeen
* @copyright ManiaControl Copyright © 2014 ManiaControl Team
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
* @author ManiaControl Team <mail@maniacontrol.com>
* @copyright 2014 ManiaControl Team
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
*/
class DedimaniaData {
/*
* Constants
*/
public $game;
public $path;
public $packmask;
@ -27,6 +31,15 @@ class DedimaniaData {
public $directoryAccessChecked = false;
public $serverMaxRank = 30;
/**
* Construct a new Dedimania Data Model
*
* @param string $serverLogin
* @param string $dedimaniaCode
* @param string $path
* @param string $packmask
* @param Version $serverVersion
*/
public function __construct($serverLogin, $dedimaniaCode, $path, $packmask, Version $serverVersion) {
$this->game = "TM2";
$this->login = $serverLogin;
@ -41,7 +54,7 @@ class DedimaniaData {
public function toArray() {
$array = array();
foreach(get_object_vars($this) as $key => $value) {
foreach (get_object_vars($this) as $key => $value) {
if ($key == 'records' || $key == 'sessionId' || $key == 'directoryAccessChecked' || $key == 'serverMaxRank' || $key == 'players') {
continue;
}
@ -62,7 +75,7 @@ class DedimaniaData {
*/
public function getPlayerMaxRank($login) {
$maxRank = $this->serverMaxRank;
foreach($this->players as $player) {
foreach ($this->players as $player) {
/** @var DedimaniaPlayer $player */
if ($player->login === $login) {
if ($player->maxRank > $maxRank) {

View File

@ -1,22 +1,32 @@
<?php
namespace Dedimania;
/**
* ManiaControl Dedimania-Plugin Player DataStructure
*
* @author kremsy and steeffeen
* @copyright ManiaControl Copyright © 2014 ManiaControl Team
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
* @author ManiaControl Team <mail@maniacontrol.com>
* @copyright 2014 ManiaControl Team
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
*/
class DedimaniaPlayer {
/*
* Public Properties
*/
public $login = '';
public $maxRank = -1;
public $banned = false;
public $optionsEnabled = false;
public $options = '';
/**
* Construct a new Dedimania Player Model
* @param mixed$player
*/
public function __construct($player) {
if (!$player) return;
if (!$player) {
return;
}
$this->login = $player['Login'];
$this->maxRank = $player['MaxRank'];
@ -28,8 +38,8 @@ class DedimaniaPlayer {
/**
* Construct a new Player by its login and maxRank
*
* @param $login
* @param $maxRank
* @param string $login
* @param int $maxRank
*/
public function constructNewPlayer($login, $maxRank) {
$this->login = $login;

View File

@ -1,16 +1,20 @@
<?php
namespace Dedimania;
use ManiaControl\Formatter;
/**
* ManiaControl Dedimania-Plugin Record DataStructure
*
* @author kremsy and steeffeen
* @copyright ManiaControl Copyright © 2014 ManiaControl Team
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
* @author ManiaControl Team <mail@maniacontrol.com>
* @copyright 2014 ManiaControl Team
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
*/
use ManiaControl\Formatter;
class RecordData {
/*
* Public Properties
*/
public $nullRecord = false;
public $login = '';
public $nickName = '';
@ -25,7 +29,7 @@ class RecordData {
/**
* Construct a Record by a given Record Array
*
* @param $record
* @param array $record
*/
public function __construct($record) {
if (!$record) {
@ -42,13 +46,13 @@ class RecordData {
}
/**
* Constructs a new Record via it's properties
* Construct a new Record via its Properties
*
* @param $login
* @param $nickName
* @param $best
* @param $checkpoints
* @param bool $newRecord
* @param string $login
* @param string $nickName
* @param float $best
* @param int $checkpoints
* @param bool $newRecord
*/
public function constructNewRecord($login, $nickName, $best, $checkpoints, $newRecord = false) {
$this->nullRecord = false;

View File

@ -11,12 +11,12 @@ use Maniaplanet\DedicatedServer\Xmlrpc\Exception;
/**
* ManiaControl Chat-Message Plugin
*
* @author kremsy <kremsy@maniacontrol.com>
* @author ManiaControl Team <mail@maniacontrol.com>
* @copyright 2014 ManiaControl Team
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
*/
class ChatMessagePlugin implements CommandListener, Plugin {
/**
/*
* Constants
*/
const PLUGIN_ID = 4;
@ -25,72 +25,55 @@ class ChatMessagePlugin implements CommandListener, Plugin {
const PLUGIN_AUTHOR = 'kremsy';
const SETTING_AFK_FORCE_SPEC = 'AFK command forces spec';
/**
/*
* Private Properties
*/
/** @var maniaControl $maniaControl */
/** @var ManiaControl $maniaControl */
private $maniaControl = null;
/**
* Prepares the Plugin
*
* @param ManiaControl $maniaControl
* @return mixed
* @see \ManiaControl\Plugins\Plugin::prepare()
*/
public static function prepare(ManiaControl $maniaControl) {
//do nothing
}
/**
* Get plugin id
*
* @return int
* @see \ManiaControl\Plugins\Plugin::getId()
*/
public static function getId() {
return self::PLUGIN_ID;
}
/**
* Get Plugin Name
*
* @return string
* @see \ManiaControl\Plugins\Plugin::getName()
*/
public static function getName() {
return self::PLUGIN_NAME;
}
/**
* Get Plugin Version
*
* @return float,,
* @see \ManiaControl\Plugins\Plugin::getVersion()
*/
public static function getVersion() {
return self::PLUGIN_VERSION;
}
/**
* Get Plugin Author
*
* @return string
* @see \ManiaControl\Plugins\Plugin::getAuthor()
*/
public static function getAuthor() {
return self::PLUGIN_AUTHOR;
}
/**
* Get Plugin Description
*
* @return string
* @see \ManiaControl\Plugins\Plugin::getDescription()
*/
public static function getDescription() {
return "Plugin offers various Chat-Commands like /gg /hi /afk /rq...";
}
/**
* Load the plugin
*
* @param \ManiaControl\ManiaControl $maniaControl
* @return bool
* @see \ManiaControl\Plugins\Plugin::load()
*/
public function load(ManiaControl $maniaControl) {
$this->maniaControl = $maniaControl;
@ -119,7 +102,7 @@ class ChatMessagePlugin implements CommandListener, Plugin {
}
/**
* Unload the plugin and its resources
* @see \ManiaControl\Plugins\Plugin::unload()
*/
public function unload() {
}

View File

@ -17,7 +17,7 @@ use ManiaControl\Settings\SettingManager;
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
*/
class ChatlogPlugin implements CallbackListener, Plugin {
/**
/*
* Constants
*/
const ID = 26;
@ -31,7 +31,7 @@ class ChatlogPlugin implements CallbackListener, Plugin {
const SETTING_LOGSERVERMESSAGES = 'Log Server Messages';
/**
* Private properties
* Private Properties
*/
/** @var ManiaControl $maniaControl */
private $maniaControl = null;

View File

@ -14,6 +14,7 @@ use FML\Controls\Quads\Quad_Icons128x32_1;
use FML\Controls\Quads\Quad_Icons64x64_1;
use FML\Controls\Quads\Quad_UIConstruction_Buttons;
use FML\ManiaLink;
use FML\Script\Features\KeyAction;
use ManiaControl\Callbacks\CallbackListener;
use ManiaControl\Callbacks\CallbackManager;
use ManiaControl\Callbacks\TimerListener;
@ -28,15 +29,14 @@ 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
* @author ManiaControl Team <mail@maniacontrol.com>
* @copyright 2014 ManiaControl Team
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
*/
class CustomVotesPlugin implements CommandListener, CallbackListener, ManialinkPageAnswerListener, TimerListener, Plugin {
/*
@ -73,7 +73,7 @@ class CustomVotesPlugin implements CommandListener, CallbackListener, ManialinkP
const CB_CUSTOM_VOTE_FINISHED = 'CustomVotesPlugin.CustomVoteFinished';
/**
/*
* Private Properties
*/
/** @var maniaControl $maniaControl */
@ -84,20 +84,48 @@ class CustomVotesPlugin implements CommandListener, CallbackListener, ManialinkP
private $currentVote = null;
/**
* Prepares the Plugin
*
* @param ManiaControl $maniaControl
* @return mixed
* @see \ManiaControl\Plugins\Plugin::prepare()
*/
public static function prepare(ManiaControl $maniaControl) {
//do nothing
}
/**
* Load the plugin
*
* @param \ManiaControl\ManiaControl $maniaControl
* @return bool
* @see \ManiaControl\Plugins\Plugin::getId()
*/
public static function getId() {
return self::PLUGIN_ID;
}
/**
* @see \ManiaControl\Plugins\Plugin::getName()
*/
public static function getName() {
return self::PLUGIN_NAME;
}
/**
* @see \ManiaControl\Plugins\Plugin::getVersion()
*/
public static function getVersion() {
return self::PLUGIN_VERSION;
}
/**
* @see \ManiaControl\Plugins\Plugin::getAuthor()
*/
public static function getAuthor() {
return self::PLUGIN_AUTHOR;
}
/**
* @see \ManiaControl\Plugins\Plugin::getDescription()
*/
public static function getDescription() {
return 'Plugin offers your Custom Votes like Restart, Skip, Balance...';
}
/**
* @see \ManiaControl\Plugins\Plugin::load()
*/
public function load(ManiaControl $maniaControl) {
$this->maniaControl = $maniaControl;
@ -140,7 +168,7 @@ class CustomVotesPlugin implements CommandListener, CallbackListener, ManialinkP
$this->defineVote("pausegame", "Vote for Pause Game");
$this->defineVote("replay", "Vote to replay current map");
foreach($this->voteCommands as $name => $voteCommand) {
foreach ($this->voteCommands as $name => $voteCommand) {
$this->maniaControl->commandManager->registerCommandListener($name, $this, 'handleChatVote', false, $voteCommand->name);
}
@ -169,7 +197,190 @@ class CustomVotesPlugin implements CommandListener, CallbackListener, ManialinkP
}
/**
* Unload the plugin and its resources
* 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;
}
/**
* 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();
}
/**
* Add a new Vote Menu Item
*
* @param Control $control
* @param int $order
* @param string $description
*/
public function addVoteMenuItem(Control $control, $order = 0, $description = null) {
if (!isset($this->voteMenuItems[$order])) {
$this->voteMenuItems[$order] = array();
array_push($this->voteMenuItems[$order], array($control, $description));
krsort($this->voteMenuItems);
}
}
/**
* Shows the Icon Widget
*
* @param bool $login
*/
private function showIcon($login = false) {
$posX = $this->maniaControl->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);
}
/**
* @see \ManiaControl\Plugins\Plugin::unload()
*/
public function unload() {
//Enable Standard Votes
@ -194,6 +405,16 @@ class CustomVotesPlugin implements CommandListener, CallbackListener, ManialinkP
$this->maniaControl->manialinkManager->hideManialink(self::MLID_ICON);
}
/**
* Destroys the current Vote
*/
private function destroyVote() {
$emptyManialink = new ManiaLink(self::MLID_WIDGET);
$this->maniaControl->manialinkManager->sendManialink($emptyManialink);
unset($this->currentVote);
}
/**
* Handle PlayerConnect callback
*
@ -203,21 +424,6 @@ class CustomVotesPlugin implements CommandListener, CallbackListener, ManialinkP
$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
*
@ -233,167 +439,6 @@ class CustomVotesPlugin implements CommandListener, CallbackListener, ManialinkP
}
}
/**
* 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
*
@ -444,6 +489,98 @@ class CustomVotesPlugin implements CommandListener, CallbackListener, ManialinkP
$this->maniaControl->chat->sendSuccess($message);
}
/**
* 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);
}
}
/**
* Undefines a Vote
*
* @param $voteIndex
*/
public function undefineVote($voteIndex) {
unset($this->voteCommands[$voteIndex]);
}
/**
* Handles a Positive Vote
*
@ -500,16 +637,6 @@ class CustomVotesPlugin implements CommandListener, CallbackListener, ManialinkP
}
}
/**
* 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
*
@ -566,7 +693,9 @@ class CustomVotesPlugin implements CommandListener, CallbackListener, ManialinkP
$timeGauge->setY(1.5);
$timeGauge->setSize($width * 0.95, 6);
$timeGauge->setDrawBg(false);
if (!$timeUntilExpire) $timeUntilExpire = 1;
if (!$timeUntilExpire) {
$timeUntilExpire = 1;
}
$timeGaugeRatio = (100 / $maxTime * $timeUntilExpire) / 100;
$timeGauge->setRatio($timeGaugeRatio + 0.15 - $timeGaugeRatio * 0.15);
$gaugeColor = ColorUtil::floatToStatusColor($timeGaugeRatio);
@ -631,7 +760,7 @@ class CustomVotesPlugin implements CommandListener, CallbackListener, ManialinkP
$positiveQuad->addActionTriggerFeature(self::ACTION_POSITIVE_VOTE);
$negativeQuad->addActionTriggerFeature(self::ACTION_NEGATIVE_VOTE);
$script = $maniaLink->getScript();
$script = $maniaLink->getScript();
$keyActionPositive = new KeyAction(self::ACTION_POSITIVE_VOTE, 'F1');
$script->addFeature($keyActionPositive);
$keyActionNegative = new KeyAction(self::ACTION_NEGATIVE_VOTE, 'F2');
@ -640,152 +769,6 @@ class CustomVotesPlugin implements CommandListener, CallbackListener, ManialinkP
// 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...';
}
}
/**

View File

@ -12,7 +12,6 @@ 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;
@ -23,21 +22,22 @@ 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
* @author ManiaControl Team <mail@maniacontrol.com>
* @copyright 2014 ManiaControl Team
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
*/
class DonationPlugin implements CallbackListener, CommandListener, Plugin {
/**
/*
* Constants
*/
const ID = 3;
const VERSION = 0.1;
const AUTHOR = 'MCTeam';
const NAME = 'Donation Plugin';
const SETTING_ANNOUNCE_SERVERDONATION = 'Enable Server-Donation Announcements';
const STAT_PLAYER_DONATIONS = 'Donated Planets';
const ACTION_DONATE_VALUE = 'Donate.DonateValue';
@ -52,8 +52,8 @@ class DonationPlugin implements CallbackListener, CommandListener, Plugin {
const SETTING_DONATION_VALUES = 'Donation Values';
const SETTING_MIN_AMOUNT_SHOWN = 'Minimum Donation amount to get shown';
/**
* Private properties
/*
* Private Properties
*/
/**
* @var maniaControl $maniaControl
@ -61,15 +61,45 @@ class DonationPlugin implements CallbackListener, CommandListener, Plugin {
private $maniaControl = null;
/**
* Prepares the Plugin
*
* @param ManiaControl $maniaControl
* @return mixed
* @see \ManiaControl\Plugins\Plugin::prepare()
*/
public static function prepare(ManiaControl $maniaControl) {
//do nothing
}
/**
* @see \ManiaControl\Plugins\Plugin::getId()
*/
public static function getId() {
return self::ID;
}
/**
* @see \ManiaControl\Plugins\Plugin::getName()
*/
public static function getName() {
return self::NAME;
}
/**
* @see \ManiaControl\Plugins\Plugin::getVersion()
*/
public static function getVersion() {
return self::VERSION;
}
/**
* @see \ManiaControl\Plugins\Plugin::getAuthor()
*/
public static function getAuthor() {
return self::AUTHOR;
}
/**
* @see \ManiaControl\Plugins\Plugin::getDescription()
*/
public static function getDescription() {
return 'Plugin offering commands like /donate, /pay and /planets and a donation widget.';
}
/**
* @see \ManiaControl\Plugins\Plugin::load()
@ -105,48 +135,6 @@ class DonationPlugin implements CallbackListener, CommandListener, Plugin {
return true;
}
/**
* @see \ManiaControl\Plugins\Plugin::unload()
*/
public function unload() {
$this->maniaControl->manialinkManager->hideManialink(self::MLID_DONATE_WIDGET);
}
/**
* @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
*
@ -158,35 +146,6 @@ class DonationPlugin implements CallbackListener, CommandListener, Plugin {
}
}
/**
* 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
*
@ -205,7 +164,7 @@ class DonationPlugin implements CallbackListener, CommandListener, Plugin {
$itemMarginFactorY = 1.2;
//If game is shootmania lower the icons position by 20
if($this->maniaControl->mapManager->getCurrentMap()->getGame() == 'sm') {
if ($this->maniaControl->mapManager->getCurrentMap()->getGame() == 'sm') {
$posY -= $shootManiaOffset;
}
@ -249,7 +208,7 @@ class DonationPlugin implements CallbackListener, CommandListener, Plugin {
$quad->setSize(strlen($values) * 2 + count($valueArray) * 1, $itemSize * $itemMarginFactorY);
$popoutFrame->add($quad);
$itemQuad->addToggleFeature($popoutFrame);
$itemQuad->addToggleFeature($popoutFrame);
// Description Label
$descriptionFrame = new Frame();
@ -267,7 +226,7 @@ class DonationPlugin implements CallbackListener, CommandListener, Plugin {
// Add items
$x = -2;
foreach(array_reverse($valueArray) as $value) {
foreach (array_reverse($valueArray) as $value) {
$label = new Label_Button();
$popoutFrame->add($label);
$label->setX($x);
@ -276,8 +235,8 @@ class DonationPlugin implements CallbackListener, CommandListener, Plugin {
$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);
$description = "Donate {$value} Planets";
$label->addTooltipLabelFeature($descriptionLabel, $description);
$x -= strlen($value) * 2 + 1.7;
}
@ -286,6 +245,90 @@ class DonationPlugin implements CallbackListener, CommandListener, Plugin {
$this->maniaControl->manialinkManager->sendManialink($maniaLink, $login);
}
/**
* @see \ManiaControl\Plugins\Plugin::unload()
*/
public function unload() {
$this->maniaControl->manialinkManager->hideManialink(self::MLID_DONATE_WIDGET);
}
/**
* Handle ManialinkPageAnswer Callback
*
* @param array $callback
*/
public function handleManialinkPageAnswer(array $callback) {
$actionId = $callback[1][2];
$boolSetting = (strpos($actionId, self::ACTION_DONATE_VALUE) === 0);
if (!$boolSetting) {
return;
}
$login = $callback[1][1];
$player = $this->maniaControl->playerManager->getPlayer($login);
$actionArray = explode(".", $callback[1][2]);
$this->handleDonation($player, intval($actionArray[2]));
}
/**
* 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 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);
}
}
/**
* Handle /donate command
*
@ -318,51 +361,14 @@ class DonationPlugin implements CallbackListener, CommandListener, Plugin {
}
/**
* Handles a Player Donate
* Send an usage example for /donate to the player
*
* @param Player $player
* @param $value
* @return boolean
*/
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;
private function sendDonateUsageExample(Player $player) {
$message = "Usage Example: '/donate 100'";
return $this->maniaControl->chat->sendChat($message, $player->login);
}
/**
@ -397,7 +403,7 @@ class DonationPlugin implements CallbackListener, CommandListener, Plugin {
$self = $this;
$this->maniaControl->billManager->sendPlanets(function ($data, $status) use (&$self, &$player, $amount, $receiver) {
switch($status) {
switch ($status) {
case BillManager::PAYED_FROM_SERVER:
$message = "Successfully payed out {$amount} to '{$receiver}'!";
$self->maniaControl->chat->sendSuccess($message, $player->login);
@ -416,6 +422,17 @@ class DonationPlugin implements CallbackListener, CommandListener, Plugin {
return true;
}
/**
* 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);
}
/**
* Handle //getplanets command
*
@ -433,28 +450,6 @@ class DonationPlugin implements CallbackListener, CommandListener, Plugin {
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
*
@ -479,8 +474,8 @@ class DonationPlugin implements CallbackListener, CommandListener, Plugin {
// create manialink
$maniaLink = new ManiaLink(ManialinkManager::MAIN_MLID);
$script = $maniaLink->getScript();
$paging = new Paging();
$script = $maniaLink->getScript();
$paging = new Paging();
$script->addFeature($paging);
// Main frame
@ -505,7 +500,7 @@ class DonationPlugin implements CallbackListener, CommandListener, Plugin {
$i = 1;
$y = $y - 10;
$pageFrames = array();
foreach($stats as $playerIndex => $donations) {
foreach ($stats as $playerIndex => $donations) {
if (!isset($pageFrame)) {
$pageFrame = new Frame();
$frame->add($pageFrame);
@ -531,7 +526,7 @@ class DonationPlugin implements CallbackListener, CommandListener, Plugin {
}
$donatingPlayer = $this->maniaControl->playerManager->getPlayerByIndex($playerIndex);
$array = array($i => $x + 5, $donatingPlayer->nickname => $x + 18, $donations => $x + 70);
$array = array($i => $x + 5, $donatingPlayer->nickname => $x + 18, $donations => $x + 70);
$this->maniaControl->manialinkManager->labelLine($playerFrame, $array);
$y -= 4;
@ -540,7 +535,7 @@ class DonationPlugin implements CallbackListener, CommandListener, Plugin {
unset($pageFrame);
}
if($i > 100) {
if ($i > 100) {
break;
}
}

View File

@ -32,6 +32,8 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
*/
const ID = 2;
const VERSION = 0.1;
const NAME = 'Karma Plugin';
const AUTHOR = 'MCTeam';
const MLID_KARMA = 'KarmaPlugin.MLID';
const TABLE_KARMA = 'mc_karma';
const CB_KARMA_CHANGED = 'KarmaPlugin.Changed';
@ -62,19 +64,15 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
/*
* Private Properties
*/
/**
* @var ManiaControl $maniaControl
*/
/** @var ManiaControl $maniaControl */
private $maniaControl = null;
private $updateManialink = false;
/**
* @var ManiaLink $manialink
*/
/** @var ManiaLink $manialink */
private $manialink = null;
private $mxKarma = array();
/**
* @see \ManiaControl\Plugins\Plugin
* @see \ManiaControl\Plugins\Plugin::prepare()
*/
public static function prepare(ManiaControl $maniaControl) {
$maniaControl->settingManager->initSetting(get_class(), self::SETTING_MX_KARMA_ACTIVATED, true);
@ -97,7 +95,7 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
* @see \ManiaControl\Plugins\Plugin::getName()
*/
public static function getName() {
return 'Karma Plugin';
return self::NAME;
}
/**
@ -111,7 +109,7 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
* @see \ManiaControl\Plugins\Plugin::getAuthor()
*/
public static function getAuthor() {
return 'steeffeen and kremsy';
return self::AUTHOR;
}
/**

View File

@ -15,67 +15,95 @@ 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\Maps\Map;
use ManiaControl\Players\Player;
use ManiaControl\Players\PlayerManager;
use ManiaControl\Plugins\Plugin;
use ManiaControl\Settings\SettingManager;
/**
* ManiaControl Local Records Plugin
*
* @author steeffeen
* @copyright ManiaControl Copyright © 2014 ManiaControl Team
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
* @author ManiaControl Team <mail@maniacontrol.com>
* @copyright 2014 ManiaControl Team
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
*/
class LocalRecordsPlugin implements CallbackListener, CommandListener, TimerListener, Plugin {
/*
* Constants
*/
const ID = 7;
const VERSION = 0.2;
const 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 ID = 7;
const VERSION = 0.2;
const NAME = 'Local Records Plugin';
const AUTHOR = 'MCTeam';
const MLID_RECORDS = 'ml_local_records';
const TABLE_RECORDS = 'mc_localrecords';
const SETTING_WIDGET_TITLE = 'Widget Title';
const SETTING_WIDGET_POSX = 'Widget Position: X';
const SETTING_WIDGET_POSY = 'Widget Position: Y';
const SETTING_WIDGET_WIDTH = 'Widget Width';
const SETTING_WIDGET_LINESCOUNT = 'Widget Displayed Lines Count';
const SETTING_WIDGET_LINEHEIGHT = 'Widget Line Height';
const SETTING_WIDGET_ENABLE = 'Enable Local Records Widget';
const SETTING_NOTIFY_ONLY_DRIVER = 'Notify only the Driver on New Records';
const SETTING_NOTIFY_BEST_RECORDS = 'Notify Publicly only for the X Best Records';
const SETTING_ADJUST_OUTER_BORDER = 'Adjust outer Border to Number of actual Records';
const CB_LOCALRECORDS_CHANGED = 'LocalRecords.Changed';
const ACTION_SHOW_RECORDSLIST = 'LocalRecords.ShowRecordsList';
const CB_LOCALRECORDS_CHANGED = 'LocalRecords.Changed';
const ACTION_SHOW_RECORDSLIST = 'LocalRecords.ShowRecordsList';
/*
* Private Properties
*/
/**
*
* @var maniaControl $maniaControl
*/
/** @var ManiaControl $maniaControl */
private $maniaControl = null;
private $updateManialink = false;
private $checkpoints = array();
/**
* Prepares the Plugin
*
* @param ManiaControl $maniaControl
* @return mixed
* @see \ManiaControl\Plugins\Plugin::prepare()
*/
public static function prepare(ManiaControl $maniaControl) {
// do nothing
}
/**
*
* @see \ManiaControl\Plugins\Plugin::getId()
*/
public static function getId() {
return self::ID;
}
/**
* @see \ManiaControl\Plugins\Plugin::getName()
*/
public static function getName() {
return self::NAME;
}
/**
* @see \ManiaControl\Plugins\Plugin::getVersion()
*/
public static function getVersion() {
return self::VERSION;
}
/**
* @see \ManiaControl\Plugins\Plugin::getAuthor()
*/
public static function getAuthor() {
return self::AUTHOR;
}
/**
* @see \ManiaControl\Plugins\Plugin::getDescription()
*/
public static function getDescription() {
return 'Plugin offering tracking of local records and manialinks to display them.';
}
/**
* @see \ManiaControl\Plugins\Plugin::load()
*/
public function load(ManiaControl $maniaControl) {
@ -111,19 +139,12 @@ class LocalRecordsPlugin implements CallbackListener, CommandListener, TimerList
return true;
}
/**
*
* @see \ManiaControl\Plugins\Plugin::unload()
*/
public function unload() {
}
/**
* Initialize needed database tables
*/
private function initTables() {
$mysqli = $this->maniaControl->database->mysqli;
$query = "CREATE TABLE IF NOT EXISTS `" . self::TABLE_RECORDS . "` (
$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,
@ -146,43 +167,9 @@ class LocalRecordsPlugin implements CallbackListener, CommandListener, TimerList
}
/**
*
* @see \ManiaControl\Plugins\Plugin::getId()
* @see \ManiaControl\Plugins\Plugin::unload()
*/
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.';
public function unload() {
}
/**
@ -209,301 +196,6 @@ class LocalRecordsPlugin implements CallbackListener, CommandListener, TimerList
}
}
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
*
@ -515,14 +207,14 @@ class LocalRecordsPlugin implements CallbackListener, CommandListener, TimerList
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();
$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);
@ -532,7 +224,7 @@ class LocalRecordsPlugin implements CallbackListener, CommandListener, TimerList
}
$manialink = new ManiaLink(self::MLID_RECORDS);
$frame = new Frame();
$frame = new Frame();
$manialink->add($frame);
$frame->setPosition($pos_x, $pos_y);
@ -540,7 +232,7 @@ class LocalRecordsPlugin implements CallbackListener, CommandListener, TimerList
$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;
$height = 7. + ($adjustOuterBorder ? count($records) : $lines) * $lineHeight;
$backgroundQuad->setSize($width * 1.05, $height);
$backgroundQuad->setStyles($quadStyle, $quadSubstyle);
$backgroundQuad->setAction(self::ACTION_SHOW_RECORDSLIST);
@ -611,8 +303,8 @@ class LocalRecordsPlugin implements CallbackListener, CommandListener, TimerList
*/
public function getLocalRecords(Map $map, $limit = -1) {
$mysqli = $this->maniaControl->database->mysqli;
$limit = ($limit > 0 ? "LIMIT " . $limit : "");
$query = "SELECT * FROM (
$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
@ -632,16 +324,155 @@ class LocalRecordsPlugin implements CallbackListener, CommandListener, TimerList
return $records;
}
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);
}
/**
* Retrieve the local record for the given map and login
*
* @param Map $map
* @param Map $map
* @param Player $player
* @return mixed
*/
private function getLocalRecord(Map $map, Player $player) {
$mysqli = $this->maniaControl->database->mysqli;
$query = "SELECT records.* FROM (
$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
@ -655,4 +486,167 @@ class LocalRecordsPlugin implements CallbackListener, CommandListener, TimerList
$result->free();
return $record;
}
/**
* 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;
}
/**
* 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);
}
}
/**
* 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');
}
/**
* 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);
}
}
}

View File

@ -6,13 +6,12 @@ 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\Maps\Map;
use ManiaControl\Players\Player;
use ManiaControl\Players\PlayerManager;
use ManiaControl\Plugins\Plugin;
@ -23,9 +22,9 @@ 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
* @author ManiaControl Team <mail@maniacontrol.com>
* @copyright 2014 ManiaControl Team
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
*/
class ServerRankingPlugin implements Plugin, CallbackListener, CommandListener {
/**
@ -33,8 +32,8 @@ class ServerRankingPlugin implements Plugin, CallbackListener, CommandListener {
*/
const PLUGIN_ID = 6;
const PLUGIN_VERSION = 0.1;
const PLUGIN_NAME = 'ServerRankingPlugin';
const PLUGIN_AUTHOR = 'kremsy';
const PLUGIN_NAME = 'Server Ranking Plugin';
const PLUGIN_AUTHOR = 'MCTeam';
const TABLE_RANK = 'mc_rank';
const RANKING_TYPE_RECORDS = 'Records';
const RANKING_TYPE_RATIOS = 'Ratios';
@ -49,26 +48,53 @@ class ServerRankingPlugin implements Plugin, CallbackListener, CommandListener {
/**
* Private Properties
*/
/** @var maniaControl $maniaControl * */
/** @var ManiaControl $maniaControl * */
private $maniaControl = null;
private $recordCount = 0;
/**
* Prepares the Plugin
*
* @param ManiaControl $maniaControl
* @return mixed
* @see \ManiaControl\Plugins\Plugin::prepare()
*/
public static function prepare(ManiaControl $maniaControl) {
//Todo
}
/**
* Load the plugin
*
* @param \ManiaControl\ManiaControl $maniaControl
* @throws Exception
* @return bool
* @see \ManiaControl\Plugins\Plugin::getId()
*/
public static function getId() {
return self::PLUGIN_ID;
}
/**
* @see \ManiaControl\Plugins\Plugin::getName()
*/
public static function getName() {
return self::PLUGIN_NAME;
}
/**
* @see \ManiaControl\Plugins\Plugin::getVersion()
*/
public static function getVersion() {
return self::PLUGIN_VERSION;
}
/**
* @see \ManiaControl\Plugins\Plugin::getAuthor()
*/
public static function getAuthor() {
return self::PLUGIN_AUTHOR;
}
/**
* @see \ManiaControl\Plugins\Plugin::getDescription()
*/
public static function getDescription() {
return "ServerRanking Plugin, ServerRanking by an avg build from the records, per count of points, or by a multiplication from Kill/Death Ratio and Laser accuracy";
}
/**
* @see \ManiaControl\Plugins\Plugin::load()
*/
public function load(ManiaControl $maniaControl) {
$this->maniaControl = $maniaControl;
@ -111,57 +137,6 @@ class ServerRankingPlugin implements Plugin, CallbackListener, CommandListener {
$this->resetRanks(); //TODO only update records count
}
/**
* @see \ManiaControl\Plugins\Plugin::unload()
*/
public function unload() {
}
/**
* 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
*/
@ -190,7 +165,7 @@ class ServerRankingPlugin implements Plugin, CallbackListener, CommandListener {
$mysqli->query('TRUNCATE TABLE ' . self::TABLE_RANK);
$type = $this->maniaControl->settingManager->getSetting($this, self::SETTING_MIN_RANKING_TYPE);
switch($type) {
switch ($type) {
case self::RANKING_TYPE_RATIOS:
$minHits = $this->maniaControl->settingManager->getSetting($this, self::SETTING_MIN_HITS_RATIO_RANKING);
@ -199,7 +174,7 @@ class ServerRankingPlugin implements Plugin, CallbackListener, CommandListener {
$accuracies = $this->maniaControl->statisticManager->getStatsRanking(StatisticManager::SPECIAL_STAT_LASER_ACC);
$ranks = array();
foreach($hits as $player => $hitCount) {
foreach ($hits as $player => $hitCount) {
if (!isset($killDeathRatios[$player]) || !isset($accuracies[$player])) {
continue;
}
@ -232,7 +207,7 @@ class ServerRankingPlugin implements Plugin, CallbackListener, CommandListener {
$result = $mysqli->query($query);
$players = array();
while($row = $result->fetch_object()) {
while ($row = $result->fetch_object()) {
$players[$row->playerIndex] = array(0, 0); //sum, count
}
$result->free_result();
@ -240,11 +215,11 @@ class ServerRankingPlugin implements Plugin, CallbackListener, CommandListener {
/** @var \MCTeam\LocalRecordsPlugin $localRecordsPlugin */
$localRecordsPlugin = $this->maniaControl->pluginManager->getPlugin('MCTeam\LocalRecordsPlugin');
$maps = $this->maniaControl->mapManager->getMaps();
foreach($maps as $map) {
foreach ($maps as $map) {
$records = $localRecordsPlugin->getLocalRecords($map, $maxRecords);
$i = 1;
foreach($records as $record) {
foreach ($records as $record) {
if (isset($players[$record->playerIndex])) {
$players[$record->playerIndex][0] += $i;
$players[$record->playerIndex][1]++;
@ -257,7 +232,7 @@ class ServerRankingPlugin implements Plugin, CallbackListener, CommandListener {
//compute each players new average score
$ranks = array();
foreach($players as $player => $val) {
foreach ($players as $player => $val) {
$sum = $val[0];
$cnt = $val[1];
// ranked maps sum + $maxRecs rank for all remaining maps
@ -278,7 +253,7 @@ class ServerRankingPlugin implements Plugin, CallbackListener, CommandListener {
$query = "INSERT INTO " . self::TABLE_RANK . " VALUES ";
$i = 1;
foreach($ranks as $player => $rankValue) {
foreach ($ranks as $player => $rankValue) {
$query .= '(' . $player . ',' . $i . ',' . $rankValue . '),';
$i++;
}
@ -287,6 +262,12 @@ class ServerRankingPlugin implements Plugin, CallbackListener, CommandListener {
$mysqli->query($query);
}
/**
* @see \ManiaControl\Plugins\Plugin::unload()
*/
public function unload() {
}
/**
* Handle PlayerConnect callback
*
@ -297,27 +278,6 @@ class ServerRankingPlugin implements Plugin, CallbackListener, CommandListener {
$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
*
@ -330,7 +290,7 @@ class ServerRankingPlugin implements Plugin, CallbackListener, CommandListener {
$message = '';
if ($rankObj) {
switch($type) {
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);
@ -343,7 +303,7 @@ class ServerRankingPlugin implements Plugin, CallbackListener, CommandListener {
$message = '$0f3Your Server rank is $<$ff3' . $rankObj->rank . '$> / $<$fff' . $this->recordCount . '$> Avg: $fff' . round($rankObj->avg, 2);
}
} else {
switch($type) {
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...';
@ -385,6 +345,29 @@ class ServerRankingPlugin implements Plugin, CallbackListener, CommandListener {
return Rank::fromArray($row);
}
/**
* 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;
}
/**
* Get the Next Ranked Player
*
@ -407,6 +390,26 @@ class ServerRankingPlugin implements Plugin, CallbackListener, CommandListener {
}
}
/**
* 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 current Server-Rank
@ -431,30 +434,6 @@ class ServerRankingPlugin implements Plugin, CallbackListener, CommandListener {
}
}
/**
* 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
*
@ -471,7 +450,7 @@ class ServerRankingPlugin implements Plugin, CallbackListener, CommandListener {
* @param Player $player
*/
private function showTopRanksList(Player $player) {
$query = "SELECT * FROM `".self::TABLE_RANK."` ORDER BY `Rank` ASC LIMIT 0, 100";
$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) {
@ -484,8 +463,8 @@ class ServerRankingPlugin implements Plugin, CallbackListener, CommandListener {
// create manialink
$maniaLink = new ManiaLink(ManialinkManager::MAIN_MLID);
$script = $maniaLink->getScript();
$paging = new Paging();
$script = $maniaLink->getScript();
$paging = new Paging();
$script->addFeature($paging);
// Main frame
@ -510,7 +489,7 @@ class ServerRankingPlugin implements Plugin, CallbackListener, CommandListener {
$i = 1;
$y = $y - 10;
$pageFrames = array();
while($rankedPlayer = $result->fetch_object()) {
while ($rankedPlayer = $result->fetch_object()) {
if (!isset($pageFrame)) {
$pageFrame = new Frame();
$frame->add($pageFrame);
@ -536,7 +515,7 @@ class ServerRankingPlugin implements Plugin, CallbackListener, CommandListener {
}
$playerObject = $this->maniaControl->playerManager->getPlayerByIndex($rankedPlayer->PlayerIndex);
$array = array($rankedPlayer->Rank => $x + 5, $playerObject->nickname => $x + 18, (string)round($rankedPlayer->Avg, 2) => $x + 70);
$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;

View File

@ -29,8 +29,7 @@ use ManiaControl\Plugins\Plugin;
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
*/
class WidgetPlugin implements CallbackListener, TimerListener, Plugin {
/**
/*
* Constants
*/
const PLUGIN_ID = 1;
@ -70,74 +69,55 @@ class WidgetPlugin implements CallbackListener, TimerListener, Plugin {
const SETTING_SERVERINFO_WIDGET_WIDTH = 'ServerInfo-Widget-Size: Width';
const SETTING_SERVERINFO_WIDGET_HEIGHT = 'ServerInfo-Widget-Size: Height';
/**
/*
* Private Properties
*/
/**
* @var maniaControl $maniaControl
*/
/** @var ManiaControl $maniaControl */
private $maniaControl = null;
/**
* Prepares the Plugin
*
* @param ManiaControl $maniaControl
* @return mixed
* @see \ManiaControl\Plugins\Plugin::prepare()
*/
public static function prepare(ManiaControl $maniaControl) {
//do nothing
}
/**
* Get plugin id
*
* @return int
* @see \ManiaControl\Plugins\Plugin::getId()
*/
public static function getId() {
return self::PLUGIN_ID;
}
/**
* Get Plugin Name
*
* @return string
* @see \ManiaControl\Plugins\Plugin::getName()
*/
public static function getName() {
return self::PLUGIN_NAME;
}
/**
* Get Plugin Version
*
* @return float,,
* @see \ManiaControl\Plugins\Plugin::getVersion()
*/
public static function getVersion() {
return self::PLUGIN_VERSION;
}
/**
* Get Plugin Author
*
* @return string
* @see \ManiaControl\Plugins\Plugin::getAuthor()
*/
public static function getAuthor() {
return self::PLUGIN_AUTHOR;
}
/**
* Get Plugin Description
*
* @return string
* @see \ManiaControl\Plugins\Plugin::getDescription()
*/
public static function getDescription() {
return 'Plugin offers some Widgets';
}
/**
* Load the plugin
*
* @param ManiaControl $maniaControl
* @return bool
* @see \ManiaControl\Plugins\Plugin::load()
*/
public function load(ManiaControl $maniaControl) {
$this->maniaControl = $maniaControl;
@ -413,7 +393,7 @@ class WidgetPlugin implements CallbackListener, TimerListener, Plugin {
}
/**
* Unload the plugin and its resources
* @see \ManiaControl\Plugins\Plugin::unload()
*/
public function unload() {
//Restore Siege Progression Layer
@ -426,9 +406,9 @@ class WidgetPlugin implements CallbackListener, TimerListener, Plugin {
}
/**
* Closes a Widget
* Close a Widget
*
* @param $widgetId
* @param string $widgetId
*/
public function closeWidget($widgetId) {
$emptyManialink = new ManiaLink($widgetId);

View File

@ -2,13 +2,12 @@
namespace steeffeen;
use ManiaControl\Callbacks\Callbacks;
use ManiaControl\ManiaControl;
use ManiaControl\Callbacks\CallbackListener;
use ManiaControl\Callbacks\CallbackManager;
use ManiaControl\Callbacks\Callbacks;
use ManiaControl\ManiaControl;
use ManiaControl\Maps\Map;
use ManiaControl\Plugins\Plugin;
use ManiaControl\Maps\MapManager;
/**
* Plugin for the TM Game Mode 'Endurance' by TGYoshi
@ -16,34 +15,67 @@ use ManiaControl\Maps\MapManager;
* @author steeffeen
*/
class EndurancePlugin implements CallbackListener, Plugin {
/**
/*
* Constants
*/
const ID = 25;
const VERSION = 0.2;
const ID = 25;
const VERSION = 0.2;
const NAME = 'Endurance Plugin';
const AUTHOR = 'steeffeen';
const CB_CHECKPOINT = 'Endurance.Checkpoint';
/**
* Private properties
* Private Properties
*/
/** @var maniaControl $maniaControl */
/** @var ManiaControl $maniaControl */
private $maniaControl = null;
/** @var Map $currentMap */
private $currentMap = null;
private $playerLapTimes = array();
/**
* Prepares the Plugin
*
* @param ManiaControl $maniaControl
* @return mixed
* @see \ManiaControl\Plugins\Plugin::prepare()
*/
public static function prepare(ManiaControl $maniaControl) {
//do nothing
}
/**
*
* @see \ManiaControl\Plugins\Plugin::getId()
*/
public static function getId() {
return self::ID;
}
/**
* @see \ManiaControl\Plugins\Plugin::getName()
*/
public static function getName() {
return self::NAME;
}
/**
* @see \ManiaControl\Plugins\Plugin::getVersion()
*/
public static function getVersion() {
return self::VERSION;
}
/**
* @see \ManiaControl\Plugins\Plugin::getAuthor()
*/
public static function getAuthor() {
return self::AUTHOR;
}
/**
* @see \ManiaControl\Plugins\Plugin::getDescription()
*/
public static function getDescription() {
return "Plugin enabling Support for the TM Game Mode 'Endurance' by TGYoshi.";
}
/**
* @see \ManiaControl\Plugins\Plugin::load()
*/
public function load(ManiaControl $maniaControl) {
@ -58,59 +90,18 @@ class EndurancePlugin implements CallbackListener, Plugin {
}
/**
*
* @see \ManiaControl\Plugins\Plugin::unload()
*/
public function unload() {
}
/**
*
* @see \ManiaControl\Plugins\Plugin::getId()
*/
public static function getId() {
return self::ID;
}
/**
*
* @see \ManiaControl\Plugins\Plugin::getName()
*/
public static function getName() {
return 'Endurance 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 enabling Support for the TM Game Mode 'Endurance' by TGYoshi.";
}
/**
* Handle ManiaControl OnInit callback
*
* @param array $callback
*/
public function callback_OnInit(array $callback) {
$this->currentMap = $this->maniaControl->mapManager->getCurrentMap();
$this->currentMap = $this->maniaControl->mapManager->getCurrentMap();
$this->playerLapTimes = array();
}
@ -120,7 +111,7 @@ class EndurancePlugin implements CallbackListener, Plugin {
* @param Map $map
*/
public function callback_BeginMap(Map $map) {
$this->currentMap = $map;
$this->currentMap = $map;
$this->playerLapTimes = array();
}

View File

@ -2,11 +2,11 @@
namespace steeffeen;
use ManiaControl\ManiaControl;
use ManiaControl\Admin\AuthenticationManager;
use ManiaControl\Callbacks\CallbackListener;
use ManiaControl\Callbacks\CallbackManager;
use ManiaControl\Commands\CommandListener;
use ManiaControl\ManiaControl;
use ManiaControl\Players\Player;
use ManiaControl\Plugins\Plugin;
use Maniaplanet\DedicatedServer\Xmlrpc\Exception;
@ -17,36 +17,67 @@ use Maniaplanet\DedicatedServer\Xmlrpc\Exception;
* @author steeffeen
*/
class ObstaclePlugin implements CallbackListener, CommandListener, Plugin {
/**
/*
* Constants
*/
const ID = 24;
const VERSION = 0.2;
const CB_JUMPTO = 'Obstacle.JumpTo';
const SCB_ONFINISH = 'OnFinish';
const SCB_ONCHECKPOINT = 'OnCheckpoint';
const ID = 24;
const VERSION = 0.2;
const NAME = 'Obstacle Plugin';
const AUTHOR = 'steeffeen';
const CB_JUMPTO = 'Obstacle.JumpTo';
const SCB_ONFINISH = 'OnFinish';
const SCB_ONCHECKPOINT = 'OnCheckpoint';
const SETTING_JUMPTOAUTHLEVEL = 'Authentication level for JumpTo commands';
/**
* Private Properties
*/
/**
* @var maniaControl $maniaControl
*/
/** @var ManiaControl $maniaControl */
private $maniaControl = null;
/**
* Prepares the Plugin
*
* @param ManiaControl $maniaControl
* @return mixed
* @see \ManiaControl\Plugins\Plugin::prepare()
*/
public static function prepare(ManiaControl $maniaControl) {
// do nothing
}
/**
*
* @see \ManiaControl\Plugins\Plugin::getId()
*/
public static function getId() {
return self::ID;
}
/**
* @see \ManiaControl\Plugins\Plugin::getName()
*/
public static function getName() {
return self::NAME;
}
/**
* @see \ManiaControl\Plugins\Plugin::getVersion()
*/
public static function getVersion() {
return self::VERSION;
}
/**
* @see \ManiaControl\Plugins\Plugin::getAuthor()
*/
public static function getAuthor() {
return self::AUTHOR;
}
/**
* @see \ManiaControl\Plugins\Plugin::getDescription()
*/
public static function getDescription() {
return "Plugin offering CP Jumping and Local Records Support for the ShootManie Gamemode 'Obstacle'.";
}
/**
* @see \ManiaControl\Plugins\Plugin::load()
*/
public function load(ManiaControl $maniaControl) {
@ -66,56 +97,15 @@ class ObstaclePlugin implements CallbackListener, CommandListener, Plugin {
}
/**
*
* @see \ManiaControl\Plugins\Plugin::unload()
*/
public function unload() {
}
/**
*
* @see \ManiaControl\Plugins\Plugin::getId()
*/
public static function getId() {
return self::ID;
}
/**
*
* @see \ManiaControl\Plugins\Plugin::getName()
*/
public static function getName() {
return 'Obstacle 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 CP Jumping and Local Records Support for the ShootManie Gamemode 'Obstacle'.";
}
/**
* Handle JumpTo command
*
* @param array $chatCallback
* @param array $chatCallback
* @param Player $player
* @return bool
*/
@ -127,11 +117,10 @@ class ObstaclePlugin implements CallbackListener, CommandListener, Plugin {
}
// Send jump callback
$params = explode(' ', $chatCallback[1][2], 2);
$param = $player->login . ";" . $params[1] . ";";
$param = $player->login . ";" . $params[1] . ";";
try {
$this->maniaControl->client->triggerModeScriptEvent(self::CB_JUMPTO, $param);
}
catch (Exception $e) {
} catch (Exception $e) {
if ($e->getMessage() == 'Not in script mode.') {
trigger_error("Couldn't send jump callback for '{$player->login}'. " . $e->getMessage());
return;
@ -146,7 +135,7 @@ class ObstaclePlugin implements CallbackListener, CommandListener, Plugin {
* @param array $callback
*/
public function callback_OnFinish(array $callback) {
$data = json_decode($callback[1]);
$data = json_decode($callback[1]);
$player = $this->maniaControl->playerManager->getPlayer($data->Player->Login);
if (!$player) {
return;
@ -154,8 +143,7 @@ class ObstaclePlugin implements CallbackListener, CommandListener, Plugin {
$time = $data->Run->Time;
// Trigger trackmania player finish callback
$finishCallback = array($player->pid, $player->login, $time);
$this->maniaControl->callbackManager->triggerCallback(CallbackManager::CB_TM_PLAYERFINISH,
array(CallbackManager::CB_TM_PLAYERFINISH, $finishCallback));
$this->maniaControl->callbackManager->triggerCallback(CallbackManager::CB_TM_PLAYERFINISH, array(CallbackManager::CB_TM_PLAYERFINISH, $finishCallback));
}
/**
@ -164,15 +152,14 @@ class ObstaclePlugin implements CallbackListener, CommandListener, Plugin {
* @param array $callback
*/
public function callback_OnCheckpoint(array $callback) {
$data = json_decode($callback[1]);
$data = json_decode($callback[1]);
$player = $this->maniaControl->playerManager->getPlayer($data->Player->Login);
$time = $data->Run->Time;
$time = $data->Run->Time;
if (!$player || $time <= 0) {
return;
}
// Trigger Trackmania player checkpoint callback
$checkpointCallback = array($player->pid, $player->login, $time, 0, 0);
$this->maniaControl->callbackManager->triggerCallback(CallbackManager::CB_TM_PLAYERCHECKPOINT,
array(CallbackManager::CB_TM_PLAYERCHECKPOINT, $checkpointCallback));
$this->maniaControl->callbackManager->triggerCallback(CallbackManager::CB_TM_PLAYERCHECKPOINT, array(CallbackManager::CB_TM_PLAYERCHECKPOINT, $checkpointCallback));
}
}