The online racing simulator
Searching in All forums
(13 results)
Hoitjes
S2 licensed
Round #1
First-n-Lastname: Christel van Essen
LFSW-Username: Hoitjes
Team: Team Rock Racing
I confirm that I will drive this round (yes/no): yes
Hoitjes
S2 licensed
Thanks alot guys it is working now!
Now lets see if I can implement it in the website
Going to be difficult with my little knowledge of php
If I get it working I let it know here, and post the files with ofcourse permission from the original authors of this part, so other people can use it as well.
It is going to be community builder based on a joomla website

Quote from Dygear :Please don't re-post the SDK's source code, it's an unnecessary burden on the LFS Forum's database. Also, your not using the latest version of the SDK, (1.9.3) your using 1.9.1. They will both work, I'm just saying there is some added functionally in the newest version along with a other issues that where fixed.

[That is to say the current version is 1.9.3 at the time of this post (Oct 18 2009).]

Sorry for that I deleted it from my post, and now used version 1.9.3 Thanks!
Last edited by Hoitjes, .
Hoitjes
S2 licensed
and where in this code should I fill in the racers username?
Last edited by Hoitjes, .
Hoitjes
S2 licensed
Quote from Dygear :

<?php 
php
    
include('lfsworldsdk.php');
    function 
trackToName($trackCode) {
        switch(
$trackCode[0]) {
            case 
0$rtn 'Blackwood ';
                switch(
$trackCode[1]) {
                    case 
0$rtn .= 'GP Track'; break;
                    case 
1$rtn .= 'Rally Cross'; break;
                    case 
2$rtn .= 'Car Park'; break;
                }
            break;
            case 
1$rtn 'South City ';
                switch(
$trackCode[1]) {
                    case 
0$rtn .= 'Classic'; break;
                    case 
1$rtn .= 'Sprint Track 1'; break;
                    case 
2$rtn .= 'Sprint Track 2'; break;
                    case 
3$rtn .= 'Long'; break;
                    case 
4$rtn .= 'Town Course'; break;
                    case 
5$rtn .= 'Chicane Route'; break;
                }
            break;
            case 
2$rtn 'Fern Bay ';
                switch(
$trackCode[1]) {
                    case 
0$rtn .= 'Club'; break;
                    case 
1$rtn .= 'Green Track'; break;
                    case 
2$rtn .= 'Gold Track'; break;
                    case 
3$rtn .= 'Black Track'; break;
                    case 
4$rtn .= 'Rally Cross'; break;
                    case 
5$rtn .= 'RallyX Green'; break;
                }
            break;
            case 
3$rtn 'Autocross ';
                switch(
$trackCode[1]) {
                    case 
0$rtn .= 'Autocross'; break;
                    case 
1$rtn .= 'Skid Pad'; break;
                    case 
2$rtn .= 'Drag Strip'; break;
                    case 
3$rtn .= '8 Lane Drag'; break;
                }
            break;
            case 
4$rtn 'Kyoto Ring ';
                switch(
$trackCode[1]) {
                    case 
0$rtn .= 'Oval'; break;
                    case 
1$rtn .= 'National'; break;
                    case 
2$rtn .= 'GP Long'; break;
                }
            break;
            case 
5$rtn 'Westhill ';
                switch(
$trackCode[1]) {
                    case 
0$rtn .= 'International'; break;
                }
            break;
            case 
6$rtn 'Aston ';
                switch(
$trackCode[1]) {
                    case 
0$rtn .= 'Cadet'; break;
                    case 
1$rtn .= 'Club'; break;
                    case 
2$rtn .= 'National'; break;
                    case 
3$rtn .= 'Historic'; break;
                    case 
4$rtn .= 'Grand Prix'; break;
                    case 
5$rtn .= 'Grand Touring'; break;
                    case 
6$rtn .= 'North'; break;
                }
            break;
            default: return 
'Unknown Track';
        }
        if (
$trackCode[2] === 1)
            return 
"$rtn Reversed";
        else
            return 
$rtn;
    }

