I just took a quick look.
But since I am using the 1.8 version of your SDK in which I already found some issues, I checked these things in 1.9 and here is my first result:
Number format of lap times didn't work for me so I changed it to %05.2f
<?php
function convert_lfsw_time($time) {
return sprintf('%d:%05.2f', floor($time / 60000), (($time % 60000) / 1000));
}
?>
Then, in the flag-conversion method, I missed some flags (SHIFTER and AUTOCLUTCH)
<?php
function convert_flags_hlaps($flags_hlaps) {
$data = array();
if ($flags_hlaps & 1) $data[1] = 'LEFTHANDDRIVE';
if ($flags_hlaps & 2) $data[2] = 'GEARCHANGECUT';
if ($flags_hlaps & 4) $data[4] = 'GEARCHANGEBLIP';
if ($flags_hlaps & 8) $data[8] = 'AUTOGEAR';
if ($flags_hlaps & 16) $data[16] = 'SHIFTER';
if ($flags_hlaps & 64) $data[64] = 'BRAKEHELP';
if ($flags_hlaps & 128) $data[128] = 'AXISCLUTCH';
if ($flags_hlaps & 512) $data[512] = 'AUTOCLUTCH';
if ($flags_hlaps & 1024) $data[1024] = 'MOUSESTEER';
if ($flags_hlaps & 2048) $data[2048] = 'KN';
if ($flags_hlaps & 4096) $data[4096] = 'KS';
if (!($flags_hlaps & 7168)) $data[7168] = 'WHEEL';
return $data;
}
?>
Furthermore, as far as I understood it, I think some of these flags might already be obsolete. According to Victors post we have
<?php
1 LEFTHANDDRIVE
8 AUTOGEAR
16 SHIFTER
64 BRAKEHELP
128 AXISCLUTCH
512 AUTOCLUTCH
1024 MOUSESTEER *
2048 KN *
4096 KS *
(*) if not 1024, 2048 or 4096, steering is wheel.
?>
Then I didn't like these flag-identifier too much, so I added a function exporting a simple string of letters (which are commonly used I guess):
<?php
function convert_flags_hlaps_to_letters($flags_hlaps) {
$string = "";
if ($flags_hlaps == "" || $flags_hlaps == 0) return;
if ($flags_hlaps & 1024) $string .= "M ";
if ($flags_hlaps & 2048) $string .= 'Kn ';
if ($flags_hlaps & 4096) $string .= 'Ks ';
if (!($flags_hlaps & 7168)) $string .= 'W ';
if ($flags_hlaps & 1) $string .= "L ";
else $string .= "R ";
if ($flags_hlaps & 2) $string .= "cc "; // obsolete?
if ($flags_hlaps & 4) $string .= "cb "; // obsolete?
if ($flags_hlaps & 8) $string .= "A "; // Autogear
if ($flags_hlaps & 16) $string .= "S "; // Shifter
if ($flags_hlaps & 64) $string .= "bh ";
if ($flags_hlaps & 128) $string .= "cl "; // Axisclutch (pedal)
if ($flags_hlaps & 512) $string .= "ac "; // Autoclutch
return $string;
}
?>
In your 1.8 version I introduced an optional parameter in the constructor that allows me to avoid the initial 6 second sleep for the first query (of course this should only be used when one is sure to have waited that time before).
So here is my old modification:
<?php
private $timestamp ,
$query;
// Constructor
function LFSWorldSDK($idk, $ps = false, $initial_sleep = true ) {
$this->ps = $ps;
$this->idk = $idk;
$this->compression = (function_exists('gzinflate')) ? 3 : 0;
$this->timestamp = time( );
if ($initial_sleep == false) // this will cause the first query to be done immediately
$this->timestamp -= 5;
}
// Core Functions.
function make_query($qryStr, $file = 'get_stat2.php') {
if (!$this->ps){
$delta = time( ) - $this->timestamp;
if ($delta < 5) // only sleep if necessary ...
sleep(6 - $delta); // ... and only as long as necessary (up to 6 seconds because 5 will fail occasionally)
$this->timestamp = time( );
}
$data = @file_get_contents("http://www.lfsworld.net/pubstat/{$file}?version=1.4&idk={$this->idk}&ps={$this->ps}{$qryStr}&c={$this->compression}&s=2");
$data = ($this->compression) ? gzinflate($data) : $data;
$data = unserialize($data);
if (is_array($data)) return $data;
return array();
}
?>
I like the error handling of your new version:
<?php
function make_query($qryStr) {
if (!$this->ps)
sleep(6);
$data = file_get_contents("http://www.lfsworld.net/pubstat/get_stat2.php?version=1.4&idk={$this->idk}&ps={$this->ps}&c={$this->compression}&s=2{$qryStr}");
if ($this->compression)
$data = gzinflate($data);
if ($this->is_lfsw_error($data))
return $this->make_query($qryStr);
$return = @unserialize($data);
if ($return === FALSE)
return $data;
else
return $return;
}
function is_lfsw_error($data) {
if ($data == 'can\'t reload this page that quickly after another')
return TRUE;
else
return FALSE;
}
?>
BUT, you really shouldn't call make_query within itself without any fallback, because you could easily end up in an endless-loop.
So I would suggest you introduce some counter or whatever to end that loop after X loops if necessary (just keep in mind that LFS-World could be down or whatever).
I will try to use the 1.9 version in my new HoT Tracker (maybe having it modified a little bit).
Great work!
HorsePower