The online racing simulator
Quote from mr Orange :As a matter of fact, all join links on LFSWorld give the same "Host not found on master server" message with Firefox. Or is that just me?

If no join links work at all, there's something wrongly setup maybe? Perhaps you need to update your join-utility to the latest? http://lfstools.crazyice.net/p ... php?action=file&id=57
Wouldn't know otherwise why it doesn't work in firefox. I haven't met anyone else having that problem I think

Additionally, I just tested hostnames with the '|' character in them, they work without any additional encoding in IE. I'm really thinking you haven' tinstalled the latest join-utility now?
Php newbie
How is it possible to achieve something like this but for PB's ?

http://www.lfsforum.net/attach ... tid=3462&d=1132355773

And with the scripts for online/offline all I can get is: Couldn't get hostlist. Click to retry...

I'm using this script

<?
//******************************************
// Add Team Member names to$TeamMembers
// LFS User Name and in lowercase
// Lowercase used to reduce typos
// in the username
//
// Also add the team Members In Game
// Name in $InGameName (any case will do)
// MUST be in the same order as $TeamMembers
//******************************************
$TeamMembers = array("pinto_pt","lfs name","lfs name","lfs name","lfs name");
$InGameName = array("pinto_pt","lfs name","lfs name","lfs name","lfs name");
//**********************************

// function to safely trim null-terminated strings
// could just use trim () in this example though
function trim_c_string ($string) {
$new = "";
$len = strlen ($string);
for ($x=0; $x<$len; $x++) {
if ($string[$x] != "\0") $new .= $string[$x];
else break;
}
return $new;
}

// 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;
}

// Function used by format_host_colours function to display correct colour value in html format
function get_colour($ColourNum){
switch ($ColourNum) {
case "0";
$ColourName = "#000000"; //Black
break;
case "1";
$ColourName = "#FF0000"; //Red
break;
case "2";
$ColourName = "#00FF00"; //Pastel Green
break;
case "3";
$ColourName = "#FFFF00"; //Yellow
break;
case "4";
$ColourName = "#0000FF"; //Light Blue
break;
case "5";
$ColourName = "#FF0080"; //Light Purple
break;
case "6";
$ColourName = "#00FFFF"; //Turquoise
break;
case "7";
// Remove comment marks on next line if not a white background
//$ColourName = "#FFFFFF"; //White
// Add Comment marks to next line if not a white background
$ColourName = "#808080"; //Dark Grey
break;
case "8";
$ColourName = "#00FF00"; //Pastel Green
break;
}
return $ColourName;
}

// Function to replace the ^x codes in the Host name to show correct colours on the screen
function format_host_colours($HostName){
for($i = 0; $i < strlen($HostName); $i++){
if(substr($HostName, $i, 1) == "^"){
$CharPos = strpos($HostName, "^", $i);
$ColNum = substr($HostName, strpos($HostName, "^", $i) + 1,1);
$ColourString = get_colour(substr($HostName, strpos($HostName, "^", $i) + 1,1));
if($i == "0"){
// If ^ found at the start of the host string remove the ^[num]
$TmpString = substr($HostName,$i+2);
// Add the html font code to the start of the string and append the
// variable $TmpString with the ^[num] removed
$HostName = "<font color='$ColourString'>".$TmpString;
}
else{
// Get the left part of the string to the next ^[num]
$LTmpString = substr($HostName,0,$i);
// Get the right part of the string after the ^[num]
$RTmpString = substr($HostName,$i+2);
// Add the html close font and add the new html colour to the end of the
// Left part of the string then add the right part of the string
$HostName = $LTmpString."</font><font color='$ColourString'>".$RTmpString;
}
}
}
// Close any html font tag left open in the above
$HostName = $HostName."</font>";
Return $HostName;
}

