The online racing simulator
hey victor.
i recognised the following issue on getting the PBs of someone.

If a player deletes his PB the lapcount is not resetted!
for example "csimpok" (sorry dude, just recognised now because of testing purpose).
he has not time for BL GP with XFG but he has done 191.
(i get this line of LFSW: 000 XFG 0 191)

well, i can ignore those lines (time = 0) but i just wanted to know, if this is intended...(honestly I do think so)
laptimes remain when ppl delete their pb
I've created a code to generate a an image singature with user name, online status, and some various online stats.

here's the code if anyone would like it...
also, if anyone notices any glaring errors or ways to improve the code, please let me know

get the cp_unicode_tables file that is referenced in the include at the top of the script in this thread...
http://www.lfsforum.net/showthread.php?t=3304

also, the msgothic.ttf file is 7.9mb, so i can't attach it here. check your windows/font directory for it. verdana should definately be in that folder.

usage is LFS_online_check.php?name=Valid LFS UserName Here

example images are attached, as is a template for where the stats go. obviously, you can change all that around if you want to change the code for the text placement.

updated script
Attached images
lfs_check_template.jpg
online_example.jpg
offline_example.jpg
Quote from glyphon :.. if anyone notices any glaring errors or ways to improve the code, please let me know

Support for kilometers / liters?
Quote from filur :Support for kilometers / liters?

metric version that gives stats in km & L.

also, for anyone using this script, don't forget to put your ID Key in the $idkey variable...the script won't work otherwise.

updated script
Hi,

Im trying to hack up (Hack being the exact term unfortunately) someones 'who's online' tracker which was posted around page 3-5 and im just having some 'fun' with the colour codes and how they work.

Its basically taking "^x" and returning "" which is great when its ^1 and its coming back with the colour code, however when your server name is ulitmately seen as
"^4(^d^s) ^7Mercury Racing Team"
which becomes
"() Mercury Racing Team"
its not much help (would seem that ^d is \ and ^s would be /, creating the (\/) logo)

The ^d also causes the existing colour to become a non colour (outside the listed possibilities) so it looks a little messy.

I've managed to pull the colour code part out of the script, colour would be nice, but its not essential. Can someone think of an alternative method of going about the colour code script?


<?php 
// 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$i1) == "^"){
     
$CharPos strpos($HostName"^"$i);
     
$ColNum substr($HostNamestrpos($HostName"^"$i) + 1,1);
     
