The online racing simulator
Commentary on the "getstat" LFS World script
(358 posts, started )
Haha ok, no I'm not bothered. Tnx. In S1 there seemed to be a lot of effort in avoiding the stats to be used more than they had to. With restricted access time, etc. So I just wanted to be sure.
In our website (mrnl.net) the who-is-online list is visible on all pages so in some cases we would need the LFSstat feed twice. Tempting for a less gifted programmer - like my self - to just call LFSworld when ever we need it and just hamer the feed.
Anyway, I'll go the extra mile and cache as many things a possible.
I'm having trouble in getting all the allowed cars from the host information (?action=hosts)
When I process the 4 bytes that hold the CARS information I only get the S1 cars (upto the MRT). Is there anyone who did sucseed in getting all the cars out?
Tnx
Quote from mr Orange :I'm having trouble in getting all the allowed cars from the host information (?action=hosts)
When I process the 4 bytes that hold the CARS information I only get the S1 cars (upto the MRT). Is there anyone who did sucseed in getting all the cars out?
Tnx

By the sounds of it you are only processing the first byte of the 4 bytes. You need to process them all because you can only get 8 cars in a byte.
The cars are in game order (i.e. the order they appear in the server list, left to right)
what would be the link just to see if my user name is online?

Guess I am just lost here :S
Quote from Pootie :what would be the link just to see if my user name is online?

Guess I am just lost here :S

http://lfsworld.net/pubstat/get_stat2.php?action=hosts is the link you should use. It'll return detailed host & racer info, so it requires some parsing. Here's an example of parsing just the racers and the host they are on :


<?php 

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

// init some vars
$users = array ();
$x 0;
$hostlist "";

// get the hostlist
$hostlist file_get_contents ("http://lfsworld.net/pubstat/get_stat2.php?action=hosts");
$len strlen ($hostlist);
if (
$len 52) exit ("Couldn't get hostlist. Quitting...");

// parse the data
while ($x $len) {
    
$hostname "";
    
$nr_racers 0;

    for (
$y=0$y<32$y++) $hostname .= $hostlist[$x++];
    
$hostname trim_c_string ($hostname);

    
$x += 20// skip some host-data

    
$nr_racers ord ($hostlist[$x++]);
    for (
$w=0$w<$nr_racers$w++) {
        
$username "";
        for (
$y=0$y<24$y++) $username .= $hostlist[$x++];
        
$users[trim_c_string ($username)] = $hostname;
    }
}

// printout of gathered data
foreach ($users as $user => $host) {
    echo 
$user." -> ".$host."<br />\n";
}

?>

Quote from Anarchi-H :By the sounds of it you are only processing the first byte of the 4 bytes. You need to process them all because you can only get 8 cars in a byte.
The cars are in game order (i.e. the order they appear in the server list, left to right)

I processed each byte separately and that did the trick. Tnx!

Just because I'm curious, is it also possible to join the 4 bytes into one long string of bits?
Quote from mr Orange :Just because I'm curious, is it also possible to join the 4 bytes into one long string of bits?

Yes, but it's treated as a 4byte integer
The reason for this is bitwise operations are performed with integers.
Once (if) the amount of cars in LFS exceeds 32, we'll need to use multiple integers if they are still transmitted bit-encoded.


<?php 
$cars 
ord($byte0) | (ord($byte1) >> 8) | (ord($byte2) >> 16);
?>

This will get you all of the cars in a single integer
just a tiny note about that that line won't work reliably when all 32 bits are used, since php doesn't do unsigned 32 bit integers. But yes, for now with S2 that'll work just dandy
right, can anyone help me at all,

i want to be able to show each racers profile in my own site, but i have absolutley no idea how to implement this script so it shows up on my site.

I want to be able to click the racers name and bring their profile details into the website.

can anyone help me out or at least point me in the right direction!

thanks in advance
Some online info??
I can't find one thing... Need a little help. Can somebody show me query for showing racer's status - offline/online and if it possible name of server when online.
Thanks for the php code Victor it works a treat.

I have amended the variable names as one or two conflicted with variables aready used in my code. I have added a function to remove the colour code data and created a formatted table that will fill with team members if they are listed in the data file.

I hope this will be of some use to someone.

Dean

Note : New code below
Little error on line 67:

<?php 
 
case "team member" LFS Name:
?>

should be:

<?php 
case "team member LFS Name"
?>

Works great so far, thanks
Would this be right? Cause its not showing my online status?