<
html>
    <
head>
        <
title>Page for echo $_GET['racer']; </title>
    </
head>
    <
body>
        <
table>
            <
tbody>
   
$pst $SDK->get_pst($_GET['racer']);
        forEach (
$pst[0] as $key => $val):    
                <
tr>
       switch (
$key):
                case 
'distance':    
                    <
th>Meters Driven</th>
                    <
td>echo $val; </td>
           break;
                case 
'fuel':    
                    <
th>Fuel burned in cl</th>
                    <
td>echo $val; </td>
           break;
                case 
'laps':    
                    <
th>Laps Driven</th>
                    <
td>echo $val; </td>
           break;
                case 
'joined':    
                    <
th>Hosts joined</th>
                    <
td>echo $val; </td>
           break;
                case 
'win':    
                    <
th>Race wins</th>
                    <
td>echo $val; </td>
           break;
                case 
'races_finished':    
                    <
th>Races finished</th>
                    <
td>echo $val; </td>
           break;
                case 
'qual':    
                    <
th>Qualifications</th>
                    <
td>echo $val; </td>
           break;
                case 
'pole':    
                    <
th>Pole positions</th>
                    <
td>echo $val; </td>
           break;
                case 
'dragwins':    
                    <
th>Drags won</th>
                    <
td>echo $val; </td>
           break;
                case 
'ostatus':    
                    <
th>Online status</th>
                    <
td>php
                        
switch ($val) {
                            case 
0:    echo 'Offline'; break;
                            case 
1: echo 'Spectating'; break;
                            case 
2: echo 'In pits'; break;
                            case 
3: echo 'In race'; break;
                        }
                    </
td>
           break;
                case 
'last_time':    
                    <
th>Last active on</th>
                    <
td>echo date('d-m-Y H:i'$val); </td>
           break;
                case 
'track':    
                    <
th>Track</th>
                    <
td>echo trackToName($val); </td>
           break;
                default:

                    <
th>echo ucwords($key); </th>
                    <
td>echo $val; </td>
       endSwitch;    
                </
tr>
php
    
endForEach;

            </
tbody>
        </
table>
    </
body>
</
html>
?>


Sorry for my late reaction i had a lot of work to do.
I got this error message:

Warning: Invalid argument supplied for foreach() in /usr/home/deb9356n2/domains/teamrockracing.com/public_html/test/lfsstats/lfsworldsdk2.php on line 339

this error message comes from the part below, first sentence


<?php 
   $pst 
$SDK->get_pst($_GET['racer']);
        forEach (
$pst[0] as $key => $val):    
                <
tr>
?>

Hoitjes
S2 licensed
Meters Driven
Fuel burned in cl
Laps Driven
Hosts joined
Race wins
Second
Third
Races finished
Qualifications
Pole positions
Drags
Drags won
Country
Online status (Offline/Spectating/In pits/In race)
Current / Last entered hostname
Last active on (13-10-2009 14:30)
Current / Last driven track (track name)
Current / last driven car

Thanks in advance,
You guys are already so helpfull
Hoitjes
Hoitjes
S2 licensed
thanks it works now!
I tried to change some things but that didn't work. So I have a few questions left (a)
Is there a way to modify the tekst output under the key column?
Is there a way to change the online status to display online / offline instead of 0 or 1
Is there a way to change the way the time is displayed in last activity?
Is there a way to change the track code to a actual name of the track?
Hoitjes
S2 licensed
yeah that worked for me too,
But I want it to be displayed nice in tables
therfor the code


<?php 
   
include('lfsworldsdk.php');    
<
table>
    <
thead>
        <
tr>
            <
th>Key</th>
            <
td>Val</td>
        </
tr>
    </
thead>
    <
tbody>
   forEach (
$SDK->get_pst('Dygear') as $key => $val):    
        <
tr>
            <
th>echo $key; </th>
            <
td>echo $val; </td>
        </
tr>
   endForEach;    
    </
