2013-11-12 19:33:25 +01:00
< ? php
2014-05-01 17:36:24 +02:00
2014-04-29 22:06:58 +02:00
namespace MCTeam ;
2014-01-04 20:20:55 +01:00
use FML\Controls\Control ;
2014-01-02 18:06:27 +01:00
use FML\Controls\Frame ;
2014-01-04 21:54:40 +01:00
use FML\Controls\Label ;
2014-01-04 20:20:55 +01:00
use FML\Controls\Labels\Label_Button ;
2014-01-04 22:58:57 +01:00
use FML\Controls\Labels\Label_Text ;
2014-01-02 18:06:27 +01:00
use FML\Controls\Quad ;
2014-05-02 16:02:09 +02:00
use FML\Controls\Quads\Quad_BgsPlayerCard ;
2014-01-02 18:06:27 +01:00
use FML\Controls\Quads\Quad_Icons128x128_1 ;
use FML\ManiaLink ;
2014-05-02 16:02:09 +02:00
use FML\Script\Features\Paging ;
2013-11-13 01:43:12 +01:00
use ManiaControl\Admin\AuthenticationManager ;
2014-02-25 18:34:35 +01:00
use ManiaControl\Bills\BillManager ;
2013-11-12 19:33:25 +01:00
use ManiaControl\Callbacks\CallbackListener ;
use ManiaControl\Callbacks\CallbackManager ;
use ManiaControl\Commands\CommandListener ;
2014-01-02 17:31:58 +01:00
use ManiaControl\ManiaControl ;
2014-05-02 16:02:09 +02:00
use ManiaControl\Manialinks\ManialinkManager ;
2013-11-12 19:33:25 +01:00
use ManiaControl\Players\Player ;
2014-01-02 18:06:54 +01:00
use ManiaControl\Players\PlayerManager ;
2013-12-03 22:21:17 +01:00
use ManiaControl\Plugins\Plugin ;
2014-05-02 16:02:09 +02:00
use ManiaControl\Statistics\StatisticManager ;
2013-11-12 19:33:25 +01:00
/**
2014-04-13 12:00:08 +02:00
* ManiaControl Donation Plugin
2013-11-12 19:33:25 +01:00
*
2014-04-13 12:00:08 +02:00
* @ author kremsy and steeffeen
* @ copyright ManiaControl Copyright © 2014 ManiaControl Team
* @ license http :// www . gnu . org / licenses / GNU General Public License , Version 3
2013-11-12 19:33:25 +01:00
*/
2013-12-03 22:21:17 +01:00
class DonationPlugin implements CallbackListener , CommandListener , Plugin {
2014-01-03 20:57:24 +01:00
/**
2013-11-12 19:33:25 +01:00
* Constants
*/
2014-01-08 20:20:18 +01:00
const ID = 3 ;
const VERSION = 0.1 ;
2013-11-12 19:33:25 +01:00
const SETTING_ANNOUNCE_SERVERDONATION = 'Enable Server-Donation Announcements' ;
2014-01-08 20:20:18 +01:00
const STAT_PLAYER_DONATIONS = 'Donated Planets' ;
const ACTION_DONATE_VALUE = 'Donate.DonateValue' ;
2014-01-02 18:06:27 +01:00
// DonateWidget Properties
2014-01-08 20:20:18 +01:00
const MLID_DONATE_WIDGET = 'DonationPlugin.DonateWidget' ;
2014-01-02 18:06:27 +01:00
const SETTING_DONATE_WIDGET_ACTIVATED = 'Donate-Widget Activated' ;
2014-01-08 20:20:18 +01:00
const SETTING_DONATE_WIDGET_POSX = 'Donate-Widget-Position: X' ;
const SETTING_DONATE_WIDGET_POSY = 'Donate-Widget-Position: Y' ;
const SETTING_DONATE_WIDGET_WIDTH = 'Donate-Widget-Size: Width' ;
const SETTING_DONATE_WIDGET_HEIGHT = 'Donate-Widget-Size: Height' ;
const SETTING_DONATION_VALUES = 'Donation Values' ;
const SETTING_MIN_AMOUNT_SHOWN = 'Minimum Donation amount to get shown' ;
2014-01-27 20:46:42 +01:00
/**
* Private properties
*/
/**
* @ var maniaControl $maniaControl
*/
private $maniaControl = null ;
2014-01-27 20:39:10 +01:00
/**
* Prepares the Plugin
*
* @ param ManiaControl $maniaControl
* @ return mixed
*/
public static function prepare ( ManiaControl $maniaControl ) {
2014-01-27 21:05:02 +01:00
//do nothing
2014-01-27 20:39:10 +01:00
}
2013-11-12 19:33:25 +01:00
/**
2013-12-14 23:29:17 +01:00
* @ see \ManiaControl\Plugins\Plugin :: load ()
2013-11-12 19:33:25 +01:00
*/
2013-12-14 23:29:17 +01:00
public function load ( ManiaControl $maniaControl ) {
2013-11-12 19:33:25 +01:00
$this -> maniaControl = $maniaControl ;
2014-01-08 20:20:18 +01:00
2013-12-03 18:50:30 +01:00
// Register for commands
2014-05-01 01:50:52 +02:00
$this -> maniaControl -> commandManager -> registerCommandListener ( 'donate' , $this , 'command_Donate' , false , 'Donate some planets to the server.' );
$this -> maniaControl -> commandManager -> registerCommandListener ( 'pay' , $this , 'command_Pay' , true , 'Pays planets from the server to a player.' );
$this -> maniaControl -> commandManager -> registerCommandListener ( 'planets' , $this , 'command_GetPlanets' , true , 'Checks the planets-balance of the server.' );
2014-05-02 16:02:09 +02:00
$this -> maniaControl -> commandManager -> registerCommandListener ( 'topdons' , $this , 'command_TopDons' , false , 'Provides an overview of who dontated the most planets.' );
2014-01-08 20:20:18 +01:00
2013-12-03 18:50:30 +01:00
// Register for callbacks
2014-02-19 10:43:37 +01:00
$this -> maniaControl -> callbackManager -> registerCallbackListener ( PlayerManager :: CB_PLAYERCONNECT , $this , 'handlePlayerConnect' );
2014-01-08 20:20:18 +01:00
$this -> maniaControl -> callbackManager -> registerCallbackListener ( CallbackManager :: CB_MP_PLAYERMANIALINKPAGEANSWER , $this , 'handleManialinkPageAnswer' );
2014-01-02 17:31:58 +01:00
// Define player stats
$this -> maniaControl -> statisticManager -> defineStatMetaData ( self :: STAT_PLAYER_DONATIONS );
2014-01-08 20:20:18 +01:00
2014-01-02 18:06:27 +01:00
$this -> maniaControl -> settingManager -> initSetting ( $this , self :: SETTING_DONATE_WIDGET_ACTIVATED , true );
$this -> maniaControl -> settingManager -> initSetting ( $this , self :: SETTING_DONATE_WIDGET_POSX , 156. );
2014-01-14 19:11:57 +01:00
$this -> maniaControl -> settingManager -> initSetting ( $this , self :: SETTING_DONATE_WIDGET_POSY , - 31.4 );
2014-01-02 18:06:27 +01:00
$this -> maniaControl -> settingManager -> initSetting ( $this , self :: SETTING_DONATE_WIDGET_WIDTH , 6 );
$this -> maniaControl -> settingManager -> initSetting ( $this , self :: SETTING_DONATE_WIDGET_HEIGHT , 6 );
2014-01-04 20:20:55 +01:00
$this -> maniaControl -> settingManager -> initSetting ( $this , self :: SETTING_DONATION_VALUES , " 20,50,100,500,1000,2000 " );
2014-01-08 20:20:18 +01:00
$this -> maniaControl -> settingManager -> initSetting ( $this , self :: SETTING_MIN_AMOUNT_SHOWN , 100 );
2014-01-29 20:51:53 +01:00
// Register Stat in Simple StatsList
$this -> maniaControl -> statisticManager -> simpleStatsList -> registerStat ( self :: STAT_PLAYER_DONATIONS , 90 , " DP " , 15 );
2014-01-18 10:26:32 +01:00
$this -> displayWidget ();
2013-12-14 23:29:17 +01:00
return true ;
}
/**
* @ see \ManiaControl\Plugins\Plugin :: unload ()
*/
public function unload () {
2014-01-17 16:16:12 +01:00
$emptyManialink = new ManiaLink ( self :: MLID_DONATE_WIDGET );
2014-03-02 13:00:23 +01:00
$this -> maniaControl -> manialinkManager -> sendManialink ( $emptyManialink );
2014-01-17 16:16:12 +01:00
2013-12-14 23:29:17 +01:00
$this -> maniaControl -> callbackManager -> unregisterCallbackListener ( $this );
$this -> maniaControl -> commandManager -> unregisterCommandListener ( $this );
unset ( $this -> maniaControl );
2013-11-12 19:33:25 +01:00
}
2013-12-09 10:04:22 +01:00
/**
* @ see \ManiaControl\Plugins\Plugin :: getId ()
*/
public static function getId () {
return self :: ID ;
}
2013-12-03 22:21:17 +01:00
/**
* @ see \ManiaControl\Plugins\Plugin :: getName ()
*/
public static function getName () {
2013-12-09 10:04:22 +01:00
return 'Donations Plugin' ;
2013-12-03 22:21:17 +01:00
}
/**
* @ see \ManiaControl\Plugins\Plugin :: getVersion ()
*/
public static function getVersion () {
return self :: VERSION ;
}
/**
* @ see \ManiaControl\Plugins\Plugin :: getAuthor ()
*/
public static function getAuthor () {
2014-01-04 20:20:55 +01:00
return 'steeffeen and kremsy' ;
2013-12-03 22:21:17 +01:00
}
/**
* @ see \ManiaControl\Plugins\Plugin :: getDescription ()
*/
public static function getDescription () {
2014-02-19 10:57:56 +01:00
return 'Plugin offering commands like /donate, /pay and /planets and a donation widget.' ;
2013-12-03 22:21:17 +01:00
}
2014-01-02 18:06:27 +01:00
/**
2014-05-02 16:13:45 +02:00
* Display the Widget
2014-01-02 18:06:27 +01:00
*/
2014-01-18 10:26:32 +01:00
public function displayWidget () {
2014-01-27 20:46:42 +01:00
if ( $this -> maniaControl -> settingManager -> getSetting ( $this , self :: SETTING_DONATE_WIDGET_ACTIVATED )) {
2014-01-02 18:06:27 +01:00
$this -> displayDonateWidget ();
}
}
2014-01-04 20:20:55 +01:00
/**
* Handle ManialinkPageAnswer Callback
*
* @ param array $callback
*/
public function handleManialinkPageAnswer ( array $callback ) {
2014-01-08 20:20:18 +01:00
$actionId = $callback [ 1 ][ 2 ];
2014-01-04 20:20:55 +01:00
$boolSetting = ( strpos ( $actionId , self :: ACTION_DONATE_VALUE ) === 0 );
2014-01-27 20:46:42 +01:00
if ( ! $boolSetting ) {
2014-01-08 20:20:18 +01:00
return ;
}
$login = $callback [ 1 ][ 1 ];
$player = $this -> maniaControl -> playerManager -> getPlayer ( $login );
2014-01-04 20:20:55 +01:00
$actionArray = explode ( " . " , $callback [ 1 ][ 2 ]);
$this -> handleDonation ( $player , intval ( $actionArray [ 2 ]));
}
2014-01-02 18:06:27 +01:00
/**
* Handle PlayerConnect callback
*
2014-02-19 15:44:00 +01:00
* @ param Player $player
2014-01-02 18:06:27 +01:00
*/
2014-02-19 15:44:00 +01:00
public function handlePlayerConnect ( Player $player ) {
2014-01-02 18:06:27 +01:00
// Display Map Widget
2014-01-27 20:46:42 +01:00
if ( $this -> maniaControl -> settingManager -> getSetting ( $this , self :: SETTING_DONATE_WIDGET_ACTIVATED )) {
2014-01-02 18:06:27 +01:00
$this -> displayDonateWidget ( $player -> login );
}
}
/**
* Displays the Donate Widget
*
* @ param bool $login
*/
public function displayDonateWidget ( $login = false ) {
2014-01-08 20:20:18 +01:00
$posX = $this -> maniaControl -> settingManager -> getSetting ( $this , self :: SETTING_DONATE_WIDGET_POSX );
$posY = $this -> maniaControl -> settingManager -> getSetting ( $this , self :: SETTING_DONATE_WIDGET_POSY );
$width = $this -> maniaControl -> settingManager -> getSetting ( $this , self :: SETTING_DONATE_WIDGET_WIDTH );
$height = $this -> maniaControl -> settingManager -> getSetting ( $this , self :: SETTING_DONATE_WIDGET_HEIGHT );
$values = $this -> maniaControl -> settingManager -> getSetting ( $this , self :: SETTING_DONATION_VALUES );
2014-01-15 22:07:09 +01:00
$shootManiaOffset = $this -> maniaControl -> manialinkManager -> styleManager -> getDefaultIconOffsetSM ();
2014-01-08 20:20:18 +01:00
$quadStyle = $this -> maniaControl -> manialinkManager -> styleManager -> getDefaultQuadStyle ();
$quadSubstyle = $this -> maniaControl -> manialinkManager -> styleManager -> getDefaultQuadSubstyle ();
2014-01-02 18:06:27 +01:00
$itemMarginFactorX = 1.3 ;
$itemMarginFactorY = 1.2 ;
2014-01-08 20:20:18 +01:00
2014-01-15 22:07:09 +01:00
//If game is shootmania lower the icons position by 20
2014-03-12 13:07:02 +01:00
if ( $this -> maniaControl -> mapManager -> getCurrentMap () -> getGame () == 'sm' ) {
2014-01-15 22:07:09 +01:00
$posY -= $shootManiaOffset ;
}
2014-01-02 18:06:27 +01:00
$itemSize = $width ;
2014-01-08 20:20:18 +01:00
2014-01-02 18:06:27 +01:00
$maniaLink = new ManiaLink ( self :: MLID_DONATE_WIDGET );
2014-01-08 20:20:18 +01:00
2014-01-05 14:14:08 +01:00
// Donate Menu Icon Frame
2014-01-02 18:06:27 +01:00
$frame = new Frame ();
$maniaLink -> add ( $frame );
$frame -> setPosition ( $posX , $posY );
2014-01-08 20:20:18 +01:00
2014-01-02 18:06:27 +01:00
$backgroundQuad = new Quad ();
$frame -> add ( $backgroundQuad );
$backgroundQuad -> setSize ( $width * $itemMarginFactorX , $height * $itemMarginFactorY );
$backgroundQuad -> setStyles ( $quadStyle , $quadSubstyle );
2014-01-08 20:20:18 +01:00
2014-01-02 18:06:27 +01:00
$iconFrame = new Frame ();
$frame -> add ( $iconFrame );
2014-01-08 20:20:18 +01:00
2014-01-02 18:06:27 +01:00
$iconFrame -> setSize ( $itemSize , $itemSize );
$itemQuad = new Quad_Icons128x128_1 ();
$itemQuad -> setSubStyle ( $itemQuad :: SUBSTYLE_Coppers );
$itemQuad -> setSize ( $itemSize , $itemSize );
$iconFrame -> add ( $itemQuad );
2014-01-08 20:20:18 +01:00
2014-01-04 20:20:55 +01:00
$valueArray = explode ( " , " , $values );
2014-01-08 20:20:18 +01:00
2014-01-05 14:14:08 +01:00
// Values Menu
2014-01-04 20:20:55 +01:00
$popoutFrame = new Frame ();
$maniaLink -> add ( $popoutFrame );
$popoutFrame -> setPosition ( $posX - $itemSize * 0.5 , $posY );
$popoutFrame -> setHAlign ( Control :: RIGHT );
$popoutFrame -> setSize ( 4 * $itemSize * $itemMarginFactorX , $itemSize * $itemMarginFactorY );
2014-01-12 01:59:23 +01:00
$popoutFrame -> setVisible ( false );
2014-01-08 20:20:18 +01:00
2014-01-04 20:20:55 +01:00
$quad = new Quad ();
$popoutFrame -> add ( $quad );
$quad -> setHAlign ( Control :: RIGHT );
$quad -> setStyles ( $quadStyle , $quadSubstyle );
$quad -> setSize ( strlen ( $values ) * 2 + count ( $valueArray ) * 1 , $itemSize * $itemMarginFactorY );
2014-01-08 20:20:18 +01:00
2014-01-04 20:20:55 +01:00
$popoutFrame -> add ( $quad );
2014-04-27 16:22:12 +02:00
$itemQuad -> addToggleFeature ( $popoutFrame );
2014-01-08 20:20:18 +01:00
2014-01-05 14:14:08 +01:00
// Description Label
2014-01-04 21:54:40 +01:00
$descriptionFrame = new Frame ();
$maniaLink -> add ( $descriptionFrame );
2014-01-04 21:57:53 +01:00
$descriptionFrame -> setPosition ( $posX - 50 , $posY - 5 );
2014-01-04 21:54:40 +01:00
$descriptionFrame -> setHAlign ( Control :: RIGHT );
2014-01-08 20:20:18 +01:00
2014-01-04 21:54:40 +01:00
$descriptionLabel = new Label ();
2014-01-04 21:57:53 +01:00
$descriptionFrame -> add ( $descriptionLabel );
$descriptionLabel -> setAlign ( Control :: LEFT , Control :: TOP );
2014-01-04 21:54:40 +01:00
$descriptionLabel -> setSize ( 40 , 4 );
$descriptionLabel -> setTextSize ( 2 );
$descriptionLabel -> setVisible ( true );
2014-01-05 00:02:13 +01:00
$descriptionLabel -> setTextColor ( " 0F0 " );
2014-01-08 20:20:18 +01:00
2014-01-04 20:20:55 +01:00
// Add items
$x = - 2 ;
2014-01-08 20:20:18 +01:00
foreach ( array_reverse ( $valueArray ) as $value ) {
2014-01-04 20:20:55 +01:00
$label = new Label_Button ();
$popoutFrame -> add ( $label );
$label -> setX ( $x );
$label -> setHAlign ( Control :: RIGHT );
2014-01-05 14:14:08 +01:00
$label -> setText ( '$s$FFF' . $value . '$09FP' );
2014-01-04 20:20:55 +01:00
$label -> setTextSize ( 1.2 );
$label -> setAction ( self :: ACTION_DONATE_VALUE . " . " . $value );
2014-01-04 22:58:57 +01:00
$label -> setStyle ( Label_Text :: STYLE_TextCardSmall );
2014-04-27 16:22:12 +02:00
$description = " Donate { $value } Planets " ;
$label -> addTooltipLabelFeature ( $descriptionLabel , $description );
2014-01-08 20:20:18 +01:00
2014-01-04 20:20:55 +01:00
$x -= strlen ( $value ) * 2 + 1.7 ;
}
2014-01-08 20:20:18 +01:00
2014-01-02 18:06:27 +01:00
// Send manialink
2014-03-02 13:00:23 +01:00
$this -> maniaControl -> manialinkManager -> sendManialink ( $maniaLink , $login );
2014-01-02 18:06:27 +01:00
}
2013-11-12 19:33:25 +01:00
/**
* Handle / donate command
*
2014-01-08 20:20:18 +01:00
* @ param array $chatCallback
2014-01-02 17:31:58 +01:00
* @ param Player $player
2013-11-12 19:33:25 +01:00
* @ return bool
*/
public function command_Donate ( array $chatCallback , Player $player ) {
2014-01-08 20:20:18 +01:00
$text = $chatCallback [ 1 ][ 2 ];
2013-11-12 19:33:25 +01:00
$params = explode ( ' ' , $text );
2014-01-27 20:46:42 +01:00
if ( count ( $params ) < 2 ) {
2013-11-12 19:33:25 +01:00
$this -> sendDonateUsageExample ( $player );
return false ;
}
2014-01-08 20:20:18 +01:00
$amount = ( int ) $params [ 1 ];
2014-01-27 20:46:42 +01:00
if ( ! $amount || $amount <= 0 ) {
2013-11-12 19:33:25 +01:00
$this -> sendDonateUsageExample ( $player );
return false ;
}
2014-01-27 20:46:42 +01:00
if ( count ( $params ) >= 3 ) {
2014-01-08 20:20:18 +01:00
$receiver = $params [ 2 ];
2013-11-12 19:33:25 +01:00
$receiverPlayer = $this -> maniaControl -> playerManager -> getPlayer ( $receiver );
2014-02-25 18:34:35 +01:00
$receiverName = ( $receiverPlayer ? $receiverPlayer -> nickname : $receiver );
2014-01-08 20:20:18 +01:00
} else {
$receiver = '' ;
2014-02-15 13:04:31 +01:00
$receiverName = $this -> maniaControl -> client -> getServerName ();
2013-11-12 19:33:25 +01:00
}
2014-01-08 20:20:18 +01:00
2014-01-04 20:20:55 +01:00
return $this -> handleDonation ( $player , $amount , $receiver , $receiverName );
}
/**
2014-05-02 16:13:45 +02:00
* Handle a Player Donation
2014-01-04 20:20:55 +01:00
*
* @ param Player $player
2014-05-02 16:13:45 +02:00
* @ param int $amount
* @ param string $receiver
* @ param string $receiverName
* @ return bool
2014-01-04 20:20:55 +01:00
*/
2014-05-02 16:13:45 +02:00
private function handleDonation ( Player $player , $amount , $receiver = '' , $receiverName = null ) {
2014-01-08 20:20:18 +01:00
2014-02-25 18:34:35 +01:00
if ( ! $receiverName ) {
$serverName = $this -> maniaControl -> client -> getServerName ();
$message = 'Donate ' . $amount . ' Planets to $<' . $serverName . '$>?' ;
} else {
$message = 'Donate ' . $amount . ' Planets to $<' . $receiverName . '$>?' ;
2013-11-12 19:33:25 +01:00
}
2014-01-20 20:51:03 +01:00
2014-02-25 18:34:35 +01:00
//Send and Handle the Bill
2014-04-20 14:52:26 +02:00
$self = $this ;
$this -> maniaControl -> billManager -> sendBill ( function ( $data , $status ) use ( & $self , & $player , $amount , $receiver ) {
2014-02-25 18:34:35 +01:00
switch ( $status ) {
case BillManager :: DONATED_TO_SERVER :
2014-04-20 14:52:26 +02:00
if ( $self -> maniaControl -> settingManager -> getSetting ( $self , DonationPlugin :: SETTING_ANNOUNCE_SERVERDONATION , true ) && $amount >= $self -> maniaControl -> settingManager -> getSetting ( $self , DonationPlugin :: SETTING_MIN_AMOUNT_SHOWN , true )) {
2014-02-25 18:34:35 +01:00
$login = null ;
$message = '$<' . $player -> nickname . '$> donated ' . $amount . ' Planets! Thanks.' ;
} else {
2014-04-13 11:53:59 +02:00
$login = $player -> login ;
2014-02-25 18:34:35 +01:00
$message = 'Donation successful! Thanks.' ;
}
2014-04-20 14:52:26 +02:00
$self -> maniaControl -> chat -> sendSuccess ( $message , $login );
$self -> maniaControl -> statisticManager -> insertStat ( DonationPlugin :: STAT_PLAYER_DONATIONS , $player , $self -> maniaControl -> server -> index , $amount );
2014-02-25 18:34:35 +01:00
break ;
case BillManager :: DONATED_TO_RECEIVER :
$message = " Successfully donated { $amount } to ' { $receiver } '! " ;
2014-04-20 14:52:26 +02:00
$self -> maniaControl -> chat -> sendSuccess ( $message , $player -> login );
2014-02-25 18:34:35 +01:00
break ;
case BillManager :: PLAYER_REFUSED_DONATION :
$message = 'Transaction cancelled.' ;
2014-04-20 14:52:26 +02:00
$self -> maniaControl -> chat -> sendError ( $message , $player -> login );
2014-02-25 18:34:35 +01:00
break ;
case BillManager :: ERROR_WHILE_TRANSACTION :
$message = $data ;
2014-04-20 14:52:26 +02:00
$self -> maniaControl -> chat -> sendError ( $message , $player -> login );
2014-02-25 18:34:35 +01:00
break ;
}
}, $player , $amount , $message );
2014-01-08 20:20:18 +01:00
2013-11-12 19:33:25 +01:00
return true ;
}
/**
2013-11-13 01:43:12 +01:00
* Handle //pay command
2013-11-12 19:33:25 +01:00
*
2014-01-08 20:20:18 +01:00
* @ param array $chatCallback
2014-01-02 17:31:58 +01:00
* @ param Player $player
2013-11-12 19:33:25 +01:00
* @ return bool
*/
public function command_Pay ( array $chatCallback , Player $player ) {
2014-01-27 20:46:42 +01:00
if ( ! $this -> maniaControl -> authenticationManager -> checkRight ( $player , AuthenticationManager :: AUTH_LEVEL_SUPERADMIN )) {
2013-11-13 01:43:12 +01:00
$this -> maniaControl -> authenticationManager -> sendNotAllowed ( $player );
2013-11-12 19:33:25 +01:00
return false ;
}
2014-01-08 20:20:18 +01:00
$text = $chatCallback [ 1 ][ 2 ];
2013-11-12 19:33:25 +01:00
$params = explode ( ' ' , $text );
2014-01-27 20:46:42 +01:00
if ( count ( $params ) < 2 ) {
2013-11-12 19:33:25 +01:00
$this -> sendPayUsageExample ( $player );
return false ;
}
2014-01-08 20:20:18 +01:00
$amount = ( int ) $params [ 1 ];
2014-01-27 20:46:42 +01:00
if ( ! $amount || $amount <= 0 ) {
2013-11-12 19:33:25 +01:00
$this -> sendPayUsageExample ( $player );
return false ;
}
2014-01-27 20:46:42 +01:00
if ( count ( $params ) >= 3 ) {
2013-11-12 19:33:25 +01:00
$receiver = $params [ 2 ];
2014-01-08 20:20:18 +01:00
} else {
2013-11-12 19:33:25 +01:00
$receiver = $player -> login ;
}
2014-02-15 13:04:31 +01:00
$message = 'Payout from $<' . $this -> maniaControl -> client -> getServerName () . '$>.' ;
2014-01-20 20:51:03 +01:00
2014-04-20 14:52:26 +02:00
$self = $this ;
$this -> maniaControl -> billManager -> sendPlanets ( function ( $data , $status ) use ( & $self , & $player , $amount , $receiver ) {
2014-02-25 18:34:35 +01:00
switch ( $status ) {
case BillManager :: PAYED_FROM_SERVER :
$message = " Successfully payed out { $amount } to ' { $receiver } '! " ;
2014-04-20 14:52:26 +02:00
$self -> maniaControl -> chat -> sendSuccess ( $message , $player -> login );
2014-02-25 18:34:35 +01:00
break ;
case BillManager :: PLAYER_REFUSED_DONATION :
$message = 'Transaction cancelled.' ;
2014-04-20 14:52:26 +02:00
$self -> maniaControl -> chat -> sendError ( $message , $player -> login );
2014-02-25 18:34:35 +01:00
break ;
case BillManager :: ERROR_WHILE_TRANSACTION :
$message = $data ;
2014-04-20 14:52:26 +02:00
$self -> maniaControl -> chat -> sendError ( $message , $player -> login );
2014-02-25 18:34:35 +01:00
break ;
}
}, $receiver , $amount , $message );
2014-01-20 20:51:03 +01:00
2013-11-12 19:33:25 +01:00
return true ;
}
/**
2013-11-13 01:43:12 +01:00
* Handle //getplanets command
2013-11-12 19:33:25 +01:00
*
2014-01-08 20:20:18 +01:00
* @ param array $chatCallback
2014-01-02 17:31:58 +01:00
* @ param Player $player
2013-11-12 19:33:25 +01:00
* @ return bool
*/
public function command_GetPlanets ( array $chatCallback , Player $player ) {
2014-01-27 20:46:42 +01:00
if ( ! $this -> maniaControl -> authenticationManager -> checkRight ( $player , AuthenticationManager :: AUTH_LEVEL_ADMIN )) {
2013-11-13 01:43:12 +01:00
$this -> maniaControl -> authenticationManager -> sendNotAllowed ( $player );
2013-11-12 19:33:25 +01:00
return false ;
}
2014-02-13 14:21:25 +01:00
$planets = $this -> maniaControl -> client -> getServerPlanets ();
2013-11-12 19:33:25 +01:00
$message = " This Server has { $planets } Planets! " ;
return $this -> maniaControl -> chat -> sendInformation ( $message , $player -> login );
}
/**
* Send an usage example for / donate to the player
*
2014-01-02 17:31:58 +01:00
* @ param Player $player
2013-11-12 19:33:25 +01:00
* @ return boolean
*/
private function sendDonateUsageExample ( Player $player ) {
2013-11-13 01:43:12 +01:00
$message = " Usage Example: '/donate 100' " ;
return $this -> maniaControl -> chat -> sendChat ( $message , $player -> login );
2013-11-12 19:33:25 +01:00
}
/**
* Send an usage example for / pay to the player
*
2014-01-02 17:31:58 +01:00
* @ param Player $player
2013-11-12 19:33:25 +01:00
* @ return boolean
*/
private function sendPayUsageExample ( Player $player ) {
2013-11-13 01:43:12 +01:00
$message = " Usage Example: '/pay 100 login' " ;
return $this -> maniaControl -> chat -> sendChat ( $message , $player -> login );
2013-11-12 19:33:25 +01:00
}
2014-05-02 16:02:09 +02:00
/**
* Handles the / topdons command
*
* @ param array $chatCallback
* @ param Player $player
*/
public function command_TopDons ( array $chatCallback , Player $player ) {
$this -> showTopDonsList ( $player );
}
/**
* Provides a ManiaLink overview with donators .
*
* @ param Player $player
* @ return null
*/
private function showTopDonsList ( Player $player ) {
$query = " SELECT * FROM ` " . StatisticManager :: TABLE_STATISTICS . " ` WHERE `statId` = 3 ORDER BY `value` DESC LIMIT 0, 100 " ;
$mysqli = $this -> maniaControl -> database -> mysqli ;
$result = $mysqli -> query ( $query );
if ( $mysqli -> error ) {
trigger_error ( $mysqli -> error );
return null ;
}
$width = $this -> maniaControl -> manialinkManager -> styleManager -> getListWidgetsWidth ();
$height = $this -> maniaControl -> manialinkManager -> styleManager -> getListWidgetsHeight ();
// create manialink
$maniaLink = new ManiaLink ( ManialinkManager :: MAIN_MLID );
$script = $maniaLink -> getScript ();
$paging = new Paging ();
$script -> addFeature ( $paging );
// Main frame
$frame = $this -> maniaControl -> manialinkManager -> styleManager -> getDefaultListFrame ( $script , $paging );
$maniaLink -> add ( $frame );
// Start offsets
$x = - $width / 2 ;
$y = $height / 2 ;
//Predefine description Label
$descriptionLabel = $this -> maniaControl -> manialinkManager -> styleManager -> getDefaultDescriptionLabel ();
$frame -> add ( $descriptionLabel );
// Headline
$headFrame = new Frame ();
$frame -> add ( $headFrame );
$headFrame -> setY ( $y - 5 );
$array = array ( '$oId' => $x + 5 , '$oNickname' => $x + 18 , '$oDonated planets' => $x + 70 );
$this -> maniaControl -> manialinkManager -> labelLine ( $headFrame , $array );
$i = 1 ;
$y = $y - 10 ;
$pageFrames = array ();
while ( $donator = $result -> fetch_object ()) {
if ( ! isset ( $pageFrame )) {
$pageFrame = new Frame ();
$frame -> add ( $pageFrame );
if ( ! empty ( $pageFrames )) {
$pageFrame -> setVisible ( false );
}
array_push ( $pageFrames , $pageFrame );
$y = $height / 2 - 10 ;
$paging -> addPage ( $pageFrame );
}
$playerFrame = new Frame ();
$pageFrame -> add ( $playerFrame );
$playerFrame -> setY ( $y );
if ( $i % 2 != 0 ) {
$lineQuad = new Quad_BgsPlayerCard ();
$playerFrame -> add ( $lineQuad );
$lineQuad -> setSize ( $width , 4 );
$lineQuad -> setSubStyle ( $lineQuad :: SUBSTYLE_BgPlayerCardBig );
$lineQuad -> setZ ( 0.001 );
}
$donatingPlayer = $this -> maniaControl -> playerManager -> getPlayerByIndex ( $donator -> playerId );
$array = array ( $i => $x + 5 , $donatingPlayer -> nickname => $x + 18 , $donator -> value => $x + 70 );
$this -> maniaControl -> manialinkManager -> labelLine ( $playerFrame , $array );
$y -= 4 ;
$i ++ ;
if (( $i - 1 ) % 15 == 0 ) {
unset ( $pageFrame );
}
}
// Render and display xml
$this -> maniaControl -> manialinkManager -> displayWidget ( $maniaLink , $player , 'TopDons' );
}
2013-11-12 19:33:25 +01:00
}