2013-11-25 02:01:15 +01:00
|
|
|
<?php
|
2014-04-27 16:22:12 +02:00
|
|
|
|
|
|
|
namespace MCTeam;
|
|
|
|
|
2014-03-01 12:18:42 +01:00
|
|
|
use FML\Controls\Control;
|
|
|
|
use FML\Controls\Frame;
|
|
|
|
use FML\Controls\Label;
|
|
|
|
use FML\Controls\Quad;
|
2014-04-17 00:43:29 +02:00
|
|
|
use FML\Controls\Quads\Quad_BgsPlayerCard;
|
2014-03-01 12:18:42 +01:00
|
|
|
use FML\ManiaLink;
|
2014-04-27 16:22:12 +02:00
|
|
|
use FML\Script\Features\Paging;
|
2014-04-27 01:30:40 +02:00
|
|
|
use ManiaControl\Admin\AuthenticationManager;
|
2014-03-01 12:18:42 +01:00
|
|
|
use ManiaControl\Callbacks\CallbackListener;
|
|
|
|
use ManiaControl\Callbacks\CallbackManager;
|
2014-04-28 20:50:38 +02:00
|
|
|
use ManiaControl\Callbacks\Callbacks;
|
2014-01-31 00:04:40 +01:00
|
|
|
use ManiaControl\Callbacks\TimerListener;
|
2014-04-17 00:43:29 +02:00
|
|
|
use ManiaControl\Commands\CommandListener;
|
|
|
|
use ManiaControl\Settings\SettingManager;
|
2013-11-25 02:01:15 +01:00
|
|
|
use ManiaControl\Formatter;
|
|
|
|
use ManiaControl\ManiaControl;
|
|
|
|
use ManiaControl\Maps\Map;
|
2014-03-01 12:18:42 +01:00
|
|
|
use ManiaControl\Maps\MapManager;
|
2014-04-17 00:43:29 +02:00
|
|
|
use ManiaControl\Manialinks\ManialinkManager;
|
2013-11-25 02:01:15 +01:00
|
|
|
use ManiaControl\Players\Player;
|
|
|
|
use ManiaControl\Players\PlayerManager;
|
|
|
|
use ManiaControl\Plugins\Plugin;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ManiaControl Local Records Plugin
|
2014-04-28 17:54:25 +02:00
|
|
|
*
|
2013-11-25 02:01:15 +01:00
|
|
|
* @author steeffeen
|
2014-04-13 12:00:08 +02:00
|
|
|
* @copyright ManiaControl Copyright © 2014 ManiaControl Team
|
|
|
|
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
2013-11-25 02:01:15 +01:00
|
|
|
*/
|
2014-04-17 00:43:29 +02:00
|
|
|
class LocalRecordsPlugin implements CallbackListener, CommandListener, TimerListener, Plugin {
|
2014-04-28 17:54:25 +02:00
|
|
|
/*
|
2013-11-25 02:01:15 +01:00
|
|
|
* Constants
|
|
|
|
*/
|
2014-04-28 17:54:25 +02:00
|
|
|
const ID = 7;
|
|
|
|
const VERSION = 0.1;
|
|
|
|
const MLID_RECORDS = 'ml_local_records';
|
|
|
|
const TABLE_RECORDS = 'mc_localrecords';
|
|
|
|
const SETTING_WIDGET_TITLE = 'Widget Title';
|
|
|
|
const SETTING_WIDGET_POSX = 'Widget Position: X';
|
|
|
|
const SETTING_WIDGET_POSY = 'Widget Position: Y';
|
|
|
|
const SETTING_WIDGET_WIDTH = 'Widget Width';
|
|
|
|
const SETTING_WIDGET_LINESCOUNT = 'Widget Displayed Lines Count';
|
|
|
|
const SETTING_WIDGET_LINEHEIGHT = 'Widget Line Height';
|
|
|
|
const SETTING_WIDGET_ENABLE = 'Enable Local Records Widget';
|
|
|
|
const SETTING_NOTIFY_ONLY_DRIVER = 'Notify only the Driver on New Records';
|
2013-12-31 15:30:25 +01:00
|
|
|
const SETTING_NOTIFY_BEST_RECORDS = 'Notify Publicly only for the X Best Records';
|
2014-02-16 13:16:11 +01:00
|
|
|
const SETTING_ADJUST_OUTER_BORDER = 'Adjust outer Border to Number of actual Records';
|
2014-04-28 17:54:25 +02:00
|
|
|
const CB_LOCALRECORDS_CHANGED = 'LocalRecords.Changed';
|
|
|
|
const ACTION_SHOW_RECORDSLIST = 'LocalRecords.ShowRecordsList';
|
|
|
|
|
2014-02-19 15:44:00 +01:00
|
|
|
/*
|
|
|
|
* Private Properties
|
2013-11-25 02:01:15 +01:00
|
|
|
*/
|
2013-12-31 15:27:40 +01:00
|
|
|
/**
|
2014-04-28 17:54:25 +02:00
|
|
|
*
|
2013-12-31 15:27:40 +01:00
|
|
|
* @var maniaControl $maniaControl
|
|
|
|
*/
|
2013-12-14 23:29:17 +01:00
|
|
|
private $maniaControl = null;
|
2013-11-25 02:01:15 +01:00
|
|
|
private $updateManialink = false;
|
2014-04-27 11:02:46 +02:00
|
|
|
private $checkpoints = array();
|
2013-11-25 02:01:15 +01:00
|
|
|
|
2014-01-27 20:39:10 +01:00
|
|
|
/**
|
|
|
|
* Prepares the Plugin
|
2014-04-28 17:54:25 +02:00
|
|
|
*
|
2014-01-27 20:39:10 +01:00
|
|
|
* @param ManiaControl $maniaControl
|
|
|
|
* @return mixed
|
|
|
|
*/
|
|
|
|
public static function prepare(ManiaControl $maniaControl) {
|
2014-04-28 17:54:25 +02:00
|
|
|
// do nothing
|
2014-01-27 20:39:10 +01:00
|
|
|
}
|
|
|
|
|
2013-11-25 02:01:15 +01:00
|
|
|
/**
|
2014-04-28 17:54:25 +02:00
|
|
|
*
|
2013-12-14 23:29:17 +01:00
|
|
|
* @see \ManiaControl\Plugins\Plugin::load()
|
2013-11-25 02:01:15 +01:00
|
|
|
*/
|
2013-12-14 23:29:17 +01:00
|
|
|
public function load(ManiaControl $maniaControl) {
|
2013-11-25 02:01:15 +01:00
|
|
|
$this->maniaControl = $maniaControl;
|
|
|
|
$this->initTables();
|
2014-04-28 17:54:25 +02:00
|
|
|
|
2013-11-28 03:47:08 +01:00
|
|
|
// Init settings
|
|
|
|
$this->maniaControl->settingManager->initSetting($this, self::SETTING_WIDGET_TITLE, 'Local Records');
|
|
|
|
$this->maniaControl->settingManager->initSetting($this, self::SETTING_WIDGET_POSX, -139.);
|
2014-02-20 12:20:35 +01:00
|
|
|
$this->maniaControl->settingManager->initSetting($this, self::SETTING_WIDGET_POSY, 75);
|
2013-11-28 03:47:08 +01:00
|
|
|
$this->maniaControl->settingManager->initSetting($this, self::SETTING_WIDGET_WIDTH, 40.);
|
2014-02-20 12:20:35 +01:00
|
|
|
$this->maniaControl->settingManager->initSetting($this, self::SETTING_WIDGET_LINESCOUNT, 15);
|
2013-11-28 03:47:08 +01:00
|
|
|
$this->maniaControl->settingManager->initSetting($this, self::SETTING_WIDGET_LINEHEIGHT, 4.);
|
2014-04-28 17:54:25 +02:00
|
|
|
$this->maniaControl->settingManager->initSetting($this, self::SETTING_WIDGET_ENABLE, true);
|
2013-12-31 15:27:40 +01:00
|
|
|
$this->maniaControl->settingManager->initSetting($this, self::SETTING_NOTIFY_ONLY_DRIVER, false);
|
2013-12-31 15:30:25 +01:00
|
|
|
$this->maniaControl->settingManager->initSetting($this, self::SETTING_NOTIFY_BEST_RECORDS, -1);
|
2014-02-16 13:16:11 +01:00
|
|
|
$this->maniaControl->settingManager->initSetting($this, self::SETTING_ADJUST_OUTER_BORDER, false);
|
2014-04-28 17:54:25 +02:00
|
|
|
|
2013-11-25 02:01:15 +01:00
|
|
|
// Register for callbacks
|
2014-01-31 00:04:40 +01:00
|
|
|
$this->maniaControl->timerManager->registerTimerListening($this, 'handle1Second', 1000);
|
2014-02-19 12:53:06 +01:00
|
|
|
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_AFTERINIT, $this, 'handleAfterInit');
|
2014-04-28 20:50:38 +02:00
|
|
|
$this->maniaControl->callbackManager->registerCallbackListener(Callbacks::BEGINMAP, $this, 'handleMapBegin');
|
2014-03-01 12:18:42 +01:00
|
|
|
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_TM_PLAYERFINISH, $this, 'handlePlayerFinish');
|
|
|
|
$this->maniaControl->callbackManager->registerCallbackListener(PlayerManager::CB_PLAYERCONNECT, $this, 'handlePlayerConnect');
|
2014-04-27 11:02:46 +02:00
|
|
|
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_TM_PLAYERCHECKPOINT, $this, 'handlePlayerCheckpoint');
|
2014-04-28 17:54:25 +02:00
|
|
|
$this->maniaControl->callbackManager->registerCallbackListener(SettingManager::CB_SETTINGS_CHANGED, $this, 'handleSettingsChanged');
|
2014-04-17 01:46:59 +02:00
|
|
|
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MP_PLAYERMANIALINKPAGEANSWER, $this, 'handleManialinkPageAnswer');
|
2014-04-17 00:43:29 +02:00
|
|
|
$this->maniaControl->commandManager->registerCommandListener('records', $this, 'showRecordsList');
|
2014-04-27 01:30:40 +02:00
|
|
|
$this->maniaControl->commandManager->registerCommandListener('delrec', $this, 'deleteRecord', true);
|
2014-04-28 17:54:25 +02:00
|
|
|
|
2013-12-14 23:29:17 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-04-28 17:54:25 +02:00
|
|
|
*
|
2013-12-14 23:29:17 +01:00
|
|
|
* @see \ManiaControl\Plugins\Plugin::unload()
|
|
|
|
*/
|
|
|
|
public function unload() {
|
|
|
|
$this->maniaControl->callbackManager->unregisterCallbackListener($this);
|
2014-02-01 14:50:24 +01:00
|
|
|
$this->maniaControl->timerManager->unregisterTimerListenings($this);
|
2013-11-25 02:01:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initialize needed database tables
|
|
|
|
*/
|
|
|
|
private function initTables() {
|
|
|
|
$mysqli = $this->maniaControl->database->mysqli;
|
2014-04-28 17:54:25 +02:00
|
|
|
$query = "CREATE TABLE IF NOT EXISTS `" . self::TABLE_RECORDS . "` (
|
2013-11-25 02:01:15 +01:00
|
|
|
`index` int(11) NOT NULL AUTO_INCREMENT,
|
|
|
|
`mapIndex` int(11) NOT NULL,
|
|
|
|
`playerIndex` int(11) NOT NULL,
|
|
|
|
`time` int(11) NOT NULL,
|
|
|
|
`changed` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
|
|
|
PRIMARY KEY (`index`),
|
|
|
|
UNIQUE KEY `player_map_record` (`mapIndex`,`playerIndex`)
|
|
|
|
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1;";
|
2013-11-28 03:47:08 +01:00
|
|
|
$mysqli->query($query);
|
|
|
|
if ($mysqli->error) {
|
|
|
|
trigger_error($mysqli->error, E_USER_ERROR);
|
2013-11-25 02:01:15 +01:00
|
|
|
}
|
2014-04-28 17:54:25 +02:00
|
|
|
|
2014-04-27 11:02:46 +02:00
|
|
|
$mysqli->query("ALTER TABLE `" . self::TABLE_RECORDS . "` ADD `checkpoints` TEXT CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL");
|
|
|
|
if ($mysqli->error) {
|
2014-04-28 17:54:25 +02:00
|
|
|
if (!strstr($mysqli->error, 'Duplicate')) {
|
2014-04-27 11:02:46 +02:00
|
|
|
trigger_error($mysqli->error, E_USER_ERROR);
|
|
|
|
}
|
|
|
|
}
|
2013-11-25 02:01:15 +01:00
|
|
|
}
|
|
|
|
|
2013-12-09 10:04:22 +01:00
|
|
|
/**
|
2014-04-28 17:54:25 +02:00
|
|
|
*
|
2013-12-09 10:04:22 +01:00
|
|
|
* @see \ManiaControl\Plugins\Plugin::getId()
|
|
|
|
*/
|
|
|
|
public static function getId() {
|
|
|
|
return self::ID;
|
|
|
|
}
|
|
|
|
|
2013-12-03 22:21:17 +01:00
|
|
|
/**
|
2014-04-28 17:54:25 +02:00
|
|
|
*
|
2013-12-03 22:21:17 +01:00
|
|
|
* @see \ManiaControl\Plugins\Plugin::getName()
|
|
|
|
*/
|
|
|
|
public static function getName() {
|
|
|
|
return 'Local Records Plugin';
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-04-28 17:54:25 +02:00
|
|
|
*
|
2013-12-03 22:21:17 +01:00
|
|
|
* @see \ManiaControl\Plugins\Plugin::getVersion()
|
|
|
|
*/
|
|
|
|
public static function getVersion() {
|
|
|
|
return self::VERSION;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-04-28 17:54:25 +02:00
|
|
|
*
|
2013-12-03 22:21:17 +01:00
|
|
|
* @see \ManiaControl\Plugins\Plugin::getAuthor()
|
|
|
|
*/
|
|
|
|
public static function getAuthor() {
|
|
|
|
return 'steeffeen';
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-04-28 17:54:25 +02:00
|
|
|
*
|
2013-12-03 22:21:17 +01:00
|
|
|
* @see \ManiaControl\Plugins\Plugin::getDescription()
|
|
|
|
*/
|
|
|
|
public static function getDescription() {
|
|
|
|
return 'Plugin offering tracking of local records and manialinks to display them.';
|
|
|
|
}
|
|
|
|
|
2013-11-25 02:01:15 +01:00
|
|
|
/**
|
2014-02-16 13:16:11 +01:00
|
|
|
* Handle ManiaControl After Init
|
2013-11-25 02:01:15 +01:00
|
|
|
*/
|
2014-02-19 15:44:00 +01:00
|
|
|
public function handleAfterInit() {
|
2013-11-25 02:01:15 +01:00
|
|
|
$this->updateManialink = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle 1Second callback
|
2014-04-28 17:54:25 +02:00
|
|
|
*
|
2014-01-31 00:04:40 +01:00
|
|
|
* @param $time
|
2013-11-25 02:01:15 +01:00
|
|
|
*/
|
2014-01-31 00:04:40 +01:00
|
|
|
public function handle1Second($time) {
|
2014-04-28 17:54:25 +02:00
|
|
|
if (!$this->updateManialink) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->updateManialink = false;
|
|
|
|
if ($this->maniaControl->settingManager->getSetting($this, self::SETTING_WIDGET_ENABLE)) {
|
|
|
|
$manialink = $this->buildManialink();
|
2014-04-17 03:42:27 +02:00
|
|
|
$this->maniaControl->manialinkManager->sendManialink($manialink);
|
|
|
|
}
|
2014-04-28 17:54:25 +02:00
|
|
|
}
|
2014-04-17 00:43:29 +02:00
|
|
|
|
2014-04-28 17:54:25 +02:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
2013-11-25 02:01:15 +01:00
|
|
|
|
2014-04-27 11:02:46 +02:00
|
|
|
/**
|
|
|
|
* Handle PlayerCheckpoint callback
|
2014-04-28 17:54:25 +02:00
|
|
|
*
|
2014-04-27 11:02:46 +02:00
|
|
|
* @param $callback
|
|
|
|
*/
|
|
|
|
public function handlePlayerCheckpoint($callback) {
|
2014-04-28 17:54:25 +02:00
|
|
|
$data = $callback[1];
|
2014-04-27 11:02:46 +02:00
|
|
|
$login = $data[1];
|
2014-04-28 17:54:25 +02:00
|
|
|
$time = $data[2];
|
|
|
|
// $lap = $data[3];
|
2014-04-27 11:02:46 +02:00
|
|
|
$cpIndex = $data[4];
|
|
|
|
if (!isset($this->checkpoints[$login]) || $cpIndex <= 0) {
|
|
|
|
$this->checkpoints[$login] = array();
|
|
|
|
}
|
|
|
|
$this->checkpoints[$login][$cpIndex] = $time;
|
|
|
|
}
|
|
|
|
|
2013-11-25 02:01:15 +01:00
|
|
|
/**
|
|
|
|
* Handle PlayerConnect callback
|
2014-04-28 17:54:25 +02:00
|
|
|
*
|
2014-03-01 12:18:42 +01:00
|
|
|
* @param Player $player
|
2013-11-25 02:01:15 +01:00
|
|
|
*/
|
2014-03-01 12:18:42 +01:00
|
|
|
public function handlePlayerConnect(Player $player) {
|
2013-11-25 02:01:15 +01:00
|
|
|
$this->updateManialink = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle BeginMap callback
|
2014-04-28 17:54:25 +02:00
|
|
|
*
|
2014-02-19 16:27:56 +01:00
|
|
|
* @param Map $map
|
2013-11-25 02:01:15 +01:00
|
|
|
*/
|
2014-02-19 16:27:56 +01:00
|
|
|
public function handleMapBegin(Map $map) {
|
2013-11-25 02:01:15 +01:00
|
|
|
$this->updateManialink = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle PlayerFinish callback
|
2014-04-28 17:54:25 +02:00
|
|
|
*
|
2013-12-31 15:27:40 +01:00
|
|
|
* @param array $callback
|
2013-11-25 02:01:15 +01:00
|
|
|
*/
|
|
|
|
public function handlePlayerFinish(array $callback) {
|
|
|
|
$data = $callback[1];
|
|
|
|
if ($data[0] <= 0 || $data[2] <= 0) {
|
|
|
|
// Invalid player or time
|
|
|
|
return;
|
|
|
|
}
|
2014-04-28 17:54:25 +02:00
|
|
|
|
|
|
|
$login = $data[1];
|
2013-11-25 02:01:15 +01:00
|
|
|
$player = $this->maniaControl->playerManager->getPlayer($login);
|
|
|
|
if (!$player) {
|
|
|
|
// Invalid player
|
|
|
|
return;
|
|
|
|
}
|
2014-04-28 17:54:25 +02:00
|
|
|
|
2013-11-25 02:01:15 +01:00
|
|
|
$time = $data[2];
|
2014-04-28 17:54:25 +02:00
|
|
|
$map = $this->maniaControl->mapManager->getCurrentMap();
|
|
|
|
|
2013-11-25 02:01:15 +01:00
|
|
|
// Check old record of the player
|
|
|
|
$oldRecord = $this->getLocalRecord($map, $player);
|
2014-04-28 17:54:25 +02:00
|
|
|
$oldRank = -1;
|
2013-11-25 02:01:15 +01:00
|
|
|
if ($oldRecord) {
|
2014-04-28 17:54:25 +02:00
|
|
|
$oldRank = $oldRecord->rank;
|
2013-11-25 02:01:15 +01:00
|
|
|
if ($oldRecord->time < $time) {
|
|
|
|
// Not improved
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if ($oldRecord->time == $time) {
|
|
|
|
// Same time
|
2014-04-28 17:54:25 +02:00
|
|
|
$message = '$<' . $player->nickname . '$> equalized his/her $<$ff0' . $oldRecord->rank . '.$> Local Record: $<$fff' . Formatter::formatTime($oldRecord->time) . '$>!';
|
|
|
|
$this->maniaControl->chat->sendInformation('$3c0' . $message);
|
2013-11-25 02:01:15 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2014-04-28 17:54:25 +02:00
|
|
|
|
2013-11-25 02:01:15 +01:00
|
|
|
// Save time
|
|
|
|
$mysqli = $this->maniaControl->database->mysqli;
|
2014-04-28 17:54:25 +02:00
|
|
|
$query = "INSERT INTO `" . self::TABLE_RECORDS . "` (
|
2013-11-25 02:01:15 +01:00
|
|
|
`mapIndex`,
|
|
|
|
`playerIndex`,
|
2014-04-27 11:02:46 +02:00
|
|
|
`time`,
|
|
|
|
`checkpoints`
|
2013-11-25 02:01:15 +01:00
|
|
|
) VALUES (
|
|
|
|
{$map->index},
|
|
|
|
{$player->index},
|
2014-04-27 11:02:46 +02:00
|
|
|
{$time},
|
|
|
|
'{$this->getCheckpoints($player->login)}'
|
2013-11-25 02:01:15 +01:00
|
|
|
) ON DUPLICATE KEY UPDATE
|
2014-04-27 11:02:46 +02:00
|
|
|
`time` = VALUES(`time`),
|
|
|
|
`checkpoints` = VALUES(`checkpoints`);";
|
2013-12-09 13:45:58 +01:00
|
|
|
$mysqli->query($query);
|
2013-11-25 02:01:15 +01:00
|
|
|
if ($mysqli->error) {
|
|
|
|
trigger_error($mysqli->error);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
$this->updateManialink = true;
|
2014-04-28 17:54:25 +02:00
|
|
|
|
2013-11-25 02:01:15 +01:00
|
|
|
// Announce record
|
2014-04-28 17:54:25 +02:00
|
|
|
$newRecord = $this->getLocalRecord($map, $player);
|
2014-04-17 22:41:34 +02:00
|
|
|
$this->maniaControl->callbackManager->triggerCallback(self::CB_LOCALRECORDS_CHANGED, $newRecord);
|
2014-04-28 17:54:25 +02:00
|
|
|
|
|
|
|
$notifyOnlyDriver = $this->maniaControl->settingManager->getSetting($this, self::SETTING_NOTIFY_ONLY_DRIVER);
|
2013-12-31 15:30:25 +01:00
|
|
|
$notifyOnlyBestRecords = $this->maniaControl->settingManager->getSetting($this, self::SETTING_NOTIFY_BEST_RECORDS);
|
|
|
|
if ($notifyOnlyDriver || $notifyOnlyBestRecords > 0 && $newRecord->rank > $notifyOnlyBestRecords) {
|
2014-04-19 00:16:19 +02:00
|
|
|
$improvement = ((!$oldRecord || $newRecord->rank < $oldRecord->rank) ? 'gained the' : 'improved your');
|
2014-04-30 17:05:24 +02:00
|
|
|
$message = 'You ' . $improvement . ' $<$ff0' . $newRecord->rank . '.$> Local Record: $<$fff' . Formatter::formatTime($newRecord->time) . '$>';
|
2014-04-28 17:54:25 +02:00
|
|
|
if ($oldRecord) $oldRank = ($improvement == 'improved your') ? '' : $oldRecord->rank . '. ';
|
2014-04-30 17:05:24 +02:00
|
|
|
if ($oldRecord) $message .= ' ($<$ff0' . $oldRank . '$>$<$fff-' . Formatter::formatTime(($oldRecord->time - $newRecord->time)) . '$>!';
|
|
|
|
$this->maniaControl->chat->sendInformation('$3c0' . $message.'!', $player->login);
|
2014-04-28 17:54:25 +02:00
|
|
|
}
|
|
|
|
else {
|
2014-01-01 18:42:43 +01:00
|
|
|
$improvement = ((!$oldRecord || $newRecord->rank < $oldRecord->rank) ? 'gained the' : 'improved the');
|
2014-04-30 17:05:24 +02:00
|
|
|
$message = '$<' . $player->nickname . '$> ' . $improvement . ' $<$ff0' . $newRecord->rank . '.$> Local Record: $<$fff' . Formatter::formatTime($newRecord->time) . '$>';
|
2014-04-28 17:54:25 +02:00
|
|
|
if ($oldRecord) $oldRank = ($improvement == 'improved the') ? '' : $oldRecord->rank . '. ';
|
2014-04-30 17:05:24 +02:00
|
|
|
if ($oldRecord) $message .= ' ($<$ff0' . $oldRank . '$>$<$fff-' . Formatter::formatTime(($oldRecord->time - $newRecord->time)) . '$>)';
|
|
|
|
$this->maniaControl->chat->sendInformation('$3c0' . $message.'!');
|
2013-11-25 02:01:15 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-17 01:46:59 +02:00
|
|
|
/**
|
|
|
|
* Handle PlayerManialinkPageAnswer callback
|
2014-04-28 17:54:25 +02:00
|
|
|
*
|
2014-04-17 01:46:59 +02:00
|
|
|
* @param array $callback
|
|
|
|
*/
|
|
|
|
public function handleManialinkPageAnswer(array $callback) {
|
2014-04-28 17:54:25 +02:00
|
|
|
$actionId = $callback[1][2];
|
|
|
|
|
|
|
|
$login = $callback[1][1];
|
2014-04-17 01:46:59 +02:00
|
|
|
$player = $this->maniaControl->playerManager->getPlayer($login);
|
2014-04-28 17:54:25 +02:00
|
|
|
|
|
|
|
if ($actionId == self::ACTION_SHOW_RECORDSLIST) {
|
2014-04-17 01:46:59 +02:00
|
|
|
$this->showRecordsList(array(), $player);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-28 17:54:25 +02:00
|
|
|
/**
|
|
|
|
* Delete a Player's record
|
|
|
|
*
|
|
|
|
* @param array $chat
|
|
|
|
* @param Player $player
|
|
|
|
*/
|
2014-04-27 01:30:40 +02:00
|
|
|
public function deleteRecord(array $chat, Player $player) {
|
2014-04-28 17:54:25 +02:00
|
|
|
if (!$this->maniaControl->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_MASTERADMIN)) {
|
2014-04-27 01:30:40 +02:00
|
|
|
$this->maniaControl->authenticationManager->sendNotAllowed($player);
|
|
|
|
return;
|
|
|
|
}
|
2014-04-28 17:54:25 +02:00
|
|
|
|
2014-04-27 01:30:40 +02:00
|
|
|
$chatCommand = explode(' ', $chat[1][2]);
|
2014-04-28 17:54:25 +02:00
|
|
|
$recordId = (int) $chatCommand[1];
|
|
|
|
if (is_integer($recordId)) {
|
2014-04-27 01:30:40 +02:00
|
|
|
$currentMap = $this->maniaControl->mapManager->getCurrentMap();
|
|
|
|
$records = $this->getLocalRecords($currentMap);
|
2014-04-28 17:54:25 +02:00
|
|
|
if (count($records) < $recordId) {
|
|
|
|
$this->maniaControl->chat->sendError('Cannot remove record $<$fff' . $recordId . '$>!', $player);
|
2014-04-27 01:30:40 +02:00
|
|
|
return;
|
|
|
|
}
|
2014-04-28 17:54:25 +02:00
|
|
|
|
2014-04-27 01:30:40 +02:00
|
|
|
$mysqli = $this->maniaControl->database->mysqli;
|
2014-04-28 17:54:25 +02:00
|
|
|
$query = "DELETE FROM `" . self::TABLE_RECORDS . "` WHERE `mapIndex` = " . $currentMap->index . " AND `playerIndex` = " . $player->index . "";
|
2014-04-27 15:12:09 +02:00
|
|
|
$mysqli->query($query);
|
2014-04-27 01:30:40 +02:00
|
|
|
if ($mysqli->error) {
|
|
|
|
trigger_error($mysqli->error);
|
2014-04-28 17:54:25 +02:00
|
|
|
return;
|
2014-04-27 01:30:40 +02:00
|
|
|
}
|
2014-04-28 17:54:25 +02:00
|
|
|
|
2014-04-27 01:30:40 +02:00
|
|
|
$this->maniaControl->callbackManager->triggerCallback(self::CB_LOCALRECORDS_CHANGED, null);
|
2014-04-28 17:54:25 +02:00
|
|
|
$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);
|
2014-04-27 01:30:40 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-17 00:43:29 +02:00
|
|
|
/**
|
|
|
|
* Shows a ManiaLink list with the local records.
|
2014-04-28 17:54:25 +02:00
|
|
|
*
|
|
|
|
* @param array $chat
|
2014-04-17 00:43:29 +02:00
|
|
|
* @param Player $player
|
|
|
|
*/
|
|
|
|
public function showRecordsList(array $chat, Player $player) {
|
2014-04-28 17:54:25 +02:00
|
|
|
$width = $this->maniaControl->manialinkManager->styleManager->getListWidgetsWidth();
|
2014-04-17 00:43:29 +02:00
|
|
|
$height = $this->maniaControl->manialinkManager->styleManager->getListWidgetsHeight();
|
2014-04-28 17:54:25 +02:00
|
|
|
|
2014-04-17 00:43:29 +02:00
|
|
|
// get PlayerList
|
|
|
|
$records = $this->getLocalRecords($this->maniaControl->mapManager->getCurrentMap());
|
2014-04-28 17:54:25 +02:00
|
|
|
|
2014-04-17 00:43:29 +02:00
|
|
|
$pagesId = '';
|
2014-04-17 00:50:44 +02:00
|
|
|
if (count($records) > 15) {
|
2014-04-17 00:43:29 +02:00
|
|
|
$pagesId = 'RecordsListPages';
|
|
|
|
}
|
2014-04-28 17:54:25 +02:00
|
|
|
|
|
|
|
// create manialink
|
2014-04-17 00:43:29 +02:00
|
|
|
$maniaLink = new ManiaLink(ManialinkManager::MAIN_MLID);
|
2014-04-28 17:54:25 +02:00
|
|
|
$script = $maniaLink->getScript();
|
|
|
|
$paging = new Paging();
|
|
|
|
$script->addFeature($paging);
|
|
|
|
|
2014-04-17 00:43:29 +02:00
|
|
|
// Main frame
|
2014-04-27 20:27:51 +02:00
|
|
|
$frame = $this->maniaControl->manialinkManager->styleManager->getDefaultListFrame($script, $paging);
|
2014-04-17 00:43:29 +02:00
|
|
|
$maniaLink->add($frame);
|
2014-04-28 17:54:25 +02:00
|
|
|
|
2014-04-17 00:43:29 +02:00
|
|
|
// Start offsets
|
|
|
|
$x = -$width / 2;
|
|
|
|
$y = $height / 2;
|
2014-04-28 17:54:25 +02:00
|
|
|
|
2014-04-17 00:43:29 +02:00
|
|
|
// Predefine Description Label
|
|
|
|
$descriptionLabel = $this->maniaControl->manialinkManager->styleManager->getDefaultDescriptionLabel();
|
|
|
|
$frame->add($descriptionLabel);
|
2014-04-28 17:54:25 +02:00
|
|
|
|
2014-04-17 00:43:29 +02:00
|
|
|
// Headline
|
|
|
|
$headFrame = new Frame();
|
|
|
|
$frame->add($headFrame);
|
|
|
|
$headFrame->setY($y - 5);
|
2014-04-17 22:04:19 +02:00
|
|
|
$array = array("Rank" => $x + 5, "Nickname" => $x + 18, "Login" => $x + 70, "Time" => $x + 101);
|
2014-04-17 00:43:29 +02:00
|
|
|
$this->maniaControl->manialinkManager->labelLine($headFrame, $array);
|
2014-04-28 17:54:25 +02:00
|
|
|
|
|
|
|
$i = 0;
|
|
|
|
$y = $height / 2 - 10;
|
2014-04-17 00:43:29 +02:00
|
|
|
$pageFrames = array();
|
2014-04-28 17:54:25 +02:00
|
|
|
foreach ($records as $listRecord) {
|
2014-04-17 00:43:29 +02:00
|
|
|
if (!isset($pageFrame)) {
|
|
|
|
$pageFrame = new Frame();
|
|
|
|
$frame->add($pageFrame);
|
|
|
|
if (!empty($pageFrames)) {
|
|
|
|
$pageFrame->setVisible(false);
|
|
|
|
}
|
|
|
|
array_push($pageFrames, $pageFrame);
|
|
|
|
$y = $height / 2 - 10;
|
2014-04-28 17:54:25 +02:00
|
|
|
|
|
|
|
$paging->addPage($pageFrame);
|
2014-04-17 00:43:29 +02:00
|
|
|
}
|
2014-04-28 17:54:25 +02:00
|
|
|
|
2014-04-17 00:50:44 +02:00
|
|
|
$recordFrame = new Frame();
|
|
|
|
$pageFrame->add($recordFrame);
|
2014-04-28 17:54:25 +02:00
|
|
|
|
2014-04-17 00:43:29 +02:00
|
|
|
if ($i % 2 != 0) {
|
|
|
|
$lineQuad = new Quad_BgsPlayerCard();
|
2014-04-17 00:50:44 +02:00
|
|
|
$recordFrame->add($lineQuad);
|
2014-04-17 00:43:29 +02:00
|
|
|
$lineQuad->setSize($width, 4);
|
|
|
|
$lineQuad->setSubStyle($lineQuad::SUBSTYLE_BgPlayerCardBig);
|
|
|
|
$lineQuad->setZ(0.001);
|
|
|
|
}
|
2014-04-28 17:54:25 +02:00
|
|
|
|
|
|
|
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);
|
2014-04-17 00:50:44 +02:00
|
|
|
$this->maniaControl->manialinkManager->labelLine($recordFrame, $array);
|
2014-04-28 17:54:25 +02:00
|
|
|
|
2014-04-17 00:50:44 +02:00
|
|
|
$recordFrame->setY($y);
|
2014-04-28 17:54:25 +02:00
|
|
|
|
2014-04-17 00:43:29 +02:00
|
|
|
$y -= 4;
|
|
|
|
$i++;
|
|
|
|
if ($i % 15 == 0) {
|
|
|
|
unset($pageFrame);
|
|
|
|
}
|
|
|
|
}
|
2014-04-28 17:54:25 +02:00
|
|
|
|
2014-04-17 00:43:29 +02:00
|
|
|
// Render and display xml
|
|
|
|
$this->maniaControl->manialinkManager->displayWidget($maniaLink, $player, 'PlayerList');
|
|
|
|
}
|
|
|
|
|
2014-04-27 11:02:46 +02:00
|
|
|
/**
|
|
|
|
* Get current checkpoint string for dedimania record
|
2014-04-28 17:54:25 +02:00
|
|
|
*
|
2014-04-27 11:02:46 +02:00
|
|
|
* @param string $login
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
private function getCheckpoints($login) {
|
|
|
|
if (!$login || !isset($this->checkpoints[$login])) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
$string = '';
|
2014-04-28 17:54:25 +02:00
|
|
|
$count = count($this->checkpoints[$login]);
|
|
|
|
foreach ($this->checkpoints[$login] as $index => $check) {
|
2014-04-27 11:02:46 +02:00
|
|
|
$string .= $check;
|
|
|
|
if ($index < $count - 1) {
|
|
|
|
$string .= ',';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $string;
|
|
|
|
}
|
|
|
|
|
2013-11-25 02:01:15 +01:00
|
|
|
/**
|
|
|
|
* Build the local records manialink
|
2014-04-28 17:54:25 +02:00
|
|
|
*
|
2013-11-25 02:01:15 +01:00
|
|
|
* @return string
|
|
|
|
*/
|
2013-11-28 03:47:08 +01:00
|
|
|
private function buildManialink() {
|
2013-11-25 02:01:15 +01:00
|
|
|
$map = $this->maniaControl->mapManager->getCurrentMap();
|
|
|
|
if (!$map) {
|
|
|
|
return null;
|
|
|
|
}
|
2014-04-28 17:54:25 +02:00
|
|
|
|
|
|
|
$title = $this->maniaControl->settingManager->getSetting($this, self::SETTING_WIDGET_TITLE);
|
|
|
|
$pos_x = $this->maniaControl->settingManager->getSetting($this, self::SETTING_WIDGET_POSX);
|
|
|
|
$pos_y = $this->maniaControl->settingManager->getSetting($this, self::SETTING_WIDGET_POSY);
|
|
|
|
$width = $this->maniaControl->settingManager->getSetting($this, self::SETTING_WIDGET_WIDTH);
|
|
|
|
$lines = $this->maniaControl->settingManager->getSetting($this, self::SETTING_WIDGET_LINESCOUNT);
|
|
|
|
$lineHeight = $this->maniaControl->settingManager->getSetting($this, self::SETTING_WIDGET_LINEHEIGHT);
|
|
|
|
$labelStyle = $this->maniaControl->manialinkManager->styleManager->getDefaultLabelStyle();
|
|
|
|
$quadStyle = $this->maniaControl->manialinkManager->styleManager->getDefaultQuadStyle();
|
2013-11-28 03:47:08 +01:00
|
|
|
$quadSubstyle = $this->maniaControl->manialinkManager->styleManager->getDefaultQuadSubstyle();
|
2014-04-28 17:54:25 +02:00
|
|
|
|
2013-11-25 02:01:15 +01:00
|
|
|
$records = $this->getLocalRecords($map);
|
|
|
|
if (!is_array($records)) {
|
|
|
|
trigger_error("Couldn't fetch player records.");
|
|
|
|
return null;
|
|
|
|
}
|
2014-04-28 17:54:25 +02:00
|
|
|
|
2013-11-25 02:01:15 +01:00
|
|
|
$manialink = new ManiaLink(self::MLID_RECORDS);
|
2014-04-28 17:54:25 +02:00
|
|
|
$frame = new Frame();
|
2013-11-25 02:01:15 +01:00
|
|
|
$manialink->add($frame);
|
|
|
|
$frame->setPosition($pos_x, $pos_y);
|
2014-04-28 17:54:25 +02:00
|
|
|
|
2013-11-25 02:01:15 +01:00
|
|
|
$backgroundQuad = new Quad();
|
|
|
|
$frame->add($backgroundQuad);
|
|
|
|
$backgroundQuad->setVAlign(Control::TOP);
|
2014-02-16 13:16:11 +01:00
|
|
|
$adjustOuterBorder = $this->maniaControl->settingManager->getSetting($this, self::SETTING_ADJUST_OUTER_BORDER);
|
2014-04-28 17:54:25 +02:00
|
|
|
$height = 7. + ($adjustOuterBorder ? count($records) : $lines) * $lineHeight;
|
2014-02-16 13:16:11 +01:00
|
|
|
$backgroundQuad->setSize($width * 1.05, $height);
|
2013-11-28 03:47:08 +01:00
|
|
|
$backgroundQuad->setStyles($quadStyle, $quadSubstyle);
|
2014-04-17 01:46:59 +02:00
|
|
|
$backgroundQuad->setAction(self::ACTION_SHOW_RECORDSLIST);
|
2014-04-28 17:54:25 +02:00
|
|
|
|
2013-11-25 02:01:15 +01:00
|
|
|
$titleLabel = new Label();
|
|
|
|
$frame->add($titleLabel);
|
2013-11-28 03:47:08 +01:00
|
|
|
$titleLabel->setPosition(0, $lineHeight * -0.9);
|
2013-11-28 02:04:06 +01:00
|
|
|
$titleLabel->setWidth($width);
|
2013-11-28 03:47:08 +01:00
|
|
|
$titleLabel->setStyle($labelStyle);
|
2013-11-25 02:01:15 +01:00
|
|
|
$titleLabel->setTextSize(2);
|
|
|
|
$titleLabel->setText($title);
|
2013-11-28 03:47:08 +01:00
|
|
|
$titleLabel->setTranslate(true);
|
2014-04-28 17:54:25 +02:00
|
|
|
|
2013-11-25 02:01:15 +01:00
|
|
|
// Times
|
2014-04-28 17:54:25 +02:00
|
|
|
foreach ($records as $index => $record) {
|
2014-02-21 22:50:17 +01:00
|
|
|
if ($index >= $lines) {
|
|
|
|
break;
|
|
|
|
}
|
2014-04-28 17:54:25 +02:00
|
|
|
|
2013-11-28 03:47:08 +01:00
|
|
|
$y = -8. - $index * $lineHeight;
|
2014-04-28 17:54:25 +02:00
|
|
|
|
2013-11-25 02:01:15 +01:00
|
|
|
$recordFrame = new Frame();
|
|
|
|
$frame->add($recordFrame);
|
|
|
|
$recordFrame->setPosition(0, $y);
|
2014-04-28 17:54:25 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* $backgroundQuad = new Quad(); $recordFrame->add($backgroundQuad); $backgroundQuad->setSize($width * 1.04, $lineHeight * 1.4); $backgroundQuad->setStyles($quadStyle, $quadSubstyle);
|
|
|
|
*/
|
|
|
|
|
2013-11-25 02:01:15 +01:00
|
|
|
$rankLabel = new Label();
|
|
|
|
$recordFrame->add($rankLabel);
|
|
|
|
$rankLabel->setHAlign(Control::LEFT);
|
2013-11-28 17:36:39 +01:00
|
|
|
$rankLabel->setX($width * -0.47);
|
2013-11-28 03:47:08 +01:00
|
|
|
$rankLabel->setSize($width * 0.06, $lineHeight);
|
2013-11-25 02:01:15 +01:00
|
|
|
$rankLabel->setTextSize(1);
|
|
|
|
$rankLabel->setTextPrefix('$o');
|
|
|
|
$rankLabel->setText($record->rank);
|
2014-03-01 19:23:21 +01:00
|
|
|
$rankLabel->setTextEmboss(true);
|
2014-04-28 17:54:25 +02:00
|
|
|
|
2013-11-25 02:01:15 +01:00
|
|
|
$nameLabel = new Label();
|
|
|
|
$recordFrame->add($nameLabel);
|
|
|
|
$nameLabel->setHAlign(Control::LEFT);
|
2013-11-28 17:36:39 +01:00
|
|
|
$nameLabel->setX($width * -0.4);
|
2013-11-28 03:47:08 +01:00
|
|
|
$nameLabel->setSize($width * 0.6, $lineHeight);
|
2013-11-25 02:01:15 +01:00
|
|
|
$nameLabel->setTextSize(1);
|
|
|
|
$nameLabel->setText($record->nickname);
|
2014-03-01 19:23:21 +01:00
|
|
|
$nameLabel->setTextEmboss(true);
|
2014-04-28 17:54:25 +02:00
|
|
|
|
2013-11-25 02:01:15 +01:00
|
|
|
$timeLabel = new Label();
|
|
|
|
$recordFrame->add($timeLabel);
|
|
|
|
$timeLabel->setHAlign(Control::RIGHT);
|
2013-11-28 17:36:39 +01:00
|
|
|
$timeLabel->setX($width * 0.47);
|
2013-11-28 03:47:08 +01:00
|
|
|
$timeLabel->setSize($width * 0.25, $lineHeight);
|
2013-11-25 02:01:15 +01:00
|
|
|
$timeLabel->setTextSize(1);
|
|
|
|
$timeLabel->setText(Formatter::formatTime($record->time));
|
2014-03-01 19:23:21 +01:00
|
|
|
$timeLabel->setTextEmboss(true);
|
2013-11-25 02:01:15 +01:00
|
|
|
}
|
2014-04-28 17:54:25 +02:00
|
|
|
|
2014-03-02 13:00:23 +01:00
|
|
|
return $manialink;
|
2013-11-25 02:01:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Fetch local records for the given map
|
2014-04-28 17:54:25 +02:00
|
|
|
*
|
2013-12-31 15:27:40 +01:00
|
|
|
* @param Map $map
|
|
|
|
* @param int $limit
|
2013-11-25 02:01:15 +01:00
|
|
|
* @return array
|
|
|
|
*/
|
2014-02-06 14:35:54 +01:00
|
|
|
public function getLocalRecords(Map $map, $limit = -1) {
|
2013-11-25 02:01:15 +01:00
|
|
|
$mysqli = $this->maniaControl->database->mysqli;
|
2014-04-28 17:54:25 +02:00
|
|
|
$limit = ($limit > 0 ? "LIMIT " . $limit : "");
|
|
|
|
$query = "SELECT * FROM (
|
2013-11-25 02:01:15 +01:00
|
|
|
SELECT recs.*, @rank := @rank + 1 as `rank` FROM `" . self::TABLE_RECORDS . "` recs, (SELECT @rank := 0) ra
|
|
|
|
WHERE recs.`mapIndex` = {$map->index}
|
|
|
|
ORDER BY recs.`time` ASC
|
|
|
|
{$limit}) records
|
|
|
|
LEFT JOIN `" . PlayerManager::TABLE_PLAYERS . "` players
|
|
|
|
ON records.`playerIndex` = players.`index`;";
|
|
|
|
$result = $mysqli->query($query);
|
|
|
|
if ($mysqli->error) {
|
|
|
|
trigger_error($mysqli->error);
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
$records = array();
|
2014-04-28 17:54:25 +02:00
|
|
|
while ($record = $result->fetch_object()) {
|
2013-11-25 02:01:15 +01:00
|
|
|
array_push($records, $record);
|
|
|
|
}
|
|
|
|
$result->free();
|
|
|
|
return $records;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieve the local record for the given map and login
|
2014-04-28 17:54:25 +02:00
|
|
|
*
|
|
|
|
* @param Map $map
|
2013-12-31 15:27:40 +01:00
|
|
|
* @param Player $player
|
2013-11-25 02:01:15 +01:00
|
|
|
* @return mixed
|
|
|
|
*/
|
|
|
|
private function getLocalRecord(Map $map, Player $player) {
|
|
|
|
$mysqli = $this->maniaControl->database->mysqli;
|
2014-04-28 17:54:25 +02:00
|
|
|
$query = "SELECT records.* FROM (
|
2013-11-25 02:01:15 +01:00
|
|
|
SELECT recs.*, @rank := @rank + 1 as `rank` FROM `" . self::TABLE_RECORDS . "` recs, (SELECT @rank := 0) ra
|
|
|
|
WHERE recs.`mapIndex` = {$map->index}
|
|
|
|
ORDER BY recs.`time` ASC) records
|
|
|
|
WHERE records.`playerIndex` = {$player->index};";
|
|
|
|
$result = $mysqli->query($query);
|
|
|
|
if ($mysqli->error) {
|
|
|
|
trigger_error("Couldn't retrieve player record for '{$player->login}'." . $mysqli->error);
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
$record = $result->fetch_object();
|
|
|
|
$result->free();
|
|
|
|
return $record;
|
|
|
|
}
|
|
|
|
}
|