// Function to display Team Members online in a dynamic table
function display_expandable_table($TeamMembers, $LfsUsers, $InGameName){
// Set the variable to count the members online
$MembersOnline = 0;
// Count the number of members
$TotalMembers = count($TeamMembers);
// Create Header row for the table
echo "<tr bgcolor='#CCCCCC' align='center'><th>Team Racer</th><th>On Server</th></tr>";
// search through the file for Team Members and add a row to the
// table showing the name and server they are on
foreach ($LfsUsers as $LfsUser => $LfsHost) {
for($i = 0; $i < $TotalMembers; $i++){
if(strtolower($LfsUser) == $TeamMembers[$i]){
$LfsUser = remove_colour_codes($LfsUser);
$LfsHost = format_host_colours($LfsHost);
echo "<tr bgcolor='#FFFFFF'>";
echo "<td>$InGameName[$i]</td>";
echo"<td>$LfsHost</td></tr>";
$MembersOnline =+ 1;
}
}
}
// Display this row only if no members are online
if($MembersOnline == 0){
echo "<tr bgcolor='#FFFFFF' align='center'><td>No Members</td><td>Are Online</td></tr>";
}
}

// Function to display all Team Member Status
function display_fixed_table($TeamMembers, $LfsUsers, $InGameName){
/// Count the number of members
$TotalMembers = count($TeamMembers);
// Create Header row for the table
echo "<tr bgcolor='#CCCCCC' align='center'><th>Team Racer</th><th>Status</th><th>On Server</th></tr>";
for($i = 0; $i < $TotalMembers; $i++){
echo "<tr bgcolor='#FFFFFF'>";
foreach ($LfsUsers as $LfsUser => $LfsHost) {
if(strtolower($LfsUser) == $TeamMembers[$i]){
$LfsHost = format_host_colours($LfsHost);
echo "<td>$InGameName[$i]</td>";
echo "<td>Online</td>";
echo"<td>$LfsHost</td></tr>";
$Found = "True";
break;
}
else{
$Found = "False";
}
}
if($Found == "False"){
echo "<td>$InGameName[$i]</td>";
echo "<td>Offline</td>";
echo"<td>&nbsp</td></tr>";
}
}
}

// init some vars
$LfsUsers = array ();
$x = 0;
$LfsHostList = "";
// get the hostlist
$LfsHostList = file_get_contents ("http://lfsworld.net/pubstat/get_stat2.php?action=hosts");
$len = strlen ($LfsHostList);
// Thanks to Tristiancliffe for this line. It is a refresh link
if ($len < 52) exit ("<a href='javascript:document.location.reload();'>Couldn't get hostlist. Click to retry...</a>");

// parse the data
while ($x < $len) {
$LfsHostName = "";
$nr_racers = 0;
for ($y=0; $y<32; $y++) $LfsHostName .= $LfsHostList[$x++];
$LfsHostName = trim_c_string ($LfsHostName);
$x += 20; // skip some host-data
$nr_racers = ord ($LfsHostList[$x++]);
for ($w=0; $w<$nr_racers; $w++) {
$LfsUserName = "";
for ($y=0; $y<24; $y++) $LfsUserName .= $LfsHostList[$x++];
$LfsUsers[trim_c_string ($LfsUserName)] = $LfsHostName;
}
}

// Create table to hold data
echo "<center><br>";
echo "<table border='1' bordercolor='C0C0C0' cellpadding='4' cellspacing='0' style='border-collapse: collapse' style='font-family: Verdana; font-size: 10pt'>";

//*************************************************
// Comment and Uncomment the type of table you want
//*************************************************
display_expandable_table($TeamMembers, $LfsUsers, $InGameName);
display_fixed_table($TeamMembers, $LfsUsers, $InGameName);
/* Close the table */
echo "</table></center><br>";
?>

Its possible that your host has disabled some settings which allow file_get_contents to open a socket to an externel website. Try putting the following into a file, and see if you can find "allow_url_fopen". If its set to false then you've got a fundamental problem and need to take it up with your host.
<?php phpinfo(); ?>

Quote from the_angry_angel :Its possible that your host has disabled some settings which allow file_get_contents to open a socket to an externel website. Try putting the following into a file, and see if you can find "allow_url_fopen". If its set to false then you've got a fundamental problem and need to take it up with your host.
<?php phpinfo(); ?>


This is what it says
Quote :allow_url_fopen | on | on

So I guess its ON

http://pitstop.mobstop.com/php.php

Quote from Victor :If no join links work at all, there's something wrongly setup maybe? Perhaps you need to update your join-utility to the latest? http://lfstools.crazyice.net/p ... php?action=file&id=57
Wouldn't know otherwise why it doesn't work in firefox. I haven't met anyone else having that problem I think