$ColourString get_colour(substr($HostNamestrpos($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;
}
?>

Ideally the colour code part would look for the ^, if its 2nd character is between 0-7 then run with it, if its x then replace it with z, everything else gets left as is.

Does any of that make sense? illepall
assuming you are basically trying to convert the ^x codes, I'll just paste what i use to convert hostnames / playernames into something html can display :


<?php 
function WriteColor($str) {
    
codepage_convert ($str);

    
$foundstart False;
    
$tmp '';
    for (
$i 0$i strlen(trim($str)); $i++) {
        if ((
$str[$i] == '^') And (ereg("[0-8]"$str[$i+1]))) {
            if (!
$foundstart) {
                
$tmp .= '<FONT COLOR="'.getcolorcode($str[$i+1]).'">';
                
$foundstart True;
            } else {
                
$tmp .= '</FONT><FONT COLOR="'.getcolorcode($str[$i+1]).'">';
            }
            
$i++;
        } else if (
$str[$i] == "^" && $str[$i+1] == 9) {
            
$tmp .= "</FONT>";
            
$i++;
        } else {
            
$tmp .= $str[$i];
        }
    }
    if (
$foundstart) {
        
$str $tmp.'</FONT>';
    }
    return 
$str;
}

function 
getcolorcode($type) {
    switch (
$type) {
        case 
$type "#000000"; return $type; Break;
        case 
$type "#FF0000"; return $type; Break;
        case 
$type "#00FF00"; return $type; Break;
        case 
$type "#FFFF00"; return $type; Break;
        case 
$type "#0000FF"; return $type; Break;
        case 
$type "#FF00FF"; return $type; Break;
        case 
$type "#00FFFF"; return $type; Break;
        case 
$type "#FFFFFF"; return $type; Break;
        case 
$type "#000000"; return $type; Break;
        case 
$type "#000000"; return $type; Break;
        return 
$type;
    }
}

function 
UnWriteColor($str) {
    
$tmp '';
    for (
$i 0$i strlen($str); $i++) {
        if ((
$str[$i] == '^') And (ereg("[0-8]"$str[$i+1]))) {
            
$i+=1;
        } else {
            
$tmp .= $str[$i];
        }
    }
    
$str $tmp;
    return 
$str;
}

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

    
$str $newstr;
}

// L = Latin 1
// G = Greek
// C = Cyrillic
// J = Japanese
// E = Central Europe
// T = Turkish
// B = Baltic
include ("/PATH TO LACATION OF/cp_unicode_tables.php");

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

that gives you all you need basically.

WriteColor ($hostorplayername) would convert all colors and also figure out the alternate codepage characters (basically what you want except one thing - read on)

UnWriteColor ($hostorplayername) strips all color codes and leaves the rest alone

I've left the ^d and ^s and so forth separate. You can do those with preg_replace :

preg_replace ($tr_ptrn, $tr_ptrn_r, $hostorplayername)

So in essence, to convert all special codes in a host or playername :

WriteColor (preg_replace ($tr_ptrn, $tr_ptrn_r, $hostorplayername))
Stats Sig graphic
couple of fixes...

added a random time generator to the cache time between 120s and 360s, so if there are multiple racer stat images on one page, they won't all try to refresh the cached image at the same time.

I also added in template support, so that different images can be used.
LFS_online_check.php?name=glyphon&template=1

And remember to change the $idkey variable to your ID Key, or the script won't work.

also, a very handy little trick for people using apache servers...
add this to your .htaccess file. with this code, you'll be able to use check#.LFS_USERNAME.jpg to point to the script (with # being the template number)
RewriteEngine on
RewriteRule ^check([0-9]+)\.([A-Za-z0-9]+|.*)\.jpg$ /LFS_online_check.php?name=$2&template=$1 [nc,ns]

updated script
Quote from Victor :assuming you are basically trying to convert the ^x codes, I'll just paste what i use to convert hostnames / playernames into something html can display :


<?php 
function WriteColor($str) {
    
codepage_convert ($str);

    
$foundstart False;
    
$tmp '';
    for (
$i 0$i strlen(trim($str)); $i++) {
        if ((
$str[$i] == '^') And (ereg("[0-8]"$str[$i+1]))) {
            if (!
$foundstart) {
                
$tmp .= '<FONT COLOR="'.getcolorcode($str[$i+1]).'">';
                
$foundstart True;
            } else {
                
$tmp .= '</FONT><FONT COLOR="'.getcolorcode($str[$i+1]).'">';
            }
            
$i++;
        } else if (
$str[$i] == "^" && $str[$i+1] == 9) {
            
$tmp .= "</FONT>";
            
$i++;
        } else {
            
$tmp .= $str[$i];
        }
    }
    if (
$foundstart) {
        
$str $tmp.'</FONT>';
    }
    return 
$str;
}

function 
getcolorcode($type) {
    switch (
$type) {
        case 
$type "#000000"; return $type; Break;
        case 
$type "#FF0000"; return $type; Break;
        case 
$type "#00FF00"; return $type; Break;
        case 
$type "#FFFF00"; return $type; Break;
        case 
$type "#0000FF"; return $type; Break;
        case 
$type "#FF00FF"; return $type; Break;
        case 
$type "#00FFFF"; return $type; Break;
        case 
$type "#FFFFFF"; return $type; Break;
        case 
$type "#000000"; return $type; Break;
        case 
$type "#000000"; return $type; Break;
        return 
$type;
    }
}

function 
UnWriteColor($str) {
    
$tmp '';
    for (
$i 0$i strlen($str); $i++) {
        if ((
$str[$i] == '^') And (ereg("[0-8]"$str[$i+1]))) {
            
$i+=1;
        } else {
            
$tmp .= $str[$i];
        }
    }
    
$str $tmp;
    return 
$str;
}

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

    
$str $newstr;
}

// L = Latin 1
// G = Greek
// C = Cyrillic
// J = Japanese
// E = Central Europe
// T = Turkish
// B = Baltic
include ("../../../lfsworld/php/inc/cp_unicode_tables.php");

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

that gives you all you need basically.

WriteColor ($hostorplayername) would convert all colors and also figure out the alternate codepage characters (basically what you want except one thing - read on)

UnWriteColor ($hostorplayername) strips all color codes and leaves the rest alone

I've left the ^d and ^s and so forth separate. You can do those with preg_replace :

preg_replace ($tr_ptrn, $tr_ptrn_r, $hostorplayername)

So in essence, to convert all special codes in a host or playername :

WriteColor (preg_replace ($tr_ptrn, $tr_ptrn_r, $hostorplayername))


<?php 
include ("/PATH TO LACATION OF/cp_unicode_tables.php");
?>

Kinda lost me anyway, but whats that?? Is this a file local to the LFSW server or something knocking about i could/should have installed local to myself.

For the time being ive just ripped out the colour code stuff, and got it to display our server name properly if thats what it returns, so our servername appears correct (in text) but everyone elses server is gonna have the ^ gubbins all over it still and theres no colours
whoops - that include was copied a bit too literally - should be

include ("/PATH TO LACATION OF/cp_unicode_tables.php");

and you can get that file from here where it is explained how to parse those codepages LFS supports :
http://www.lfsforum.net/showth ... mp;highlight=parsing+code

