<?php
php
// Copyright 2006 Mark 'Dygear' Tomlin & Mikael 'filur' Forsberg
// Verison 1.5.beta (UNI)
class LFSWorldSDK {
function LFSWorldSDK($idk, $ver = 1.3, $pre = false) {
$this->ps = $pre;
$this->idk = $idk;
$this->version = $ver;
}
function make_query($qryStr) {
return file_get_contents("http://www.lfsworld.net/pubstat/get_stat2.php?version={$this->version}&idk={$this->idk}&ps={$this->ps}{$qryStr}");
}
function get_hl($racer) {
foreach (explode("\n", $this->make_query("&action=hl&racer={$racer}")) as $line => $data)
list($result[$line]['id_hl'], $result[$line]['track'], $result[$line]['car'], $result[$line]['split1'], $result[$line]['split2'], $result[$line]['split3'], , $result[$line]['time'], $result[$line]['flags_hlaps']) = split(' ', $data, 8);
return $result;
}
function get_pb($racer) {
foreach (explode("\n", $this->make_query("&action=pb&racer={$racer}")) as $line => $data)
list($result[$line]['track'], $result[$line]['car'], $result[$line]['time'], $result[$line]['lapcount']) = split(' ', $data, 4);
return $result;
}
function get_ch($track, $car, $control = null) {
foreach (explode("\n", $this->make_query("&action=ch&track={$track}&car={$car}&control={$control}")) as $line => $data)
list($result[$line]['split1'], $result[$line]['split2'], $result[$line]['split3'], $result[$line]['time'], $result[$line]['flags_hlaps'], $result[$line]['racername']) = split(' ', $data, 6);
return $result;
}
function get_wr() {
foreach (explode("\n", $this->make_query("&action=wr")) as $line => $data)
list($result[$line]['id_wr'], $result[$line]['track'], $result[$line]['car'], $result[$line]['split1'], $result[$line]['split2'], $result[$line]['split3'], $result[$line]['time'], $result[$line]['flags_hlaps'], $result[$line]['racername']) = split(' ', $data, 9);
return $result;
}
function get_pst($racer) {
list($result['distance'], $result['fuel'], $result['laps'], $result['hosts'], $result['wins'], $result['second'], $result['third'], $result['finished'], $result['quals'], $result['pole'], $result['online'], $result['drags'], $result['drag'], $result['online'], $result['hostname'], $result['time'], $result['track'], $result['car']) = split("\n", $this->make_query("&action=pst&racer={$racer}"), 19);
return $result;
}
function get_hosts() {
$string = $this->make_query("&action=hosts");
for ($pointer = 0, $i = 0; $pointer <= strlen($string); $i++) {
$NumberOfRacers = @unpack("c", substr($string, $pointer + 52, 1));
$NumberOfRacers = $NumberOfRacers[1];
$NumberOfRacersLen = $NumberOfRacers * 24;
$PointerPast = $NumberOfRacersLen + 53;
$result[$i] = array();
if (($result[$i] = @unpack("a32hostname/A4tmlt/A4tcrm/icars/irules/claps/cqual/cspare1/cspare2/cnrofracers/a{$NumberOfRacersLen}racernames", substr($string, $pointer, $PointerPast)))) {
$result[$i]['racernames'] = preg_split("/\\0/", $result[$i]['racernames'], -1, PREG_SPLIT_NO_EMPTY);
$result[$i]['tmlt'] = unpack("ctype/cmain/a1letter/ctestId", $result[$i]['tmlt']);
$result[$i]['tcrm'] = unpack("ctrack/cconfig/creversed/cmax", $result[$i]['tcrm']);
}
else
unset($result[$i]);
$pointer += $PointerPast;
}
return $result;
}
function get_teams() {
$string = $this->make_query("&action=teams");
for ($pointer = 0, $i = 0; $pointer <= strlen($string); $i++) {
$infoLen = @unpack("S", substr($string, $pointer + 298, 2));
$infoLen = $infoLen[1];
$nrMembers = @unpack("S", substr($string, $pointer + 300 + $infoLen, 2));
$nrMembers = $nrMembers[1] * 24;
$PointerPast = 302 + $infoLen + $nrMembers;
$result[$i] = array();
if (($result[$i] = @unpack("a128team/a6tag/a32country/a128url/Ibits/Sinfo_len/a{$infoLen}info/Snr_members/a{$nrMembers}members", substr($string, $pointer, $PointerPast)))) {
$result[$i]['members'] = preg_split("/\\0/", $result[$i]['members'], -1, PREG_SPLIT_NO_EMPTY);
$result[$i]['info'] = urldecode($result[$i]['info']);
}
else
unset($result[$i]);
$pointer += $PointerPast;
}
return $result;
}
function get_hl_log($log_filter = 4, $lines = 150, $control = null, $starttime = 0) {
$string = $this->make_query("&action=hl_log&log_filter={$log_filter}&lines={$lines}&control={$control}&starttime={$starttime}&format=3");
for ($pointer = 0, $i = 0; $pointer <= strlen($string); $i++) {
$result[$i] = array();
if (($result[$i] = @unpack("itime/a24racer/a32country/A4tcrc/i4split/Spos/Sflags/iid_hl", substr($string, $pointer, 88))))
$result[$i]['tcrc'] = unpack("ctrack/cconfig/creversed/ccar", $result[$i]['tcrc']);
else
unset($result[$i]);
$pointer += 88;
}
return $result;
}
}
?>
This should be faster as it does not rely on preg for it's string parsing in all cases.
This is not directly compatible with the older versions due to the fact that I've changed around the order of the args for the entry function.