Now saving checkpoints for localrecords

This commit is contained in:
Max Klaversma 2014-04-27 11:02:46 +02:00 committed by Steffen Schröder
parent f50f29cd10
commit a125deaf8d

View File

@ -56,6 +56,7 @@ class LocalRecordsPlugin implements CallbackListener, CommandListener, TimerList
*/
private $maniaControl = null;
private $updateManialink = false;
private $checkpoints = array();
/**
* Prepares the Plugin
@ -92,6 +93,7 @@ class LocalRecordsPlugin implements CallbackListener, CommandListener, TimerList
$this->maniaControl->callbackManager->registerCallbackListener(MapManager::CB_BEGINMAP, $this, 'handleMapBegin');
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_TM_PLAYERFINISH, $this, 'handlePlayerFinish');
$this->maniaControl->callbackManager->registerCallbackListener(PlayerManager::CB_PLAYERCONNECT, $this, 'handlePlayerConnect');
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_TM_PLAYERCHECKPOINT, $this, 'handlePlayerCheckpoint');
$this->maniaControl->callbackManager->registerCallbackListener(SettingManager::CB_SETTINGS_CHANGED, $this, 'handleSettingsChanged');
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MP_PLAYERMANIALINKPAGEANSWER, $this, 'handleManialinkPageAnswer');
$this->maniaControl->commandManager->registerCommandListener('records', $this, 'showRecordsList');
@ -127,6 +129,13 @@ class LocalRecordsPlugin implements CallbackListener, CommandListener, TimerList
if ($mysqli->error) {
trigger_error($mysqli->error, E_USER_ERROR);
}
$mysqli->query("ALTER TABLE `" . self::TABLE_RECORDS . "` ADD `checkpoints` TEXT CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL");
if ($mysqli->error) {
if(!strstr($mysqli->error, 'Duplicate')) {
trigger_error($mysqli->error, E_USER_ERROR);
}
}
}
/**
@ -202,6 +211,23 @@ class LocalRecordsPlugin implements CallbackListener, CommandListener, TimerList
}
}
/**
* 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
*
@ -262,13 +288,16 @@ class LocalRecordsPlugin implements CallbackListener, CommandListener, TimerList
$query = "INSERT INTO `" . self::TABLE_RECORDS . "` (
`mapIndex`,
`playerIndex`,
`time`
`time`,
`checkpoints`
) VALUES (
{$map->index},
{$player->index},
{$time}
{$time},
'{$this->getCheckpoints($player->login)}'
) ON DUPLICATE KEY UPDATE
`time` = VALUES(`time`);";
`time` = VALUES(`time`),
`checkpoints` = VALUES(`checkpoints`);";
$mysqli->query($query);
if ($mysqli->error) {
trigger_error($mysqli->error);
@ -429,6 +458,27 @@ class LocalRecordsPlugin implements CallbackListener, CommandListener, TimerList
$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
*