tbody>
</
table>
?>

and then it does not work or something
Hoitjes
S2 licensed
oops forgot that part, but it doesn't affect the outcome
Hoitjes
S2 licensed
Hmm I changed it to my own key en changed dygear to my own username didn't work
I did put everything in one .php file cause I need one file for my profile it looks like this now:


<?php 
php

# $SDK = new LFSWorldSDK('Em2EB5oKYk0d33FeKD0cf13Hw18terK7', FALSE);
$SDK = new LFSWorldSDK('92qe7FM72U6uTtGOn4xC0cF3Jh3pjSYw'TRUE);

/*
** Live For Speed World SDK, easily find what you need from the World of Live For Speed.
**
** @package   LFSWorldSDK
** @since     2009-03-14 19:45
** @author    Mark 'Dygear' Tomlin
** @coauthor  Mikael 'filur' Forsberg.
** @coauthor  Victor van Vlaardingen.
** @coauthor  Jeff 'glyphon' DeLamater.
** @coauthor  AndroidXP.
** @coauthor  Dr. Timo 'HorsePower' Bergmann.
** @license   MIT License (http://opensource.org/licenses/mit-license.php)
** @copyright Copyright (C) 2006 - 2009,
**            Mark 'Dygear' Tomlin, Mikael 'filur' Forsberg,
**            Victor van Vlaardingen, Jeff 'glyphon' DeLamater,
**            AndroidXP and Dr. Timo 'HorsePower' Bergmann.
** @version   1.9.1
*/

class LFSWorldSDK {
    
// Constructor
    
function LFSWorldSDK($idk$ps FALSE) {
        
$this->ps $ps;
        
$this->idk $idk;
        
$this->time time();
        
$this->fpass TRUE;
        
$this->compression = (function_exists('gzinflate')) ? 0;
    }
    
// Core Functions.
    
function make_query($qryStr) {
        if (
$this->ps === FALSE && $this->fpass === TRUE && (time() - $this->time) < 5) {
            
sleep(- (time() - $this->time));
            
$this->time time();
            
$this->fpass false;
        }
        
$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;
    }
    
// Helper Fuctions.
    
function convert_lfsw_time($time) {
        return 
sprintf('%d:%2.2f'floor($time 60000), (($time 60000) / 1000));
    }
    function 
convert_flags_hlaps($flags_hlaps$toString FALSE) {
        if (
$toString == FALSE) {
            
$data = array();
            
$data[1] = ($flags_hlaps 1)  ? 'LEFTHANDDRIVE' 'RIGHTHANDDRIVE';
            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] = 'THROTTLEHELP';
            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';
        } else {
            
$data '';
            
$data .= ($flags_hlaps 1)  ? 'L ' 'R ';
            if (
$flags_hlaps 2)        $data .= 'cc&nbsp';
            if (
$flags_hlaps 4)        $data .= 'cb ';
            if (
$flags_hlaps 8)        $data .= 'A ';
            if (
$flags_hlaps 16)        $data .= 'S '
            if (
$flags_hlaps 64)        $data .= 'bh ';
            if (
$flags_hlaps 128)        $data .= 'cl ';
            if (
$flags_hlaps 512)        $data .= 'ac '
            if (
$flags_hlaps 1024)    $data .= 'M ';
            if (
$flags_hlaps 2048)    $data .= 'Kn ';
            if (
$flags_hlaps 4096)    $data .= 'Ks ';
            if (!(
$flags_hlaps 7168))    $data .= 'W ';
        }
        return 
$data;
    }
    function 
convert_team_bits($bits) {
        
$data = array();
        if (
$bits 1)        $data[1]        = 'race';
        if (
$bits 2)        $data[2]        = 'drift';
        if (
$bits 4)        $data[4]        = 'drag';
        if (
$bits 8)        $data[8]        = 'can apply';
        if (
$bits 16)        $data[16]        = 'has host';
        if (
$bits 32)        $data[32]        = 'Demo';
        if (
$bits 64)        $data[64]        = 'S1';
        if (
$bits 128)    $data[128]        = 'S2';
        if (
$bits 256)    $data[256]        = 'S3';
        return 
$data;
    }
    function 
