The online racing simulator
PHP4/5 - LFSWorldSDK, class for stats retrieval
After alot of time, and some blood (punching the screen, wall, and myself [once I realized how bad of a programmer I am], sweat (Man, it's freaking hot), and tears (mainly due to me punching myself) the latest stable release is done. That means you and me can start to have to have some fun with this. It's fully compatible with the current version of LFSWorld (1.3 at the time of writing). Keep in mind there have been some changes to the syntax of some of the functions. Mainly due to the fact that it now allows for arrays, other then that, it should just be a little faster then the one your running right now (With any luck).

Well, you know the drill, if you should happen to see anything wrong, shoot me a PM, or just reply to this topic with the bugs you've found.

Most Current Release (1.9.7).

And you could include it, or just add this to the bottom :


<?php 
php
    
include('lfsworldsdk.php');
    echo 
'<!-- get_hl --><p />';
    
print_r($SDK->get_hl(array('Dygear''filur''Victor''glyphon')));
    echo 
'<!-- get_ch --><p />';
    
print_r($SDK->get_ch(array('000''230''420''630'), array('MRT''FOX''FO8''BF1')));
    echo 
'<!-- get_wr --><p />';
    
print_r($SDK->get_wr());
    echo 
'<!-- get_pb --><p />';
    
print_r($SDK->get_pb(array('Dygear''filur''Victor''glyphon')));
    echo 
'<!-- get_fuel --><p />';
    
print_r($SDK->get_fuel(array('Dygear''filur''Victor''glyphon')));
    echo 
'<!-- get_pst --><p />';
    
print_r($SDK->get_pst(array('Dygear''filur''Victor''glyphon')));
    echo 
'<!-- get_host --><p />';
    
print_r($SDK->get_hosts());
    echo 
'<!-- get_teams --><p />';
    
print_r($SDK->get_teams());
    echo 
'<!-- get_hl_log --><p />';
    
print_r($SDK->get_hl_log());
    echo 
'<!-- get_progress --><p />';
    
print_r($SDK->get_progress('^1(^3FM^1) ^4OvaL ^1JuNkIeS!'));

?>

Can i ask what it is lol
I have the same question.
Its a higher level API to query LFSWorld.

Nice work Dygear and filur I'll have a shufti tomorrow
That is right now, just the core of it. I'll add things like converting time into a more human readable form. The url encoded team string and so on. But first I must finish the core. There are some issues with host, and I'm not totaly sure what they all are. Saying that they sould be done faily soon, when in the next day or two.
great work you guys. truely awesome.

PS: I'd like to help if needed and given the chance.
really coOL
Probably another dumb question by me, but Im gonna ask anyway.

Am I the only one who gets this:
Quote :Parse error: parse error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /var/www/html/includes/custom/LFSWorldSDK.php on line 15

error?
#9 - filur
Quote from traxxion :error?

You're probably running php 4, which fails at declaring variables as private (php5+). This code doesn't really need php 5 and i think Dygear will remove the php 5 specifics.
Quote from filur :You're probably running php 4, which fails at declaring variables as private (php5+). This code doesn't really need php 5 and i think Dygear will remove the php 5 specifics.

I thought that! Looking forward to the php4 version then
Kickass!
If it wasnt for the fact that the Mercury site has been up & down like a streetwalkers undergarments today, i'd have given a thumbs up on whatever appeared, and then probably asked a whole heap of questions about wtf it all means and whatnot
If at first you dont succeed, find another server to go mess up!

http://www.qazwert.com/LFS_SDK.php

Quote :Parse error: parse error, unexpected T_NEW in /home2/qazwert/public_html/LFS_SDK.php on line 175



edit: PHP version = 4.4.1
Quote from PaulC2K :parse error, unexpected T_NEW ...

If you're looking for assistance you'll need to make the source visible, that error message says pretty much nothing.

Rename the file to .txt or make another script containing ..

<?php 
php
    highlight_file
('problem_file.php');

?>

I get the same as Paul.
Quote :Parse error: parse error, unexpected T_NEW in /var/www/html/includes/custom/LFSWorldSDK.php on line 175

Haven't changed anything from the original file so line 175 is this one:
Throw New Exception($str);

Am I right in thinking that the place to add the idkey is ...


<?php 
 
function __construct($IdKey 'xxxxxxxxx'$TarPited False$Version '1.2')
?>

However, when I do this I get the following error ....


<?php 
Warning
gzuncompress() [function.gzuncompress]: data error in LFSWorldSDK.php on line 86
?>


Am I missing something?
Quote from OldBloke :Am I missing something?

Looks like you're using the version Dygear links to in the first post, if so, try the most recent one instead.
Quote from filur :Looks like you're using the version Dygear links to in the first post, if so, try the most recent one instead.

Yep. Now working fine.

I'm used to getting the latest version from the first post
Great work.. This will make life easier in my next incarnation of the Team Setup Station.

Thanks
Dean
Awsome, glad it's getting used, and thanks filur for fixing it! I was at work, and missed it all. Happy to see I picked a awsome co-author . If you use the program for anything do let us know about it. I myself am going to remake the SimFIA website with this bad boy!
Dygear/filur :
Dont suppose either of you could point me in the direction of how you then use this information, ie now that info is pulled, how would it be seperated to be usable?

Take the HL example, you get:
Quote :Array ( [id_hl] => 1205 [track] => 420 [car] => BF1 [time] => 104250 [flags_hlaps] => 1614 )

... amongst other HL info, how would i go about picking out peices so i can specify say:
$id = 1205
$track = 420
$car = BF1
$time = 104250
$flags_hlaps = 1614

I know little more than how to get stuff to & from a db, so thats what i plan to do with all this info, show it into a db, cronjob it as frequently as it might require updating, and pull any results from within the db, it just works easier for me in the future.

Love the fact that you've included the examples for each type of stat were likely to require
The SDK comes with a built in way of finding hot laps. While I wanted to keep in more bare bones. I thought it would be better, and faster to just simply have it in one function.


<?php 
php
    
// Include LFSWorldSDK so that you can use it the functions.
    
include('LFSWorldSDK.php');
    
$SDK = new LFSWorldSDK;
    
// So to get the data you wanted from LFSWorld, you would run this :
    
$data $SDK->get_hl('PaulC2K''420''BF1');
    
// Now we have an array in $data, to use this information we could just assign it to a variable like so :
    
$id $data['id'];
    
$track $data['track'];
    
$car $data['car'];
    
$time $data['time'];
    
$flags_hlaps $data['flags_hlaps'];
    
// The question now becomes why? Why read the value of $data into separate entities, when they are allready distinguable in the first place? You could just do this :
    
echo 'Driver PaulC2K set a time of ' $data['time'] . ' on track ' $data['track'] . ' in the ' $data['car'] . ', man he\'s quick!';
    
// Or use complex strings like this :
    
echo "Driver PaulC2K set a time of {$data['time']} on track {$data['track']} in the {$data['car']}, man he's quick!";
?>

Now as for your SQL code, something like this would work :


<?php 
php

    
include('LFSWorldSDK.php');
    
$SDK = new LFSWorldSDK;

    
$racer 'PaulC2K';
    
$track '420';
    
$car 'BF1';
    
$hl $SDK->get_hl($racer$track$car);

    if (
count($hl) != 0) {
        
mysql_connect($hostname$username$password);
        @
mysql_select_db($database) or die('Unable to select database');
        
mysql_query("INSERT INTO hotlaps VALUES ('','{$racer}','{$hl['track']}','{$hl['car']}','{$hl['time']}','{$hl['flags_hlaps']}'");
        
mysql_close();
    }
    else
        die(
'No HotLaps Returned!');
?>

Hi,

Look this:


<?php 
    
include "LFSWorldSDK.php";
    
$LFSWorld = new LFSWorldSDK;
        
$user 'jscorrea';
    
$stats $LFSWorld->get_stats($user);
    echo 
$stats[distance] == "" "no user" :"ok";
    echo 
$stats[online] == 0"OFFLINE" "ONLINE";
?>

This is the right way to show if the user exists?

In my case i have user im my database and the code below dont work:


<?php 
    
include "LFSWorldSDK.php";
    
$LFSWorld = new LFSWorldSDK;
        
$user $a["uname"];
    
$stats $LFSWorld->get_stats($user);
    echo 
$stats[distance] == "" "no user" :"ok";
    echo 
$stats[online] == 0"OFFLINE" "ONLINE";
?>

$a["uname"] return in my site a username.

The error is:

LFSWorld error: $str

Regards.
JS

PHP4/5 - LFSWorldSDK, class for stats retrieval
(288 posts, started )
FGED GREDG RDFGDR GSFDG