foreach ($LfsUsers as $LfsUser => $LfsHost) {
switch (strtolower($LfsUser)) {
case "[M.B]Budman Pootie":
case "team member LFS Name":
case "team member elecc":
case "team member LFS Name":
case "team member LFS Name":
case "team member LFS Name":
$LfsUser = remove_colour_codes($LfsUser);
$LfsHost = remove_colour_codes($LfsHost);
echo "<tr bgcolor='#FFFFFF'>";
echo "<td>$LfsUser</td>";
echo"<td>$LfsHost</td></tr>";
$TeamMembers + 1;

Full not much changed,just so that someone with knowledge can have a look see
<?
// 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;
}

// 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);
if ($len < 52) exit ("Couldn't get hostlist. Quitting...");

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

/* Set the variable to count the members online */
$TeamMembers = 0;

/* 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'>";
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) {
switch (strtolower($LfsUser)) {
case "[M.B]Budman Pootie":
case "team member LFS Name":
case "team member LFS Name":
case "team member LFS Name":
case "team member LFS Name":
case "team member LFS Name":
$LfsUser = remove_colour_codes($LfsUser);
$LfsHost = remove_colour_codes($LfsHost);
echo "<tr bgcolor='#FFFFFF'>";
echo "<td>$LfsUser</td>";
echo"<td>$LfsHost</td></tr>";
$TeamMembers + 1;
break;
}
}
/* Display this row only if no members are online */
if($TeamMembers == 0){
echo "<tr bgcolor='#FFFFFF' align='center'><td>No Members</td><td>Are Online</td></tr>";
}
/* Close the table */
echo "</table></center><br>";
?>

prolly something like: (note the two comments as well)


<?php 
foreach ($LfsUsers as $LfsUser => $LfsHost) {
    switch (
$LfsUser) { // don't strtolower ()
     
case "Pootie":       // use only your LFS username
     
case "team member LFS Name":
     case 
"team member elecc":
     case 
"team member LFS Name":
     case 
"team member LFS Name":
     case 
"team member LFS Name":
         
$LfsUser remove_colour_codes($LfsUser);
         
$LfsHost remove_colour_codes($LfsHost);
         echo 
"<tr bgcolor='#FFFFFF'>";
         echo 
"<td>$LfsUser</td>";
         echo
"<td>$LfsHost</td></tr>";
         
$TeamMembers 1;
?>

What can I say thanks,that fixed it :P
:doh: I should have said to put the "team member LFS Name": in lower case.

The reason for using strtolower in the switch statement was to try and stop any mistyping of Upper and Lowercase characters in the LFS Name. The ouput though is in the case as defined in the data file.

Dean
Thanks a lot guys!!!
how to get this stats --- I'm not a programmer
Embarrassed here but I guess that's what happens when you don't know almost anything about coding.

Any help will be appreciated

We have started a remote dedicated host, running 3 lfs servers. I would be interested only in knowing if some of our users are online (The users from our website), or simply to show "This user left the pits" etc... in our website.

We would like to display all possible stats from LFS World as well, but I can't find the way just yet. What Victor talks about is completely above my understanding and I can't find a simple file to download to query lfsworld, or if there is a way only to query a limited amount of users that we could enter ourselves so the queries aren't as big.

If someone who knows more about this could actually help us out, we'll give full credit, our site has not gone public yet but it already has a lot of users.

Thanks in advance.

Best wishes

Sergio
Long way to go...
I have just started to try to learn PHP. Perhaps a big start but I tried to recive some data from lfsworld and the result goes like this

"Fatal error: Call to undefined function: file_get_contents() in c:\phpdev\www\lfsdata.php on line 16"

I got phpdev423 installed. Is the problem that the function file_get_contents() don't exist or...I would be glad if someone could point me in the right direction.

Thanx
Tooby
Cheers for that Dean

I've got a rudimentary version running now, with the table that expands and contracts as members join and leave. GREAT!!!

What I'd really like though is a fixed table with members in it, and the words Online or Offline to appear as required. Or even images

Anyone know how to do this (I guess someone does, cos most team websites seem to be like it ).

Ta ta for now...
Since there is no racerlist for S2 stats, you have to fetch the full server detail listing and scan each servers racer list for the names you are looking for. If you find them, they are online, if not then they are offline.
In noobspeak? Oh, nvm

PM's saving the day again!
Quote from D34N0 :This is a link to the function file_get_contents http://uk2.php.net/manual/en/function.file-get-contents.php

It is only available in PHP 4 >= 4.3.0, PHP 5 as stated in the above link.

Heres a link to the PHP Quick Manual Reference http://www.php.net/quickref.php

Also if learning PHP I found the tutorials on this site very helpful http://www.tizag.com they gave me a good understanding and it's just the tip of the iceberg

Thanx! I thought I was a total looser. I've started to look at the tutorials and uppdated my php install. Se if that makes any difference

/Tooby
I have updated the code to show the server name in the correct colours (except white which is set to dark grey as it shows better on a white background ).

The team Members are now entered into an array at the beginning of the code, use lowercase in the array as this helps to minimise the chances of mistyping the name. If you want to use the name in the correct case you will need to remove strtolower used in the display table functions. At the end are two lines that allow you to display the online status in an expandable table with columns Name and Server or a fixed table showing all team members with the columns Name, Status and Server. Comment out the one you do not want to use.

Hope this will be of use.

Dean

Note : The code has been updated and is in the message below

Commentary on the "getstat" LFS World script
(358 posts, started )
FGED GREDG RDFGDR GSFDG