Additionally, I just tested hostnames with the '|' character in them, they work without any additional encoding in IE. I'm really thinking you haven' tinstalled the latest join-utility now?

Thanks. I apologise, I should have tested a new join-version first. I used the original LFSJoin, maybe it ran out of date or got corrupted when I installed the new FF. Join2LFS works perfect.

Is there a reason you replaced all " " with "%20" on lfsworld.net for IE? As it seams Join2LFS works fine without.

For those interested: urlencode for FF seems to be necessary, else with a host like "ATC Team Public #1" the last space between Public and #1 gets lost.
Login / Identification UPDATE:

Quote :NEW : User-identification (login / Ident-Key)
--------------------------------------------
The option to identify yourself has been introduced. For now this will be voluntary, but in the future it will become obligatory for logging purposes, so you best start using this option right now.
There are two ways to identify yourself:
1) Using an Ident-Key which you can generate on behalf of your account on the LFS World settings pages
You can feed an Ident-Key to the pubstat script via the following variable:
&idk=<Ident-Key>

If you bind an IP address to an Ident-Key, then pubstat will make sure that only that IP address can use that Ident-Key.

or

2) Using your normal login (the same as your LFS account), via the following two url-variables :
&user=<username>
&pass=<password>

<password> may be your password in plain text, or you can md5 it before sending (strongly recommended).

Please try it out
Quote from mr Orange :Is there a reason you replaced all " " with "%20" on lfsworld.net for IE? As it seams Join2LFS works fine without.

Hmm, I thought there was a reason, but I can't recall which one exactly (probably the difference between working and not working). But maybe crazyice made it so that it wasn't needed anymore. If it works it works
Quote from Victor :Please try it out

