2014-05-04 00:36:20 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace MCTeam\Dedimania;
|
|
|
|
|
|
|
|
use FML\Controls\Frame;
|
|
|
|
use FML\Controls\Label;
|
|
|
|
use FML\Controls\Quad;
|
|
|
|
use FML\Controls\Quads\Quad_BgsPlayerCard;
|
|
|
|
use FML\ManiaLink;
|
|
|
|
use FML\Script\Features\Paging;
|
|
|
|
use ManiaControl\Callbacks\CallbackListener;
|
|
|
|
use ManiaControl\Callbacks\CallbackManager;
|
|
|
|
use ManiaControl\Callbacks\Callbacks;
|
2017-05-08 19:55:07 +02:00
|
|
|
use ManiaControl\Callbacks\Structures\TrackMania\OnWayPointEventStructure;
|
2014-05-04 00:36:20 +02:00
|
|
|
use ManiaControl\Callbacks\TimerListener;
|
|
|
|
use ManiaControl\Commands\CommandListener;
|
|
|
|
use ManiaControl\ManiaControl;
|
|
|
|
use ManiaControl\Manialinks\ManialinkManager;
|
|
|
|
use ManiaControl\Players\Player;
|
|
|
|
use ManiaControl\Players\PlayerManager;
|
|
|
|
use ManiaControl\Plugins\Plugin;
|
2017-05-21 23:11:52 +02:00
|
|
|
use ManiaControl\Settings\Setting;
|
|
|
|
use ManiaControl\Settings\SettingManager;
|
2014-05-13 16:40:05 +02:00
|
|
|
use ManiaControl\Utils\Formatter;
|
2017-05-21 23:11:52 +02:00
|
|
|
use MCTeam\Common\RecordWidget;
|
2014-05-04 00:36:20 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* ManiaControl Dedimania Plugin
|
|
|
|
*
|
|
|
|
* @author ManiaControl Team <mail@maniacontrol.com>
|
2020-01-22 10:39:35 +01:00
|
|
|
* @copyright 2014-2020 ManiaControl Team
|
2014-05-04 00:36:20 +02:00
|
|
|
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
|
|
|
*/
|
|
|
|
class DedimaniaPlugin implements CallbackListener, CommandListener, TimerListener, Plugin {
|
|
|
|
/*
|
|
|
|
* Constants
|
|
|
|
*/
|
2017-05-19 23:55:45 +02:00
|
|
|
const ID = 8;
|
Multiple Features to improve ManiaControl usability (#234)
* ServerUIPropertiesMenu for Configurator to edit builtin UIProperties of MP
* fixed unregister-functions of CallbackManager
* Reducing menuItemHeight in Configurator to avoid overlapping of the menu items
* Fully rebuild the admins menu after a player rights changed
* Added function to FileUtil to improve realpath, so symbolic links can be resolved
* Fixed indentation
* Update FileUtil.php
Fixed error in case of an absolute path on Unix-like systems.
* New CallQueue which runs once inbetween the MC-loops
* Added important queued call to be executed earlier
* ErrorMethod made optional, as in some cases, there might be nothing to fail
* Clean up repository from unnecessary files
* Added easy installation script for DB on Unix-like systems
* Replaced deprecated is_real by is_float
* Add milliseconds with dot instead of double colon
* Resolved deprecated curly braces error
* gitignore all hidden files (except git and gitignore)
* Update MC-update-check-interval, so that a restart is not required
* Update gitignore to not ignore changes in MCTeam-Plugins
* Update gitignore again
* And another try
* fixed MasterAdmin //delrec, added personal /delrec-command with permission-setting
* Increase version number of local records plugin
* Add Permission to delete any record
* Reworked notifications of locals, removed private only, added private at rank
* Fix formatting
* Allow AuthenticationManager to store Plugin Permissions
* Method to check, if a named function call is already queued
* Added command disable feature
* Reset timer if DeltaTime updated, so it does not try to catch up missed timings
* Added private notification setting
* To reduce load of multiple records (especially in rounds), queue call chat notifications
* Added internal function to plugin manager to return plugin menu
* restore .idea codestyle files
* Update MC-Version number to 0.250
2020-02-24 17:20:51 +01:00
|
|
|
const VERSION = 0.6;
|
2017-05-19 23:55:45 +02:00
|
|
|
const AUTHOR = 'MCTeam';
|
|
|
|
const NAME = 'Dedimania Plugin';
|
|
|
|
const MLID_DEDIMANIA = 'Dedimania.ManialinkId';
|
|
|
|
|
Multiple Features to improve ManiaControl usability (#234)
* ServerUIPropertiesMenu for Configurator to edit builtin UIProperties of MP
* fixed unregister-functions of CallbackManager
* Reducing menuItemHeight in Configurator to avoid overlapping of the menu items
* Fully rebuild the admins menu after a player rights changed
* Added function to FileUtil to improve realpath, so symbolic links can be resolved
* Fixed indentation
* Update FileUtil.php
Fixed error in case of an absolute path on Unix-like systems.
* New CallQueue which runs once inbetween the MC-loops
* Added important queued call to be executed earlier
* ErrorMethod made optional, as in some cases, there might be nothing to fail
* Clean up repository from unnecessary files
* Added easy installation script for DB on Unix-like systems
* Replaced deprecated is_real by is_float
* Add milliseconds with dot instead of double colon
* Resolved deprecated curly braces error
* gitignore all hidden files (except git and gitignore)
* Update MC-update-check-interval, so that a restart is not required
* Update gitignore to not ignore changes in MCTeam-Plugins
* Update gitignore again
* And another try
* fixed MasterAdmin //delrec, added personal /delrec-command with permission-setting
* Increase version number of local records plugin
* Add Permission to delete any record
* Reworked notifications of locals, removed private only, added private at rank
* Fix formatting
* Allow AuthenticationManager to store Plugin Permissions
* Method to check, if a named function call is already queued
* Added command disable feature
* Reset timer if DeltaTime updated, so it does not try to catch up missed timings
* Added private notification setting
* To reduce load of multiple records (especially in rounds), queue call chat notifications
* Added internal function to plugin manager to return plugin menu
* restore .idea codestyle files
* Update MC-Version number to 0.250
2020-02-24 17:20:51 +01:00
|
|
|
const SETTING_WIDGET_ENABLE = 'Enable Dedimania Widget';
|
|
|
|
const SETTING_WIDGET_TITLE = 'Widget Title';
|
|
|
|
const SETTING_WIDGET_POSX = 'Widget Position: X';
|
|
|
|
const SETTING_WIDGET_POSY = 'Widget Position: Y';
|
|
|
|
const SETTING_WIDGET_WIDTH = 'Widget Width';
|
|
|
|
const SETTING_WIDGET_LINE_COUNT = 'Widget Displayed Lines Count';
|
|
|
|
const SETTING_WIDGET_LINE_HEIGHT = 'Widget Line Height';
|
|
|
|
const SETTING_DEDIMANIA_CODE = '$l[http://dedimania.net/tm2stats/?do=register]Dedimania Code for ';
|
|
|
|
const SETTING_NOTIFY_BEST_RECORDS_PUBLIC = 'Notify Publicly only for the X Best Records';
|
|
|
|
const SETTING_NOTIFY_BEST_RECORDS_PRIVATE = 'Notify Privately only for the X Best Records';
|
|
|
|
const SETTING_MAX_RECORDS = 'Max Records, only increase if you bought a rank update from Dedimania!';
|
2017-05-22 16:48:03 +02:00
|
|
|
|
2017-05-19 23:55:45 +02:00
|
|
|
const CB_DEDIMANIA_CHANGED = 'Dedimania.Changed';
|
|
|
|
const CB_DEDIMANIA_UPDATED = 'Dedimania.Updated';
|
|
|
|
const ACTION_SHOW_DEDIRECORDSLIST = 'Dedimania.ShowDediRecordsList';
|
2014-05-04 00:36:20 +02:00
|
|
|
|
|
|
|
/*
|
2014-08-02 22:31:46 +02:00
|
|
|
* Private properties
|
2014-05-04 00:36:20 +02:00
|
|
|
*/
|
|
|
|
/** @var ManiaControl $maniaControl */
|
|
|
|
private $maniaControl = null;
|
2017-05-19 23:53:21 +02:00
|
|
|
|
2017-05-21 23:11:52 +02:00
|
|
|
/** @var \MCTeam\Common\RecordWidget $recordWidget */
|
|
|
|
private $recordWidget = null;
|
|
|
|
|
2017-05-19 23:55:45 +02:00
|
|
|
private $checkpoints = array();
|
2018-07-03 18:12:47 +02:00
|
|
|
private $allCheckpoints = array();
|
2014-05-04 00:36:20 +02:00
|
|
|
|
2017-05-19 23:53:21 +02:00
|
|
|
/** @var \MCTeam\Dedimania\DedimaniaWebHandler $webHandler */
|
|
|
|
private $webHandler = null;
|
2014-07-05 20:24:54 +02:00
|
|
|
|
2018-07-11 16:24:42 +02:00
|
|
|
private $isMultilap = false;
|
|
|
|
private $isRounds = false;
|
|
|
|
|
2014-05-04 00:36:20 +02:00
|
|
|
/**
|
|
|
|
* @see \ManiaControl\Plugins\Plugin::prepare()
|
|
|
|
*/
|
|
|
|
public static function prepare(ManiaControl $maniaControl) {
|
2014-08-13 11:14:29 +02:00
|
|
|
$servers = $maniaControl->getServer()->getAllServers();
|
2014-05-04 00:36:20 +02:00
|
|
|
foreach ($servers as $server) {
|
2014-08-13 11:14:29 +02:00
|
|
|
$maniaControl->getSettingManager()->initSetting(get_class(), self::SETTING_DEDIMANIA_CODE . $server->login . '$l', '');
|
2014-05-04 00:36:20 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @see \ManiaControl\Plugins\Plugin::load()
|
|
|
|
*/
|
|
|
|
public function load(ManiaControl $maniaControl) {
|
|
|
|
$this->maniaControl = $maniaControl;
|
|
|
|
|
|
|
|
if (!extension_loaded('xmlrpc')) {
|
|
|
|
throw new \Exception("You need to activate the PHP extension xmlrpc to run this Plugin!");
|
|
|
|
}
|
|
|
|
|
2014-08-03 01:34:18 +02:00
|
|
|
// Settings
|
2014-08-13 11:14:29 +02:00
|
|
|
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_WIDGET_ENABLE, true);
|
|
|
|
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_WIDGET_TITLE, 'Dedimania');
|
|
|
|
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_WIDGET_POSX, -139);
|
|
|
|
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_WIDGET_POSY, 7);
|
|
|
|
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_WIDGET_WIDTH, 40);
|
|
|
|
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_WIDGET_LINE_HEIGHT, 4);
|
|
|
|
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_WIDGET_LINE_COUNT, 12);
|
Multiple Features to improve ManiaControl usability (#234)
* ServerUIPropertiesMenu for Configurator to edit builtin UIProperties of MP
* fixed unregister-functions of CallbackManager
* Reducing menuItemHeight in Configurator to avoid overlapping of the menu items
* Fully rebuild the admins menu after a player rights changed
* Added function to FileUtil to improve realpath, so symbolic links can be resolved
* Fixed indentation
* Update FileUtil.php
Fixed error in case of an absolute path on Unix-like systems.
* New CallQueue which runs once inbetween the MC-loops
* Added important queued call to be executed earlier
* ErrorMethod made optional, as in some cases, there might be nothing to fail
* Clean up repository from unnecessary files
* Added easy installation script for DB on Unix-like systems
* Replaced deprecated is_real by is_float
* Add milliseconds with dot instead of double colon
* Resolved deprecated curly braces error
* gitignore all hidden files (except git and gitignore)
* Update MC-update-check-interval, so that a restart is not required
* Update gitignore to not ignore changes in MCTeam-Plugins
* Update gitignore again
* And another try
* fixed MasterAdmin //delrec, added personal /delrec-command with permission-setting
* Increase version number of local records plugin
* Add Permission to delete any record
* Reworked notifications of locals, removed private only, added private at rank
* Fix formatting
* Allow AuthenticationManager to store Plugin Permissions
* Method to check, if a named function call is already queued
* Added command disable feature
* Reset timer if DeltaTime updated, so it does not try to catch up missed timings
* Added private notification setting
* To reduce load of multiple records (especially in rounds), queue call chat notifications
* Added internal function to plugin manager to return plugin menu
* restore .idea codestyle files
* Update MC-Version number to 0.250
2020-02-24 17:20:51 +01:00
|
|
|
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_NOTIFY_BEST_RECORDS_PRIVATE, 30);
|
|
|
|
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_NOTIFY_BEST_RECORDS_PUBLIC, 15);
|
2017-05-22 16:48:03 +02:00
|
|
|
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_MAX_RECORDS, 30);
|
2014-08-03 01:34:18 +02:00
|
|
|
|
|
|
|
// Callbacks
|
2014-08-13 11:14:29 +02:00
|
|
|
$this->maniaControl->getCallbackManager()->registerCallbackListener(Callbacks::BEGINMAP, $this, 'handleBeginMap');
|
|
|
|
$this->maniaControl->getCallbackManager()->registerCallbackListener(Callbacks::ENDMAP, $this, 'handleMapEnd');
|
|
|
|
$this->maniaControl->getCallbackManager()->registerCallbackListener(CallbackManager::CB_MP_PLAYERMANIALINKPAGEANSWER, $this, 'handleManialinkPageAnswer');
|
|
|
|
$this->maniaControl->getCallbackManager()->registerCallbackListener(PlayerManager::CB_PLAYERCONNECT, $this, 'handlePlayerConnect');
|
|
|
|
$this->maniaControl->getCallbackManager()->registerCallbackListener(PlayerManager::CB_PLAYERDISCONNECT, $this, 'handlePlayerDisconnect');
|
2017-05-08 19:55:07 +02:00
|
|
|
$this->maniaControl->getCallbackManager()->registerCallbackListener(Callbacks::TM_ONWAYPOINT, $this, 'handleCheckpointCallback');
|
|
|
|
$this->maniaControl->getCallbackManager()->registerCallbackListener(Callbacks::TM_ONFINISHLINE, $this, 'handleFinishCallback');
|
2017-07-18 21:52:52 +02:00
|
|
|
$this->maniaControl->getCallbackManager()->registerCallbackListener(Callbacks::TM_ONLAPFINISH, $this, 'handleFinishCallback');
|
2017-05-21 23:11:52 +02:00
|
|
|
$this->maniaControl->getCallbackManager()->registerCallbackListener(SettingManager::CB_SETTING_CHANGED, $this, 'handleSettingChanged');
|
2017-06-22 15:07:00 +02:00
|
|
|
$this->maniaControl->getCallbackManager()->registerCallbackListener(Callbacks::AFTERLOOP, $this, 'handleAfterLoop');
|
2014-08-13 11:14:29 +02:00
|
|
|
|
|
|
|
$this->maniaControl->getTimerManager()->registerTimerListening($this, 'updateEverySecond', 1000);
|
2017-05-22 15:52:59 +02:00
|
|
|
$this->maniaControl->getTimerManager()->registerTimerListening($this, 'handleEveryMinute', 1000 * 60);
|
2014-08-13 11:14:29 +02:00
|
|
|
|
2017-05-08 19:55:07 +02:00
|
|
|
$this->maniaControl->getCommandManager()->registerCommandListener(array('dedirecs',
|
|
|
|
'dedirecords'), $this, 'showDediRecordsList', false, 'Shows a list of Dedimania records of the current map.');
|
2014-05-04 00:36:20 +02:00
|
|
|
|
|
|
|
// Open session
|
2014-08-13 11:14:29 +02:00
|
|
|
$serverInfo = $this->maniaControl->getServer()->getInfo();
|
|
|
|
$serverVersion = $this->maniaControl->getClient()->getVersion();
|
2017-05-08 17:45:16 +02:00
|
|
|
|
|
|
|
$packMask = $this->maniaControl->getMapManager()->getCurrentMap()->environment;
|
2014-05-04 00:36:20 +02:00
|
|
|
|
2014-08-13 11:14:29 +02:00
|
|
|
$dedimaniaCode = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_DEDIMANIA_CODE . $serverInfo->login . '$l');
|
2014-05-24 20:19:41 +02:00
|
|
|
if (!$dedimaniaCode) {
|
2014-05-04 00:36:20 +02:00
|
|
|
throw new \Exception("No Dedimania Code Specified, check the settings!");
|
|
|
|
}
|
|
|
|
|
2017-05-21 19:36:57 +02:00
|
|
|
if ($this->maniaControl->getMapManager()->getCurrentMap()->getGame() !== 'tm') {
|
|
|
|
throw new \Exception("This Plugin is only for Trackmania!");
|
|
|
|
}
|
2014-07-05 20:24:54 +02:00
|
|
|
|
2017-05-22 16:48:03 +02:00
|
|
|
$maxRecords = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MAX_RECORDS);
|
|
|
|
|
2017-05-22 17:54:18 +02:00
|
|
|
$dedimaniaData = new DedimaniaData($serverInfo->login, $dedimaniaCode, $serverInfo->path, $packMask, $serverVersion);
|
2017-05-22 16:48:03 +02:00
|
|
|
$dedimaniaData->serverMaxRank = $maxRecords;
|
2014-05-04 00:36:20 +02:00
|
|
|
|
2017-05-19 23:53:21 +02:00
|
|
|
//New Version
|
|
|
|
$this->webHandler = new DedimaniaWebHandler($this->maniaControl);
|
|
|
|
$this->webHandler->setDedimaniaData($dedimaniaData);
|
|
|
|
$this->webHandler->openDedimaniaSession(true);
|
2017-05-21 23:11:52 +02:00
|
|
|
|
|
|
|
$this->recordWidget = new RecordWidget($this->maniaControl);
|
2018-07-11 16:24:42 +02:00
|
|
|
|
2020-03-16 10:56:38 +01:00
|
|
|
if ($this->maniaControl->getServer()->getGameMode() == 0) {
|
2018-07-11 16:24:42 +02:00
|
|
|
$gameMode = $this->maniaControl->getClient()->getScriptName()['CurrentValue'];
|
|
|
|
$this->isMultilap = ($gameMode == 'Laps.Script.txt' || $this->maniaControl->getMapManager()->getCurrentMap()->nbLaps > 0);
|
|
|
|
$this->isRounds = ($gameMode == 'Rounds.Script.txt');
|
|
|
|
} else {
|
|
|
|
$this->isMultilap = ($this->maniaControl->getServer()->getGameMode(true) == 'Laps' || $this->maniaControl->getMapManager()->getCurrentMap()->nbLaps > 0);
|
|
|
|
$this->isRounds = ($this->maniaControl->getServer()->getGameMode(true) == 'Rounds');
|
|
|
|
}
|
2014-05-04 00:36:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2014-06-14 14:32:29 +02:00
|
|
|
* Handle 1 Second Callback
|
2017-06-22 15:07:00 +02:00
|
|
|
*
|
|
|
|
* @internal
|
2014-05-04 00:36:20 +02:00
|
|
|
*/
|
2014-06-14 14:32:29 +02:00
|
|
|
public function updateEverySecond() {
|
2017-05-19 23:53:21 +02:00
|
|
|
if (!$this->webHandler->doesManiaLinkNeedUpdate()) {
|
2014-05-04 00:36:20 +02:00
|
|
|
return;
|
|
|
|
}
|
2017-05-19 23:53:21 +02:00
|
|
|
$this->webHandler->maniaLinkUpdated();
|
2014-07-05 18:02:27 +02:00
|
|
|
|
2017-05-08 17:45:16 +02:00
|
|
|
if ($this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_WIDGET_ENABLE)) {
|
2017-05-08 19:55:07 +02:00
|
|
|
$this->sendManialink();
|
2020-03-16 10:56:38 +01:00
|
|
|
} else {
|
|
|
|
$this->maniaControl->getManialinkManager()->hideManialink(self::MLID_DEDIMANIA);
|
2014-05-04 00:36:20 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-05-08 19:55:07 +02:00
|
|
|
* Builds and Sends the Manialink
|
2014-05-04 00:36:20 +02:00
|
|
|
*/
|
2017-05-08 19:55:07 +02:00
|
|
|
private function sendManialink() {
|
2017-05-19 23:53:21 +02:00
|
|
|
$records = $this->webHandler->getDedimaniaData()->records;
|
2014-05-04 00:36:20 +02:00
|
|
|
|
2014-08-13 11:14:29 +02:00
|
|
|
$title = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_WIDGET_TITLE);
|
|
|
|
$posX = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_WIDGET_POSX);
|
|
|
|
$posY = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_WIDGET_POSY);
|
|
|
|
$width = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_WIDGET_WIDTH);
|
|
|
|
$lines = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_WIDGET_LINE_COUNT);
|
|
|
|
$lineHeight = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_WIDGET_LINE_HEIGHT);
|
|
|
|
$labelStyle = $this->maniaControl->getManialinkManager()->getStyleManager()->getDefaultLabelStyle();
|
|
|
|
$quadStyle = $this->maniaControl->getManialinkManager()->getStyleManager()->getDefaultQuadStyle();
|
|
|
|
$quadSubstyle = $this->maniaControl->getManialinkManager()->getStyleManager()->getDefaultQuadSubstyle();
|
2014-05-04 00:36:20 +02:00
|
|
|
|
|
|
|
|
|
|
|
$manialink = new ManiaLink(self::MLID_DEDIMANIA);
|
|
|
|
$frame = new Frame();
|
2017-03-25 19:15:50 +01:00
|
|
|
$manialink->addChild($frame);
|
2014-06-14 15:48:27 +02:00
|
|
|
$frame->setPosition($posX, $posY);
|
2014-05-04 00:36:20 +02:00
|
|
|
|
|
|
|
$backgroundQuad = new Quad();
|
2017-03-25 19:15:50 +01:00
|
|
|
$frame->addChild($backgroundQuad);
|
|
|
|
$backgroundQuad->setVerticalAlign($backgroundQuad::TOP);
|
2014-05-04 00:36:20 +02:00
|
|
|
$height = 7. + $lines * $lineHeight;
|
|
|
|
$backgroundQuad->setSize($width * 1.05, $height);
|
|
|
|
$backgroundQuad->setStyles($quadStyle, $quadSubstyle);
|
2017-05-21 23:11:52 +02:00
|
|
|
$backgroundQuad->setAction(self::ACTION_SHOW_DEDIRECORDSLIST);
|
2014-05-04 00:36:20 +02:00
|
|
|
|
|
|
|
$titleLabel = new Label();
|
2017-03-25 19:15:50 +01:00
|
|
|
$frame->addChild($titleLabel);
|
2014-05-04 00:36:20 +02:00
|
|
|
$titleLabel->setPosition(0, $lineHeight * -0.9);
|
|
|
|
$titleLabel->setWidth($width);
|
|
|
|
$titleLabel->setStyle($labelStyle);
|
|
|
|
$titleLabel->setTextSize(2);
|
|
|
|
$titleLabel->setText($title);
|
|
|
|
$titleLabel->setTranslate(true);
|
|
|
|
|
2017-05-22 16:48:03 +02:00
|
|
|
$recordsFrame = $this->recordWidget->generateRecordsFrame($records, $lines);
|
2017-05-21 23:11:52 +02:00
|
|
|
$frame->addChild($recordsFrame);
|
2014-05-04 00:36:20 +02:00
|
|
|
|
2017-05-08 19:55:07 +02:00
|
|
|
$this->maniaControl->getManialinkManager()->sendManialink($manialink);
|
2014-05-04 00:36:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-05-13 16:40:05 +02:00
|
|
|
* Handle 1 Minute Callback
|
2017-06-22 15:07:00 +02:00
|
|
|
*
|
|
|
|
* @internal
|
2014-05-04 00:36:20 +02:00
|
|
|
*/
|
2017-05-22 15:52:59 +02:00
|
|
|
public function handleEveryMinute() {
|
2017-05-19 23:53:21 +02:00
|
|
|
if ($this->webHandler->getDedimaniaData()->sessionId == "") {
|
2014-05-04 00:36:20 +02:00
|
|
|
return;
|
|
|
|
}
|
2017-05-19 23:53:21 +02:00
|
|
|
$this->webHandler->checkDedimaniaSession();
|
2014-05-04 00:36:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle PlayerConnect callback
|
|
|
|
*
|
2017-06-22 15:07:00 +02:00
|
|
|
* @internal
|
2014-05-24 20:19:41 +02:00
|
|
|
* @param Player $player
|
2014-05-04 00:36:20 +02:00
|
|
|
*/
|
|
|
|
public function handlePlayerConnect(Player $player) {
|
2017-05-19 23:53:21 +02:00
|
|
|
$this->webHandler->handlePlayerConnect($player);
|
2014-05-04 00:36:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-06-14 22:30:33 +02:00
|
|
|
* Handle Player Disconnect Callback
|
2014-05-04 00:36:20 +02:00
|
|
|
*
|
2017-06-22 15:07:00 +02:00
|
|
|
* @internal
|
2014-06-14 22:30:33 +02:00
|
|
|
* @param Player $player
|
2014-05-04 00:36:20 +02:00
|
|
|
*/
|
|
|
|
public function handlePlayerDisconnect(Player $player) {
|
2017-05-19 23:53:21 +02:00
|
|
|
$this->webHandler->handlePlayerDisconnect($player);
|
2014-05-04 00:36:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-05-13 16:40:05 +02:00
|
|
|
* Handle Begin Map Callback
|
2017-06-22 15:07:00 +02:00
|
|
|
*
|
|
|
|
* @internal
|
2014-05-04 00:36:20 +02:00
|
|
|
*/
|
2014-05-13 16:40:05 +02:00
|
|
|
public function handleBeginMap() {
|
2017-06-30 18:33:54 +02:00
|
|
|
$this->checkpoints = null;
|
2018-07-03 18:12:47 +02:00
|
|
|
$this->allCheckpoints = null;
|
2017-05-19 23:53:21 +02:00
|
|
|
$this->webHandler->getDedimaniaData()->unsetRecords();
|
|
|
|
$this->webHandler->maniaLinkUpdateNeeded();
|
|
|
|
$this->webHandler->fetchDedimaniaRecords(true);
|
2014-05-04 00:36:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-05-13 16:40:05 +02:00
|
|
|
* Handle EndMap Callback
|
2017-06-22 15:07:00 +02:00
|
|
|
*
|
|
|
|
* @internal
|
2014-05-04 00:36:20 +02:00
|
|
|
*/
|
2014-05-13 16:40:05 +02:00
|
|
|
public function handleMapEnd() {
|
2017-05-19 23:53:21 +02:00
|
|
|
$this->webHandler->submitChallengeTimes();
|
2014-05-04 00:36:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-05-24 20:29:32 +02:00
|
|
|
* Handle Checkpoint Callback
|
2014-05-04 00:36:20 +02:00
|
|
|
*
|
2017-06-22 15:07:00 +02:00
|
|
|
* @internal
|
2017-05-08 19:55:07 +02:00
|
|
|
* @param OnWayPointEventStructure $callback
|
2014-05-24 20:29:32 +02:00
|
|
|
*/
|
2017-05-08 19:55:07 +02:00
|
|
|
public function handleCheckpointCallback(OnWayPointEventStructure $structure) {
|
2017-07-18 21:52:52 +02:00
|
|
|
if (!$structure->getLapTime()) {
|
2017-05-08 17:45:16 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-05-11 23:35:59 +02:00
|
|
|
$login = $structure->getLogin();
|
2017-05-08 17:45:16 +02:00
|
|
|
if (!isset($this->checkpoints[$login])) {
|
|
|
|
$this->checkpoints[$login] = array();
|
|
|
|
}
|
2018-07-03 18:12:47 +02:00
|
|
|
if (!isset($this->allCheckpoints[$login])) {
|
|
|
|
$this->allCheckpoints[$login] = array();
|
|
|
|
}
|
|
|
|
|
2017-07-18 21:52:52 +02:00
|
|
|
$this->checkpoints[$login][$structure->getCheckPointInLap()] = $structure->getLapTime();
|
2018-07-03 18:12:47 +02:00
|
|
|
$this->allCheckpoints[$login][$structure->getCheckPointInRace()] = $structure->getRaceTime();
|
2014-05-24 20:29:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle Finish Callback
|
|
|
|
*
|
2017-06-22 15:07:00 +02:00
|
|
|
* @internal
|
2017-05-20 10:10:39 +02:00
|
|
|
* @param \ManiaControl\Callbacks\Structures\TrackMania\OnWayPointEventStructure $structure
|
2014-05-24 20:29:32 +02:00
|
|
|
*/
|
2017-05-08 19:55:07 +02:00
|
|
|
public function handleFinishCallback(OnWayPointEventStructure $structure) {
|
|
|
|
if ($structure->getRaceTime() <= 0) {
|
2014-05-24 20:29:32 +02:00
|
|
|
// Invalid time
|
2014-05-04 00:36:20 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-08-13 11:14:29 +02:00
|
|
|
$map = $this->maniaControl->getMapManager()->getCurrentMap();
|
2014-05-04 00:36:20 +02:00
|
|
|
if (!$map) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-05-08 17:45:16 +02:00
|
|
|
if ($map->nbCheckpoints < 2) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-05-08 19:55:07 +02:00
|
|
|
$player = $structure->getPlayer();
|
|
|
|
|
2018-07-03 18:12:47 +02:00
|
|
|
$this->checkpoints[$player->login][$structure->getCheckPointInLap()] = $structure->getLapTime();
|
|
|
|
$this->allCheckpoints[$player->login][$structure->getCheckPointInRace()] = $structure->getRaceTime();
|
2018-07-11 16:24:42 +02:00
|
|
|
|
|
|
|
$recTime = $structure->getLapTime();
|
|
|
|
if ($this->isMultilap && $this->isRounds) {
|
|
|
|
$recTime = $structure->getRaceTime();
|
|
|
|
if (!$structure->getIsEndRace()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2018-07-03 18:12:47 +02:00
|
|
|
|
2017-05-08 19:55:07 +02:00
|
|
|
$oldRecord = $this->getDedimaniaRecord($player->login);
|
2018-07-11 16:24:42 +02:00
|
|
|
if ($oldRecord->nullRecord || $oldRecord && $oldRecord->best > $recTime) {
|
2014-05-04 00:36:20 +02:00
|
|
|
// Save time
|
|
|
|
$newRecord = new RecordData(null);
|
2017-05-08 17:45:16 +02:00
|
|
|
|
2017-05-08 19:55:07 +02:00
|
|
|
$checkPoints = $this->getCheckpoints($player->login);
|
2018-07-03 18:12:47 +02:00
|
|
|
$allCPs = $this->getAllCheckpoints($player->login);
|
2017-05-08 17:45:16 +02:00
|
|
|
|
2018-07-11 16:24:42 +02:00
|
|
|
if ($this->isMultilap && $this->isRounds) {
|
|
|
|
$newRecord->constructNewRecord($player->login, $player->nickname, $recTime, $allCPs, true, $allCPs);
|
|
|
|
} else {
|
|
|
|
$newRecord->constructNewRecord($player->login, $player->nickname, $recTime, $checkPoints, true, $allCPs);
|
|
|
|
}
|
2017-05-08 17:45:16 +02:00
|
|
|
|
2014-05-04 00:36:20 +02:00
|
|
|
if ($this->insertDedimaniaRecord($newRecord, $oldRecord)) {
|
|
|
|
// Get newly saved record
|
2017-05-19 23:53:21 +02:00
|
|
|
foreach ($this->webHandler->getDedimaniaData()->records as &$record) {
|
2014-05-04 00:36:20 +02:00
|
|
|
if ($record->login !== $newRecord->login) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
$newRecord = $record;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2014-08-13 11:14:29 +02:00
|
|
|
$this->maniaControl->getCallbackManager()->triggerCallback(self::CB_DEDIMANIA_CHANGED, $newRecord);
|
2014-05-04 00:36:20 +02:00
|
|
|
|
|
|
|
// Announce record
|
|
|
|
if ($oldRecord->nullRecord || $newRecord->rank < $oldRecord->rank) {
|
|
|
|
// Gained rank
|
|
|
|
$improvement = 'gained the';
|
|
|
|
} else {
|
|
|
|
// Only improved time
|
2017-05-08 20:36:29 +02:00
|
|
|
$improvement = 'improved the';
|
2014-05-04 00:36:20 +02:00
|
|
|
}
|
2017-05-22 16:48:03 +02:00
|
|
|
|
2020-02-25 19:37:17 +01:00
|
|
|
$notifyName = '';
|
Multiple Features to improve ManiaControl usability (#234)
* ServerUIPropertiesMenu for Configurator to edit builtin UIProperties of MP
* fixed unregister-functions of CallbackManager
* Reducing menuItemHeight in Configurator to avoid overlapping of the menu items
* Fully rebuild the admins menu after a player rights changed
* Added function to FileUtil to improve realpath, so symbolic links can be resolved
* Fixed indentation
* Update FileUtil.php
Fixed error in case of an absolute path on Unix-like systems.
* New CallQueue which runs once inbetween the MC-loops
* Added important queued call to be executed earlier
* ErrorMethod made optional, as in some cases, there might be nothing to fail
* Clean up repository from unnecessary files
* Added easy installation script for DB on Unix-like systems
* Replaced deprecated is_real by is_float
* Add milliseconds with dot instead of double colon
* Resolved deprecated curly braces error
* gitignore all hidden files (except git and gitignore)
* Update MC-update-check-interval, so that a restart is not required
* Update gitignore to not ignore changes in MCTeam-Plugins
* Update gitignore again
* And another try
* fixed MasterAdmin //delrec, added personal /delrec-command with permission-setting
* Increase version number of local records plugin
* Add Permission to delete any record
* Reworked notifications of locals, removed private only, added private at rank
* Fix formatting
* Allow AuthenticationManager to store Plugin Permissions
* Method to check, if a named function call is already queued
* Added command disable feature
* Reset timer if DeltaTime updated, so it does not try to catch up missed timings
* Added private notification setting
* To reduce load of multiple records (especially in rounds), queue call chat notifications
* Added internal function to plugin manager to return plugin menu
* restore .idea codestyle files
* Update MC-Version number to 0.250
2020-02-24 17:20:51 +01:00
|
|
|
$notifyOnlyBestRecordsPrivate = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_NOTIFY_BEST_RECORDS_PRIVATE);
|
|
|
|
$notifyOnlyBestRecordsPublic = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_NOTIFY_BEST_RECORDS_PUBLIC);
|
|
|
|
if ($newRecord->rank <= $notifyOnlyBestRecordsPublic) {
|
2017-05-22 16:48:03 +02:00
|
|
|
$notifyName = $player->nickname;
|
Multiple Features to improve ManiaControl usability (#234)
* ServerUIPropertiesMenu for Configurator to edit builtin UIProperties of MP
* fixed unregister-functions of CallbackManager
* Reducing menuItemHeight in Configurator to avoid overlapping of the menu items
* Fully rebuild the admins menu after a player rights changed
* Added function to FileUtil to improve realpath, so symbolic links can be resolved
* Fixed indentation
* Update FileUtil.php
Fixed error in case of an absolute path on Unix-like systems.
* New CallQueue which runs once inbetween the MC-loops
* Added important queued call to be executed earlier
* ErrorMethod made optional, as in some cases, there might be nothing to fail
* Clean up repository from unnecessary files
* Added easy installation script for DB on Unix-like systems
* Replaced deprecated is_real by is_float
* Add milliseconds with dot instead of double colon
* Resolved deprecated curly braces error
* gitignore all hidden files (except git and gitignore)
* Update MC-update-check-interval, so that a restart is not required
* Update gitignore to not ignore changes in MCTeam-Plugins
* Update gitignore again
* And another try
* fixed MasterAdmin //delrec, added personal /delrec-command with permission-setting
* Increase version number of local records plugin
* Add Permission to delete any record
* Reworked notifications of locals, removed private only, added private at rank
* Fix formatting
* Allow AuthenticationManager to store Plugin Permissions
* Method to check, if a named function call is already queued
* Added command disable feature
* Reset timer if DeltaTime updated, so it does not try to catch up missed timings
* Added private notification setting
* To reduce load of multiple records (especially in rounds), queue call chat notifications
* Added internal function to plugin manager to return plugin menu
* restore .idea codestyle files
* Update MC-Version number to 0.250
2020-02-24 17:20:51 +01:00
|
|
|
} elseif ($newRecord->rank <= $notifyOnlyBestRecordsPrivate) {
|
2017-05-22 16:48:03 +02:00
|
|
|
$notifyName = 'You';
|
|
|
|
}
|
|
|
|
|
|
|
|
$message = '$390$<$fff' . $notifyName . '$> ' . $improvement . ' $<$ff0' . $newRecord->rank . '.$> Dedimania Record: $<$fff' . Formatter::formatTime($newRecord->best) . '$>';
|
2014-05-04 00:36:20 +02:00
|
|
|
if (!$oldRecord->nullRecord) {
|
2018-07-11 16:24:42 +02:00
|
|
|
$message .= ' ($<$ff0' . $oldRecord->rank . '.$> $<$fff-' . Formatter::formatTime(($oldRecord->best - $recTime)) . '$>)';
|
2014-05-04 00:36:20 +02:00
|
|
|
}
|
2017-05-22 16:48:03 +02:00
|
|
|
|
Multiple Features to improve ManiaControl usability (#234)
* ServerUIPropertiesMenu for Configurator to edit builtin UIProperties of MP
* fixed unregister-functions of CallbackManager
* Reducing menuItemHeight in Configurator to avoid overlapping of the menu items
* Fully rebuild the admins menu after a player rights changed
* Added function to FileUtil to improve realpath, so symbolic links can be resolved
* Fixed indentation
* Update FileUtil.php
Fixed error in case of an absolute path on Unix-like systems.
* New CallQueue which runs once inbetween the MC-loops
* Added important queued call to be executed earlier
* ErrorMethod made optional, as in some cases, there might be nothing to fail
* Clean up repository from unnecessary files
* Added easy installation script for DB on Unix-like systems
* Replaced deprecated is_real by is_float
* Add milliseconds with dot instead of double colon
* Resolved deprecated curly braces error
* gitignore all hidden files (except git and gitignore)
* Update MC-update-check-interval, so that a restart is not required
* Update gitignore to not ignore changes in MCTeam-Plugins
* Update gitignore again
* And another try
* fixed MasterAdmin //delrec, added personal /delrec-command with permission-setting
* Increase version number of local records plugin
* Add Permission to delete any record
* Reworked notifications of locals, removed private only, added private at rank
* Fix formatting
* Allow AuthenticationManager to store Plugin Permissions
* Method to check, if a named function call is already queued
* Added command disable feature
* Reset timer if DeltaTime updated, so it does not try to catch up missed timings
* Added private notification setting
* To reduce load of multiple records (especially in rounds), queue call chat notifications
* Added internal function to plugin manager to return plugin menu
* restore .idea codestyle files
* Update MC-Version number to 0.250
2020-02-24 17:20:51 +01:00
|
|
|
if ($newRecord->rank <= $notifyOnlyBestRecordsPublic) {
|
2017-05-22 16:48:03 +02:00
|
|
|
$this->maniaControl->getChat()->sendInformation($message . '!');
|
Multiple Features to improve ManiaControl usability (#234)
* ServerUIPropertiesMenu for Configurator to edit builtin UIProperties of MP
* fixed unregister-functions of CallbackManager
* Reducing menuItemHeight in Configurator to avoid overlapping of the menu items
* Fully rebuild the admins menu after a player rights changed
* Added function to FileUtil to improve realpath, so symbolic links can be resolved
* Fixed indentation
* Update FileUtil.php
Fixed error in case of an absolute path on Unix-like systems.
* New CallQueue which runs once inbetween the MC-loops
* Added important queued call to be executed earlier
* ErrorMethod made optional, as in some cases, there might be nothing to fail
* Clean up repository from unnecessary files
* Added easy installation script for DB on Unix-like systems
* Replaced deprecated is_real by is_float
* Add milliseconds with dot instead of double colon
* Resolved deprecated curly braces error
* gitignore all hidden files (except git and gitignore)
* Update MC-update-check-interval, so that a restart is not required
* Update gitignore to not ignore changes in MCTeam-Plugins
* Update gitignore again
* And another try
* fixed MasterAdmin //delrec, added personal /delrec-command with permission-setting
* Increase version number of local records plugin
* Add Permission to delete any record
* Reworked notifications of locals, removed private only, added private at rank
* Fix formatting
* Allow AuthenticationManager to store Plugin Permissions
* Method to check, if a named function call is already queued
* Added command disable feature
* Reset timer if DeltaTime updated, so it does not try to catch up missed timings
* Added private notification setting
* To reduce load of multiple records (especially in rounds), queue call chat notifications
* Added internal function to plugin manager to return plugin menu
* restore .idea codestyle files
* Update MC-Version number to 0.250
2020-02-24 17:20:51 +01:00
|
|
|
} elseif ($newRecord->rank <= $notifyOnlyBestRecordsPrivate) {
|
2017-05-22 16:48:03 +02:00
|
|
|
$this->maniaControl->getChat()->sendInformation($message . '!', $player);
|
|
|
|
}
|
2014-05-04 00:36:20 +02:00
|
|
|
|
2017-05-19 23:53:21 +02:00
|
|
|
$this->webHandler->maniaLinkUpdateNeeded();
|
2014-05-04 00:36:20 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the dedimania record of the given login
|
|
|
|
*
|
|
|
|
* @param string $login
|
|
|
|
* @return RecordData $record
|
|
|
|
*/
|
|
|
|
private function getDedimaniaRecord($login) {
|
2017-05-19 23:53:21 +02:00
|
|
|
if (!$this->webHandler->getDedimaniaData()->recordsExisting()) {
|
2014-05-04 00:36:20 +02:00
|
|
|
return new RecordData(null);
|
|
|
|
}
|
2017-05-19 23:53:21 +02:00
|
|
|
$records = $this->webHandler->getDedimaniaData()->records;
|
2014-05-04 00:36:20 +02:00
|
|
|
foreach ($records as &$record) {
|
|
|
|
if ($record->login === $login) {
|
|
|
|
return $record;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return new RecordData(null);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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;
|
|
|
|
}
|
|
|
|
|
2018-07-03 18:12:47 +02:00
|
|
|
/**
|
|
|
|
* Get total checkpoint string for dedimania record
|
|
|
|
*
|
|
|
|
* @param string $login
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
private function getAllCheckpoints($login) {
|
|
|
|
if (!$login || !isset($this->allCheckpoints[$login])) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
$string = '';
|
|
|
|
$count = count($this->allCheckpoints[$login]);
|
|
|
|
foreach ($this->allCheckpoints[$login] as $index => $check) {
|
|
|
|
$string .= strval($check);
|
|
|
|
if ($index < $count - 1) {
|
|
|
|
$string .= ',';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $string;
|
|
|
|
}
|
|
|
|
|
2014-05-04 00:36:20 +02:00
|
|
|
/**
|
|
|
|
* Inserts the given new Dedimania record at the proper position
|
|
|
|
*
|
2014-05-09 17:31:29 +02:00
|
|
|
* @param RecordData $newRecord
|
|
|
|
* @param RecordData $oldRecord
|
2014-05-04 00:36:20 +02:00
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
private function insertDedimaniaRecord(RecordData &$newRecord, RecordData $oldRecord) {
|
2017-05-19 23:53:21 +02:00
|
|
|
if ($newRecord->nullRecord) {
|
2014-05-04 00:36:20 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
$insert = false;
|
|
|
|
|
|
|
|
// Get max possible rank
|
2017-05-19 23:53:21 +02:00
|
|
|
$maxRank = $this->webHandler->getDedimaniaData()->getPlayerMaxRank($newRecord->login);
|
2014-05-04 00:36:20 +02:00
|
|
|
|
|
|
|
// Loop through existing records
|
2017-05-19 23:53:21 +02:00
|
|
|
foreach ($this->webHandler->getDedimaniaData()->records as $key => &$record) {
|
2014-05-04 00:36:20 +02:00
|
|
|
if ($record->rank > $maxRank) {
|
|
|
|
// Max rank reached
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if ($record->login === $newRecord->login) {
|
|
|
|
// Old record of the same player
|
|
|
|
if ($record->best <= $newRecord->best) {
|
|
|
|
// It's better - Do nothing
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Replace old record
|
2017-05-19 23:53:21 +02:00
|
|
|
$this->webHandler->getDedimaniaData()->deleteRecordByIndex($key);
|
2014-05-04 00:36:20 +02:00
|
|
|
$insert = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Other player's record
|
|
|
|
if ($record->best <= $newRecord->best) {
|
|
|
|
// It's better - Skip
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// New record is better - Insert it
|
|
|
|
$insert = true;
|
|
|
|
if ($oldRecord) {
|
|
|
|
// Remove old record
|
2017-05-19 23:53:21 +02:00
|
|
|
foreach ($this->webHandler->getDedimaniaData()->records as $key2 => $record2) {
|
2014-05-04 00:36:20 +02:00
|
|
|
if ($record2->login !== $oldRecord->login) {
|
|
|
|
continue;
|
|
|
|
}
|
2017-05-19 23:53:21 +02:00
|
|
|
unset($this->webHandler->getDedimaniaData()->records[$key2]);
|
2014-05-04 00:36:20 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2017-05-19 23:53:21 +02:00
|
|
|
if (!$insert && count($this->webHandler->getDedimaniaData()->records) < $maxRank) {
|
2014-05-04 00:36:20 +02:00
|
|
|
// Records list not full - Append new record
|
|
|
|
$insert = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($insert) {
|
|
|
|
// Insert new record
|
2017-05-19 23:53:21 +02:00
|
|
|
array_push($this->webHandler->getDedimaniaData()->records, $newRecord);
|
2014-05-04 00:36:20 +02:00
|
|
|
|
|
|
|
// Update ranks
|
|
|
|
$this->updateDedimaniaRecordRanks();
|
|
|
|
|
|
|
|
// Save replays
|
2017-05-19 23:53:21 +02:00
|
|
|
foreach ($this->webHandler->getDedimaniaData()->records as &$record) {
|
2014-05-04 00:36:20 +02:00
|
|
|
if ($record->login !== $newRecord->login) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
$this->setRecordReplays($record);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
// Record inserted
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
// No new record
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update the sorting and the ranks of all dedimania records
|
|
|
|
*/
|
|
|
|
private function updateDedimaniaRecordRanks() {
|
2017-05-19 23:53:21 +02:00
|
|
|
if (!$this->webHandler->getDedimaniaData()->recordsExisting()) {
|
|
|
|
$this->maniaControl->getCallbackManager()->triggerCallback(self::CB_DEDIMANIA_UPDATED, $this->webHandler->getDedimaniaData()->records);
|
2014-05-04 00:36:20 +02:00
|
|
|
return;
|
|
|
|
}
|
2014-06-14 15:48:27 +02:00
|
|
|
|
2017-05-19 23:53:21 +02:00
|
|
|
//Sort Records
|
|
|
|
$this->webHandler->getDedimaniaData()->sortRecords();
|
2014-05-04 00:36:20 +02:00
|
|
|
|
|
|
|
// Update ranks
|
2017-05-19 23:53:21 +02:00
|
|
|
$this->webHandler->getDedimaniaData()->updateRanks();
|
|
|
|
|
|
|
|
$this->maniaControl->getCallbackManager()->triggerCallback(self::CB_DEDIMANIA_UPDATED, $this->webHandler->getDedimaniaData()->records);
|
2014-05-04 00:36:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-05-09 17:31:29 +02:00
|
|
|
* Update the replay values for the given record
|
2014-05-04 00:36:20 +02:00
|
|
|
*
|
2014-05-09 17:31:29 +02:00
|
|
|
* @param RecordData $record
|
2014-05-04 00:36:20 +02:00
|
|
|
*/
|
|
|
|
private function setRecordReplays(RecordData &$record) {
|
|
|
|
// Set validation replay
|
2017-05-19 23:53:21 +02:00
|
|
|
//TODO verify why it can be that login is not set
|
|
|
|
if (!$record->login) {
|
|
|
|
return;
|
2014-05-04 00:36:20 +02:00
|
|
|
}
|
|
|
|
|
2017-05-19 23:53:21 +02:00
|
|
|
$validationReplay = $this->maniaControl->getServer()->getValidationReplay($record->login);
|
|
|
|
if ($validationReplay) {
|
|
|
|
$record->vReplay = $validationReplay;
|
2017-05-19 23:55:45 +02:00
|
|
|
} else {
|
2017-05-19 23:53:21 +02:00
|
|
|
return;
|
|
|
|
}
|
2017-05-12 21:28:26 +02:00
|
|
|
|
2014-05-04 00:36:20 +02:00
|
|
|
// Set ghost replay
|
|
|
|
if ($record->rank <= 1) {
|
2017-05-15 19:30:22 +02:00
|
|
|
$dataDirectory = $this->maniaControl->getServer()->getDirectory()->getUserDataFolder();
|
2017-05-19 23:53:21 +02:00
|
|
|
if (!isset($this->webHandler->getDedimaniaData()->directoryAccessChecked)) {
|
2014-08-13 11:14:29 +02:00
|
|
|
$access = $this->maniaControl->getServer()->checkAccess($dataDirectory);
|
2014-05-04 00:36:20 +02:00
|
|
|
if (!$access) {
|
|
|
|
trigger_error("No access to the servers data directory. Can't retrieve ghost replays.");
|
|
|
|
}
|
2017-05-19 23:53:21 +02:00
|
|
|
$this->webHandler->getDedimaniaData()->directoryAccessChecked = $access;
|
2014-05-04 00:36:20 +02:00
|
|
|
}
|
2017-05-19 23:53:21 +02:00
|
|
|
if ($this->webHandler->getDedimaniaData()->directoryAccessChecked) {
|
2014-08-13 11:14:29 +02:00
|
|
|
$ghostReplay = $this->maniaControl->getServer()->getGhostReplay($record->login);
|
2014-05-04 00:36:20 +02:00
|
|
|
if ($ghostReplay) {
|
|
|
|
$record->top1GReplay = $ghostReplay;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle PlayerManialinkPageAnswer callback
|
|
|
|
*
|
2017-06-22 15:07:00 +02:00
|
|
|
* @internal
|
2014-05-04 00:36:20 +02:00
|
|
|
* @param array $callback
|
|
|
|
*/
|
|
|
|
public function handleManialinkPageAnswer(array $callback) {
|
|
|
|
$actionId = $callback[1][2];
|
2017-05-12 21:06:43 +02:00
|
|
|
//TODO use manialinkpageanswerlistener
|
2014-05-04 00:36:20 +02:00
|
|
|
$login = $callback[1][1];
|
2014-08-13 11:14:29 +02:00
|
|
|
$player = $this->maniaControl->getPlayerManager()->getPlayer($login);
|
2014-05-04 00:36:20 +02:00
|
|
|
|
2014-06-14 14:32:29 +02:00
|
|
|
if ($actionId === self::ACTION_SHOW_DEDIRECORDSLIST) {
|
2014-05-04 00:36:20 +02:00
|
|
|
$this->showDediRecordsList(array(), $player);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-22 15:07:00 +02:00
|
|
|
/**
|
|
|
|
* Process Dedimania Webreqests at end of Loop
|
|
|
|
*
|
|
|
|
* @internal
|
|
|
|
*/
|
|
|
|
public function handleAfterLoop(){
|
|
|
|
$this->webHandler->callDedimania();
|
|
|
|
}
|
|
|
|
|
2014-05-04 00:36:20 +02:00
|
|
|
/**
|
|
|
|
* Shows a ManiaLink list with the local records.
|
|
|
|
*
|
2017-06-22 15:07:00 +02:00
|
|
|
* @api
|
2014-05-04 00:36:20 +02:00
|
|
|
* @param array $chat
|
|
|
|
* @param Player $player
|
|
|
|
*/
|
|
|
|
public function showDediRecordsList(array $chat, Player $player) {
|
2014-08-13 11:14:29 +02:00
|
|
|
$width = $this->maniaControl->getManialinkManager()->getStyleManager()->getListWidgetsWidth();
|
|
|
|
$height = $this->maniaControl->getManialinkManager()->getStyleManager()->getListWidgetsHeight();
|
2014-05-04 00:36:20 +02:00
|
|
|
|
|
|
|
// get PlayerList
|
2017-05-19 23:53:21 +02:00
|
|
|
$records = $this->webHandler->getDedimaniaData()->records;
|
2014-05-04 00:36:20 +02:00
|
|
|
if (!$records) {
|
2014-08-13 11:14:29 +02:00
|
|
|
$this->maniaControl->getChat()->sendInformation('There are no Dedimania records on this map!');
|
2014-05-04 00:36:20 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
//create manialink
|
|
|
|
$maniaLink = new ManiaLink(ManialinkManager::MAIN_MLID);
|
|
|
|
$script = $maniaLink->getScript();
|
|
|
|
$paging = new Paging();
|
|
|
|
$script->addFeature($paging);
|
|
|
|
|
|
|
|
// Main frame
|
2014-08-13 11:14:29 +02:00
|
|
|
$frame = $this->maniaControl->getManialinkManager()->getStyleManager()->getDefaultListFrame($script, $paging);
|
2017-03-25 19:15:50 +01:00
|
|
|
$maniaLink->addChild($frame);
|
2014-05-04 00:36:20 +02:00
|
|
|
|
|
|
|
// Start offsets
|
2014-06-14 15:48:27 +02:00
|
|
|
$posX = -$width / 2;
|
|
|
|
$posY = $height / 2;
|
2014-05-04 00:36:20 +02:00
|
|
|
|
|
|
|
// Predefine Description Label
|
2014-08-13 11:14:29 +02:00
|
|
|
$descriptionLabel = $this->maniaControl->getManialinkManager()->getStyleManager()->getDefaultDescriptionLabel();
|
2017-03-25 19:15:50 +01:00
|
|
|
$frame->addChild($descriptionLabel);
|
2014-05-04 00:36:20 +02:00
|
|
|
|
|
|
|
// Headline
|
|
|
|
$headFrame = new Frame();
|
2017-03-25 19:15:50 +01:00
|
|
|
$frame->addChild($headFrame);
|
2014-06-14 15:48:27 +02:00
|
|
|
$headFrame->setY($posY - 5);
|
2014-08-03 01:34:18 +02:00
|
|
|
$array = array('Rank' => $posX + 5, 'Nickname' => $posX + 18, 'Login' => $posX + 70, 'Time' => $posX + 101);
|
2014-08-13 11:14:29 +02:00
|
|
|
$this->maniaControl->getManialinkManager()->labelLine($headFrame, $array);
|
2014-05-04 00:36:20 +02:00
|
|
|
|
2014-06-14 15:48:27 +02:00
|
|
|
$index = 0;
|
|
|
|
$posY = $height / 2 - 10;
|
2014-05-15 17:45:08 +02:00
|
|
|
$pageFrame = null;
|
|
|
|
|
2014-05-04 00:36:20 +02:00
|
|
|
foreach ($records as $listRecord) {
|
2014-06-14 15:48:27 +02:00
|
|
|
if ($index % 15 === 0) {
|
2014-05-04 00:36:20 +02:00
|
|
|
$pageFrame = new Frame();
|
2017-03-25 19:15:50 +01:00
|
|
|
$frame->addChild($pageFrame);
|
2014-06-14 15:48:27 +02:00
|
|
|
$posY = $height / 2 - 10;
|
2017-05-08 17:45:16 +02:00
|
|
|
$paging->addPageControl($pageFrame);
|
2014-05-04 00:36:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$recordFrame = new Frame();
|
2017-03-25 19:15:50 +01:00
|
|
|
$pageFrame->addChild($recordFrame);
|
2014-05-04 00:36:20 +02:00
|
|
|
|
2014-06-14 15:48:27 +02:00
|
|
|
if ($index % 2 !== 0) {
|
2014-05-04 00:36:20 +02:00
|
|
|
$lineQuad = new Quad_BgsPlayerCard();
|
2017-03-25 19:15:50 +01:00
|
|
|
$recordFrame->addChild($lineQuad);
|
2014-05-04 00:36:20 +02:00
|
|
|
$lineQuad->setSize($width, 4);
|
|
|
|
$lineQuad->setSubStyle($lineQuad::SUBSTYLE_BgPlayerCardBig);
|
2017-05-21 23:11:52 +02:00
|
|
|
$lineQuad->setZ(-0.001);
|
2014-05-04 00:36:20 +02:00
|
|
|
}
|
|
|
|
|
2017-05-21 23:11:52 +02:00
|
|
|
if (strlen($listRecord->nickname) < 2) {
|
|
|
|
$listRecord->nickname = $listRecord->login;
|
2014-05-04 00:36:20 +02:00
|
|
|
}
|
2017-05-21 23:11:52 +02:00
|
|
|
$array = array($listRecord->rank => $posX + 5, '$fff' . $listRecord->nickname => $posX + 18, $listRecord->login => $posX + 70, Formatter::formatTime($listRecord->best) => $posX + 101);
|
2014-08-13 11:14:29 +02:00
|
|
|
$this->maniaControl->getManialinkManager()->labelLine($recordFrame, $array);
|
2014-05-04 00:36:20 +02:00
|
|
|
|
2014-06-14 15:48:27 +02:00
|
|
|
$recordFrame->setY($posY);
|
2014-05-04 00:36:20 +02:00
|
|
|
|
2014-06-14 15:48:27 +02:00
|
|
|
$posY -= 4;
|
|
|
|
$index++;
|
2014-05-04 00:36:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Render and display xml
|
2014-08-13 11:14:29 +02:00
|
|
|
$this->maniaControl->getManialinkManager()->displayWidget($maniaLink, $player, 'DediRecordsList');
|
2014-05-04 00:36:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function to retrieve the dedimania records on the current map
|
|
|
|
*
|
2017-06-22 15:07:00 +02:00
|
|
|
* @api
|
2014-07-20 00:24:25 +02:00
|
|
|
* @return RecordData[]
|
2014-05-04 00:36:20 +02:00
|
|
|
*/
|
|
|
|
public function getDedimaniaRecords() {
|
2017-05-20 10:27:29 +02:00
|
|
|
return $this->webHandler->getDedimaniaData()->records;
|
2014-05-04 00:36:20 +02:00
|
|
|
}
|
|
|
|
|
2017-05-21 23:11:52 +02:00
|
|
|
/**
|
|
|
|
* Update the RecordWidget variables
|
2017-06-22 15:07:00 +02:00
|
|
|
*
|
2017-05-21 23:11:52 +02:00
|
|
|
*/
|
|
|
|
private function updateRecordWidget() {
|
2017-05-22 16:48:03 +02:00
|
|
|
$width = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_WIDGET_WIDTH);
|
|
|
|
$lineHeight = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_WIDGET_LINE_HEIGHT);
|
2017-05-21 23:11:52 +02:00
|
|
|
|
|
|
|
$this->recordWidget->setWidth($width);
|
|
|
|
$this->recordWidget->setLineHeight($lineHeight);
|
|
|
|
|
|
|
|
$this->webHandler->maniaLinkUpdateNeeded();
|
|
|
|
}
|
|
|
|
|
2017-06-22 15:07:00 +02:00
|
|
|
/**
|
|
|
|
* Handle settings Changed
|
|
|
|
*
|
|
|
|
* @internal
|
|
|
|
* @param \ManiaControl\Settings\Setting $setting
|
|
|
|
*/
|
2017-05-22 16:48:03 +02:00
|
|
|
public function handleSettingChanged(Setting $setting) {
|
2017-05-21 23:11:52 +02:00
|
|
|
if (!$setting->belongsToClass($this)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
$this->updateRecordWidget();
|
|
|
|
}
|
|
|
|
|
2017-06-22 15:07:00 +02:00
|
|
|
|
2014-05-04 00:36:20 +02:00
|
|
|
/**
|
|
|
|
* @see \ManiaControl\Plugins\Plugin::unload()
|
|
|
|
*/
|
|
|
|
public function unload() {
|
2020-03-16 10:56:38 +01:00
|
|
|
$this->maniaControl->getManialinkManager()->hideManialink(self::MLID_DEDIMANIA);
|
2014-05-04 00:36:20 +02:00
|
|
|
}
|
2017-05-19 23:53:21 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @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 'Dedimania Plugin for TrackMania';
|
|
|
|
}
|
2014-07-20 00:19:54 +02:00
|
|
|
}
|