convert_car_bits($bits) {
        
$data = array();
        if (
$bits 1)        $data[1]        = 'XFG';
        if (
$bits 2)        $data[2]        = 'XRG';
        if (
$bits 4)        $data[4]        = 'XRT';
        if (
$bits 8)        $data[8]        = 'RB4';
        if (
$bits 16)        $data[16]        = 'FXO';
        if (
$bits 32)        $data[32]        = 'LX4';
        if (
$bits 64)        $data[64]        = 'LX6';
        if (
$bits 128)    $data[128]        = 'MRT';
        if (
$bits 256)    $data[256]        = 'UF1';
        if (
$bits 512)    $data[512]        = 'RAC';
        if (
$bits 1024)    $data[1024]        = 'FZ5';
        if (
$bits 2048)    $data[2048]        = 'FOX';
        if (
$bits 4096)    $data[4096]        = 'XFR';
        if (
$bits 8192)    $data[8192]        = 'UFR';
        if (
$bits 16384)    $data[16384]    = 'FO8';
        if (
$bits 32768)    $data[32768]    = 'FXR';
        if (
$bits 65536)    $data[65536]    = 'XRR';
        if (
$bits 131072)    $data[131072]    = 'FZR';
        if (
$bits 262144)    $data[262144]    = 'BF1';
        if (
$bits 524288)    $data[524288]    = 'FBM';
        return 
$data;
    }
    function 
convert_rule_bits($bits) {
        
$data = array();
        if (
$bits 1)        $data[1]        = 'CAN_VOTE';
        if (
$bits 2)        $data[2]        = 'CAN_SELECT';
        if (
$bits 4)        $data[4]        = 'QUALIFY';
        if (
$bits 8)        $data[8]        = 'PRIVATE';
        if (
$bits 16)        $data[16]        = 'MODIFIED';
        if (
$bits 32)        $data[32]        = 'MIDRACEJOIN';
        if (
$bits 64)        $data[64]        = 'MUSTPIT';
        if (
$bits 128)    $data[128]        = 'CAN_RESET';
        if (
$bits 256)    $data[256]        = 'FCV';
        return 
$data;
    }
    
// LFSWorld Functions
    
function get_hl($racer) {
        if (
is_array($racer)) {
            foreach(
$racer as $uname) {
                
$result[$uname] = $this->get_hl($uname);
            }
        } else {
            if ((
$result $this->make_query("&action=hl&racer={$racer}")) !== FALSE) {
                if (
is_array($result)) {
                    foreach (
$result as $i => $data) {
                        
$result[$i]['flags_hlaps'] = $this->convert_flags_hlaps($data);
                    }
                }
            }
        }
        return 
$result;
    }
    function 
get_ch($track$car$control null) {
        if (
is_array($track) || is_array($car)) {
            if (
is_array($track) && is_array($car)) {
                foreach(
$track as $tname) {
                    foreach (
$car as $cname) {
                        
$result[$tname][$cname] = $this->get_ch($tname$cname$control);
                    }
                }
            } else if (
is_array($track)) {
                foreach(
$track as $tname) {
                    
$result[$tname] = $this->get_ch($tname$cname$control);
                }
            } else if (
is_array($car)) {
                foreach (
$car as $cname) {
                    
$result[$cname] = $this->get_ch($tname$cname$control);
                }
            }
        } else {
            if ((
$result $this->make_query("&action=ch&track={$track}&car={$car}&control={$control}")) !== FALSE) {
                foreach (
$result as $i => $data) {
                    
$result[$i]['flags_hlaps'] = $this->convert_flags_hlaps($data);
                }
            }
        }
        return 
$result;
    }
    function 
get_wr() {
        if ((
$result $this->make_query("&action=wr")) !== FALSE) {
            foreach (
$result as $i => $data) {
                
$result[$i]['flags_hlaps'] = $this->convert_flags_hlaps($data);
            }
        }
        return 
$result;
    }
    function 
