The online racing simulator
the userNameSwitch.php is only necessary if you want the name that displays on the graphic to be different somehow from your actual LFS user name.

for example, one of the guys that is using this registered as mini z, but later decided he didn't like that name, so changed the ingame name to rotary power. but if you try to pull rotary power, nothing comes up. so this is where the userNameSwitch.php file comes into play.

it uses mini z to pull the statistics from the LFS servers, but the name that is displayed on the graphic is rotary power.

like wise, i'm assuming your LFS username is banshee56, but if you wanted the graphic to show [CORE]Banshee56, you'd use the userNameSwitch file.

also, the name variable is case-insentive, BaNshEE56 is basically the same as banshee56. the only difference between the two is how they are displayed on the graphic. both pull the same stats. make sense?

and as for each teammate, all you have to do is change the username in the url (and the template number if you wish, but not necessary).

now, for the ident key...what i'm doing right now is just using my key for all my friends that are using the script (they are just linking the code on my page and putting there username in). Which is fine, except for the "who's online" page that displays all of these graphics on one page, because the LFS server that the stats are pulled from only allows access from one ident key every 5 seconds...so on a page with 6 graphics, that could take ~30 seconds to load them all.

but i just thought of a solution to that. so for now, just let them use your ident key (they won't ever see it), and i'll get a new version out later today or tomorrow (or you could purchase some credits and go with premium access, which has no delay on multiple access.

in short, no, only one folder.
for multiple users, just do the following...
http://your-host/check#.glyphon.jpg
http://your-host/check#.banshee56.jpg
http://your-host/check#.Victor.jpg
...

and keep me updated as to what happens with the online graphic. (make sure its permission is set to 644).
2nd attempt...

new version up.
to update, replace LFS_online_check.php with new version, and add identKeys.php to inc/ folder, and then edit with appropriate info.

also, it seems that the Pubstat tarpit (5sec delay) is based off of IP address, and not $identykey (Victor, correct me if i'm wrong), so if the delay really bugs you, go with the premium pubstats. its insanely cheap. each access of my script uses ~50b, and it costs $(gbp)0.0015/mb.
Ok, I think I know what I did. I added a variable statement to change the stats font styles in the last group of "imagegettftext" statements. I moved the variable declaration to a place earlier in the file. It works now. I also made a couple of changes to not show the fuel burnt, but rather to show 3rd place finishes and races finished. I also changed the description of "1st" to wins.

Here is the file I have with changes to fonts and the stats shown:

<?php
@extract($_GET);

//If the LFS player name has changed since registering LFS, edit the below file to
//display the correct name and pull the correct stats.
include ("inc/userNameSwitch.php");

//If the template isn't explicitly set as a variable, set it to the default template.
if (!isset ($template) || empty($template)) {
$template = 1;
}

//Reads the number of files in the images directory.
$files = (getDirFiles("images/")) ;
function getDirFiles($dirPath){
if ($dirPath[strlen($dirPath)] != "/")
$dirPath .= "/";
if ($handle = opendir($dirPath)) {
while (false !== ($file = readdir($handle)))
if ($file != "." && $file != ".." && (!is_dir($dirPath . $file))) {
$filesArr[] = trim($file);
};
closedir($handle);
}
return $filesArr;
}

//Calculates the number of unique templates in the images directory.
if ($template == "R") {
$i = count($files);
$i = ($i / 2);
$template = rand(1,$i);
}

//Checks to see if the set template number exists. if not, use default template.
$offline = "images/lfs_check_offline".$template.".png";
$online = "images/lfs_check_online".$template.".png";

if (!file_exists($offline)) {
$offline = "images/lfs_check_offline1.png";
$online = "images/lfs_check_online1.png";
}
if (!file_exists($online)) {
$offline = "images/lfs_check_offline1.png";
$online = "images/lfs_check_online1.png";
}

//UserNames with spaces was breaking the LFS query, so this fixes it.
$name = str_replace(" ", "%20",$name);

$cachefile = 'cache/'.$name.'_cached.php';

//setup random cachetime
$randTime = rand(2,6);
$cachetime = $randTime * 60;

// Serve from the cache if it is younger than $cachetime
if (file_exists($cachefile) && time() - $cachetime < filemtime($cachefile)) {
$url = $cachefile;
$stream = file_get_contents( $url );
$stats = explode( "\n", $stream );
} else {
$ver = '1.2';
$act = 'pst';
$host = 'http://www.lfsworld.net';
$path = '/pubstat/get_stat2.php';
$query = "?version=$ver&action=$act&racer=";
$idkey = "&idk=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
$url = $host . $path . $query . $name . $idkey;

$stream = file_get_contents( $url );
$stats = explode( "\n", $stream );

$calendar = date("M.d.Y ");
$tzMod = 3;
$hour = date("g") + $tzMod;
$time = date(":i a");
$date = $calendar . $hour . $time;

//if refresh too soon is returned, read the cached file.
//if cached file doesn't exist, check LFS server for stats every 5 seconds
if ($stats[0] == "can't reload this page that quickly after another"){
if (file_exists($cachefile) && time() - $cachetime < filemtime($cachefile)) {
$url = $cachefile;
$stream = file_get_contents( $url );
$stats = explode( "\n", $stream );
} else {
while ($stats[0] == "can't reload this page that quickly after another"){
sleep(5);
$ver = '1.2';
$act = 'pst';
$host = 'http://www.lfsworld.net';
$path = '/pubstat/get_stat2.php';
$query = "?version=$ver&action=$act&racer=";
$idkey = "&idk=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
$url = $host . $path . $query . $name . $idkey;
$stream = file_get_contents( $url );
$stats = explode( "\n", $stream );
}
// Cache the output to a file after receiving the live stats.
$fp = fopen($cachefile, 'w');
fwrite($fp, $stream."\n<--cached-->\n".$date);
fclose($fp);
}
} else {
// Cache the output to a file when reading live stats.
$fp = fopen($cachefile, 'w');
fwrite($fp, $stream."\n<--cached-->\n".$date);
fclose($fp);
}
}

//function for converting foreign texts for display on the graphic.
function codepage_convert ($str) {
global $cp_tables;

$newstr = "";
$current_cp = "L";
$len = strlen ($str);
for ($i=0; $i<$len; $i++) {
if ($str{$i} == "^" && is_array ($cp_tables[$str{$i+1}])) {
$i++;
$current_cp = $str{$i};
continue;
}

$decimal = ord ($str{$i});
if ($decimal > 127) $newstr .= sprintf ("&#%05d;", $cp_tables[$current_cp][$decimal]);
else $newstr .= $str{$i};
}
return $newstr;
}

//function that returns the current codepage of a given text.
function codepage_setting ($str) {
global $cp_tables;
$newstr = "";
$current_cp = "L";
$len = strlen ($str);
for ($i=0; $i<$len; $i++) {
if ($str{$i} == "^" && is_array ($cp_tables[$str{$i+1}])) {
$i++;
$current_cp = $str{$i};
}
}
return $current_cp;
}

// Code page indicators
// ^L = Latin 1
// ^G = Greek
// ^C = Cyrillic
// ^J = Japanese
// ^E = Central Europe
// ^T = Turkish
// ^B = Baltic

include ("inc/cp_unicode_tables.php");

// Function to remove the colour code data from a string
function remove_colour_codes($String){
$ColCodes = array("^0","^1","^2","^3","^4","^5","^6","^7","^8","^9");
$NewString = str_replace($ColCodes, "",$String);
return $NewString;
}

$tr_ptrn = array ("/\^d/", "/\^s/", "/\^c/", "/\^a/", "/\^q/", "/\^t/", "/\^l/", "/\^r/", "/\^v/", "/\^\^/", "/</");
$tr_ptrn_r = array ("\", "/", ":", "*", "?", "\"", "<", ">", "|", "^", "<");

// sets Units for Fuel and Distant to either metric or imperial
if ($units == "metric") {
//Convert distance to km, add comna, no decimals
$distDrvn = number_format($stats[0] * .001, 0, ".", ","). " km";
//Convert fuel to liters, add comma, no decimals
$fuel = number_format($stats[1] * .01, 0, ".", ",") . " L";
} else {
//Convert distance to miles, add comna, no decimals
$distDrvn = number_format($stats[0] * .000621371, 0, ".", ","). " miles";
//Convert fuel to gallons, add comma, no decimals
$fuel = number_format($stats[1] * .00264172, 0, ".", ",") . " gal";
}
//Stats, add comma, no decimals
$laps = number_format($stats[2], 0, ".", ",") . " laps";
$wins = number_format($stats[4], 0, ".", ",") . " wins";
$second = number_format($stats[5], 0, ".", ",") . " 2nd";
$third = number_format($stats[6], 0, ".", ",") . " 3rd";
$races = number_format($stats[7], 0, ".", ",") . " races";
$poles = number_format($stats[9], 0, ".", ",") . " poles";
[COLOR="Red"][B] $statfont = "fonts/verdana.ttf";[/B][/COLOR]

if ($stats[0] == "pst: no valid username") {
header("content-type: image/jpeg");
$im = imagecreatetruecolor(100,10);
$white = imagecolorallocate($im, 255, 255, 255);
$black = imagecolorallocate($im, 0, 0, 0);
imagefilledrectangle($im, 0, 0, 399, 29, $white);
$font = "fonts/SERPNTBI.TTF";
$text = "invalid username";
imagettftext($im, 8, 0, 1, 9, $black, $font, $text);
imagegif($im);
imagedestroy($im);
unlink($cachefile);
exit;
} elseif ($stats[13] == "0") {
$offlineTxt1 = "is not";
$offlineTxt2 = "racing";
$offlineTxt3 = "online";
header("content-type: image/jpeg");
$font = "fonts/SERPNTBI.TTF";
$statfont = "fonts/verdana.ttf";
$im = imagecreatefrompng($offline);
$white = imagecolorallocate($im, 255,255,255);
$black = imagecolorallocate($im, 0,0,0);
//Add stats to graphics
$grey = imagecolorallocate($im, 175,175,175);
imagettftext($im, 6, 0, 330, 65, $grey, $font, $stats[16]);
imagettftext($im, 6, 0, 315, 75, $grey, $font, $stats[17]);
imagettftext($im, 15, 0, 11, 24, $black, $font, $user);
imagettftext($im, 15, 0, 10, 23, $white, $font, $user);
imagettftext($im, 10, 0, 11, 41, $black, $font, $offlineTxt1);
imagettftext($im, 10, 0, 11, 56, $black, $font, $offlineTxt2);
imagettftext($im, 10, 0, 11, 71, $black, $font, $offlineTxt3);
imagettftext($im, 10, 0, 10, 40, $white, $font, $offlineTxt1);
imagettftext($im, 10, 0, 10, 55, $white, $font, $offlineTxt2);
imagettftext($im, 10, 0, 10, 70, $white, $font, $offlineTxt3);
imagettftext($im, 7, 0, 85, 36, $black, $statfont, $distDrvn);
imagettftext($im, 7, 0, 85, 45, $black, $statfont, $laps);
[COLOR="Red"][B] imagettftext($im, 7, 0, 85, 55, $black, $statfont, $races);
imagettftext($im, 7, 0, 170, 36, $black, $statfont, $wins);
imagettftext($im, 7, 0, 170, 45, $black, $statfont, $second);
imagettftext($im, 7, 0, 170, 55, $black, $statfont, $third);[/B][/COLOR]
imagejpeg($im,"",90);
imagedestroy($im);
} else {
//If online, create online graphic
$onlineTxt1 = "is racing";
$onlineTxt2 = "online";
header("content-type: image/jpeg");
$font = "fonts/SERPNTBI.TTF";
$kana = $font;
$fontSize = 8;
$im = imagecreatefrompng($online);
$white = imagecolorallocate($im, 255,255,255);
//if server name is available, adds server name to graphic
if (!empty ($stats[14])) {
$server = remove_colour_codes($stats[14]);
$cp = codepage_setting($server);
if ($cp == "J"){
//$kana = "fonts/msgothic.ttf";
$kana = "fonts/verdana.ttf";
$fontSize = 8;
}
$serverList = codepage_convert($server);
$serverList = preg_replace ($tr_ptrn, $tr_ptrn_r, $serverList);
imagettftext($im, 7, 0, 85, 64, $black, $statfont, "racing on");
imagettftext($im, $fontSize, 0, 85, 74, $black, $kana, $serverList);
}
//Add stats to graphics
$grey = imagecolorallocate($im, 175,175,175);
imagettftext($im, 6, 0, 330, 65, $grey, $font, $stats[16]);
imagettftext($im, 6, 0, 315, 75, $grey, $font, $stats[17]);
imagettftext($im, 15, 0, 11, 24, $black, $font, $user);
imagettftext($im, 15, 0, 10, 23, $white, $font, $user);
imagettftext($im, 10, 0, 11, 41, $black, $font, $onlineTxt1);
imagettftext($im, 10, 0, 11, 56, $black, $font, $onlineTxt2);
imagettftext($im, 10, 0, 10, 40, $white, $font, $onlineTxt1);
imagettftext($im, 10, 0, 10, 55, $white, $font, $onlineTxt2);
imagettftext($im, 7, 0, 85, 36, $black, $statfont, $distDrvn);
imagettftext($im, 7, 0, 85, 45, $black, $statfont, $laps);
imagettftext($im, 7, 0, 85, 55, $black, $statfont, $races);
imagettftext($im, 7, 0, 170, 36, $black, $statfont, $wins);
imagettftext($im, 7, 0, 170, 45, $black, $statfont, $second);
imagettftext($im, 7, 0, 170, 55, $black, $statfont, $third);
imagejpeg($im,"",90);
imagedestroy($im);
}
?>

I will merge my changes with your new file.

Nice work BTW, I really like this sig.
Quote from banshee56 :Nice work BTW, I really like this sig.

Thanks, and glad you got it figured out. it would have taken me a while to figure that out without knowing you changed it
Is it possible to get WHOLE LFS username database with account license type please ?
Quote from Phlos :Is it possible to get WHOLE LFS username database with account license type please ?

Sounds like a security problem almost. Reminds of me AOL's search query.
I don't see why not tho. I would like to also see sign up dates, and times.
You can't put in The First name and Last name, and that's really to bad, as I could use that for SimFIA.
Quote from glyphon :Update - v0.9

Great script glyphon, I really like it!
One question, is it possible to have the racernames shown with their original colors?
Please helpme !!

No showme nothing..
Only showme:
he page cannot be found
I make the LFS_Checker folder en the root web site and i typing http://mihost/check#.matuka.jpg but.. nothing...




Quote from arco :Great script glyphon, I really like it!
One question, is it possible to have the racernames shown with their original colors?

maybe, but because of the way that the text is written onto the graphic, the solution isn't readily apparenty to me. I could easily figure out how to make the text the color if there is only one color used, or the first color in multiple color names, but switching colors...that's a bit more tricky (and when i say a bit, i mean a lot). but i'll look into it.

Quote from matuka :Please helpme !!
No showme nothing..
Only showme:
he page cannot be found
I make the LFS_Checker folder en the root web site and i typing http://mihost/check#.matuka.jpg but.. nothing...

are you typing check#.matuka.jpg, or are you putting a number in the place of the #?

maybe this is a cultural thing (and if it is, i'm sorry), but the # is a place holder, kind of like a variable, that means a number should go there. for example, a valid address would be check1.matuka.jpg.

does that make sense? if you are still having problems, let me know and i'll try and help you fix them.

and thanks
Quote from glyphon :maybe, but because of the way that the text is written onto the graphic, the solution isn't readily apparenty to me. I could easily figure out how to make the text the color if there is only one color used, or the first color in multiple color names, but switching colors...that's a bit more tricky (and when i say a bit, i mean a lot). but i'll look into it.

Thanks, if you get it to work that would be arwsome!
Quote from glyphon :.. but switching colors...that's a bit more tricky

Allocate all the standard LFS colors, print each character in the name separately with the current color.


colors = array (
0 = imagecolorallocate( .. black )
1 = .. red
..
)

name = str_split(name)
currentcolor = default color
x = start x
y = start y
for (i = 0; i<=strlen(name); i++)
if (name[i] == "^" && preg_match("/[0-8]/", name[i+1])) {
currentcolor =& colors[i+1]
i += 2
}
imagestring(image, font, x, y, name[i], currentcolor)
x += char spacing x
}

excellent. thanks filur!
I have a question about the hightlight page.
Is there a possibility to add timestamps to it ?

The reason is that I created a java program that calls pubstat every x minutes to fetch pb's of my league members. It then generates a php file (with some extra stuff to show in realtime if someone is online, and where...) and uploads it.
I recently added some stuff fetched from the highlights page (under the header "Laatst gereden pb's"). But it would be nice to also have a date when those pb's where driven.

http://www.vrl-simracing.be/lfs_pb/results.php
Does anyone happen to have a basic php scripts to do various bits n peices with the LFSW stats?

Im hopeless when it comes to getting the info, but if i have a script that does the basic job then im fine at making it do whatever im looking for it to do, its just getting there that im unable to manage.
I've tried contacting Anachy-H but he seems to have gone AWOL the last 2 months, i had planned to try his LFSW-PPF thingie but i cant get 'PEAR' installed and i've been waiting to hear from him but im guessing he's got computer/internet issues or something, so i was wondering if anyone had any kind of solution to my problems.
Im sure im not the only person looking for something able to pull info for use on a team website, and with very limited coding knowledge it'd be a great help if there were a couple of very basic scripts to pull info like PB/HL times, Online status and stuff like this.

Its the HLVC/PB stats im personally looking for, but if there were other basic scripts for popular stats then im sure many like myself would appreciate this help in getting started.
Hi Paul,

I recently created a script that receives a racers personal stats from lfsw and creates a status-image for forum-signatures. I think this will explain pretty good how to do a connection to lfsw and it also does a bit of caching.

You may want to look at it here:
http://www.stalkernet.info/source/lfsstatus/index.php

If you want to get hotlap-data, you will possibly have to filter $iter == 0 and then explode the next received line. like this:

<?php 
$content 
= array();
while(
$line fgets($lfswconn)) {
    
// Filter unneeded entries - Chunk size
    
if($iter != 0) {
        
$content[] = $line;
    }
    
$iter++;
}
foreach(
$content as $hl) {
    
$data explode(" "$content);
}
?>

Greets, Stalker
Quote from St4Lk3R :I recently created a script that receives a racers personal stats from lfsw and creates a status-image for forum-signatures. I think this will explain pretty good how to do a connection to lfsw and it also does a bit of caching.

You may want to look at it here:
http://www.stalkernet.info/source/lfsstatus/index.php

looks like an early version of my script
(functionally that is. your code is very different from mine :nod
It would be nice if we could get the hole database from lfsworld in one go. That would be tarpitted for a whole day. You could gzip file the and place it on the server. Then with cron, update it evey 24 hours. It would save some querys, and it might save some bandwith in the long run too.
Quote from Dygear :It would be nice if we could get the hole database from lfsworld in one go. That would be tarpitted for a whole day. You could gzip file the and place it on the server. Then with cron, update it evey 24 hours. It would save some querys, and it might save some bandwith in the long run too.

I recently asked Victor a very similar question via pm. Something that I hadn't really considered was the actual player size of LFS - theres a lot of 'em, and dumping them to csv / other format and then gzipping it wouldnt be particularly economical.

Plus Victor's stated he'd prefer the pubstats to be "live" - which didnt really bother me for my project.
Quote from the_angry_angel :I recently asked Victor a very similar question via pm. Something that I hadn't really considered was the actual player size of LFS - theres a lot of 'em, and dumping them to csv / other format and then gzipping it wouldnt be particularly economical.

Plus Victor's stated he'd prefer the pubstats to be "live" - which didnt really bother me for my project.

24 hours is still pretty live. That said, I know it's alot of data, but really how much? 30MB?
Quote from Dygear :24 hours is still pretty live. That said, I know it's alot of data, but really how much? 30MB?

*shrugs* No idea tbh. Having that much data would allow you to do some interesting stuff with it though.
A database dump would make some stuff simpler for sure, maybe a dump exluding detailed race results could work? I'm thinking about writing something to show statistics on overall team progress, with FLP's meager 6 members it'll still be hundreds of queries.

I could live with such a thing being tarpitted an entire week.

Getting a dump of all players in <team> would also be great if a complete one isn't happening.
Quote from filur :A database dump would make some stuff simpler for sure, maybe a dump exluding detailed race results could work? I'm thinking about writing something to show statistics on overall team progress, with FLP's meager 6 members it'll still be hundreds of queries.

I've been thinking about throwing together something like that, with hotlaps and pbs and stuff, generating + / - % differences, and pretty graphs and stuff for pbs and hotlaps, possibly team size growth (with child-ish league tables based on the results), etc. and mashing it together with links to and from lfsworld and the forums - but its simply not possible with the current system.

Quote from filur : I could live with such a thing being tarpitted an entire week.

Hell yeah. I could probably cope with per-month tbh. I'm specifically thinking something along the lines of Planetarion's old dump's (csv files dumped out, and then gzipped; although this is rather different from what they do now). Although, I'd be perfectly happy with most formats, as long as its well documented

Btw Victor, sorry I never got around to actually responding to your pm about this - it kinda got pushed to the bottom of the pile and then I forgot about it until now :s
I've gotten part way on the team stats that I co-made with traxxion, traxxion comming up with the original idea. At the end of the day, I'd like to know alot more about the racer so that I can better get information on them. SimFIA's racer db files are built like so.


<?php 
function write_user_cache($LFSName)
{
    
$LFSWName str_replace(' ''%20'$LFSName);
    
sleep(5);
    
$data file("http://www.lfsworld.net/pubstat/get_stat2.php?version=1.2&idk=8Kz5s8x5PMl7JwImr4VtYX3K99S9s5bf&action=pst&racer=${LFSWName}");
    
$array['OS']['DIST'] = $data[0];
    
$array['OS']['FULE'] = $data[1];
    
$array['OS']['LAPS'] = $data[2];
    
$array['OS']['JOIN'] = $data[3];
    
$array['OS']['WINS'] = $data[4];
    
$array['OS']['SECO'] = $data[5];
    
$array['OS']['THIR'] = $data[6];
    
$array['OS']['FINS'] = $data[7];
    
$array['OS']['QUAL'] = $data[8];
    
$array['OS']['POLE'] = $data[9];
    
$array['OS']['CRED'] = $data[10];
    
$array['OS']['DRAG'] = $data[11];
    
$array['OS']['DWIN'] = $data[12];
    
$array['OS']['ONLI'] = $data[13];
    
$array['OS']['HOST'] = $data[14];
    
sleep(5);
    foreach(
file("http://www.lfsworld.net/pubstat/get_stat2.php?version=1.2&idk=8Kz5s8x5PMl7JwImr4VtYX3K99S9s5bf&action=hl&racer=${LFSWName}") as $data)
    {
        
$info explode(' '$data);
        
$array['HL'][] = array('ID_HL' => $info[0], 'TRACK' => $info[1], 'CAR' => $info[2], 'TIME' => $info[3], 'FLAGS' => $info[4]);
    }
    
sleep(5);
    foreach(
file("http://www.lfsworld.net/pubstat/get_stat2.php?version=1.2&idk=8Kz5s8x5PMl7JwImr4VtYX3K99S9s5bf&action=pb&racer=${LFSWName}") as $data)
    {
        
$info explode(' '$data);
        
$array['PB'][] = array('TRACK' => $info[0], 'CAR' => $info[1], 'TIME' => $info[2], 'LAPS' => $info[3]);
    }
    
file_put_contents("./cache/{$LFSName}.txt"serialize($array));
    return 
$array;
}
function 
read_user_cache($LFSName)
{
    
$Path "./cache/{$LFSName}.txt";
    if (
file_exists($Path))
        return 
unserialize(file_get_contents($Path));
    else
        return 
write_user_cache($LFSName);
}
?>

I am making a classy PHP5 Live For Speed SDK. Want to help me on it?
Oh and while I have your ear, try using complex strings.


<?php 
file_get_contents
("{$this->pubstatURL}&c=2&idk={$this->idKey}&action={$action}&racer={$racer}");
?>

If they would open that up for premium stats only I would sign up for it, even with a one day tar pit.

FGED GREDG RDFGDR GSFDG