Well, I generated a ident-key and tried to call pubstat with a fake ident-key but didn't get any error msg?
k, added a mesasge for that (your fake key probably didn't meet the basic requirements so the value never made it into the actual check - or at least I think)
seems fine now
Appears to work ok. An invalid username / pass doesn't give any feedback though.
yeah but that's as long as it's voluntary. Later on it'll be more strict (and fail when wrong username and pass are used)
I decided to try this to see if I could implement it into my league site, I've got the data and parsed it to some extent but I've come to a problem. I am using an array to get the names of the tracks but it only appears once for each person. This is my code:

<?
$TeamMembers = array("Leifde", "csimpok");

$trackValues = array( "000" => "Blackwood GP",
"001" => "Blackwood GP Rev",
"010" => "Blackwood Rallycross",
"011" => "Blackwood Rallycross Rev",
"100" => "South City Classic",
"101" => "South City Classic Rev",
"110" => "South City Sprint 1",
"111" => "South City Sprint 1 Rev",
"120" => "South City Sprint 2",
"121" => "South City Sprint 2 Rev",
"130" => "South City Long",
"131" => "South City Long Rev",
"140" => "South City Town",
"141" => "South City Town Rev",
"200" => "Fern Bay Club",
"201" => "Fern Bay Club Rev",
"210" => "Fern Bay Green",
"211" => "Fern Bay Green Rev",
"220" => "Fern Bay Gold",
"221" => "Fern Bay Gold Rev",
"230" => "Fern Bay Black",
"231" => "Fern Bay Black Rev",
"240" => "Fern Bay Rallycross",
"241" => "Fern Bay Rallycross Rev",
"250" => "Fern Bay Rallycross Green",
"251" => "Fern Bay Rallycross Green Rev",
"400" => "Kyoto Ring Oval",
"401" => "Kyoto Ring Oval Rev",
"410" => "Kyoto Ring National",
"411" => "Kyoto Ring National Rev",
"420" => "Kyoto Ring GP",
"421" => "Kyoto Ring GP Rev",
"500" => "Westhill International",
"501" => "Westhill International Rev",
"600" => "Aston Cadet",
"601" => "Aston Cadet Rev",
"610" => "Aston Club",
"611" => "Aston Club Rev",
"620" => "Aston National",
"621" => "Aston National Rev",
"630" => "Aston Historic",
"631" => "Aston Historic Rev",
"640" => "Aston GP",
"641" => "Aston GP Rev");

$x = 0;
$numMembers = count($TeamMembers);
$LFSRacerHL = array();
$LFSHotlap = "";

while ($x < $numMembers) {
$LFSHotlap = file_get_contents ("http://lfsworld.net/pubstat/get_stat2.php?action=hl&racer=".$TeamMembers[$x]);
if ($LFSHotlap == "no output" || $LFSHotlap == "can't reload this page that quickly after another") {
die("ERROR! LFSWORLD RETURNED:<br />".$LFSHotlap);
}
$LFSHotlap = nl2br($LFSHotlap);
$LFSHotlap = explode("<br />", $LFSHotlap);
$i = 0;
$LFSHotlapNum = count($LFSHotlap);
while ($i < $LFSHotlapNum) {
$LFSRacerHL[$x][$i] = explode(" ", $LFSHotlap[$i]);
$i++;
}
$x++;
sleep("5");
}

$x = 0;
$i = 0;

print "<center><table border=\"1\" cellspacing=\"0\" cellpadding=\"2\"><tr><td><b>Driver Name</b></td><td><b>Track</b></td><td><b>Car</b></td><td><b>Time</b></td></tr>";

foreach ($LFSRacerHL as $key => $value) {
foreach ($LFSRacerHL[$key] as $key2 => $value2) {
print "<tr><td>".$TeamMembers[$key]."</td>";
foreach ($LFSRacerHL[$key][$key2] as $key3 => $value3) {
if ($key3 == 0) {
$newValue3 = $trackValues[$value3];
print "<td>".$newValue3."</td>";
} else {
print "<td>".$value3."</td>";
}
}
print "</tr>";
}
}

print "</table></center>";
?>

I'm using me and csimpok. (csimpok has a lot of hotlaps uploaded which is why I chose him)

The output is here.
You have a space at the start of $value3 for all but the first entries (presumably either \r, \n or both)

Solution?


<?php 
if ($key3 == 0) {
    
$newValue3 $trackValues[trim($value3)];
    print 
"<td>".$newValue3."</td>";
} else {
?>

Notice the 'trim($value3)'.

In addition to that though you have a blank entry in the table at the end of each player, but I'll let you solve that one
I presume that the Per Request and Per MB add up to form the total?
So if I make 10000 requests (@£0.00001 per req), and in those 10000 requests I transfer 261Mb (@£0.0015 per Mb)

£0.10 (10000 requests)
+
£0.3915 (261Mb)
=
£0.50 (rounded up)

(Approximation of data transfer for 10000 hostslist requests)

Correct?
yup

and i'm too lazy to calculate if you used compression in your calculation, but just a general reminder that you can use compression (will make a big difference when getting a lot of hostlists)
ps, I have monthly approximations for the big users. If someone's interested in seeing his current approximation, just pm me and I'll pm back the results. But only the big users please (the majority won't even go beyond 1 pound a month).
It was without compression; I wanted to see how a relatively large output (although I suspect that chart is the largest) scales up in price.

I'll make sure I add idk and username / pass support to PPF when I get my lazy arse around to releasing it. Sorry to anyone who expected it when I said 'shortly'. I have an assload of lame excuses, but I'm sure no one cares

I have just had a thought that poses a problem to the current logisitcs of how this will work though....

ATM, the idea is that the tarpitted stats are free, and the untarpitted stats get charged for...

However, most of the stats will be cached anyway... the main use of untarpitted stats would be to make it easier to get pb, pst, hl data etc.
It is still possible to get that data untarpitted with a little extra code AND the premium members may be getting charged for data that everyone else is getting free just cos they have credit. (I.e. If Mr A requests a host list every 2 minutes, and has credit he may get charged. Mr B requests a host list every 60 seconds, doesn't have any credit & gets it free.)

Just wondering if you've accounted for this in your usage scheme, or if the tarpitted stats are going to have further sanctions imposed?
I'm stuck again...

I'm trying to convert the milliseconds to minutes:seconds.milliseconds format but it won't work, here's my code (the relevant bit).

foreach ($LFSRacerHL[$key][$key2] as $key3 => $value3) {
if ($key3 == 0) {
$newValue3 = $trackValues[trim($value3)];
print "<td>".$newValue3."</td>";
} elseif ($key3 == 2) {
$newValue3 = round(trim($value3)/1000);
$newValue3_1 = round($newValue3/60);
$newValue3_2 = $newValue3_1*60;
$newValue3_3 = $newValue3 - $newValue3_2;
print "<td>".$newValue3_1.":".$newValue3_3."</td>";
} else {
print "<td>".$value3."</td>";
}
}

The output is here.

Any ideas?
Quote from Anarchi-H :It was without compression; I wanted to see how a relatively large output (although I suspect that chart is the largest) scales up in price.

I'll make sure I add idk and username / pass support to PPF when I get my lazy arse around to releasing it. Sorry to anyone who expected it when I said 'shortly'. I have an assload of lame excuses, but I'm sure no one cares

I have just had a thought that poses a problem to the current logisitcs of how this will work though....

ATM, the idea is that the tarpitted stats are free, and the untarpitted stats get charged for...

However, most of the stats will be cached anyway... the main use of untarpitted stats would be to make it easier to get pb, pst, hl data etc.
It is still possible to get that data untarpitted with a little extra code AND the premium members may be getting charged for data that everyone else is getting free just cos they have credit. (I.e. If Mr A requests a host list every 2 minutes, and has credit he may get charged. Mr B requests a host list every 60 seconds, doesn't have any credit & gets it free.)

Just wondering if you've accounted for this in your usage scheme, or if the tarpitted stats are going to have further sanctions imposed?

there's the variable &free=1 that you can use if you have credit to avoid making use of the premium service (the default is 'have credit? use premium - if not, use free').
Obviously you will be tarpitted again when you throw in one free request right after you did a premium request. It won't work, because the tarpitting is still there - it just doesn't break your request when using premium.
Quote from Leifde :I'm stuck again...

I'm trying to convert the milliseconds to minutes:seconds.milliseconds format but it won't work, here's my code (the relevant bit).

foreach ($LFSRacerHL[$key][$key2] as $key3 => $value3) {
if ($key3 == 0) {
$newValue3 = $trackValues[trim($value3)];
print "<td>".$newValue3."</td>";
} elseif ($key3 == 2) {
$newValue3 = round(trim($value3)/1000);
$newValue3_1 = round($newValue3/60);
$newValue3_2 = $newValue3_1*60;
$newValue3_3 = $newValue3 - $newValue3_2;
print "<td>".$newValue3_1.":".$newValue3_3."</td>";
} else {
print "<td>".$value3."</td>";
}
}

The output is here.

Any ideas?

forgive me, but i get lost in your example.
I'll just paste my function for converting ms into msht:

<?php 
function time2msht ($time) {
    
$div1 = (int) ($time 1000);
    
$ms = ($time 1000)-$div1;
    
$min = (int) ($div1 60);
    
$sec $div1 - ($min 60);
    
$msht $min.":".substr ($sec 100, -2).".".substr (round ($ms 1000 1000), -3);
    return 
$msht;
}
?>

General tip for you beginner programmers - put things in functions. It's much nicer if you have one line in your main code block that says

$msht = time2msht ($milliseconds);

instead of writing the actual code to convert milliseconds to msht on the place of that line. You'll get lost in the end, when trying to find a bug or even just a variable.

Functions are there to make programming easier and more fun Use them.

EDIT - note that this function is just for positive values and doesn't indicate hours.
Fair enough. Mixing and matching free & premium requests on the same cache is going to present some fun, but it's good to know you've covered the bases
Quote from Victor :forgive me, but i get lost in your example.
I'll just paste my function for converting ms into msht:

<?php 
function time2msht ($time) {
    
$div1 = (int) ($time 1000);
    
$ms = ($time 1000)-$div1;
    
$min = (int) ($div1 60);
    
$sec $div1 - ($min 60);
    
$msht $min.":".substr ($sec 100, -2).".".substr (round ($ms 1000 1000), -3);
    return 
$msht;
}
?>

General tip for you beginner programmers - put things in functions. It's much nicer if you have one line in your main code block that says

$msht = time2msht ($milliseconds);

instead of writing the actual code to convert milliseconds to msht on the place of that line. You'll get lost in the end, when trying to find a bug or even just a variable.

Functions are there to make programming easier and more fun Use them.

EDIT - note that this function is just for positive values and doesn't indicate hours.

Thanks

P.S. Thanks Anarchi-H for solving my first problem
Quick question for you Victor, is the unique ident key always a fixed length?

FGED GREDG RDFGDR GSFDG