get_pb($racer) {
        if (
is_array($racer)) {
            foreach(
$racer as $uname) {
                
$result[$uname] = $this->get_pb($uname);
            }
        } else {
            
$result $this->make_query("&action=pb&racer={$racer}");
        }
        return 
$result;
    }
    function 
get_fuel($racer) {
        if (
is_array($racer)) {
            foreach(
$racer as $uname) {
                
$result[$uname] = $this->get_fuel($uname);
            }
        } else {
            return 
$this->make_query("&action=fuel&racer={$racer}");
        }
    }
    function 
get_pst($racer) {
        if (
is_array($racer)) {
            foreach(
$racer as $uname) {
                
$result[$uname] = $this->get_pst($uname);
            }
        } else {
            
$result $this->make_query("&action=pst&racer={$racer}");
        }
        return 
$result;
    }
    function 
get_hosts() {
        
$result $this->make_query("&action=hosts");
        foreach (
$result as $i => $data) {
            
$result[$i]['tmlt'] = unpack("ctype/cmain/aletter/ctestId"$data['tmlt']);
            
$result[$i]['tcrm'] = unpack("ctrack/cconfig/creversed/cmax"$data['tcrm']);
            
$result[$i]['cars'] = $this->convert_car_bits($data['cars']);
            
$result[$i]['rules'] = $this->convert_rule_bits($data['rules']);
        }
        return 
$result;
    }
    function 
get_teams() {
        
$result $this->make_query("&action=teams");
        foreach (
$result as $i => $data) {
            
$result[$i]['info'] = urldecode($data['info']);
            
$result[$i]['bits'] = $this->convert_team_bits($data['bits']);
        }
        return 
$result;
    }
    function 
get_hl_log($log_filter 4$lines 150$control null$starttime 0) {
        
$result $this->make_query("&action=hl_log&log_filter={$log_filter}&lines={$lines}&control={$control}&starttime={$starttime}");
        foreach (
$result as $i => $data) {
            
$result[$i]['flags_hlaps'] = $this->convert_flags_hlaps($data);
        }
        return 
$result;
    }
    function 
get_progress($host) {
        if (
is_array($host)) {
            foreach (
$host as $name) {
                
$return $this->get_progress($name);
                
$return[$return['hostinfo']['host_stripped']] = $return;
            }
        } else {
            return 
json_decode(array_pop(explode("\n"file_get_contents('http://www.lfsworld.net/pubstat/hostprogress.php?host='.urlencode($host)))), TRUE);
        }
    }
}


<
table>
    <
thead>
        <
tr>
            <
th>Key</th>
            <
td>Val</td>
        </
tr>
    </
thead>
    <
tbody>
   forEach (
$SDK->get_pst('Hoitjes') as $key => $val):    
        <
tr>
            <
th>echo $key; </th>
            <
td>echo $val; </td>
        </
tr>
   endForEach;    
    </
tbody>
</
table>

?>

Hoitjes
S2 licensed
How do I do that?
Hoitjes
S2 licensed
hmm yeah that makes sence but it does not show it :S

http://www.teamrockracing.com/test/lfsstats/get_stats.php
Hoitjes
S2 licensed
I probably am stupid but does this supose to dsiplay?
Key Val 0 Array
Thanks,
Hoitjes
Hoitjes
S2 licensed
Hello

I am not that good in php so I have a question.
I am working on a website for a lfs team. All members of that team will have their own profile page. On that page I want to display LFSWorld stats.
No i found out about this script (LFSWorldSDK1.9.1) and uploaded it on the server.
I think it works the way it should, but how can I display it in a table? like 2 columns with left side what the data is en the right side the value of lfs world. (I only care about the pst part)

for example:

Distance driven in km | 6499559
Fuel burned | 171064

Thanks in advance,
Hoitjes
FGED GREDG RDFGDR GSFDG