improved PHPDoc & applied common style
This commit is contained in:
parent
8296e8457c
commit
9aea33951a
File diff suppressed because it is too large
Load Diff
@ -1,4 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Dedimania;
|
namespace Dedimania;
|
||||||
|
|
||||||
use ManiaControl\ManiaControl;
|
use ManiaControl\ManiaControl;
|
||||||
@ -7,11 +8,14 @@ use Maniaplanet\DedicatedServer\Structures\Version;
|
|||||||
/**
|
/**
|
||||||
* ManiaControl Dedimania Plugin DataStructure
|
* ManiaControl Dedimania Plugin DataStructure
|
||||||
*
|
*
|
||||||
* @author kremsy and steeffeen
|
* @author ManiaControl Team <mail@maniacontrol.com>
|
||||||
* @copyright ManiaControl Copyright © 2014 ManiaControl Team
|
* @copyright 2014 ManiaControl Team
|
||||||
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
||||||
*/
|
*/
|
||||||
class DedimaniaData {
|
class DedimaniaData {
|
||||||
|
/*
|
||||||
|
* Constants
|
||||||
|
*/
|
||||||
public $game;
|
public $game;
|
||||||
public $path;
|
public $path;
|
||||||
public $packmask;
|
public $packmask;
|
||||||
@ -27,6 +31,15 @@ class DedimaniaData {
|
|||||||
public $directoryAccessChecked = false;
|
public $directoryAccessChecked = false;
|
||||||
public $serverMaxRank = 30;
|
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) {
|
public function __construct($serverLogin, $dedimaniaCode, $path, $packmask, Version $serverVersion) {
|
||||||
$this->game = "TM2";
|
$this->game = "TM2";
|
||||||
$this->login = $serverLogin;
|
$this->login = $serverLogin;
|
||||||
|
@ -1,22 +1,32 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Dedimania;
|
namespace Dedimania;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ManiaControl Dedimania-Plugin Player DataStructure
|
* ManiaControl Dedimania-Plugin Player DataStructure
|
||||||
*
|
*
|
||||||
* @author kremsy and steeffeen
|
* @author ManiaControl Team <mail@maniacontrol.com>
|
||||||
* @copyright ManiaControl Copyright © 2014 ManiaControl Team
|
* @copyright 2014 ManiaControl Team
|
||||||
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
||||||
*/
|
*/
|
||||||
class DedimaniaPlayer {
|
class DedimaniaPlayer {
|
||||||
|
/*
|
||||||
|
* Public Properties
|
||||||
|
*/
|
||||||
public $login = '';
|
public $login = '';
|
||||||
public $maxRank = -1;
|
public $maxRank = -1;
|
||||||
public $banned = false;
|
public $banned = false;
|
||||||
public $optionsEnabled = false;
|
public $optionsEnabled = false;
|
||||||
public $options = '';
|
public $options = '';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Construct a new Dedimania Player Model
|
||||||
|
* @param mixed$player
|
||||||
|
*/
|
||||||
public function __construct($player) {
|
public function __construct($player) {
|
||||||
if (!$player) return;
|
if (!$player) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
$this->login = $player['Login'];
|
$this->login = $player['Login'];
|
||||||
$this->maxRank = $player['MaxRank'];
|
$this->maxRank = $player['MaxRank'];
|
||||||
@ -28,8 +38,8 @@ class DedimaniaPlayer {
|
|||||||
/**
|
/**
|
||||||
* Construct a new Player by its login and maxRank
|
* Construct a new Player by its login and maxRank
|
||||||
*
|
*
|
||||||
* @param $login
|
* @param string $login
|
||||||
* @param $maxRank
|
* @param int $maxRank
|
||||||
*/
|
*/
|
||||||
public function constructNewPlayer($login, $maxRank) {
|
public function constructNewPlayer($login, $maxRank) {
|
||||||
$this->login = $login;
|
$this->login = $login;
|
||||||
|
@ -1,16 +1,20 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Dedimania;
|
namespace Dedimania;
|
||||||
|
|
||||||
|
use ManiaControl\Formatter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ManiaControl Dedimania-Plugin Record DataStructure
|
* ManiaControl Dedimania-Plugin Record DataStructure
|
||||||
*
|
*
|
||||||
* @author kremsy and steeffeen
|
* @author ManiaControl Team <mail@maniacontrol.com>
|
||||||
* @copyright ManiaControl Copyright © 2014 ManiaControl Team
|
* @copyright 2014 ManiaControl Team
|
||||||
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
||||||
*/
|
*/
|
||||||
use ManiaControl\Formatter;
|
|
||||||
|
|
||||||
class RecordData {
|
class RecordData {
|
||||||
|
/*
|
||||||
|
* Public Properties
|
||||||
|
*/
|
||||||
public $nullRecord = false;
|
public $nullRecord = false;
|
||||||
public $login = '';
|
public $login = '';
|
||||||
public $nickName = '';
|
public $nickName = '';
|
||||||
@ -25,7 +29,7 @@ class RecordData {
|
|||||||
/**
|
/**
|
||||||
* Construct a Record by a given Record Array
|
* Construct a Record by a given Record Array
|
||||||
*
|
*
|
||||||
* @param $record
|
* @param array $record
|
||||||
*/
|
*/
|
||||||
public function __construct($record) {
|
public function __construct($record) {
|
||||||
if (!$record) {
|
if (!$record) {
|
||||||
@ -42,12 +46,12 @@ class RecordData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs a new Record via it's properties
|
* Construct a new Record via its Properties
|
||||||
*
|
*
|
||||||
* @param $login
|
* @param string $login
|
||||||
* @param $nickName
|
* @param string $nickName
|
||||||
* @param $best
|
* @param float $best
|
||||||
* @param $checkpoints
|
* @param int $checkpoints
|
||||||
* @param bool $newRecord
|
* @param bool $newRecord
|
||||||
*/
|
*/
|
||||||
public function constructNewRecord($login, $nickName, $best, $checkpoints, $newRecord = false) {
|
public function constructNewRecord($login, $nickName, $best, $checkpoints, $newRecord = false) {
|
||||||
|
@ -11,12 +11,12 @@ use Maniaplanet\DedicatedServer\Xmlrpc\Exception;
|
|||||||
/**
|
/**
|
||||||
* ManiaControl Chat-Message Plugin
|
* ManiaControl Chat-Message Plugin
|
||||||
*
|
*
|
||||||
* @author kremsy <kremsy@maniacontrol.com>
|
* @author ManiaControl Team <mail@maniacontrol.com>
|
||||||
* @copyright 2014 ManiaControl Team
|
* @copyright 2014 ManiaControl Team
|
||||||
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
||||||
*/
|
*/
|
||||||
class ChatMessagePlugin implements CommandListener, Plugin {
|
class ChatMessagePlugin implements CommandListener, Plugin {
|
||||||
/**
|
/*
|
||||||
* Constants
|
* Constants
|
||||||
*/
|
*/
|
||||||
const PLUGIN_ID = 4;
|
const PLUGIN_ID = 4;
|
||||||
@ -25,72 +25,55 @@ class ChatMessagePlugin implements CommandListener, Plugin {
|
|||||||
const PLUGIN_AUTHOR = 'kremsy';
|
const PLUGIN_AUTHOR = 'kremsy';
|
||||||
const SETTING_AFK_FORCE_SPEC = 'AFK command forces spec';
|
const SETTING_AFK_FORCE_SPEC = 'AFK command forces spec';
|
||||||
|
|
||||||
/**
|
/*
|
||||||
* Private Properties
|
* Private Properties
|
||||||
*/
|
*/
|
||||||
/** @var maniaControl $maniaControl */
|
/** @var ManiaControl $maniaControl */
|
||||||
private $maniaControl = null;
|
private $maniaControl = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Prepares the Plugin
|
* @see \ManiaControl\Plugins\Plugin::prepare()
|
||||||
*
|
|
||||||
* @param ManiaControl $maniaControl
|
|
||||||
* @return mixed
|
|
||||||
*/
|
*/
|
||||||
public static function prepare(ManiaControl $maniaControl) {
|
public static function prepare(ManiaControl $maniaControl) {
|
||||||
//do nothing
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get plugin id
|
* @see \ManiaControl\Plugins\Plugin::getId()
|
||||||
*
|
|
||||||
* @return int
|
|
||||||
*/
|
*/
|
||||||
public static function getId() {
|
public static function getId() {
|
||||||
return self::PLUGIN_ID;
|
return self::PLUGIN_ID;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get Plugin Name
|
* @see \ManiaControl\Plugins\Plugin::getName()
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
*/
|
||||||
public static function getName() {
|
public static function getName() {
|
||||||
return self::PLUGIN_NAME;
|
return self::PLUGIN_NAME;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get Plugin Version
|
* @see \ManiaControl\Plugins\Plugin::getVersion()
|
||||||
*
|
|
||||||
* @return float,,
|
|
||||||
*/
|
*/
|
||||||
public static function getVersion() {
|
public static function getVersion() {
|
||||||
return self::PLUGIN_VERSION;
|
return self::PLUGIN_VERSION;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get Plugin Author
|
* @see \ManiaControl\Plugins\Plugin::getAuthor()
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
*/
|
||||||
public static function getAuthor() {
|
public static function getAuthor() {
|
||||||
return self::PLUGIN_AUTHOR;
|
return self::PLUGIN_AUTHOR;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get Plugin Description
|
* @see \ManiaControl\Plugins\Plugin::getDescription()
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
*/
|
||||||
public static function getDescription() {
|
public static function getDescription() {
|
||||||
return "Plugin offers various Chat-Commands like /gg /hi /afk /rq...";
|
return "Plugin offers various Chat-Commands like /gg /hi /afk /rq...";
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Load the plugin
|
* @see \ManiaControl\Plugins\Plugin::load()
|
||||||
*
|
|
||||||
* @param \ManiaControl\ManiaControl $maniaControl
|
|
||||||
* @return bool
|
|
||||||
*/
|
*/
|
||||||
public function load(ManiaControl $maniaControl) {
|
public function load(ManiaControl $maniaControl) {
|
||||||
$this->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() {
|
public function unload() {
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,7 @@ use ManiaControl\Settings\SettingManager;
|
|||||||
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
||||||
*/
|
*/
|
||||||
class ChatlogPlugin implements CallbackListener, Plugin {
|
class ChatlogPlugin implements CallbackListener, Plugin {
|
||||||
/**
|
/*
|
||||||
* Constants
|
* Constants
|
||||||
*/
|
*/
|
||||||
const ID = 26;
|
const ID = 26;
|
||||||
@ -31,7 +31,7 @@ class ChatlogPlugin implements CallbackListener, Plugin {
|
|||||||
const SETTING_LOGSERVERMESSAGES = 'Log Server Messages';
|
const SETTING_LOGSERVERMESSAGES = 'Log Server Messages';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Private properties
|
* Private Properties
|
||||||
*/
|
*/
|
||||||
/** @var ManiaControl $maniaControl */
|
/** @var ManiaControl $maniaControl */
|
||||||
private $maniaControl = null;
|
private $maniaControl = null;
|
||||||
|
@ -14,6 +14,7 @@ use FML\Controls\Quads\Quad_Icons128x32_1;
|
|||||||
use FML\Controls\Quads\Quad_Icons64x64_1;
|
use FML\Controls\Quads\Quad_Icons64x64_1;
|
||||||
use FML\Controls\Quads\Quad_UIConstruction_Buttons;
|
use FML\Controls\Quads\Quad_UIConstruction_Buttons;
|
||||||
use FML\ManiaLink;
|
use FML\ManiaLink;
|
||||||
|
use FML\Script\Features\KeyAction;
|
||||||
use ManiaControl\Callbacks\CallbackListener;
|
use ManiaControl\Callbacks\CallbackListener;
|
||||||
use ManiaControl\Callbacks\CallbackManager;
|
use ManiaControl\Callbacks\CallbackManager;
|
||||||
use ManiaControl\Callbacks\TimerListener;
|
use ManiaControl\Callbacks\TimerListener;
|
||||||
@ -28,14 +29,13 @@ use ManiaControl\Server\Server;
|
|||||||
use ManiaControl\Server\ServerCommands;
|
use ManiaControl\Server\ServerCommands;
|
||||||
use Maniaplanet\DedicatedServer\Structures\VoteRatio;
|
use Maniaplanet\DedicatedServer\Structures\VoteRatio;
|
||||||
use Maniaplanet\DedicatedServer\Xmlrpc\NotInScriptModeException;
|
use Maniaplanet\DedicatedServer\Xmlrpc\NotInScriptModeException;
|
||||||
use FML\Script\Features\KeyAction;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ManiaControl Custom-Votes Plugin
|
* ManiaControl Custom-Votes Plugin
|
||||||
*
|
*
|
||||||
* @author kremsy
|
* @author ManiaControl Team <mail@maniacontrol.com>
|
||||||
* @copyright ManiaControl Copyright © 2014 ManiaControl Team
|
* @copyright 2014 ManiaControl Team
|
||||||
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
||||||
*/
|
*/
|
||||||
class CustomVotesPlugin implements CommandListener, CallbackListener, ManialinkPageAnswerListener, TimerListener, Plugin {
|
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';
|
const CB_CUSTOM_VOTE_FINISHED = 'CustomVotesPlugin.CustomVoteFinished';
|
||||||
|
|
||||||
/**
|
/*
|
||||||
* Private Properties
|
* Private Properties
|
||||||
*/
|
*/
|
||||||
/** @var maniaControl $maniaControl */
|
/** @var maniaControl $maniaControl */
|
||||||
@ -84,20 +84,48 @@ class CustomVotesPlugin implements CommandListener, CallbackListener, ManialinkP
|
|||||||
private $currentVote = null;
|
private $currentVote = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Prepares the Plugin
|
* @see \ManiaControl\Plugins\Plugin::prepare()
|
||||||
*
|
|
||||||
* @param ManiaControl $maniaControl
|
|
||||||
* @return mixed
|
|
||||||
*/
|
*/
|
||||||
public static function prepare(ManiaControl $maniaControl) {
|
public static function prepare(ManiaControl $maniaControl) {
|
||||||
//do nothing
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Load the plugin
|
* @see \ManiaControl\Plugins\Plugin::getId()
|
||||||
*
|
*/
|
||||||
* @param \ManiaControl\ManiaControl $maniaControl
|
public static function getId() {
|
||||||
* @return bool
|
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) {
|
public function load(ManiaControl $maniaControl) {
|
||||||
$this->maniaControl = $maniaControl;
|
$this->maniaControl = $maniaControl;
|
||||||
@ -169,68 +197,20 @@ class CustomVotesPlugin implements CommandListener, CallbackListener, ManialinkP
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unload the plugin and its resources
|
* Defines a Vote
|
||||||
*/
|
|
||||||
public function unload() {
|
|
||||||
//Enable Standard Votes
|
|
||||||
$defaultRatio = $this->maniaControl->client->getCallVoteRatio();
|
|
||||||
|
|
||||||
$array["Command"] = VoteRatio::COMMAND_BAN;
|
|
||||||
$array["Param"] = "";
|
|
||||||
$array["Ratio"] = (float)$defaultRatio;
|
|
||||||
$ratioArray[] = $array;
|
|
||||||
$array["Command"] = VoteRatio::COMMAND_KICK;
|
|
||||||
$ratioArray[] = $array;
|
|
||||||
$array["Command"] = VoteRatio::COMMAND_RESTART_MAP;
|
|
||||||
$ratioArray[] = $array;
|
|
||||||
$array["Command"] = VoteRatio::COMMAND_TEAM_BALANCE;
|
|
||||||
$ratioArray[] = $array;
|
|
||||||
$array["Command"] = VoteRatio::COMMAND_NEXT_MAP;
|
|
||||||
$ratioArray[] = $array;
|
|
||||||
|
|
||||||
$this->maniaControl->client->setCallVoteRatiosEx(false, $ratioArray);
|
|
||||||
|
|
||||||
$this->destroyVote();
|
|
||||||
$this->maniaControl->manialinkManager->hideManialink(self::MLID_ICON);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Handle PlayerConnect callback
|
|
||||||
*
|
*
|
||||||
* @param Player $player
|
* @param $voteIndex
|
||||||
|
* @param $voteName
|
||||||
|
* @param bool $idBased
|
||||||
|
* @param $neededRatio
|
||||||
*/
|
*/
|
||||||
public function handlePlayerConnect(Player $player) {
|
public function defineVote($voteIndex, $voteName, $idBased = false, $startText = '', $neededRatio = -1) {
|
||||||
$this->showIcon($player->login);
|
if ($neededRatio == -1) {
|
||||||
}
|
$neededRatio = $this->maniaControl->settingManager->getSetting($this, self::SETTING_DEFAULT_RATIO);
|
||||||
|
|
||||||
/**
|
|
||||||
* Add a new Vote Menu Item
|
|
||||||
*
|
|
||||||
* @param Control $control
|
|
||||||
* @param int $order
|
|
||||||
* @param string $description
|
|
||||||
*/
|
|
||||||
public function addVoteMenuItem(Control $control, $order = 0, $description = null) {
|
|
||||||
if (!isset($this->voteMenuItems[$order])) {
|
|
||||||
$this->voteMenuItems[$order] = array();
|
|
||||||
array_push($this->voteMenuItems[$order], array($control, $description));
|
|
||||||
krsort($this->voteMenuItems);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Chat Vote
|
|
||||||
*
|
|
||||||
* @param array $chat
|
|
||||||
* @param Player $player
|
|
||||||
*/
|
|
||||||
public function chat_vote(array $chat, Player $player) {
|
|
||||||
$command = explode(" ", $chat[1][2]);
|
|
||||||
if (isset($command[1])) {
|
|
||||||
if (isset($this->voteCommands[$command[1]])) {
|
|
||||||
$this->startVote($player, strtolower($command[1]));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
$voteCommand = new VoteCommand($voteIndex, $voteName, $idBased, $neededRatio);
|
||||||
|
$voteCommand->startText = $startText;
|
||||||
|
$this->voteCommands[$voteIndex] = $voteCommand;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -285,360 +265,18 @@ class CustomVotesPlugin implements CommandListener, CallbackListener, ManialinkP
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Destroy the Vote on Canceled Callback
|
* Add a new Vote Menu Item
|
||||||
*
|
*
|
||||||
* @param Player $player
|
* @param Control $control
|
||||||
|
* @param int $order
|
||||||
|
* @param string $description
|
||||||
*/
|
*/
|
||||||
public function handleVoteCanceled(Player $player) {
|
public function addVoteMenuItem(Control $control, $order = 0, $description = null) {
|
||||||
//reset vote
|
if (!isset($this->voteMenuItems[$order])) {
|
||||||
$this->destroyVote();
|
$this->voteMenuItems[$order] = array();
|
||||||
|
array_push($this->voteMenuItems[$order], array($control, $description));
|
||||||
|
krsort($this->voteMenuItems);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Handle Standard Votes
|
|
||||||
*
|
|
||||||
* @param $voteName
|
|
||||||
* @param $voteResult
|
|
||||||
*/
|
|
||||||
public function handleVoteFinished($voteName, $voteResult) {
|
|
||||||
if ($voteResult >= $this->currentVote->neededRatio) {
|
|
||||||
// Call Closure if one exists
|
|
||||||
if (is_callable($this->currentVote->function)) {
|
|
||||||
call_user_func($this->currentVote->function, $voteResult);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
switch($voteName) {
|
|
||||||
case 'teambalance':
|
|
||||||
$this->maniaControl->client->autoTeamBalance();
|
|
||||||
$this->maniaControl->chat->sendInformation('$f8fVote to $fffbalance the teams$f8f has been successfull!');
|
|
||||||
break;
|
|
||||||
case 'skipmap':
|
|
||||||
case 'skip':
|
|
||||||
case 'nextmap':
|
|
||||||
$this->maniaControl->client->nextMap();
|
|
||||||
$this->maniaControl->chat->sendInformation('$f8fVote to $fffskip the map$f8f has been successfull!');
|
|
||||||
break;
|
|
||||||
case 'restartmap':
|
|
||||||
$this->maniaControl->client->restartMap();
|
|
||||||
$this->maniaControl->chat->sendInformation('$f8fVote to $fffrestart the map$f8f has been successfull!');
|
|
||||||
break;
|
|
||||||
case 'pausegame':
|
|
||||||
$this->maniaControl->client->sendModeScriptCommands(array('Command_ForceWarmUp' => True));
|
|
||||||
$this->maniaControl->chat->sendInformation('$f8fVote to $fffpause the current game$f8f has been successfull!');
|
|
||||||
break;
|
|
||||||
case 'replay':
|
|
||||||
$this->maniaControl->mapManager->mapQueue->addFirstMapToMapQueue($this->currentVote->voter, $this->maniaControl->mapManager->getCurrentMap());
|
|
||||||
$this->maniaControl->chat->sendInformation('$f8fVote to $fffreplay the map$f8f has been successfull!');
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
$this->maniaControl->chat->sendError('Vote Failed!');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Handles the ManialinkPageAnswers and start a vote if a button in the panel got clicked
|
|
||||||
*
|
|
||||||
* @param array $callback
|
|
||||||
*/
|
|
||||||
public function handleManialinkPageAnswer(array $callback) {
|
|
||||||
$actionId = $callback[1][2];
|
|
||||||
$actionArray = explode('.', $actionId);
|
|
||||||
if (count($actionArray) <= 2) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$voteIndex = $actionArray[2];
|
|
||||||
if (isset($this->voteCommands[$voteIndex])) {
|
|
||||||
$login = $callback[1][1];
|
|
||||||
$player = $this->maniaControl->playerManager->getPlayer($login);
|
|
||||||
$this->startVote($player, $voteIndex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function handleChatVote(array $chat, Player $player) {
|
|
||||||
$chatCommand = explode(' ', $chat[1][2]);
|
|
||||||
$chatCommand = $chatCommand[0];
|
|
||||||
$chatCommand = str_replace('/', '', $chatCommand);
|
|
||||||
|
|
||||||
if (isset($this->voteCommands[$chatCommand])) {
|
|
||||||
$this->startVote($player, $chatCommand);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Defines a Vote
|
|
||||||
*
|
|
||||||
* @param $voteIndex
|
|
||||||
* @param $voteName
|
|
||||||
* @param bool $idBased
|
|
||||||
* @param $neededRatio
|
|
||||||
*/
|
|
||||||
public function defineVote($voteIndex, $voteName, $idBased = false, $startText = '', $neededRatio = -1) {
|
|
||||||
if ($neededRatio == -1) {
|
|
||||||
$neededRatio = $this->maniaControl->settingManager->getSetting($this, self::SETTING_DEFAULT_RATIO);
|
|
||||||
}
|
|
||||||
$voteCommand = new VoteCommand($voteIndex, $voteName, $idBased, $neededRatio);
|
|
||||||
$voteCommand->startText = $startText;
|
|
||||||
$this->voteCommands[$voteIndex] = $voteCommand;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Undefines a Vote
|
|
||||||
*
|
|
||||||
* @param $voteIndex
|
|
||||||
*/
|
|
||||||
public function undefineVote($voteIndex) {
|
|
||||||
unset($this->voteCommands[$voteIndex]);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Starts a vote
|
|
||||||
*
|
|
||||||
* @param \ManiaControl\Players\Player $player
|
|
||||||
* @param $voteIndex
|
|
||||||
* @param $action
|
|
||||||
*/
|
|
||||||
public function startVote(Player $player, $voteIndex, $function = null) {
|
|
||||||
//Player is muted
|
|
||||||
if ($this->maniaControl->playerManager->playerActions->isPlayerMuted($player)) {
|
|
||||||
$this->maniaControl->chat->sendError('Muted Players are not allowed to start a vote.', $player->login);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
//Specators are not allowed to start a vote
|
|
||||||
if ($player->isSpectator && !$this->maniaControl->settingManager->getSetting($this, self::SETTING_SPECTATOR_ALLOW_START_VOTE)) {
|
|
||||||
$this->maniaControl->chat->sendError('Spectators are not allowed to start a vote.', $player->login);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
//Vote does not exist
|
|
||||||
if (!isset($this->voteCommands[$voteIndex])) {
|
|
||||||
$this->maniaControl->chat->sendError('Undefined vote.', $player->login);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
//A vote is currently running
|
|
||||||
if (isset($this->currentVote)) {
|
|
||||||
$this->maniaControl->chat->sendError('There is currently another vote running.', $player->login);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$maxTime = $this->maniaControl->settingManager->getSetting($this, self::SETTING_VOTE_TIME);
|
|
||||||
|
|
||||||
$this->currentVote = $this->voteCommands[$voteIndex];
|
|
||||||
|
|
||||||
$this->currentVote = new CurrentVote($this->voteCommands[$voteIndex], $player, time() + $maxTime);
|
|
||||||
$this->currentVote->neededRatio = floatval($this->maniaControl->settingManager->getSetting($this, self::SETTING_DEFAULT_RATIO));
|
|
||||||
$this->currentVote->neededPlayerRatio = floatval($this->maniaControl->settingManager->getSetting($this, self::SETTING_DEFAULT_PLAYER_RATIO));
|
|
||||||
$this->currentVote->function = $function;
|
|
||||||
|
|
||||||
if ($this->currentVote->voteCommand->startText != '') {
|
|
||||||
$message = $this->currentVote->voteCommand->startText;
|
|
||||||
} else {
|
|
||||||
$message = '$fff$<' . $player->nickname . '$>$s$f8f started a $fff$<' . $this->currentVote->voteCommand->name . '$>$f8f!';
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->maniaControl->chat->sendSuccess($message);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Handles a Positive Vote
|
|
||||||
*
|
|
||||||
* @param array $callback
|
|
||||||
* @param Player $player
|
|
||||||
*/
|
|
||||||
public function handlePositiveVote(array $callback, Player $player) {
|
|
||||||
if (!isset($this->currentVote) || $player->isSpectator && !$this->maniaControl->settingManager->getSetting($this, self::SETTING_SPECTATOR_ALLOW_VOTE)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->currentVote->votePositive($player->login);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Handles a negative Vote
|
|
||||||
*
|
|
||||||
* @param array $callback
|
|
||||||
* @param Player $player
|
|
||||||
*/
|
|
||||||
public function handleNegativeVote(array $callback, Player $player) {
|
|
||||||
if (!isset($this->currentVote) || $player->isSpectator && !$this->maniaControl->settingManager->getSetting($this, self::SETTING_SPECTATOR_ALLOW_VOTE)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->currentVote->voteNegative($player->login);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Handle ManiaControl 1 Second callback
|
|
||||||
*
|
|
||||||
* @param $time
|
|
||||||
*/
|
|
||||||
public function handle1Second($time) {
|
|
||||||
if (!isset($this->currentVote)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$votePercentage = $this->currentVote->positiveVotes / $this->currentVote->getVoteCount();
|
|
||||||
|
|
||||||
$timeUntilExpire = $this->currentVote->expireTime - time();
|
|
||||||
$this->showVoteWidget($timeUntilExpire, $votePercentage);
|
|
||||||
|
|
||||||
$playerCount = $this->maniaControl->playerManager->getPlayerCount();
|
|
||||||
$playersVoteRatio = (100 / $playerCount * $this->currentVote->getVoteCount()) / 100;
|
|
||||||
|
|
||||||
//Check if vote is over
|
|
||||||
if ($timeUntilExpire <= 0 || (($playersVoteRatio >= $this->currentVote->neededPlayerRatio) && (($votePercentage >= $this->currentVote->neededRatio) || ($votePercentage <= 1 - $this->currentVote->neededRatio)))) {
|
|
||||||
// Trigger callback
|
|
||||||
$this->maniaControl->callbackManager->triggerCallback(self::CB_CUSTOM_VOTE_FINISHED, $this->currentVote->voteCommand->index, $votePercentage);
|
|
||||||
|
|
||||||
//reset vote
|
|
||||||
$this->destroyVote();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Destroys the current Vote
|
|
||||||
*/
|
|
||||||
private function destroyVote() {
|
|
||||||
$emptyManialink = new ManiaLink(self::MLID_WIDGET);
|
|
||||||
$this->maniaControl->manialinkManager->sendManialink($emptyManialink);
|
|
||||||
|
|
||||||
unset($this->currentVote);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Shows the vote widget
|
|
||||||
*
|
|
||||||
* @param $timeUntilExpire
|
|
||||||
* @param $votePercentage
|
|
||||||
*/
|
|
||||||
private function showVoteWidget($timeUntilExpire, $votePercentage) {
|
|
||||||
$pos_x = $this->maniaControl->settingManager->getSetting($this, self::SETTING_WIDGET_POSX);
|
|
||||||
$pos_y = $this->maniaControl->settingManager->getSetting($this, self::SETTING_WIDGET_POSY);
|
|
||||||
$width = $this->maniaControl->settingManager->getSetting($this, self::SETTING_WIDGET_WIDTH);
|
|
||||||
$height = $this->maniaControl->settingManager->getSetting($this, self::SETTING_WIDGET_HEIGHT);
|
|
||||||
$maxTime = $this->maniaControl->settingManager->getSetting($this, self::SETTING_VOTE_TIME);
|
|
||||||
|
|
||||||
$quadStyle = $this->maniaControl->manialinkManager->styleManager->getDefaultQuadStyle();
|
|
||||||
$quadSubstyle = $this->maniaControl->manialinkManager->styleManager->getDefaultQuadSubstyle();
|
|
||||||
$labelStyle = $this->maniaControl->manialinkManager->styleManager->getDefaultLabelStyle();
|
|
||||||
|
|
||||||
$maniaLink = new ManiaLink(self::MLID_WIDGET);
|
|
||||||
|
|
||||||
// mainframe
|
|
||||||
$frame = new Frame();
|
|
||||||
$maniaLink->add($frame);
|
|
||||||
$frame->setSize($width, $height);
|
|
||||||
$frame->setPosition($pos_x, $pos_y, 30);
|
|
||||||
|
|
||||||
// Background Quad
|
|
||||||
$backgroundQuad = new Quad();
|
|
||||||
$frame->add($backgroundQuad);
|
|
||||||
$backgroundQuad->setSize($width, $height);
|
|
||||||
$backgroundQuad->setStyles($quadStyle, $quadSubstyle);
|
|
||||||
|
|
||||||
//Vote for label
|
|
||||||
$label = new Label_Text();
|
|
||||||
$frame->add($label);
|
|
||||||
$label->setY($height / 2 - 3);
|
|
||||||
$label->setAlign(Control::CENTER, Control::CENTER);
|
|
||||||
$label->setSize($width - 5, $height);
|
|
||||||
$label->setTextSize(1.3);
|
|
||||||
$label->setText('$s ' . $this->currentVote->voteCommand->name);
|
|
||||||
|
|
||||||
//Started by nick
|
|
||||||
$label = new Label_Text();
|
|
||||||
$frame->add($label);
|
|
||||||
$label->setY($height / 2 - 6);
|
|
||||||
$label->setAlign(Control::CENTER, Control::CENTER);
|
|
||||||
$label->setSize($width - 5, 2);
|
|
||||||
$label->setTextSize(1);
|
|
||||||
$label->setTextColor("F80");
|
|
||||||
$label->setText('$sStarted by ' . $this->currentVote->voter->nickname);
|
|
||||||
|
|
||||||
//Time Gauge
|
|
||||||
$timeGauge = new Gauge();
|
|
||||||
$frame->add($timeGauge);
|
|
||||||
$timeGauge->setY(1.5);
|
|
||||||
$timeGauge->setSize($width * 0.95, 6);
|
|
||||||
$timeGauge->setDrawBg(false);
|
|
||||||
if (!$timeUntilExpire) $timeUntilExpire = 1;
|
|
||||||
$timeGaugeRatio = (100 / $maxTime * $timeUntilExpire) / 100;
|
|
||||||
$timeGauge->setRatio($timeGaugeRatio + 0.15 - $timeGaugeRatio * 0.15);
|
|
||||||
$gaugeColor = ColorUtil::floatToStatusColor($timeGaugeRatio);
|
|
||||||
$timeGauge->setColor($gaugeColor . '9');
|
|
||||||
|
|
||||||
//Time Left
|
|
||||||
$label = new Label_Text();
|
|
||||||
$frame->add($label);
|
|
||||||
$label->setY(0);
|
|
||||||
$label->setAlign(Control::CENTER, Control::CENTER);
|
|
||||||
$label->setSize($width - 5, $height);
|
|
||||||
$label->setTextSize(1.1);
|
|
||||||
$label->setText('$sTime left: ' . $timeUntilExpire . "s");
|
|
||||||
$label->setTextColor("FFF");
|
|
||||||
|
|
||||||
//Vote Gauge
|
|
||||||
$voteGauge = new Gauge();
|
|
||||||
$frame->add($voteGauge);
|
|
||||||
$voteGauge->setY(-4);
|
|
||||||
$voteGauge->setSize($width * 0.65, 12);
|
|
||||||
$voteGauge->setDrawBg(false);
|
|
||||||
$voteGauge->setRatio($votePercentage + 0.10 - $votePercentage * 0.10);
|
|
||||||
$gaugeColor = ColorUtil::floatToStatusColor($votePercentage);
|
|
||||||
$voteGauge->setColor($gaugeColor . '6');
|
|
||||||
|
|
||||||
$y = -4.4;
|
|
||||||
$voteLabel = new Label();
|
|
||||||
$frame->add($voteLabel);
|
|
||||||
$voteLabel->setY($y);
|
|
||||||
$voteLabel->setSize($width * 0.65, 12);
|
|
||||||
$voteLabel->setStyle($labelStyle);
|
|
||||||
$voteLabel->setTextSize(1);
|
|
||||||
$voteLabel->setText(' ' . round($votePercentage * 100.) . '% (' . $this->currentVote->getVoteCount() . ')');
|
|
||||||
|
|
||||||
|
|
||||||
$positiveQuad = new Quad_BgsPlayerCard();
|
|
||||||
$frame->add($positiveQuad);
|
|
||||||
$positiveQuad->setPosition(-$width / 2 + 6, $y);
|
|
||||||
$positiveQuad->setSubStyle($positiveQuad::SUBSTYLE_BgPlayerCardBig);
|
|
||||||
$positiveQuad->setSize(5, 5);
|
|
||||||
|
|
||||||
$positiveLabel = new Label_Button();
|
|
||||||
$frame->add($positiveLabel);
|
|
||||||
$positiveLabel->setPosition(-$width / 2 + 6, $y);
|
|
||||||
$positiveLabel->setStyle($labelStyle);
|
|
||||||
$positiveLabel->setTextSize(1);
|
|
||||||
$positiveLabel->setSize(3, 3);
|
|
||||||
$positiveLabel->setTextColor("0F0");
|
|
||||||
$positiveLabel->setText("F1");
|
|
||||||
|
|
||||||
$negativeQuad = clone $positiveQuad;
|
|
||||||
$frame->add($negativeQuad);
|
|
||||||
$negativeQuad->setX($width / 2 - 6);
|
|
||||||
|
|
||||||
$negativeLabel = clone $positiveLabel;
|
|
||||||
$frame->add($negativeLabel);
|
|
||||||
$negativeLabel->setX($width / 2 - 6);
|
|
||||||
$negativeLabel->setTextColor("F00");
|
|
||||||
$negativeLabel->setText("F2");
|
|
||||||
|
|
||||||
// Voting Actions
|
|
||||||
$positiveQuad->addActionTriggerFeature(self::ACTION_POSITIVE_VOTE);
|
|
||||||
$negativeQuad->addActionTriggerFeature(self::ACTION_NEGATIVE_VOTE);
|
|
||||||
|
|
||||||
$script = $maniaLink->getScript();
|
|
||||||
$keyActionPositive = new KeyAction(self::ACTION_POSITIVE_VOTE, 'F1');
|
|
||||||
$script->addFeature($keyActionPositive);
|
|
||||||
$keyActionNegative = new KeyAction(self::ACTION_NEGATIVE_VOTE, 'F2');
|
|
||||||
$script->addFeature($keyActionNegative);
|
|
||||||
|
|
||||||
// Send manialink
|
|
||||||
$this->maniaControl->manialinkManager->sendManialink($maniaLink);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -741,50 +379,395 @@ class CustomVotesPlugin implements CommandListener, CallbackListener, ManialinkP
|
|||||||
$this->maniaControl->manialinkManager->sendManialink($maniaLink, $login);
|
$this->maniaControl->manialinkManager->sendManialink($maniaLink, $login);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get plugin id
|
* @see \ManiaControl\Plugins\Plugin::unload()
|
||||||
*
|
|
||||||
* @return int
|
|
||||||
*/
|
*/
|
||||||
public static function getId() {
|
public function unload() {
|
||||||
return self::PLUGIN_ID;
|
//Enable Standard Votes
|
||||||
|
$defaultRatio = $this->maniaControl->client->getCallVoteRatio();
|
||||||
|
|
||||||
|
$array["Command"] = VoteRatio::COMMAND_BAN;
|
||||||
|
$array["Param"] = "";
|
||||||
|
$array["Ratio"] = (float)$defaultRatio;
|
||||||
|
$ratioArray[] = $array;
|
||||||
|
$array["Command"] = VoteRatio::COMMAND_KICK;
|
||||||
|
$ratioArray[] = $array;
|
||||||
|
$array["Command"] = VoteRatio::COMMAND_RESTART_MAP;
|
||||||
|
$ratioArray[] = $array;
|
||||||
|
$array["Command"] = VoteRatio::COMMAND_TEAM_BALANCE;
|
||||||
|
$ratioArray[] = $array;
|
||||||
|
$array["Command"] = VoteRatio::COMMAND_NEXT_MAP;
|
||||||
|
$ratioArray[] = $array;
|
||||||
|
|
||||||
|
$this->maniaControl->client->setCallVoteRatiosEx(false, $ratioArray);
|
||||||
|
|
||||||
|
$this->destroyVote();
|
||||||
|
$this->maniaControl->manialinkManager->hideManialink(self::MLID_ICON);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get Plugin Name
|
* Destroys the current Vote
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
*/
|
||||||
public static function getName() {
|
private function destroyVote() {
|
||||||
return self::PLUGIN_NAME;
|
$emptyManialink = new ManiaLink(self::MLID_WIDGET);
|
||||||
|
$this->maniaControl->manialinkManager->sendManialink($emptyManialink);
|
||||||
|
|
||||||
|
unset($this->currentVote);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get Plugin Version
|
* Handle PlayerConnect callback
|
||||||
*
|
*
|
||||||
* @return float,,
|
* @param Player $player
|
||||||
*/
|
*/
|
||||||
public static function getVersion() {
|
public function handlePlayerConnect(Player $player) {
|
||||||
return self::PLUGIN_VERSION;
|
$this->showIcon($player->login);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get Plugin Author
|
* Chat Vote
|
||||||
*
|
*
|
||||||
* @return string
|
* @param array $chat
|
||||||
|
* @param Player $player
|
||||||
*/
|
*/
|
||||||
public static function getAuthor() {
|
public function chat_vote(array $chat, Player $player) {
|
||||||
return self::PLUGIN_AUTHOR;
|
$command = explode(" ", $chat[1][2]);
|
||||||
|
if (isset($command[1])) {
|
||||||
|
if (isset($this->voteCommands[$command[1]])) {
|
||||||
|
$this->startVote($player, strtolower($command[1]));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get Plugin Description
|
* Starts a vote
|
||||||
*
|
*
|
||||||
* @return string
|
* @param \ManiaControl\Players\Player $player
|
||||||
|
* @param $voteIndex
|
||||||
|
* @param $action
|
||||||
*/
|
*/
|
||||||
public static function getDescription() {
|
public function startVote(Player $player, $voteIndex, $function = null) {
|
||||||
return 'Plugin offers your Custom Votes like Restart, Skip, Balance...';
|
//Player is muted
|
||||||
|
if ($this->maniaControl->playerManager->playerActions->isPlayerMuted($player)) {
|
||||||
|
$this->maniaControl->chat->sendError('Muted Players are not allowed to start a vote.', $player->login);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Specators are not allowed to start a vote
|
||||||
|
if ($player->isSpectator && !$this->maniaControl->settingManager->getSetting($this, self::SETTING_SPECTATOR_ALLOW_START_VOTE)) {
|
||||||
|
$this->maniaControl->chat->sendError('Spectators are not allowed to start a vote.', $player->login);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Vote does not exist
|
||||||
|
if (!isset($this->voteCommands[$voteIndex])) {
|
||||||
|
$this->maniaControl->chat->sendError('Undefined vote.', $player->login);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//A vote is currently running
|
||||||
|
if (isset($this->currentVote)) {
|
||||||
|
$this->maniaControl->chat->sendError('There is currently another vote running.', $player->login);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$maxTime = $this->maniaControl->settingManager->getSetting($this, self::SETTING_VOTE_TIME);
|
||||||
|
|
||||||
|
$this->currentVote = $this->voteCommands[$voteIndex];
|
||||||
|
|
||||||
|
$this->currentVote = new CurrentVote($this->voteCommands[$voteIndex], $player, time() + $maxTime);
|
||||||
|
$this->currentVote->neededRatio = floatval($this->maniaControl->settingManager->getSetting($this, self::SETTING_DEFAULT_RATIO));
|
||||||
|
$this->currentVote->neededPlayerRatio = floatval($this->maniaControl->settingManager->getSetting($this, self::SETTING_DEFAULT_PLAYER_RATIO));
|
||||||
|
$this->currentVote->function = $function;
|
||||||
|
|
||||||
|
if ($this->currentVote->voteCommand->startText != '') {
|
||||||
|
$message = $this->currentVote->voteCommand->startText;
|
||||||
|
} else {
|
||||||
|
$message = '$fff$<' . $player->nickname . '$>$s$f8f started a $fff$<' . $this->currentVote->voteCommand->name . '$>$f8f!';
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->maniaControl->chat->sendSuccess($message);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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
|
||||||
|
*
|
||||||
|
* @param array $callback
|
||||||
|
* @param Player $player
|
||||||
|
*/
|
||||||
|
public function handlePositiveVote(array $callback, Player $player) {
|
||||||
|
if (!isset($this->currentVote) || $player->isSpectator && !$this->maniaControl->settingManager->getSetting($this, self::SETTING_SPECTATOR_ALLOW_VOTE)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->currentVote->votePositive($player->login);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handles a negative Vote
|
||||||
|
*
|
||||||
|
* @param array $callback
|
||||||
|
* @param Player $player
|
||||||
|
*/
|
||||||
|
public function handleNegativeVote(array $callback, Player $player) {
|
||||||
|
if (!isset($this->currentVote) || $player->isSpectator && !$this->maniaControl->settingManager->getSetting($this, self::SETTING_SPECTATOR_ALLOW_VOTE)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->currentVote->voteNegative($player->login);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle ManiaControl 1 Second callback
|
||||||
|
*
|
||||||
|
* @param $time
|
||||||
|
*/
|
||||||
|
public function handle1Second($time) {
|
||||||
|
if (!isset($this->currentVote)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$votePercentage = $this->currentVote->positiveVotes / $this->currentVote->getVoteCount();
|
||||||
|
|
||||||
|
$timeUntilExpire = $this->currentVote->expireTime - time();
|
||||||
|
$this->showVoteWidget($timeUntilExpire, $votePercentage);
|
||||||
|
|
||||||
|
$playerCount = $this->maniaControl->playerManager->getPlayerCount();
|
||||||
|
$playersVoteRatio = (100 / $playerCount * $this->currentVote->getVoteCount()) / 100;
|
||||||
|
|
||||||
|
//Check if vote is over
|
||||||
|
if ($timeUntilExpire <= 0 || (($playersVoteRatio >= $this->currentVote->neededPlayerRatio) && (($votePercentage >= $this->currentVote->neededRatio) || ($votePercentage <= 1 - $this->currentVote->neededRatio)))) {
|
||||||
|
// Trigger callback
|
||||||
|
$this->maniaControl->callbackManager->triggerCallback(self::CB_CUSTOM_VOTE_FINISHED, $this->currentVote->voteCommand->index, $votePercentage);
|
||||||
|
|
||||||
|
//reset vote
|
||||||
|
$this->destroyVote();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Shows the vote widget
|
||||||
|
*
|
||||||
|
* @param $timeUntilExpire
|
||||||
|
* @param $votePercentage
|
||||||
|
*/
|
||||||
|
private function showVoteWidget($timeUntilExpire, $votePercentage) {
|
||||||
|
$pos_x = $this->maniaControl->settingManager->getSetting($this, self::SETTING_WIDGET_POSX);
|
||||||
|
$pos_y = $this->maniaControl->settingManager->getSetting($this, self::SETTING_WIDGET_POSY);
|
||||||
|
$width = $this->maniaControl->settingManager->getSetting($this, self::SETTING_WIDGET_WIDTH);
|
||||||
|
$height = $this->maniaControl->settingManager->getSetting($this, self::SETTING_WIDGET_HEIGHT);
|
||||||
|
$maxTime = $this->maniaControl->settingManager->getSetting($this, self::SETTING_VOTE_TIME);
|
||||||
|
|
||||||
|
$quadStyle = $this->maniaControl->manialinkManager->styleManager->getDefaultQuadStyle();
|
||||||
|
$quadSubstyle = $this->maniaControl->manialinkManager->styleManager->getDefaultQuadSubstyle();
|
||||||
|
$labelStyle = $this->maniaControl->manialinkManager->styleManager->getDefaultLabelStyle();
|
||||||
|
|
||||||
|
$maniaLink = new ManiaLink(self::MLID_WIDGET);
|
||||||
|
|
||||||
|
// mainframe
|
||||||
|
$frame = new Frame();
|
||||||
|
$maniaLink->add($frame);
|
||||||
|
$frame->setSize($width, $height);
|
||||||
|
$frame->setPosition($pos_x, $pos_y, 30);
|
||||||
|
|
||||||
|
// Background Quad
|
||||||
|
$backgroundQuad = new Quad();
|
||||||
|
$frame->add($backgroundQuad);
|
||||||
|
$backgroundQuad->setSize($width, $height);
|
||||||
|
$backgroundQuad->setStyles($quadStyle, $quadSubstyle);
|
||||||
|
|
||||||
|
//Vote for label
|
||||||
|
$label = new Label_Text();
|
||||||
|
$frame->add($label);
|
||||||
|
$label->setY($height / 2 - 3);
|
||||||
|
$label->setAlign(Control::CENTER, Control::CENTER);
|
||||||
|
$label->setSize($width - 5, $height);
|
||||||
|
$label->setTextSize(1.3);
|
||||||
|
$label->setText('$s ' . $this->currentVote->voteCommand->name);
|
||||||
|
|
||||||
|
//Started by nick
|
||||||
|
$label = new Label_Text();
|
||||||
|
$frame->add($label);
|
||||||
|
$label->setY($height / 2 - 6);
|
||||||
|
$label->setAlign(Control::CENTER, Control::CENTER);
|
||||||
|
$label->setSize($width - 5, 2);
|
||||||
|
$label->setTextSize(1);
|
||||||
|
$label->setTextColor("F80");
|
||||||
|
$label->setText('$sStarted by ' . $this->currentVote->voter->nickname);
|
||||||
|
|
||||||
|
//Time Gauge
|
||||||
|
$timeGauge = new Gauge();
|
||||||
|
$frame->add($timeGauge);
|
||||||
|
$timeGauge->setY(1.5);
|
||||||
|
$timeGauge->setSize($width * 0.95, 6);
|
||||||
|
$timeGauge->setDrawBg(false);
|
||||||
|
if (!$timeUntilExpire) {
|
||||||
|
$timeUntilExpire = 1;
|
||||||
|
}
|
||||||
|
$timeGaugeRatio = (100 / $maxTime * $timeUntilExpire) / 100;
|
||||||
|
$timeGauge->setRatio($timeGaugeRatio + 0.15 - $timeGaugeRatio * 0.15);
|
||||||
|
$gaugeColor = ColorUtil::floatToStatusColor($timeGaugeRatio);
|
||||||
|
$timeGauge->setColor($gaugeColor . '9');
|
||||||
|
|
||||||
|
//Time Left
|
||||||
|
$label = new Label_Text();
|
||||||
|
$frame->add($label);
|
||||||
|
$label->setY(0);
|
||||||
|
$label->setAlign(Control::CENTER, Control::CENTER);
|
||||||
|
$label->setSize($width - 5, $height);
|
||||||
|
$label->setTextSize(1.1);
|
||||||
|
$label->setText('$sTime left: ' . $timeUntilExpire . "s");
|
||||||
|
$label->setTextColor("FFF");
|
||||||
|
|
||||||
|
//Vote Gauge
|
||||||
|
$voteGauge = new Gauge();
|
||||||
|
$frame->add($voteGauge);
|
||||||
|
$voteGauge->setY(-4);
|
||||||
|
$voteGauge->setSize($width * 0.65, 12);
|
||||||
|
$voteGauge->setDrawBg(false);
|
||||||
|
$voteGauge->setRatio($votePercentage + 0.10 - $votePercentage * 0.10);
|
||||||
|
$gaugeColor = ColorUtil::floatToStatusColor($votePercentage);
|
||||||
|
$voteGauge->setColor($gaugeColor . '6');
|
||||||
|
|
||||||
|
$y = -4.4;
|
||||||
|
$voteLabel = new Label();
|
||||||
|
$frame->add($voteLabel);
|
||||||
|
$voteLabel->setY($y);
|
||||||
|
$voteLabel->setSize($width * 0.65, 12);
|
||||||
|
$voteLabel->setStyle($labelStyle);
|
||||||
|
$voteLabel->setTextSize(1);
|
||||||
|
$voteLabel->setText(' ' . round($votePercentage * 100.) . '% (' . $this->currentVote->getVoteCount() . ')');
|
||||||
|
|
||||||
|
|
||||||
|
$positiveQuad = new Quad_BgsPlayerCard();
|
||||||
|
$frame->add($positiveQuad);
|
||||||
|
$positiveQuad->setPosition(-$width / 2 + 6, $y);
|
||||||
|
$positiveQuad->setSubStyle($positiveQuad::SUBSTYLE_BgPlayerCardBig);
|
||||||
|
$positiveQuad->setSize(5, 5);
|
||||||
|
|
||||||
|
$positiveLabel = new Label_Button();
|
||||||
|
$frame->add($positiveLabel);
|
||||||
|
$positiveLabel->setPosition(-$width / 2 + 6, $y);
|
||||||
|
$positiveLabel->setStyle($labelStyle);
|
||||||
|
$positiveLabel->setTextSize(1);
|
||||||
|
$positiveLabel->setSize(3, 3);
|
||||||
|
$positiveLabel->setTextColor("0F0");
|
||||||
|
$positiveLabel->setText("F1");
|
||||||
|
|
||||||
|
$negativeQuad = clone $positiveQuad;
|
||||||
|
$frame->add($negativeQuad);
|
||||||
|
$negativeQuad->setX($width / 2 - 6);
|
||||||
|
|
||||||
|
$negativeLabel = clone $positiveLabel;
|
||||||
|
$frame->add($negativeLabel);
|
||||||
|
$negativeLabel->setX($width / 2 - 6);
|
||||||
|
$negativeLabel->setTextColor("F00");
|
||||||
|
$negativeLabel->setText("F2");
|
||||||
|
|
||||||
|
// Voting Actions
|
||||||
|
$positiveQuad->addActionTriggerFeature(self::ACTION_POSITIVE_VOTE);
|
||||||
|
$negativeQuad->addActionTriggerFeature(self::ACTION_NEGATIVE_VOTE);
|
||||||
|
|
||||||
|
$script = $maniaLink->getScript();
|
||||||
|
$keyActionPositive = new KeyAction(self::ACTION_POSITIVE_VOTE, 'F1');
|
||||||
|
$script->addFeature($keyActionPositive);
|
||||||
|
$keyActionNegative = new KeyAction(self::ACTION_NEGATIVE_VOTE, 'F2');
|
||||||
|
$script->addFeature($keyActionNegative);
|
||||||
|
|
||||||
|
// Send manialink
|
||||||
|
$this->maniaControl->manialinkManager->sendManialink($maniaLink);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12,7 +12,6 @@ use FML\Controls\Quads\Quad_BgsPlayerCard;
|
|||||||
use FML\Controls\Quads\Quad_Icons128x128_1;
|
use FML\Controls\Quads\Quad_Icons128x128_1;
|
||||||
use FML\ManiaLink;
|
use FML\ManiaLink;
|
||||||
use FML\Script\Features\Paging;
|
use FML\Script\Features\Paging;
|
||||||
|
|
||||||
use ManiaControl\Admin\AuthenticationManager;
|
use ManiaControl\Admin\AuthenticationManager;
|
||||||
use ManiaControl\Bills\BillManager;
|
use ManiaControl\Bills\BillManager;
|
||||||
use ManiaControl\Callbacks\CallbackListener;
|
use ManiaControl\Callbacks\CallbackListener;
|
||||||
@ -23,21 +22,22 @@ use ManiaControl\Manialinks\ManialinkManager;
|
|||||||
use ManiaControl\Players\Player;
|
use ManiaControl\Players\Player;
|
||||||
use ManiaControl\Players\PlayerManager;
|
use ManiaControl\Players\PlayerManager;
|
||||||
use ManiaControl\Plugins\Plugin;
|
use ManiaControl\Plugins\Plugin;
|
||||||
use ManiaControl\Statistics\StatisticManager;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ManiaControl Donation Plugin
|
* ManiaControl Donation Plugin
|
||||||
*
|
*
|
||||||
* @author kremsy and steeffeen
|
* @author ManiaControl Team <mail@maniacontrol.com>
|
||||||
* @copyright ManiaControl Copyright © 2014 ManiaControl Team
|
* @copyright 2014 ManiaControl Team
|
||||||
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
||||||
*/
|
*/
|
||||||
class DonationPlugin implements CallbackListener, CommandListener, Plugin {
|
class DonationPlugin implements CallbackListener, CommandListener, Plugin {
|
||||||
/**
|
/*
|
||||||
* Constants
|
* Constants
|
||||||
*/
|
*/
|
||||||
const ID = 3;
|
const ID = 3;
|
||||||
const VERSION = 0.1;
|
const VERSION = 0.1;
|
||||||
|
const AUTHOR = 'MCTeam';
|
||||||
|
const NAME = 'Donation Plugin';
|
||||||
const SETTING_ANNOUNCE_SERVERDONATION = 'Enable Server-Donation Announcements';
|
const SETTING_ANNOUNCE_SERVERDONATION = 'Enable Server-Donation Announcements';
|
||||||
const STAT_PLAYER_DONATIONS = 'Donated Planets';
|
const STAT_PLAYER_DONATIONS = 'Donated Planets';
|
||||||
const ACTION_DONATE_VALUE = 'Donate.DonateValue';
|
const ACTION_DONATE_VALUE = 'Donate.DonateValue';
|
||||||
@ -52,8 +52,8 @@ class DonationPlugin implements CallbackListener, CommandListener, Plugin {
|
|||||||
const SETTING_DONATION_VALUES = 'Donation Values';
|
const SETTING_DONATION_VALUES = 'Donation Values';
|
||||||
const SETTING_MIN_AMOUNT_SHOWN = 'Minimum Donation amount to get shown';
|
const SETTING_MIN_AMOUNT_SHOWN = 'Minimum Donation amount to get shown';
|
||||||
|
|
||||||
/**
|
/*
|
||||||
* Private properties
|
* Private Properties
|
||||||
*/
|
*/
|
||||||
/**
|
/**
|
||||||
* @var maniaControl $maniaControl
|
* @var maniaControl $maniaControl
|
||||||
@ -61,15 +61,45 @@ class DonationPlugin implements CallbackListener, CommandListener, Plugin {
|
|||||||
private $maniaControl = null;
|
private $maniaControl = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Prepares the Plugin
|
* @see \ManiaControl\Plugins\Plugin::prepare()
|
||||||
*
|
|
||||||
* @param ManiaControl $maniaControl
|
|
||||||
* @return mixed
|
|
||||||
*/
|
*/
|
||||||
public static function prepare(ManiaControl $maniaControl) {
|
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()
|
* @see \ManiaControl\Plugins\Plugin::load()
|
||||||
@ -105,48 +135,6 @@ class DonationPlugin implements CallbackListener, CommandListener, Plugin {
|
|||||||
return true;
|
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
|
* 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
|
* Displays the Donate Widget
|
||||||
*
|
*
|
||||||
@ -287,34 +246,27 @@ class DonationPlugin implements CallbackListener, CommandListener, Plugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handle /donate command
|
* @see \ManiaControl\Plugins\Plugin::unload()
|
||||||
*
|
|
||||||
* @param array $chatCallback
|
|
||||||
* @param Player $player
|
|
||||||
* @return bool
|
|
||||||
*/
|
*/
|
||||||
public function command_Donate(array $chatCallback, Player $player) {
|
public function unload() {
|
||||||
$text = $chatCallback[1][2];
|
$this->maniaControl->manialinkManager->hideManialink(self::MLID_DONATE_WIDGET);
|
||||||
$params = explode(' ', $text);
|
|
||||||
if (count($params) < 2) {
|
|
||||||
$this->sendDonateUsageExample($player);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
$amount = (int)$params[1];
|
|
||||||
if (!$amount || $amount <= 0) {
|
|
||||||
$this->sendDonateUsageExample($player);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (count($params) >= 3) {
|
|
||||||
$receiver = $params[2];
|
|
||||||
$receiverPlayer = $this->maniaControl->playerManager->getPlayer($receiver);
|
|
||||||
$receiverName = ($receiverPlayer ? $receiverPlayer->nickname : $receiver);
|
|
||||||
} else {
|
|
||||||
$receiver = '';
|
|
||||||
$receiverName = $this->maniaControl->client->getServerName();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->handleDonation($player, $amount, $receiver, $receiverName);
|
/**
|
||||||
|
* 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]));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -365,6 +317,60 @@ class DonationPlugin implements CallbackListener, CommandListener, Plugin {
|
|||||||
return true;
|
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
|
||||||
|
*
|
||||||
|
* @param array $chatCallback
|
||||||
|
* @param Player $player
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function command_Donate(array $chatCallback, Player $player) {
|
||||||
|
$text = $chatCallback[1][2];
|
||||||
|
$params = explode(' ', $text);
|
||||||
|
if (count($params) < 2) {
|
||||||
|
$this->sendDonateUsageExample($player);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
$amount = (int)$params[1];
|
||||||
|
if (!$amount || $amount <= 0) {
|
||||||
|
$this->sendDonateUsageExample($player);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (count($params) >= 3) {
|
||||||
|
$receiver = $params[2];
|
||||||
|
$receiverPlayer = $this->maniaControl->playerManager->getPlayer($receiver);
|
||||||
|
$receiverName = ($receiverPlayer ? $receiverPlayer->nickname : $receiver);
|
||||||
|
} else {
|
||||||
|
$receiver = '';
|
||||||
|
$receiverName = $this->maniaControl->client->getServerName();
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->handleDonation($player, $amount, $receiver, $receiverName);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handle //pay command
|
* Handle //pay command
|
||||||
*
|
*
|
||||||
@ -416,6 +422,17 @@ class DonationPlugin implements CallbackListener, CommandListener, Plugin {
|
|||||||
return true;
|
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
|
* Handle //getplanets command
|
||||||
*
|
*
|
||||||
@ -433,28 +450,6 @@ class DonationPlugin implements CallbackListener, CommandListener, Plugin {
|
|||||||
return $this->maniaControl->chat->sendInformation($message, $player->login);
|
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
|
* Handles the /topdons command
|
||||||
*
|
*
|
||||||
|
@ -32,6 +32,8 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
|
|||||||
*/
|
*/
|
||||||
const ID = 2;
|
const ID = 2;
|
||||||
const VERSION = 0.1;
|
const VERSION = 0.1;
|
||||||
|
const NAME = 'Karma Plugin';
|
||||||
|
const AUTHOR = 'MCTeam';
|
||||||
const MLID_KARMA = 'KarmaPlugin.MLID';
|
const MLID_KARMA = 'KarmaPlugin.MLID';
|
||||||
const TABLE_KARMA = 'mc_karma';
|
const TABLE_KARMA = 'mc_karma';
|
||||||
const CB_KARMA_CHANGED = 'KarmaPlugin.Changed';
|
const CB_KARMA_CHANGED = 'KarmaPlugin.Changed';
|
||||||
@ -62,19 +64,15 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
|
|||||||
/*
|
/*
|
||||||
* Private Properties
|
* Private Properties
|
||||||
*/
|
*/
|
||||||
/**
|
/** @var ManiaControl $maniaControl */
|
||||||
* @var ManiaControl $maniaControl
|
|
||||||
*/
|
|
||||||
private $maniaControl = null;
|
private $maniaControl = null;
|
||||||
private $updateManialink = false;
|
private $updateManialink = false;
|
||||||
/**
|
/** @var ManiaLink $manialink */
|
||||||
* @var ManiaLink $manialink
|
|
||||||
*/
|
|
||||||
private $manialink = null;
|
private $manialink = null;
|
||||||
private $mxKarma = array();
|
private $mxKarma = array();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see \ManiaControl\Plugins\Plugin
|
* @see \ManiaControl\Plugins\Plugin::prepare()
|
||||||
*/
|
*/
|
||||||
public static function prepare(ManiaControl $maniaControl) {
|
public static function prepare(ManiaControl $maniaControl) {
|
||||||
$maniaControl->settingManager->initSetting(get_class(), self::SETTING_MX_KARMA_ACTIVATED, true);
|
$maniaControl->settingManager->initSetting(get_class(), self::SETTING_MX_KARMA_ACTIVATED, true);
|
||||||
@ -97,7 +95,7 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
|
|||||||
* @see \ManiaControl\Plugins\Plugin::getName()
|
* @see \ManiaControl\Plugins\Plugin::getName()
|
||||||
*/
|
*/
|
||||||
public static function 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()
|
* @see \ManiaControl\Plugins\Plugin::getAuthor()
|
||||||
*/
|
*/
|
||||||
public static function getAuthor() {
|
public static function getAuthor() {
|
||||||
return 'steeffeen and kremsy';
|
return self::AUTHOR;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -15,21 +15,20 @@ use ManiaControl\Callbacks\CallbackManager;
|
|||||||
use ManiaControl\Callbacks\Callbacks;
|
use ManiaControl\Callbacks\Callbacks;
|
||||||
use ManiaControl\Callbacks\TimerListener;
|
use ManiaControl\Callbacks\TimerListener;
|
||||||
use ManiaControl\Commands\CommandListener;
|
use ManiaControl\Commands\CommandListener;
|
||||||
use ManiaControl\Settings\SettingManager;
|
|
||||||
use ManiaControl\Formatter;
|
use ManiaControl\Formatter;
|
||||||
use ManiaControl\ManiaControl;
|
use ManiaControl\ManiaControl;
|
||||||
use ManiaControl\Maps\Map;
|
|
||||||
use ManiaControl\Maps\MapManager;
|
|
||||||
use ManiaControl\Manialinks\ManialinkManager;
|
use ManiaControl\Manialinks\ManialinkManager;
|
||||||
|
use ManiaControl\Maps\Map;
|
||||||
use ManiaControl\Players\Player;
|
use ManiaControl\Players\Player;
|
||||||
use ManiaControl\Players\PlayerManager;
|
use ManiaControl\Players\PlayerManager;
|
||||||
use ManiaControl\Plugins\Plugin;
|
use ManiaControl\Plugins\Plugin;
|
||||||
|
use ManiaControl\Settings\SettingManager;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ManiaControl Local Records Plugin
|
* ManiaControl Local Records Plugin
|
||||||
*
|
*
|
||||||
* @author steeffeen
|
* @author ManiaControl Team <mail@maniacontrol.com>
|
||||||
* @copyright ManiaControl Copyright © 2014 ManiaControl Team
|
* @copyright 2014 ManiaControl Team
|
||||||
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
||||||
*/
|
*/
|
||||||
class LocalRecordsPlugin implements CallbackListener, CommandListener, TimerListener, Plugin {
|
class LocalRecordsPlugin implements CallbackListener, CommandListener, TimerListener, Plugin {
|
||||||
@ -38,6 +37,8 @@ class LocalRecordsPlugin implements CallbackListener, CommandListener, TimerList
|
|||||||
*/
|
*/
|
||||||
const ID = 7;
|
const ID = 7;
|
||||||
const VERSION = 0.2;
|
const VERSION = 0.2;
|
||||||
|
const NAME = 'Local Records Plugin';
|
||||||
|
const AUTHOR = 'MCTeam';
|
||||||
const MLID_RECORDS = 'ml_local_records';
|
const MLID_RECORDS = 'ml_local_records';
|
||||||
const TABLE_RECORDS = 'mc_localrecords';
|
const TABLE_RECORDS = 'mc_localrecords';
|
||||||
const SETTING_WIDGET_TITLE = 'Widget Title';
|
const SETTING_WIDGET_TITLE = 'Widget Title';
|
||||||
@ -56,26 +57,53 @@ class LocalRecordsPlugin implements CallbackListener, CommandListener, TimerList
|
|||||||
/*
|
/*
|
||||||
* Private Properties
|
* Private Properties
|
||||||
*/
|
*/
|
||||||
/**
|
/** @var ManiaControl $maniaControl */
|
||||||
*
|
|
||||||
* @var maniaControl $maniaControl
|
|
||||||
*/
|
|
||||||
private $maniaControl = null;
|
private $maniaControl = null;
|
||||||
private $updateManialink = false;
|
private $updateManialink = false;
|
||||||
private $checkpoints = array();
|
private $checkpoints = array();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Prepares the Plugin
|
* @see \ManiaControl\Plugins\Plugin::prepare()
|
||||||
*
|
|
||||||
* @param ManiaControl $maniaControl
|
|
||||||
* @return mixed
|
|
||||||
*/
|
*/
|
||||||
public static function prepare(ManiaControl $maniaControl) {
|
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()
|
* @see \ManiaControl\Plugins\Plugin::load()
|
||||||
*/
|
*/
|
||||||
public function load(ManiaControl $maniaControl) {
|
public function load(ManiaControl $maniaControl) {
|
||||||
@ -111,13 +139,6 @@ class LocalRecordsPlugin implements CallbackListener, CommandListener, TimerList
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @see \ManiaControl\Plugins\Plugin::unload()
|
|
||||||
*/
|
|
||||||
public function unload() {
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialize needed database tables
|
* Initialize needed database tables
|
||||||
*/
|
*/
|
||||||
@ -146,43 +167,9 @@ class LocalRecordsPlugin implements CallbackListener, CommandListener, TimerList
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* @see \ManiaControl\Plugins\Plugin::unload()
|
||||||
* @see \ManiaControl\Plugins\Plugin::getId()
|
|
||||||
*/
|
*/
|
||||||
public static function getId() {
|
public function unload() {
|
||||||
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.';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -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
|
* Build the local records manialink
|
||||||
*
|
*
|
||||||
@ -632,6 +324,145 @@ class LocalRecordsPlugin implements CallbackListener, CommandListener, TimerList
|
|||||||
return $records;
|
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
|
* Retrieve the local record for the given map and login
|
||||||
*
|
*
|
||||||
@ -655,4 +486,167 @@ class LocalRecordsPlugin implements CallbackListener, CommandListener, TimerList
|
|||||||
$result->free();
|
$result->free();
|
||||||
return $record;
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,13 +6,12 @@ use FML\Controls\Frame;
|
|||||||
use FML\Controls\Quads\Quad_BgsPlayerCard;
|
use FML\Controls\Quads\Quad_BgsPlayerCard;
|
||||||
use FML\ManiaLink;
|
use FML\ManiaLink;
|
||||||
use FML\Script\Features\Paging;
|
use FML\Script\Features\Paging;
|
||||||
|
|
||||||
use ManiaControl\Callbacks\CallbackListener;
|
use ManiaControl\Callbacks\CallbackListener;
|
||||||
use ManiaControl\Callbacks\Callbacks;
|
use ManiaControl\Callbacks\Callbacks;
|
||||||
use ManiaControl\Commands\CommandListener;
|
use ManiaControl\Commands\CommandListener;
|
||||||
use ManiaControl\ManiaControl;
|
use ManiaControl\ManiaControl;
|
||||||
use ManiaControl\Maps\Map;
|
|
||||||
use ManiaControl\Manialinks\ManialinkManager;
|
use ManiaControl\Manialinks\ManialinkManager;
|
||||||
|
use ManiaControl\Maps\Map;
|
||||||
use ManiaControl\Players\Player;
|
use ManiaControl\Players\Player;
|
||||||
use ManiaControl\Players\PlayerManager;
|
use ManiaControl\Players\PlayerManager;
|
||||||
use ManiaControl\Plugins\Plugin;
|
use ManiaControl\Plugins\Plugin;
|
||||||
@ -23,8 +22,8 @@ use Maniaplanet\DedicatedServer\Structures\AbstractStructure;
|
|||||||
/**
|
/**
|
||||||
* ManiaControl ServerRanking Plugin
|
* ManiaControl ServerRanking Plugin
|
||||||
*
|
*
|
||||||
* @author kremsy
|
* @author ManiaControl Team <mail@maniacontrol.com>
|
||||||
* @copyright ManiaControl Copyright © 2014 ManiaControl Team
|
* @copyright 2014 ManiaControl Team
|
||||||
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
||||||
*/
|
*/
|
||||||
class ServerRankingPlugin implements Plugin, CallbackListener, CommandListener {
|
class ServerRankingPlugin implements Plugin, CallbackListener, CommandListener {
|
||||||
@ -34,7 +33,7 @@ class ServerRankingPlugin implements Plugin, CallbackListener, CommandListener {
|
|||||||
const PLUGIN_ID = 6;
|
const PLUGIN_ID = 6;
|
||||||
const PLUGIN_VERSION = 0.1;
|
const PLUGIN_VERSION = 0.1;
|
||||||
const PLUGIN_NAME = 'Server Ranking Plugin';
|
const PLUGIN_NAME = 'Server Ranking Plugin';
|
||||||
const PLUGIN_AUTHOR = 'kremsy';
|
const PLUGIN_AUTHOR = 'MCTeam';
|
||||||
const TABLE_RANK = 'mc_rank';
|
const TABLE_RANK = 'mc_rank';
|
||||||
const RANKING_TYPE_RECORDS = 'Records';
|
const RANKING_TYPE_RECORDS = 'Records';
|
||||||
const RANKING_TYPE_RATIOS = 'Ratios';
|
const RANKING_TYPE_RATIOS = 'Ratios';
|
||||||
@ -49,26 +48,53 @@ class ServerRankingPlugin implements Plugin, CallbackListener, CommandListener {
|
|||||||
/**
|
/**
|
||||||
* Private Properties
|
* Private Properties
|
||||||
*/
|
*/
|
||||||
/** @var maniaControl $maniaControl * */
|
/** @var ManiaControl $maniaControl * */
|
||||||
private $maniaControl = null;
|
private $maniaControl = null;
|
||||||
private $recordCount = 0;
|
private $recordCount = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Prepares the Plugin
|
* @see \ManiaControl\Plugins\Plugin::prepare()
|
||||||
*
|
|
||||||
* @param ManiaControl $maniaControl
|
|
||||||
* @return mixed
|
|
||||||
*/
|
*/
|
||||||
public static function prepare(ManiaControl $maniaControl) {
|
public static function prepare(ManiaControl $maniaControl) {
|
||||||
//Todo
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Load the plugin
|
* @see \ManiaControl\Plugins\Plugin::getId()
|
||||||
*
|
*/
|
||||||
* @param \ManiaControl\ManiaControl $maniaControl
|
public static function getId() {
|
||||||
* @throws Exception
|
return self::PLUGIN_ID;
|
||||||
* @return bool
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @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) {
|
public function load(ManiaControl $maniaControl) {
|
||||||
$this->maniaControl = $maniaControl;
|
$this->maniaControl = $maniaControl;
|
||||||
@ -111,57 +137,6 @@ class ServerRankingPlugin implements Plugin, CallbackListener, CommandListener {
|
|||||||
$this->resetRanks(); //TODO only update records count
|
$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
|
* Create necessary database tables
|
||||||
*/
|
*/
|
||||||
@ -287,6 +262,12 @@ class ServerRankingPlugin implements Plugin, CallbackListener, CommandListener {
|
|||||||
$mysqli->query($query);
|
$mysqli->query($query);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see \ManiaControl\Plugins\Plugin::unload()
|
||||||
|
*/
|
||||||
|
public function unload() {
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handle PlayerConnect callback
|
* Handle PlayerConnect callback
|
||||||
*
|
*
|
||||||
@ -297,27 +278,6 @@ class ServerRankingPlugin implements Plugin, CallbackListener, CommandListener {
|
|||||||
$this->showNextRank($player);
|
$this->showNextRank($player);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Shows Ranks on endMap
|
|
||||||
*
|
|
||||||
* @param Map $map
|
|
||||||
*/
|
|
||||||
public function handleEndMap(Map $map) {
|
|
||||||
$this->resetRanks();
|
|
||||||
|
|
||||||
foreach($this->maniaControl->playerManager->getPlayers() as $player) {
|
|
||||||
/** @var Player $player */
|
|
||||||
if ($player->isFakePlayer()) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
$this->showRank($player);
|
|
||||||
$this->showNextRank($player);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Trigger callback
|
|
||||||
$this->maniaControl->callbackManager->triggerCallback(self::CB_RANK_BUILT);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Shows the serverRank to a certain Player
|
* Shows the serverRank to a certain Player
|
||||||
*
|
*
|
||||||
@ -385,6 +345,29 @@ class ServerRankingPlugin implements Plugin, CallbackListener, CommandListener {
|
|||||||
return Rank::fromArray($row);
|
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
|
* 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
|
* 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
|
* Handles /topranks|top100 command
|
||||||
*
|
*
|
||||||
|
@ -29,8 +29,7 @@ use ManiaControl\Plugins\Plugin;
|
|||||||
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
||||||
*/
|
*/
|
||||||
class WidgetPlugin implements CallbackListener, TimerListener, Plugin {
|
class WidgetPlugin implements CallbackListener, TimerListener, Plugin {
|
||||||
|
/*
|
||||||
/**
|
|
||||||
* Constants
|
* Constants
|
||||||
*/
|
*/
|
||||||
const PLUGIN_ID = 1;
|
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_WIDTH = 'ServerInfo-Widget-Size: Width';
|
||||||
const SETTING_SERVERINFO_WIDGET_HEIGHT = 'ServerInfo-Widget-Size: Height';
|
const SETTING_SERVERINFO_WIDGET_HEIGHT = 'ServerInfo-Widget-Size: Height';
|
||||||
|
|
||||||
/**
|
/*
|
||||||
* Private Properties
|
* Private Properties
|
||||||
*/
|
*/
|
||||||
/**
|
/** @var ManiaControl $maniaControl */
|
||||||
* @var maniaControl $maniaControl
|
|
||||||
*/
|
|
||||||
private $maniaControl = null;
|
private $maniaControl = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Prepares the Plugin
|
* @see \ManiaControl\Plugins\Plugin::prepare()
|
||||||
*
|
|
||||||
* @param ManiaControl $maniaControl
|
|
||||||
* @return mixed
|
|
||||||
*/
|
*/
|
||||||
public static function prepare(ManiaControl $maniaControl) {
|
public static function prepare(ManiaControl $maniaControl) {
|
||||||
//do nothing
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get plugin id
|
* @see \ManiaControl\Plugins\Plugin::getId()
|
||||||
*
|
|
||||||
* @return int
|
|
||||||
*/
|
*/
|
||||||
public static function getId() {
|
public static function getId() {
|
||||||
return self::PLUGIN_ID;
|
return self::PLUGIN_ID;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get Plugin Name
|
* @see \ManiaControl\Plugins\Plugin::getName()
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
*/
|
||||||
public static function getName() {
|
public static function getName() {
|
||||||
return self::PLUGIN_NAME;
|
return self::PLUGIN_NAME;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get Plugin Version
|
* @see \ManiaControl\Plugins\Plugin::getVersion()
|
||||||
*
|
|
||||||
* @return float,,
|
|
||||||
*/
|
*/
|
||||||
public static function getVersion() {
|
public static function getVersion() {
|
||||||
return self::PLUGIN_VERSION;
|
return self::PLUGIN_VERSION;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get Plugin Author
|
* @see \ManiaControl\Plugins\Plugin::getAuthor()
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
*/
|
||||||
public static function getAuthor() {
|
public static function getAuthor() {
|
||||||
return self::PLUGIN_AUTHOR;
|
return self::PLUGIN_AUTHOR;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get Plugin Description
|
* @see \ManiaControl\Plugins\Plugin::getDescription()
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
*/
|
||||||
public static function getDescription() {
|
public static function getDescription() {
|
||||||
return 'Plugin offers some Widgets';
|
return 'Plugin offers some Widgets';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Load the plugin
|
* @see \ManiaControl\Plugins\Plugin::load()
|
||||||
*
|
|
||||||
* @param ManiaControl $maniaControl
|
|
||||||
* @return bool
|
|
||||||
*/
|
*/
|
||||||
public function load(ManiaControl $maniaControl) {
|
public function load(ManiaControl $maniaControl) {
|
||||||
$this->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() {
|
public function unload() {
|
||||||
//Restore Siege Progression Layer
|
//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) {
|
public function closeWidget($widgetId) {
|
||||||
$emptyManialink = new ManiaLink($widgetId);
|
$emptyManialink = new ManiaLink($widgetId);
|
||||||
|
@ -2,13 +2,12 @@
|
|||||||
|
|
||||||
namespace steeffeen;
|
namespace steeffeen;
|
||||||
|
|
||||||
use ManiaControl\Callbacks\Callbacks;
|
|
||||||
use ManiaControl\ManiaControl;
|
|
||||||
use ManiaControl\Callbacks\CallbackListener;
|
use ManiaControl\Callbacks\CallbackListener;
|
||||||
use ManiaControl\Callbacks\CallbackManager;
|
use ManiaControl\Callbacks\CallbackManager;
|
||||||
|
use ManiaControl\Callbacks\Callbacks;
|
||||||
|
use ManiaControl\ManiaControl;
|
||||||
use ManiaControl\Maps\Map;
|
use ManiaControl\Maps\Map;
|
||||||
use ManiaControl\Plugins\Plugin;
|
use ManiaControl\Plugins\Plugin;
|
||||||
use ManiaControl\Maps\MapManager;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Plugin for the TM Game Mode 'Endurance' by TGYoshi
|
* Plugin for the TM Game Mode 'Endurance' by TGYoshi
|
||||||
@ -16,34 +15,67 @@ use ManiaControl\Maps\MapManager;
|
|||||||
* @author steeffeen
|
* @author steeffeen
|
||||||
*/
|
*/
|
||||||
class EndurancePlugin implements CallbackListener, Plugin {
|
class EndurancePlugin implements CallbackListener, Plugin {
|
||||||
/**
|
/*
|
||||||
* Constants
|
* Constants
|
||||||
*/
|
*/
|
||||||
const ID = 25;
|
const ID = 25;
|
||||||
const VERSION = 0.2;
|
const VERSION = 0.2;
|
||||||
|
const NAME = 'Endurance Plugin';
|
||||||
|
const AUTHOR = 'steeffeen';
|
||||||
const CB_CHECKPOINT = 'Endurance.Checkpoint';
|
const CB_CHECKPOINT = 'Endurance.Checkpoint';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Private properties
|
* Private Properties
|
||||||
*/
|
*/
|
||||||
/** @var maniaControl $maniaControl */
|
/** @var ManiaControl $maniaControl */
|
||||||
private $maniaControl = null;
|
private $maniaControl = null;
|
||||||
/** @var Map $currentMap */
|
/** @var Map $currentMap */
|
||||||
private $currentMap = null;
|
private $currentMap = null;
|
||||||
private $playerLapTimes = array();
|
private $playerLapTimes = array();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Prepares the Plugin
|
* @see \ManiaControl\Plugins\Plugin::prepare()
|
||||||
*
|
|
||||||
* @param ManiaControl $maniaControl
|
|
||||||
* @return mixed
|
|
||||||
*/
|
*/
|
||||||
public static function prepare(ManiaControl $maniaControl) {
|
public static function prepare(ManiaControl $maniaControl) {
|
||||||
//do nothing
|
//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()
|
* @see \ManiaControl\Plugins\Plugin::load()
|
||||||
*/
|
*/
|
||||||
public function load(ManiaControl $maniaControl) {
|
public function load(ManiaControl $maniaControl) {
|
||||||
@ -58,52 +90,11 @@ class EndurancePlugin implements CallbackListener, Plugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @see \ManiaControl\Plugins\Plugin::unload()
|
* @see \ManiaControl\Plugins\Plugin::unload()
|
||||||
*/
|
*/
|
||||||
public function 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
|
* Handle ManiaControl OnInit callback
|
||||||
*
|
*
|
||||||
|
@ -2,11 +2,11 @@
|
|||||||
|
|
||||||
namespace steeffeen;
|
namespace steeffeen;
|
||||||
|
|
||||||
use ManiaControl\ManiaControl;
|
|
||||||
use ManiaControl\Admin\AuthenticationManager;
|
use ManiaControl\Admin\AuthenticationManager;
|
||||||
use ManiaControl\Callbacks\CallbackListener;
|
use ManiaControl\Callbacks\CallbackListener;
|
||||||
use ManiaControl\Callbacks\CallbackManager;
|
use ManiaControl\Callbacks\CallbackManager;
|
||||||
use ManiaControl\Commands\CommandListener;
|
use ManiaControl\Commands\CommandListener;
|
||||||
|
use ManiaControl\ManiaControl;
|
||||||
use ManiaControl\Players\Player;
|
use ManiaControl\Players\Player;
|
||||||
use ManiaControl\Plugins\Plugin;
|
use ManiaControl\Plugins\Plugin;
|
||||||
use Maniaplanet\DedicatedServer\Xmlrpc\Exception;
|
use Maniaplanet\DedicatedServer\Xmlrpc\Exception;
|
||||||
@ -17,11 +17,13 @@ use Maniaplanet\DedicatedServer\Xmlrpc\Exception;
|
|||||||
* @author steeffeen
|
* @author steeffeen
|
||||||
*/
|
*/
|
||||||
class ObstaclePlugin implements CallbackListener, CommandListener, Plugin {
|
class ObstaclePlugin implements CallbackListener, CommandListener, Plugin {
|
||||||
/**
|
/*
|
||||||
* Constants
|
* Constants
|
||||||
*/
|
*/
|
||||||
const ID = 24;
|
const ID = 24;
|
||||||
const VERSION = 0.2;
|
const VERSION = 0.2;
|
||||||
|
const NAME = 'Obstacle Plugin';
|
||||||
|
const AUTHOR = 'steeffeen';
|
||||||
const CB_JUMPTO = 'Obstacle.JumpTo';
|
const CB_JUMPTO = 'Obstacle.JumpTo';
|
||||||
const SCB_ONFINISH = 'OnFinish';
|
const SCB_ONFINISH = 'OnFinish';
|
||||||
const SCB_ONCHECKPOINT = 'OnCheckpoint';
|
const SCB_ONCHECKPOINT = 'OnCheckpoint';
|
||||||
@ -30,23 +32,52 @@ class ObstaclePlugin implements CallbackListener, CommandListener, Plugin {
|
|||||||
/**
|
/**
|
||||||
* Private Properties
|
* Private Properties
|
||||||
*/
|
*/
|
||||||
/**
|
/** @var ManiaControl $maniaControl */
|
||||||
* @var maniaControl $maniaControl
|
|
||||||
*/
|
|
||||||
private $maniaControl = null;
|
private $maniaControl = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Prepares the Plugin
|
* @see \ManiaControl\Plugins\Plugin::prepare()
|
||||||
*
|
|
||||||
* @param ManiaControl $maniaControl
|
|
||||||
* @return mixed
|
|
||||||
*/
|
*/
|
||||||
public static function prepare(ManiaControl $maniaControl) {
|
public static function prepare(ManiaControl $maniaControl) {
|
||||||
// do nothing
|
// 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()
|
* @see \ManiaControl\Plugins\Plugin::load()
|
||||||
*/
|
*/
|
||||||
public function load(ManiaControl $maniaControl) {
|
public function load(ManiaControl $maniaControl) {
|
||||||
@ -66,52 +97,11 @@ class ObstaclePlugin implements CallbackListener, CommandListener, Plugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @see \ManiaControl\Plugins\Plugin::unload()
|
* @see \ManiaControl\Plugins\Plugin::unload()
|
||||||
*/
|
*/
|
||||||
public function 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
|
* Handle JumpTo command
|
||||||
*
|
*
|
||||||
@ -130,8 +120,7 @@ class ObstaclePlugin implements CallbackListener, CommandListener, Plugin {
|
|||||||
$param = $player->login . ";" . $params[1] . ";";
|
$param = $player->login . ";" . $params[1] . ";";
|
||||||
try {
|
try {
|
||||||
$this->maniaControl->client->triggerModeScriptEvent(self::CB_JUMPTO, $param);
|
$this->maniaControl->client->triggerModeScriptEvent(self::CB_JUMPTO, $param);
|
||||||
}
|
} catch (Exception $e) {
|
||||||
catch (Exception $e) {
|
|
||||||
if ($e->getMessage() == 'Not in script mode.') {
|
if ($e->getMessage() == 'Not in script mode.') {
|
||||||
trigger_error("Couldn't send jump callback for '{$player->login}'. " . $e->getMessage());
|
trigger_error("Couldn't send jump callback for '{$player->login}'. " . $e->getMessage());
|
||||||
return;
|
return;
|
||||||
@ -154,8 +143,7 @@ class ObstaclePlugin implements CallbackListener, CommandListener, Plugin {
|
|||||||
$time = $data->Run->Time;
|
$time = $data->Run->Time;
|
||||||
// Trigger trackmania player finish callback
|
// Trigger trackmania player finish callback
|
||||||
$finishCallback = array($player->pid, $player->login, $time);
|
$finishCallback = array($player->pid, $player->login, $time);
|
||||||
$this->maniaControl->callbackManager->triggerCallback(CallbackManager::CB_TM_PLAYERFINISH,
|
$this->maniaControl->callbackManager->triggerCallback(CallbackManager::CB_TM_PLAYERFINISH, array(CallbackManager::CB_TM_PLAYERFINISH, $finishCallback));
|
||||||
array(CallbackManager::CB_TM_PLAYERFINISH, $finishCallback));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -172,7 +160,6 @@ class ObstaclePlugin implements CallbackListener, CommandListener, Plugin {
|
|||||||
}
|
}
|
||||||
// Trigger Trackmania player checkpoint callback
|
// Trigger Trackmania player checkpoint callback
|
||||||
$checkpointCallback = array($player->pid, $player->login, $time, 0, 0);
|
$checkpointCallback = array($player->pid, $player->login, $time, 0, 0);
|
||||||
$this->maniaControl->callbackManager->triggerCallback(CallbackManager::CB_TM_PLAYERCHECKPOINT,
|
$this->maniaControl->callbackManager->triggerCallback(CallbackManager::CB_TM_PLAYERCHECKPOINT, array(CallbackManager::CB_TM_PLAYERCHECKPOINT, $checkpointCallback));
|
||||||
array(CallbackManager::CB_TM_PLAYERCHECKPOINT, $checkpointCallback));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user