The online racing simulator
Read mpr data in php
(7 posts, started )
Read mpr data in php
Hi

I´m going to try do a php script which can read all the data from mpr.

WeatherWind, LapsPlayerFast Lap, End places, etc..

And I would get a bit help for this..

**Note, I know that would be more easy in C but must be in php..**

Thx
Well you just need to open the file and read out the bytes, it's farily simple in both C and PHP. The way the data is stored is actually pleasingly straight-forward, you can see what each byte means on the LFS site: http://www.lfs.net/?page=MPR.
Already I can open the replay file, with fopen, with I don´t know how do it by bites :S
OK - It's been a long time since I did any PHP, and I never really worked with binary data much, but if I remember rightly you just need to read the data out as strings and then use the unpack() function to convert the bytes from their binary representation into all the nice numbers and stuff that you need. If you look round the forum, or search on google, you'll find a few example of how to work it.
Aja, ok thx, I will try and I´ll post again here with the results.

Thx u again
I´ve tried unpack() but It don´t work, but very posible because me.. Could someone do a little example using unpack for read the mpr?
A good example could be found in my signature, It contains code that uses the unpack function to read data from LFSWorld.


<?php 
    
function get_hosts() {
        
$string $this->make_query("&action=hosts");
        for (
$pointer 0$i 0$pointer <= strlen($string); $i++) {
            
$NumberOfRacers = @unpack("c"substr($string$pointer 521));
            
$NumberOfRacers $NumberOfRacers[1];
            
$NumberOfRacersLen $NumberOfRacers 24;
            
$PointerPast $NumberOfRacersLen 53;
            
$result[$i] = array();
            if ((
$result[$i] = @unpack("a32hostname/c4tmlt/a4tcrm/icars/irules/claps/cqual/cspare1/cspare2/cnrofracers/a{$NumberOfRacersLen}racernames"substr($string$pointer$PointerPast)))) {
                
$result[$i]['racernames'] = preg_split("/\\0/"$result[$i]['racernames'], -1PREG_SPLIT_NO_EMPTY);
                
$result[$i]['tmlt'] = unpack("ctype/cmain/cletter/ctestId"$result[$i]['tmlt']);
                
$result[$i]['tcrm'] = unpack("ctrack/cconfig/creversed/cmax"$result[$i]['tcrm']);
            } else {
                unset(
$result[$i]);
            }
            
$pointer += $PointerPast;
        }
        return 
$result;
    }
?>


Read mpr data in php
(7 posts, started )
FGED GREDG RDFGDR GSFDG