about colours in other hostnames - i can only suspect you don't run them through the color writing functions.
Quote from Jos Belgium :Hi again,
in post 52in this thread ( http://www.lfsforum.net/showthread.php?p=35947#post35947 ) there is a terrific working script to find who is online. I'm using this script and i love it. But there is one little problem with it i think. What about lfs users that have a space in their name? (e.g. like myself "Jos Belgium"). Is there a way to fix this? I've tried some things i could come up with (in the function trim_c_string in the if statement add something like " || $string[$x] == '(just a space here)'"
but i wasn't able to correct this...
Any help?

I have the same problem with the script, when user have a space in his TEAMMEMBERNAME they dont show it when the user is online!
e.g.
$TeamMembers = array("braxel","benzinx","Bill Darkman");
$InGameName = array("Braxel","Benzin","Bill Darkman"");
Bill Darkman will never show onlne, all other works.
Sorry for my bad english!
I've got a low priority request...could Track and Car data be added to the action=PST query?
not really sure what you mean. All pb's of that person?
nah, nothing that elaborate. just the car/track currently being used if the person is online, or the car/track they were using the last time they were online...like on the racer stats page of LFSWorld.

see example pic.
Attached images
example.gif
k, let me think about that for the next version update
Also if he's not online, a timestamp for "last seen online" or something would be useful too..
Quote from Victor :k, let me think about that for the next version update

thanks
Update - v0.9
added support for identkey per user

I left out some information from the installation instruction (thanks banshee). I've updated the instructions and replaced the attached file, so any downloads after now will have the correct instructions.

For everyone that has already downloaded the file, here are the missing instructions...

Quote :6. .htaccess
A. No .htaccess file in the Public_HTML directory
Move the supplied .htaccess file to the public_html directory.

B. There is a .htaccess file already in the public_html directory
Open the supplied .htaccess file and copy the code.
Now open the existing .htaccess file in th public_html directory and paste the code.
Make sure there is only one line in the file that has "RewriteEngine on"
Group all lines that start with "RewriteRule" together

Made some fairly significant changes to the code of the script.
  • Added ability to set template selection to random
  • Reorganized the directory structure
  • Changed the way player stats is cached. Now cached as text data instead of as the generated graphic.
  • Units can now be set to metric or imperial units
  • Fixed bug that showed offline players as online when script tried to pull the live stats from the LFSWorld server too quickly after just pulling the stats
  • added switch command for formating user name on signature stats graphic.
  • changed how racing server names are displayed to fix bug that caused incorrect character to be displayed at times.
  • switched fonts used for Japanese text. (included)
Attached files
LFS_online_check.zip - 1.8 MB - 608 views
LFS_online_check_update_only.zip - 3.4 KB - 550 views
Quote from banshee56 :Glyphon, in the readme, you state:
Shouldn't the url be "http://your-host/LFS_Checker/check1.glyphon.jpg" ??

nope. assuming that you make the LFS_Checker folder in the root public_html folder of the webhost, then the "short" url would be http://your-host/check1.banshee56.jpg

if you changed the name of the "LFS_Checker" folder, or place it in a different folder, then you'd have to edit the .htaccess file so that the "short" url would still work, and even then it would be http://your-host/check1.banshee56.jpg
I entered the url as you typed it (with my web address) within the IMG tags on various forum sigs, and it did not work until I added the "LFS_Checker" to the address. I did not change the file structure and the folder was installed in my website root directory.

One thing that was missing was the rewrite line you posted several posts up as needed in the htaccess file. After I added that, everything worked.
Quote from banshee56 :One thing that was missing was the rewrite line you posted several posts up as needed in the htaccess file. After I added that, everything worked.

Oh, you are right...i included the rewrite line in a .htaccess file, but in the zip file it would get uploaded into the LFS_Checker folder, but the code in that file needs to get added to the .htaccess file in the public_html directory.:doh:

good catch. thanks
Another thing that has me baffled: I tested both versions (off & online) and only the offline image shows. When I went online to see if the online image shows, I only get the url of the PHP, and not the image. I created two different images, named per the instructions, and based on the template. I've looked through the PHP file and can find no reasons why the online wouldn't show. Any ideas?
Quote from banshee56 :I've looked through the PHP file and can find no reasons why the online wouldn't show. Any ideas?

try and pull up the stats for someone online. then if it displays the same issue, go into the cache directory and open up the cache file for that person. are there any error messages? if there are no error messages, and the cache file has stats in it, then the problem is with the image file. double check the spelling of the online file. also make sure that its a .png file.

if everything is correct, then PM the url to me so i can see if i can figure out what's going on.
I can tell you already that the spelling is the same. I checked specifically for that and for the png file format. I know the image is good as it is exactly the same as the offline image, except for one color. I used the same working XAR (Xara Xtreme graphics package) file to create both images.

I will go online tonight and then check for the image to show and then check the cache file for errors.

One other note, I used the userNameSwitch.php file to have my name show up the same as my ingame name. Does this matter?

Also, If I wanted to create these for all my teammates, all I would have to do is to create an LFS_Checker folder for each member and get the ident key from them, correct? Is there a simpler way?

FGED GREDG RDFGDR GSFDG